
    UHjG                    *   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  e	e      j!                         j*                  d   Zedz  Zd	Zd
ZdZdZdZdZdZdZdZ ddgZ!d#dZ"d$dZ#d%dZ$d&dZ%d'dZ&d(dZ'd)dZ(d*dZ)	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d+dZ*	 	 	 	 d,	 	 	 	 	 	 	 	 	 	 	 d-dZ+d.dZ,d.dZ-d/d Z.d0d!Z/e0d"k(  r e/        yy)1zOScan direct bridge refs between predecessor 1:0 and current 2:0 selector roots.    )annotationsN)Path)Any)read_sectionsva_to_offset   outz1:0z2:0idG iEH iT ix5T i+T iD+T i+T iDH iDH c                    d| dS )N0x08x values    L/home/exedev/hwanse/tools/summarize_save_selector_predecessor_bridge_refs.pyhex32r   !   s    c{    c                4    t        |        dt        |       S )Nz..)r   )startends     r   	range_hexr   %   s    El^2eCj\**r   c                p    | j                         s|S t        j                  | j                  d            S )Nutf-8encoding)existsjsonloads	read_text)pathfallbacks     r   	load_jsonr!   )   s*    ;;=::dnngn677r   c                v    t        ||      }||dz   t        |       kD  ry t        j                  d| |      d   S )N   z<Ir   )r   lenstructunpack_from)datasectionsvaoffsets       r   dword_at_var+   /   s?    (B'F~!c$i/dD&1!44r   c                "    | rt        | d      S d S )N   )intr   s    r   	parse_hexr/   6   s    "3ub>,,r   c                    |j                  dd      \  }}t        |      t        |      t        fd| D              S )N:r   c              3  r   K   | ].  }|j                  d       k(  r|j                  d      k(  r| 0 yw)groupslotN)get).0rowr3   r4   s     r   	<genexpr>zselector_row.<locals>.<genexpr>>   s9      777u$D)@ 	s   47)splitr.   next)	selectorslabel
group_text	slot_textr3   r4   s       @@r   selector_rowr?   :   sD    !KKQ/J	
OEy>D    r   c                   i }| D ]  }|j                  d      |k7  r|j                  d      xs g D ]   }|j                  t        |      | d       " t        |j                  d            }|m|j                  || d        |S )Nr<   r   z selector pathrefVaHexz resource ref)r5   
setdefaultr.   r/   )select_refsr<   targetsr7   path_varef_vas         r   collect_path_targetsrG   D   s     G @777u$wwv," 	GGs7|wn-EF	G377:./v%'>?@ Nr   c                    t        | j                               D cg c]  \  }}|t        |      |d c}}S c c}}w )N)r)   vaHexr<   )sorteditemsr   )rD   r)   r<   s      r   exact_target_rowsrL   Q   s>      0B E"I6  s   :c           
     f   g }d}d}	t        ||d      D ]l  }
t        | ||
      }||	dz  }	|dz  }||cxk  xr |k  nc }|j                  |      }|s|C|j                  |
t	        |
      |t	        |      ||d       n t        ||      t        ||      ||	t        |      t        |      |dS )Nr   r#   r   )sourceVasourceVaHexr   valueHexinsideTargetRootRange
exactLabel)sourceRangeHextargetRootRangeHexreadableDwordCountunreadableDwordCounttargetExactValueshitCounthits)ranger+   r5   appendr   r   rL   r$   )exer(   source_start
source_endtarget_start
target_endexact_targetsrY   readable_countunreadable_countr)   r   inside_target_rangeexact_labels                 r   scan_dwords_for_bridgerf   X   s     DNL*a0 C2.=!!*e@j@#''."{': 9e%8%
 	& $L*='jA, 0.}=I r   c           
        t        |       }||nt        t        dz  g       }||nt        t        dz  g       }||nt        t        dz  i       }||nt        t        dz  i       }t        |t              }t        |t
              }t        |j                  d            xs t        }t        |j                  d            xs t        }	t        |j                  d            xs t        }
