diff --git a/src/target/Windows32Target.cpp b/src/target/Windows32Target.cpp index 1436c0f..8b35dd5 100644 --- a/src/target/Windows32Target.cpp +++ b/src/target/Windows32Target.cpp @@ -1,7 +1,6 @@ #include "Windows32Target.hpp" #include -#include using namespace tulip::hook; @@ -53,9 +52,18 @@ Result<> Windows32Target::protectMemory(void* address, size_t size, uint32_t pro } Result<> Windows32Target::rawWriteMemory(void* destination, void const* source, size_t size) { - if (!WriteProcessMemory(GetCurrentProcess(), destination, source, size, nullptr)) { - return Err("Unable to write to memory"); + DWORD oldProtection; + + // protect memory to be writable + if (!VirtualProtect(destination, size, this->getWritableProtection(), &oldProtection)) { + return Err("Unable to protect memory"); } + + std::memcpy(destination, source, size); + + // restore old protection + VirtualProtect(destination, size, oldProtection, &oldProtection); + return Ok(); }