Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved Detours logic for detection of 32bit processes (#104)
This patch improves the logic for detecting whether the process to be patched is a 32bit or a 64bit process. The old logic would first enumerate the modules in the process and see if: 1. There is a 32bit executable module 2. There is a 64bit DLL module In case 1.) is true and 2.) is false, i.e. a 32bit executable but no 64bit DLL, the process was deemed to be a 32bit process. This seems plausible, but I encountered a case in which it is not true: I launched an IL-only .NET application (a Windows Forms GUI application) in Windows 10. Right after the CreateProcess call, there were just two modules in the process - A 32bit executable - A 32bit ntdll.dll library I.e. the .NET runtime was not loaded yet. Hence, because there *is* a 32bit executable but there is *not* a 64bit DLL, bIs32BitProcess was set to TRUE. However, when resuming the process and inspecting with Process Explorer, it appears that the process executed in 64bit mode! I suppose it would be possible to replicate the behavior of the Windows loader and be a bit smarter about looking for 32bit executables: instead of just looking at the 'machine' flag, also look for a potential IMAGE_COR20_HEADER (which basically acts as the PE header for .NET executables) and see if that requires 32bit. However, I think there is an easier way to check if the process is 32bit or not. The new logic performs two steps: 1. Detect whether the operating system is 64bit. If the code is compiled as 64bit, then the OS is trivially 64bit. If the code does not have _WIN64 defined, i.e. it is 32bit, but it is running under WOW64, then the OS is 64bit, too. 2. Detect if the process to be patched is 32bit. If the OS is *not* 64bit, the process can't possibly be 64bit. So it must be 32bit. If the OS *is* 64bit, we can identify 32bit processes by calling IsWow64Process() again.
- Loading branch information
two-stop -> two-step