import cffi wffi = cffi.FFI() wffi.cdef(f''' HANDLE GetCurrentProcess(); void *GetProcAddress(HMODULE hModule, LPCSTR lpProcName); ''') wlib = wffi.dlopen('Kernel32.dll') psffi = cffi.FFI() psffi.cdef('BOOL EnumProcessModules(HANDLE hProcess, HMODULE *lphModule, DWORD cb, LPDWORD lpcbNeeded);') pslib = psffi.dlopen('Psapi.dll') def dlsym(sym): process = wlib.GetCurrentProcess() needed = wffi.new('LPDWORD') pslib.EnumProcessModules(process, wffi.NULL, 0, needed) buf = wffi.new('HANDLE[]', needed[0]//wffi.sizeof('HANDLE')) if pslib.EnumProcessModules(process, buf, wffi.sizeof(buf), needed): count = min(needed[0], wffi.sizeof(buf))//wffi.sizeof('HANDLE') mods = buf[0:count] for mod in mods: addr = wlib.GetProcAddress(mod, sym.encode('utf8')) if addr: return addr return wffi.NULL