diff --git a/src/ll/api/memory/Memory.h b/src/ll/api/memory/Memory.h index 770f7708c..4fb47779b 100644 --- a/src/ll/api/memory/Memory.h +++ b/src/ll/api/memory/Memory.h @@ -199,7 +199,7 @@ enum ProtectionFlag { }; LLAPI void* vallocate(size_t size, unsigned flag); -LLAPI unsigned vquery(void* address, size_t size); +LLAPI unsigned vquery(void* address); LLAPI bool vprotect(void* address, size_t size, unsigned flag); LLAPI bool vfree(void* address, size_t size); diff --git a/src/ll/api/memory/linux/Memory.cpp b/src/ll/api/memory/linux/Memory.cpp index 52ce5f77d..e58c15cb1 100644 --- a/src/ll/api/memory/linux/Memory.cpp +++ b/src/ll/api/memory/linux/Memory.cpp @@ -13,9 +13,10 @@ FuncPtr resolveSignature(std::string_view signature, std::span range) } void modify(void* ptr, size_t len, const std::function& callback) { - // VirtualProtect(ptr, len, PAGE_EXECUTE_READWRITE, &oldProtect); + auto oldProtect = vquery(ptr); + vprotect(ptr, len, MF_READ | MF_WRITE | MF_EXEC); callback(); - // VirtualProtect(ptr, len, oldProtect, &oldProtect); + vprotect(ptr, len, oldProtect); } static int getPosixProtectionFlag(unsigned flags) { @@ -49,7 +50,7 @@ static int getPosixProtectionFlag(unsigned flags) { return PROT_NONE; } -void* vallocate(size_t size, ProtectionFlag flag) { +void* vallocate(size_t size, unsigned flag) { if (size == 0) return nullptr; // On platforms that have it, we can use MAP_ANON to get a memory-mapped @@ -135,7 +136,7 @@ unsigned vquery(void* address) { return 0; } -bool vprotect(void* address, size_t size, ProtectionFlag flag) { +bool vprotect(void* address, size_t size, unsigned flag) { if (address == nullptr || size == 0 || !flag) return false; int protectFlag = getPosixProtectionFlag(flag); diff --git a/src/ll/api/memory/win/Memory.cpp b/src/ll/api/memory/win/Memory.cpp index 26dc817c2..fce6a0691 100644 --- a/src/ll/api/memory/win/Memory.cpp +++ b/src/ll/api/memory/win/Memory.cpp @@ -66,7 +66,7 @@ static DWORD getWindowsProtectionFlags(unsigned Flags) { return PAGE_NOACCESS; } -void* vallocate(size_t size, ProtectionFlag flag) { +void* vallocate(size_t size, unsigned flag) { if (size == 0) return nullptr; DWORD allocFlag = MEM_RESERVE | MEM_COMMIT; @@ -83,7 +83,7 @@ unsigned vquery(void* address) { return info.Protect; } -bool vprotect(void* address, size_t size, ProtectionFlag flag) { +bool vprotect(void* address, size_t size, unsigned flag) { if (!address || size == 0) return false; DWORD protectFlag = getWindowsProtectionFlags(flag);