Skip to content

Commit

Permalink
Fix calls to FlushInstructionCache
Browse files Browse the repository at this point in the history
They now operate on the process' handle instead of the hmodule of the
main module.
  • Loading branch information
Sylmir committed Nov 16, 2024
1 parent 902273e commit 142b779
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions libzhl/ASMPatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ void ASMPatcher::FlatPatch(void* at, const char* with, size_t len, bool nopRest)
throw std::runtime_error("Parallel patching is not allowed");
}

FlushInstructionCache(GetModuleHandle(NULL), NULL, 0);
BOOL flushOk = FlushInstructionCache(GetCurrentProcess(), NULL, 0);
if (!flushOk) {
logger.Log("[CRITICAL] ASMPatcher::FlatPatch: FlushInstructionCache failed (%d)\n", GetLastError());
}
}

void* ASMPatcher::Patch(void* at, void* targetPage, const char* with, size_t len) {
Expand Down Expand Up @@ -197,7 +200,10 @@ void* ASMPatcher::Patch(void* at, void* targetPage, const char* with, size_t len
}

logger.Log("ASMPatcher::Patch: flushing instruction pipeline\n");
FlushInstructionCache(GetModuleHandle(NULL), NULL, 0);
BOOL flushOk = FlushInstructionCache(GetCurrentProcess(), NULL, 0);
if (!flushOk) {
logger.Log("[CRITICAL] ASMPatcher::Patch: FlushInstructionCache failed (%d)\n", GetLastError());
}

return targetPage;
}
Expand Down
2 changes: 1 addition & 1 deletion repentogon/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ static void FixLuaDump()
fprintf(stderr, "VirtualProtect error %d\n", GetLastError());
}

FlushInstructionCache(GetModuleHandle(NULL), NULL, 0);
FlushInstructionCache(GetCurrentProcess(), NULL, 0);
}
char REPENTOGON::stocktitle[256]="";
char REPENTOGON::moddedtitle[256] = "";
Expand Down

0 comments on commit 142b779

Please sign in to comment.