summaryrefslogtreecommitdiff
path: root/inject
diff options
context:
space:
mode:
authorJose Fonseca <jfonseca@vmware.com>2014-06-18 15:03:25 +0100
committerJose Fonseca <jfonseca@vmware.com>2014-06-18 15:03:25 +0100
commit0b5390db2bca71212ee66507861adcd2e3ddcb4f (patch)
tree63ad58692bef9f5da309f8fc8fbaf78ab67ebc22 /inject
parent159d62dde1a7b05fdc8a77ded4b4fec81e47bcc7 (diff)
inject: Handle Windows API Sets.
This is the proper fix for issue #122 and #172. Windows 8.x's gdi32.dll was getting LoadLibrary/GetProcAddress from API-MS-WIN-CORE-LIBRARYLOADER-L1-?-?.DLL instead of kernel32.dll, hence bypassing our hooks.
Diffstat (limited to 'inject')
-rw-r--r--inject/injectee.cpp37
1 files changed, 30 insertions, 7 deletions
diff --git a/inject/injectee.cpp b/inject/injectee.cpp
index 0e0f132b..4d512134 100644
--- a/inject/injectee.cpp
+++ b/inject/injectee.cpp
@@ -292,6 +292,19 @@ static unsigned numReplacements = 0;
static Replacement replacements[32];
+static void
+hookLibraryLoaderFunctions(HMODULE hModule,
+ const char *szModule,
+ const char *pszDllName)
+{
+ hookFunction(hModule, szModule, pszDllName, "LoadLibraryA", (LPVOID)MyLoadLibraryA);
+ hookFunction(hModule, szModule, pszDllName, "LoadLibraryW", (LPVOID)MyLoadLibraryW);
+ hookFunction(hModule, szModule, pszDllName, "LoadLibraryExA", (LPVOID)MyLoadLibraryExA);
+ hookFunction(hModule, szModule, pszDllName, "LoadLibraryExW", (LPVOID)MyLoadLibraryExW);
+ hookFunction(hModule, szModule, pszDllName, "GetProcAddress", (LPVOID)MyGetProcAddress);
+}
+
+
/* Set of previously hooked modules */
static std::set<HMODULE>
g_hHookedModules;
@@ -310,36 +323,46 @@ hookModule(HMODULE hModule,
return;
}
+ /* Never hook this module */
if (hModule == g_hThisModule) {
return;
}
+ /* Don't hook our replacement modules (based on HMODULE) */
for (unsigned i = 0; i < numReplacements; ++i) {
if (hModule == replacements[i].hReplaceModule) {
return;
}
}
- hookFunction(hModule, szModule, "kernel32.dll", "LoadLibraryA", (LPVOID)MyLoadLibraryA);
- hookFunction(hModule, szModule, "kernel32.dll", "LoadLibraryW", (LPVOID)MyLoadLibraryW);
- hookFunction(hModule, szModule, "kernel32.dll", "LoadLibraryExA", (LPVOID)MyLoadLibraryExA);
- hookFunction(hModule, szModule, "kernel32.dll", "LoadLibraryExW", (LPVOID)MyLoadLibraryExW);
- hookFunction(hModule, szModule, "kernel32.dll", "GetProcAddress", (LPVOID)MyGetProcAddress);
-
const char *szBaseName = getBaseName(szModule);
+
+ /* Don't hook our replacement modules (based on MODULE name) */
for (unsigned i = 0; i < numReplacements; ++i) {
if (stricmp(szBaseName, replacements[i].szMatchModule) == 0) {
return;
}
}
+ /* Leave these modules alone */
+ if (stricmp(szBaseName, "kernel32.dll") == 0 ||
+ stricmp(szBaseName, "ConEmuHk.dll") == 0) {
+ return;
+ }
+
+ /* Hook library loader functions */
+ hookLibraryLoaderFunctions(hModule, szModule, "kernel32.dll");
+ hookLibraryLoaderFunctions(hModule, szModule, "api-ms-win-core-libraryloader-l1-1-1.dll");
+ hookLibraryLoaderFunctions(hModule, szModule, "api-ms-win-core-libraryloader-l1-2-0.dll");
+
/* Don't hook internal dependencies */
if (stricmp(szBaseName, "d3d10core.dll") == 0 ||
stricmp(szBaseName, "d3d10level9.dll") == 0 ||
stricmp(szBaseName, "d3d10sdklayers.dll") == 0 ||
stricmp(szBaseName, "d3d10_1core.dll") == 0 ||
stricmp(szBaseName, "d3d11sdklayers.dll") == 0 ||
- stricmp(szBaseName, "d3d11_1sdklayers.dll") == 0) {
+ stricmp(szBaseName, "d3d11_1sdklayers.dll") == 0 ||
+ stricmp(szBaseName, "d3d11_2sdklayers.dll") == 0) {
return;
}