#!/usr/bin/env python3 """Original complete020153 instructions; inspect actual native constructor calls. Private Unicorn memory only. External queries/diagnostics/MMIO are recorders. """ from pathlib import Path from _binary_path import resolve_580_binary import argparse,hashlib,json,struct,warnings warnings.filterwarnings('ignore',category=UserWarning,module='unicorn') from elftools.elf.elffile import ELFFile from unicorn import Uc,UC_ARCH_X86,UC_MODE_64,UC_HOOK_CODE from unicorn.x86_const import * p=argparse.ArgumentParser();p.add_argument('--check',action='store_true');p.add_argument('--dump-private-images');options=p.parse_args() R=Path(__file__).resolve().parents[1];P=resolve_580_binary(verify=True) TEXT=0x10000000;RO=0x18000000;DATA=0x24000000;STACK=0x40000000;STUB=0x50000000;STOP=0x60000000 meta=json.loads((R/'reports/gpu-clock-object-metadata.json').read_text()) names=['_nv020155rm','_nv029329rm','_nv020198rm','_nv021074rm','_nv021109rm','_nv021101rm','_nv020153rm','_nv020711rm','_nv020712rm','_nv020418rm','_nv045098rm']+['_nv'+name+'rm' for name in meta['deactivation_method_offsets']] with P.open('rb') as f: e=ELFFile(f);symbols=list(e.get_section_by_name('.symtab').iter_symbols());defined={s.name:s for s in symbols};text=bytearray(e.get_section_by_name('.text').data());rodata=bytearray(e.get_section_by_name('.rodata').data());functions={n:(defined[n]['st_value'],defined[n]['st_size']) for n in names};maps={e.get_section_index('.text'):TEXT,e.get_section_index('.rodata'):RO,e.get_section_index('.data'):0x21000000,e.get_section_index('.bss'):0x22000000};undefined={};hooks={} for name in ['_nv044886rm','_nv053907rm','_nv020158rm','_nv047869rm','_nv047868rm','_nv046745rm','_nv049786rm']: hooks[TEXT+defined[name]['st_value']]=name for section,buffer,base in [('.rela.text',text,TEXT),('.rela.rodata',rodata,RO)]: for rel in e.get_section_by_name(section).iter_relocations(): off=rel['r_offset'] if section=='.rela.text' and not any(start<=off