X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=wrappers%2Fdlltrace.py;h=f7ad20fe8c4a399337fe61313c48d8681a3c5741;hb=7a9fb5103e052150232b64cb5d99374cda3f1234;hp=cea7dc7464c4717efe44828a917f65a6a4c2d3d9;hpb=81301939f025407ceb284a9dcd5d5a1f05d27b8f;p=apitrace diff --git a/wrappers/dlltrace.py b/wrappers/dlltrace.py index cea7dc7..f7ad20f 100644 --- a/wrappers/dlltrace.py +++ b/wrappers/dlltrace.py @@ -26,50 +26,49 @@ """Trace code generation for Windows DLLs.""" +import ntpath + from trace import Tracer from dispatch import Dispatcher from specs.stdapi import API -class DllTracer(Tracer): +class DllDispatcher(Dispatcher): - def __init__(self, dllname): - self.dllname = dllname - - def header(self, api): - print ''' -static HMODULE g_hDll = NULL; + def dispatchModule(self, module): + tag = module.name.upper() + print r'HMODULE g_h%sModule = NULL;' % (tag,) + print r'' + print r'static PROC' + print r'_get%sProcAddress(LPCSTR lpProcName) {' % tag + print r' if (!g_h%sModule) {' % tag + print r' char szDll[MAX_PATH] = {0};' + print r' if (!GetSystemDirectoryA(szDll, MAX_PATH)) {' + print r' return NULL;' + print r' }' + print r' strcat(szDll, "\\\\%s.dll");' % module.name + print r' g_h%sModule = LoadLibraryA(szDll);' % tag + print r' if (!g_h%sModule) {' % tag + print r' return NULL;' + print r' }' + print r' }' + print r' return GetProcAddress(g_h%sModule, lpProcName);' % tag + print r'}' + print r'' -static PROC -_getPublicProcAddress(LPCSTR lpProcName) -{ - if (!g_hDll) { - char szDll[MAX_PATH] = {0}; - - if (!GetSystemDirectoryA(szDll, MAX_PATH)) { - return NULL; - } - - strcat(szDll, "\\\\%s"); - - g_hDll = LoadLibraryA(szDll); - if (!g_hDll) { - return NULL; - } - } - - return GetProcAddress(g_hDll, lpProcName); -} + Dispatcher.dispatchModule(self, module) -''' % self.dllname + def getProcAddressName(self, module, function): + assert self.isFunctionPublic(module, function) + return '_get%sProcAddress' % (module.name.upper()) + + +class DllTracer(Tracer): + + def header(self, api): for module in api.modules: - dispatcher = Dispatcher() + dispatcher = DllDispatcher() dispatcher.dispatchModule(module) Tracer.header(self, api) - - def traceModule(self, module): - api = API() - api.addModule(module) - self.traceApi(api)