mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 14:38:47 +00:00
37 lines
2.7 KiB
Python
37 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Original pure GPIO/DISP assignment instructions, no target execution/hardware."""
|
|
from pathlib import Path
|
|
from _binary_path import resolve_580_binary
|
|
import 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
|
|
from unicorn.x86_const import *
|
|
R=Path(__file__).resolve().parents[1]
|
|
P=resolve_580_binary()
|
|
SHA='5269a23ffba19a17fe16f076463e7ad4151254659441d1711bee6c6221ff6f4b'
|
|
assert hashlib.sha256(P.read_bytes()).hexdigest()==SHA
|
|
TEXT=0x10000000;DATA=0x30000000;STACK=0x40000000;STOP=0x60000000
|
|
with P.open('rb') as f:
|
|
e=ELFFile(f);symbols=list(e.get_section_by_name('.symtab').iter_symbols());byname={s.name:s for s in symbols};text=bytearray(e.get_section_by_name('.text').data());index=e.get_section_index('.text')
|
|
names=['_nv006035rm'];ranges=[(byname[n]['st_value'],byname[n]['st_size']) for n in names]
|
|
for rel in e.get_section_by_name('.rela.text').iter_relocations():
|
|
off=rel['r_offset']
|
|
if not any(a<=off<a+size for a,size in ranges):continue
|
|
sym=symbols[rel['r_info_sym']];assert rel['r_info_type']==11 and sym['st_shndx']==index
|
|
struct.pack_into('<i',text,off,TEXT+sym['st_value']+rel['r_addend'])
|
|
reverse={TEXT+s['st_value']:s.name for s in symbols if s['st_info']['type']=='STT_FUNC'}
|
|
uc=Uc(UC_ARCH_X86,UC_MODE_64);uc.mem_map(TEXT,(len(text)+4095)&~4095);uc.mem_write(TEXT,bytes(text));uc.mem_map(DATA,0x30000);uc.mem_map(STACK,0x10000);uc.mem_map(STOP,4096)
|
|
uc.mem_write(DATA+0x20010,struct.pack('<H',2));uc.mem_write(DATA+0x21010,struct.pack('<H',0x23))
|
|
rows=[]
|
|
for chip in range(64):
|
|
uc.mem_write(DATA+0x20010,struct.pack('<H',chip))
|
|
name='_nv006035rm';uc.mem_write(DATA,bytes(0x10000));uc.reg_write(UC_X86_REG_RDI,DATA);uc.reg_write(UC_X86_REG_RSI,DATA+0x20000);uc.reg_write(UC_X86_REG_RSP,STACK+0xfff8);uc.reg_write(UC_X86_REG_RBP,STACK+0x8000);uc.mem_write(STACK+0xfff8,struct.pack('<Q',STOP))
|
|
uc.emu_start(TEXT+byname[name]['st_value'],STOP,count=20000);assert uc.reg_read(UC_X86_REG_RIP)==STOP
|
|
target=reverse[struct.unpack('<Q',uc.mem_read(DATA+0x300,8))[0]]
|
|
if chip==35:assert target=='_nv052404rm'
|
|
rows.append({'setter':name,'chip_hal':chip,'offset':'0x300','target':target})
|
|
report={'artifact_sha256':SHA,'passed':True,'rows':rows,'limits':['Pure original assignment instructions only. No native target calls or hardware access.','Chip HAL35 selects exact052404 NV_OK no-op prehook; no guessed default.','Pmu classf3d722 hasbinder006035. GPU2120 object association is investigated separately.']}
|
|
(R/'reports/gpu-pf-rom-prehook-bindings.json').write_text(json.dumps(report,indent=2)+'\n')
|
|
print(len(rows),'original PMU prehook callback bindings verified')
|