
    7,JjJ                       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 ddlmZ ej                  j                  d e ee      j%                         j&                               ddlmZmZmZ ddlmZ  ee      j%                         j4                  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Z&dZ'ddgZ(h dZ)ddddddZ*dg d d!d"g d#d!d$g d%d!gZ+d@d&Z,dAdBd'Z-dCd(Z.dDd)Z/dDd*Z0dDd+Z1dDd,Z2dEd-Z3dFd.Z4dGd/Z5d0d1d2	 	 	 	 	 	 	 	 	 	 	 	 	 dHd3Z6dId4Z7dJd5Z8dKd6Z9	 	 	 	 	 	 	 	 dLd7Z:dMd8Z;	 	 	 	 	 	 	 	 	 	 	 	 	 	 dNd9Z<	 	 dO	 	 	 	 	 	 	 dPd:Z=dQd;Z>dQd<Z?efdRd=Z@dSd>ZAeBd?k(  r eA        yy)TzRCheck whether predecessor descriptor boundaries bridge to fill/current route code.    )annotationsN)deque)Path)Any)offset_to_varead_sectionsva_to_offset)section_name_for_va   outmap1_01amap2_02diG i
D iDH i\D i(D iT i*T i*T i+T iDH iDH >   .text.rdata.datazHroot-stop descriptor edge or node reaching the predecessor fill fragmentzYfill-stop descriptor edge or node reaching the current root, wrapper, frontier, or readerz]descriptor closure target edge classified as route execution rather than descriptor-only datazJencoded descriptor scalar attached to modeled route-execution control flowzLruntime trace or decoded non-linear VM path crossing the descriptor boundary)root-stop-to-fill-bridgefill-stop-to-current-bridgeroute-execution-target-edge,descriptor-encoded-route-target-control-flow$runtime-or-decoded-nonlinear-vm-pathHwanse2.exe)z'0x00440a9c root-stop descriptor closurez'0x00440c5c fill-stop descriptor closurez,0x004844d0/0x004844d8 predecessor fill sitesz0x00542b0c current reader)pathfieldsz1out/save_selector_data_descriptor_opcode_map.json)#predecessorRootStopIsDataDescriptor#predecessorFillStopIsDataDescriptor d0DescriptorSharedHandlerOpcodes c0DescriptorSharedHandlerOpcodesz;out/save_selector_predecessor_fill_execution_order_gap.json)	fillSiteslocalFillTraceStopHexcurrentRootHexcurrentReaderHex)rootEntryFixedTraversalFillSitesReachablec                    | d| dS d S )N0x08x values    V/home/exedev/hwanse/tools/summarize_save_selector_predecessor_descriptor_bridge_gap.pyhex32r*   V   s    $0Rc{:d:    c                x    | j                         s|i S |S t        j                  | j                  d            S )Nutf-8encoding)existsjsonloads	read_text)r   fallbacks     r)   	load_jsonr5   Z   s5    ;;=%r383::dnngn677r+   c                @    | sy 	 t        | d      S # t        $ r Y y w xY w)N   )int
ValueErrorr'   s    r)   	parse_hexr:   `   s+    5"~ s    	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       r)   dword_atrG   i   ?    (B'F~!c#h.dC033r+   c                v    t        ||      }||dz   t        |       kD  ry t        j                  d| |      d   S )N   z<Hr   r>   rB   s       r)   u16_atrK   p   rH   r+   c                v    t        ||      }||dz   t        |       kD  ry t        j                  d| |      d   S )NrJ   z<hr   r>   rB   s       r)   s16_atrM   w   rH   r+   c                v    t        ||      }||dz   t        |       kD  ry t        j                  d| |      d   S )Nr<   z<ir   r>   rB   s       r)   s32_atrO   ~   rH   r+   c                N    | D ]   }|d   }||d   z   }||cxk  r	|k  s|c S  " y )Nrawraw_sizer&   )rD   rF   sectionstartends        r)   section_for_offsetrV      sE     gj))F S N !
 r+   c                   t        j                  d|      }g }d}	 | j                  ||      }|dk  r	 |S |dz   }t        ||      }||d   t        vr:t        ||      }|I|j                  t        |      |d   d|dd       n)Nr=   r   r   namer$   06x)refVaHexrS   fileOffsetHex)r@   packfindrV   SCAN_SECTIONSr   appendr*   )	rC   rD   r(   needlerefssearchhitrS   ref_vas	            r)   
value_refsre      s    [[u%FDF
hhvv&7 K q$Xs3?gfo]Bh,>fv!#c^
 	 r+   c                j    |j                  d      xs g D ]  }|j                  d      | k(  s|c S  i S )Nsitesroleget)rh   descriptor_maprows      r)   site_from_descriptor_maprm      s=    !!'*0b 776?d"J Ir+   r7   i  )window_dwords	max_nodesc                  t        |g      }g }t               }g }	g }
