mirror of
https://github.com/elliotnunn/tbxi-patches.git
synced 2024-05-28 14:41:26 +00:00
Allow for multiple code sections when finding glue
This commit is contained in:
parent
491e85d8a8
commit
610ec9c8d9
19
cfmtool.py
19
cfmtool.py
|
@ -251,7 +251,7 @@ def repr(obj):
|
|||
return accum
|
||||
|
||||
elif isinstance(obj, dict):
|
||||
if set(obj) in (set(('kind', 'weakFlag', 'name')), set(('section', 'offset', 'to'))):
|
||||
if set(obj) in (set(('kind', 'weakFlag', 'name')), set(('section', 'offset', 'to')), set(('file', 'offset', 'function'))):
|
||||
oneline = True
|
||||
else:
|
||||
oneline = False
|
||||
|
@ -549,7 +549,14 @@ def dump_locations(from_path, to_path):
|
|||
"""Create some useful files: glue.txt
|
||||
"""
|
||||
|
||||
with open(path.join(from_path, 'code'), 'rb') as f: code = f.read()
|
||||
with open(path.join(from_path, 'sections.txt')) as f: section_list = eval(f.read())
|
||||
|
||||
gluelocs = []
|
||||
|
||||
for idx, sec in enumerate(section_list):
|
||||
if sec['sectionKind'] != 'code': continue
|
||||
|
||||
with open(path.join(from_path, sec['filename']), 'rb') as f: code = f.read()
|
||||
|
||||
gluescan = []
|
||||
for i in range(0, len(code) - 24, 4):
|
||||
|
@ -566,19 +573,17 @@ def dump_locations(from_path, to_path):
|
|||
|
||||
toc_vectors = {}
|
||||
for rel in relocs:
|
||||
if rel['section'] == 1 and rel['to'][0] == 'import':
|
||||
if 'data' in section_list[rel['section']]['sectionKind'] and rel['to'][0] == 'import':
|
||||
toc_vectors[rel['offset']] = imports[rel['to'][1]]
|
||||
|
||||
gluelocs = []
|
||||
for code_ofs, toc_ofs in gluescan:
|
||||
try:
|
||||
gluelocs.append((code_ofs, toc_vectors[toc_ofs]))
|
||||
gluelocs.append(dict(file=sec['filename'], offset=code_ofs, function=toc_vectors[toc_ofs]))
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
gluelocs.sort()
|
||||
|
||||
# Okay, let's do a nasty cross-referencing job!
|
||||
gluelocs.sort(key=lambda dct: tuple(dct.values()))
|
||||
|
||||
to_path = path.join(to_path, 'locations')
|
||||
os.makedirs(to_path, exist_ok=True)
|
||||
|
|
Loading…
Reference in New Issue
Block a user