Skip to content

Commit

Permalink
[BUGFIX] Fixed building for 32-bit
Browse files Browse the repository at this point in the history
  • Loading branch information
hasherezade committed Jan 26, 2025
1 parent c8356f5 commit 65b1772
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions run_pe/patch_ntdll.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#include "patch_ntdll.h"
#include <peconv.h>

bool apply_ntdll_patch(HANDLE hProcess, LPVOID module_ptr)
bool apply_ntdll_patch64(HANDLE hProcess, LPVOID module_ptr)
{
#ifndef _WIN64
return false;
#else
HMODULE hNtdll = GetModuleHandleA("ntdll");
if (!hNtdll) return false; // should never happen

Expand All @@ -27,7 +30,7 @@ bool apply_ntdll_patch(HANDLE hProcess, LPVOID module_ptr)
if (!ReadProcessMemory(hProcess, (LPVOID)stub_ptr, stub_buffer_orig, stub_size, &out_bytes) || out_bytes != stub_size) {
return false;
}
const BYTE nop_pattern[sizeof(LPVOID)] = {0x0F, 0x1F, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00};
const BYTE nop_pattern[] = {0x0F, 0x1F, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00};
if (::memcmp(stub_buffer_orig, nop_pattern, sizeof(nop_pattern)) != 0) {
return false;
}
Expand Down Expand Up @@ -91,4 +94,5 @@ bool apply_ntdll_patch(HANDLE hProcess, LPVOID module_ptr)
return false;
}
return true;
#endif
}
2 changes: 1 addition & 1 deletion run_pe/patch_ntdll.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

#include <windows.h>

bool apply_ntdll_patch(HANDLE hProcess, LPVOID module_ptr);
bool apply_ntdll_patch64(HANDLE hProcess, LPVOID module_ptr);
2 changes: 1 addition & 1 deletion run_pe/run_pe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ bool _run_pe(BYTE *loaded_pe, size_t payloadImageSize, PROCESS_INFORMATION &pi,
std::cerr << "Redirecting failed!\n";
return false;
}
if (!is32bit && g_PatchRequired && !apply_ntdll_patch(pi.hProcess, remoteBase)) {
if (!is32bit && g_PatchRequired && !apply_ntdll_patch64(pi.hProcess, remoteBase)) {
std::cout << "ERROR: failed to apply the required patch on NTDLL\n";
}
std::cout << "Resuming the process: " << std::dec << pi.dwProcessId << std::endl;
Expand Down

0 comments on commit 65b1772

Please sign in to comment.