|j                         D ci c]  }|d }}|j                         D ci c]  }|d }}|rdt        |      |k  rU|j	                         }||v r'|j                  |       |j                  |       ||v r|||   xx   dz  cc<   g }t        |      D ]  }||dz  z   }t        | ||      }|t        ||      nd }|dk(  s.t        |      t        |      t        |      |j                  |      |d}|	j                  |       |j                  |       ||v r|||   xx   dz  cc<   ||vs|j                  |        |
j                  t        |      ||v |j                  |      t        |      |d d d       |rt        |      |k  rUt        |      ||t        |      t        |      t        |	      |||	D cg c]  }|j                  d      s| c}|d d	 D cg c]  }t        |       c}|D cg c]  }t        |       c}|
d d	 d
S c c}w c c}w c c}w c c}w c c}w )Nr   r   r<   r   )sourceVaHexsourceNodeHexvalueHextargetLabeltargetSection   )	nodeVaHexisTargetNodert   pointerCountInWindowpointerValuesrt       )startHexwindowDwordsmaxNodesvisitedNodeCount	truncated	edgeCounttargetNodeHitstargetEdgeHitstargetEdgeRows
firstNodesvisitedNodesHexnodeRows)r   setvaluesr?   popleftaddr_   rangerG   r
   r*   rj   bool)rC   rD   start_vatargetsrn   ro   queueseenseen_setedges	node_rowslabeltarget_node_hitstarget_edge_hitsrE   pointer_valuesindexrow_var(   rS   edges                        r)   descriptor_closurer      si    8*EDHEI>Enn>N'OUq'O'O>Enn>N'OUq'O'O
CI	)]]_>RB=WR[)Q.)=) 	(E%!)^FS(F3E>C>O)(E:UYG'!#(=%*2Y %e#*;;u#5%, T"%%d+G#$WU^494(LL'#	($ 	r'M";;r?$'$7+CR0
 	9 CI	)J (O%I%[Z**,1MDTXXm5L4M15cr;uU|;6:;UE%L;crN O (P'O^ N;;s#   
I
I0III,Ic                    g }|j                         D ]X  \  }}t        | ||      }|j                  |t        |      t	        |      t        |D ch c]  }|d   	 c}      |d d d       Z |S c c}w )NrS      )r   	targetHexrefCountrefSectionsra   )itemsre   r_   r*   r?   sorted)rC   rD   r   rowsr(   r   ra   refs           r)   target_ref_rowsr      s}    D u#x/uD	!T"Bc3y>"BC"I
 	 K #Cs   A0c                ,     t         fd|D              S )Nc              3  B   K   | ]  }j                  |d         yw)r   Nri   ).0r   hitss     r)   	<genexpr>znonzero_hits.<locals>.<genexpr>   s     6etxxq!6s   )sum)r   labelss   ` r)   nonzero_hitsr      s    6v666r+   c                   g }|j                  d      xs g D ]  }t        |j                  d            }t        |j                  d            }|j                  | |j                  d      |j                  d      ||t        ||z
        nd |j                  d      |j                  d      |j                  d      d        |S )Nr   rq   rr   rs   rt   ru   )closurerr   rq   sourceOffsetFromNodeHexr   rt   ru   )rj   r:   r_   r*   )closure_namer   r   rl   	source_vasource_nodes         r)   compact_target_edge_rowsr     s    D{{+,2 cggm45	 89# WW_577=1$)@ (-Y-D'E,77=1 WW_5

 
	 Kr+   c                   t        d|       }t        d|      }h d}|D cg c]  }|j                  d      |v s| }}|D cg c]  }|j                  d      |v s| }}|D cg c]  }|j                  d      |v s| }	}|D cg c]  }|j                  d      |v s| }
}t        |      t        |      t        |	      t        |
      t        |D ch c]  }|j                  d       c}      t        |D ch c]  }|j                  d       c}      t	        |xs |      xr |	 xr |
 ||d	S c c}w c c}w c c}w c c}w c c}w c c}w )Nroot-stop-descriptorfill-stop-descriptor>   e8-route-descriptorc0-fill-stop-descriptord0-root-stop-descriptorrt   )	rootDescriptorTargetEdgeCountfillDescriptorTargetEdgeCount!rootRouteExecutionTargetEdgeCount!fillRouteExecutionTargetEdgeCountrootDescriptorOnlyTargetLabelsfillDescriptorOnlyTargetLabelssharedDescriptorOnlyrootTargetEdgeRowsfillTargetEdgeRows)r   rj   r?   r   r   )root_closurefill_closureroute_execution_labels	root_rows	fill_rowsdescriptor_labelsrl   root_descriptor_rowsfill_descriptor_rowsroot_route_rowsfill_route_rowss              r)   descriptor_target_edge_summaryr     s_   
 ))?NI()?NIe+4dC8NRc8cCdd+4dC8NRc8cCdd&/ds377=3IMc3csdOd&/ds377=3IMc3csdOd),-A)B),-A)B-0-A-0-A*0Th1iS#''-2H1i*j*0Th1iS#''-2H1i*j $%9%Q=Q R ! ! '' 	 eddd 2j1is:   D<D<EE'E E
