#! /usr/bin/python

import sys
import os
import subprocess   # requires Python 2.5
import plistlib

def addExportedSymbols(symDict, kextPath):
    infoPlist = plistlib.readPlist(os.path.join(kextPath, &#34;Info.plist&#34;))
    if infoPlist.has_key(&#39;CFBundleExecutable&#39;):
        bundleID = infoPlist[&#39;CFBundleIdentifier&#39;]
        imagePath = os.path.join(kextPath, infoPlist[&#39;CFBundleExecutable&#39;])
        symbols = subprocess.Popen(
            [&#34;nm&#34;, &#34;-j&#34;, imagePath], 
            stdout=subprocess.PIPE
        ).communicate()[0].split(&#34;\n&#34;)
        for sym in symbols:
            if sym != &#34;&#34;:
                assert not symDict.has_key(sym)
                symDict[sym] = bundleID

def getSymbolsForExtensions():
    kextDir = &#34;/System/Library/Extensions/System.kext/PlugIns&#34;
    symDict = {}
    for kextName in os.listdir(kextDir):
        # Don&#39;t consider certain KEXTs.  Specifically exclude the 
        # Unsupported and MACFramework KEXTs.  Also, ignore any 
        # &#34;6.0&#34; KEXTs, which are present for compatibility only.
        if (   kextName not in (&#34;Unsupported.kext&#34;, &#34;MACFramework.kext&#34;)
           and not os.path.splitext(kextName)[0].endswith(&#34;6.0&#34;) ):
            addExportedSymbols(symDict, os.path.join(kextDir, kextName))
    return symDict

if len(sys.argv) &lt; 2:
    print &gt;&gt; sys.stderr, &#34;usage: %s name...&#34; % os.path.basename(sys.argv[0])
    print &gt;&gt; sys.stderr, &#34;    where name is either a C function name or a C++ class name&#34;
    sys.exit(1)
else:
    symDict = getSymbolsForExtensions()
    for arg in sys.argv[1:]:
        sym = &#34;_&#34; + arg
        if sym in symDict:
            id = symDict[sym]
        else:
            sym = &#34;__ZTV%d%s&#34; % (len(arg), arg)
            if sym in symDict:
                id = symDict[sym]
            else:
                id = &#34;*** not found ***&#34;
        print &#34;%s %s&#34; % (arg, id)
