
    MjO                       d Z ddlmZ ddlZddlZddlmZmZ ddl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edz  Zedz  Zedz  Zedz  ZdZdZddg ddddg dddZddddddd d!ddd"dd#d$dd%Zd2d&Zd3d'Zd4d(Zd5d)Z d6d*Z!d7d+Z"d7d,Z#d8d-Z$d9d.Z%d:d/Z&d;d0Z'e(d1k(  r e'        yy)<a  Bridge the HUD-open runtime trace back to static EXE evidence.

The low-level runtime trace is intentionally noisy.  This report keeps the
useful promoted facts in one place:

* X opens the status/menu HUD and reaches the selected-root/top-region streams.
* The status/menu surface is rendered through window regions and then composed
  onto the frame surface.
* Korean HUD/menu text is emitted through two GDI TextOutA callsites with
  different roles.
    )annotationsN)Counterdefaultdict)Path)Any   outwebz"runtime_trace_hud_open_review.jsonz!menu_descriptor_stack_review.jsonz'hud_input_consumer_boundary_review.jsonz&hud_menu_vm_graph_frontier_review.jsonzexe_imports.jsonz%hud_runtime_static_bridge_review.jsonz%hud_runtime_static_bridge_review.html
0x100979C0
0x1004C438
0x0041f073z!streamed HUD/status text renderer)z,Reads object +0xb0 as a text stream pointer.zOUses +0xca/+0xcc and globals 0x0055b284/0x0055b288 as stream delay/width state.VCalls GDI32!TextOutA through IAT 0x005a03b8 after SelectObject/SetTextColor/SetBkMode.)functionVaHexrolestaticNotes
0x0041b369z,fixed-width immediate HUD/menu slot renderer)z\Uses object +0xd6/+0xda as output coordinates and +0xe0/+0xe2/+0xe4 as RGB text color bytes.z`The runtime strings are padded with full-width spaces, matching fixed list/equipment/menu slots.r   )
0x0041F293
0x0041B41D   zleft status window)regionIndexname   zright top menu window   zright submenu windowzbottom left HUD window   zbottom right info window)z0,0,416,352z416,0,640,96z416,96,640,352z0,352,416,480z416,352,640,480c                V    t        j                  | dd      S t        |       d      S )N T)quote)htmlescapestr)values    /tools/build_hud_runtime_static_bridge_review.pyhr#   C   s%    ;;U]r$GGE
$GG    c                p    | j                         si S t        j                  | j                  d            S )Nutf-8encoding)existsjsonloads	read_text)paths    r"   	read_jsonr.   G   s*    ;;=	::dnngn677r$   c                    t        t              } i }| j                  d      xs g D ]  }|j                  d      xs g D ]  }|j                  d      }t        |t              s%|j                  d      |j                  d      |j                  d      xs g D cg c]  }d|v sdt	        |d         d	 c}d
|d|d	<     |S c c}w )Nimports	functionsiatVadllr   refsva0x08x)r3   r   refsHex)r.   IMPORTS_REVIEWget
isinstanceint)datar4   r3   functioniatrefs         r"   import_refs_by_iatrA   M   s    ^$D&(Dxx	"(b 	,2 	H,,w'Cc3'wwu~ V,AIfAUA[Y[k#_cgj_jbSY 45k$D2c#Y 			 K ls   	C%Cc           	        g }g }g }| j                  d      xs g D ]  }t        |j                  d      xs d      }t        |j                  d      xs d      }|j                  d      xs i }|j                  d      xs d}|j                  d      xs d}	t        |j                  d      xs d      }
t        j                         ||z   |
z   j                         v r|j	                  |       |j                         t        j                         k(  rX|j                         t
        j                         k(  r3t        j                  |      }|j	                  i ||||	|rd	nd
d       |j                         t        j                         k(  s||j                  d      dk(  s|j	                  |        |||dS )NdrawSurfaceRowssourcer   destinationparsedsrcRectdstRectdetailzregion-knownzunclassified-text-surface-copy)regionrG   rH   compositionStatuspc
0x00419C25)textSurfaceRowscompositionRowstemplateTileRows)r:   r    TEXT_SURFACElowerappendFRAME_SURFACEREGION_BY_RECT)tracetext_surface_rowscomposition_rowstemplate_tile_rowsrowrD   rE   rF   src_rectdst_rectrI   rJ   s               r"   surface_rowsr]   ]   s   yy*+1r +SWWX&,"-#''-06B7"(b::i(.B::i(.BSWWX&,"-F[$86$A#H#H#JJ$$S)<<>\//11k6G6G6I]M`M`Mb6b#''1F##$'';AGg ,"4"4"663774=L;X%%c*++. -+. r$   c                   i }| D ]$  }|j                  d      }|st        |j                  d      xs d      t        |j                  d      xs d      f}|j                  |      }|||j                  d      |j                  d      |j                  d      |j                  d      |j                  d      |j                  d      |j                  d      d|j                  d	      d

||<   |j                  d      |d<   |j                  d      |d<   |dxx   dz  cc<   ' t        |j                         d       S )NrJ   rG   r   rH   flagsseqframer   rI   )
rJ   rG   rH   r_   firstSeqlastSeq
firstFrame	lastFramerepeatCountsampleDetailrc   re   rf   c                    t        | j                  d      xs i j                  d      xs d      t        | j                  d      xs d      fS )NrJ   r   c   rb   r   )r<   r:   )rZ   s    r"   <lambda>z'summarize_composition.<locals>.<lambda>   sE    "(b--m<BC
#(q)
 r$   key)r:   r    sortedvalues)rowsgroupedrZ   rJ   rl   currents         r"   summarize_compositionrr   ~   s4   57G $"3779%+,c#'')2D2J.KL++c"? 779-779-)GGEN775>!ggg. WWW-  # 1GCL  WWU^	"www/!#-$. 
 r$   c                   t        t              }| j                  d      xs g D ].  }|t        |j                  d               j	                  |       0 g }t        |j                               D ]  \  }}t        j                  |i       }|j	                  ||j                  d      |j                  dd      t        |      |D cg c]  }|j                  d       c}|D cg c]  }|j                  d       c}t        |D ch c]/  }|j                  d      xs d	 d
|j                  d      xs d	 1 c}      |j                  d      xs g |d d d	        |S c c}w c c}w c c}w )NtextDrawRowsrL   r   r   zunclassified TextOutA callsitedecodedTextrectfont-z / colorr      )	rL   r   r   counttextsrects
fontColorsr   
sampleRows)	r   listr:   r    rS   rm   itemsTEXT_OUT_CALLSITESlen)rV   groupsrZ   r	   rL   ro   r   s          r"   text_groupsr      s\   .9$.?Fyy(.B /s3774=!"))#./ C6<<>* 
D!%%b"-

!%/!:)IJT<@AS#''-0A59:c#''&/:$ $( 776?1c2#cggg6F6M#5NO  $xx6<""3Bi	

( J B:s   E&&E+	4E0c                   g }| j                  d      xs g D ]  }|j                  d      xs i }|j                  |j                  d      |j                  d      |j                  d      |j                  d      |j                  d      |j                  d      |j                  d	      |j                  d
      |j                  d      d	        |S )NexactRegionHitsstreamAnchorr`   ra   streamopcoder   rectTexttemplateIndexlabelstatus)	r`   ra   r   r   r   r   r   r   r   )r:   rS   )rV   ro   rZ   anchors       r"   exact_region_rowsr      s    Dyy*+1r 
(.Bwwu~)''(+''(+%zz-8"JJz2!'O!<G,''(+
	

 Kr$   c                    | j                  d      xs i g}|D cg c]&  }|j                  di       j                  d      s%|( }}|rt        |d       d   S |r|d   S i S c c}w )NtracesruntimeSignalsresourceSurfaceLabelCountc                d    t        | j                  d      xs i j                  d      xs d      S )Nmanifestexported_atr   )r    r:   )rV   s    r"   rj   zchoose_trace.<locals>.<lambda>   s+    eii
6K6Qr5V5VWd5e5kik1l r$   rk   )r:   rm   )runtimer   rV   labeleds       r"   choose_tracer      sr    [["*rdF"(mEII6F,K,O,OPk,lumGmg#lmnpqq6":'R' ns   &A$A$c                 &	   t        t              } t        t              }t        t              }t        t              }t               }t        |       }t        |      }t        |      }t        |      }t               }	|D ]2  }
|
j                  d      xs g D ]  }|	t        |      xx   dz  cc<    4 |d   D cg c]  }|j                  d      s| }}t        |      }t        |D ch c]8  }|j                  d      r%|d   j                  d      t        |d   d         : c}      }d|j                  d      xs dd	g d
ddddddgddddddgdg}ddddddddddddg}dd t        t!        t"              j%                  t&                    t        t        j%                  t&                    t        t        j%                  t&                    t        t        j%                  t&                    t        t        j%                  t&                    t        t(        j%                  t&                    d!i dd"d#|j                  d#      d$|j                  d$      d%|j                  d%      d&|j                  d&      d't*        d(t,        d)d*d+t/        |j                  d+      xs g       d,t/        |      d-t/        |      d.|d/t/        |d0         dt/        |d         d1t/        |      d2t/        |d2         d3t/        |j                  d3      xs g       t/        |j                  d4      xs g       |j                  d5      |j                  d6      xs i j                  d7      |j                  d      |j                  d8      xs! |j                  d9i       j                  d8      |j                  d9      xs i j                  d:      |j                  d9      xs i j                  d;      d<d=D ci c]  }||v r||j                  |       c}|||j                  d+      xs g D cg c]  }|j                  d>       c}t1        |	      d?|||d d@ |d0   d dA |dBS c c}w c c}w c c}w c c}w )CNr|   r   rO   rJ   r   z$normal field X/ESC status HUD openerr   zstatic-only pendingzruntime-confirmed)z5selectedRootExecutorSeen is true in the runtime tracezGtop menu/context stream neighborhood appears after the input-edge writezCexact top context region initializers #6/#3/#4 execute in frame 277zAstatus-window text markers are emitted in the same HUD-open trace)areapreviousStatus	newStatusevidencezHUD region compositionz,layout grounded, runtime composition partialz,runtime-confirmed for regions #1/#2/#3/#4/#6zSsurface 0x100979C0 is copied to frame surface 0x1004C438 by exact region rectangleszdcomposition copies include 0,0,416,352; 416,0,640,96; 416,96,640,352; 0,352,416,480; 416,352,640,480zHUD/menu Korean text draw sinkz&text tables known, draw sink separatedz#runtime-confirmed GDI TextOutA sinkzP0x0041F293 and 0x0041B41D are direct calls through GDI32!TextOutA IAT 0x005a03b8zruntime TextOutA rows include character name, equipment names, stat labels, status comment, mode, category, and skill list labelsz+menu navigation/deeper submenu state writeszjThis capture only opened the status HUD; it did not press arrows/confirm/cancel after the HUD was visible.zkCapture Down/Up, Left/Right, Enter, ESC while the menu is open with mem-write/object-stream-change enabled.)itemreason	nextTracez!asset-level source surface labelsztDraw rows expose surface handles and source rects, but not yet the originating CNS filename for each surface handle.z[Add surface creation/resource-label events or wrapper id labels when CNS assets are loaded.zdynamic status valueszThis trace proves label/text positions and surface composition. It does not yet prove the exact producer for HP/MP/EXP numeric CNS glyph values.zXCapture status HUD with numeric glyph draw source labels and watched stat memory values.z'hwanse-hud-runtime-static-bridge-review)r   menuDescriptorhudInput
vmFrontierr0   z1hud-open-consumer-runtime-confirmed-static-bridgetraceIdclassification
eventCount
frameRangetextSurfaceframeSurface
textOutIat
0x005a03b8rt   textOutCallsiteCountexactTopRegionInitializerHitsknownComposedRegionstextSurfaceDrawRowsrN   compositionRegionRowsrP   surfaceSnapshotRowsresourceSurfaceLabelRows	jsonlPathr   r   
conclusionsummarytopMenuObjectSequenceVaHextopMenuParentContextScriptVaHex)r   traceJsonlPathtraceExportedAtoldStaticFrontierStatusoldHudInputConclusionr   r   )
0x005a03a4r   
0x005a03cc
0x005a03d0ru   )allDecodedTextscountsrz   (   )versionkindrD   inputsr   gdiImportRefs
promotionstextOutCallsitestextMarkersexactRegionInitializerRowssurfaceCompositionRowssurfaceCompositionRawSampletextSurfaceRowsSampleremainingRuntimeNeeds)r.   RUNTIME_REVIEWMENU_DESCRIPTOR_REVIEWHUD_INPUT_REVIEWVM_FRONTIER_REVIEWrA   r   r]   r   r   r   r:   r    rr   rm   r<   r   __file__relative_toROOTr9   rQ   rT   r   dict)r   menu	hud_inputfrontierr0   rV   surfacestextexacttext_countergroupr!   rZ   composition_knowncomposition_summaryknown_regionsr   	remainingrl   s                      r"   buildr      s   'G+,D*+I+,H "G!EE"HuDe$E9L *YYw'-2 	*EU$)$	** )11B(CYswwxGXYY/0AB )	
wwx S]%6%6}%E%Q Hm,-	
M ;'||H5N9N,	
	
 -LGev		
 5F>b T		
+JD B C G	
 8 Mv	
 , is	
I& 9d8n0067>55d;<!"8"D"DT"JK,88>?0<<TBC>55d;<

I
uyy+
 eii(89
 %))L1	

 %))L1
 <
 M
 ,
 C		. 9 ?R@
 #CI
 ,SZ
 #M
 "3x0A'B#C
 s8,=#>?
 $S)<%=
  H-?$@ A!
" "3uyy1F'G'M2#N#
$ ),EII6P,Q,WUW(X#ii4 %		* 5 ;@@O'/||H'=%.]]<%@%rIMMR[]_D`DdDdeqDr+/88I+>+D"*I*IJf*g040C0Ir/N/NOp/q1
8 P
g~ S!!

 ! BG))NB[Ba_ab3 6b<(
 ',"5'8"'=!)*;!<Sb!A!*i5 5y Z	
|
  cs   ;Q?Q?,=RR	Rc                
   | d   }g }|j                  d       |j                  d       |j                  d       |j                  d       |j                  d       |j                  d       |j                  d       d	D ];  }|j                  d
