Ghidra 12.2 project and full dump of isaac-ng.exe v1.9.7.17, query scripts, notes indexed by entity, anm2/rooms reimplementations, and db/ (names + fields) that build.sh re-applies. Fixes awk numeric address comparison in find.sh/decompile.sh. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
22 lines
1.4 KiB
Python
22 lines
1.4 KiB
Python
# Applies db/names.tsv to the dump in place (no Ghidra): headers, call sites, functions.tsv, strings.tsv, npc_ai.tsv.
|
|
# Only names change; types/fields need build.sh --db. Safe to re-run. Usage: apply_db.py names.tsv dumpdir
|
|
import re, sys
|
|
db, d = sys.argv[1:3]
|
|
fns = dict(l.rstrip('\n').split('\t')[:2] for l in open(f'{d}/functions.tsv'))
|
|
ren = {}
|
|
for l in open(db):
|
|
if l.strip() and not l.startswith('#'):
|
|
a, new = l.rstrip('\n').split('\t')[:2]
|
|
if a in fns and list(fns.values()).count(fns[a]) == 1: ren[a] = (fns[a], new)
|
|
# FUN_<addr> is unique; a qualified old name is replaced only where it is a whole token
|
|
# (strings.tsv and npc_ai.tsv list users as addr:name, rewritten by address)
|
|
old2new = {o: n for o, n in ren.values() if o != n}
|
|
pat = re.compile(r'(?<!\w)(?<!::)(' + '|'.join(sorted(map(re.escape, old2new), key=len, reverse=True)) + r')(?![\w:])')
|
|
users = re.compile(r'\b(' + '|'.join(ren) + r'):[^\s]+')
|
|
def fix(s): return users.sub(lambda m: m.group(1) + ':' + ren[m.group(1)][1], pat.sub(lambda m: old2new[m.group(1)], s) if old2new else s)
|
|
for f in ('all.c', 'strings.tsv', 'npc_ai.tsv'):
|
|
p = f'{d}/{f}'; s = open(p).read(); open(p, 'w').write(fix(s))
|
|
rows = [l.split('\t', 2) for l in open(f'{d}/functions.tsv')]
|
|
open(f'{d}/functions.tsv', 'w').writelines(f'{a}\t{ren[a][1] if a in ren else n}\t{r}' for a, n, r in rows)
|
|
print(f'apply_db: {len(ren)} renamed')
|