E#EEEc                T   | j                  d      xs g }| j                  d      xs g }||z   }| j                  d      xs d}| j                  d      xs d}| j                  d      xs d}| j                  d      xs d}||z   }||z   }	t        |      xr t        d |D              }
|r|	dk(  r| j                  d	      d
u r|
rd}n|	rd}n
|dk(  rd}nd}|||	||||| j                  d	      d
u |
| j                  d      xs g | j                  d      xs g |dk(  rddS ddS )Nr   r   r   r   r   r   r   c              3  D   K   | ]  }|j                  d       dk(    yw)ru   r   Nri   )r   rl   s     r)   r   z4descriptor_edge_rejection_summary.<locals>.<genexpr>;  s#      603 G+6s    r   Tz'descriptor-only-no-route-execution-edgezroute-execution-edge-candidatezno-descriptor-target-edgezreview-requiredr   r   blocked)classificationdescriptorTargetEdgeCountrouteExecutionTargetEdgeCountr   r   r   r   r   allTargetSectionsDatar   r   promotionStatus)rj   r   all)edge_summaryr   r   all_rowsroot_descriptor_countfill_descriptor_countroot_route_countfill_route_countdescriptor_edge_countroute_execution_edge_countall_target_sections_datar   s               r)   !descriptor_edge_rejection_summaryr   1  s     !56<"I  !56<"I9$H(,,-LMRQR(,,-LMRQR#''(KLQPQ#''(KLQPQ14II!14D!D#H~  # 67?6 3 	&!+34<$B	#9	!	#4*(%:)C)>)>-=-= , 0 01G HD P!9*6*:*:;[*\*b`b*6*:*:;[*\*b`bFF %   r+   c                   t        |      }|j                         D cg c]  \  }}||v r||f }	}}g }
t               }d|fd|ffD ]>  \  }}|j                  d      xs d}|j                  d      xs g D ]
  }t        |      }|t	        |      D ]  }||dz  z   }t        ||      }|dk7  rdt        | ||      d fd	t        | ||      |d
z   fdt        | ||      |dz   fg}|D ]  \  }}}|
|	D ]  \  }}|dk(  r	||dz  k(  }n|d uxr ||z   |k(  }|s%||||f}||v r0|j                  |       |
j                  |||t        |      t        ||z
        t        |dz        t        |      ||ddd           A |
D cg c]  }|d   dk(  s| }}|
D cg c]  }|d   dk(  s| }}i }i } |
D ]>  }|j                  |d   d      dz   ||d   <   | j                  |d   d      dz   | |d   <   @ |
rdnd}!|!t        |
      t        |      t        |      dt        t        |j                                     t        t        | j                                     |
d d dd	S c c}}w c c}w c c}w )Nr   r   r}   r   r   r<   r   z	abs16-lowzsigned-rel16-site-plus2rJ   zsigned-rel32-site-plus4i  l    r   F)r   kindrr   	slotVaHexslotOffsetFromNodeHexrs   r   rt   sourceSectionr   promotesRouteExecutionr   rt   r   r   z4descriptor-encoded-route-target-scalars-nonpromotingz-no-encoded-route-target-in-descriptor-closurer   )	r   rawScalarCandidateCountrootRawScalarCandidateCountfillRawScalarCandidateCountpromotingCandidateCounttargetLabelCounts
kindCounts
sampleRowsr   )r   r   rj   r:   r   r
   rK   rM   rO   r   r_   r*   r?   dictr   )"rC   rD   r   r   r   r   route_label_settargetr   target_itemsr   r   r   r   rn   node_hexnode_var   slot_vasource_sectionr   r   r(   rel_base	target_vatarget_labelmatcheskeyrl   r   r   target_countskind_countsr   s"                                     r)   descriptor_encoded_target_scanr   ]  sJ    01O %]]_FEO# 
L 
 D+.5D 
 .	." -g  N38q$56<" (	H)G}- $!EAI-!4Xw!G!W, &h"@$G.sHg0NPWZ[P[\.sHg0NPWZ[P[\
 .4 )D%} 3? /	<;.&+	F0B&CG&.d&:&\x%?OS\?\G&$+T7IF$;$'3$(-5).w5:7W;L5M(-ej.@(A).y)9+7-;/86;% $	(	-^ !%QI:P(PQIQ $QI:P(PQIQ$&M"$K G,9,=,=c->PRS,TWX,Xc-()#.??3v;#BQ#FCK G
  	?<  )#&t9'*9~'*9~#$!&)<)<)>"?@6+"3"3"5673Bi$
 
Gn RQs   I1I7I7&I<4I<c                d
   |xs i }|xs i }t        |       }|j                  dg       D cg c]  }t        |       c}xs t        }|D cg c]  }||	 }}t        dt
        dt        dt        dt        dt        dt        dt        d	t        d