t        }t        |t              }|j                  |di       t        D ]  }d||<   	 t        |t
              }|j                  |	d	t        d
t         dt"        di       |j                  d      xs |j                  d      xs g D ]1  }t        |j                  d            }| |j%                  |d       3 t'        | |||
|	||      }t'        | ||	|||
|      }|d   dkD  }|d   }|D cg c]  }|d   t        v r| }}t)        t              }|D cg c]  }|d   |k  r| }}|D cg c]  }|d   |k\  r| }}|D cg c]  }|d   dk  r| }}|xs t+        |      }t+        |      xr t-        |      t-        |      k(  }d}i dt        dt/        |      dt1        ||
      d|j                  d      xs g dt
        dt/        |	      dt1        |	|      d |j                  d      xs g d!|d"|d#|d$|d%t-        |      d&t-        |      d't-        |      d(t-        |      d)t-        |      |d*d+g d,g d-|d.S c c}w c c}w c c}w c c}w )/Nzsave_scene_selectors.jsonz#save_scene_selector_references.jsonz)save_selector_predecessor_tail_reset.jsonz.save_selector_current_root_frontier_paths.jsonselectedPointerHexnextRootHexzpredecessor root 1:0z%predecessor secondaryBranchState fillzcurrent root 2:0z%current frontier reader/resource gatez$current source scene record map1_01az$current target scene record map2_02d	leafPathsleavesleafPointerHexzcurrent leaf pathrX   r   rY   r   rN   i(T a0  The direct bridge scan found no predecessor->current dword edge. The reverse direction has current-root dwords that point back into the predecessor root, but all of those targets are before the predecessor secondary fill sites 0x004844d0/0x004844d8 and none targets the fill sites themselves. This looks like shared/reused script substructure rather than proof that selector 1:0 executes into selector 2:0 or leaves its fill state for the current frontier. Promotion remains blocked until runtime order/state persistence or a strict map1_01a hotspot is proven.predecessorSelectorpredecessorRootHexpredecessorRootRangeHexpredecessorFieldMaps	fieldMapscurrentSelectorcurrentRootHexcurrentRootRangeHexcurrentFieldMapspredecessorToCurrentcurrentToPredecessorbridgeFoundforwardExecutionBridgeFoundreverseReuseHitCountreverseHitsToFillSiteCountreverseHitsBeforeFillCountreverseHitsAfterOrAtFillCount#reverseHitsBeforeCurrentWriterCountFblocked)zLThis scan covers direct dword values in the known selector root ranges only.zqIt does not rule out VM-dispatched execution order, save flag progression, or indirect runtime state transitions.zEIt does not replace the strict hotspot/source-coordinate requirement.)zJprove selector 1:0 executes before selector 2:0 in the normal runtime pathzKprove secondaryBranchState persists from predecessor fill to current readerz1find strict map1_01a source coordinate or hotspot)reverseHitsOnlyBeforeFillrouteOrderProvenpromotionStatuslimitationsremainingProofs
