diff options
author | Jose Fonseca <jfonseca@vmware.com> | 2015-08-03 11:58:35 +0100 |
---|---|---|
committer | Jose Fonseca <jfonseca@vmware.com> | 2015-08-03 11:58:35 +0100 |
commit | 6ddfd98cdafefaa1b60273d5568b8dbd13730dae (patch) | |
tree | 26fdfaa226326069ee753dfe10c1b25cdc8873c1 /inject | |
parent | 1ec8346e096979617d6c48a44e137632ccc15aed (diff) |
inject: Detect mixed architectures for child processes too.
Diffstat (limited to 'inject')
-rw-r--r-- | inject/inject.h | 31 | ||||
-rw-r--r-- | inject/injectee.cpp | 15 | ||||
-rw-r--r-- | inject/injector.cpp | 30 |
3 files changed, 49 insertions, 27 deletions
diff --git a/inject/inject.h b/inject/inject.h index a293b5ce..703735ce 100644 --- a/inject/inject.h +++ b/inject/inject.h @@ -203,6 +203,37 @@ CloseSharedMem(void) { } +/* + * XXX: Mixed architecture don't quite work. See also + * http://www.corsix.org/content/dll-injection-and-wow64 + */ +static BOOL +isDifferentArch(HANDLE hProcess) +{ + typedef BOOL (WINAPI *PFNISWOW64PROCESS)(HANDLE, PBOOL); + PFNISWOW64PROCESS pfnIsWow64Process; + pfnIsWow64Process = (PFNISWOW64PROCESS) + GetProcAddress(GetModuleHandleA("kernel32"), "IsWow64Process"); + if (!pfnIsWow64Process) { + return FALSE; + } + +#ifdef _WIN64 + BOOL isThisWow64 = FALSE; +#else + BOOL isThisWow64 = TRUE; +#endif + + BOOL isOtherWow64 = FALSE; + if (!pfnIsWow64Process(hProcess, &isOtherWow64)) { + logLastError("IsWow64Process failed"); + return FALSE; + } + + return bool(isThisWow64) != bool(isOtherWow64); +} + + static BOOL injectDll(HANDLE hProcess, const char *szDllPath) { diff --git a/inject/injectee.cpp b/inject/injectee.cpp index c0f417e7..05fc5ab7 100644 --- a/inject/injectee.cpp +++ b/inject/injectee.cpp @@ -118,16 +118,23 @@ MyCreateProcessCommon(BOOL bRet, LPPROCESS_INFORMATION lpProcessInformation) { if (!bRet) { + debugPrintf("inject: warning: failed to create child process\n"); return; } DWORD dwLastError = GetLastError(); - char szDllPath[MAX_PATH]; - GetModuleFileNameA(g_hThisModule, szDllPath, sizeof szDllPath); + if (isDifferentArch(lpProcessInformation->hProcess)) { + debugPrintf("inject: error: child process %lu has different architecture\n", + GetProcessId(lpProcessInformation->hProcess)); + } else { + char szDllPath[MAX_PATH]; + GetModuleFileNameA(g_hThisModule, szDllPath, sizeof szDllPath); - if (!injectDll(lpProcessInformation->hProcess, szDllPath)) { - debugPrintf("inject: warning: failed to inject child process\n"); + if (!injectDll(lpProcessInformation->hProcess, szDllPath)) { + debugPrintf("inject: warning: failed to inject into child process %lu\n", + GetProcessId(lpProcessInformation->hProcess)); + } } if (!(dwCreationFlags & CREATE_SUSPENDED)) { diff --git a/inject/injector.cpp b/inject/injector.cpp index ecdfc1f8..4034c413 100644 --- a/inject/injector.cpp +++ b/inject/injector.cpp @@ -683,32 +683,16 @@ main(int argc, char *argv[]) hProcess = processInfo.hProcess; } - /* - * XXX: Mixed architecture don't quite work. See also - * http://www.corsix.org/content/dll-injection-and-wow64 - */ - { - typedef BOOL (WINAPI *PFNISWOW64PROCESS)(HANDLE, PBOOL); - PFNISWOW64PROCESS pfnIsWow64Process; - pfnIsWow64Process = (PFNISWOW64PROCESS) - GetProcAddress(GetModuleHandleA("kernel32"), "IsWow64Process"); - if (pfnIsWow64Process) { - BOOL isParentWow64 = FALSE; - BOOL isChildWow64 = FALSE; - if (pfnIsWow64Process(GetCurrentProcess(), &isParentWow64) && - pfnIsWow64Process(hProcess, &isChildWow64) && - isParentWow64 != isChildWow64) { - debugPrintf("error: binaries mismatch: you need to use the " + if (isDifferentArch(hProcess)) { + debugPrintf("error: binaries mismatch: you need to use the " #ifdef _WIN64 - "32-bits" + "32-bits" #else - "64-bits" + "64-bits" #endif - " apitrace binaries to trace this application\n"); - TerminateProcess(hProcess, 1); - return 1; - } - } + " apitrace binaries to trace this application\n"); + TerminateProcess(hProcess, 1); + return 1; } if (bAttachDwm && IsWindows8OrGreater()) { |