
    UHj0<                    R   d Z ddlmZ ddlZddlZddlZddlZddlZddlm	Z	 ddl
mZ ej                  j                  d e e	e      j!                         j"                               ddlmZmZmZ  e	e      j!                         j,                  d   Zedz  Zd	Zd
Zg dZg dZddddddgZdZdZdZ dZ!dZ"dZ#dZ$dddddddd d!d"d#
d$d%d&d'd(d'd)d d*d+d#
d,d-d.d/d0d1d2d3d4d5d#
gZ%dBd6Z&dCd7Z'dDd8Z(dEd9Z)dFd:Z*dGdHd;Z+	 dI	 	 	 	 	 dJd<Z,dKd=Z-dKd>Z.efdLd?Z/dMd@Z0e1dAk(  r e0        yy)NzHSummarize runtime writers that materialize opcode 0x20 slot descriptors.    )annotationsN)Path)Any)offset_to_varead_sectionsva_to_offset   outmap1_01amap2_02d)zruntime-active-orderz!descriptor-materializer-executionzdescriptor-plus4-selectionz selected-root-execution-or-trace)z=runtime active order/count selecting descriptor table entrieszCdescriptor materializer routine execution on the current route pathzCdescriptor+4 script selected by opcode 0x20 mode 0 for selector 2:0zWselected-root execution or equivalent runtime trace reaching descriptor materializationHwanse2.exez;descriptor table references and materializer routine writes)pathdescriptionz,out/save_selector_opcode20_slot_sources.jsonzAslot base/count source and runtime descriptor pointer requirementi-D ivE ivE iPwE    i0Y ipY 
0x0043215czadd active save/object slotzwadds an id to 0x004576e9[count], stores slot base in 0x0059db30[count], increments count, then materializes descriptors
0x00432167
0x00432188
0x0043218f
0x004321cd0x00
0x004321fe
0x004322bd)
routineVaHexnameroleorderWriteVaHexslotBaseTableWriteVaHexcountWriteVaHexdescriptorWriteVaHexdescriptorScriptOffsetnestedRunVaHexobjectStoreVaHex
0x00432323zrebuild active slot descriptorszhrebuilds active descriptors from 0x004576e9 order bytes and stores created runtime objects in 0x0059dd70-
0x004323ba
0x004323dd
0x0043240e
0x004324cd
0x00432541z&remove/rebuild active slot descriptorszruns descriptor+4 scripts for active objects, removes a matching id, compacts order/slot tables, then rematerializes descriptors
0x004326a3
0x004326b6
0x004326c2
0x0043271fz'0x00 after removal; 0x04 before removalz0x004325a7, 0x00432750
0x0043280fc                    d| dS )N0x08x )values    U/home/exedev/hwanse/tools/summarize_save_selector_opcode20_slot_descriptor_writers.pyhex32r5   ]   s    c{    c                p    | j                         s|S t        j                  | j                  d            S )Nutf-8encoding)existsjsonloads	read_text)r   fallbacks     r4   	load_jsonr@   a   s*    ;;=::dnngn677r6   c                v    t        ||      }||dz   t        |       kD  ry t        j                  d| |      d   S )N   <Ir   )r   lenstructunpack_from)exesectionsvaoffsets       r4   dword_atrK   g   s?    (B'F~!c#h.dC033r6   c                    g }d}	 | j                  ||      }|dk  r|S t        ||      }||j                  |       |dz   }>)Nr   r	   )findr   append)rG   rH   patternrowsrJ   hitrI   s          r4   pattern_hitsrR   n   sU    DF
hhw'7K(C(>KKOq r6   c                    t        | |t        j                  d|            }t        |      t	        |      |d d D cg c]  }t        |       c}dS c c}w )NrC      )targetVaHexcount
sampleRefs)rR   rE   packr5   rD   )rG   rH   r3   refsrefs        r4   dword_ref_summaryr[   {   sP    Xv{{4'?@DU|T-1#2Y7cuSz7  8s   Ac                x   g }t        |      D ]  }t        |dz  z   }t        | ||      }|rt        | ||      nd }|rt        | ||dz         nd }|rt        | ||dz         nd }	|j                  |t	        |      |t	        |      nd |t	        |      nd |t	        |      nd |	t	        |	      nd d        |S )NrB      )index
entryVaHexdescriptorVaHexscript0VaHexscript4VaHexscript8VaHex)rangeDESCRIPTOR_TABLE_VArK   rN   r5   )
rG   rH   limitrP   r^   entry_va
descriptorfirstsecondthirds
             r4   descriptor_rowsrl      s    Du &2c8X6
7Ah
3t<F#xa8D;Eh
Q74/4>4JuZ0PT,1,=E%L4-3-?E&MT,1,=E%L4
 	 Kr6   c           
     L   t        |       }||nt        t        dz  i       }t        | |t              }d}i dt
        dt        d|j                  d      xs t        t              d|j                  d      xs ddt        t              d	t        t              d