i	}t        |      D ]  \  }}d| ||<    t        d|      }t        d|      }	t        | |t        |      }
t        | |t
        |      }t!        | ||      }|D ci c]  }|d   |d    }}|j#                         D cg c]  }|j%                  d      s| }}|j'                  d       g d}t)        t+        ||z               }t-        |
||      }t/        |      }t1        | ||
|||      }t3        |
d   |      t3        |
d   |      z   dkD  }t3        |d   |      t3        |d   |      z   dkD  }|d   j                  dd      dkD  }|xr |}g }|s|j'                  d       |s|j'                  d       |d   dk(  r|j'                  d       |d   dk(  r|j'                  d       |s|j'                  d       |D cg c]  }t4        |    }}d|sdndd|
d     d!|
d"    d#|
d    d$d%|r|sd&ndd'|d     d!|d"    d#|d    d$d(d)d*| d$d+|d,   rd-nd.d/|d0    d1|d2    d3|d4    d5|d6    d7|d8    d9|d:    d$d;|d<   d=|d0    d>|d2    d?|d4    d>|d6    d@|dA    d7|d8    d9|d:    dB|dC    d$dD|d<   dE|dF    dG|dH    d>|dI    dJ|d    dK|dL    dM|dN    d$g}dO}i dPt6        dQt8        dR|j                  dR      xs dSdT|j                  dT      xs dUdVt;        t              dWt;        t              dX|dYt;        t              dZt;        t
              d[|	d|D cg c]  }t;        |       c}d\t;        t              d]t;        t              d^t;        t              d_t;        t              d`|da|i db|
dc|dd|de|df|d<   dg|dA   dh|di   dj|d   dk|d0   dl|d2   dm|d4   dn|d6   do|d8   dp|d:   dq|dr|d<   ds|dF   i dt|dH   du|dI   dv|d   dw|dL   dx|dN   dy|
d   j                  dd      dkD  xs |
d   j                  dd      dkD  dz|d{|d||d}|d~|d|d|dt<        dt?        t<              dCdd|g d|dS c c}w c c}w c c}w c c}w c c}w c c}w )Nr   r   r   r   zpredecessor-root-stop-sitezpredecessor-fill-stop-sitecurrent-rootwrapper-leaffrontier-leafcurrent-readerzpredecessor-fill-site-zpredecessor-root-entry-stopzpredecessor-fill-fragment-stopr   r   zpredecessor-fill-site)r  r  r  r  r   r   r   r   r   r   r   r   r   r   zroot-stop-descriptor-closurezno-fill-site-bridgezbridge-candidatezd0 closure nodes=r   z edges=r   z targetEdges=)r   statusdetailzfill-stop-descriptor-closurezself-loop-no-current-bridgezc0 closure nodes=zdirect-target-ref-scanz&route-target-refs-absent-or-table-onlyz
refCounts=z%descriptor-target-edge-classificationr   zshared-descriptor-onlyzroute-edge-candidatezrootDescriptorEdges=r   z; fillDescriptorEdges=r   z; rootRouteEdges=r   z; fillRouteEdges=r   z; rootLabels=r   z; fillLabels=r   zdescriptor-edge-rejectionr   zdescriptorEdges=/z; routeEdges=z; allTargetSectionsData=r   z	; status=r   zdescriptor-encoded-target-scanzraw=r   z; root/fill=r   r   z; promoting=z
; targets=r   z; kinds=r   as  The predecessor root stop descriptor 0x00440a9c has a complete bounded .data pointer closure that reaches shared descriptor data, including the c0 fill-stop descriptor, but it does not contain an edge or node for the predecessor fill sites or the 0x004844dc fill-fragment stop. The fill-stop descriptor 0x00440c5c forms a small self-referential descriptor closure and has no edge to the current root, wrapper leaf, frontier leaf, or reader. The encoded target scan over descriptor closure slots adds no modeled route-execution edge; any encoded scalar matches remain descriptor data, not a control-flow bridge. This closes the obvious descriptor pointer/scalar bridge and leaves the predecessor fill/current-reader order blocked behind a real execution trace or decoded non-linear VM path. The target-edge rows are classified as descriptor-only data edges, not route-execution edges.sourcer   predecessorSelectorz1:0currentSelectorz2:0predecessorRootStopSiteHex predecessorRootStopDescriptorHexpredecessorRootStopSitepredecessorFillStopSiteHex predecessorFillStopDescriptorHexpredecessorFillStopSiter    wrapperLeafHexfrontierLeafHexr!   
targetRefstargetRefCountsrootStopDescriptorClosurefillStopDescriptorClosuredescriptorTargetEdgeSummarydescriptorEdgeRejection%descriptorEdgeRejectionClassification#descriptorEdgeAllTargetSectionsData'descriptorEdgeDescriptorTargetEdgeCountr   +descriptorEdgeRouteExecutionTargetEdgeCount+descriptorEdgeRootDescriptorTargetEdgeCount+descriptorEdgeFillDescriptorTargetEdgeCount/descriptorEdgeRootRouteExecutionTargetEdgeCount/descriptorEdgeFillRouteExecutionTargetEdgeCount,descriptorEdgeRootDescriptorOnlyTargetLabels,descriptorEdgeFillDescriptorOnlyTargetLabelsdescriptorEncodedTargetScan%descriptorEncodedTargetClassification.descriptorEncodedTargetRawScalarCandidateCount2descriptorEncodedTargetRootRawScalarCandidateCount2descriptorEncodedTargetFillRawScalarCandidateCount.descriptorEncodedTargetPromotingCandidateCount"descriptorEncodedTargetLabelCounts!descriptorEncodedTargetKindCounts(rootStopClosureReachesFillStopDescriptorrootStopToFillBridgeFoundfillStopClosureSelfLoopFoundfillStopToCurrentBridgeFounddescriptorBridgeProofFound
proofFoundfailedDescriptorBridgeGateIdsmissingEvidenceevidenceRefsevidenceRefCountr   evidence)zCobserve execution from 0x004783e0 into the 0x004844d0 fill fragmentzZdecode a non-linear VM path that legally crosses the 0x00440a9c/0x00440c5c descriptor datazSobserve or decode execution from the fill fragment toward current reader 0x00542b0c)remainingProofs
conclusion) r   rj   r:   DEFAULT_FILL_SITESROOT_STOP_DESCRIPTORFILL_STOP_DESCRIPTORE8_DESCRIPTORROOT_STOP_SITEFILL_STOP_SITECURRENT_ROOTWRAPPER_LEAFFRONTIER_LEAFCURRENT_READER	enumeraterm   r   r   r   
startswithr_   r   r   r   r   r   r   *DESCRIPTOR_BRIDGE_MISSING_EVIDENCE_BY_GATEROUTE_SOURCEROUTE_TARGETr*   DESCRIPTOR_BRIDGE_EVIDENCE_REFSr?   )rC   rk   $predecessor_fill_execution_order_gaprD   r(   
fill_sitesr   r   root_stop_sitefill_stop_siter   r   target_refsrl   
ref_countsr   root_to_fill_labelsfill_to_current_labelsr   r   edge_rejectionencoded_target_scanroot_stop_to_fill_bridge_found!fill_stop_to_current_bridge_foundc0_self_loop_founddescriptor_bridge_proof_found!failed_descriptor_bridge_gate_idsgate_idmissing_evidencer5  r7  s                                  r)   build_summaryrY    s	   
 $)rN+O+USU(S!H :==k2N 	%  
  &0EE53D%EJE77,44nn(
G "*- :u1%9: ..K^\N-.NP^_N%c85I7SL%c85I7SL!#x9K;FGC#g,J/GJG.5nn.>lU%BRBRSjBk5ll;<`#C(;>T(T$UV1,NdeL6|DN8 	\"235HI
|$457J
K	L	&
"
 	\"235KL
