Implement source-backed Scooter vehicle in tutorial and outside
This commit is contained in:
1 parent
8df5e81070
commit
62c07a3d59
44 files changed
+3135
-174
No files matched your search
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Guarded Scooter drive/input source and copied-code probe preparation."""
|
||||
import argparse,hashlib,json,re,struct,subprocess
|
||||
from pathlib import Path
|
||||
from scooter import collect as scooter_collect
|
||||
from checkpoint_script_state import find_case,read_va
|
||||
from pe_inspect import PE
|
||||
|
||||
RANGES=((0x421910,0x421ba4),(0x467000,0x467045),(0x4669f0,0x466aea),(0x458890,0x458a00),(0x473320,0x47353a),(0x465220,0x46582d),(0x465830,0x465dfe),(0x421c10,0x421cf7),
|
||||
(0x476ff0,0x477490),(0x4723f0,0x472420),(0x472480,0x472570),(0x472b10,0x472c10))
|
||||
EVIDENCE_RANGES=RANGES+((0x467080,0x4679c0),(0x468020,0x468300),
|
||||
(0x412f90,0x413030),(0x466af0,0x466b30),(0x425120,0x425170),
|
||||
(0x41e0f9,0x41e1f8),(0x41e2f0,0x41e3a0),(0x408e40,0x409010))
|
||||
def collect(original):
|
||||
report=scooter_collect(original);pe=PE(find_case(Path(original),'Neutron.exe'))
|
||||
# Only absolute data/IAT references found in decoded disassembly are eligible.
|
||||
targets=set()
|
||||
for start,end in RANGES:
|
||||
result=subprocess.run(['objdump','-d','-Mintel',f'--start-address={start}',f'--stop-address={end}',str(pe.path)],capture_output=True,text=True,check=True)
|
||||
targets.update(int(v,16) for v in re.findall(r'ds:0x([0-9a-f]+)',result.stdout))
|
||||
targets.update((0x48d104,0x48d10c))
|
||||
report['motion_ranges']=[dict(va=hex(start),file_offset=hex(pe.offset(start-pe.base)),length=end-start,
|
||||
sha256=hashlib.sha256(read_va(pe,start,end-start)).hexdigest()) for start,end in EVIDENCE_RANGES]
|
||||
report['motion_relocations']=[]
|
||||
for start,end in RANGES:
|
||||
data=read_va(pe,start,end-start)
|
||||
for target in sorted(targets):
|
||||
for match in re.finditer(re.escape(struct.pack('<I',target)),data):
|
||||
report['motion_relocations'].append(dict(va=start+match.start(),target=target))
|
||||
report['motion_constants']={hex(va):struct.unpack('<d' if wide else '<f',read_va(pe,va,8 if wide else 4))[0]
|
||||
for va,wide in [(0x4d5888,False),(0x48d948,False),(0x49b1f8,False),(0x49fac0,False),(0x4d5880,True),
|
||||
(0x4d5878,False),(0x4d5870,True),(0x4a3144,False)]}
|
||||
return report
|
||||
|
||||
def generate(original,output):
|
||||
output=Path(output).resolve();original=Path(original).resolve()
|
||||
if output.is_relative_to(original) or original.is_relative_to(output):raise ValueError('Separate output required')
|
||||
output.mkdir(parents=True,exist_ok=True);report=collect(original)
|
||||
body=(Path(__file__).with_name('scooter_motion_probe.c')).read_text()
|
||||
body=body.replace('/* RELOCATIONS */',','.join('{0x%x,0x%x}'%(r['va'],r['target']) for r in report['motion_relocations']))
|
||||
(output/'scooter_motion_probe.c').write_text(body)
|
||||
(output/'source.json').write_text(json.dumps(report,indent=2)+'\n');return report
|
||||
if __name__=='__main__':
|
||||
p=argparse.ArgumentParser();p.add_argument('original',type=Path);p.add_argument('--generate-probe',type=Path);a=p.parse_args()
|
||||
r=generate(a.original,a.generate_probe) if a.generate_probe else collect(a.original)
|
||||
print(json.dumps(r,indent=2))
|
||||
Reference in new issue
Block a user