conclusion)r   r!   OUTr?   PREDECESSOR_SELECTORCURRENT_SELECTORr/   r5   PREDECESSOR_ROOTCURRENT_ROOTPREDECESSOR_ENDCURRENT_ENDrG   updatePREDECESSOR_FILL_SITESCURRENT_FRONTIER_READERCURRENT_SOURCE_RECORDCURRENT_TARGET_RECORDrB   rf   minboolr$   r   r   )r\   save_scene_selectorssave_scene_selector_refspredecessor_tail_resetcurrent_root_pathsr(   predecessor_rowcurrent_rowpredecessor_rootcurrent_rootpredecessor_endcurrent_endpredecessor_exact_targetsfill_vacurrent_exact_targetsleafleaf_vapredecessor_to_currentcurrent_to_predecessorforward_execution_bridge_foundreverse_reuse_hitsr7   reverse_hits_to_fill
first_fillreverse_hits_before_fillreverse_hits_after_or_at_fill"reverse_hits_before_current_writerbridge_foundreverse_hits_only_before_fillr   s                                 r   build_summaryr      s    S!H3G3S/Yb))
Z <T;_7en33
f 8N7Y3_h99
` 0B/M+S\>>
T
 ##79MNO35EFK !4!45I!JK_O_[__-ABCS|L 6 : := IJ]oOK 45MOc d$$0&  * U-T!'*U01IK[\  (!HEE	"  #&&{3]7I7M7Mh7W][] KDHH%567!,,W6IJK
 4 4! &<J%G!%K"/7)w<11 	  +,J) w<*$ 	   
 *%w<:% 	%! %
 **z?Z' 	*& * 2MT:L5ML  	E()S1C-DD "
	  3 e$45  	"9-=#O  	 3 3K @ FB	 
 	+  	%-  	y{C  	KOOK8>B  	 6  	 6  	|  	&'E  	$6 7  	%c*>&?  	%c*B&C   	(-J)K! " 	.s3U/V# $ &C!$



 !?   =
 %*s   +MM+MMc                T   | d   }| d   }g 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&    d'|d(    d)|d    d*	d+|d$    d%|d&    d'|d(    d)|d    d*	dd,dd-d.d/| d0    d*d1| d2    d*d3| d4    d*d5| d    d*d6| d7    d*d8| d    d*dd9dd:dd;d<}|d=   rE|d=   D ]<  }|j                  d>|d?    d%|d@    d'|dA    d)|j                  dB      xs dC d*	       > n|j                  dD       |j                  g dE       |d=   rE|d=   D ]<  }|j                  d>|d?    d%|d@    d'|dA    d)|j                  dB      xs dC d*	       > n|j                  dD       |j                  g dF       |j                  dG | dH   D               |j                  d       dIj                  |      S )JNrv   rw   z'# Save Selector Predecessor Bridge Refs z- predecessor: `rm   z` root `rn   z	` range `ro   `z- current: `rr   rs   rt   z- predecessor -> current hits: rX   z- current -> predecessor hits: z- bridge found: rx   z"- forward execution bridge found: ry   z- reverse hits to fill sites: r{   z!- reverse hits only before fill: r   z- route order proven: r   z- promotion status: `r   r   z## Scan SummaryzI| direction | source range | target root range | readable dwords | hits |z!| --- | --- | --- | ---: | ---: |z| predecessor -> current | `rS   z` | `rT   z` | rU   z | z |z| current -> predecessor | `z## Reverse Hit Classificationz| metric | count/status |z| --- | ---: |z| reverse reuse hits | rz   z)| reverse hits before predecessor fill | r|   z+| reverse hits at/after predecessor fill | r}   z%| reverse hits to exact fill sites | z2| reverse hits before current writer 0x005428bc | r~   z"| reverse hits only before fill | z## Hitsz### Predecessor -> Current6| source | value | inside target range | exact label || --- | --- | --- | --- |rY   z| `rO   rP   rQ   rR   -z| - | - | - | - |)r   z### Current -> Predecessorr   r   r   )r   z## Remaining Proofsr   c              3  &   K   | ]	  }d |   yw)z- Nr   r6   items     r   r8   zmarkdown.<locals>.<genexpr>J  s     D2dVDs   r   
)r[   r5   extendjoin)summaryp2cc2plinesr7   s        r   markdownr     s   
(
)C
(
)C(1(
( 7#89:(7K_C`Baajkr  tM  lN  kO  OP  	Q( w012(7CS;T:UU^_fg|_}^~~  	A	(
 *#j/):;( *#j/):;( 7=123( -W5R-S,TU( )1M)N(OP( ,G4O,P+QR( !);!< =>(  (9 :;1=( 	( 	( 	(  	!(" 	#($ 	T%(& 	,'(( 's+;'<&=U3G[C\B]]abefzb{a||  AD  EO  AP  @Q  QS  	T)(* 's+;'<&=U3G[C\B]]abefzb{a||  AD  EO  AP  @Q  QS  	T+(, 	-(. 	(/(0 	1(2 	$3(4 	5(6 "'*@"A!B"E7(8 4G<X4Y3ZZ\]9(: 6g>]6^5__ab;(< 08T0U/VVXY=(> =WEj=k<llno?(@ -W5P-Q,RRTUA(B 	C(D 	E(F 	G(H 	%I(J 	K(L 	AM(N 	$O(ER 6{v; 	CLLc-()s:.?tCH_D`Caadehelelmyez  fB  B  eC  CE  F	
 	()	LL   6{v; 	CLLc-()s:.?tCH_D`Caadehelelmyez  fB  B  eC  CE  F	
 	()	LL01	LLD1B)CDD	LL99Ur   c                   dId}| d   }| d   }dj                  d | d   D              }dj                  d | d   D              }d	j                  g 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&t        j                  | d'          d(d)d*d+|d,    d-|d.    d/|d0    d1|d    d2	d3|d,    d-|d.    d/|d0    d1|d    d2	d4d5d6d7| d8    d2d9| d:    d2d;| d<    d2d=| d"    d2d>| d?    d2d@| d$    d2d4dAdB ||dC         d4dDdB ||dC         d4dEdF| dGdHdF| dG      S )JNc                8    | sydj                  d | D              S )Nz&<tr><td colspan="4">No hits.</td></tr>r   c              3     K   | ]h  }d t        j                  |d          dt        j                  |d          d|d    dt        j                  |j                  d      xs d       d		 j y
w)z<tr><td><code>rO   </code></td><td><code>rP   </code></td><td>rQ   	</td><td>rR   r   
</td></tr>N)htmlescaper5   )r6   r7   s     r   r8   z.html_page.<locals>.hit_rows.<locals>.<genexpr>S  s      
 S%789 :S_56 7./0 1;;sww|4;<= >	
s   A.A0)r   )rowss    r   hit_rowszhtml_page.<locals>.hit_rowsP  s(    ;yy 
 
 
 	
r   rv   rw   r   c              3  N   K   | ]  }d t        j                  |       d  ywz<li>z</li>Nr   r   r   s     r   r8   zhtml_page.<locals>.<genexpr>_  s#     _D$t{{4017_   #%r   c              3  N   K   | ]  }d t        j                  |       d  ywr   r   r   s     r   r8   zhtml_page.<locals>.<genexpr>`  s#     ]dDT!2 359]r   r   r   zY<!doctype html><meta charset="utf-8"><title>Save Selector Predecessor Bridge Refs</title>a(  <style>body{font-family:system-ui,sans-serif;background:#111;color:#eee;max-width:1120px;margin:24px auto;line-height:1.45}table{border-collapse:collapse;width:100%;margin:16px 0 28px}td,th{border:1px solid #444;padding:6px 8px;vertical-align:top}th{background:#202020}code{color:#9bd4ff}</style>z.<h1>Save Selector Predecessor Bridge Refs</h1>z<p>predecessor <code>rm   z</code> root <code>rn   z</code> range <code>ro   z</code>; current <code>rr   rs   rt   z</code>.</p>z <p>predecessor -> current hits: rX   z; current -> predecessor hits: z; bridge found: rx   z; promotion status <code>r   z#<p>forward execution bridge found: ry   z; reverse hits to fill sites: r{   z!; reverse hits only before fill: r   z.</p>z<p>r   z</p>z<h2>Scan Summary</h2>z<table><thead><tr><th>direction</th><th>source range</th><th>target root range</th><th>readable dwords</th><th>hits</th></tr></thead><tbody>z0<tr><td>predecessor -&gt; current</td><td><code>rS   r   rT   r   rU   r   r   z0<tr><td>current -&gt; predecessor</td><td><code>z</tbody></table>z#<h2>Reverse Hit Classification</h2>zJ<table><thead><tr><th>metric</th><th>count/status</th></tr></thead><tbody>z#<tr><td>reverse reuse hits</td><td>rz   z5<tr><td>reverse hits before predecessor fill</td><td>r|   z7<tr><td>reverse hits at/after predecessor fill</td><td>r}   z1<tr><td>reverse hits to exact fill sites</td><td>z><tr><td>reverse hits before current writer 0x005428bc</td><td>r~   z.<tr><td>reverse hits only before fill</td><td>z'<h2>Predecessor -&gt; Current Hits</h2>zs<table><thead><tr><th>source</th><th>value</th><th>inside target range</th><th>exact label</th></tr></thead><tbody>rY   z'<h2>Current -&gt; Predecessor Hits</h2>z<h2>Remaining Proofs</h2>z<ul>z</ul>z<h2>Limitations</h2>)r   
list[dict]returnstr)r   r   r   )r   r   r   r   	remainingr   s         r   	html_pager   O  s   
 (
)C
(
)C_GL]D^__I'']gmF\]]K99 "e" 	s" 	9"  (= >??RSZ[oSpRq  rF  GN  Oh  Gi  Fj  jA  BI  J[  B\  A]  ]p  qx  yI  qJ  pK  K_  `g  h}  `~  _  K  	L	"
 +3z?*;;Z[^_i[jZkk{  }D  ER  }S  |T  Tm  nu  vG  nH  mI  IU  	V" .g6S.T-UUst{  }Y  uZ  t[  [|  }D  E`  }a  |b  bg  	h" dkk',/016" 	 " 	W" ;3?O;P:QQghk  mA  iB  hC  CS  TW  Xl  Tm  Sn  nw  x{  |F  xG  wH  HR  	S" ;3?O;P:QQghk  mA  iB  hC  CS  TW  Xl  Tm  Sn  nw  x{  |F  xG  wH  HR  	S" 	" 	." 	U" .g6L.M-NjY"  @Hd@e?ffpq!"" B'JiBjAkkuv#"$ <GD`<a;bblm%"& IQvIwHx  yC  	D'"( 9A\9]8^^hi)"* 	+", 	2-". 	~/"0 	V1"2 	3"4 	25"6 	~7"8 	V9": 	;"< 	$="> yk?"@ 	A"B {m5!C" " "r   c                    |j                  dd       |dz  j                  t        j                  | dd      dz   d	       |d
z  j                  t	        |       d	       y )NT)parentsexist_okz*save_selector_predecessor_bridge_refs.jsonF   )ensure_asciiindentr   r   r   *save_selector_predecessor_bridge_refs.html)mkdir
write_textr   dumpsr   )r   out_dirs     r   write_outputsr     sf    MM$M.;;GG