t        t              dt        t              dt        t              d|dt        | |      dt        dt!        t              ddddddddddt"        t$        t&        t!        t&              d|dS )Nz(save_selector_opcode20_slot_sources.jsona  The opcode 0x20 slot first dword is a runtime descriptor pointer, not a static object pointer. The materializer routines write descriptors from table 0x00442d95 into 0x00457750 + slot*0xd8, using active order bytes at 0x004576e9 and the runtime count at 0x004576e8. Opcode 0x20 mode 0 therefore follows descriptor+4 scripts only after these routines have run. The next proof target is the active order/count at the current frontier or the descriptor+4 script chosen for that order; route promotion remains blocked.sourcetargetslotBaseHexslotStrideHex0x00d8countRuntimeVaHexorderBytesVaHexruntimeSlotBaseTableHexruntimeObjectTableHexdescriptorTableVaHexdescriptorTableRefSummarydescriptorRowsroutinesdescriptorWriteCountslotFirstDwordSourcez*runtime descriptor table 0x00442d95[index]opcode20Mode0ScriptSourcezdescriptor+4runtimeActiveOrderRequiredTcontrolPathProofStatusblockedF)
proofFound"opcode20DescriptorWriterProofFound%failedOpcode20DescriptorWriterGateIdsmissingEvidenceevidenceRefsevidenceRefCountpromotionStatus
conclusion)r   r@   OUTr[   re   SOURCETARGETgetr5   SLOT_BASE_VACOUNT_RUNTIME_VAORDER_BYTES_VARUNTIME_SLOT_BASE_TABLERUNTIME_OBJECT_TABLErl   ROUTINESrD   *FAILED_OPCODE20_DESCRIPTOR_WRITER_GATE_IDS+OPCODE20_DESCRIPTOR_WRITER_MISSING_EVIDENCE(OPCODE20_DESCRIPTOR_WRITER_EVIDENCE_REFS)rG   opcode20_slot_sourcesrH   descriptor_refsr   s        r4   build_summaryr      s    S!H !, 	sGGL 
 (X7JKO	% && 	,00?V5CV 	.22?COx	
 	U#34 	50 	"5)@#A 	 ';!< 	&9 : 	$_ 	/#x8 	H 	H 	 L 	$^  	%d!" 	!)#$ .31[F@ HI$ 3 r6   c                n   ddd| d    d| d    d| d    d	| d
    dd| d    dd| d    dd| d    dd| d   d    d| d    d| d    dd| d    d| d    dd| d    dd| d     dd| d!   dd"dg}|j                  d# | d$   D               |j                  g d%       |j                  d& | d'   D               |j                  g d(       |j                  d) | d*   D               |j                  g d+       | d,   D ]8  }|j                  d-|d.    d/|d0    d1|d2    d3|d4    d3|d5    d/|d6    d7       : |j                  g d8       | d9   D ]8  }|j                  d:|d;    d1|d<    d3|d=    d3|d>    d3|d?    d3|d@    dA       : |j                  d       dBj                  |      S )CNz3# Save Selector Opcode 0x20 Slot Descriptor Writers z	- route: rn   z -> ro   z- slot base: `rp   z
` stride `rq   `z- count byte: `rs   z- order bytes: `rt   z- descriptor table: `rw   z- descriptor table refs: rx   rV   z- slot first dword source: r|   z%- opcode 0x20 mode 0 script source: `r}   z!- runtime active order required: r~   z- proofFound: `r   z'- opcode20DescriptorWriterProofFound: `r   z- promotion status: `r   r   z## Failed Gatesc              3  (   K   | ]
  }d | d  yw)- `r   Nr2   .0items     r4   	<genexpr>zmarkdown.<locals>.<genexpr>   s     \43tfA\s   r   )r   z## Missing Evidencer   c              3  &   K   | ]	  }d |   yw)z- Nr2   r   s     r4   r   zmarkdown.<locals>.<genexpr>   s     D2dVDs   r   )r   z## Evidence Refsr   c              3  8   K   | ]  }d |d    d|d      yw)r   r   z`: r   Nr2   r   rows     r4   r   zmarkdown.<locals>.<genexpr>   s/       c&k]#c-012s   r   )r   z## Materializer Routinesr   zH| routine | name | descriptor write | nested run | object store | role |z%| --- | --- | --- | --- | --- | --- |rz   z| `r   z` | r   z | `r   z` | `r!   r"   r   z |)r   z## Descriptor Table Samplesr   z?| index | entry | descriptor | script+0 | script+4 | script+8 |z&| ---: | --- | --- | --- | --- | --- |ry   z| r^   r_   r`   ra   rb   rc   z` |
)extendrN   join)summarylinesr   s      r4   markdownr      s   =

