Skip to content

Commit

Permalink
fix: fix declaration of vquery.
Browse files Browse the repository at this point in the history
  • Loading branch information
Redbeanw44602 committed Aug 22, 2024
1 parent fd1574a commit 5bd3970
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/ll/api/memory/Memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
9 changes: 5 additions & 4 deletions src/ll/api/memory/linux/Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ FuncPtr resolveSignature(std::string_view signature, std::span<std::byte> range)
}

void modify(void* ptr, size_t len, const std::function<void()>& 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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/ll/api/memory/win/Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 5bd3970

Please sign in to comment.