7q9D@ H  ;;GG	RYHZelGmr   c                 j   t        j                         } | j                  dt        t        dz         | j                  dt        t
               | j                         }t        |j                  j                               }t        ||j                         t        d|j                  dz          y )Nz--exezHwanse2.exe)typedefaultz	--out-dirz!wrote predecessor bridge refs -> r   )argparseArgumentParseradd_argumentr   ROOTr   
parse_argsr   r\   
read_bytesr   r   print)parserargsr   s      r   mainr     s    $$&F
dD=4HI
$<DDHH//12G'4<<(	-dll=i.i-j
klr   __main__)r   r.   r   r   )r   r.   r   r.   r   r   )r   r   r    r   r   r   )r'   bytesr(   r   r)   r.   r   
int | None)r   z
str | Noner   r   )r;   r   r<   r   r   dict)rC   r   r<   r   r   dict[int, str])rD   r   r   r   )r\   r   r(   r   r]   r.   r^   r.   r_   r.   r`   r.   ra   r   r   r   )NNNN)r\   r   r   list[dict] | Noner   r   r   dict | Noner   r   r   r   )r   r   r   r   )r   r   r   r   r   None)r   r   )1__doc__
__future__r   r   r   r   r%   syspathlibr   typingr   r   insertr   __file__resolveparentprobe_exe_scene_tablesr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r!   r+   r/   r?   rG   rL   rf   r   r   r   r   r   __name__r   r   r   <module>r     s   U "     
   3tH~--/667 8 > H~''*
Ul   $ " " $j1 +85-
&	&& & 	&
 & & "& 
&V /326*.&*D	D+D 0D (	D
 $D 
DNDN4nnm zF r   