mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 22:48:43 +00:00
21 lines
2.0 KiB
Python
21 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Extract selected immutable legacy HAL interface labels from pinned original ELF."""
|
|
from pathlib import Path
|
|
import json,hashlib,argparse,struct
|
|
from elftools.elf.elffile import ELFFile
|
|
R=Path(__file__).resolve().parents[1];P=Path('/home/geodd/nvidia-driver/analysis-580.178.04/extracted/kernel/nvidia/nv-kernel.o_binary');opt=argparse.ArgumentParser();opt.add_argument('--check',action='store_true');a=opt.parse_args()
|
|
assert hashlib.sha256(P.read_bytes()).hexdigest()=='5269a23ffba19a17fe16f076463e7ad4151254659441d1711bee6c6221ff6f4b'
|
|
with P.open('rb')as f:
|
|
e=ELFFile(f);symbols=list(e.get_section_by_name('.symtab').iter_symbols());relocs={r['r_offset']:r for r in e.get_section_by_name('.rela.rodata').iter_relocations()};raw=e.get_section_by_name('.rodata').data();bases={e.get_section_index('.text'):0x0616f810,e.get_section_index('.rodata'):0x0111d660,e.get_section_index('.data'):0x00f7e890,e.get_section_index('.bss'):0x05fd2180}
|
|
def pointer(address):
|
|
offset=address-0x0111d660;r=relocs.get(offset)
|
|
if r is None:return struct.unpack_from('<Q',raw,offset)[0]
|
|
s=symbols[r['r_info_sym']];return bases[s['st_shndx']]+s['st_value']+r['r_addend']
|
|
setup=[pointer(0x0113b3f0+i*8)for i in range(2)];entries=[pointer(0x01137f20+i*8)for i in range(205)]
|
|
code='// Original GV100 legacy HAL setup labels; metadata, never native calls.\nconst SETUP_IDENTITY:u64=0x0113b3f0;\nconst SETUP:[u64;2]=['+','.join(map(str,setup))+'];\n#[rustfmt::skip]\nconst INTERFACES:[u64;205]=[\n'+''.join(str(v)+',\n'for v in entries)+'];\n'
|
|
p=R/'src/nvidia/src/gpu/legacy_hal_data.rs'
|
|
if a.check:assert p.read_text()==code
|
|
else:p.write_text(code)
|
|
(R/'reports/gpu-legacy-hal-data.json').write_text(json.dumps({'artifact_sha256':hashlib.sha256(P.read_bytes()).hexdigest(),'hal_index':35,'setup_identity':0x0113b3f0,'setup':setup,'interface_source':0x01137f20,'interface_count':205,'interfaces':entries,'scope':'immutable metadata labels only; method implementations not established by presence'},indent=2)+'\n')
|
|
print('2 setup labels,205 interfaces')
|