|$457M
N	O	)
% &&67;;<UWXY\]]$B$hGh!(*%))001KL,)001NO56!;)001NO45:)001_`()001WX 9 	37;  33Q+Wi#L1C$D#EW\ZeMfLg h+,<=>@		
 3!*K 4##L1C$D#EW\ZeMfLg h+,<=>@		
 ->":,/	
 <2>?U2V.\r&|4S'T&U V''34S'T&U V""./R"S!T U""./R"S!T U*+KLM N*+KLMO		
 0$%56"!"ABC1!"ABC D!"EFGq!"EFG H))78O)P(Q R,-MNO P,-MNO P():;<	>		
" 5)*:;*+DEF G01NOPPQ&'DEF G01JKL M./BCD E,\:;=		
i@HD	! S,S,S 	CGGH]^gbgS 	?CCDUV_Z_	S
 	%eN&;S 	+E2F,GS 	">S 	%eN&;S 	+E2F,GS 	">S 	
;ueEl;S 	%-S 	%-S 	5/S 	E.1S  	k!S" 	:#S$ 	$\%S& 	$\'S( 	&|)S* 	">+S, 	0@P1Q-S. 	.~>U/V/S0 	2>B]3^1S2 	6~+8
3S8 	6~+8
9S> 	6~+8
?SD 	:>/<
ESJ 	:>/<
KSP 	7,9
QSV 	7,9
WS\ 	&':]S^ 	01DEU1V_S` 	9:M%;
aSf 	=>Q)?
gSl 	=>Q)?
mSr 	9:M%;
sSx 	-.ABU.VySz 	,-@-N{S| 	3)*../H!LqP T,-112KQORSSASD 	$%CESF 	'(:GSH 	'(IISJ 	%&CKSL 	3MSN 	()JOSP 	+QSR 	7SST 	C ?@USV 	9WSX 	HYSZ

 !eS S] F( HlHv <s/   TTT;TT#6T##T(T-c                   ddd| d    d| d    d| d    d| d	    d
| d    d| d    dd| d    d| d    dddj                  | 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)| j                  d*       d+dj                  | j                  d,      xs g       xs d- dd.t        | j                  d/      xs g        d0| j                  d1       d2| d3    d| d4   dd5dd6d7g}| d8   D ]&  }|j                  d9|d:    d;|d<    d;|d=    d>       ( |j	                  g d?       | d@   D ]?  }|j                  d9|dA    dB|dC    dD|dE    d;dj                  |dF         xs d- d>	       A | dG   }| dH   }|j	                  ddIddJ|dK    dL|dM    dN|dO    dP|dQ    dR|dS    dT|dU    ddV|dW    d!|dX    dY|dZ    dd[d\g       |d]   |d^   z   D ]8  }|j                  d9|d_    dB|d`    da|db    da|dc    da|dC    dD|dd    d>       : |j	                  g de       dfD ]  \  }}| |   }|j	                  dg| ddh|di    ddj|dk    dl|dm    dn|do    dp|dq    dr|ds    ddtd7g       |du   D ]6  }|j                  dv|dw    dD|dx    d;|j                  dd      xs d- d>       8 |j                  d        |j	                  dydg       | dz   D ]  }|j                  d{|         |j                  d       d|j                  |      S )}Nz1# Save Selector Predecessor Descriptor Bridge Gap z	- route: r  z -> r   z!- predecessor/current selectors: r	  r
  z- root stop: `r  z` -> `r  `z- fill stop: `r  r  z- fill sites: , r   z- current reader: `r!   z&- root closure reaches c0 descriptor: r+  z"- root stop to fill bridge found: r,  z%- fill stop closure self loop found: r-  z%- fill stop to current bridge found: r.  z5- descriptor encoded target raw/root/fill/promoting: r%   / r&  r'  r(  z-- descriptor encoded target classification: `r$  z!- descriptor bridge proof found: r/  z- proof found: r0  z#- failed descriptor bridge gates: `r1  -z- missing evidence count: r2  z- evidence refs: r4  z- promotion status: r   r7  z## Evidencez| kind | status | detail |z| --- | --- | --- |r5  z| r   z | r  r  z |)r[  z## Target Refsr[  z$| label | target | refs | sections |z| --- | --- | --- | --- |r  r   z | `r   z` | r   r   r  r  z## Target Edge Classificationz- shared descriptor only: r   z - root descriptor target edges: r   z - fill descriptor target edges: r   z%- root route execution target edges: r   z%- fill route execution target edges: r   z- descriptor edge rejection: `r   z,- descriptor / route execution edge counts: r   r   z- all target sections data: r   z<| closure | source node | source | offset | target | label |z%| --- | --- | --- | --- | --- | --- |r   r   r   rr   z` | `rq   r   rt   )r[  z## Descriptor Closuresr[  )zRoot Stop Descriptor Closurer  )zFill Stop Descriptor Closurer  z### z
