MCPcopy Create free account
hub / github.com/OpenSteam001/OpenSteamTool / WriteExecutableByte

Function WriteExecutableByte

src/OSTPlatform/Windows/Memory.cpp:23–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21}
22
23bool WriteExecutableByte(void* target, uint8_t value) {
24 if (!target) {
25 OSTP_LOG_WARN("WriteExecutableByte: target is null");
26 return false;
27 }
28
29 DWORD oldProtect = 0;
30 if (!VirtualProtect(target, 1, PAGE_EXECUTE_READWRITE, &oldProtect)) {
31 OSTP_LOG_WARN("WriteExecutableByte(target={}) VirtualProtect(RWX) failed (error={})",
32 target, GetLastError());
33 return false;
34 }
35 *static_cast<uint8_t*>(target) = value;
36
37 DWORD ignored = 0;
38 if (!VirtualProtect(target, 1, oldProtect, &ignored)) {
39 OSTP_LOG_WARN("WriteExecutableByte(target={}) VirtualProtect(restore=0x{:X}) failed (error={})",
40 target, oldProtect, GetLastError());
41 return false;
42 }
43 if (!FlushInstructionCache(GetCurrentProcess(), target, 1)) {
44 OSTP_LOG_WARN("WriteExecutableByte(target={}) FlushInstructionCache failed (error={})",
45 target, GetLastError());
46 return false;
47 }
48 return true;
49}
50
51} // namespace OSTPlatform::Memory

Callers 2

ArmInt3Function · 0.85
RestoreByteFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected