mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 14:38:47 +00:00
37 lines
3.0 KiB
Python
37 lines
3.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Original pure GPIO/DISP assignment instructions, no target execution/hardware."""
|
|
from pathlib import Path
|
|
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=Path('/home/geodd/nvidia-driver/analysis-580.178.04/extracted/kernel/nvidia/nv-kernel.o_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=['_nv006018rm','_nv005963rm','_nv006019rm'];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 disp_ip in range(64):
|
|
uc.mem_write(DATA+0x20012,struct.pack('<H',disp_ip))
|
|
for name,offsets in [('_nv006018rm',[0x158,0x238,0x260,0x288,0x2b0]),('_nv005963rm',[0x4b8,0x4c0,0x518]),('_nv006019rm',[0x48,0x50,0x90,0x100])]:
|
|
uc.mem_write(DATA,bytes(0x10000));uc.reg_write(UC_X86_REG_RDI,DATA);uc.reg_write(UC_X86_REG_RSI,DATA+(0x21000 if name in ('_nv006018rm','_nv006019rm') else 0x20000));uc.reg_write(UC_X86_REG_RDX,DATA+(0x20000 if name=='_nv006019rm' else 0x21000));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
|
|
for offset in offsets:
|
|
target=reverse[struct.unpack('<Q',uc.mem_read(DATA+offset,8))[0]]
|
|
rows.append({'setter':name,'chip_hal':35,'rm_hal':2,'display_ip_hal':disp_ip,'offset':hex(offset),'target':target})
|
|
report={'artifact_sha256':SHA,'passed':True,'rows':rows,'limits':['Pure original assignment instructions only. No native target calls or hardware access.','Actual Display IP must come from owned factory. This table does not infer physical IP.']}
|
|
(R/'reports/gpu-pf-rom-source-bindings.json').write_text(json.dumps(report,indent=2)+'\n')
|
|
print(len(rows),'original VBIOS/DISP source-prefix bindings')
|