- start: `r|   z- visited nodes: r   z	- edges: r   z- truncated: r   z- target node hits: r   z- target edge hits: r   z!| node | pointer count | target |r   z| `rw   ry   z## Remaining Proofsr6  z- 
)joinrj   r?   r_   extend)	summarylinesrl   r   rP  titleclosure_keyr   proofs	            r)   markdownri    s   ;

GH%&d78+<*=>
+G4I,J+K4PWXiPjOkl
!=>?vgNpFqErrst
!=>?vgNpFqErrst
7;#789:
g&89:!<
09c1d0ef
,W5P-Q,RS
/8V0W/XY
/8V0W/XYCGHIKLMSKLMSGHI	K 8@g8h7iijk
+G4P,Q+RS
'++l345
-diiDc8d8jhj.k.ror-sstu
$S5F)G)M2%N$OP
GKK(:;<=
w'89:;


$C"EF z" Or#f+c#h-CM?"MNO	LLpq|$ 
Wd3{#3"4DZ8ITYYWZ[hWiMjMqnqLrrtu	

 89L67N	LL
'

$\2H%I$JK
*<8W+X*YZ
*<8W+X*YZ
/=`0a/bc
/=`0a/bc
(8H)I(J!L
6~Fa7b6ccfgu  wV  hW  gX  	Y
&~6M'N&OP
F/   01LAU4VV 
Y S%9$:%M@R?S T-./uS5E4Fd3}K]J^^`b	


 
LL34 { +&5'N,-Q/(: ;<=,-.GK012"7+;#<"=>"7+;#<"=>/!
 	 :& 	CLLc+&'tC0F,G+HCGGTaLbLifiKjjlm	 	R-. 
LL',-*+ #r%\"#	LL99Ur+   c           .        d~ddj                  fd| d   D              }dj                  fd| d   D              }| d   }| d   }dj                  fd	|d
   |d   z   D              }g }dD ]  \  }}| |   }	dj                  fd|	d   D              }
|j                  d |       d |	d          d |	d          d |	d          d |	d          d |	d          d |	d          d|
 d        dj                  fd| d   D              }d j                  d!d"d#d$d%d&d'd(d)d*d+ | d,          d- | d.          d/ | d0          d1 | d2          d3 | d4          d5d6 | d7          d- | d8          d9 | d:          d- | d;          d< d=j                  | d>                d? | d@          dAdB | dC          dD | dE          dF | dG          dH | dI          dJ | dK          dL | dM          dL | dN          dL | dO          dP | dQ          dR | dS          dT | j                  dU             dV d=j                  | j                  dW      xs g       xs dX       dY t        | j                  dZ      xs g              d[ | j                  d\             d5d] | d^          d_d`dadb| ddcdddb| ddedf |dg          dh |di          dj |dk          dl |dm          dn |do          dp |dq          dr |ds          dt |du          dv |dw          d5dxdb| dd j                  |      dydz| d{d|d}dg      S )Nc                >    t        j                  t        |             S N)htmlescapestrr'   s    r)   esczhtml_page.<locals>.esc  s    {{3u:&&r+   r[  c           
   3  l   K   | ]+  }d  |d          d |d          d |d          d - yw)<tr><td>r   	</td><td>r  r  