GH%&d78+<*=>
/0
7?;S:TTUV
'"567q9
7#456a8
(> ?@B
#G,G$H$Q#RS
%g.D&E%FG
/8S0T/UUVW
+G4P,Q+RS
',/02
1':^2_1``ab
(9 :;1=


'E* 
LL\73Z+[\\	LL  
 
LLD1B)CDD	LL  
 
LL >*  
LL   z" 
#n%&d3v;-tC@V<W;X Y$%&eC0B,C+DDVUWY	


 
LL   '( 
Wd3|#4"5U3?P;Q:R SN#$E#n*=)>eCDWCXX[]	


 
LL99Ur6   c                "   dj                  d | d   D              }dj                  d | d   D              }dj                  d | d   D              }g }| d   D ]  }|j                  d	t        j                  |d
          dt        j                  |d          dt        j                  |d          dt        j                  |d          dt        j                  |d          dt        j                  |d          d        g }| d   D ]  }|j                  d|d    dt        j                  |d          dt        j                  |d   xs d       dt        j                  |d   xs d       dt        j                  |d   xs d       dt        j                  |d   xs d       d        dj                  g dd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3t        j                  | d4          d5t        j                  | d6          d7t        j                  | d8          d9t        j                  | d:          d;t        j                  | d<          d=t        j                  | d>          d?t        j                  | d@          dA| dB    dC| dD    dEt        j                  | dF          dGdHt        j                  | dI          dJdKdL| dMdNdL| dMdOdL| dMdPdQ|dRdSdT|dRdUdVd      S )WNr   c              3  N   K   | ]  }d t        j                  |       d  yw)
