"""Validate the disclosure detector before trusting its negative. 1) How many bytes do the TAs actually write back? (if ~0, the scan is vacuous) 2) Does classify() actually fire on a known PSP-range value? (ground truth) """ import ctypes,struct,collections,sys 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/'; SHMSZ=0x8000; MARK=0x5A RANGES=[(0x00020000,0x00070000,'sOS'),(0x00400000,0x00412000,'HDCP'), (0x00D00000,0x00D50000,'ASD'),(0x00E10000,0x00E80000,'SYSDRV'),(0x0020A000,0x0020C000,'TAstage')] def classify(v): for lo,hi,nm in RANGES: if lo<=v %-8s expect %-8s %s"%(v,got,exp,ok)) 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(SHMSZ) 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=SHMSZ return psp._ring_submit(c).resp.session_id, cp def inv(sid,shm,buf,tc): adev.vram.view(shm,SHMSZ)[:]=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,SHMSZ)[:]) 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(SHMSZ); struct.pack_into('