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

Function DetourUpdateProcessWithDllEx

lib_fiber/cpp/src/detours/creatwth.cpp:751–896  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

749}
750
751BOOL WINAPI DetourUpdateProcessWithDllEx(_In_ HANDLE hProcess,
752 _In_ HMODULE hModule,
753 _In_ BOOL bIs32BitProcess,
754 _In_reads_(nDlls) LPCSTR *rlpDlls,
755 _In_ DWORD nDlls)
756{
757 // Find the next memory region that contains a mapped PE image.
758 //
759 BOOL bIs32BitExe = FALSE;
760
761 DETOUR_TRACE(("DetourUpdateProcessWithDllEx(%p,%p,dlls=%lu)\n", hProcess, hModule, nDlls));
762
763 IMAGE_NT_HEADERS32 inh;
764
765 if (hModule == NULL || !LoadNtHeaderFromProcess(hProcess, hModule, &inh)) {
766 SetLastError(ERROR_INVALID_OPERATION);
767 return FALSE;
768 }
769
770 if (inh.OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC
771 && inh.FileHeader.Machine != 0) {
772
773 bIs32BitExe = TRUE;
774 }
775
776 DETOUR_TRACE((" 32BitExe=%d\n", bIs32BitExe));
777
778 if (hModule == NULL) {
779 SetLastError(ERROR_INVALID_OPERATION);
780 return FALSE;
781 }
782
783 // Save the various headers for DetourRestoreAfterWith.
784 //
785 DETOUR_EXE_RESTORE der;
786
787 if (!RecordExeRestore(hProcess, hModule, der)) {
788 return FALSE;
789 }
790
791#if defined(DETOURS_64BIT)
792 // Try to convert a neutral 32-bit managed binary to a 64-bit managed binary.
793 if (bIs32BitExe && !bIs32BitProcess) {
794 if (!der.pclr // Native binary
795 || (der.clr.Flags & COMIMAGE_FLAGS_ILONLY) == 0 // Or mixed-mode MSIL
796 || (der.clr.Flags & COMIMAGE_FLAGS_32BITREQUIRED) != 0) { // Or 32BIT Required MSIL
797
798 SetLastError(ERROR_INVALID_HANDLE);
799 return FALSE;
800 }
801
802 if (!UpdateFrom32To64(hProcess, hModule,
803#if defined(DETOURS_X64)
804 IMAGE_FILE_MACHINE_AMD64,
805#elif defined(DETOURS_IA64)
806 IMAGE_FILE_MACHINE_IA64,
807#elif defined(DETOURS_ARM64)
808 IMAGE_FILE_MACHINE_ARM64,

Callers 1

Calls 5

LoadNtHeaderFromProcessFunction · 0.85
RecordExeRestoreFunction · 0.85
UpdateFrom32To64Function · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…