#!/home/geodd/.local/opt/rea-python/bin/python """Execute whole original031359 GPU-instance selection in private Unicorn RAM.""" import argparse import hashlib import json from pathlib import Path import random import struct import warnings 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_RDI, UC_X86_REG_RSP, UC_X86_REG_RIP, UC_X86_REG_RAX 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') TEXT, BSS, DATA, STACK, STOP = 0x10000000, 0x20000000, 0x30000000, 0x40000000, 0x50000000 with ARTIFACT.open('rb') as stream: elf = ELFFile(stream) symbols = list(elf.get_section_by_name('.symtab').iter_symbols()) names = {symbol.name: symbol for symbol in symbols} function = names['_nv031359rm'] start, size = function['st_value'], function['st_size'] text = bytearray(elf.get_section_by_name('.text').data()) for relocation in elf.get_section_by_name('.rela.text').iter_relocations(): offset = relocation['r_offset'] if not start <= offset < start + size: continue symbol = symbols[relocation['r_info_sym']] assert symbol.name == '_nv029075rm' and relocation['r_info_type'] == 2 assert elf.get_section(symbol['st_shndx']).name == '.bss' target = BSS + symbol['st_value'] struct.pack_into('