error on architecture mismatch

This commit is contained in:
Akash Mozumdar 2018-08-22 15:11:58 -04:00
parent cda2cefc28
commit 588b013392

View File

@ -57,8 +57,20 @@ namespace Host
FreeLibrary(textHooker); FreeLibrary(textHooker);
if (HANDLE processHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId)) if (HANDLE processHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId))
{
#ifdef _WIN64
BOOL invalidProcess = FALSE;
IsWow64Process(processHandle, &invalidProcess);
if (invalidProcess)
{
AddConsoleOutput(L"architecture mismatch: try 32 bit NextHooker instead");
CloseHandle(processHandle);
return false;
}
#endif
if (LPVOID remoteData = VirtualAllocEx(processHandle, nullptr, textHookerPathSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)) if (LPVOID remoteData = VirtualAllocEx(processHandle, nullptr, textHookerPathSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE))
if (WriteProcessMemory(processHandle, remoteData, textHookerPath, textHookerPathSize, nullptr)) {
WriteProcessMemory(processHandle, remoteData, textHookerPath, textHookerPathSize, nullptr);
if (HANDLE thread = CreateRemoteThread(processHandle, nullptr, 0, (LPTHREAD_START_ROUTINE)LoadLibraryW, remoteData, 0, nullptr)) if (HANDLE thread = CreateRemoteThread(processHandle, nullptr, 0, (LPTHREAD_START_ROUTINE)LoadLibraryW, remoteData, 0, nullptr))
{ {
WaitForSingleObject(thread, timeout); WaitForSingleObject(thread, timeout);
@ -67,6 +79,10 @@ namespace Host
CloseHandle(processHandle); CloseHandle(processHandle);
return true; return true;
} }
VirtualFreeEx(processHandle, remoteData, 0, MEM_RELEASE);
CloseHandle(processHandle);
}
}
AddConsoleOutput(L"couldn't inject dll"); AddConsoleOutput(L"couldn't inject dll");
return false; return false;