diff --git a/README.md b/README.md index ae2b17b..35f39e4 100644 --- a/README.md +++ b/README.md @@ -220,6 +220,8 @@ finding only in your scratch files or your final message. routines that take only the npc (they get typed `Entity_NPC *npc`), `NpcHelper::snake_name` for NPC helpers with other arguments, `Class::snake_name` otherwise. Then run `python3 -I scripts/apply_db.py db/names.tsv dump` (instant: renames it in the dump everywhere, including call sites and `npc_ai.tsv`). + For a virtual method, `./find.sh vtable CLASS` shows which slot it is; slot names are the most reliable evidence + there is (a short ZHL sig or ICF can put a name on the wrong function, a vtable slot cannot). 2. **A struct field** you have confirmed: add `Class0xOFFtype _nameevidence` to `db/fields.tsv`. **A local variable** in a function you have read closely: `functionlocal_2c0newName[C type]` in `db/locals.tsv`. Only when every use has the same role: MSVC reuses registers and stack slots (see the file header). diff --git a/db/names.tsv b/db/names.tsv index 6e0f8e7..d82a8e9 100644 --- a/db/names.tsv +++ b/db/names.tsv @@ -1362,3 +1362,40 @@ 00a0e270 Weapon_UmbilicalWhip::Fire vftable 0078dc20 Entity_Player::RenderShadowLayer vftable slot 6 00954cd0 Manager::Update main loop +# +# Vtable slots named from the base class layout REPENTOGON declares (python3 -I scripts/vtable.py bin/isaac-ng.exe dump/functions.tsv zhl_vtables.tsv) +006a7ee0 Entity_Dummy::Free vtable slot 0 of Entity_Dummy; slot name from Entity +006a7f20 Entity_Dummy::Init vtable slot 1 of Entity_Dummy; slot name from Entity +006a7f30 Entity_Dummy::Update vtable slot 3 of Entity_Dummy; slot name from Entity +006a7f80 Entity_Dummy::Render vtable slot 5 of Entity_Dummy; slot name from Entity +00754d60 Entity_Player::Free vtable slot 0 of Entity_Player; slot name from Entity +00757a40 Entity_Player::ClearReferences vtable slot 17 of Entity_Player; slot name from Entity +00757ab0 Entity_Player::CanShutDoors vtable slot 18 of Entity_Player; slot name from Entity +005ccc60 Entity_Text::Free vtable slot 0 of Entity_Text; slot name from Entity +005ccca0 Entity_Text::Init vtable slot 1 of Entity_Text; slot name from Entity +005ccd80 Entity_Text::Update vtable slot 3 of Entity_Text; slot name from Entity +005cd2e0 Entity_Text::Interpolate vtable slot 4 of Entity_Text; slot name from Entity +005ccfc0 Entity_Text::Render vtable slot 5 of Entity_Text; slot name from Entity +009f9880 Weapon_Bombs::Free vtable slot 0 of Weapon_Bombs; slot name from Weapon +009fa190 Weapon_Bombs::GetFocusEntity vtable slot 9 of Weapon_Bombs; slot name from Weapon +009fa1b0 Weapon_Bombs::GetMarkedTargetVariant vtable slot 12 of Weapon_Bombs; slot name from Weapon +009fef20 Weapon_Bone::TriggerNewRoom vtable slot 11 of Weapon_Bone; slot name from Weapon +009ff1a0 Weapon_Bone::CanTriggerCursedEyeTeleport vtable slot 14 of Weapon_Bone; slot name from Weapon +009ff210 Weapon_Bone::CanTriggerKidneyStone vtable slot 15 of Weapon_Bone; slot name from Weapon +009ff230 Weapon_Bone::CanOverrideForgottenThrow vtable slot 16 of Weapon_Bone; slot name from Weapon +00a036b0 Weapon_Deathmatch::GetMaxCharge vtable slot 6 of Weapon_Deathmatch; slot name from Weapon +00a03f60 Weapon_Fetus::GetMaxCharge vtable slot 6 of Weapon_Fetus; slot name from Weapon +009f99b0 Weapon_Knife::Free vtable slot 0 of Weapon_Knife; slot name from Weapon +00a05060 Weapon_Knife::SupportsTractorBeam vtable slot 13 of Weapon_Knife; slot name from Weapon +009f9930 Weapon_Laser::Free vtable slot 0 of Weapon_Laser; slot name from Weapon +00a068e0 Weapon_Laser::CanTriggerCursedEyeTeleport vtable slot 14 of Weapon_Laser; slot name from Weapon +00a099a0 Weapon_Rockets::GetMarkedTargetVariant vtable slot 12 of Weapon_Rockets; slot name from Weapon +00a0a6f0 Weapon_SpiritSword::Reset vtable slot 4 of Weapon_SpiritSword; slot name from Weapon +00a0a700 Weapon_SpiritSword::GetMaxCharge vtable slot 6 of Weapon_SpiritSword; slot name from Weapon +009f9900 Weapon_Tears::Free vtable slot 0 of Weapon_Tears; slot name from Weapon +00a0d950 Weapon_Tears::CanTriggerCursedEyeTeleport vtable slot 14 of Weapon_Tears; slot name from Weapon +00a0e260 Weapon_TechX::GetMaxCharge vtable slot 6 of Weapon_TechX; slot name from Weapon +009f97e0 Weapon_UrnOfSouls::Free vtable slot 0 of Weapon_UrnOfSouls; slot name from Weapon +00a0f410 Weapon_UrnOfSouls::Reset vtable slot 4 of Weapon_UrnOfSouls; slot name from Weapon +00a0f420 Weapon_UrnOfSouls::ClearReferences vtable slot 5 of Weapon_UrnOfSouls; slot name from Weapon +009f3170 Weapon_UrnOfSouls::GetMainEntity vtable slot 10 of Weapon_UrnOfSouls; slot name from Weapon diff --git a/find.sh b/find.sh index 3fcda20..2d2045a 100755 --- a/find.sh +++ b/find.sh @@ -41,6 +41,6 @@ case "$MODE" in lua) grep -P -- "$ARG" "$T/lua_bindings.tsv" ;; val) python3 -I "$D/scripts/read_value.py" "$D/bin/isaac-ng.exe" "${ARG#DAT_}" ;; 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}" ;; + vtable) python3 -I "$D/scripts/vtable.py" "$D/bin/isaac-ng.exe" "$T/functions.tsv" "$D/zhl_vtables.tsv" "$ARG" "${3:-60}" ;; *) sed -n '2,17p' "$0"; exit 1 ;; esac diff --git a/scripts/vtable.py b/scripts/vtable.py index 37ab8aa..5b83197 100644 --- a/scripts/vtable.py +++ b/scripts/vtable.py @@ -1,49 +1,59 @@ -# 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(' CompleteObjectLocator -> vftable, bases from the +# ClassHierarchyDescriptor). Usage: +# vtable.py exe functions.tsv zhl_vtables.tsv CLASS [maxslots] print CLASS's slots with their current names +# vtable.py exe functions.tsv zhl_vtables.tsv names.tsv lines for still-FUN_ slots whose slot name a base +# class declares in REPENTOGON (zhl_vtables.tsv) +import struct, sys, re, collections +exe, fns_path, zv_path = sys.argv[1:4] +data = open(exe, 'rb').read() +names = {int(p[0], 16): p[1] for p in (l.rstrip('\n').split('\t') for l in open(fns_path)) if len(p) >= 2} +zv = collections.defaultdict(dict) +for l in open(zv_path): + c, s, n = l.rstrip('\n').split('\t'); zv[c][int(s)] = n +pe = struct.unpack_from(' 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(' 0xb20000: break - print(' %2d %08x %s' % (i, f, names.get(f, '?'))) +u32 = lambda o: struct.unpack_from(' (vtable offset, bases list nearest first) +for m in re.finditer(rb'\.\?AV[\w@]+?@@\x00', data): + tdva = off2va(m.start() - 8); cls = tdname(tdva) + if not cls or cls in vt: continue + for k in re.finditer(re.escape(struct.pack(' 200: return out + out.append(f) +if len(sys.argv) > 4: + for cls in [c for c in vt if c == sys.argv[4] or c.endswith('::' + sys.argv[4])]: + print(f'{cls} vftable @ {off2va(vt[cls][0]):08x}, bases: {", ".join(vt[cls][1]) or "-"}') + for i, f in enumerate(slots(cls)[:int(sys.argv[5]) if len(sys.argv) > 5 else 60]): print(f' {i:2d} {f:08x} {names.get(f, "?")}') + sys.exit() +seen = set() +for cls, (o, bases) in sorted(vt.items()): + for i, f in enumerate(slots(cls)): + if not names.get(f, '').startswith('FUN_') or f in seen: continue + for b in [cls] + bases: + nm = zv.get(b, {}).get(i) # REPENTOGON's declared layout only: names on base stubs are often ICF-folded + if nm: + print(f'{f:08x}\t{cls}::{nm}\tvtable slot {i} of {cls}; slot name from {b}'); seen.add(f); break