<li><code>z</code></li>Nhtmlescaper   s     r4   r   zhtml_page.<locals>.<genexpr>
  s+       T[[&'|4   #%r   c              3  N   K   | ]  }d t        j                  |       d  yw)z<li></li>Nr   r   s     r4   r   zhtml_page.<locals>.<genexpr>  s+       t{{4 !'r   r   c              3     K   | ]9  }d t        j                  |d          dt        j                  |d          d ; yw)r   r   z	</code>: r   r   Nr   r   s     r4   r   zhtml_page.<locals>.<genexpr>  sE       T[[V-.iCDV8W7XX]^s   ?Ar   rz   z<tr><td><code>r   z</code></td><td>r   z</td><td><code>r   z</code></td><td><code>r!   r"   r   z
</td></tr>ry   z<tr><td>r^   r_   r`   r$   ra   rb   rc   z</code></td></tr>r   z<!doctype html>z<html lang="en">z<head>z  <meta charset="utf-8">zF  <meta name="viewport" content="width=device-width, initial-scale=1">zB  <title>Save Selector Opcode 0x20 Slot Descriptor Writers</title>z	  <style>zg    :root { color-scheme: dark; font-family: system-ui, sans-serif; background: #101010; color: #eee; }z&    body { margin: 0; padding: 24px; }z,    h1 { margin: 0 0 8px; font-size: 24px; }z/    h2 { margin: 24px 0 8px; font-size: 18px; }z<    p { max-width: 1120px; color: #bbb; line-height: 1.45; }z[    table { width: 100%; border-collapse: collapse; margin: 12px 0 20px; font-size: 13px; }zi    th, td { border-bottom: 1px solid #303030; padding: 7px 8px; text-align: left; vertical-align: top; }zF    th { position: sticky; top: 0; background: #181818; color: #ddd; }z    code { color: #d7f0ff; }z
  </style>z</head>z<body>z<  <h1>Save Selector Opcode 0x20 Slot Descriptor Writers</h1>z  <p>route rn   z -&gt; ro   z; descriptor table <code>rw   z</code>; slot base <code>rp   z</code>; count byte <code>rs   z</code>; order bytes <code>rt   z0</code>; opcode 0x20 mode 0 script source <code>r}   z(</code>; runtime active order required: r~   z; proofFound <code>r   z </code>; promotion status <code>r   z</code>.</p>z  <p>r   z</p>z  <h2>Failed Gates</h2>z  <ul>z</ul>z  <h2>Missing Evidence</h2>z  <h2>Evidence Refs</h2>z   <h2>Materializer Routines</h2>z  <table><thead><tr><th>routine</th><th>name</th><th>descriptor write</th><th>nested run</th><th>object store</th><th>role</th></tr></thead><tbody>z  </tbody></table>z#  <h2>Descriptor Table Samples</h2>z  <table><thead><tr><th>index</th><th>entry</th><th>descriptor</th><th>script+0</th><th>script+4</th><th>script+8</th></tr></thead><tbody>z</body>z</html>)r   rN   r   r   )r   failed_gatesmissing_evidenceevidence_refsroutine_rowsr   rl   s          r4   	html_pager   	  s   77 CD L ww -.  GG >* M Lz" 

S%89: ;;;s6{+, -S)?%@AB CS)9%:;< =S);%<=> ?;;s6{+, -		


 O'( 

w<. !S%678 9S):%;%BsCD ES%8%?C@A BS%8%?C@A BS%8%?C@A B		


 99 ((( 	( 	#	(
 	Q( 	M( 	( 	r( 	1( 	7( 	:( 	G( 	f( 	t( 	Q(  	'!(" 	#($ 	%(& 	'(( 	G)(* dkk'("345WT[[QYIZ=[<\\uvz  wB  wB  CJ  Ka  Cb  wc  vd  d}  ~B  ~I  ~I  JQ  R_  J`  ~a  }b  b|  }A  }H  }H  IP  Qd  Ie  }f  |g  gB  CG  CN  CN  OV  Wh  Oi  Cj  Bk  k[  \`  \g  \g  ho  pK  hL  \M  [N  Nv  w~  [  w\  v]  ]p  qx  yE	  qF	  pG	  G	g	  h	l	  h	s	  h	s	  t	{	  |	M
  t	N
  h	O
  g	P
  P
\
  	]
+(, GL12348-(. 	"/(0 e$1(2 	&3(4 !"%(5(6 	#7(8 u%9(: 	+;(< 	^=(> 
?(@ 	A(B 	.C(D 	UE(F 
G(H 	I(J 	K(L 	M(N 	O( ( (r6   c                    |j                  dd       |dz  j                  t        j                  | dd      dz   d	       |d
z  j                  t	        |       d	       y )NT)parentsexist_okz3save_selector_opcode20_slot_descriptor_writers.jsonF   )ensure_asciiindentr   r8   r9   3save_selector_opcode20_slot_descriptor_writers.html)mkdir
write_textr<   dumpsr   )r   out_dirs     r4   write_outputsr   Y  sg    MM$M.DDPP

7q9D@ Q  DDPPQZ[bQcnuPvr6   c                 v   t        j                  t              } | j                  dt        t
        dz         | j                  dt        t               | j                         }t        |j                  j                               }t        ||j                         t        d|j                  dz          y )N)r   z--exer   )typedefaultz	--out-dirz;wrote save selector opcode 0x20 slot descriptor writers -> r   )argparseArgumentParser__doc__add_argumentr   ROOTr   
parse_argsr   rG   
read_bytesr   r   print)parserargsr   s      r4   mainr   b  s    $$9F
dD=4HI
$<DDHH//12G'4<<(	E<<OO
P	Rr6   __main__)r3   intreturnstr)r   r   r?   r   r   r   )rG   bytesrH   
list[dict]rI   r   r   z
int | None)rG   r   rH   r   rO   r   r   z	list[int])rG   r   rH   r   r3   r   r   dict)   )rG   r   rH   r   rf   r   r   r   )N)rG   r   r   zdict | Noner   r   )r   r   r   r   )r   r   r   r   r   None)r   r   )2r   
__future__r   r   r   r<   rE   syspathlibr   typingr   r   insertr   __file__resolveparentprobe_exe_scene_tablesr   r   r   r   r   r   r   r   r   r   r   re   r   r   r   SLOT_STRIDEr   r   r   r5   r@   rK   rR   r[   rl   r   r   r   r   r   __name__r2   r6   r4   <module>r      s   N "     
   3tH~--/667 8 L L H~''*
Ul		. */ + T
 ?Z	, ( !  $ !  %- J'#/' ,"(&( %1z#/ ,"(&( %8 S'#/' ,"K2(3%P84
* *.-	-&- 
-`?DM` 25 w
 zF r6   