
    Lj9                       d Z ddlm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mZmZ ddlmZ  ee      j#                         j$                  d   Zed	z  Zed
z  Zedz  Zedz  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'dZ"d(dZ#d)dZ$d*dZ%d+dZ&d,dZ'd-dZ(d.d/dZ)d0d1dZ*d2d Z+d3d!Z,d4d"Z-d5d#Z.d6d$Z/e0d%k(  r e/        yy)7aP  Trace the HUD top-menu VM graph around the remaining opener boundary.

The x86 and descriptor-stack reviews already proved the #6/#3/#4 HUD menu
payload and ruled out a number of direct opener shapes.  This pass focuses on
the nearby VM command/data graph so later analysis does not accidentally promote
table bytes as command streams.
    )annotationsN)Path)Any)offset_to_varead_sectionsva_to_offset)decode_stream   zHwanse2.exeoutwebz&hud_menu_vm_graph_frontier_review.jsonz&hud_menu_vm_graph_frontier_review.htmli8D i8@ i$G idG ipG iG iG ilM i,J c                    | dS d| d| dS )N-0x0x )valuewidths     0tools/build_hud_menu_vm_graph_frontier_review.pyhxr   )   s#    -3;r%%z):%;;    c                V    t        j                  | dd      S t        |       d      S )N T)quote)htmlescapestr)r   s    r   hr   -   s%    ;;U]r$GGE
$GGr   c                    |y | D ]?  }t        |d         }|t        |d         z   }||cxk  r|k  s.n 1t        |d         c S  y )Nvaraw_sizename)intr   )sectionsr    sectionstartends        r   section_name_forr(   1   s\    	z (GDM"c'*-..Bwv''	(
 r   c                v    t        ||      }||dz   t        |       kD  ry t        j                  d| |      d   S )N   <Ir   )r   lenstructunpack_from)exer$   r    offs       r   dword_atr1   <   s?    
x
$C
{cAgC(dC-a00r   c                0    t        ||      }|y| |||z    S )Nr   )r   )r/   r$   r    sizer0   s        r   bytes_atr4   C   s'    
x
$C
{sS4Z  r   c                    t        j                  d|      }g }| j                  |      }|dk7  r:t        ||      }||j	                  |       | j                  ||dz         }|dk7  r:|S )Nr+   r
   )r-   packfindr   append)r/   r$   r   needlerefsposr    s          r   
dword_refsr=   J   sl    [[u%FD
((6
C
)(C(>KKOhhvsQw'	 )
 Kr   c                    g }t        |      D ]`  }||dz  z   }t        | ||      }|j                  ||t        |      |t        |      |t	        ||xs d      d undt        ||      d       b |S )Nr*   r   F)indexentryVa
entryVaHexr   valueHexisVar%   )ranger1   r9   r   r   r(   )r/   r$   start_vacountrowsr?   entry_var   s           r   
dword_rowsrI   V   s    !#Du 
eai'h1# luIJOJ[Xuz:$Faf+He<
	

 Kr   c                   t        | |||d      }g }|j                  dg       D ]  }|j                  |j                  d      |j                  d      |j                  d      |j                  d      |j                  d      xs d	|j                  d
      |j                  d      |j                  d      xs g d        ||d<   |S )Ni`  )max_commands	max_bytescommandsvaHex	opcodeHex
opcodeNamelengthsummaryr   targetVaHexpayloadVaHexpointerOperands)rN   rO   rP   rQ   rR   rS   rT   rU   )r	   getr9   )r/   r$   r    rM   decodedcompactrows          r   stream_previewrZ   i   s    C2HPUVGG{{:r* 
) WW[1!ggl3''(+779-3"ww}5 # 7#&77+<#=#C		

 "GJNr   c                   t        ||      }|g S g }|}|t        |       k  rt        |      |k  r| j                  d|      }|dk  r	 |S | || }t        |      dk\  r3t        d |D              r!	 |j	                  |j                  d             |dz   }|t        |       k  rt        |      |k  r|S # t        $ r% |j	                  |j                  dd             Y Qw xY w)	N    r   r*   c              3  <   K   | ]  }d |cxk  xr dk  nc   yw)       Nr   ).0bytes     r   	<genexpr>z(resource_list_preview.<locals>.<genexpr>   s      E!4!4!4 Es   asciireplace)errorsr
   )r   r,   r8   allr9   decodeUnicodeDecodeError)	r/   r$   rE   rF   r0   stringscursorr'   raws	            r   resource_list_previewrl   }   s    
x
*C
{	GF
3s8
Gu 4hhw'7 N &os8q=S E EEFszz'23 q 3s8
Gu 4 N & Fszz')zDEFs   1 B5 5+C#"C#c                    t         j                         } t        |       }t        | |t        dz         }t        | |t        d      }|d   d   }t        |d uxr t        ||      d u      }t        |d uxr |dz  dk(        }t        | |t              }t        | |t              }t        | |t              }	t        | |t              }
t        | |t              }t        | |t              }t        | |t              }t        | |t              }g }|d   D ]  }|j                  d      d	k7  r|j                  d
      xs g }|s0|d   j                  d      }t!        |t"              sU|j%                  |j                  d      t'        |      t        | ||d      d        i dt'        |      d|t(        k(  dt'        t              dt'        |      d|d|d|xr | dt+        |      d|D cg c]  }t'        |       c}dt+        |      dt+        |	      d|	D cg c]  }t'        |       c}dt+        |
      dt-        | |t.              dddd }d!d"d#|t'        t              t'        t0              t'        t              t'        t              t'        t              t'        t              t'        t.              d$|||||d%|g d&g d'd(
