#!/usr/bin/env python3 """Enumerate FIFA 17's resident item map authoritatively. Layout recovered from the lower_bound at 0x180119640: owner+0x160c8 sentinel / end marker owner+0x160d8 root owner+0x160e8 count node+0x00, node+0x08 children node+0x20 key = wire instance id (qword) node+0x28 the item record On miss the client returns the static sentinel 0x1802c2a28 whose +0x10 is NULL. Read-only. usage: probe_map2.py PID [id ...] """ import re, struct, sys, collections PID = int(sys.argv[1]); WANT = {int(a) for a in sys.argv[2:]} mem = open(f"/proc/{PID}/mem", "rb", buffering=0) def rd(a, n): mem.seek(a); return mem.read(n) def q(a): return struct.unpack(" 5000: continue seen.add(n) try: h = rd(n, 0x30) except OSError: continue if len(h) < 0x30: continue nodes.append(n) stack.append(struct.unpack_from("11} {'record':>12} {'id':>10} {'resource':>10} {'ct':>3} {'sub':>4} {'st':>4} {'cat':>4}") hist = collections.Counter(); found = {} rows = [] for n in nodes: key = q(n + 0x20) rec = n + 0x28 try: r = rd(rec, 0x180) except OSError: continue if len(r) < 0x180: continue g = lambda o: struct.unpack_from("11} {rec:#12x} {rid:>10} {res:>10} {ct:>3} {sub:>4} {st:>4} {cat:>4}{tag}") print(f"\n cardtype histogram: {dict(sorted(hist.items()))} total={sum(hist.values())}") for w in sorted(WANT): print(f" id {w}: {'RESIDENT' if w in found else 'ABSENT'}")