</td></tr>Nr&   r   rl   rp  s     r)   r   zhtml_page.<locals>.<genexpr>  s\       	3v;  !3x=!" #3x=!" #	s   14r5  c              3     K   | ]J  }d  |d          d |d          d |d          d dj                  |d         xs d	       d
	 L yw)rr  r   </td><td><code>r   </code></td><td>r   rs  r]  r   r_  rt  N)rb  ru  s     r)   r   zhtml_page.<locals>.<genexpr>  s       	3w< ! "[)*+ ,3z?#$ %499S/07C89 :		s   AAr  r  r  c              3     K   | ]O  }d  |d          d |d          d |d          d |d          d |d          d |d	          d
 Q yw)rr  r   rw  rr   z</code></td><td><code>rq   r   r   rx  rt   rt  Nr&   ru  s     r)   r   zhtml_page.<locals>.<genexpr>  s      
 	3y>"# $_-./ 0]+,- .6789 :[)*+ ,3}%&' (	
s   AAr   r   r`  c              3     K   | ];  }d  |d          d |d          d |j                  d      xs d       d = yw)	z<tr><td><code>rw   rx  ry   rs  rt   r_  rt  Nri   ru  s     r)   r   zhtml_page.<locals>.<genexpr>+  si      
 S-./ 0s1234 5sww}-456 7
s   AAr   z<h2>z</h2><p>start <code>r|   z</code>; visited nodes: r   z	; edges: r   z; truncated: r   z; target node hits: r   z; target edge hits: r   z].</p><table><thead><tr><th>node</th><th>pointer count</th><th>target</th></tr></thead><tbody>z</tbody></table>c              3  6   K   | ]  }d  |       d  yw)z<li>z</li>Nr&   )r   rh  rp  s     r)   r   zhtml_page.<locals>.<genexpr>;  s     [uDUE2[s   r6  ra  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">z@  <title>Save Selector Predecessor Descriptor Bridge Gap</title>a    <style>body{margin:24px;background:#101010;color:#eee;font:14px system-ui,sans-serif}table{border-collapse:collapse;width:100%;margin:16px 0 28px}th,td{border:1px solid #333;padding:6px 8px;vertical-align:top}th{background:#1d1d1d}code{color:#f5d76e}</style>z</head>z<body>z:  <h1>Save Selector Predecessor Descriptor Bridge Gap</h1>z  <p>route <code>r  z</code> -&gt; <code>r   z</code>; selectors r	  z -&gt; r
  z; promotion status: r   z.</p>z  <p>root stop <code>r  r  z</code>; fill stop <code>r  r  z</code>; fill sites r]  r   z; current reader <code>r!   z</code>.</p>z)  <p>root closure reaches c0 descriptor: r+  z"; root stop to fill bridge found: r,  z%; fill stop closure self loop found: r-  z%; fill stop to current bridge found: r.  z5; descriptor encoded target raw/root/fill/promoting: r%  r  r&  r'  r(  z,; descriptor encoded target classification: r$  z!; descriptor bridge proof found: r/  z; proof found: r0  z"; failed descriptor bridge gates: r1  r_  z; missing evidence count: r2  z; evidence refs: r4  z  <p>r7  z</p>z  <h2>Evidence</h2>zL  <table><thead><tr><th>kind</th><th>status</th><th>detail</th></tr></thead>z	  <tbody>z  <h2>Target Refs</h2>z\  <table><thead><tr><th>label</th><th>target</th><th>refs</th><th>sections</th></tr></thead>z%  <h2>Target Edge Classification</h2>z  <p>shared descriptor only: r   z; root descriptor edges: r   z; fill descriptor edges: r   z; root route execution edges: r   z; fill route execution edges: r   z; descriptor edge rejection: r   z,; descriptor / route execution edge counts: r   r^  r   z; all target sections data: r   z  <table><thead><tr><th>closure</th><th>source node</th><th>source</th><th>offset</th><th>target</th><th>label</th></tr></thead>z  <h2>Remaining Proofs</h2>z  <ul>z</ul>z</body>z</html>)r(   r   returnro  )rb  r_   rj   r?   )rd  evidence_rowstarget_rowsr   rP  	edge_rowsclosure_sectionsrf  rg  r   r   proof_itemsrp  s               @r)   	html_pager    s   ' GG  :& M ''  <( K 89L67N 
   45EY8ZZ
 
I  
{ +&ww 
 z*
 
 	3u:, !'*"5677OPST[\nToPpOq r'+./0c'+BV>W=X Y!!$W-=%>!? @@TUXY`aqYrUsTt uV+-	

