"""Determinism test = uninitialized-memory detector. Identical input, repeated. Any output byte that VARIES between runs cannot come from our request -- it comes from uninitialized stack/heap or stale PSP state. That is the disclosure primitive this project has been missing. Also dumps the payload so constant-but-unexplained bytes can be inspected. """ import ctypes,struct,sys,collections from tinygrad import Device from tinygrad.runtime.autogen.am import am from tinygrad.helpers import lo32,hi32 d=Device["AMD"]; adev=d.iface.dev_impl; psp=adev.psp SZ=ctypes.sizeof(am.struct_psp_gfx_cmd_resp); P='/Users/user/dev/amd-psp-re/psp_out/'; S=0x8000; MARK=0x5A def alloc(n): pa=adev.mm.palloc(n,align=0x1000,zero=True); return pa,adev.paddr2mc(pa) def load(cmd,blob): ap,amc=alloc(0x40000); cp,cmc=alloc(S) adev.vram.view(ap,len(blob))[:]=blob; adev.gmc.flush_hdp() adev.vram.view(psp.cmd_paddr,SZ)[:]=b"\x00"*SZ c=am.struct_psp_gfx_cmd_resp(cmd_id=cmd); t=c.cmd.cmd_load_ta t.app_phy_addr_hi,t.app_phy_addr_lo=hi32(amc),lo32(amc); t.app_len=len(blob) t.cmd_buf_phy_addr_hi,t.cmd_buf_phy_addr_lo=hi32(cmc),lo32(cmc); t.cmd_buf_len=S return psp._ring_submit(c).resp.session_id, cp def inv(sid,shm,buf,tc): adev.vram.view(shm,S)[:]=bytes(buf); adev.gmc.flush_hdp() adev.vram.view(psp.cmd_paddr,SZ)[:]=b"\x00"*SZ ic=am.struct_psp_gfx_cmd_resp(cmd_id=am.GFX_CMD_ID_INVOKE_CMD); iv=ic.cmd.cmd_invoke_cmd iv.session_id,iv.ta_cmd_id=sid,tc try: psp._ring_submit(ic) except RuntimeError: pass except TimeoutError: return None return bytes(adev.vram.view(shm,S)[:]) asd,_=load(am.GFX_CMD_ID_LOAD_ASD,open(P+'asd_full.bin','rb').read()) dtm,dsh=load(am.GFX_CMD_ID_LOAD_TA,open(P+'dtm_full.bin','rb').read()) hdcp,hsh=load(am.GFX_CMD_ID_LOAD_TA,open(P+'hdcp_full.bin','rb').read()) def topo(h): b=bytearray(S); struct.pack_into('1] tag="" if vary: tag=" <== NON-DETERMINISTIC at %s"%[hex(0x1400+i) for i in vary[:8]] found.append((sub,N,vary)) print(" %-5d %-3d %5d %s%s"%(sub,N,len(vary),outs[0][0x10:0x38].hex(),tag)) print("\nnon-deterministic sites: %d"%len(found)) # also: does the payload differ when we change ONLY the fill byte? (echo vs leak) o1=inv(hdcp,hsh,mk(12,40,0x41),0x0F); o2=inv(hdcp,hsh,mk(12,40,0x42),0x0F) d12=[i for i in range(0x1400,0x1500) if o1[i]!=o2[i]] print("bytes in output that track our fill byte (echo, not leak): %d"%len(d12)) print("sos_alive:",psp.is_sos_alive())