MCPcopy Create free account
hub / github.com/acl-dev/acl / DetourUpdateProcessWithDll

Function DetourUpdateProcessWithDll

lib_fiber/cpp/src/detours/creatwth.cpp:678–749  ·  view source on GitHub ↗

/////////////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

676//////////////////////////////////////////////////////////////////////////////
677//
678BOOL WINAPI DetourUpdateProcessWithDll(_In_ HANDLE hProcess,
679 _In_reads_(nDlls) LPCSTR *rlpDlls,
680 _In_ DWORD nDlls)
681{
682 // Find the next memory region that contains a mapped PE image.
683 //
684 BOOL bIs32BitProcess;
685 BOOL bIs64BitOS = FALSE;
686 HMODULE hModule = NULL;
687 HMODULE hLast = NULL;
688
689 DETOUR_TRACE(("DetourUpdateProcessWithDll(%p,dlls=%lu)\n", hProcess, nDlls));
690
691 for (;;) {
692 IMAGE_NT_HEADERS32 inh;
693
694 if ((hLast = EnumerateModulesInProcess(hProcess, hLast, &inh, NULL)) == NULL) {
695 break;
696 }
697
698 DETOUR_TRACE(("%p machine=%04x magic=%04x\n",
699 hLast, inh.FileHeader.Machine, inh.OptionalHeader.Magic));
700
701 if ((inh.FileHeader.Characteristics & IMAGE_FILE_DLL) == 0) {
702 hModule = hLast;
703 DETOUR_TRACE(("%p Found EXE\n", hLast));
704 }
705 }
706
707 if (hModule == NULL) {
708 SetLastError(ERROR_INVALID_OPERATION);
709 return FALSE;
710 }
711
712 // Determine if the target process is 32bit or 64bit. This is a two-stop process:
713 //
714 // 1. First, determine if we're running on a 64bit operating system.
715 // - If we're running 64bit code (i.e. _WIN64 is defined), this is trivially true.
716 // - If we're running 32bit code (i.e. _WIN64 is not defined), test if
717 // we're running under Wow64. If so, it implies that the operating system
718 // is 64bit.
719 //
720#ifdef _WIN64
721 bIs64BitOS = TRUE;
722#else
723 if (!IsWow64ProcessHelper(GetCurrentProcess(), &bIs64BitOS)) {
724 return FALSE;
725 }
726#endif
727
728 // 2. With the operating system bitness known, we can now consider the target process:
729 // - If we're running on a 64bit OS, the target process is 32bit in case
730 // it is running under Wow64. Otherwise, it's 64bit, running natively
731 // (without Wow64).
732 // - If we're running on a 32bit OS, the target process must be 32bit, too.
733 //
734 if (bIs64BitOS) {
735 if (!IsWow64ProcessHelper(hProcess, &bIs32BitProcess)) {

Calls 3

IsWow64ProcessHelperFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…