find.sh vtable CLASS: vtable slots from the exe's RTTI
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0a615743fc
commit
3e43a4ced2
3 files changed
+53
-1
No files matched your search
@@ -49,7 +49,8 @@ so parallel live calls work too. Set `DECOMP_TIMEOUT=secs` for big functions (de
|
|||||||
|
|
||||||
`find.sh` modes (run it without args to list them): `name REGEX`, `str REGEX` (strings and their users),
|
`find.sh` modes (run it without args to list them): `name REGEX`, `str REGEX` (strings and their users),
|
||||||
`strs FUNC` (strings a function uses), `code REGEX` (functions whose C matches, with hit counts),
|
`strs FUNC` (strings a function uses), `code REGEX` (functions whose C matches, with hit counts),
|
||||||
`callers X`, `callees X`, `npc TYPE`, `item ID`, `active ID [N]`, `player ID`, `enum REGEX`, `lua REGEX`, `field REGEX`, `val ADDR`.
|
`callers X`, `callees X`, `npc TYPE`, `item ID`, `active ID [N]`, `player ID`, `enum REGEX`, `lua REGEX`, `field REGEX`, `val ADDR`,
|
||||||
|
`vtable CLASS` (slots read from the exe's RTTI: the authoritative way to name Update/Render/Fire... of an Entity_* or Weapon_* class).
|
||||||
|
|
||||||
## Naming you will see
|
## Naming you will see
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
# lua REGEX Lua API bindings (class, member, target function or field+offset)
|
# lua REGEX Lua API bindings (class, member, target function or field+offset)
|
||||||
# val ADDR constant at DAT_ADDR as int/float/double/string (decompiler leaves floats as DAT_)
|
# val ADDR constant at DAT_ADDR as int/float/double/string (decompiler leaves floats as DAT_)
|
||||||
# field REGEX known struct field offsets (REPENTOGON zhl struct defs)
|
# field REGEX known struct field offsets (REPENTOGON zhl struct defs)
|
||||||
|
# vtable CLASS vtable slots of an RTTI class, read from the exe (e.g. Weapon_Knife, Entity_Player)
|
||||||
D="$(cd "$(dirname "$0")" && pwd)"; T="$D/dump"
|
D="$(cd "$(dirname "$0")" && pwd)"; T="$D/dump"
|
||||||
MODE="$1"; ARG="$2"
|
MODE="$1"; ARG="$2"
|
||||||
[ -z "$ARG" ] && { sed -n '2,17p' "$0"; exit 1; }
|
[ -z "$ARG" ] && { sed -n '2,17p' "$0"; exit 1; }
|
||||||
@@ -40,5 +41,6 @@ case "$MODE" in
|
|||||||
lua) grep -P -- "$ARG" "$T/lua_bindings.tsv" ;;
|
lua) grep -P -- "$ARG" "$T/lua_bindings.tsv" ;;
|
||||||
val) python3 -I "$D/scripts/read_value.py" "$D/bin/isaac-ng.exe" "${ARG#DAT_}" ;;
|
val) python3 -I "$D/scripts/read_value.py" "$D/bin/isaac-ng.exe" "${ARG#DAT_}" ;;
|
||||||
field) grep -P -- "$ARG" "$T/zhl_fields.tsv" ;;
|
field) grep -P -- "$ARG" "$T/zhl_fields.tsv" ;;
|
||||||
|
vtable) python3 -I "$D/scripts/vtable.py" "$D/bin/isaac-ng.exe" "$T/functions.tsv" "$ARG" "${3:-40}" ;;
|
||||||
*) sed -n '2,17p' "$0"; exit 1 ;;
|
*) sed -n '2,17p' "$0"; exit 1 ;;
|
||||||
esac
|
esac
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
# Prints the vtable slots of an MSVC RTTI class straight from the exe (TypeDescriptor -> CompleteObjectLocator -> vftable).
|
||||||
|
# Usage: vtable.py exe functions.tsv ClassName [maxslots]
|
||||||
|
import struct, sys, re
|
||||||
|
data = open(sys.argv[1], 'rb').read()
|
||||||
|
names = {}
|
||||||
|
for line in open(sys.argv[2]):
|
||||||
|
p = line.rstrip('\n').split('\t')
|
||||||
|
if len(p) >= 2: names[int(p[0], 16)] = p[1]
|
||||||
|
pe = struct.unpack_from('<I', data, 0x3c)[0]
|
||||||
|
optsz = struct.unpack_from('<H', data, pe + 20)[0]
|
||||||
|
base = struct.unpack_from('<I', data, pe + 52)[0]
|
||||||
|
secs = []
|
||||||
|
for i in range(struct.unpack_from('<H', data, pe + 6)[0]):
|
||||||
|
sva, rsz, raw = struct.unpack_from('<III', data, pe + 24 + optsz + 40 * i + 12)
|
||||||
|
secs.append((sva, rsz, raw))
|
||||||
|
def va2off(va):
|
||||||
|
rva = va - base
|
||||||
|
for sva, rsz, raw in secs:
|
||||||
|
if sva <= rva < sva + rsz: return raw + rva - sva
|
||||||
|
return None
|
||||||
|
def off2va(o):
|
||||||
|
for sva, rsz, raw in secs:
|
||||||
|
if raw <= o < raw + rsz: return base + sva + o - raw
|
||||||
|
return None
|
||||||
|
def u32(o): return struct.unpack_from('<I', data, o)[0]
|
||||||
|
cls = sys.argv[3]; maxslots = int(sys.argv[4]) if len(sys.argv) > 4 else 40
|
||||||
|
sig = ('.?AV' + cls + '@IsaacRepentancePlus@@').encode()
|
||||||
|
starts = [m.start() for m in re.finditer(re.escape(sig), data)]
|
||||||
|
if not starts: sig = ('.?AV' + cls + '@@').encode(); starts = [m.start() for m in re.finditer(re.escape(sig), data)]
|
||||||
|
for s in starts:
|
||||||
|
tdoff = s - 8 # TypeDescriptor: vfptr, spare, name
|
||||||
|
tdva = off2va(tdoff)
|
||||||
|
# find COLs referencing tdva at offset 12
|
||||||
|
key = struct.pack('<I', tdva)
|
||||||
|
for m in re.finditer(re.escape(key), data):
|
||||||
|
colo = m.start() - 12
|
||||||
|
if colo < 0 or u32(colo) != 0: continue # signature 0
|
||||||
|
if u32(colo + 4) != 0: continue # offset 0 only (primary vtable)
|
||||||
|
colva = off2va(colo)
|
||||||
|
if colva is None: continue
|
||||||
|
k2 = struct.pack('<I', colva)
|
||||||
|
for m2 in re.finditer(re.escape(k2), data):
|
||||||
|
vto = m2.start() + 4
|
||||||
|
vtva = off2va(vto)
|
||||||
|
print('%s vftable @ %08x' % (cls, vtva))
|
||||||
|
for i in range(maxslots):
|
||||||
|
f = u32(vto + 4 * i)
|
||||||
|
if va2off(f) is None or f < 0x401000 or f > 0xb20000: break
|
||||||
|
print(' %2d %08x %s' % (i, f, names.get(f, '?')))
|
||||||
Reference in new issue
Block a user