mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 06:28:39 +00:00
80 lines
2.5 KiB
Python
Executable File
80 lines
2.5 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Record original ELF relocations establishing gmmu-walk callback identity."""
|
|
import json
|
|
from pathlib import Path
|
|
import sys
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
if str(ROOT / 'tools') not in sys.path:
|
|
sys.path.insert(0, str(ROOT / 'tools'))
|
|
|
|
from _elf64_reader import (
|
|
EXPECTED_RM_OBJECT_SHA256,
|
|
STT_FUNC,
|
|
Elf64Relocatable,
|
|
find_rm_object,
|
|
verify_rm_object_sha256,
|
|
)
|
|
|
|
EXPECTED_SYMBOLS = [
|
|
'_nv013506rm',
|
|
'_nv013507rm',
|
|
'_nv013511rm',
|
|
'_nv013512rm',
|
|
'_nv013503rm',
|
|
'_nv013500rm',
|
|
]
|
|
|
|
|
|
def main() -> None:
|
|
obj_path = find_rm_object()
|
|
sha = verify_rm_object_sha256(obj_path, EXPECTED_RM_OBJECT_SHA256)
|
|
|
|
elf = Elf64Relocatable.from_path(obj_path)
|
|
syms = elf.symbols()
|
|
names = {
|
|
s['st_value']: s['name']
|
|
for s in syms
|
|
if s['name'].startswith('_nv') and s['st_type'] == STT_FUNC
|
|
}
|
|
table = []
|
|
for r_offset, r_sym, _, r_addend in elf.relocations('.rela.rodata'):
|
|
if 0x4C5DA80 <= r_offset < 0x4C5DAB8:
|
|
sym = syms[r_sym]
|
|
sec_name = elf.section_name(sym['st_shndx'])
|
|
if sec_name != '.text':
|
|
raise SystemExit(f'unexpected callback relocation target section {sec_name!r} != .text')
|
|
if r_addend not in names:
|
|
raise SystemExit(f'no _nv* function symbol at .text+0x{r_addend:x}')
|
|
table.append({
|
|
'offset': hex(r_offset),
|
|
'text_addend': hex(r_addend),
|
|
'symbol': names[r_addend],
|
|
})
|
|
observed = [x['symbol'] for x in table]
|
|
if observed != EXPECTED_SYMBOLS:
|
|
raise SystemExit(f'unexpected g_gmmuWalkCallbacks sequence: {observed} != {EXPECTED_SYMBOLS}')
|
|
|
|
report_path = ROOT / 'reports/mmu-callback-relocations.json'
|
|
report_path.parent.mkdir(parents=True, exist_ok=True)
|
|
report_path.write_text(
|
|
json.dumps(
|
|
{
|
|
'artifact': str(obj_path),
|
|
'sha256': sha,
|
|
'rodata_base': '0x4c5da80',
|
|
'callback_order': ['LevelAlloc', 'LevelFree', 'UpdatePdb', 'UpdatePde', 'FillEntries', 'CopyEntries'],
|
|
'relocations': table,
|
|
'interpretation': 'Callback order corroborated by exact-version g_gmmuWalkCallbacks definition and complete REA callback behavior',
|
|
},
|
|
indent=2,
|
|
)
|
|
+ '\n',
|
|
encoding='utf-8',
|
|
)
|
|
print('Six actual ELF callback relocations verified')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|