diff --git a/scripts/source_tree.py b/scripts/source_tree.py index d63ad29..541b6d9 100644 --- a/scripts/source_tree.py +++ b/scripts/source_tree.py @@ -8,11 +8,14 @@ # Targets 64-bit Linux. The original 32-bit layout is kept as LAYOUT32 asserts, checked with -m32. # --check compiles every .cpp for x86_64, reports how many methods compile and how many raw offset accesses remain # (each one is a 64-bit hazard until it becomes a named field). -# Usage: source_tree.py out_dir classes.tsv dump_dir zhl_vtables.tsv [--check] +# Fields come from the build's merged list with db/fields.tsv (and any --fields file) on top, so a field added there +# shows up in classes.h without a Ghidra rebuild. +# Usage: source_tree.py out_dir classes.tsv dump_dir zhl_vtables.tsv [--check] [--fields extra.tsv ...] import collections, concurrent.futures, os, re, subprocess, sys outDir, classesPath, dumpDir, zhlVtablesPath = sys.argv[1:5] isCheck = '--check' in sys.argv +overlayPaths = [sys.argv[i + 1] for i, arg in enumerate(sys.argv) if arg == '--fields'] # more field rows, after db/fields.tsv CALLING = re.compile(r'^(?P.+?)\s*\b(?:(?P__thiscall|__fastcall|__cdecl|__stdcall)\s+)?(?P[\w:~]+)\((?P.*)\)\s*$') POINTER_LIKE = {'EntityPtr'} # REPENTOGON's smart pointer, a raw Entity * in the decompiled code LIBRARY = re.compile(r'^(std|rapidxml|theoraplayer|luabridge|stb_vorbis|Concurrency)(::|$)') # third party: declared, not reconstructed @@ -106,11 +109,13 @@ def container_name(typ): # vector_DamageEvent -> std_vector: the MSVC layouts def fields_load(): fields, bases, sizes = collections.defaultdict(dict), {}, {} - for line in open(dumpDir + '/zhl_fields.tsv'): + overlays = [os.path.join(os.path.dirname(os.path.abspath(dumpDir)), 'db', 'fields.tsv')] + overlayPaths + for line in [l for path in [dumpDir + '/zhl_fields.tsv'] + overlays if os.path.exists(path) for l in open(path)]: cols = line.rstrip('\n').split('\t') if line.startswith('#') or len(cols) < 3: continue if cols[1] == 'base': bases[cols[0]] = cols[2]; continue if cols[1] == 'size': sizes[cols[0]] = int(cols[2], 0); continue + if cols[2].startswith('- '): fields[cols[0]].pop(int(cols[1], 16), None); continue # a deleted wrong field decl = cols[2].replace('const ', '').strip() count = re.search(r'\[(\w+)\]\s*$', decl) if count: decl = decl[:count.start()]