From 1af7c15801095f76adfc9356ee703cf1693da34c Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Tue, 7 Jan 2025 15:34:11 +0100 Subject: Trace program program to not allocate memory over there (help TalosPrinciple2, probably other UE5 games too) --- src/custommem.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/custommem.c') diff --git a/src/custommem.c b/src/custommem.c index 1b8da942..43dd76f5 100644 --- a/src/custommem.c +++ b/src/custommem.c @@ -1624,6 +1624,9 @@ void allocProtection(uintptr_t addr, size_t size, uint32_t prot) // don't need to add precise tracking probably } +uintptr_t pbrk = 0; +uintptr_t old_brk = 0; +uintptr_t* cur_brk = NULL; void loadProtectionFromMap() { if(box64_mapclean) @@ -1640,6 +1643,8 @@ void loadProtectionFromMap() if(sscanf(buf, "%lx-%lx %c%c%c", &s, &e, &r, &w, &x)==5) { int prot = ((r=='r')?PROT_READ:0)|((w=='w')?PROT_WRITE:0)|((x=='x')?PROT_EXEC:0); allocProtection(s, e-s, prot); + if(!pbrk && strstr(buf, "[heap]")) + pbrk = s; if(s>0x7fff00000000LL) have48bits = 1; } @@ -1652,6 +1657,10 @@ void loadProtectionFromMap() else printf_log(LOG_INFO, "BOX64: Didn't detect 48bits of address space, considering it's 39bits\n"); } + if(!pbrk) { + printf_log(LOG_INFO, "BOX64: Warning, program break not found\n"); + if(cur_brk) pbrk = *cur_brk; // approximate is better than nothing + } fclose(f); box64_mapclean = 1; } @@ -1701,6 +1710,11 @@ int memExist(uintptr_t addr) void* find31bitBlockNearHint(void* hint_, size_t size, uintptr_t mask) { + // first, check if program break as changed + if(pbrk && cur_brk && *cur_brk!=old_brk) { + old_brk = *cur_brk; + setProtection(pbrk, old_brk-pbrk, PROT_READ|PROT_WRITE); + } uint32_t prot; uintptr_t hint = (uintptr_t)hint_; if(hint_