* ''[HY@Z[[K99"PJ 	OD
C 1233GGT\L]H^G_ `!6789WM^E_A`@a b ):!;<=U	D  G,H$I JK LW?@AB CW9:;< =W?@ABBVtyy-./
00GGTfLgHhGiiu		w
 4C@j8k4l3m n++.w7R/S+T*U V..1':X2Y.Z-[ \..1':X2Y.Z-[ \>wGHI
J!wKLM
NawKLM
NawGHI
J K558Ah9i5j4k l**-g6R.S*T)U VGKK567 8++.tyyEd9e9kik/l/sps+t*u v##&s7;;7H+I+OR'P#Q"R Sgkk*<=>?u	F GL)*+40V
M?"23 f
K= 01/
'L9O,P(Q'R S""%l3R&S"T!U V""%l3R&S"T!U V''*<8[+\']&^ _''*<8[+\']&^ _&&).9I*J&K%L M558Hc9d5e4ffi~=>?
@ A%%(8O)P%Q$RRW	Y 	K
I;./		"#%
U#
u; ; ;r+   c                    |j                  dd       |dz  j                  t        j                  | dd      dz   d	       |d
z  j                  t	        |       d	       y )NT)parentsexist_okz4save_selector_predecessor_descriptor_bridge_gap.jsonFrJ   )ensure_asciiindentra  r-   r.   4save_selector_predecessor_descriptor_bridge_gap.html)mkdir
write_textr1   dumpsr  )rd  out_dirs     r)   write_outputsr  z  sk    MM$M.EEQQ

7q9D@ R  EEQQ' R r+   c                 T   t        j                  t              } | j                  dt        t
        dz         | j                  dt        t        dz         | j                  dt        t        dz         | j                  d	t        t               | j                         }t        |j                  j                         t        |j                        t        |j                              }t        ||j                         t!        d
|d   d    d|j                  dz          y )N)descriptionz--exer   )typedefaultz--descriptor-mapz-save_selector_data_descriptor_opcode_map.jsonz--predecessor-fill-orderz7save_selector_predecessor_fill_execution_order_gap.jsonz	--out-dirz7wrote save-selector predecessor descriptor bridge gap (r  r   z root nodes) -> r  )argparseArgumentParser__doc__add_argumentr   ROOTOUT
parse_argsrY  rC   
read_bytesr5   rk   predecessor_fill_orderr  r  print)parserargsrd  s      r)   mainr    s   $$9F
dD=4HI
*sEt?tu
"OO  
 $<D$%%&$--.G
 '4<<(		/01CDEEU<<PP
Q	Sr+   __main__)r(   
int | Noner|  
str | Nonerl  )r   r   r4   z
Any | Noner|  r   )r(   r  r|  r  )rC   bytesrD   
list[dict]rE   r8   r|  r  )rD   r  rF   r8   r|  dict | None)rC   r  rD   r  r(   r8   r|  r  )rh   ro  rk   r   r|  r   )rC   r  rD   r  r   r8   r   dict[int, str]rn   r8   ro   r8   r|  r   )rC   r  rD   r  r   r  r|  r  )r   zdict[str, int]r   	list[str]r|  r8   )r   ro  r   r   r|  r  )r   r   r   r   r   r  r|  r   )r   r   r|  r   )rC   r  rD   r  r   r   r   r   r   r  r   r  r|  r   )NN)rC   r  rk   r  rH  r  r|  r   )rd  r   r|  ro  )rd  r   r  r   r|  None)r|  r  )Cr  
__future__r   r  rm  r1   r@   syscollectionsr   pathlibr   typingr   r   insertro  __file__resolveparentprobe_exe_scene_tablesr   r   r	   summarize_script_handler_tabler
   r  r  r  rE  rF  r<  r9  r=  r:  r;  r>  r?  r@  rA  r8  r^   rD  rG  r*   r5   r:   rG   rK   rM   rO   rV   re   rm   r   r   r   r   r   r   r   rY  ri  r  r  r  __name__r&   r+   r)   <module>r     s   X "     
    3tH~--/667 8 L L > H~''*
Ul! !  *- , 	S 	d 	h 	U 	W. *& 
 D
 N
	'# @;84444. B	BB B 	B B B 
BJ7& & 
	6)XV	VV V 	V
 V &V 
Vv #'8<i	ii +6i 
	iX^Btn 25 	0 zF r+   