leakhunt/tools/peek_addr.py
acbot 57b5e43d0e Initial commit — leak-hunt project complete
Five bugs identified and patched in retail Asheron's Call client:
- v3b: palette refcount over-increment (3-byte NOP at two sites)
- v5: RenderSurface PurgeResource no-op stub (vtable slot 2 thunk)
- v11: two dangling-pointer crash guards (NULL-check + reorder)
- v14: CEnvCell::Destroy ClipPlaneList leak (18-byte JMP to cleanup thunk)
- v22: unpacker stale-pointer SEH guard (whole-function __try/__except)

All five ship in leakfix.dll (117 KB, SHA d282f23c…) which is loaded
by acclient.exe at process start via PE import table patching by
tools/install_leakfix.py.

Controlled 15-client fleet soak: unpatched control died at 26h with
palette exhaustion; all 14 patched clients survived past that point
and reached ≥5-day uptime.

Residual ~15 MB/h growth traced to d3d9.dll's internal slab allocator
(260KB surface backing buffers retained after Release). See REPORT.md
§10 for the full investigation; conclusion is that it's unfixable from
outside d3d9.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-23 21:07:58 +02:00

33 lines
1.8 KiB
Python

"""peek_addr.py <pid> <va> [n=16]
Read n bytes at va from a live process. Print as hex + try to interpret prologue."""
import ctypes, ctypes.wintypes as wt, sys
PROCESS_VM_READ = 0x10
PROCESS_QUERY_INFORMATION = 0x400
k = ctypes.windll.kernel32
k.OpenProcess.argtypes = [wt.DWORD, wt.BOOL, wt.DWORD]; k.OpenProcess.restype = wt.HANDLE
k.CloseHandle.argtypes = [wt.HANDLE]; k.CloseHandle.restype = wt.BOOL
k.ReadProcessMemory.argtypes = [wt.HANDLE, wt.LPCVOID, wt.LPVOID, ctypes.c_size_t, ctypes.POINTER(ctypes.c_size_t)]
k.ReadProcessMemory.restype = wt.BOOL
pid = int(sys.argv[1]); va = int(sys.argv[2], 0); n = int(sys.argv[3]) if len(sys.argv) > 3 else 16
h = k.OpenProcess(PROCESS_VM_READ|PROCESS_QUERY_INFORMATION, False, pid)
if not h: print(f"OpenProcess err={ctypes.get_last_error()}"); sys.exit(2)
buf = (ctypes.c_ubyte * n)(); sz = ctypes.c_size_t(0)
if not k.ReadProcessMemory(h, va, buf, n, ctypes.byref(sz)):
print(f"ReadProcessMemory @ 0x{va:08x} err={ctypes.get_last_error()}"); sys.exit(3)
data = bytes(buf[:sz.value])
print(f"@ 0x{va:08x}: {data.hex(' ')}")
# rough heuristics
hints = []
if data[:1] == b'\x55': hints.append("push ebp (typical prologue)")
if data[:1] == b'\x56': hints.append("push esi (thiscall this->esi prologue)")
if data[:1] == b'\x53': hints.append("push ebx (prologue start)")
if data[:1] == b'\x8b': hints.append("mov reg, ... (could be prologue or middle)")
if data[:1] == b'\x83': hints.append("sub/add esp, imm8 (stack alloc, prologue)")
if data[:3] == b'\xb0\x01\xc3': hints.append("mov al,1; ret (no-op stub)")
if data[:3] == b'\xb0\x00\xc3': hints.append("mov al,0; ret")
if data[:1] == b'\xc3': hints.append("bare ret")
if data[:2] == b'\x90\x90': hints.append("NOP pad (real code likely after)")
if hints: print(" -> " + "; ".join(hints))
k.CloseHandle(h)