#!/usr/bin/env python3 """Execute four original timer interrupt leaves with scripted MMIO only.""" import argparse import hashlib import itertools import json import struct import warnings from pathlib import Path 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 UC_X86_REG_RAX, UC_X86_REG_RBP, UC_X86_REG_RIP, UC_X86_REG_RSP, UC_X86_REG_RDI, UC_X86_REG_RSI, UC_X86_REG_RDX, UC_X86_REG_RCX, UC_X86_REG_R8, UC_X86_REG_R9 parser = argparse.ArgumentParser() parser.add_argument('--check', action='store_true') options = parser.parse_args() root = Path(__file__).resolve().parents[1] artifact = Path('/home/geodd/nvidia-driver/analysis-580.178.04/extracted/kernel/nvidia/nv-kernel.o_binary') sha = '5269a23ffba19a17fe16f076463e7ad4151254659441d1711bee6c6221ff6f4b' assert hashlib.sha256(artifact.read_bytes()).hexdigest() == sha TEXT, DATA, STACK, STOP = 0x10000000, 0x30000000, 0x40000000, 0x50000000 names = ['_nv059571rm', '_nv059576rm', '_nv059635rm', '_nv059648rm'] with artifact.open('rb') as stream: elf = ELFFile(stream) symbols = list(elf.get_section_by_name('.symtab').iter_symbols()) syms = {s.name: s for s in symbols} text = bytearray(elf.get_section_by_name('.text').data()) section = elf.get_section_index('.text') spans = [(syms[n]['st_value'], syms[n]['st_size']) for n in names] for rel in elf.get_section_by_name('.rela.text').iter_relocations(): off = rel['r_offset'] if not any(start <= off < start + size for start, size in spans): continue symbol = symbols[rel['r_info_sym']] assert symbol['st_shndx'] == section and rel['r_info_type'] in (2, 4) struct.pack_into('