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>
This commit is contained in:
acbot 2026-05-23 21:05:17 +02:00
commit 57b5e43d0e
199 changed files with 1648333 additions and 0 deletions

View file

@ -0,0 +1,81 @@
"""list_image_modules.py <pid>
Enumerate all MEM_IMAGE allocation bases. For each, read the PE export
table to grab the module name. List with sizes."""
import ctypes, ctypes.wintypes as wt, sys, struct
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.ReadProcessMemory.argtypes = [wt.HANDLE, wt.LPCVOID, wt.LPVOID, ctypes.c_size_t, ctypes.POINTER(ctypes.c_size_t)]
k.ReadProcessMemory.restype = wt.BOOL
k.VirtualQueryEx.argtypes = [wt.HANDLE, wt.LPCVOID, ctypes.c_void_p, ctypes.c_size_t]
k.VirtualQueryEx.restype = ctypes.c_size_t
class MBI(ctypes.Structure):
_fields_ = [("BaseAddress", ctypes.c_void_p), ("AllocationBase", ctypes.c_void_p),
("AllocationProtect", wt.DWORD), ("RegionSize", ctypes.c_size_t),
("State", wt.DWORD), ("Protect", wt.DWORD), ("Type", wt.DWORD)]
def rd(h, va, n):
buf = (ctypes.c_ubyte * n)(); sz = ctypes.c_size_t(0)
if not k.ReadProcessMemory(h, va, buf, n, ctypes.byref(sz)): return None
return bytes(buf[:sz.value])
def get_module_name(h, base):
"""Read PE export name from the module."""
hdr = rd(h, base + 0x3C, 4)
if not hdr or len(hdr) != 4: return None
pe_off = struct.unpack('<I', hdr)[0]
if pe_off > 0x1000: return None
# Read optional header, find export directory
opt_off = base + pe_off + 4 + 20
# Export RVA at opt_off + 96 (for PE32)
expdir_b = rd(h, opt_off + 96, 8)
if not expdir_b: return None
exp_rva, exp_size = struct.unpack('<II', expdir_b)
if not exp_rva or exp_size < 12: return None
# Read first 64 bytes of export dir; Name RVA is at offset 12
exp = rd(h, base + exp_rva, 64)
if not exp or len(exp) < 16: return None
name_rva = struct.unpack_from('<I', exp, 12)[0]
name_bytes = rd(h, base + name_rva, 64)
if not name_bytes: return None
n = name_bytes.split(b'\x00', 1)[0]
return n.decode(errors='replace')
pid = int(sys.argv[1])
h = k.OpenProcess(PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, False, pid)
if not h: print("OpenProcess fail"); sys.exit(2)
seen = {}
mbi = MBI()
addr = 0
while k.VirtualQueryEx(h, addr, ctypes.byref(mbi), ctypes.sizeof(mbi)):
base = mbi.BaseAddress or 0
sz = mbi.RegionSize
if mbi.State == 0x1000 and mbi.Type == 0x1000000:
ab = mbi.AllocationBase or 0
if ab not in seen:
# Read SizeOfImage
hdr = rd(h, ab + 0x3C, 4)
img_size = 0
if hdr:
pe_off = struct.unpack('<I', hdr)[0]
sz_b = rd(h, ab + pe_off + 4 + 20 + 56, 4)
if sz_b:
img_size = struct.unpack('<I', sz_b)[0]
name = get_module_name(h, ab) or "?"
seen[ab] = (name, img_size)
next_addr = base + sz
if next_addr <= addr: break
addr = next_addr
if addr >= 0x80000000: break
k.CloseHandle(h)
print(f"{len(seen)} image bases found:")
print(f" {'base':>10} {'size':>9} name")
for ab in sorted(seen):
name, sz = seen[ab]
print(f" 0x{ab:08x} {sz:>9} {name}")