diff options
author | Jose Fonseca <jfonseca@vmware.com> | 2015-07-10 09:46:16 +0100 |
---|---|---|
committer | Jose Fonseca <jfonseca@vmware.com> | 2015-07-10 09:46:16 +0100 |
commit | bd725c22b9e0ee5341cfd34a00c6f68a64a608e6 (patch) | |
tree | 80a2d66baf32c544f073b341c0b0fe112cc49028 | |
parent | dcdeba4e6142030b3dc0daf8261bb5f0a764a140 (diff) |
inject: Ensure we always get the real module handle.
By using an absolute path.
-rw-r--r-- | inject/injectee.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/inject/injectee.cpp b/inject/injectee.cpp index e31df595..5ffdbafd 100644 --- a/inject/injectee.cpp +++ b/inject/injectee.cpp @@ -586,6 +586,9 @@ enum Action { }; +static char g_szSystemDirectory[MAX_PATH]; + + template< class T > void patchDescriptor(HMODULE hModule, @@ -608,7 +611,9 @@ patchDescriptor(HMODULE hModule, // Knowning the real address is useful when patching imports by ordinal LPVOID lpRealAddress = NULL; - HMODULE hRealModule = GetModuleHandleA(szDescriptorName); + char szRealModule[MAX_PATH]; + _snprintf(szRealModule, sizeof szRealModule, "%s\\%s", g_szSystemDirectory, szDescriptorName); + HMODULE hRealModule = GetModuleHandleA(szRealModule); if (hRealModule) { assert(hRealModule != g_hHookModule); lpRealAddress = (LPVOID)GetProcAddress(hRealModule, szFunctionName); @@ -1030,6 +1035,10 @@ DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) debugPrintf("inject: attached to process %s\n", szProcess); } + if (!GetSystemDirectoryA(g_szSystemDirectory, _countof(g_szSystemDirectory))) { + assert(0); + } + /* * Calling LoadLibrary inside DllMain is strongly discouraged. But it * works quite well, provided that the loaded DLL does not require or do |