S c c}w c c}w ))NP      r   r         rM   rO   0x07rU   rN      )rM   )sourceCommandVaHexchildScriptVaHexpreviewopcode14DispatchVaHexopcode14DispatchMatchesExpectedpostSelectedRootTableVaHexpostSelectedRootFirstDwordHex.postSelectedRootFirstDwordLowByteLooksOpcode14postSelectedRootFirstDwordIsVa(postSelectedRootRejectedAsLinearOpcode14gateDirectRefCountgateDirectRefsHexwrapperDirectRefCounttopSequenceDirectRefCounttopSequenceDirectRefsHexparentDirectRefCountintroTitleResourcePreviewnormalFieldEscOpenerPromotedFdecisiona  The VM graph still does not prove the normal-field ESC/X opener. 0x0047e624 creates supporting child objects, stores selectedRoot from the inline 0x004a2cb0 intro/title resource list, and calls selectedRoot.  The only top-menu sequence reference remains the wrapper's opcode 0x04 operand at 0x0047e6ac. The apparent 0x14 byte at 0x0047e670 is rejected as a linear command because its overlapped first dword is not a valid VA; the later 0x0047e688 pointer is a table entry/reference to the wrapper gate, not opener proof.z(hwanse-hud-menu-vm-graph-frontier-reviewz0tools/build_hud_menu_vm_graph_frontier_review.pyz/top-menu-vm-graph-grounded-opener-still-pending)parentContextselectedRootStorepostSelectedRootTablegatewrappertopSequenceintroTitleResourceList)r   r   r   r   )zm0x0047e670 is not accepted as a linear opcode 0x14 command because dword[0x0047e670] is not a file-backed VA.zM0x0047e688 is referenced only as a table entry from 0x0047e678 in this graph.zH0x004ddc6c is only referenced by the wrapper call operand at 0x0047e6b0.zt0x004a2cb0 is the compile/aaa/logo/title/btl_k intro-title resource list, so the parent remains intro/title-context.)ziFind a non-intro field state/root stream that reaches a menu-equivalent wrapper or descriptor attachment.zsIf opcode 0x14 is used elsewhere as a branch command, accept it only when dword[stream] is a file-backed target VA.zuTrace producers of object+0x40 stream pointers for the normal field mode rather than promoting nearby pointer tables.)
kindsourcestatusrR   	watchedVapostSelectedRootTableRowsstreamPreviewsparentChildScriptsnegativeEvidencenextFrontier)EXE
read_bytesr   r1   GENERAL_VM_TABLE_VArI   $TOP_MENU_POST_SELECTED_ROOT_TABLE_VAboolr   r=   TOP_MENU_GATE_VATOP_MENU_WRAPPER_VATOP_MENU_SEQUENCE_VATOP_MENU_PARENT_CONTEXT_VArZ   rV   
isinstancer#   r9   r   OPCODE14_HANDLER_VAr,   rl   INTRO_TITLE_RESOURCE_LIST_VA&TOP_MENU_PARENT_SELECTED_ROOT_STORE_VA)r/   r$   opcode14_dispatch	post_rowsfirst_dwordfirst_dword_is_valow_byte_looks_opcode14	gate_refswrapper_refstop_sequence_refsparent_refsparent_streamgate_streamwrapper_streamtop_sequence_streamchild_scriptscommandoperandschild_varefrR   s                        r   build_reportr      sV   
..
CS!H h0Ch0NO3*NPQRIA,w'K[4hhP[9\dh9hi";d#:#[d@RW[?[\3*:;Ic8-@AL"32FGS(,FGK"32LMM h0@AK#C3FGN(h8LMM , ;;{#v-;;017RA;??7+h$  *1++g*>(*8-c8XPQR $5!6)+<@S+S 	%b)M&N 	(K	
 	9:Q 	)*; 	34K4eTePe 	c)n 	;#bg; 	 \!2 	$S):%; 	#8I$JRW$J 	K 0 	$%:3Jf%g 	'  	E#G8 ;DC :;!#$J!K%'(L%M'(-.23&()E&F
 &/*%.	
 ,

9! !% < %Ks   4K&Kc                    g }| D ]1  |j                  ddj                  fd|D              z   dz          3 dj                  d |D              }d| ddj                  |       dS )	Nz<tr>r   c              3  `   K   | ]%  \  }}d t        j                  |             d ' yw)z<td>z</td>N)r   rV   )r`   key_labelrY   s      r   rb   zrender_table.<locals>.<genexpr>   s+     OVQswws|_-U3Os   +.z</tr>c              3  @   K   | ]  \  }}d t        |       d  yw)z<th>z</th>Nr   )r`   _keylabels      r   rb   zrender_table.<locals>.<genexpr>   s!     EkdET!E(5)Es   z<table><thead><tr>z</tr></thead><tbody></tbody></table>)r9   join)rG   columnsbodyheadrY   s       @r   render_tabler      s{    D 
ggOwOOP	

 77EWEEDv%9"''$-HXYYr   c                   | j                  d      xs g }g }|D ]  }|j                  dt        |j                  d             dt        |j                  d             dt        |j                  d             dt        |j                  d	             dt        |j                  d
             d        ddj                  |      z   dz   S )NrM   z<tr><td><code>rN   z</code></td><td><code>rO   z</code><br>rP   z	</td><td>rQ   rR   z
</td></tr>z\<table><thead><tr><th>VA</th><th>opcode</th><th>len</th><th>summary</th></tr></thead><tbody>r   r   )rV   r9   r   r   )streamrG   r   rY   s       r   render_commandsr      s    ::j!'RDD 
3777+,- .377;/01Qsww|?T=U<V WSWWX&'( )SWWY'() *		

 jlnlslstxlyy  }O  O  Or   c                   | d   }d| d   fd|d   fd|d   fd|d   fd	|d
   fd|d   fg}dj                  d |D              }t        | d   g d      }dj                  d | d   j                         D              }dj                  d | d   D              }dj                  d | d   D              }dj                  d | d   D              }t        j                  | d      }	d| dt        |d          d| d| d | d!| d"| d#|	 d$S )%NrR   r   zop14 handlerrw   zpost table rejectedr}   z	gate refsr~   ztop refsr   openerr   r   c              3  X   K   | ]"  \  }}d t        |       dt        |       d $ yw)z<div class='card'><b>z
</b><span>z</span></div>Nr   )r`   kvs      r   rb   zrender_html.<locals>.<genexpr>  s/     fX\XY[\/!vZ!v]Sf   (*r   ))r?   #)rA   entry)rB   r   )rC   zis VA)r%   r%   c              3  X   K   | ]"  \  }}d t        |       dt        |       d $ yw)z<section><h2>z</h2>
</section>Nr   r   )r`   r"   r   s      r   rb   zrender_html.<locals>.<genexpr>  s5      D& $yof&=%>jIr   r   c           
   3  |   K   | ]4  }d t        |d          dt        |d          dt        |d          d 6 yw)z<section><h2>Child ru   z</h2><p>from <code>rt   z</code></p>rv   r   Nr   )r`   rY   s     r   rb   zrender_html.<locals>.<genexpr>"  su       a$6 7899LQsSgOhMiLjju  wF  GJ  KT  GU  wV  vW  Wa  	bs   :<r   c              3  :   K   | ]  }d t        |       d  ywz<li>z</li>Nr   r`   items     r   rb   zrender_html.<locals>.<genexpr>&  s     U$$qwiu-U   r   c              3  :   K   | ]  }d t        |       d  ywr   r   r   s     r   rb   zrender_html.<locals>.<genexpr>'  s     R44$y.Rr   r   F)ensure_asciiu[  <!doctype html>
<html lang="ko">
<head>
  <meta charset="utf-8">
  <title>HUD Menu VM Graph Frontier</title>
  <style>
    body { margin: 0; padding: 24px; font-family: system-ui, sans-serif; background: #f7f2e8; color: #1f2430; }
    h1 { margin: 0 0 8px; }
    h2 { margin: 22px 0 8px; }
    .sub { color: #5d6470; margin-top: 0; }
    .cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; margin: 18px 0; }
    .card { background: #fffaf0; border: 1px solid #d7c7a8; border-radius: 6px; padding: 10px 12px; }
    .card b { display: block; color: #6b421a; font-size: 12px; }
    .card span { font-weight: 700; }
    section { background: white; border: 1px solid #decfb2; border-radius: 6px; padding: 14px; margin: 14px 0; overflow: auto; }
    table { width: 100%; border-collapse: collapse; font-size: 13px; }
    th, td { border-bottom: 1px solid #eadcc5; text-align: left; vertical-align: top; padding: 7px 8px; }
    th { background: #f3e6d0; }
    code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
    pre { white-space: pre-wrap; background: #272822; color: #f8f8f2; padding: 12px; border-radius: 6px; }
  </style>
</head>
<body>
  <h1>HUD Menu VM Graph Frontier</h1>
  <p class="sub">top-menu wrapper/sequence 주변 VM graph와 0x14/table false promotion 방지 리포트.</p>
  <div class="cards">z0</div>
  <section>
    <h2>Decision</h2>
    <p>r   zG</p>
  </section>
  <section>
    <h2>Post SelectedRoot Table</h2>
    z
  </section>
  z
  z4
  <section>
    <h2>Negative Evidence</h2>
    <ul>z)</ul>
    <h2>Next Frontier</h2>
    <ul>z~</ul>
  </section>
  <section>
    <h2>Raw JSON</h2>
    <pre id="payload"></pre>
  </section>
  <script>
    const payload = zu;
    document.getElementById('payload').textContent = JSON.stringify(payload, null, 2);
  </script>
</body>
</html>
)r   r   itemsjsondumpsr   )
reportrR   cards	card_html
post_tablestreamschildren	negatives
next_itemspayloads
             r   render_htmlr     s   YG	6(#$	!89:	(R ST	g234	W89:	79:;E f`effI*+sJ gg "#34::< G ww ./ H U&AS:TUUIR6.;QRRJjje4G2  [ ! 	
'*
   L 
) * 	 
 		  I _4 4r   c                     t               } t        j                  d       t        j                  d       t        j                  t        j                  | dd      d       t        j                  t        |       d       t        d       y )	NT)exist_okF   )r   indentzutf-8)encodingz$hud_menu_vm_graph_frontier_review ok)r   OUTmkdirWEBJSON_OUT
write_textr   r   HTML_OUTr   print)r   s    r   mainr   `  sg    ^FIItIIItI

6aHSZ[F+g>	
01r   __main__)rs   )r   
int | Noner   r#   returnr   )r   r   r   r   )r$   list[dict[str, Any]]r    r   r   z
str | None)r/   bytesr$   r   r    r#   r   r   )
r/   r   r$   r   r    r#   r3   r#   r   r   )r/   r   r$   r   r   r#   r   z	list[int])
r/   r   r$   r   rE   r#   rF   r#   r   r   )   )
r/   r   r$   r   r    r#   rM   r#   r   dict[str, Any])
   )
r/   r   r$   r   rE   r#   rF   r#   r   z	list[str])r   r   )rG   r   r   zlist[tuple[str, str]]r   r   )r   r   r   r   )r   r   r   r   )r   None)1__doc__
__future__r   r   r   r-   pathlibr   typingr   probe_exe_scene_tablesr   r   r   'summarize_object_payload_442c75_callersr	   __file__resolveparentsROOTr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r(   r1   r4   r=   rI   rZ   rl   r   r   r   r   r   __name__r   r   r   <module>r	     s   #      L L A H~''*
]
Ul
Ul9999    ' )3 &'1 $   ! ) <H1!	&((`F	ZONb2 zF r   