Skip to content

Commit 1cb5e7b

Browse files
authored
Fix invalid call to VirtualProtect (#27)
* Fix invalid call to VirtualProtect VirtualProtect fails if fourth argument is NULL, see: https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-virtualprotect On some versions of wine this leads to null pointer dereference and crash. * Call FlushInstructionCache after patching
1 parent a39f2e2 commit 1cb5e7b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/Utilities/Patch.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ void Patch::Apply()
6161
DWORD protect_flag;
6262
VirtualProtect(pAddress, this->size, PAGE_EXECUTE_READWRITE, &protect_flag);
6363
memcpy(pAddress, this->pData, this->size);
64-
VirtualProtect(pAddress, this->size, protect_flag, NULL);
64+
VirtualProtect(pAddress, this->size, protect_flag, &protect_flag);
65+
// NOTE: Instruction cache flush isn't required on x86. This is just to conform with Win32 API docs.
66+
FlushInstructionCache(GetCurrentProcess(), pAddress, this->size);
6567
}
6668

6769
void Patch::Apply_LJMP(DWORD offset, DWORD pointer)

0 commit comments

Comments
 (0)