"""Bounded .54 SYS_DRV opcode-0x33 handler trace for object handle zero. This is a *separate* signed-image emulator observation from the HDCP caller failure-injection test. Stop before the fatal function executes; do not turn a simulated branch into a claimed hardware effect. """ from __future__ import annotations import os import sys from unicorn import UC_HOOK_CODE sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) from pspemu import Component # noqa: E402 SIGNED_SYSDRV = os.path.abspath(os.path.join( os.path.dirname(__file__), "..", "..", "psp_out", "elf", "sys_drv_0.49.0.54_18bd9d26.elf")) HANDLER_33 = 0xE1EA54 FATAL = 0xE0F890 def main(): comp = Component("sys_drv", image_path=SIGNED_SYSDRV) req = comp.alloc(0x80) attrs = comp.alloc(0x20) comp.wr32(req + 0x38, 0) seen = [] def stop_at_fatal(uc, addr, size, user_data): seen.append(addr) uc.emu_stop() # The callback marks the *first instruction* of sub_E0F890. Stopping # there avoids executing its uninitialized standalone-emulator globals # and prevents a deliberate infinite loop from obscuring the branch. comp.uc.hook_add(UC_HOOK_CODE, stop_at_fatal, begin=FATAL, end=FATAL) comp.run_function(HANDLER_33, (req, attrs, 1, 1), thumb=True, count=20000, timeout=2_000_000) print("signed_sysdrv_image:", os.path.basename(comp.image_path)) print("handler:", hex(HANDLER_33), "object_handle:", hex(comp.rd32(req + 0x38))) print("fatal_entry_reached:", [hex(a) for a in seen]) print("faults:", comp.faults) assert seen == [FATAL], seen assert not comp.faults if __name__ == "__main__": main()