t        |       dt        |j                  |             d       = |j                  d       |j                  d       | d   D ]]  }|j                  dt        |d          dt        |d          dt        |d          ddj                  d |d   D               d	       _ |j                  d       |j                  d       | d   D ]  }|j                  dt        |d          d t        |j                  d!             d"t        |j                  d#             dt        |j                  d$             ddj                  d% |j                  d&      xs g D               ddj                  d' |j                  d(      xs g D               d        |j                  d       |j                  d)       | d*   D ]  }|j                  dt        |j                  d+             dt        |j                  d,             d-t        |j                  d.             d/t        |j                  d0             dt        |j                  d1             dt        |j                  d2             d        |j                  d       |j                  d3       | d4   D ]S  }|j                  d5      xs i }|j                  dt        |j                  d6             d7t        |j                  d8             dt        |j                  d9             d7t        |j                  d:             d;t        |j                  d0             d<t        |j                  d=             d-t        |j                  d>             d t        |j                  d?             d t        |j                  d@             d"t        |j                  dA             dBt        |j                  dC             d       V |j                  d       |j                  dD       | dE   D ]e  }|j                  dFt        |j                  dG             dt        |j                  dH             dt        |j                  dI             d       g |j                  d       t        j                  dJj                  |      dJz   dKL       y )MNr   z%<!doctype html><meta charset="utf-8">z(<title>HUD Runtime Static Bridge</title>a  
<style>
body{font-family:system-ui,-apple-system,Segoe UI,sans-serif;margin:24px;background:#f7f5ef;color:#202020}
a{color:#135c8a} .top{display:flex;gap:10px;flex-wrap:wrap;margin:12px 0 20px}
.chip{display:inline-block;padding:6px 10px;border:1px solid #bbb;border-radius:999px;background:white;text-decoration:none;color:#222}
.panel{background:white;border:1px solid #d8d0c1;border-radius:8px;padding:16px;margin:14px 0;box-shadow:0 1px 3px #0001}
h1{margin:0 0 8px;font-size:26px} h2{font-size:18px;margin:0 0 12px}
table{border-collapse:collapse;width:100%;font-size:13px} th,td{border:1px solid #ddd;padding:7px;vertical-align:top}
th{background:#eee7d8;text-align:left} code{font-family:ui-monospace,SFMono-Regular,Consolas,monospace}
.ok{color:#116b29;font-weight:700}.pending{color:#8a5300;font-weight:700}
.grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(260px,1fr));gap:10px}
.small{font-size:12px;color:#555}.nowrap{white-space:nowrap}
</style>
z"<h1>HUD Runtime Static Bridge</h1>u   <p>웹 런타임 HUD-open trace를 기존 EXE 정적 분석 앵커와 연결해 승격 가능한 항목만 모은 리포트입니다.</p>z<div class="top"><a class="chip" href="index.html">index</a><a class="chip" href="runtime_trace_hud_open_review.html">runtime trace source</a><a class="chip" href="../out/hud_runtime_static_bridge_review.json">json</a></div>z9<section class="panel"><h2>Summary</h2><div class="grid">)r   r   r   r   r   r   r   rt   r   r   r   r   z<div><b>z</b><br><code>z</code></div>z</div></section>zu<section class="panel"><h2>Promotions</h2><table><tr><th>area</th><th>previous</th><th>new</th><th>evidence</th></tr>r   z<tr><td>r   z	</td><td>r   z</td><td><span class="ok">r   z</span></td><td>z<br>c              3  2   K   | ]  }t        |        y wNr#   ).0r   s     r"   	<genexpr>zwrite_html.<locals>.<genexpr>  s     C4qwC   r   z
</td></tr>z</table></section>z<section class="panel"><h2>TextOutA Callsites</h2><table><tr><th>pc</th><th>function</th><th>role</th><th>count</th><th>texts</th><th>static notes</th></tr>r   z<tr><td><code>rL   z</code></td><td><code>r   z</code></td><td>r   r{   c              3  2   K   | ]  }t        |        y wr   r   )r   r   s     r"   r   zwrite_html.<locals>.<genexpr>  s     J4qwJr   r|   c              3  2   K   | ]  }t        |        y wr   r   )r   notes     r"   r   zwrite_html.<locals>.<genexpr>  s     P4qwPr   r   z<section class="panel"><h2>Region Initializers</h2><table><tr><th>seq</th><th>frame</th><th>stream</th><th>region</th><th>rect</th><th>status</th></tr>r   r`   ra   z</td><td><code>r   z</code></td><td>#r   r   r   z<section class="panel"><h2>Surface Composition</h2><table><tr><th>seq</th><th>frame</th><th>region</th><th>src rect</th><th>dst rect</th><th>flags</th><th>repeat</th><th>detail</th></tr>r   rJ   rb   z..rc   rd   re   z
</td><td># r   rG   rH   r_   rf   z</td><td class="small">rg   zv<section class="panel"><h2>Remaining Runtime Needs</h2><table><tr><th>item</th><th>reason</th><th>next trace</th></tr>r   z<tr><td class="pending">r   r   r   
r&   r'   )rS   r#   r:   joinHTML_OUT
write_text)r=   r   ro   rl   rZ   rJ   s         r"   
write_htmlr   ]  sw   9oGDKK9:KK:;KK	  	KK45KK  \  ]KK	] 	KKKL Y 	hqvhnQw{{37G5H4IWXY 	KK"#KK  H  IL! 
S[>" #S)*+, -&&'K(8&9%: ;;;C3z?CCD E		

 	KK$%KK  o  p&' 

3t9 '377?345 6SWWV_%& 'SWWW%&' (;;J37773C3IrJJK L;;P377=3I3ORPPQ R		


 	KK$%KK  j  k01 

SWWU^$% &SWWW%&' (3778,-. /cggm,-. /SWWZ()* +SWWX&'( )		


 	KK$%KK  M  N,- 
"(bSWWZ()*"Qswwy/A-B,C DSWW\*+,Bq1E/F.G Hfjj/011VZZ5G3H2I J3779-./ 03779-./ 03777+,- .SWW]+,- .##$SWW^%<#="> ?		

 	KK$%KK  I  J+, 
%%&swwv%7$8 9SWWX&'( )SWW[)*+ ,	

 	KK$%		$$.Ar$   c                 ~   t         j                  dd       t        j                  dd       t               } t        j                  t        j                  | dd      dz   d       t        |        t        d	t        j                  t                      t        d	t        j                  t                      y )
NT)parentsexist_okFr   )ensure_asciiindentr   r&   r'   zwrote )OUTmkdirWEBr   JSON_OUTr   r*   dumpsr   printr   r   r   )r=   s    r"   mainr    s    IIdTI*IIdTI*7D

4eAFMX_`t	F8''-.
/0	F8''-.
/0r$   __main__)r!   r   returnr    )r-   r   r  dict[str, Any])r  zdict[str, dict[str, Any]])rV   r  r  zdict[str, list[dict[str, Any]]])ro   list[dict[str, Any]]r  r  )rV   r  r  r  )r   r  r  r  )r  r  )r=   r  r  None)r  r  ))__doc__
__future__r   r   r*   collectionsr   r   pathlibr   typingr   r   resolver   r   r   r   r   r   r   r   r9   r   r   rQ   rT   r   rU   r#   r.   rA   r]   rr   r   r   r   r   r   r  __name__ r$   r"   <module>r     s\  
 #   ,  H~''*
Ul
Ul;;BB BB CC ))8888 &3
 &>
 , $%.BC$%/FG&'1GH%&0HI'(2LMH8 BD:((AHsBl1 zF r$   