source_tree: db/fields.tsv (and --fields files) overlay the build's field list, so a new field needs no Ghidra rebuild
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4badd39376
commit
832ea0297b
1 file changed
+7
-2
@@ -8,11 +8,14 @@
|
|||||||
# Targets 64-bit Linux. The original 32-bit layout is kept as LAYOUT32 asserts, checked with -m32.
|
# 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
|
# --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).
|
# (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
|
import collections, concurrent.futures, os, re, subprocess, sys
|
||||||
|
|
||||||
outDir, classesPath, dumpDir, zhlVtablesPath = sys.argv[1:5]
|
outDir, classesPath, dumpDir, zhlVtablesPath = sys.argv[1:5]
|
||||||
isCheck = '--check' in sys.argv
|
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<ret>.+?)\s*\b(?:(?P<cc>__thiscall|__fastcall|__cdecl|__stdcall)\s+)?(?P<name>[\w:~]+)\((?P<params>.*)\)\s*$')
|
CALLING = re.compile(r'^(?P<ret>.+?)\s*\b(?:(?P<cc>__thiscall|__fastcall|__cdecl|__stdcall)\s+)?(?P<name>[\w:~]+)\((?P<params>.*)\)\s*$')
|
||||||
POINTER_LIKE = {'EntityPtr'} # REPENTOGON's smart pointer, a raw Entity * in the decompiled code
|
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
|
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():
|
def fields_load():
|
||||||
fields, bases, sizes = collections.defaultdict(dict), {}, {}
|
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')
|
cols = line.rstrip('\n').split('\t')
|
||||||
if line.startswith('#') or len(cols) < 3: continue
|
if line.startswith('#') or len(cols) < 3: continue
|
||||||
if cols[1] == 'base': bases[cols[0]] = cols[2]; 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[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()
|
decl = cols[2].replace('const ', '').strip()
|
||||||
count = re.search(r'\[(\w+)\]\s*$', decl)
|
count = re.search(r'\[(\w+)\]\s*$', decl)
|
||||||
if count: decl = decl[:count.start()]
|
if count: decl = decl[:count.start()]
|
||||||
|
|||||||
Reference in new issue
Block a user