+
     h c                   s   R t RtRtRt^ RIt^ RIt^ RIt^ RIt^ RI	t	^ RI
t
^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIHtHtHtHt ^ RIHt ^ RIt]P4                  ! R]P6                  ! R	4      4       ]tRR lt]! RR7      R 4       tR t R
t!Rt"Rt#Rt$Rt%Rt&Rt'Rt(^ t)Rt*Rt+Rt,Rt-Rt.Rt/Rt0Rt1^t2Rt3Rt4Rt5Rt6R t7. ROt8]7! ]84      t9. ROt:]7! ]:4      t;. RNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNt<]7! ]<4      t=. ROt>]7! ]>4      t?. ROt@]7! ]@4      tA. RNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNtB]7! ]B4      tC. ROtD]7! ]D4      tE. ROtF]7! ]F4      tG. ROtH]7! ]H4      tIRtJRtK. ROtL]7! ]L4      tM. ROtN]7! ]N4      tO^ tP^tQ^tR^tS^tT^tU^tV^tW^	tX^
tY. ROtZ]7! ]Z4      t[. RNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNER NERNERNERNERNERNERNERNERNER	NER
NERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNER NER!NER"NER#NER$NER%NER&NER'NER(NER)NER*NER+NER,NER-NER.NER/NER0NER1NER2NER3NER4NER5NER6NER7NER8NER9NER:NER;NER<NER=NER>NER?NER@NERANERBNERCNERDNERENERFNERGNERHNERINERJNERKNt\]7! ]\4      t]. ERLNERMNERNNERONERPNERQNERRNERSNERTNERUNERVNERWNERXNERYNERZNER[NER\NER]NER^NER_NER`NERaNERbNERcNERdNEReNERfNERgNERhNERiNERjNERkNERlNERmNERnNERoNERpNERqNERrNERsNERtNERuNERvNERwNERxNERyNERzNER{NER|NER}NER~NERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNERNt^]7! ]^4      t_]`! ]^4      t_]^ F-  w  tatb]b]_9   d   ]_]b,          P                  ]a4       K'  ]a.]_]b&   K/  	  R  tdR! teR" tfR# tgR$ th ! R% R&]i4      tj ! R' R(4      tk ! R) R*]l4      tm ! R+ R,4      tnR-^R.^R/^R0^R1^R2^R3^R4^R5^R6^R7^R8^R9^R:^R;^/to]! RR7      R< 4       tp]! RR=R>7      R? 4       tq ! R@ RA4      tr ! RB RC]r4      ts]! RR
R>7      RD 4       tt ! RE RF]r4      tu ! RG RH4      tv ! RI RJ]v4      tw ! RK RL]v4      tx ! RM RN]v4      ty ! RO RP]v4      tz ! RQ RR]v4      t{ ! RS RT]v4      t| ! RU RV]v4      t} ! RW RX]v4      t~ ! RY RZ]v4      t ! R[ R\]v4      t ! R] R^]v4      t ! R_ R`]v4      t ! Ra Rb]v4      t ! Rc Rd]v4      t ! Re Rf]v4      t ! Rg Rh]v4      t ! Ri Rj]v4      t ! Rk Rl]v4      t ! Rm Rn]v4      t ! Ro Rp]u4      t ! Rq Rr4      t ! Rs Rt]4      t ! Ru Rv]4      t ! Rw Rx]4      t ! Ry Rz]4      t ! R{ R|]4      t ! R} R~]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R4      t]EP.                  ]EP0                  ,           ]EP2                  ,           R,           EP5                  4       tR t]EP.                  ]EP0                  ,           ]EP2                  ,           EP5                  4       t]! RR7      ERR R ll4       t ! R R4      tR t]R8X  d
   ]! 4        R# R# (  ab  pefile, Portable Executable reader module

All the PE file basic structures are available with their default names as
attributes of the instance returned.

Processed elements such as the import table are made available with lowercase
names, to differentiate them from the upper case basic structure names.

pefile has been tested against many edge cases such as corrupted and malformed
PEs as well as malware, which often attempts to abuse the format way beyond its
standard use. To the best of my knowledge most of the abuse is handled
gracefully.

Copyright (c) 2005-2024 Ero Carrera <ero.carrera@gmail.com>
zEro Carreraz	2024.8.26zero.carrera@gmail.comN)Counter)md5sha1sha256sha512)Unionbackslashreplace_backslashreplaceFc                 sV   a a V'       g   \         P                  ! S S4      # V V3R  lpV# )c                 s   <a \         P                  ! SS4      ! V 4      o\         P                  ! V 4      V3R  l4       pV# )c                  s<   < \         P                  ! S! V / VB 4      # N)copymodcopy)argskwargscached_funcs   *,+/usr/lib/python3.14/site-packages/pefile.pywrapperZ-lru_cache.<locals>.decorator.<locals>.wrapper8   s     <<T <V <==    )	functools	lru_cacheZwraps)fr   r   maxsizetypeds   & @r   	decoratorZlru_cache.<locals>.decorator5   s<    ))'59!<			> 
	> r   )r   r   )r   r   r
   r   s   ff& r   r   r   1   s&    ""7E22 r      )r   c                 st    VR 8  d   TpV'       d'   W,          '       d   V\        W,          4      ,          # V # )   )int)valsection_alignmentfile_alignment   &&&r   cache_adjust_SectionAlignmentr   B   s5    6!* S44 C(?$@AAJr   c                 s$    V P                  ^ 4      #     )count)data   &r   count_zeroesr$   R   s    ::a=r                iMZ  iZM  iNE  iLE  iLX  iVZ  iPE          l            i  i  c                 sn    \        V  Uu. uF  q^,          V^ ,          3NK  	  upV ,           4      # u upi )   )dict)Zpairse   & r   two_way_dictr.      s.    u-u!A$!u-566-s   2c                 s    \         P                  V R 4      p\        P                  V. 4       F  pW#9   g   K  Vu # 	  \        P                  VR .4      ^ ,          # )	*unknown*)LANGgetSUBLANG)Z
lang_valuesublang_valueZ	lang_namesublang_name   &&  r   get_sublang_name_for_langr6     sO    [1IM26 $	 7 ;;}{m4Q77r   c                 s   ^ p^ pV\        V 4      8  d   WV^,            p\        V4      ^8  d   R# \        P                  ! RV4      ^ ,          pV^,          pV^ 8w  d^   ^ V^,          u;8:  d   \        V 4      8:  d?   M M; WW6^,          ,            P                  R4      W!&   V^8  d   R# W6^,          ,          pV^,          pK  R#   \         d    T^,          p L;i ; i)r    z<hutf-16leN)lenstructunpackdecodeZUnicodeDecodeError)r"   Zcounterlierror_countZ
data_sliceZlen_s   &&&    r   parse_stringsr?     s    	AK
c$i-a!e_
z?Q}}T:.q1	Q19dQh3#d)3!!a(l3:::F
 aMA1  & !q !s   "C
 
C! C!c                s    V P                  4        Uu. uFD  p\        V\        \        34      '       g   K!  VP	                  V4      '       g   K:  W V,          3NKF  	  up# u upi )zRead the flags from a dictionary and return them in a usable form.

Will return a list of (flag, value) for all flags in "flag_dict"
matching the filter "flag_filter".
)keys
isinstancestrbytes
startswith)Z	flag_dictZflag_filterflag   && r   retrieve_flagsrG     sX     NN$$DdS%L) 	 .2ook.J 	 $  s   A A A c                sx    V F3  w  r4WA,          '       d   RV P                   V&   K$  RV P                   V&   K5  	  R# )zWill process the flags and set attributes in the object accordingly.

The object "obj" will gain attributes named after the flags provided in
"flags" and valued True/False, matching the results of applying each
flag value from "flags" to flag_field.
TFN)__dict__)ZobjZ
flag_fieldflagsrE   value   &&&  r   	set_flagsrL     s5     !%CLL!&CLL	 r   c                 s@    V ^ 8g  ;'       d    W ^,
          ,          ^ 8H  # r    )r   r#   r   power_of_tworN     s    !8..aQ..r   c                   sD   a a ] tR tRt oV 3R ltV 3R ltR tRtVtV ;t	# )
AddressSeti  c                s@   < \         SV `  4        R V n        R V n        R # r   )super__init__minmax)self	__class__   &r   rQ   ZAddressSet.__init__  s    r   c                s   < \         SV `  V4       V P                  f   TM\        V P                  V4      V n        V P                  f	   Wn        R # \        V P                  V4      V n        R # r   )rP   addrR   rS   )rT   rJ   rU      &&r   rW   ZAddressSet.add  sK    E HH,5#dhh2F HH,5#dhh2Fr   c                sx    V P                   e   V P                  f   ^ # V P                  V P                   ,
          # r   )rR   rS   rT   r#   r   diffZAddressSet.diff  s,    HH$(8qQdhh>QQr   )rS   rR   )
__name__
__module____qualname____firstlineno__rQ   rW   rZ   __static_attributes____classdictcell____classcell__rU   __classdict__   @@r   rO   rO     s     
G
R Rr   rO   c                   s`   a  ] tR tRt o RtR tR tR tR tR t	R t
R	 tR
 tR tR tRtV tR# )!UnicodeStringWrapperPostProcessori  zThis class attempts to help the process of identifying strings
that might be plain Unicode or Pascal. A list of strings will be
wrapped on it with the hope the overlappings will help make the
decision about their type.c                s,    Wn         W n        R V n        R # r   )perva_ptrstring)rT   rf   rg   r   r   rQ   Z*UnicodeStringWrapperPostProcessor.__init__  s    r   c                    V P                   # )zGet the RVA of the string.)rg   rY   r#   r   get_rvaZ)UnicodeStringWrapperPostProcessor.get_rva  s    ||r   c                s&    V P                  RR4      # )z6Return the escaped UTF-8 representation of the string.utf-8r   )r;   rY   r#   r   __str__Z)UnicodeStringWrapperPostProcessor.__str__  s    {{7$788r   c                s^    V P                   '       g   R # V P                   P                  ! V!  #  )rh   r;   )rT   r   s   &*r   r;   Z(UnicodeStringWrapperPostProcessor.decode  s#    {{{{{!!4((r   c                s
    Rp R# )z>Make this instance None, to express it's no known string type.NrM   rY   r#   r   
invalidateZ,UnicodeStringWrapperPostProcessor.invalidate  s    r   c                s@    V P                   P                  V P                  ^,           V P                  4       R7      V n        R#   \
         dN    T P                   P                  4       P                  RP                  T P                  ^,           4      4        R# i ; i)   
max_lengthzCFailed rendering pascal string, attempting to read from RVA 0x{0:x}N)	rf   get_string_u_at_rvarg   get_pascal_16_lengthrh   PEFormatErrorget_warningsappendformatrY   r#   r   render_pascal_16Z2UnicodeStringWrapperPostProcessor.render_pascal_16  s}    	''55q T-F-F-H 6 DK  	GG  "))66<fT\\A=M6N	s   AA ABBc                s8    V P                  V P                  4      # r   )9_UnicodeStringWrapperPostProcessor__get_word_value_at_rvarg   rY   r#   r   rt   Z6UnicodeStringWrapperPostProcessor.get_pascal_16_length  s    ++DLL99r   c                s     V P                   P                  V^4      p\        T4      ^8  d   R# \        P
                  ! RT4      ^ ,          #   \         d     R# i ; i)rp   F<H)rf   get_dataru   r8   r9   r:   )rT   rvar"   rF   r   Z__get_word_value_at_rvaZ9UnicodeStringWrapperPostProcessor.__get_word_value_at_rva  sW    	77##C+D t9q=}}T4(++  		s   A AAc                sr    V P                  V^,
          4      ^ 8X  d   WP                  ,
          V n        R# R# )zThe next RVA is taken to be the one immediately following this one.

Such RVA could indicate the natural end of the string and will be checked
to see if there's a Unicode NULL character there.
TF)rz   rg   length)rT   Znext_rva_ptr   &&r   ask_unicode_16Z0UnicodeStringWrapperPostProcessor.ask_unicode_16  s0     ''q(89Q>&5DKr   c                s    V P                   P                  V P                  4      V n        R#   \         dG    T P                   P                  4       P                  R P                  T P                  4      4        R# i ; i)zDFailed rendering unicode string, attempting to read from RVA 0x{0:x}N)rf   rs   rg   rh   ru   rv   rw   rx   rY   r#   r   render_unicode_16Z3UnicodeStringWrapperPostProcessor.render_unicode_16(  s^    	''55dllCDK 	GG  "))66<fT\\6J	s   *. AA?>A?)r~   rf   rg   rh   N)r[   r\   r]   r^   __doc__rQ   rj   rl   r;   ro   ry   rt   rz   r   r   r_   r`   rc      @r   re   re     sA     "

9)
	:	,
 r   re   c                   0   a  ] tR tRt o RtR tR tRtV tR# )ru   i2  z"Generic PE format error exception.c                    Wn         R # r   rJ   )rT   rJ   r   r   rQ   ZPEFormatError.__init__5  s    
r   c                s,    \        V P                  4      # r   )reprrJ   rY   r#   r   rl   ZPEFormatError.__str__8  s    DJJr   r   N)	r[   r\   r]   r^   r   rQ   rl   r_   r`   r   r   r   ru   ru   2  s     ,   r   ru   c                   sZ   a  ] tR tRt o RtR tRR ltRR ltRR ltR t	R t
R	 tR
tV tR# )Dumpi<  z1Convenience class for dumping the PE information.c                s    . V n         R # r   textrY   r#   r   rQ   ZDump.__init__?  s	    	r   c                s:    V F  pV P                  W24       K  	  R# )zUAdds a list of lines.

The list can be indented with the optional argument 'indent'.
N)add_line)rT   txtindentline   &&& r   	add_linesZDump.add_linesB  s    
 DMM$' r   c                s8    V P                  VR,           V4       R# )zLAdds a line.

The line can be indented with the optional argument 'indent'.

N)rW   rT   r   r   r   r   r   ZDump.add_lineJ  s    
 	tV$r   c                sj    V P                   P                  RP                  RV,          V4      4       R# )zlAdds some text, no newline will be appended.

The text can be indented with the optional argument 'indent'.
z{0}{1} N)r   rw   rx   r   r   r   rW   ZDump.addQ  s%    
 			vs;<r   c                sH    V P                  RP                  RV4      4       R# )zAdds a header element.z
{0}{1}{0}
Nz
----------)r   rx   )rT   r   r   r   
add_headerZDump.add_headerX  s    m**8S9:r   c                s<    V P                   P                  R4       R# )zAdds a newline.r   N)r   rw   rY   r#   r   add_newlineZDump.add_newline\  s    		r   c                sF    RP                  R V P                   4       4      # )z"Get the text in its current state.rn   c              3   sD   "   T F  pR P                  V4      x  K  	  R# 5i){0}Nrx   ).0br-   r   	<genexpr>Z Dump.get_text.<locals>.<genexpr>b  s     :	1u||A	s    )joinr   rY   r#   r   get_textZDump.get_text`  s    ww:		:::r   r   Nr   )r[   r\   r]   r^   r   rQ   r   r   rW   r   r   r   r_   r`   r   r   r   r   r   <  s0     ;(%=;; ;r   r   xcr   ZBZhZHr=   Ir<   ZLr   ZqZQdsc           	      sl   ^pT pV ^ ,          \         P                  9   dx   \        RP                  V  Uu. uF  q3\         P                  9   g   K  VNK  	  up4      4      pRP                  V  Uu. uF  q3\         P                  9  g   K  VNK  	  up4      p\        V,          V,          # u upi u upi )r*   rn   )rh   digitsr   r   STRUCT_SIZEOF_TYPES)Ztr!   Z_tr      &   r   sizeof_typer   x  s    E	
Btv}}BGG@1&---?QQ@ABWW=Av}}&<aa=>r"U** A=s   B,B,0B1B1T)r   r
   c           
      s   R p. p/ p. p^ p^ pV  F  pRV9   g   K  VP                  R^4      w  rW,          pVP                  R4       V	P                  R4      p
. pV
 F\  p	W9   d?   V Uu. uF  qR\        V	4       NK  	  ppVP                  V	4      pRP	                  W4      p	VP                  V	4       WcV	&   K^  	  V\        V4      ,          pVP                  V4       K  	  \        P                  ! V4      pVVVVV3# u upi )<,Nz	{0}_{1:d})splitrw   r8   r!   rx   r   r9   Zcalcsize)rx   __format_str____unpacked_data_elms____field_offsets____keys____format_length__offsetelmelm_typeelm_nameZ	elm_namesZnamesr   Zsearch_listZ	occ_counts   &              r   
set_formatr     s"   NHF#:!$3!2H&N"))$/ s+IE%'?G"Hx!_s8}#5xK"H + 1 1( ;I*11(FHX&.4(+ & k(++F
 OOE"+ . 7 	  #Is   *Dc                   s   a  ] tR tRt o RtRR ltV 3R lR ltR tR tR	 t	R
 t
R tR tR tR tR tR tRR ltR tRtV tR# )	Structurei  zPrepare structure object to extract members from data.

Format is a list containing definitions for the elements
of the structure.
Nc                sJ   R V n         . V n        ^ V n        / V n        . V n        V^,          p\        V\        4      '       g   \        V4      p\        V4      w  V n         V n        V n        V n        V n        RV n        W0n	        V'       d	   W n
        R# V^ ,          V n
        R# )r   FN)r   r   r   r   r   rA   tupler   __all_zeroes____file_offset__name)rT   rx   r   file_offsetr      &&&& r   rQ   ZStructure.__init__  s    !!"!#&(#1I!U##aA qM	
'"M" $*Iq	DIr   c                s    < V ^8  d   QhRS[ /# )rp   return)rB   rx   rc      "r   __annotate__ZStructure.__annotate__  s     # # #r   c                ri   r   )r   rY   r#   r   __get_format__ZStructure.__get_format__      """r   c                sJ    V P                   V P                  V,          ,           # )zLReturn the offset within the field for the requested field in the structure.)r   r   rT   Z
field_namer   r   get_field_absolute_offsetZ#Structure.get_field_absolute_offset  s    ##d&<&<Z&HHHr   c                s(    V P                   V,          # )z?Return the offset within the structure for the requested field.)r   r   r   r   get_field_relative_offsetZ#Structure.get_field_relative_offset  s    %%j11r   c                ri   r   r   rY   r#   r   get_file_offsetZStructure.get_file_offset  s    ###r   c                r   r   r   rT   r   r   r   set_file_offsetZStructure.set_file_offset  s    %r   c                ri   )z/Returns true is the unpacked data is all zeros.)r   rY   r#   r   
all_zeroesZStructure.all_zeroes  s     """r   c                ri   )zReturn size of the structure.)r   rY   r#   r   sizeofZStructure.sizeof  s     %%%r   c                s   Tp\        V4      V P                  8  d   VR V P                   pM%\        V4      V P                  8  d   \        R4      h\        V4      \        V4      8X  d   RV n        \
        P                  ! V P                  V4      V n        \        V P                  4       F+  w  r#V P                  V,           F  p\        WV4       K  	  K-  	  R # )Nz-Data length less than expected header length.T)r8   r   ru   r$   r   r9   r:   r   r   	enumerater   setattr)rT   r"   idxr   keys   &&   r   
__unpack__ZStructure.__unpack__  s    t9t---0$001D Y/// OPPT*"&D&,mmD4G4G&N#!$"="=>HC}}S))3' * ?r   c                s   . p\        V P                  4       FE  w  r#R pV P                  V,           F  p\        W4      pWC8w  g   K   M	  VP	                  V4       KG  	  \
        P                  ! V P                  .VO5!  # r   )r   r   r   getattrrw   r9   packr   )rT   Z
new_valuesr   r   Znew_valr      &     r   __pack__ZStructure.__pack__  sy    
!$"="=>HCG}}S))!$, > * g& ? {{4..<<<r   c                s@    R P                  V P                  4       4      # )r   )r   dumprY   r#   r   rl   ZStructure.__str__  s    yy%%r   c           
     s    R RP                  V P                  4        Uu. uF"  pRP                  VP                  4       4      NK$  	  up4      ,          # u upi )z<Structure: %s>r   )r   r   r   )rT   r   r-   r   __repr__ZStructure.__repr__  sB     HH499;?;achhqwwy);?@
 	
?s   (A
c           
     s   . pVP                  RP                  V P                  4      4       \        P                   Uu. uF$  q3\        P
                  9  g   K  \        V4      NK&  	  ppV P                   EF  pV EF  p\        W4      p\        V\        \        34      '       d   VP                  R4      '       d   RP                  V4      pMRP                  V4      pVR8X  g   VR8X  d;    VR\        P                  ! \        P                  ! V4      4      ,          ,          pMM\#        V4      pVP                  R	4      '       dA   R
P%                  VP'                  R4       Uu. uF  pRP                  V4      NK  	  up4      pMPR
P%                  VP'                  R4       Uu. uF%  pW49   d   \)        V4      MRP                  V4      NK'  	  up4      pVP                  RV P*                  V,          V P,                  ,           V P*                  V,          VR,           V3,          4       EK  	  EK  	  V# u upi   \          d    TR,          p L}i ; iu upi u upi )z1Returns a string representation of the structure.z[{0}]Z
Signature_z{:<8X}z0x{:<8X}TimeDateStampdwTimeStampz	 [%s UTC]z [INVALID TIME]	Signaturern       z{:02X}z	\x{0:02x}z0x%-8X 0x%-3X %-30s %s:)rw   rx   r   rh   	printableZ
whitespaceordr   r   rA   r   longrD   timeasctimegmtime
ValueError	bytearrayr   rstripchrr   r   )	rT   indentationr   r=   Zprintable_bytesr@   r   r   Zval_strs	   &&       r   r   ZStructure.dump  s    GNN499-. #,,
,q9J9J0JFCF, 	 
 MMDd(cC;//~~l33"*//#"6","3"3C"8o-1E9#{T\\$++cBR5S'SSG 2F (nG~~k22"$''9@9PQ9PAX__Q/9PQ# #%''
 *1)@	 *AA %&$8 !$A%1%8%8%;!< *A	# ,..s3d6J6JJ..s3c		9  "N [
"  * 9#'88G9 Rs)   H?H?18I+I++I#IIc                s   / pV P                   VR&   V P                   F  pV F  p\        W4      p\        V\        \
        34      '       dE   VR8X  g   VR8X  d6    RV\        P                  ! \        P                  ! V4      4      3,          pMJMIRP                  R V Uu. uF&  p\        V\        4      '       g   \        V4      MTNK(  	  up 4       4      pRV P                  V,          V P                  ,           R	V P                  V,          R
V/W&   K  	  K  	  V#   \         d    RT,          p L]i ; iu upi )z5Returns a dictionary representation of the structure.r   r   r   z0x%-8X [%s UTC]z0x%-8X [INVALID TIME]rn   c              3   s   "   T F7  p\        V4      \        P                  9   d   \        V4      MR V,          x  K9  	  R# 5i)z\x%02xN)r   rh   r   )r   r   r-   r   r   Z&Structure.dump_dict.<locals>.<genexpr>d  s5      "!WA #&a&F,<,<"<A)a-O!Ws   ?AZ
FileOffsetOffsetZValue)r   r   r   rA   r   r   r   r   r   r   r   r   r   r   )rT   	dump_dictr@   r   r   r   r   r   r   ZStructure.dump_dictN  s6    	!%	+ MMDd(cC;//o-1E@"3 # $T[[-= >7 #C 2F '' "SV!WSVa
1c0B0B#a&"ISV!W" C !$"8"8"=@T@T"Td44S9S"	#  "0   * @"9C"?C@
 "Xs   3D!",D;!D87D8)r   r   r   r   r   r   r   r   NNr   )r[   r\   r]   r^   r   rQ   r   r   r   r   r   r   r   r   r   rl   r   r   r   r_   r`   r   r   r   r   r     s\     "8# #I2$&#
&
(*=&

4l! !r   r   c                   s   a a ] tR tRt oRtV 3R ltR tR tRR ltR t	R t
R	 tR
 tR tR tR tR tR tR tR tR tRtVtV ;t# )SectionStructureir  z#Convenience section handling class.c                s   < R V9   d   VR ,          V n         VR  RV n        RV n        RV n        RV n        \
        SV `  ! V/ VB  RV n        RV n        RV n	        RV n
        R# )rf   N)rf   PointerToRawDataVirtualAddressSizeOfRawDataMisc_VirtualSizerP   rQ   PointerToRawData_adjVirtualAddress_adjsection_min_addrsection_max_addr)rT   r   r   rU   s   &*,r   rQ   ZSectionStructure.__init__u  sn    6>TlDGt $"! $$)&)$(!"& $ $r   c                s@   V P                   f   V P                  ex   V P                  P                  V P                  4      pV P                  P                  P
                  R8  d(   V P                  V P                  8X  d   V P                  pWn         V P                   # )Nr   )r   r   rf   adjust_PointerToRawDataOPTIONAL_HEADERSectionAlignmentr   )rT   Zptrdr-   r   get_PointerToRawData_adjZ)SectionStructure.get_PointerToRawData_adj  s~    $$,1F1F1R772243H3HID
 ww&&77&@((D,?,??..D(,%(((r   c                s"   V P                   fw   V P                  ei   V P                  P                  V P                  V P                  P                  P
                  V P                  P                  P                  4      V n         V P                   # r   )r   r   rf   adjust_SectionAlignmentr   r   FileAlignmentrY   r#   r   get_VirtualAddress_adjZ'SectionStructure.get_VirtualAddress_adj  sn    ""*"".*.''*I*I''GG++<<GG++99+'
 &&&r   c                s   Vf   V P                  4       pM+WP                  4       ,
          V P                  4       ,           pVe
   WB,           pM#V P                  e   W@P                  ,           pMTpV'       d%   Ve!   Ve   \        WTV P                  ,           4      pV P
                  eM   V P                  e?   WPP
                  V P                  ,           8  d   V P
                  V P                  ,           pV P                  P                  WE # )a  Get data chunk from a section.

Allows to query data from the section by passing the
addresses where the PE file would be loaded by default.
It is then possible to retrieve code and data by their real
addresses as they would be if loaded.

Note that sections on disk can include padding that would
not be loaded to memory. That is the case if `section.SizeOfRawData`
is greater than `section.Misc_VirtualSize`, and that means
that data past `section.Misc_VirtualSize` is padding.
In case you are not interested in this padding, passing
`ignore_padding=True` will truncate the result in order
not to return the padding (if any).

Returns bytes().
)r   r   r   rR   r   r   rf   __data__)rT   startr~   Zignore_paddingr   end   &&&&  r   r|   ZSectionStructure.get_data  s    & =224F 3355--/0F /C+---CCco&2DcD$9$99:C
   ,1C1C1O**T-?-???++d.@.@@ww++r   c                sT   VR 8X  d   \        \        R4      p\        WV4       MuRV9   do   \        W4      '       d^   V'       d,   V P                  R ;;,          \        V,          ,          uu&   M*V P                  R ;;,          \        V,          ,          uu&   W P                  V&   R# )Characteristics
IMAGE_SCN_N)rG   SECTION_CHARACTERISTICSrL   hasattrrH   )rT   r   r   section_flagsr   r   __setattr__ZSectionStructure.__setattr__  s{    $$*+BLQM d/T!gd&9&9/04KD4QQ0/04KD4QQ0!dr   c                X    WP                  4       ,
          V P                  4       ,           # r   )r   r   r   r   r   get_rva_from_offsetZ$SectionStructure.get_rva_from_offset  s"    5577$:U:U:WWWr   c                r  r   )r   r   rT   r}   r   r   get_offset_from_rvaZ$SectionStructure.get_offset_from_rva  s"    0022T5R5R5TTTr   c                s    V P                   f   R# V P                  4       pY!u;8*  ;'       d    W P                  ,           8  # u # )z<Check whether the section contains the file offset provided.F)r   r   r   )rT   r   r   rF   r   contains_offsetZ SectionStructure.contains_offset  sI       ( #<<> VV-ADVDV-VV	
V	
r   c                s   V P                   e9   V P                  e+   V P                   Tu;8*  ;'       d    V P                  8  # u # V P                  4       p\        V P                  P
                  4      V P                  4       ,
          V P                  8  d   V P                  pM \        V P                  V P                  4      pV P                  eF   V P                  V P                  8  d+   W#,           V P                  8  d   V P                  V,
          pW n         W#,           V n        Y!u;8*  ;'       d    W#,           8  # u # )z8Check whether the section contains the address provided.)r   r   r   r8   rf   r   r   r   r   rS   next_section_virtual_addressr   )rT   r}   r   sizer5   r   contains_rvaZSectionStructure.contains_rva  s      ,1F1F1R((CGG$2G2GGGGG!88: tww 4#@#@#BBTEWEWW ((Dt))4+@+@AD --911D4G4GG")D,M,MM447IID 2 2 9!DD+=+DDDDDr   c                s$    V P                  V4      # r   )r	  r  r   r   containsZSectionStructure.contains  s      %%r   c                s@    V P                  V P                  4       4      # )z1Calculate and return the entropy for the section.)	entropy_Hr|   rY   r#   r   get_entropyZSectionStructure.get_entropy  s     ~~dmmo..r   c                d    \         e(   \        V P                  4       4      P                  4       # R# )z/Get the SHA-1 hex-digest of the section's data.N)r   r|   	hexdigestrY   r#   r   get_hash_sha1ZSectionStructure.get_hash_sha1  s)     (2244 r   c                r  )z1Get the SHA-256 hex-digest of the section's data.N)r   r|   r  rY   r#   r   get_hash_sha256Z SectionStructure.get_hash_sha256  )     $--/*4466 r   c                r  )z1Get the SHA-512 hex-digest of the section's data.N)r   r|   r  rY   r#   r   get_hash_sha512Z SectionStructure.get_hash_sha512"  r  r   c                r  )z-Get the MD5 hex-digest of the section's data.N)r   r|   r  rY   r#   r   get_hash_md5ZSectionStructure.get_hash_md5(  s(     ?t}}'1133 r   c                s    V'       g   R# \        \        V4      4      p^ pVP                  4        FB  p\        V4      \	        V4      ,          pW5\
        P                  ! V^4      ,          ,          pKD  	  V# )z)Calculate the entropy of a chunk of data.g        )r    r   valuesZfloatr8   mathZlog)rT   r"   Z
occurencesZentropyr   Zp_xs   &&    r   r  ZSectionStructure.entropy_H.  sa     Yt_-
""$A(SY&CTXXc1---G % r   )	r   r   r   r   r   r   rf   r   r   )NNF)r[   r\   r]   r^   r   rQ   r   r   r|   r  r  r  r  r	  r
  r  r  r  r  r  r  r_   r`   ra   rb   rd   r   r   r   r  sb     -%)'*,X"XU

$EL&/
5774 r   r   c                 sp    ! R  R4      p. p/ pV! W#4      pV ^,           F  pRV9  d$   VP                  4        VP                  V4       K-  VP                  R^4      w  rgRV9   d   \        R4      hVP                  R^4      w  rh\	        V4      pWdP                  4       8w  g   WP                  4       8  d"   VP                  4        VP                  V4       VP                  Wx4       K  	  VP                  4        \        \        V4      4      w  rrp. p\        V4       F  w  ppW9  d   VP                  V4       K  W?,          w  p
pV Uu. uF  pV\        P                  ,          .NK  	  ppVP                  V4       V F  pVV^ ,          ,          VV^ ,          &   K  	  K  	  WWW3# u upi )c                   sJ   a  ] tR tRt o R tR tR tR tR tR t	R t
R	tV tR
# ))set_bitfields_format.<locals>.Accumulatori@  c                sV    . V n         R V n        RV n        ^ V n        W n        Wn        R# )~N)
_subfields_name_type
_bits_left_comp_fields_format)rT   fmtcomp_fieldsr   r   rQ   Z2set_bitfields_format.<locals>.Accumulator.__init__A  s+     DO DJDJDO +Lr   c                sH   V P                   f   R # V P                  P                  V P                   R,           V P                  ,           4       V P                   V P                  3V P
                  \        V P                  4      ^,
          &   RV n        R V n         . V n        R # )Nr   r  )r  r  rw   r  r  r  r8   rY   r#   r   wrap_upZ1set_bitfields_format.<locals>.Accumulator.wrap_upK  ss    zz!LL

S 04:: =>8<

DOO7TDc$,,/!34DJDJ DOr   c                sD    \         V,          ^,          V n        Wn        R# )   N)r   r  r  )rT   Ztpr   r   new_typeZ2set_bitfields_format.<locals>.Accumulator.new_typeT  s    1"59DOJr   c                s    V ;P                   V,          un         V ;P                  V,          un        V P                  P                  W34       R # r   )r  r  r  rw   )rT   r   Zbitcntr   r   add_subfieldZ6set_bitfields_format.<locals>.Accumulator.add_subfieldX  s2    JJ$JOOv%OOO""D>2r   c                ri   r   )r  rY   r#   r   get_typeZ2set_bitfields_format.<locals>.Accumulator.get_type]      ::r   c                ri   r   )r  rY   r#   r   get_nameZ2set_bitfields_format.<locals>.Accumulator.get_name`  r%  r   c                ri   r   )r  rY   r#   r   get_bits_leftZ7set_bitfields_format.<locals>.Accumulator.get_bits_leftc  s    ??"r   )r  r  r  r  r  r  N)r[   r\   r]   r^   rQ   r   r"  r#  r$  r&  r'  r_   r`   r   r   r   Accumulatorr  @  s-     		!		3
			# 	#r   r(  r   r   z3Structures with bitfields do not support unions yet)r   rw   r   ZNotImplementedErrorr   r$  r'  r"  r#  r   r   r   StructureWithBitfieldsBTF_NAME_IDXextend)rx   r(  Zold_fmtr  Zacr   r   r   Zelm_bitsZ
format_str_Zfield_offsetsr@   Zformat_lengthZextended_keysr   r   Zsbfr   Zbf_namesZns   &                    r   set_bitfields_formatr-  >  s   $# $#L GK	W	*Bayyc>JJLNN3 YYsA.(?%E  &^^C3x={{}$3C3C3E(EJJLKK!
+' ( JJL8B5>8R5J=MdOS!  %!3FIJcQ-::;<cJX&A"/A"7M!A$  $ }MWW Ks   !F3c                   s   a a ] tR tRt oRt^ t^t^ t^tRR lt	V 3R lt
V 3R ltRV 3R lltV 3R ltR tR	 tR
tVtV ;t# )r)  i  a  
Extends Structure's functionality with support for bitfields such as:
    ('B:4,LowerHalf', 'B:4,UpperHalf')
To this end, two lists are maintained:
    * self.__keys__ that contains compound fields, for example
      ('B,~LowerHalfUpperHalf'), and is used during packing/unpaking
    * self.__keys_ext__ containing a separate key for each field (ex., LowerHalf,
      UpperHalf) to simplify implementation of dump()
This way the implementation of unpacking/packing and dump() from Structure can be
reused.

In addition, we create a dictionary:
    <comound_field_index_in_keys> -->
        (data type, [ (subfield name, length in bits)+ ] )
that facilitates bitfield paking and unpacking.

With lru_cache() creating only once instance per format string, the memory
overhead is negligible.
c                s   \        V4      w  V n        V n        V n        V n        V n        V n        \        V P                  4       Uu. uF  pR NK  	  upV n        RV n	        W0n
        VR 8w  d	   W n        R # V^ ,          V n        R # u upi NF)r-  r   r   r   r   __keys_ext____compound_fields__ranger   r   r   r   )rT   rx   r   r   r=   r   r   rQ   ZStructureWithBitfields.__init__  s     !(	
""M$ 6;4;Q;Q5R&S5Rt5R&S##* DLD	fQi	 'Ts   Bc                sF   < \         SV `  V4       V P                  4        R # r   )rP   r   _unpack_bitfield_attributesrT   r"   rU   rX   r   r   Z!StructureWithBitfields.__unpack__  s     	4 ((*r   c                s   < V P                  4         \        SV `	  4       pV P                  4        V#   T P                  4        i ; ir   )_pack_bitfield_attributesrP   r   r2  r3     & r   r   ZStructureWithBitfields.__pack__  sB    &&(	/7#%D,,. ,,.s	   3 Ac                s   < V P                   pV P                  V n          \        SV `  V4      pW n         V#   Y n         i ; ir   )r   r/  rP   r   )rT   r   tkretrU   s   &&  r   r   ZStructureWithBitfields.dump  s?    ]]))	',{+CM
 Ms   7 ?c                s   < V P                   pV P                  V n          \        SV `  4       pWn         V#   Yn         i ; ir   )r   r/  rP   r   )rT   r6  r7  rU   s   &  r   r   Z StructureWithBitfields.dump_dict  s>    ]]))	'#%CM
 Ms   6 >c                s   V P                   P                  4        F  pV P                  V,          ^ ,          p\        W4      p\	        W4       ^ pV P                   V,          \
        P                  ,           F|  p^V\
        P                  ,          ,          ^,
          pWd,          p\        V V\
        P                  ,          W6,          V,	          4       WE\
        P                  ,          ,          pK~  	  K  	  R# )zQReplace compound attributes corresponding to bitfields with separate
sub-fields.
N)
r0  r@   r   r   Zdelattrr)  CF_SUBFLD_IDXBTF_BITCNT_IDXr   r*  )rT   r=   cf_nameZcvaloffstsfmasks   &      r   r2  Z2StructureWithBitfields._unpack_bitfield_attributes  s     ))..0AmmA&q)G4)DD"E..q12H2V2VWWR 6 E EFF!K-::;[U*
 2AABB X 1r   c                s   V P                   P                  4        F  pV P                  V,          ^ ,          p^ ^ rCV P                   V,          \        P                  ,           F{  p^V\        P
                  ,          ,          ^,
          p\        W\        P                  ,          4      V,          pWGV,          ,          pW5\        P
                  ,          ,          pK}  	  \        WV4       K  	  R# )z(Pack attributes into a compound bitfieldN)	r0  r@   r   r)  r8  r9  r   r*  r   )rT   r=   r:  r;  Zacc_valr<  r=  Z	field_val   &       r   r4  Z0StructureWithBitfields._pack_bitfield_attributes  s    ))..0AmmA&q)G7..q12H2V2VWWR 6 E EFF!KD%;%H%H"IJTQ  --2AABB X D7+ 1r   )
r   r0  r   r   r   r   r   r/  r   r   r   r   )r[   r\   r]   r^   r   r*  r9  ZCF_TYPE_IDXr8  rQ   r   r   r   r   r2  r4  r_   r`   ra   rb   rd   r   r)  r)    sI     ( LNKM8 +C&, ,r   r)  c                   s6   a a ] tR tRt oRtV 3R ltRtVtV ;t# )DataContaineri  zGeneric data container.c                s^   < \         SV `  pVP                  4        F  w  r4V! W44       K  	  R # r   )rP   r  items)rT   r   Zbare_setattrr   rJ   rU   s   &,   r   rQ   ZDataContainer.__init__  s'    w* ,,.JC$ )r   rM   )	r[   r\   r]   r^   r   rQ   r_   r`   ra   rb   rd   r   r?  r?    s     !% %r   r?  c                       ] tR tRtRtRtR# )ImportDescDatai  zHolds import descriptor information.

dll:        name of the imported DLL
imports:    list of imported symbols (ImportData instances)
struct:     IMAGE_IMPORT_DESCRIPTOR structure
rM   Nr[   r\   r]   r^   r   r_   rM   r   r   rB  rB        r   rB  c                   *   a  ] tR tRt o RtR tRtV tR# )
ImportDatai  zHolds imported symbol's information.

ordinal:    Ordinal of the symbol
name:       Name of the symbol
bound:      If the symbol is bound, this contains
            the address.
c                s   \        V R 4      '       Ed   \        V R4      '       Ed   \        V R4      '       Ed   VR 8X  d   V P                  P                  \        8X  d   \        pM%V P                  P                  \
        8X  d   \        pXVR,          ,          V P                  n        V P                  P                  V P                  n	        V P                  P                  V P                  n
        V P                  P                  V P                  n        EMVR8X  d   V P                  e   W P                  n	        V P                  P                  V P                  n	        V P                  P                  V P                  n
        V P                  P                  V P                  n        EMFVR8X  d   W P                  n	        V P                  P                  V P                  n        V P                  P                  V P                  n
        V P                  P                  V P                  n        MVR8X  d   V P                  '       d   V P                  P                  V P                  4      pV P                  P                  V P                   ^ V,          4       \#        V4      \#        V P$                  4      8  d   \'        R4      hV P                  P)                  V P                  V4       W P*                  V&   R# )ordinalboundr     Naddress9The export name provided is longer than the existing one.)r   rf   PE_TYPEOPTIONAL_HEADER_MAGIC_PEIMAGE_ORDINAL_FLAGOPTIONAL_HEADER_MAGIC_PE_PLUSIMAGE_ORDINAL_FLAG64struct_tableOrdinalAddressOfDataFunctionForwarderString
struct_iatname_offsetr  set_dword_at_offsetordinal_offsetr8   r   ru   set_bytes_at_offsetrH   )rT   r   r   ordinal_flagZname_rvarK   r   r  ZImportData.__setattr__  s%    D)$$g&&f%%y 77??&>>#5LWW__(EE#7L -9C&L,I!!)262C2C2K2K!!/-1->->-F-F!!*484E4E4M4M!!1??.47OO148OO4Q4QDOO1/3/L/LDOO,6:oo6S6SDOO3"25!!/,0,=,=,K,K!!)-1->->-L-L!!*484E4E4S4S!!1 ####ww::4;K;KLHGG//++g-A 3x#dii.0+W  GG//0@0@#F!dr   rM   Nr[   r\   r]   r^   r   r  r_   r`   r   r   r   rF  rF    s     2" 2"r   rF  c                   rA  )ExportDirDataiL  zHolds export directory information.

struct:     IMAGE_EXPORT_DIRECTORY structure
symbols:    list of exported symbols (ExportData instances)rM   NrC  rM   r   r   r]  r]  L  s    Cr   r]  c                   rE  )
ExportDataiS  aD  Holds exported symbols' information.

ordinal:    ordinal of the symbol
address:    address of the symbol
name:       name of the symbol (None if the symbol is
            exported by ordinal only)
forwarder:  if the symbol is forwarded it will
            contain the name of the target symbol,
            None otherwise.
c                s   \        V R 4      '       EdM   \        V R4      '       Ed:   \        V R4      '       Ed'   \        V R4      '       Ed   VR 8X  d(   V P                  P                  V P                  V4       MVR8X  d(   V P                  P	                  V P
                  V4       MVR8X  dV   \        V4      \        V P                  4      8  d   \        R4      hV P                  P                  V P                  V4       M[VR8X  dU   \        V4      \        V P                  4      8  d   \        R4      hV P                  P                  V P                  V4       W P                  V&   R# )rG  rJ  	forwarderr   rK  z<The forwarder name provided is longer than the existing one.N)r   rf   set_word_at_offsetrY  rX  address_offsetr8   r   ru   rZ  rW  r_  forwarder_offsetrH   rT   r   r   r   r   r  ZExportData.__setattr___  s    D)$$i((k**f%%y **4+>+>D"++D,?,?E s8c$))n,'S  ++D,<,<cB$ s8c$..11'V  ++D,A,A3G!dr   rM   Nr\  r   r   r   r^  r^  S  s     	 "  "r   r^  c                   rA  )ResourceDirDatai  zHolds resource directory information.

struct:     IMAGE_RESOURCE_DIRECTORY structure
entries:    list of entries (ResourceDirEntryData instances)
rM   NrC  rM   r   r   rd  rd        r   rd  c                   rA  )ResourceDirEntryDatai  a  Holds resource directory entry data.

struct:     IMAGE_RESOURCE_DIRECTORY_ENTRY structure
name:       If the resource is identified by name this
            attribute will contain the name string. None
            otherwise. If identified by id, the id is
            available at 'struct.Id'
id:         the id, also in struct.Id
directory:  If this entry has a lower level directory
            this attribute will point to the
            ResourceDirData instance representing it.
data:       If this entry has no further lower directories
            and points to the actual resource data, this
            attribute will reference the corresponding
            ResourceDataEntryData instance.
(Either of the 'directory' or 'data' attribute will exist,
but not both.)
rM   NrC  rM   r   r   rf  rf    s    r   rf  c                   rA  )ResourceDataEntryDatai  zHolds resource data entry information.

struct:     IMAGE_RESOURCE_DATA_ENTRY structure
lang:       Primary language ID
sublang:    Sublanguage ID
rM   NrC  rM   r   r   rg  rg    rD  r   rg  c                   rA  )	DebugDatai  zHolds debug information.

struct:     IMAGE_DEBUG_DIRECTORY structure
entries:    list of entries (IMAGE_DEBUG_TYPE instances)
rM   NrC  rM   r   r   rh  rh    re  r   rh  c                   rA  )DynamicRelocationDatai  zHolds dynamic relocation information.

struct:        IMAGE_DYNAMIC_RELOCATION structure
symbol:        Symbol to which dynamic relocations must be applied
relocations:   List of dynamic relocations for this symbol (BaseRelocationData instances)
rM   NrC  rM   r   r   ri  ri    rD  r   ri  c                   rA  )FunctionOverrideDatai  ap  Holds Function and bdd dynamic relocation information.

struct:        IMAGE_DYNAMIC_RELOCATION structure
symbol:        Symbol to which dynamic relocations must be applied
bdd_relocs:    List of bdd dynamic relocations (BddDynamicRelocationData instances)
func_relocs:   List of function override dynamic relocations (FunctionOverrideDynamicRelocationData instances)
rM   NrC  rM   r   r   rj  rj        r   rj  c                   rA  )%FunctionOverrideDynamicRelocationDatai  a  Holds Function override dynamic relocation information.

struct:        IMAGE_FUNCTION_OVERRIDE_DYNAMIC_RELOCATION structure
func_rva:      Original function rva
override_rvas: List of overriding function rvas
relocations:   List of dynamic relocations (BaseRelocationData instances)
rM   NrC  rM   r   r   rl  rl    rk  r   rl  c                   rA  )BddDynamicRelocationDatai  zaHolds Bdd dynamic relocation information.

struct:        IMAGE_BDD_DYNAMIC_RELOCATION structure
rM   NrC  rM   r   r   rm  rm        r   rm  c                   rA  )BaseRelocationDatai  zHolds base relocation information.

struct:     IMAGE_BASE_RELOCATION structure
entries:    list of relocation data (RelocationData instances)
rM   NrC  rM   r   r   ro  ro    re  r   ro  c                   rE  )RelocationDatai  zHolds relocation information.

type:       Type of relocation
            The type string can be obtained by
            RELOCATION_TYPE[type]
rva:        RVA of the relocation
c                sD   \        V R 4      '       d   V P                  P                  pVR8X  d   V^,          VR,          ,          pM:VR8X  d4   \        W P                  ,
          ^ 4      pVR,          VR,          ,          pW0P                  n        W P
                  V&   R# )r9   type  r}   i   N)r   r9   DatarS   base_rvarH   )rT   r   r   wordr   rK   r   r  ZRelocationData.__setattr__  s    
 4"" ;;##Dv~r	dUl3S==0!4v&5.9  $KK!dr   rM   Nr\  r   r   r   rp  rp    s     " "r   rp  c                   rA  )TlsDatai  zBHolds TLS information.

struct:     IMAGE_TLS_DIRECTORY structure
rM   NrC  rM   r   r   rv  rv    rn  r   rv  c                   rA  )BoundImportDescDatai  a  Holds bound import descriptor data.

This directory entry will provide information on the
DLLs this PE file has been bound to (if bound at all).
The structure will contain the name and timestamp of the
DLL at the time of binding so that the loader can know
whether it differs from the one currently present in the
system and must, therefore, re-bind the PE's imports.

struct:     IMAGE_BOUND_IMPORT_DESCRIPTOR structure
name:       DLL name
entries:    list of entries (BoundImportRefData instances)
            the entries will exist if this DLL has forwarded
            symbols. If so, the destination DLL will have an
            entry in this list.
rM   NrC  rM   r   r   rw  rw    s    r   rw  c                   rA  )LoadConfigDatai  zHolds Load Config data.

struct:     IMAGE_LOAD_CONFIG_DIRECTORY structure
name:       dll name
dynamic_relocations: dynamic relocation information, if present
rM   NrC  rM   r   r   rx  rx    rD  r   rx  c                   rA  )BoundImportRefDatai  zHolds bound import forwarder reference data.

Contains the same information as the bound descriptor but
for forwarded DLLs, if any.

struct:     IMAGE_BOUND_FORWARDER_REF structure
name:       dll name
rM   NrC  rM   r   r   ry  ry    s    r   ry  c                   rA  )ExceptionsDirEntryDatai*  zHolds the data related to SEH (and stack unwinding, in particular)

struct      an instance of RUNTIME_FUNTION
unwindinfo  an instance of UNWIND_INFO
rM   NrC  rM   r   r   rz  rz  *  re  r   rz  c                   s   a a ] tR tRt oRtRV 3R lltV 3R ltRV 3R lltV 3R ltR t	R t
V 3R	 ltR
 tR tRtVtV ;t# )
UnwindInfoi2  zHandles the complexities of UNWIND_INFO structure:
* variable number of UWIND_CODEs
* optional ExceptionHandler and FunctionEntry fields
c                s   < \         SV `  RVR7       \         SV `	  4       V n        RV n        \        R^ R7      V n        RV n        RV n        R# )UNWIND_INFOr   NF)r|  )zB:3,Versionz	B:5,FlagszB,SizeOfPrologzB,CountOfCodeszB:4,FrameRegisterzB:4,FrameOffsetUNWIND_CODE)B,CodeOffsetB:4,UnwindOp
B:4,OpInfo)	rP   rQ   r   
_full_size_opt_field_namer)  
_code_info_chained_entry_finished_unpacking)rT   r   rU   rX   r   rQ   ZUnwindInfo.__init__8  s[    
 $ 	 	
  '.*#0K
 ##( r   c                s  < V P                   '       d   R# \        S	V `	  V4       V P                  ^,           R	,          p\        S	V `  4       W P
                  P	                  4       ,          ,           pTV P                  ^ 8X  d   ^ M\        R,          ,           V n        \        V4      V P                  8  d   R# V P                  ^8w  d.   V P                  ^8w  d   R\        V P                  4      ,           # . V n        \        S	V `  4       pV P                  pV^ 8  Ed$   V P
                  P                  WW@P
                  P	                  4       ,            4       \        P                  V P
                  4      pVf$   R\        V P                  V,           4      ,           # VP!                  V P
                  V 4      pV P
                  P	                  4       V,          pVP#                  V P
                  WWH,            V V P                  V,           4       WH,          pWW,          pV P                  P%                  V4       EK+  V P&                  '       g   V P(                  '       d   RV n        V P,                  '       d   RV n        V P*                  R8w  dH   \/        V V P*                  \0        P2                  ! RWV\        R,          ,            4      ^ ,          4       RV n         R# )
zUnpacks the UNWIND_INFO "in two calls", with the first call establishing
a full size of the structure and the second, performing the actual unpacking.
Nr   z&Unsupported version of UNWIND_INFO at zUnknown UNWIND_CODE at ZExceptionHandlerFunctionEntry<ITi)r  rP   r   ZCountOfCodesr   r  Flagsr   r  r8   Versionhexr   UnwindCodesPrologEpilogOpsFactorycreatelength_in_code_structures
initializerw   UNW_FLAG_EHANDLERUNW_FLAG_UHANDLERr  UNW_FLAG_CHAININFOr   r9   r:   )
rT   r"   Zcodes_cnt_maxZhdlr_offsetZroZ
codes_leftZucodeZlen_in_codesZopc_sizerU   s
   &&       r   unpack_in_stagesZUnwindInfo.unpack_in_stagesP  sH    ###4 **Q."4gn&9O9O9Q)QQ%qA&9#&>
 t9t&<<1!2;c$BVBV>WWWW^&&
1nOO&&too6L6L6N1N'OP*11$//BE}03t7K7Kb7P3QQQ ::4??DQL--/,>H"-($$r)	 NB&J##E*!!!T%;%;%;#5D """#2D 4'$$$[;Ns;S-ST $( r   c                sF  < V P                   R 8w  d\   V P                  \        R,          ,
          V P                  V P                   &   V P                  P                  V P                   .4        \        SV `  V4      pV P                   R 8w  d   V P                  P                  4        TP                  RRP                  \         Uu. uF&  p\        Y^ ,          4      '       g   K  T^ ,          NK(  	  up4      ,           4       TP                  RRP                  T P                   Uu. uF%  qDP                  4       '       g   K  \        T4      NK'  	  up4      ,           4       T#   T P                   R 8w  d   T P                  P                  4        i i ; iu upi u upi )Nr   Flags: , zUnwind codes: z; )r  r  r   r   r/  rw   rP   r   popr   unwind_info_flagsr   r  is_validrB   )rT   r   r   r   r   rU   s   &&   r   r   ZUnwindInfo.dump  sT    4'"5c":: ""4#7#78 $$d&:&:%;<	(7<,D##t+!!%%'ii'8P'8!GDA$<O1'8PQR	
 	ii)9)9J)9AZZ\Q)9JKL	
  ##t+!!%%' ,
 Q Ks$   /E( F'F*FF(.Fc                s  < V P                   R 8w  d\   V P                  \        R,          ,
          V P                  V P                   &   V P                  P                  V P                   .4        \        SV `  4       pV P                   R 8w  d   V P                  P                  4        V#   T P                   R 8w  d   T P                  P                  4        i i ; i)Nr   )	r  r  r   r   r/  rw   rP   r   r  )rT   r7  rU   r5  r   r   ZUnwindInfo.dump_dict  s    4'"5c":: ""4#7#78 $$d&:&:%;<	('#%C##t+!!%%'
 ##t+!!%%' ,s   /B* *.Cc                s<   VR 8X  d   \        W\        4       MuRV9   do   \        W4      '       d^   V'       d,   V P                  R ;;,          \        V,          ,          uu&   M*V P                  R ;;,          \        V,          ,          uu&   W P                  V&   R# )r  Z	UNW_FLAG_N)rL   r  r   rH   UNWIND_INFO_FLAGSrc  r   r   r  ZUnwindInfo.__setattr__  si    7?d!23D WT%8%8g&*;D*AA&g&*;D*AA&!dr   c                ri   r   )r  rY   r#   r   r   ZUnwindInfo.sizeof  s    r   c                s  < \        V P                  4      p\        SV `  4       V^ \        SV `  4       % \        SV `  4       pV P
                   F  pW#P                  P	                  4       ,           V P                  8  d    M^VP                  P                  4       WW#P                  P	                  4       ,           % W#P                  P	                  4       ,          pK  	  V P                  R8w  dT   \        P                  ! R\        W P                  4      4      VV P                  \        R,          ,
          V P                  % V# )r    Nr  r   )r   r  rP   r   r   r  r9   r  r   r   r   )rT   r"   Z
cur_offsetZucrU   s   &   r   r   ZUnwindInfo.__pack__  s    )%*W%5%7Q!"W^%
""BII,,..@ACASASAUDj99+;+;+==>))**,,J	 # 4' D'$0D0D"EF "5c"::T__ r   c                ri   r   )r  rY   r#   r   get_chained_function_entryZ%UnwindInfo.get_chained_function_entry  r   r   c                sJ    V P                   R 8w  d   \        R4      hWn         R # )Nz(Chained function entry cannot be changed)r  ru   )rT   entryr   r   set_chained_function_entryZ%UnwindInfo.set_chained_function_entry  s"    $& JKK#r   )r  r  r  r  r  r  r   )r[   r\   r]   r^   r   rQ   r  r   r   r  r   r   r  r  r_   r`   ra   rb   rd   r   r{  r{  2  s=     
)0:x6"$#$ $r   r{  c                   <   a  ] tR tRt o RtR tR tR tR tRt	V t
R# )	PrologEpilogOpi  zMeant as an abstract class representing a generic unwind code.
There is a subclass of PrologEpilogOp for each member of UNWIND_OP_CODES enum.
c                s~    \        V P                  V4      VR 7      V n        V P                  P                  V4       R# )r}  N)r)  _get_formatr9   r   )rT   unw_coder"   unw_infor   s   &&&&&r   r  ZPrologEpilogOp.initialize  s2    ,X&K
 	t$r   c                s    ^# )zComputes how many UNWIND_CODE structures UNWIND_CODE occupies.
May be called before initialize() and, for that reason, should not rely on
the values of intance attributes.
rM   rT   r  r  r   r   r  Z(PrologEpilogOp.length_in_code_structures  s    
 r   c                s    R # )TrM   rY   r#   r   r  ZPrologEpilogOp.is_valid  s    r   c                    R# )r  r~  rM   rT   r  r   r   r  ZPrologEpilogOp._get_format  s    NNr   r9   N)r[   r\   r]   r^   r   r  r  r  r  r_   r`   r   r   r   r  r    s%     %O Or   r  c                   r   )PrologEpilogOpPushRegi  UWOP_PUSH_NONVOLc                r  )UNWIND_CODE_PUSH_NONVOL)r  )r  r  B:4,RegrM   r  r   r   r  Z!PrologEpilogOpPushReg._get_format  s    WWr   c                sR    R \         V P                  P                  ,          ,           # )z	.PUSHREG )	REGISTERSr9   RegrY   r#   r   rl   ZPrologEpilogOpPushReg.__str__  s    Yt{{777r   rM   N)	r[   r\   r]   r^   r   r  rl   r_   r`   r   r   r   r  r    s     X8 8r   r  c                   r  )	PrologEpilogOpAllocLargei  UWOP_ALLOC_LARGEc                s<    R RRRVP                   ^ 8X  d   R33# R33# )ZUNWIND_CODE_ALLOC_LARGEr  r  r  zH,AllocSizeInQwordszI,AllocSizeOpInfor  r   r   r  Z$PrologEpilogOpAllocLarge._get_format  sB    %)1A)=%	
 	
 DQ	
 	
r   c                s,    VP                   ^ 8X  d   ^# ^# r   r  r  r   r   r  Z2PrologEpilogOpAllocLarge.length_in_code_structures  s    OOq(q/a/r   c                s    V P                   P                  ^ 8X  d   V P                   P                  ^,          # V P                   P                  # r   )r9   r  ZAllocSizeInQwordsZ	AllocSizerY   r#   r   get_alloc_sizeZ'PrologEpilogOpAllocLarge.get_alloc_size  sC     {{!!Q& KK))A-	
 &&	
r   c                B    R \        V P                  4       4      ,           # z.ALLOCSTACK r  r  rY   r#   r   rl   Z PrologEpilogOpAllocLarge.__str__      D$7$7$9 :::r   rM   N)r[   r\   r]   r^   r   r  r  r  rl   r_   r`   r   r   r   r  r    s!     	
0
; ;r   r  c                   s6   a  ] tR tRt o RtR tR tR tRtV t	R# )PrologEpilogOpAllocSmalli  UWOP_ALLOC_SMALLc                r  )UNWIND_CODE_ALLOC_SMALL)r  )r  r  zB:4,AllocSizeInQwordsMinus8rM   r  r   r   r  Z$PrologEpilogOpAllocSmall._get_format      
 	
r   c                sJ    V P                   P                  ^,          ^,           # r!  )r9   ZAllocSizeInQwordsMinus8rY   r#   r   r  Z'PrologEpilogOpAllocSmall.get_alloc_size$  s    {{22Q6::r   c                r  r  r  rY   r#   r   rl   Z PrologEpilogOpAllocSmall.__str__'  r  r   rM   N)
r[   r\   r]   r^   r   r  r  rl   r_   r`   r   r   r   r  r    s     
;; ;r   r  c                   s<   a a ] tR tRt oRtV 3R ltR tRtVtV ;t	# )PrologEpilogOpSetFPi+  UWOP_SET_FPREGc                sz   < \         SV `  WW44       VP                  V n        VP                  ^,          V n        R# )   N)rP   r  ZFrameRegister_frame_registerZFrameOffset_frame_offsetrT   r  r"   r  r   rU      &&&&&r   r  ZPrologEpilogOpSetFP.initialize.  s3    88A'55%11B6r   c                s    R \         V P                  ,          ,           R,           \        V P                  4      ,           # )z
.SETFRAME r  )r  r  r  r  rY   r#   r   rl   ZPrologEpilogOpSetFP.__str__3  s:    ,,-. $$$%&	
r   )r  r  )
r[   r\   r]   r^   r   r  rl   r_   r`   ra   rb   rd   r   r  r  +  s     7

 
r   r  c                   r  )	PrologEpilogOpSaveRegi<  UWOP_SAVE_NONVOLc                    ^# rp   rM   )rT   unwcoder  r   r   r  Z/PrologEpilogOpSaveReg.length_in_code_structures?      r   c                s<    V P                   P                  ^,          # r  )r9   ZOffsetInQwordsrY   r#   r   
get_offsetZ PrologEpilogOpSaveReg.get_offsetB  s    {{))A--r   c                r  )UNWIND_CODE_SAVE_NONVOL)r  )r  r  r  zH,OffsetInQwordsrM   r  r   r   r  Z!PrologEpilogOpSaveReg._get_formatE  r  r   c                s    R \         V P                  P                  ,          ,           R,           \        V P	                  4       4      ,           # z	.SAVEREG r  )r  r9   r  r  r  rY   r#   r   rl   ZPrologEpilogOpSaveReg.__str__K  s0    Yt{{77$>T__EVAWWWr   rM   Nr[   r\   r]   r^   r   r  r  r  rl   r_   r`   r   r   r   r  r  <  s#     .
X Xr   r  c                   r  )	PrologEpilogOpSaveRegFariO  UWOP_SAVE_NONVOL_FARc                    ^#    rM   r  r   r   r  Z2PrologEpilogOpSaveRegFar.length_in_code_structuresR  r  r   c                .    V P                   P                  # r   r9   r   rY   r#   r   r  Z#PrologEpilogOpSaveRegFar.get_offsetU      {{!!!r   c                r  )UNWIND_CODE_SAVE_NONVOL_FAR)r  r  r  r  zI,OffsetrM   r  r   r   r  Z$PrologEpilogOpSaveRegFar._get_formatX  r  r   c                s    R \         V P                  P                  ,          ,           R,           \        V P                  P                  4      ,           # r  )r  r9   r  r  r   rY   r#   r   rl   Z PrologEpilogOpSaveRegFar.__str__^  s3    Yt{{77$>T[[EWEWAXXXr   rM   Nr  r   r   r   r  r  O  s#     "
Y Yr   r  c                   r  )	PrologEpilogOpSaveXMMib  UWOP_SAVE_XMM128c                r  )UNWIND_CODE_SAVE_XMM128)r  )r  r  r  zH,OffsetIn2QwordsrM   r  r   r   r  Z!PrologEpilogOpSaveXMM._get_formate  r  r   c                r  r  rM   r  r   r   r  Z/PrologEpilogOpSaveXMM.length_in_code_structuresk  r  r   c                s<    V P                   P                  ^,          # )r  )r9   ZOffsetIn2QwordsrY   r#   r   r  Z PrologEpilogOpSaveXMM.get_offsetn  s    {{**R//r   c                s    R \        V P                  P                  4      ,           R,           \        V P	                  4       4      ,           # z.SAVEXMM128 XMMr  )rB   r9   r  r  r  rY   r#   r   rl   ZPrologEpilogOpSaveXMM.__str__q  s0     3t{{#77$>T__EVAWWWr   rM   Nr[   r\   r]   r^   r   r  r  r  rl   r_   r`   r   r   r   r  r  b  s#     
0X Xr   r  c                   r  )	PrologEpilogOpSaveXMMFariu  UWOP_SAVE_XMM128_FARc                r  )UNWIND_CODE_SAVE_XMM128_FAR)r  r  rM   r  r   r   r  Z$PrologEpilogOpSaveXMMFar._get_formatx  r  r   c                r  r  rM   r  r   r   r  Z2PrologEpilogOpSaveXMMFar.length_in_code_structures~  r  r   c                r  r   r  rY   r#   r   r  Z#PrologEpilogOpSaveXMMFar.get_offset  r  r   c                s    R \        V P                  P                  4      ,           R,           \        V P                  P                  4      ,           # r  )rB   r9   r  r  r   rY   r#   r   rl   Z PrologEpilogOpSaveXMMFar.__str__  s3     3t{{#77$>T[[EWEWAXXXr   rM   Nr  r   r   r   r  r  u  s#     
"Y Yr   r  c                   rE  )PrologEpilogOpPushFramei  UWOP_PUSH_MACHFRAMEc                s\    R V P                   P                  '       d	   R,           # R,           # )z
.PUSHFRAMEz <code>rn   )r9   r  rY   r#   r   rl   ZPrologEpilogOpPushFrame.__str__  s$    DKK,>,>,>yGGBGGr   rM   N)r[   r\   r]   r^   r   rl   r_   r`   r   r   r   r  r    s     H Hr   r  c                   sT   a a ] tR tRt oRtV 3R ltR tR tR tR t	R t
R	tVtV ;t# )
PrologEpilogOpEpilogMarkeri  UWOP_EPILOGc                s   < R V n         \        VR4      '       * V n        \        SV `  WW44       V P                  '       d=   \        VRV P                  P                  4       VP                  ^,          ^ 8H  V n         VP                  V n
        R# )TSizeOfEpilogN)_long_offstr   _firstrP   r  r   r9   Sizer  r  _epilog_sizer  r  r   r  Z%PrologEpilogOpEpilogMarker.initialize  sn    !(N;;88A;;;Hndkk.>.>?'2a7D$11r   c                sh    V P                   '       d    R VP                  ^,          ^8X  d   R3# R3# R# )UNWIND_CODE_EPILOG)zB,OffsetLow,Sizer  	B:4,Flags)zB,Sizer  r  B,OffsetLowz
B:4,UnusedB:4,OffsetHigh)r  )r  r  r  )r  r  r  r   r   r  Z&PrologEpilogOpEpilogMarker._get_format  sJ     ;;;$??Q&!+ B 	  r   c                s^    \        VR 4      '       g   VP                  ^,          ^ 8X  d   ^# ^# )r  )r   r  r  r   r   r  Z4PrologEpilogOpEpilogMarker.length_in_code_structures  s6     8^44(//A:MRS9S 	
 	
r   c                s    V P                   P                  V P                  '       d$   V P                   P                  ^,          ,          # ^ ,          # r  )r9   Z	OffsetLowr  Z
OffsetHighrY   r#   r   r  Z%PrologEpilogOpEpilogMarker.get_offset  sC    {{$$+/+;+;+;DKK""a'
 	
AB
 	
r   c                s(    V P                  4       ^ 8  # r   )r  rY   r#   r   r  Z#PrologEpilogOpEpilogMarker.is_valid  s     1$$r   c                s    V P                  4       ^ 8  dB   R\        V P                  4      ,           R,           \        V P                  4       4      ,           # R# )r    zEPILOG: size=z, offset from the end=-rn   )r  r  r  rY   r#   r   rl   Z"PrologEpilogOpEpilogMarker.__str__  sX      1$	 $##$%'( $//#$%	
 	
r   )r  r  r  )r[   r\   r]   r^   r   r  r  r  r  r  rl   r_   r`   ra   rb   rd   r   r  r    s+     2.


%	
 	
r   r  c                   s`   a  ] tR tRt o Rt]]]]]	]
]]]]]]]]]]]]]]/
t]R 4       tRtV tR# )r  i  zBA factory for creating unwind codes based on the value of UnwindOpc                s    V P                   pV\        P                  9   d   \        P                  V,          ! 4       # R # r   )ZUnwindOpr  _class_dict)r  Zcoder-   r   r  ZPrologEpilogOpsFactory.create  s@     -999 #..t46	
 	
r   rM   N)r[   r\   r]   r^   r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  Zstaticmethodr  r_   r`   r   r   r   r  r    sa     L 	/22+/6/64/K 
 
r   r  z!#$%&'()-@^_`{}~+,.;=[]:c                 s  a V e"   \        V \        \        \        34      '       g   R# \        R,           o\
        ;QJ d(    V3R l\        V 4       4       F  '       d   K   R# 	  R# ! V3R l\        V 4       4       4      # )NFs   \/c              3   s,   <"   T F	  qS9   x  K  	  R # 5ir   rM   )r   r   allowedr5  r   r   Z(is_valid_dos_filename.<locals>.<genexpr>  s     ,VG|Vs   T)rA   rB   rC   r   allowed_filenameallset)r   r  s   &@r   is_valid_dos_filenamer    sY    y
1sE9&=>>'G3,SV,33,3,3,SV,,,r   c                sh    V ^8  d   QhR\         \        \        \        3,          R\        R\        /# )rp   r   relax_allowed_charactersr   )r   rB   rC   r   Zboolr   s   "r   r   r   	  s0     
 
S%"#
?C
	
r   c                 s  a R oV'       d   RoV RJ;'       dp    \        V \        \        \        34      ;'       dM    \        ;QJ d(    V3R l\        V 4       4       F  '       d   K   R# 	  R# ! V3R l\        V 4       4       4      # )s	   ._?@$()<>s   !"#$%&'()*+,-./:<>?[\]^_`{|}~@Nc              3   sN   <"   T F  q\         9   ;'       g    VS9   x  K  	  R # 5ir   )allowed_function_name)r   r   allowed_extrar5  r   r   Z)is_valid_function_name.<locals>.<genexpr>	  s%     SFq++AAqM/AAFs   %%FT)rA   rB   rC   r   r  r  )r   r  r  s   &&@r   is_valid_function_namer  
	  s     !M;	 	T 	Tq3y12	T 	TCSCPQFSCC  SCPQFSSr   c                   sJ  a  ] tR tRt o RtRatRbtRctRdtRet	Rft
RgtRhtRitRjtRktRltRmtRntRotRptRqtRrtRstRttRutRvtRwtRxtRytRztR{tR|t R}t!R~t"Rt#Rt$Rt%Rt&Rt'Rt(Rt)Rt*Rt+Rt,Rt-Rt.Rt/RRR]0^x3R lt1R t2R t3R t4R t5R	 t6R
 t7R t8R t9R t:R t;R t<RR lt=R t>RR lt?R t@R tAR tBR tCR tDR tER tFRR ltGR tHR tIR tJRR ltKR tLR  tMR! tNRR" ltOR# tPR$ tQR% tRRR& ltSR' tTR( tURR) ltVRR* ltWRR+ ltXRR, ltYR- tZRR. lt[R/ t\R0 t]]^3R1 lt_R2 t`R3 taRR4 ltbR5 tcR6 tdR7 teR8 tfR9 tgRR: lthRR; ltiR< tjR= tkR> tlR? tmR@ tnRA toRB tpRC tqRD trRE tsRF ttRG tuRH tvRI twRJ txRK tyRL tzRM t{RN t|RO t}RP t~RQ tV 3RR lRS ltRT tRU tRV tRW tRX tRY tRZ tR[ tR\ tR] tR^ tR_ tR`tV tR# )PEi	  a  A Portable Executable representation.

This class provides access to most of the information in a PE file.

It expects to be supplied the name of the file to load or PE data
to process and an optional argument 'fast_load' (False by default)
which controls whether to load all the directories information,
which can be quite time consuming.

pe = pefile.PE('module.dll')
pe = pefile.PE(name='module.dll')

would load 'module.dll' and process it. If the data is already
available in a buffer the same can be achieved with:

pe = pefile.PE(data=module_dll_data)

The "fast_load" can be set to a default by setting its value in the
module itself by means, for instance, of a "pefile.fast_load = True".
That will make all the subsequent instances not to load the
whole PE structure. The "full_load" method can be used to parse
the missing data at a later stage.

Basic headers information will be available in the attributes:

DOS_HEADER
NT_HEADERS
FILE_HEADER
OPTIONAL_HEADER

All of them will contain among their attributes the members of the
corresponding structures as defined in WINNT.H

The raw data corresponding to the header (from the beginning of the
file up to the start of the first section) will be available in the
instance's attribute 'header' as a string.

The sections will be available as a list in the 'sections' attribute.
Each entry will contain as attributes all the structure's members.

Directory entries will be available as attributes (if they exist):
(no other entries are processed at this point)

DIRECTORY_ENTRY_IMPORT (list of ImportDescData instances)
DIRECTORY_ENTRY_EXPORT (ExportDirData instance)
DIRECTORY_ENTRY_RESOURCE (ResourceDirData instance)
DIRECTORY_ENTRY_DEBUG (list of DebugData instances)
DIRECTORY_ENTRY_BASERELOC (list of BaseRelocationData instances)
DIRECTORY_ENTRY_TLS
DIRECTORY_ENTRY_BOUND_IMPORT (list of BoundImportData instances)

The following dictionary attributes provide ways of mapping different
constants. They will accept the numeric value and return the string
representation and the opposite, feed in the string and get the
numeric constant:

DIRECTORY_ENTRY
IMAGE_CHARACTERISTICS
SECTION_CHARACTERISTICS
DEBUG_TYPE
SUBSYSTEM_TYPE
MACHINE_TYPE
RELOCATION_TYPE
RESOURCE_TYPE
LANG
SUBLANG
Nc                s   W@n         WPn        R V n        . V n        . V n        R V n        Vf   Vf   \        R4      h. V n        R V n        RV n	        RV n
        ^ V n        ^ V n        ^ V n        ^\        P                  ^\        P                   ^\        P"                  /V n        Ve   TM\'        4       R,          p V P)                  WV4       R #    T P+                  4        h ; i)NzMust supply either name or dataF	fast_load)max_symbol_exportsmax_repeated_symbol_get_section_by_rva_last_usedsections_PE__warningsrL  r   __structures___PE__from_fileFileAlignment_WarningSectionAlignment_Warning!_PE__total_resource_entries_count_PE__total_resource_bytes_PE__total_import_symbolsr  ;__IMAGE_IMPORT_CONTROL_TRANSFER_DYNAMIC_RELOCATION_format__:__IMAGE_INDIR_CONTROL_TRANSFER_DYNAMIC_RELOCATION_format__6__IMAGE_SWITCHTABLE_BRANCH_DYNAMIC_RELOCATION_format__#dynamic_relocation_format_by_symbolZglobals	__parse__close)rT   r   r"   r  r  r  s   &&&&&&r   rQ   ZPE.__init__L  s     #5#6 -1*<DL>??
 ! &+"(-% /0+ '(#&'# rMMrLLrHH4
0 "+!6IGIk<R		NN4y1	JJLs   <C C#c                s    V # r   rM   rY   r#   r   	__enter__ZPE.__enter__  s    r   c                &    V P                  4        R # r   )r	  )rT   rq  rJ   Z	traceback   &&&&r   __exit__ZPE.__exit__  s    

r   c                s   V P                   R J d   \        V R4      '       d   \        \        P                  \        4      '       d+   \        V P
                  \        P                  4      '       g$   R\        \	        V P
                  4      4      9   d   V P
                  P                  4        V =\        P                  ! 4        R# )Tr   z	mmap.mmapN)
r  r   rA   mmaprq  r   r   r	  gcZcollectrY   r#   r   _close_dataZPE._close_data  sx    $j))DIIt,,DMM4991U1U$tDMM':";; MM!


r   c                r  r   )r  rY   r#   r   r	  ZPE.close  s    r   c                   \        WR7      p VP                  V4       T P                  P	                  T4       T#   \         d>   pT P                  P	                  RP                  T^ ,          Y54      4        Rp?R# Rp?ii ; iziApply structure format to raw data.

Returns an unpacked structure object if successful, None otherwise.
r}  z7Corrupt header "{0}" at file offset {1}. Exception: {2}N)r   r   ru   r  rw   rx   r  rT   rx   r"   r   	structureZerrr   r   __unpack_data__ZPE.__unpack_data__  s}     f>		  & 	""9-  	OO""IPP1I{
 	   < B2A??Bc                r  r  )r)  r   ru   r  rw   rx   r  r  r   r   __unpack_data_with_bitfields__Z!PE.__unpack_data_with_bitfields__  s}     +6K		  & 	""9-  	OO""IPP1I{
 	r  c           
     s   Ve   \         P                  ! V4      pVP                  ^ 8X  d   \        R4      hRp \	        VR4      pVP                  4       V n        \        \        R4      '       d7   \        P                  ! V P
                  ^ \        P                  4      V n	        M6\        P                  ! V P
                  ^ \        P                  R7      V n	        RV n         Te   TP                  4        MVe   W n	        R
V n        \!        V P                  4      V n        R
V n        V'       g   \'        \)        V P                  4      4      P+                  4        F  w  rV^ 8X  d"   V	\!        V P                  4      ,          R8  g-   V^ 8w  g   K6  V	\!        V P                  4      ,          R8  g   KY  V P,                  P/                  RP                  VRV	,          \!        V P                  4      ,          4      4       K  	  V P                  R,          p
\!        V
4      ^@8w  d   \        R4      hV P1                  V P2                  V
^ R7      V n        V P4                  P6                  \8        8X  d   \        R4      hV P4                  '       d    V P4                  P6                  \:        8w  d   \        R4      hV P4                  P<                  \!        V P                  4      8  d   \        R4      hV P4                  P<                  pV P1                  V P>                  V P                  W^,            VR7      V n         V P@                  '       d   V P@                  PB                  '       g   \        R4      hRV P@                  PB                  ,          \D        8X  d   \        R4      hRV P@                  PB                  ,          \F        8X  d   \        R4      hRV P@                  PB                  ,          \H        8X  d   \        R4      hRV P@                  PB                  ,          \J        8X  d   \        R4      hV P@                  PB                  \L        8w  d   \        R4      hV P1                  V PN                  V P                  V^,           V^,           ^ ,            V^,           R7      V n(        \S        \T        R4      pV PP                  '       g   \        R4      h\W        V PP                  V PP                  PX                  V4       V^,           V PP                  P[                  4       ,           pWPP                  P\                  ,           pV P1                  V P^                  V P                  WR,            VR7      V n0        ^EpV P`                  fl   \!        V P                  WR,            4      V8  dI   ^pV P                  WR,            R V,          ,           pV P1                  V P^                  VVR7      V n0        V P`                  Ee   V P`                  Pb                  \d        8X  d   \d        V n3        MV P`                  Pb                  \h        8X  d   \h        V n3        V P1                  V Pj                  V P                  WR,            VR7      V n0        ^IpV P`                  fl   \!        V P                  WR,            4      V8  dI   ^pV P                  WR,            R V,          ,           pV P1                  V Pj                  VVR7      V n0        V PP                  '       g   \        R4      hV P`                  f   \        R!4      hV Pf                  f?   V P,                  P/                  R"P                  V P`                  Pb                  4      4       \S        \l        R#4      p\W        V P`                  V P`                  Pn                  V4       . V P`                  n8        WP`                  P[                  4       ,           pV PP                  V P@                  n(        V P`                  V P@                  n0        V P`                  Pr                  V P`                  Pt                  8  d   V P,                  P/                  R$4       V P`                  Pv                  ^8  d7   V P,                  P/                  R%V P`                  Pv                  ,          4       Rp\y        \{        R&V P`                  Pv                  ,          4      4       EF  p\!        V P                  4      V,
          ^ 8X  d    M\!        V P                  4      V,
          ^8  d   V P                  VR R),           pMV P                  VVV,            pV P1                  V P|                  VVR7      pVf    M \~        V,          Vn@        TTP[                  4       ,          pT P`                  Pp                  P/                  T4       TYP`                  P[                  4       ,           ^,           8  g   EK   M	  V P                  V4      pV P                   Uu. uF1  pVP                  ^ 8  g   K  V P                  VP                  4      NK3  	  pp\!        V4      ^ 8  d   \        V4      pMRpV'       d   VV8  d   V P                  RV V nH        MV P                  RV V nH        V P                  V P`                  Pr                  4       ew   V P                  V P`                  Pr                  4      pV\!        V P                  4      8  d7   V P,                  P/                  R'V P`                  Pr                  ,          4       M6V P,                  P/                  R(V P`                  Pr                  ,          4       V'       g   V P                  4        R# R#   \         dD   pRP                  T4      pT;'       d
    RT,          p\        R	P                  Y4      4      hRp?ii ; i  Te   TP                  4        i i ; i  \        \        3 d      EK  i ; iu upi )*zParse a Portable Executable file.

Loads a PE file, parsing all its structures and making them available
through the instance's attributes.
NzThe file is emptyZrbMAP_PRIVATE)ZaccessTr   z: %szUnable to access file '{0}'{1}Fg      ?g333333?zeByte 0x{0:02x} makes up {1:.4f}% of the file's contents. This may indicate truncation / malformation.g      Y@:N@   Nz9Unable to read the DOS Header, possibly a truncated file.r}  z)Probably a ZM Executable (not a PE file).zDOS Header magic not found.z.Invalid e_lfanew value, probably not a PE filezNT Headers not found.rI  z0Invalid NT Headers signature. Probably a NE filez0Invalid NT Headers signature. Probably a LE filez0Invalid NT Headers signature. Probably a LX filez0Invalid NT Headers signature. Probably a TE filezInvalid NT Headers signature.IMAGE_FILE_zFile Header missing   r'   r   z5No Optional Header found, invalid PE32 or PE32+ file.z*Invalid type 0x{0:04x} in Optional Header.IMAGE_DLLCHARACTERISTICS_zXSizeOfHeaders is smaller than AddressOfEntryPoint: this file cannot run under Windows 8.zsSuspicious NumberOfRvaAndSizes in the Optional Header. Normal values are never larger than 0x10, the value is: 0x%xz[Possibly corrupt file. AddressOfEntryPoint lies outside the file. AddressOfEntryPoint: 0x%xzTAddressOfEntryPoint lies outside the sections' boundaries. AddressOfEntryPoint: 0x%xs           )LosstatZst_sizeru   openfilenor   r  r  r   ZACCESS_READr  ZIOErrorrx   	Exceptionr	  r8   $_PE__resource_size_limit_upperbounds _PE__resource_size_limit_reachedr    r   r@  r  rw   r  __IMAGE_DOS_HEADER_format__
DOS_HEADERZe_magicIMAGE_DOSZM_SIGNATUREIMAGE_DOS_SIGNATUREZe_lfanew__IMAGE_NT_HEADERS_format__
NT_HEADERSr   IMAGE_NE_SIGNATUREIMAGE_LE_SIGNATUREIMAGE_LX_SIGNATUREIMAGE_TE_SIGNATUREIMAGE_NT_SIGNATURE__IMAGE_FILE_HEADER_format__FILE_HEADERrG   IMAGE_CHARACTERISTICSrL   r   r   SizeOfOptionalHeader __IMAGE_OPTIONAL_HEADER_format__r   ZMagicrM  rL  rO  "__IMAGE_OPTIONAL_HEADER64_format__DLL_CHARACTERISTICSDllCharacteristicsDATA_DIRECTORYZAddressOfEntryPointZSizeOfHeadersZNumberOfRvaAndSizesr1  r   __IMAGE_DATA_DIRECTORY_format__DIRECTORY_ENTRYr   KeyErrorZAttributeErrorparse_sectionsr  r   r   rR   headerget_section_by_rvar  	full_load)rT   Zfnamer"   r  r  ZfdexcpZexception_msgZbyteZ
byte_countZdos_header_dataZnt_headers_offsetimage_flagsZoptional_header_offsetZsections_offsetZ&MINIMUM_VALID_OPTIONAL_HEADER_RAW_SIZEpadding_lengthZpadded_datadll_characteristics_flagsr   Z)MAX_ASSUMED_VALID_NUMBER_OF_RVA_AND_SIZESr=   	dir_entryr   ZrawDataPointersZlowest_section_offsetZ	ep_offsets   &&&&                       r   r  ZPE.__parse__  s|
    775>D||q #$788B%& iik4//$(IIdkk1d>N>N$ODM %)IIdkk1TEUEU$VDM#'  >HHJ M$D 25T]]1C.-2*$+Idmm,D$E$K$K$M 
 AI*s4==/A"AC"GAI*s4==/A"AD"HOO**L &uz'9C<N'NO	 %N --,2%K  ..,,o1 / 
 ??""&;; KLL$//"9"9=P"P =>> ??##c$--&88 PQQ OO44..,,MM+!.CD) / 
 doo&?&?&? 788T__...3EE RSST__...3EE RSST__...3EE RSST__...3EE RSS??$$(:: ?@@//--MM+a/2Ca2G"2LM)A- 0 

 %%:MJ 566 	$""D$4$4$D$DkR!2Q!69I9I9P9P9R!R 13C3C3X3XX#3311MM0C3OP.	  4  
  24.   (4PU7UV 66 !N --&%)G')K $(#7#7552 $8 $D  +##))-EE7%%++/LL<'+';';;;MM.%1O !7 (< ($ :@6 ((02e5S
 >> &)N"&--.%1O#/#1K ,0+?+???#$: ,@ ,D(  566 ' WXX<<OO""<CC((.. %3!<%
!
 	    33%	
 /1+'*>*>*E*E*GG&*&6&6#*.*>*>'
   44""001 OO"". 33d:OO""O&&::; 5:1s:(<(<(P(PPQRA4==!F*a/4==!F*Q.}}VW-	9}}V&OO ,,44d - I  !0!3	 i&&((F  //66yA &)=)=)D)D)FFO S SV $$_5 ]]
"!!A% =D((););<" 	 
 !#$'$8!$(!$(=(F--0DK--(>)>?DK
 ##D$8$8$L$LM
 00$$88I 3t}}--&&7**>>? OO"",.2.B.B.V.VW
 NN M
   %T 2 - J J6M3I4;;EQ  >HHJ "t n- :
sB   B*o $p.qqp>ppp p+.qqc                sr   RpRpV P                   P                  R^V P                  P                  4       4      pVR8X  d   R#  V P                   ^V^,            pVR^\	        V4      ^,          ,           p\        \        P                  ! RP                  \	        V4      ^,          4      V4      4      pW%9  d   R#  \        P                  ! RYUP                  T4      ^,           ,          4      pRT/pTRTP                  R4       pYR&   R	 p	\        4       p
\        T4       F?  w  rT
P                  T	! T4      T	! Yk\	        T4      ,          ,          4      ,          4       KA  	  \        T
4      TR
&   \         P#                  TR4      pT^ ,          T,          T8w  g+   T^,          T8w  g   T^,          T8w  g   T^,          T8w  d   T P$                  P                  R4       YR&   . pYR&   TR,          p\'        \	        T4      ^,          4       F  pT^T,          ,          T8X  d;   T^T,          ^,           ,          T8w  d   T P$                  P                  R4        T# Y^T,          ,          T,          T^T,          ^,           ,          T,          .,          pK  	  T#   \         d     R# i ; i)zParses the rich header
see https://www.ntcore.com/files/richsign.htm for more information

Structure:
00 DanS ^ checksum, checksum, checksum, checksum
10 Symbol RVA ^ checksum, Symbol size ^ checksum...
...
XX Rich, checksum, 0, 0,...
iDanSiRichs   RichNz<{0}I<Lr   raw_datac                 sH    \        V \        4      '       g   \        V 4      # T # r   )rA   r   r   )r   r#   r   <lambda>Z&PE.parse_rich_header.<locals>.<lambda>O  s    z!S'9'9Q@q@r   
clear_dataZlittlez:Rich Header is not in Microsoft format, possibly malformedchecksumr  :   NNzRich Header is malformed)r   findr   r   r8   listr9   r:   rx   ru   r   Zindexr   r   rw   rC   r   Z
from_bytesr  r1  )rT   ZDANSZRICHZ
rich_indexZ	rich_datar"   r   ZresultrF  Zord_rH  r   r   rI  Zheadervaluesr=   s   &               r   parse_rich_headerZPE.parse_rich_header#  sr    ]]''T4//??A

 	 dZ!^<I ""=AY1)<$=>IgnnS^q5H&I9UVD   kk$ZZ%5%9 :;6y~~g67%z@[
!(+HCd3i$sS>/B*CCD ,$Z0| >>#x0 Gh$&Aw("Aw("Aw("OO""L &z'xBxs4yA~&A AE{d" A	?h.OO**+EF
  !a%[83T!a%!)_x5OPPL ' c  		s   A7J' 'J65J6c                ri   )zReturn the list of warnings.

Non-critical problems found when parsing the PE file are
appended to a list of warnings. This method returns the
full list.
)r  rY   r#   r   rv   ZPE.get_warningsx  s     r   c                sD    V P                    F  p\        RV4       K  	  R# )zPrint the list of warnings.

Non-critical problems found when parsing the PE file are
appended to a list of warnings. This method prints the
full list to standard output.
Z>N)r  print)rT   warningr-   r   show_warningsZPE.show_warnings  s     G#w 'r   c                s   V P                  4         ! R R4      pV P                  4       pV'       d   V! 4       V n        VP                  RR4      V P                  n        VP                  RR4      V P                  n        VP                  RR4      V P                  n        VP                  RR4      V P                  n        VP                  RR4      V P                  n        R# RV n        R# )	zProcess the data directories.

This method will load the data directories which might not have
been loaded if the "fast_load" option was used.

It also parses the rich header, which may or may not present.
c                   s    ] tR tRtRtR# ) PE.full_load.<locals>.RichHeaderi  rM   N)r[   r\   r]   r^   r_   rM   r   r   
RichHeaderrR    s    r   rS  rI  Nr  r   rF  rH  )	parse_data_directoriesrN  RICH_HEADERr1   rI  r  r   rF  rH  )rT   rS  Zrich_header   &  r   r?  ZPE.full_load  s     	##%	 	 ,,.)|D(3
D(ID%&1ooh&ED##.??5$#?D (3
D(ID%*5//,*MD'#Dr   c                sV   \        V P                  4      pV P                   F?  p\        VP                  4       4      pVP	                  4       pWBWU\        V4      ,           % KA  	  \        V R4      '       Edd   \        V R4      '       EdQ   V P                   EF?  pV EF4  p\        VR4      '       g   K  VP                   EF  p\        VP                  P                  4       4       F  w  rVP                  V	,          p
VP                  V	,          p\        V4      V^,          8  d\   VP                  R4      P                  R4      pVRV^,          ^,           VV
^,          V
^,          V^,          ^,          ,           % K  VP                  R4      P                  R4      pVVV
^,          V
^,          \        V4      ,           % K  	  EK  	  EK7  	  EKB  	  TpV'       g   V# \!        VR4      ;_uu_ 4       pVP#                  V4       RRR4       R#   + '       g   i     R# ; i)aM  Write the PE file.

This function will process all headers and components
of the PE file and include all changes made (by just
assigning to attributes in the PE objects) and write
the changes back to a file whose name is provided as
an argument. The filename is optional, if not
provided the data will be returned as a 'str' object.
VS_VERSIONINFOFileInfoStringTablerk   r7   Nzwb+)r   r   r  r   r   r8   r   rX  rY  rM  entriesr@  entries_offsetsentries_lengthsr;   encoder   write)rT   ZfilenameZ	file_datar  Zstruct_datar   finfor  st_entryr   offsetsZlengthsr<   Zencoded_dataZnew_file_datar   s   &&              r   r^  ZPE.write  s    dmm,	,,I#I$6$6$89K..0F<GfK(889 -
 4)**tZ((!]]E!&"5-88,1,=,=26x7G7G7M7M7O2PJC
 /7.F.Fs.KG.6.F.Fs.KG'*5zGAJ'>,1LL,A,H,H,T -..>
Q,? )2,3AJgajSTn9T)* 8=||G7L7S7S,68*
 -9 )2,3AJc,FW9W)*# 3Q -> "' +2 "  (E""aGGM" #"""s   ;HH(	c                s
   . V n         ^p\        V P                  P                  4       EF0  pV\        8  dG   V P
                  P                  RP                  V P                  P                  \        4      4        EM^ p\        V P                  V R7      pV'       g    EMWP                  4       V,          ,           pVP                  V4       V P                  WfVP                  4       ,            p\        V4      VP                  4       8X  d#   V P
                  P                  RV R24        EM+V'       g#   V P
                  P                  RV R24        EMVP                  V4       V P                  P                  V4       VP                   VP"                  ,           \%        V P                  4      8  d)   V^,          pV P
                  P                  RV R24       V P'                  VP"                  4      \%        V P                  4      8  d)   V^,          pV P
                  P                  RV R24       VP(                  R	8  d)   V^,          pV P
                  P                  R
V R24       V P+                  VP,                  V P.                  P0                  V P.                  P2                  4      R	8  d)   V^,          pV P
                  P                  R
V R24       V P.                  P2                  ^ 8w  dU   VP"                  V P.                  P2                  ,          ^ 8w  d)   V^,          pV P
                  P                  RV R24       WB8  d   V P
                  P                  R4        M\5        \6        R4      p\9        WUP:                  V4       VP<                  P?                  RR4      '       dy   VP<                  P?                  RR4      '       dW   VP@                  PC                  R4      R8X  d   V PE                  4       '       d   MV P
                  P                  RV R24       V P                   P                  V4       EK3  	  V P                   PG                  R R7       \I        V P                   4       FX  w  rV	\%        V P                   4      ^,
          8X  d
   RVn%        K/  V P                   V	^,           ,          P,                  Vn%        KZ  	  V P                  P                  ^ 8  dU   V P                   '       dC   WP                   ^ ,          P                  4       V P                  P                  ,          ,           # V# )a  Fetch the PE file sections.

The sections will be readily available in the "sections" attribute.
Its attributes will contain all the section information plus "data"
a buffer containing the section's data.

The "Characteristics" member will be processed and attributes
representing the section characteristics (with the 'IMAGE_SCN_'
string trimmed from the constant's names) will be added to the
section instance.

Refer to the SectionStructure class for additional info.
zToo many sections {0} (>={1}))rf   zInvalid section z. Contents are null-bytes.z8. No data in the file (is this corkami's virtsectblXP?).zError parsing section z$. SizeOfRawData is larger than file.z5. PointerToRawData points beyond the end of the file.   z'Suspicious value found parsing section z*. VirtualSize is extremely large > 256MiB.z&. VirtualAddress is beyond 0x10000000.z. PointerToRawData should normally be a multiple of FileAlignment, this might imply the file is trying to confuse tools which parse this incorrectly.z,Too many warnings parsing section. Aborting.r   IMAGE_SCN_MEM_WRITEFIMAGE_SCN_MEM_EXECUTEr   s   PAGEz!Suspicious flags set for section zf. Both IMAGE_SCN_MEM_WRITE and IMAGE_SCN_MEM_EXECUTE are set. This might indicate a packed executable.c                 ri   r   )r   )Zar#   r   rG  Z#PE.parse_sections.<locals>.<lambda>W  s
    )9)9r   )r   N)&r  r1  r1  ZNumberOfSectionsMAX_SECTIONSr  rw   rx   r   __IMAGE_SECTION_HEADER_format__r   r   r   r$   r   r  r   r   r8   r   r   r   r   r   r   r   rG   r   rL   r   rH   r1   Namer   	is_driversortr   r  )
rT   r   ZMAX_SIMULTANEOUS_ERRORSr=   Zsimultaneous_errorssectionZsection_offsetZsection_datar   r   
   &&        r   r<  ZPE.parse_sections  s    "#t''889AL &&3::((99<
 "#&t'K'KPTUG#nn&6&::N##N3=='..2B!BL L)W^^-==&&)9!<V'WX&&&qc *& & |,&&w/$$w'?'??#dmmBTT#q(#&&,QC/ST ++G,D,DEI  $q(#&&,QC 0+ +
 ''*4#q(#&&=aS A0 0 ,,**((99((66
  $q(#&&=aS A) ) $$22a7--0D0D0R0RRWXX#q(#&&0 4S S #=&&'UV*+BLQM g66F##%u ""&&'>FF<<&&w/7:t~~?O?O OO**;A3 ?C C MM  )O :X 	9:%dmm4LCc$--(1,,7;47;}}!G8 . 4	 5 ,,q0T]]]q)002T5E5E5V5VVV Mr   c                s   RV P                   3RV P                  3RV P                  3RV P                  3RV P                  3RV P
                  3RV P                  3RV P                  3R	V P                  3R
V P                  33
pVe    \        V\        \        34      '       g   V.pV EFW  p \        V^ ,          ,          pV P                  P                  V,          pTe   Ya9   d   RpTP"                  '       d   T'       d6   T^ ,          R8X  d(   T^,          ! TP"                  TP$                  RR7      pMbT'       d6   T^ ,          R8X  d(   T^,          ! TP"                  TP$                  RR7      pM% T^,          ! TP"                  TP$                  4      pT'       d   \-        Y^ ,          R,          T4       Tf   EK  \        T\        4      '       g   EK5  T^ ,          T9   g   EKF  TP/                  T4       EKZ  	  R#   \          d      R# i ; i  \&         d3   p	T P(                  P+                  RT^ ,           RT	 24        Rp	?	LRp	?	ii ; i)a  Parse and process the PE file's data directories.

If the optional argument 'directories' is given, only
the directories at the specified indexes will be parsed.
Such functionality allows parsing of areas of interest
without the burden of having to parse all others.
The directories can then be specified as:

For export / import only:

  directories = [ 0, 1 ]

or (more verbosely):

  directories = [ DIRECTORY_ENTRY['IMAGE_DIRECTORY_ENTRY_IMPORT'],
    DIRECTORY_ENTRY['IMAGE_DIRECTORY_ENTRY_EXPORT'] ]

If 'directories' is a list, the ones that are processed will be removed,
leaving only the ones that are not present in the image.

If `forwarded_exports_only` is True, the IMAGE_DIRECTORY_ENTRY_EXPORT
attribute will only contain exports that are forwarded to another DLL.

If `import_dllnames_only` is True, symbols will not be parsed from
the import table and the entries in the IMAGE_DIRECTORY_ENTRY_IMPORT
attribute will not have a `symbols` attribute.
IMAGE_DIRECTORY_ENTRY_IMPORTIMAGE_DIRECTORY_ENTRY_EXPORTIMAGE_DIRECTORY_ENTRY_RESOURCEIMAGE_DIRECTORY_ENTRY_DEBUGIMAGE_DIRECTORY_ENTRY_BASERELOCIMAGE_DIRECTORY_ENTRY_TLS!IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG"IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT"IMAGE_DIRECTORY_ENTRY_BOUND_IMPORTIMAGE_DIRECTORY_ENTRY_EXCEPTIONNT)forwarded_only)dllnames_onlyzFailed to process directory "z": :   NN)parse_import_directoryparse_export_directoryparse_resources_directoryparse_debug_directoryparse_relocations_directoryparse_directory_tlsparse_directory_load_configparse_delay_import_directoryparse_directory_bound_importsparse_exceptions_directoryrA   r   rM  r:  r   r8  
IndexErrorr   r  ru   r  rw   r   Zremove)
rT   directoriesZforwarded_exports_onlyZimport_dllnames_onlyZdirectory_parsingr  Zdirectory_indexrD  rJ   r@  
   &&&&      r   rT  ZPE.parse_data_directoriesg  s#   @ ,T-H-HI+T-H-HI-t/M/MN*D,F,FG.0P0PQ($*B*BC0$2R2RS143T3TU143U3UV.0O0OP
 "kE4=99*m&E"1%("; 00??P	 "o&D+++.!!H(FF %a%44%NN+/! -!!H(FF %a%44innTX!
$)!HY-E-Ey~~$VE
 AhrlE: ({D111X,""?3[ '  :  -  OO22"?azTF S s*   /1H9$HHHI&(IIc                s   V P                   P                  \        R,          8w  d)   V P                   P                  \        R,          8w  d   R# \        V P                  4      pVP                  4       p/ p. p/ p\        W$,          4       EF  pV P                  V P                  V P                  W4      V P                  V4      R7      pVf    EMRp	VP                  ^,          ^ 8X  Ed-   VP                  V9   d   WsP                  ,          p	M3\        V P                  VP                  4      R7      p	WVP                  &   V	P                  V P                  VP                  V	P                  4       4      4      p
V
R8w  d   V P                  P                  V
4        MV	P                  V P                  VP                  V	P                  4       4      4      p
V
R8w  d   V P                  P                  V
4        MSV P                  P                  V	4       \!        W9R7      pVP                  V4       WVP"                  &   W,          pEK  	  V F  pVP$                  f   K  \'        VP$                  R4      '       g   K1  VP$                  P(                  V9  d;   V P                  P                  RVP*                  P-                  4       R R	24       K   VP$                  P/                  WSP$                  P(                  ,          4       K  	  V#   \0         dG   pT P                  P                  R
TP*                  P-                  4       R RT 24        Rp?EK  Rp?ii ; i)zParses exception directory

All the code related to handling exception directories is documented in
https://auscitte.github.io/systems%20blog/Exception-Directory-pefile#implementation-details
IMAGE_FILE_MACHINE_AMD64IMAGE_FILE_MACHINE_IA64Nr}  )r9   
unwindinfor  z FunctionEntry of UNWIND_INFO at r   z' points to an entry that does not existz/Failed parsing FunctionEntry of UNWIND_INFO at z: )r1  MachineMACHINE_TYPEr   __RUNTIME_FUNCTION_format__r   r1  r  r|   r  Z
UnwindDatar{  r  r  rw   r  rz  ZBeginAddressr  r   r  r9   r   r  ru   )rT   r}   r  rfZrf_sizeZrva2rtZrt_funcsZ	rva2infosr,  ZuiZwsr  r@  s   &&&          r   r  ZPE.parse_exceptions_directory  s    $$5O(PP  ((L9R,SSt778))+	t'A%%00c+ 44S9 & B zB#) MMY."==1B#0H0H0WXB/1bmm,((r}}biik)RS:OO**2.((r}}biik)RS:OO**2.##**2.*"DEOOE"&+2??#NCQ (V B}}$
 2==/::}}**&8&&6ryy7P7P7RST6U=> 	88==667! 4  ! &&Eyy00215Rv? s   5LM& :M!!M&c           	     s   \        V P                  4      pVP                  4       pTp. p V P                  V P                  V P                  WV,            VR7      pVf   V P
                  P                  R4       R# VP                  4       '       d    V# WP                  4       ,          pV P                  V4      pV P                  V4      pVf   \        V P                  4      V,
          p	V P                   U
u. uF"  p
V
P                  V8  g   K  V
P                  NK$  	  pp
V'       d4   \        V4      pV P                  V4      pVe   VP                  V,
          p	M1VP                  \        VP                  4       4      ,           V,
          p	V'       g-   V P
                  P                  RP                  V4      4       R# . p\!        \        VP"                  \%        V	^,          4      4      4       EF  pV P                  V P&                  V P                  WV,            VR7      pV'       g   \)        R4      hWP                  4       ,          pW_P*                  ,           pV P-                  ^ V P                  VV\.        ,            4      pV'       dU   \1        V4       Uu. uF%  p\3        V4      \4        P6                  9  g   K#  VNK'  	  pp\        V4      R8  g	   V'       d    M!VP                  \9        VVR7      4       EK  	  WSP*                  ,           pV P-                  ^ V P                  VV\.        ,            4      pV'       dV   \1        V4       Uu. uF%  p\3        V4      \4        P6                  9  g   K#  VNK'  	  pp\        V4      R8  g	   V'       d    V# V'       g    V# VP                  \;        VVVR7      4       EK  u up
i u upi u upi )	rn   r}  Nz7The Bound Imports directory exists but can't be parsed.zHRVA of IMAGE_BOUND_IMPORT_DESCRIPTOR points to an invalid address: {0:x}z(IMAGE_BOUND_FORWARDER_REF cannot be readr  )r9   r   )r9   r   rZ  )r   (__IMAGE_BOUND_IMPORT_DESCRIPTOR_format__r   r  r   r  rw   r   get_section_by_offsetr  r8   r  r   rR   r|   rx   r1  ZNumberOfModuleForwarderRefsr   $__IMAGE_BOUND_FORWARDER_REF_format__ru   ZOffsetModuleNameget_string_from_dataMAX_STRING_LENGTHr   r   rh   r   ry  rw  )rT   r}   r  Z	bnd_descrZbnd_descr_sizer   Zbound_importsrj  r   safety_boundaryr   Zsections_after_offsetZfirst_section_after_offsetZforwarder_refsr,  Zbnd_frwd_refr   Zname_strr   Zinvalid_chars   &&&                 r   r  Z PE.parse_directory_bound_imports   s    dKKL	"))+,,==c.$89 - I
  
 &&M ##%%v s ##%%C005G2237K"%dmm"4{"B "]])*))K7 'A&&* & )
 ) 255J1K."889STG**1*B*B[*P ,,s73C3C3E/FFT   &&7fSk	 NI993QR?R;ST
  $33==MM#n(<= #  4   $'(RSS**,,!>!>>44t}}Vf7H.HI #,X#6%#6a#a&HXHX:X#6 " % 8}s*m%%&lJAH 777F004==&3D*DEH (2!2!c!fFDTDT6TAA2  ! x=3&-      #$8^[)j% !s$   <OO' OO  OOc           	     s   V P                   pV P                  \        8X  d   V P                  p V P	                  VV P                  V\        V4      P                  4       4      V P                  V4      R7      pV'       g   R# \        VR7      #   \         d(    T P                  P                  RT,          4       Rp LGi ; i)rn   r}  z5Invalid TLS information. Can't read data at RVA: 0x%xNr  )__IMAGE_TLS_DIRECTORY_format__rL  rO   __IMAGE_TLS_DIRECTORY64_format__r  r|   r   r   r  ru   r  rw   rv  )rT   r}   r  rx   Z
tls_structrK   r   r~  ZPE.parse_directory_tls  s     44<<88::F
	--c9V#4#;#;#=> 44S9 . J j))  	OO""JSP J		s   A
B /C Cc           	     sZ   V P                   \        8X  d   V P                  V4      pV P                  pMPV P                   \        8X  d   V P                  V4      pV P
                  pMV P                  P                  R4       R# ^ p^ pV^,           F>  pV^,          pV\        VP                  R4      ^ ,          ,          ,          pWc8X  g   K>   M	  V^ ,          V^,          RV 3pRp V P                  VV P                  V\        V4      P                  4       4      V P                  V4      R7      pV'       g   R# Rp	V^#8  d'   V P!                  VP"                  VP$                  4      p	\'        WR7      #   \         d&    T P                  P                  RT,          4        Lti ; i)rn   zGDon't know how to parse LOAD_CONFIG information for non-PE32/PE32+ fileNr   r}  z=Invalid LOAD_CONFIG information. Can't read data at RVA: 0x%x)r9   dynamic_relocations)rL  rM  get_dword_at_rva&__IMAGE_LOAD_CONFIG_DIRECTORY_format__rO  (__IMAGE_LOAD_CONFIG_DIRECTORY64_format__r  rw   r   r   r  r|   r   r   r  ru   parse_dynamic_relocationsZDynamicValueRelocTableOffsetZDynamicValueRelocTableSectionrx  )
rT   r}   r  Zload_config_dir_szrx   Zfields_counterZcumulative_szZfieldZload_config_structr  
   &&&       r   r  ZPE.parse_directory_load_config  s    <<33!%!6!6s!;@@F\\::!%!6!6s!;BBFOO""  AYYEaN0S1A!1DEEM2	 
 )VAY78!		!%!5!5c9V#4#;#;#=> 44S9 "6 " ""B"&"@"@"??"@@#
 %
 	
  	OO""RUXX	s   +A
E: :-F*)F*c           	     s   V'       g   R # V'       g   R # V\        V P                  4      8  d   R # V P                  V^,
          ,          pVP                  V,           pR p\        V P                  4      P                  4       p V P                  V P                  V P                  WF4      V P                  V4      R7      pTP                  ^8w  d/   T P                  P                  RTP                  ,          4       R # YF,          pYEP                  ,           p. pYG8  Edp   T P                  p	T P                  \         8X  d   T P"                  p	\        T	4      P                  4       p
 T P                  T	T P                  YJ4      T P                  T4      R7      pT'       g    T# YJ,          pTP$                  pTP&                  p^Tu;8:  d   ^8:  dD   M M@T P)                  YMT P*                  T,          4      pTP                  \-        YTR7      4       MnT^8X  d4   T P/                  T4      w  ppTP                  \1        TTTTR7      4       M4T^8  d.   T P)                  YM4      pTP                  \-        YTR7      4       YM,          pEKv  T#   \         d'    T P                  P                  RT,          4        R # i ; i  \         d)    T P                  P                  RT,          4       R p EL^i ; i)Nr}  zPInvalid IMAGE_DYNAMIC_RELOCATION_TABLE information. Can't read data at RVA: 0x%xzDNo parsing available for IMAGE_DYNAMIC_RELOCATION_TABLE.Version = %d<Invalid relocation information. Can't read data at RVA: 0x%x)r9   symbolrelocations)r9   r  
bdd_relocsfunc_relocs)r8   r  r   r   )__IMAGE_DYNAMIC_RELOCATION_TABLE_format__r   r  r|   r  ru   r  rw   r  r  #__IMAGE_DYNAMIC_RELOCATION_format__rL  rO  %__IMAGE_DYNAMIC_RELOCATION64_format__ZSymbolBaseRelocSize parse_image_base_relocation_listr  ri  parse_function_override_datarj  )rT   Z dynamic_value_reloc_table_offsetZ!dynamic_value_reloc_table_sectionrj  r}   Z image_dynamic_reloc_table_structZreloc_table_sizer   r  rx   rlc_sizeZdynamic_rlcr  r  r  r  r  s   &&&              r   r  ZPE.parse_dynamic_relocations  s    00,s4==/AA-- AA EF$$'GG+/($::

&( 		/3/C/C>>c4 44S9 0D 0, ,33q8OO""V2::; 999 i==F||<<CC (//1H#"22MM#0 $ 8 8 = 3  J #"G OC ''F,,DFa"CCtGGO $**)*{ 1*.*K*KC*P'Z#**(*%#-$/	 !"CCCN#**)*{ KC""[  	OO""$&)* 	@ ! #&&(*-. ##s$   <J )2K -KK/K:9K:c           
     sX   . p. pV P                   pV P                  VV P                  V\        V4      P	                  4       4      V P                  V4      4      pV'       g&   V P                  P                  RV,          4       W#3# V\        V4      P	                  4       ,          pWP                  ,           pW8  Edf   V P                  pV P                  VV P                  V\        V4      P	                  4       4      V P                  V4      4      pV'       g&   V P                  P                  RV,          4       W#3# V\        V4      P	                  4       ,          p. p\        VP                  ^,          4       FI  p	VP                  \        P                  ! RV P                  V^4      4      ^ ,          4       V^,          pKK  	  V P                  WP                  4      p
WP                  ,          pVP                  \!        VVP"                  VV
R7      4       EKl  V P$                  pV P                  VV P                  V\        V4      P	                  4       4      V P                  V4      4      pV'       g&   V P                  P                  RV,          4       W#3# V\        V4      P	                  4       ,          p\        VP&                  ^,          4       F  p	V P(                  pV P                  VV P                  V\        V4      P	                  4       4      V P                  V4      4      pV'       g(   V P                  P                  RV,          4       W#3u # V\        V4      P	                  4       ,          pVP                  \+        VR7      4       K  	  W#3# )rn   z>Invalid function override header. Can't read data at RVA: 0x%xz<Invalid function override info. Can't read data at RVA: 0x%xr  )r9   Zfunc_rvaoverride_rvasr  z.Invalid bdd info. Can't read data at RVA: 0x%xz<Invalid bdd dynamic relocation. Can't read data at RVA: 0x%xr  ))__IMAGE_FUNCTION_OVERRIDE_HEADER_format__r  r|   r   r   r  r  rw   ZFuncOverrideSize5__IMAGE_FUNCTION_OVERRIDE_DYNAMIC_RELOCATION_format__r1  ZRvaSizer9   r:   r  r  rl  ZOriginalRva__IMAGE_BDD_INFO_format__ZBDDSize'__IMAGE_BDD_DYNAMIC_RELOCATION_format__rm  )rT   r}   r  r  rx   Zfunc_headerZfunc_endZ	func_infor  r=   r  Zbdd_infoZ	bdd_relocs   &&           r   r  ZPE.parse_function_override_dataN  s6   
??**MM#y0779:$$S)

 OO""$&)* **y ''))555nOOF,,c9V#4#;#;#=>((-I
 &&(*-. #..9V$++--CM9,,12$$V]]4sA9N%OPQ%RSq 3 ??,,K ***C5$&22"/ +	 //''MM#y0779:$$S)

 OO""CcI **y ''))x''1,-AAAF,,c9V#4#;#;#=>((-I
 &&(*-. #..9V$++--C6iHI ." &&r   c                s$    V P                  W4      # rm   )r  )rT   r}   r  r   r   r}  ZPE.parse_relocations_directory  s     44S??r   c                s    \        V P                  4      P                  4       pW,           p. pW8  Ed    V P                  V P                  V P	                  W4      V P                  V4      R 7      pV'       g    V# VP                  V P                  P                  8  d0   V P                  P                  RVP                  ,          4        V# VP                  V P                  P                  8  d0   V P                  P                  RVP                  ,          4        V# Vf6   V P                  W,           VP                  VP                  V,
          4      pM5V P                  W,           VP                  VP                  V,
          V4      pVP                  \        WxR7      4       VP                  '       g    V# WP                  ,          pEK  V#   \         d)    T P                  P                  RT,          4       Rp ELi ; i)r}  r  NzEInvalid relocation information. VirtualAddress outside of Image: 0x%xz9Invalid relocation information. SizeOfBlock too large: %dr9   rZ  )r    __IMAGE_BASE_RELOCATION_format__r   r  r|   r  ru   r  rw   r   r   SizeOfImageZSizeOfBlockparse_relocationsparse_relocations_with_formatro  )	rT   r}   r  r  r  r   r  ZrlcZreloc_entriess	   &&&&     r   r  Z#PE.parse_image_base_relocation_list  s   TBBCJJLji**99MM#0 $ 8 8 = +  D ? !!D$8$8$D$DD&&&(+(:(:; 4 - !5!5!A!AA&& __- "  { $ 6 6NC$6$6(8R! !% B BNC$6$6(8RTW! 1TU???  ??"CU ! &&(*-. s   <G /HHc           
     s    V P                  W4      pV P                  V4      p. p\        4       p\        \        T4      ^,          4       F  pT P                  T P                  YH^,          T^,           ^,           TR7      p	T	'       g    T# T	P                  p
T
^,	          pT
R,          pY3T9   d,   T P                  P	                  RY,           ,          4        T# TP                  Y34       TP	                  \        YY,T,           R7      4       YYP                  4       ,          pK  	  T#   \         d%    T P                  P	                  RTR 24       . u # i ; i)rn   Bad RVA in relocation data: 0xr   r}  rr  3Overlapping offsets in relocation data at RVA: 0x%x)r9   rq  rt  r}   )r|   r  ru   r  rw   r  r1  r8   r  &__IMAGE_BASE_RELOCATION_ENTRY_format__rs  rW   rp  r   )rT   data_rvar}   r  r"   r   rZ  Zoffsets_and_typer   r  ru  Z
reloc_typereloc_offsets   &&&&         r   r  ZPE.parse_relocations  sb   	==0D228<K
 5Ta(C((;;1Wa1}-' ) E * ) ::DJ&=L)-==&&#&2&8:     ,!;<NN CTWEW
 <<>)K7 ): G  	OO""%CHQ<#PQI	s   "D0 0,EEc           	     s    V P                  W4      pV P                  V4      p\        T4      P                  4       p. p\        4       p	\        \        T4      T,          4       F  p
T P                  TYZT,          T
^,           T,           TR7      pT'       g    T# TP                  pY9   d,   T P                  P	                  RY,           ,          4        T# T	P                  T4       TP	                  \        YY,           R7      4       Yg,          pK  	  T#   \         d%    T P                  P	                  RTR 24       . u # i ; i)rn   r  r   r}  r  )r9   rt  r}   )r|   r  ru   r  rw   r)  r   r  r1  r8   r  ZPageRelativeOffsetrW   rp  )rT   r  r}   r  rx   r"   r   Z
entry_sizerZ  ra  r   r  r  s   &&&&&        r   r  Z PE.parse_relocations_with_format  sI   	==0D228<K
 ,F3::<
%Tj01C77:%qJ(>?' 8 E    !33L&&&#&2&8:   KK%NNe|?QR %K- 20 ?  	OO""%CHQ<#PQI	s   "D ,E
	E
c                s   \        V P                  4      P                  4       p. p\        \	        W#,          4      4       EF  p V P                  WV,          ,           V4      pT P                  T P                  TT P                  YT,          ,           4      R7      pT'       g    R# RpTP                  ^8X  d   EMITP                  ^8X  Ed   TP                  p	TP                  p
T P                  YT
,            pTR,          R8X  Ed9   R. RO.pT
\        T4      P                  4       ,
          pT^ 8  d(   T^,          P                  RP                  T4      4       T P                  YT	4      pTe   \         P"                  ! RR	TP$                  ,           4      ^ ,          Tn        \)        \*        P,                  ! TP.                  TP0                  TP2                  TP4                  TP6                  TP&                  3R
7      4      P9                  RR 4      P;                  4       TP<                  R ,           Tn        EMTR,          R8X  dg   R. RO.pT
\        T4      P                  4       ,
          pT^ 8  d(   T^,          P                  RP                  T4      4       T P                  YT	4      pEMMTP                  ^8X  d   TP                  p	TP                  p
T P                  YT
,            pR. RO.pT P                  YT	4      pT'       dr   TP@                  R9   da   T
\        T4      P                  4       ,
          pT^ 8  d(   T^,          P                  RP                  T4      4       T P                  YT	4      pM}TP                  ^8X  dm   TP                  p	TP                  p
T P                  YT
,            pRR..pT P                  TTT	4      p\C        \D        R4      p\G        TTPH                  T4       TP                  \K        YxR7      4       EK  	  V#   \         d(    T P                  P                  RT,          4         R# i ; i)rn   z7Invalid debug information. Can't read data at RVA: 0x%xNr}  :NrJ  Ns   RSDSZCV_INFO_PDB70z{0}s,PdbFileNamez>Q     )Zfields-Xs   NB10ZCV_INFO_PDB20ZIMAGE_DEBUG_MISCz	{0}s,DataZ!IMAGE_DEBUG_EX_DLLCHARACTERISTICSzI,ExDllCharacteristicsIMAGE_DLLCHARACTERISTICS_EX_)r9   r  )z4s,CvSignaturezI,Signature_Data1zH,Signature_Data2zH,Signature_Data3zB,Signature_Data4zB,Signature_Data5z6s,Signature_Data6I,Age)zI,CvHeaderSignaturezI,CvHeaderOffsetI,Signaturer  )z
I,DataTypezI,Lengthz	B,UnicodezB,Reserved1H,Reserved2r    r*   )&r    __IMAGE_DEBUG_DIRECTORY_format__r   r1  r   r|   ru   r  rw   r  r  Typer   Z
SizeOfDatar   rx   r9   r:   ZSignature_Data6ZSignature_Data6_valuerB   uuidZUUIDZSignature_Data1ZSignature_Data2ZSignature_Data3ZSignature_Data4ZSignature_Data5replaceZupperZAgeZSignature_StringZUnicoderG   EX_DLL_CHARACTERISTICSrL   ZExDllCharacteristicsrh  )rT   r}   r  Zdbg_sizeZdebugr   r"   dbgZdbg_typeZdbg_type_offsetZdbg_type_sizeZdbg_type_dataZ__CV_INFO_PDB70_format__ZpdbFileName_sizeZ__CV_INFO_PDB20_format__Z___IMAGE_DEBUG_MISC_format__Zdbg_type_partialZ	data_sizeZ-___IMAGE_DEBUG_EX_DLLCHARACTERISTICS_format__ex_dll_characteristics_flagsr  r   r|  ZPE.parse_debug_directory7  sL    TBBCJJLT_-.C}}Sc>%98D &&55 44Sc>5IJ ' C 
 Hxx1}Q"%"6"6 # $#&E! !$/ (	0, &	2J(K(R(R(TT % (!+03::.556FG  $330 H  +9? 'H,D,D"D::6   $		(0(@(@(0(@(@(0(@(@(0(@(@(0(@(@(0(F(F,&	!" %WS"-"UW!)a 02 !1$ #2&'1 (0, &	2J(K(R(R(TT % (!+03::.556FG  $330 H Q"%"6"6 # $#&E! '	0, $(#7#70$  $'//69)'(DELLNO " %q=8;BB + 2 29 = $(#7#78$ R"%"6"6 # $#&E! 80A=  //A!# 0>*,J0, 110 LL#>? /B } ! &&PSVV 	s   P))-QQc           
     sJ   Vf   V.pVf   TpV\         8  d+   V P                  P                  RV\         3,          4       R#  V P                  V\	        V P
                  4      P                  4       4      pT P                  T P
                  TT P                  T4      R7      pTf%   T P                  P                  RT,          4       R# . pYP                  4       ,          pTP                  TP                  ,           p	Rp
Y8  d&   T P                  P                  RY3,          4       R# T ;P                  T	,          un        T P                  \        8  d5   T P                  P                  RT P                  \        3,          4       R# . pRp\        T	4       EF  pT P                  '       g[   T P                   T P"                  8  d@   R	T n        T P                  P                  R
T P                   T P"                  3,          4       T P%                  T4      pTf'   T P                  P                  RY3,          4        EMGRpRpTP&                  R,          ^,	          pT'       g   TP&                  pMY>P(                  ,           p \+        T T4      pT ;P                   TP-                  4       ,          un        T'       dR   T^ ,          T8  dD   T^,          T8  d6   TP/                  4        T P                  P                  RT,          4        EMuTTTP-                  4       ,           3pTP                  T4       TP0                  '       Ed   Y>P2                  ,           T9   d    EMT P5                  Y>P2                  ,           Y!T,
          ,
          TT^,           YSTP2                  ,           .,           R7      pT'       g    EMRpT\6        R,          8X  Ed8   / pTP8                   EF$  p\;        TR4      '       g   K  / pTP<                  P8                   F  pTeC   \;        TR4      '       d1   TP>                  P@                  PB                  e   TPD                  f   KK  TP>                  P@                  PF                  pTP>                  P@                  PB                  pTPD                  p T P                  TT4      p\I        T\K        T4      ^,
          ^,          T4       TPM                  T4       K  	  TTP<                  n'        EK'  	  TP                  \Q        TTTTR7      4       MT PS                  Y>P2                  ,           4      pT'       dr   T ;P                   TPB                  ,          un        \U        TTP&                  R,          TP&                  ^
,	          R7      pTP                  \Q        YTTR7      4       M MT^ 8X  d   TPV                  \6        R,          8X  d}   T'       d
   TR,          p XP<                  P8                  ^ ,          P<                  P8                  pT F3  p Rp! T P>                  P@                  p!T!f   K"  T PY                  T!4       K5  	  YP                  4       ,          pEK  	  T U"u. uF  p"T"P[                  4       NK  	  p#p"T#P]                  4        \_        T4       F  w  pp"T"Pa                  4        K  	  \c        YxR7      p$T$#   \         d'    T P                  P                  RT,          4        R# i ; i  \         d'    T P                  P                  RT,          4        ELi ; i  \         d(    T P                  P                  RTR RT 24        EKi  i ; i    EL:; i    EL'; iu up"i )aX  Parse the resources directory.

Given the RVA of the resources directory, it will process all
its entries.

The root will have the corresponding member of its structure,
IMAGE_RESOURCE_DIRECTORY plus 'entries', a list of all the
entries in the directory.

Those entries will have, correspondingly, all the structure's
members (IMAGE_RESOURCE_DIRECTORY_ENTRY) and an additional one,
"directory", pointing to the IMAGE_RESOURCE_DIRECTORY structure
representing upper layers of the tree. This one will also have
an 'entries' attribute, pointing to the 3rd, and last, level.
Another directory with more entries. Those last entries will
have a new attribute (both 'leaf' or 'data_entry' can be used to
access it). This structure finally points to the resource data.
All the members of this structure, IMAGE_RESOURCE_DATA_ENTRY,
are available as its attributes.
NzNError parsing the resources directory. Excessively nested table depth %d (>%s)zCInvalid resources directory. Can't read directory data at RVA: 0x%xr}  zDInvalid resources directory. Can't parse directory data at RVA: 0x%xr   zNError parsing the resources directory. The directory contains %d entries (>%s)zRError parsing the resources directory. The file contains at least %d entries (>%d)TzGResource size 0x%x exceeds file size 0x%x, overlapping resources found.zHError parsing the resources directory, Entry %d is invalid, RVA = 0x%x. r)   z^Error parsing the resources directory, attempting to read entry name. Entry names overlap 0x%xznError parsing the resources directory, attempting to read entry name. Can't read unicode string at offset 0x%x)rt  leveldirs	RT_STRING	directoryr"   z2Error parsing resource of type RT_STRING at RVA 0xr   z with size )r9   r   idr  i  )r9   langsublang)r9   r   r  r"   
RT_VERSIONr  rK  )2MAX_RESOURCE_DEPTHr  rw   r|   r   #__IMAGE_RESOURCE_DIRECTORY_format__r   ru   r  r  ZNumberOfNamedEntriesZNumberOfIdEntriesr  MAX_RESOURCE_ENTRIESr1  r$  r  r#  parse_resource_entryrg  
NameOffsetre   rt   r  DataIsDirectoryOffsetToDirectoryr{  RESOURCE_TYPErZ  r   r  r"   r9   r  r  OffsetToDatar?   r   updatestringsrf  parse_resource_data_entryrg  Idparse_version_informationrj   ri  r   ry   rd  )%rT   r}   r  rt  r  r  r"   Zresource_dirZdir_entriesZnumber_of_entriesZMAX_ALLOWED_ENTRIESZstrings_to_postprocessZlast_name_begin_endr   ZresZ
entry_nameZentry_idZname_is_stringustr_offsetZentry_directoryr  resource_idZresource_stringsresource_langZstring_entry_rvaZstring_entry_sizeZstring_entry_idZstring_entry_datar9   Z
entry_dataZ
last_entryZversion_entriesZversion_entryZrt_version_structr   Zstring_rvasZresource_directory_datas%   &&&&&&                               r   r{  ZPE.parse_resources_directory   s@   , <5DH%%OO"":=BDV<WX 	 ==YtGGHOOQD ++44005 , 

  OO"".034 
 	""$$ --0N0NN 	
 #2OO"":$:;
 ++/@@+..1EEOO"">668LMN
 !#
 #*+C666//$2X2XX592&&' 33>> ++C0C{&&8;>*E JH!hh3:N!88&7 !B4!UJ//:3R3R3TT/ ++A.</2kA /224..7:EG
  $#j&E&E&GG+'
 +11*= """ 333t;"&"@"@444(N+%!)C,A,A!A BB #A # ' }[99 G'6'>'>";<</1,1<1F1F1N1N$1$9+2=&+I+I'4'9'9'@'@'E'E'M'2~~'=$, %2$6$6$=$=$J$J !1 5B4F4F4M4M4R4R 12=..
!-8<(8:K9&$5 !.$5%(%9A%=$C$4!"
 !(/? @C 2OF =MK119O (?R ""("'#"1	 77444 //6;;>/!6%CHHu,<chhRTn"J  &&,#&H:  zcffl(CC!,RJN&0&:&:&B&B1&E&O&O&W&WO *9,0)!0=0B0B0I0I- -8 ::;LM *9 ::<C{ ,~ -CC,Bqqyy{,BC 67FC  8 #2#
 '&M  	OO"".034 	n % OO**CFQSx (5 !-$(OO$:$:+11A!0D E00A/B)D%&
 %-!-~! !   Ds[   3[3 B	\'*\';]1^^^ 3-\$#\$'-]]-^	^	^^c                s0    V P                  V\        V P                  4      P                  4       4      pT P                  T P                  TT P                  T4      R7      pT#   \         d'    T P
                  P                  RT,          4        R# i ; i)z0Parse a data entry from the resources directory.zGError parsing a resource directory data entry, the RVA is invalid: 0x%xNr}  )	r|   r   $__IMAGE_RESOURCE_DATA_ENTRY_format__r   ru   r  rw   r  r  )rT   r}   r"   Z
data_entryr5   r   r  ZPE.parse_resource_data_entry1  s    	 ==YtHHIPPRD ))55005 * 

   	OO""+.13 	s   3A$ $-BBc                s    V P                  V\        V P                  4      P                  4       4      pT P                  T P                  TT P                  T4      R7      pTf   R# TP                  R,          Tn        TP                  R,          Tn	        TP                  R,          Tn
        TP                  R,          ^,	          Tn        TP                  R,          Tn        T#   \         d     R# i ; i)z5Parse a directory entry from the resources directory.Nr}  r        rI  r)   )r|   r   )__IMAGE_RESOURCE_DIRECTORY_ENTRY_format__r   ru   r  r  rg  r  Z_PE__padr  r  r  r  )rT   r}   r"   Zresourcer5   r   r  ZPE.parse_resource_entryI  s    	==YtMMNUUWD ''::005 ( 
  'mmj8!3mmj0$,$9$9J$F2#M %-%:%:Z%G"-  		s   3C) )C87C8c                s    V P                  VP                  4      pT P                  Y"TP                  ,            pT P                  T P                  Y2R7      pTf   R# TP                  TP                  4       ,           pT P                  T4      pRpT'       d2   TP                  \        TP                  TP                  4      ,           pRp Tf   T P!                  TRR7      pM"T P!                  YWT,
          ^,	          RR7      p Tf-   T P                  P	                  RP                  T4      4       R# Te   TR8w  d   \#        T4      ^8  dV   TR	,          P%                  R4      p	T	RT	P'                  R
4       p	RP                  T	\#        T4      4      P)                  4       pT P                  P	                  RP                  TP%                  R4      P+                  RR4      4      4       R# \-        T R4      '       g   . T n        Tp
Yn        T P.                  P	                  T
4       Tf   RpT P3                  TP                  4       ^\#        T4      ^,           ,          ,           TP                  4      pT P                  T P4                  Y;R Y+,           R7      pT'       g   R# \-        T R4      '       g   . T n        T P6                  P	                  T4       T P3                  YP                  4       ,           TP                  4      p\-        T R4      '       g   . T n        . p T P                  T P:                  Y=R Y-,           R7      pTf   T P                  P	                  R4       R# TP                  T,           TP                  4       ,           p T P!                  T4      pTTn        TP	                  T4       T'       Ed   TP=                  R4      '       Ed}   TP>                  R9   Edi   TP@                  ^ 8X  EdW   T P3                  TTP                  4       ,           ^\#        T4      ^,           ,          ,           TP                  4      p. Tn!         T P                  T PD                  TTR TT,           R7      pT'       g   EM?TP                  T,           TP                  4       ,           p T P!                  T4      pTTn#        / Tn$        / Tn%        / Tn&        TPB                  P	                  T4       T P3                  TTP                  4       ,           ^\#        T4      ^,           ,          ,           TP                  4      pTTTPN                  ,           8  Ed   T P                  T PP                  TTR TT,           R7      pT'       g   EMtTP                  T,           TP                  4       ,           p T P!                  T4      pT P                  T4      pT P3                  ^\#        T4      ^,           ,          T,           TP                  4       ,           TP                  4      pTP                  T,           p T P!                  TTP@                  R7      pT P                  T4      pTPN                  ^ 8X  d   TTPN                  ,           pM-T P3                  TPN                  T,           TP                  4      pTTPH                  T&   TT3TPJ                  T&   \#        T4      \#        T4      3TPL                  T&   EK  T P3                  TPN                  T,           TP                  4      pTT8X  d   EMTpTTPN                  8  g   EK  EMrEMpT'       Edh   TP=                  R4      '       EdP   TpRTn)        TP>                  R9   Ed5   TP@                  ^ 8X  Ed#   T P3                  TTP                  4       ,           ^\#        T4      ^,           ,          ,           TP                  4      p. Tn*         T P                  T PV                  TTR TT,           R7      pT'       g   EMTP                  T,           TP                  4       ,           p T P!                  T4      pTf   EMYTPT                  P	                  T4       T P3                  ^\#        T4      ^,           ,          T,           TP                  4       ,           TP                  4      pTp TT TP@                  ,           8  d   T PY                  TTT^,            ^ 4      p!T PY                  TT^,           T^,            ^ 4      p"T^,          p\[        T!\\        4      '       g   Kx  \[        T"\\        4      '       g   K  TRT!T"3,          /Tn/        K  T P3                  TTPN                  ,           TP                  4      pTTTPN                  ,           8:  g   EK   T P3                  TPN                  T,           TP                  4      pTPN                  ^ 8X  g   YPN                  8  g   EK   T P8                  P	                  T4       R#   \         d9    T P                  P	                  RP                  TP                  4      4        R# i ; i  \         d'    T P                  P	                  RT,          4        E	Li ; i  \         d/    T P                  P	                  RP                  T4      4        K  i ; i  \         d0    T P                  P	                  RP                  T4      4        EK^  i ; i  \         d0    T P                  P	                  RP                  T4      4        EK[  i ; i  \         d%    T P                  P	                  RTR 24        EK  i ; i  \         d0    T P                  P	                  RP                  T4      4        EK
  i ; i)a  Parse version information structure.

The date will be made available in three attributes of the PE object.

VS_VERSIONINFO   will contain the first three fields of the main structure:
    'Length', 'ValueLength', and 'Type'

VS_FIXEDFILEINFO will hold the rest of the fields, accessible as sub-attributes:
    'Signature', 'StrucVersion', 'FileVersionMS', 'FileVersionLS',
    'ProductVersionMS', 'ProductVersionLS', 'FileFlagsMask', 'FileFlags',
    'FileOS', 'FileType', 'FileSubtype', 'FileDateMS', 'FileDateLS'

FileInfo    is a list of all StringFileInfo and VarFileInfo structures.

StringFileInfo structures will have a list as an attribute named 'StringTable'
containing all the StringTable structures. Each of those structures contains a
dictionary 'entries' with all the key / value version information string pairs.

VarFileInfo structures will have a list as an attribute named 'Var' containing
all Var structures. Each Var structure will have a dictionary as an attribute
named 'entry' which will contain the name and value of the Var.
zWError parsing the version information, attempting to read OffsetToData with RVA: 0x{:x}Nr}  asciiencodingzzError parsing the version information, attempting to read VS_VERSION_INFO string. Can't read unicode string at offset 0x%xz"Invalid VS_VERSION_INFO block: {0}s   VS_VERSION_INFO:N   Nz\uz({0} ... ({1} bytes, too long to display)Z z\00rW  rn   VS_FIXEDFILEINFOrX  z/Error parsing StringFileInfo/VarFileInfo structz|Error parsing the version information, attempting to read StringFileInfo string. Can't read unicode string at offset 0x{0:x}s   StringFileInfozyError parsing the version information, attempting to read StringTable string. Can't read unicode string at offset 0x{0:x}z}Error parsing the version information, attempting to read StringTable Key string. Can't read unicode string at offset 0x{0:x}rq   zzError parsing the version information, attempting to read StringTable Value string. Can't read unicode string at offset 0xr   s   VarFileInfoZVarFileInfoz}Error parsing the version information, attempting to read VarFileInfo Var string. Can't read unicode string at offset 0x{0:x}z0x%04x 0x%04xr  )0r  r  ru   r  rw   rx   r   r  r  __VS_VERSIONINFO_format__r   r>  r   rS   r   r   rs   r8   r;   Zrfindr]  r  r   rW  ZKeydword_align__VS_FIXEDFILEINFO_format__r  rX  __StringFileInfo_format__rD   r  ZValueLengthrY  __StringTable_format__LangIDrZ  r[  r\  ZLength__String_format__r   Var__Var_format__get_word_from_datarA   r   r  )#rT   Zversion_structZstart_offsetrF  Zversioninfo_structr  rj  Zsection_endZversioninfo_stringZexcerptZvinfoZfixedfileinfo_offsetZfixedfileinfo_structZstringfileinfo_offsetr_  Zstringfileinfo_structZstringfileinfo_stringZstringtable_offsetZstringtable_structZstringtable_stringZentry_offsetZstring_structr   Z
key_offsetZvalue_offsetrJ   Znew_stringtable_offsetZvarfileinfo_structZ
var_offsetZ
var_structZ
var_stringZvarword_offsetZorig_varword_offsetZword1Zword2s#   &&                                 r   r  ZPE.parse_version_informationh  s   4		33N4O4OPL ==~?R?R0RS "11**H 2 
 %$114F4M4M4OO))+6!003%%w'?'?4 K "
	"%)%=%=' &> &" &*%=%=";!AG &> &" %OO""4;;<NO  ).@DV.V%&,,T299'B!"8GMM%$89%O%V%VS!34&&( # OO""4;;&--g6>>ufM
 t-.."$D # '	""5)%!##//%%'!s3E/F/J*KK'' 
  $33,,*+$;  4  
 $t/00$&D! 	$$%9:
 !% 0 0 #>#>#@@''!
 tZ((DM$($8$8../0(@ %9 %! %,&&E  ++'($++-. 
(,(@(@(M% )>!% LL./ %$)>)I)I!* * *..&8-99Q>)-)9)9-/6689s#89A=>? '33	*& 9;)5 -1-A-A 77$%7%89(47I(I .B .*  2! +77010779: $

"151I1I+1V. 5G*157*2=?*:=?*:-99@@AST'+'7'7.0779:3'9#:Q#>?@ +77	( )03E3L3LLM -1,@,@ $ 6 6 ( 7,8<,G -A -M $1 % !/ ; ;".!/"/"6"6"8!9 (
&&*&>&>{&K-1-E-Ek-R
 ,0+;+; !SX\ 2".!/"/"6"6"8!9 !/ ; ;	,L +9*E*E*TK&(,(@(@$/M<U<U )A )" 04/G/G/T  -33q8$69K9R9R$R !- 04/?/?$1$8$8<$G$2$?$?0"
 ?D.66s; * ,G.>>sC
 !$C #E
G.>>sC
 261A1A.558JJ*772. 25GG!-C*-1F1M1MM! '&+@+K+K, , &;"*7"' '++v5*66!;!%!1!1-,3356s#89A=>? '33	"J .0&* %)%9%9 //$Z[1(4z(A &: &
  *! +77()(//12 $

")-)A)A+)NJ &-!*..55jA)-)9)9Z1!45()(//12 +77	* /=+ +1J4J4JJK %)$;$; (.1:L Mq%E %)$;$; (!);nq>P QST%E +a/N)%55*UC:P:P$.5%.0P4"
 0 &*%5%5&):)::N<W<W&
 &j6G6G)GG! %)$4$4%,,/DD++%! &,,1(,E,EEU#]  	OO""CCI6"//D 	R  	OO""58CE	D ! &&<<BF;<O
 b  - " OO22!HHN$/I" ""\ $1 & $ 6 6%LLRF(3M&!" !&&. $1 & $ 6 6%BBMa%R!"
 !&&b  - " OO22!NNTf$/O" ""s   i j	 '!j	 j= >k9 	"l6 .m3 $n% ?jj	-j:9j:=5k65k695l32l365m0/m03*n"!n"%5ooc                s  a   S P                  S P                  S P                  V\        S P                  4      P	                  4       4      S P                  V4      R7      pT'       g   R# T 3R lp S P                  TP                  \        T! TP                  4      TP                  ^,          4      4      pS P                  TP                  \        T! TP                  4      TP                  ^,          4      4      pS P                  TP                  \        T! TP                  4      TP                  ^,          4      4      p. p	^
p
S P                  TP                  4      p\!        S P"                  4      pT'       d<   TP$                  \!        TP                  4       4      ,           TP                  ,
          p\&        P(                  ! \*        4      pRp\-        \        TP                  \+        T^,          4      4      4       EF!  pS P/                  Y4      pTe+   T^,          \!        T4      8  d   S P1                  TT4      pM R# Te   T^ 8X  d   KS  TT8  d2   TY,           8  d%   S P3                  T4      p S P                  T4      pMT'       d   K  RpRpS P1                  Yo4      pTf   T
^,          p
T
^ 8:  d   Rp EMcS P3                  T\4        4      p\7        TRR7      '       g   Rp EM5 S P                  T4      pTTT3;;,          ^,          uu&   TTT3,          ^
8  d&   S P                  P                  RT R	TR
 R24        M\!        T4      S P8                  8  d7   S P                  P                  RP;                  S P8                  4      4        MT	P                  \=        S TP>                  T,           S P                  TP                  ^T,          ,           4      TS P                  TP                  ^T,          ,           4      TTTTR7	      4       EK$  	  T'       g*   S P                  P                  RTP                  R 24       T	 Uu0 uF  pTP@                  kK  	  pp^
p
S P                  TP                  4      p\!        S P"                  4      pT'       d<   TP$                  \!        TP                  4       4      ,           TP                  ,
          p\&        P(                  ! \*        4      pRp\-        \        TP                  \+        T^,          4      4      4       EFW  pTTP>                  ,           T9  g   K   S P1                  TT4      pTf   T
^,          p
T
^ 8:  d   Rp EMT^ 8X  d   KS  Te'   TT8  d    TY,           8  d   S P3                  T4      pMRpTT;;,          ^,          uu&   TT,          S PB                  8  d8   S P                  P                  RP;                  S PB                  T4      4        My\!        T4      S P8                  8  d,   S P                  P                  RS P8                   R24        M4T	P                  \=        TP>                  T,           TRTR7      4       EKZ  	  T'       g,   S P                  P                  RTP                  R 24       R# T	'       g   TPE                  4       '       d   R# \G        TT	S P3                  TPH                  4      R7      #   \         d'    S P                  P                  RT,          4        R# i ; i  \         d'    S P                  P                  RT,          4        R# i ; i  \         d     EK  i ; i  \         dZ    T
^,          p
T
^ 8:  d   Rp  EK   S P                  T4      p EL  \         d    T
^,          p
T
^ 8:  d	   Rp   EK    EK  i ; ii ; iu upi   \         d    Rp ELi ; i)zParse the export directory.

Given the RVA of the export directory, it will process all
its entries.

The exports will be made available as a list of ExportData
instances in the 'IMAGE_DIRECTORY_ENTRY_EXPORT' PE attribute.
r}  z+Error parsing export directory at RVA: 0x%xNc                 sZ   < \        SP                  4      SP                  V 4      ,
          # r   )r8   r   r  )r}   rT   rV   r   length_until_eofZ3PE.parse_export_directory.<locals>.length_until_eof2  s"    t}}%(@(@(EEEr   TF)r  z9Export directory contains more than 10 repeated entries (r  z#02xz). Assuming corrupt.zHExport directory contains more than {} symbol entries. Assuming corrupt.)	rf   rG  rY  rJ  ra  r   rW  r_  rb  zIRVA AddressOfNames in the export directory points to an invalid address: r   z[Export directory contains more than {} repeated ordinal entries (0x{:x}). Assuming corrupt.z$Export directory contains more than z# ordinal entries. Assuming corrupt.)rG  rJ  r   r_  zMRVA AddressOfFunctions in the export directory points to an invalid address: )r9   symbolsr   )%r  !__IMAGE_EXPORT_DIRECTORY_format__r|   r   r   r  ru   r  rw   ZAddressOfNamesrR   ZNumberOfNamesZAddressOfNameOrdinalsZAddressOfFunctionsZNumberOfFunctionsr>  r8   r   r   collectionsZdefaultdictr   r1  r  get_dword_from_dataget_string_at_rvaMAX_SYMBOL_NAME_LENGTHr  r  rx   r^  ZBaserG  r  r   r]  rg  )rT   r}   r  rv  Z
export_dirr  Zaddress_of_namesZaddress_of_name_ordinalsZaddress_of_functionsexportsZ#max_failed_entries_before_giving_uprj  r  Zsymbol_countsZ&export_parsing_loop_completed_normallyr=   Zsymbol_ordinalZsymbol_addressZforwarder_strrb  Zsymbol_name_addressZsymbol_nameZsymbol_name_offsetexpZordinalsr   s   f&&&                      r   rz  ZPE.parse_export_directory  s   	--664#I#IJQQS !44S9 . J 
	F	#}}))$Z%>%>?,,q0  (,}}00$Z%E%EF,,q0($ $(==--$Z%B%BC0014$  .0+))**C*CDdmm,&&g&&()*++,  $//415.s:33S19L5MNOA!445MQN)nq.@3$D / "&!9!9(." %1)<
 $#*)D $ 6 6~ F'+'?'?'O$ " $#' "&":":;K"O"*3q836!;=B:00#%;K *+PTUU9>6%)%=%=>Q%R"$ ;78A=8k>:;b@&&#}B~d&;;OQ ]#d&=&==&&((.t/F/F(G NN&OOn<#'#;#;"881q5@$ +#'#;#;"55N8JJ$ % 2+%5[ P~ 6OO""&55a8:
 ,337CCKK73.0+))**G*GHdmm,&&g&&()*//0  $//415.Z993QR?R;STUCZ__$H4*%)%=%=>RTW%XN ")71<7:a?AF>!Q& #.&#-&3$($:$:>$JM$(M
 n-2- 043K3KKOO**FFLf 44nG '$*A*AAOO**>2233VX  *# 5 .!"/	] Vn 6OO""&99!<> :0022''
8
 	
a  	OO""=E 		J  	OO""=E 		Z % . ! 3q836!;=B:)-)A)ABU)V&$ 71<7:a?AF>n 4( % *%)N*s   A\ 2C] ]9;^$_3_8-]]-]65]69^	^	_0/__, _0&_0+_,,_08`	`	c                sJ    W,           ^,           R,          VR,          ,
          # )r  l    rM   )rT   r   Zbaser   r   r  ZPE.dword_align  s    "j0TJ5FGGr   c                s    V P                   P                  pV P                   P                  V P                   P                  ,           pY!u;8:  d   V8  d   M V# W,          pV# r   )r   	ImageBaser  )rT   ZvaZbegin_of_imageZend_of_imager5   r   normalize_import_vaZPE.normalize_import_va  sV    --77++558L8L8X8XX .,.	  B	r   c                s   . p^ p  V P                  V\        V P                  4      P                  4       4      pT P                  T4      pT P                  T P                  TTR7      pT'       d   TP                  4       '       d    T# RpTP                  ^ 8X  d   T P                  P                  \        R,          8X  d   T P                  TP                  4      Tn        T P                  TP                   4      Tn        T P                  TP"                  4      Tn        T P                  TP$                  4      Tn        T P                  TP$                  4      Tn        T P                  TP(                  4      Tn        RpYP                  4       ,          p\+        T P,                  4      T,
          p	YP"                  8  g   YP                   8  d-   \/        YP"                  ,
          YP                   ,
          4      p	. p
 T P1                  TP"                  TP                   RT	T4      p
T^8  d.   T P
                  P                  RP3                  T4      4        T# T
'       g   T^,          pEKr  T P6                  \8        8  d6   T P
                  P                  R	T P6                  \8        3,          4        T# T P;                  TP(                  \<        4      p\?        T4      '       g   R
pT'       g   EK  T
 FR  pTP@                  e   K  \B        PD                  ! TPG                  4       TPH                  4      pT'       g   KL  Yn         KT  	  TP                  \K        YzTR7      4       EKq    \         d'    T P
                  P                  RT,          4        T# i ; i  \         d@   pT P
                  P                  RP3                  YP4                  4      4        Rp?ELRp?ii ; i)z*Walk and parse the delay import directory.Tz5Error parsing the Delay import directory at RVA: 0x%xr}  FIMAGE_FILE_MACHINE_I386NzSError parsing the Delay import directory. Invalid import data at RVA: 0x{0:x} ({1})zWToo many errors parsing the Delay import directory. Invalid import data at RVA: 0x{0:x}z)Error, too many imported symbols %d (>%s)	   *invalid*r9   importsdll)&r|   r   (__IMAGE_DELAY_IMPORT_DESCRIPTOR_format__r   ru   r  rw   r  r  r   ZgrAttrsr1  r  r  r  Z	pBoundIATZpIATZpINTZ
pUnloadIATZphmodZszNamer8   r   rS   parse_importsrx   rJ   r  MAX_IMPORT_SYMBOLSr  MAX_DLL_LENGTHr  r   	ordlookup	ordLookuplowerrG  rB  )rT   r}   r  import_descsr>   r"   r   import_desccontains_addressesmax_lenimport_datar@  r   r  funcnames   &&&            r   r  ZPE.parse_delay_import_directory*  s     }}dKKLSSU 2237K..==' / K +"8"8":":^ ] "' ##q($$,,=V0WW(,(@(@AVAV(W%#'#;#;K<L<L#M #'#;#;K<L<L#M )-)A)A***& %)$<$<[=S=S$T!%)%=%=k>P>P%Q"%)"%%''C
 $--(;6G%%%/?/?)?c$4$44c<L<L6LMK"00$$$$& Q&&::@&+ 6 3 q **-??&&?224FGH    ((););^LC(--"s)F{{*#,#6#6syy{FNN#S#8*2K	 *
 ##"+PSTu ! &&KsS t }p ! &&@@FsJJ@W s)   3M6 )N* 6-N'&N'*O454O//O4c                s   \        V R 4      '       d   V P                  f   R# VR8X  d.   \        V P                  P                  4      P	                  4       # VR8X  d.   \        V P                  P                  4      P	                  4       # VR8X  d.   \        V P                  P                  4      P	                  4       # VR8X  d.   \        V P                  P                  4      P	                  4       # \        R4      h)rU  rn   r   r   r   r   z#Invalid hashing algorithm specified)	r   rU  r   rH  r  r   r   r   r"  )rT   Z	algorithmr   r   get_rich_header_hashZPE.get_rich_header_hash  s    t]++t/?/?/Gt''223==??& ((334>>@@("$**556@@BB("$**556@@BB=>>r   c           	     s   . p. ROp\        V R4      '       g   R# V P                   EF  p\        VP                  \        4      '       d*   VP                  P                  4       P                  4       pMVP                  P                  4       pVP                  R^4      p\        V4      ^8  d   V^,          V9   d
   V^ ,          pVP                  P                  4       pVP                   F  pRpVP                  '       gR   \        P                  ! WgP                  RR7      pV'       g'   \        RVP                   RVP                  R	 24      hMVP                  pV'       g   K~  \        V\        4      '       d   VP                  4       pVP                  VP                  4       : RVP                  4       : 24       K  	  EK  	  \!        R
P#                  V4      P%                  4       4      P'                  4       # )a  Return the imphash of the PE file.

Creates a hash based on imported symbol names and their specific order within
the executable:
https://www.mandiant.com/resources/blog/tracking-malware-import-hashing

Returns:
    the hexdigest of the MD5 hash of the exported symbols.
DIRECTORY_ENTRY_IMPORTrn   .NT)Z	make_namezUnable to look up ordinal r   Z04xr   )Zocxsysr   )r   r  rA   r   rC   r;   r  Zrsplitr8   r  r   r  r  rG  ru   rw   r   r   r]  r  )	rT   ZimpstrsZextsr  ZlibnameZpartsZentry_dll_lowerimpr  s	   &        r   get_imphashZPE.get_imphash  s    $t56600E%))U++))**,224))//+NN3*E5zA~%(d"2(#iioo/O}}xxx(22' H $+81S[[QTDUV  $
  #xxHh..'0H'--/8>>;KLM% % 1> 388G$++-.88::r   c                s   \        V R4      '       g   R# \        V P                  R4      '       g   R# V P                  P                   Uu. uFE  pV'       g   K  VP                  f   K  VP                  P	                  4       P                  4       NKG  	  pp\        V4      ^ 8X  d   R# \        RP                  V4      P                  4       4      P                  4       # u upi )zReturn the exphash of the PE file.

Similar to imphash, but based on exported symbol names and their specific order.

Returns:
    the hexdigest of the SHA256 hash of the exported symbols.
DIRECTORY_ENTRY_EXPORTrn   r  r   )r   r  r  r   r;   r  r8   r   r   r]  r  )rT   r,   Zexport_listrV  r   get_exphashZPE.get_exphash  s     t566t22I>> 0088
8 $VV $AFFMMO!!#8 	 

 {q 388K(//12<<>>
s   
C C *,C c                sD   . p^ p\        V P                  4      P                  4       p  V P                  W4      pT P                  T4      pT P                  T P                  YxR7      p	T	'       d   T	P                  4       '       d   EMYP                  4       ,          p\        T P                  4      T,
          p
YP                  8  g   YP                  8  d-   \        YP                  ,
          YP                  ,
          4      p
. pT'       gp    T P                  T	P                  T	P                  T	P                   T
R7      pT^8  d!   T P
                  P                  R	TR 24       MT'       g   T^,          pEKX  T P%                  T	P&                  \(        4      p\+        T4      '       g   R
pT'       g   EK  T FR  pTP,                  e   K  \.        P0                  ! TP3                  4       TP4                  4      pT'       g   KL  Yn        KT  	  TP                  \7        YTR7      4       EK  T'       g   RR0p^ p^ pT F  pTP8                   F  pT F  pT'       d   TP,                  '       g   K  TP,                  p\;        TP,                  4      \<        8X  d   TP,                  P?                  R4      pTPA                  T4      '       g   K}  T^,          p M	  T^,          pK  	  K  	  T\        T4      8X  d#   T^8  d   T P
                  P                  R4       T#   \         d%    T P
                  P                  RTR 24        EK#  i ; i  \         d9   pT P
                  P                  RTR RTP"                   R24        Rp?ELURp?ii ; i)z$Walk and parse the import directory.z-Error parsing the import directory at RVA: 0xr   r}  rq   zBError parsing the import directory. Invalid Import data at RVA: 0xz ()NzLToo many errors parsing the import directory. Invalid import data at RVA: 0xr  r  ZLoadLibraryZGetProcAddressrk   z?Imported symbols contain entries typical of packed executables.)!r   "__IMAGE_IMPORT_DESCRIPTOR_format__r   r|   ru   r  rw   r  r  r   r8   r   ZOriginalFirstThunkZ
FirstThunkrS   r  ZForwarderChainrJ   r  rg  r  r  r   r  r  r  rG  rB  r  rq  rC   r;   rD   )rT   r}   r  rw  r  r>   Zimage_import_descriptor_sizer"   r   r	  r  r  r,   r   r  r  Zsuspicious_importsZsuspicious_imports_countZtotal_symbolsZimp_dllZsuspicious_symbolr   s   &&&&                  r   ry  ZPE.parse_import_directory  sH    '033(

&( 	%  }}SG 2237K..77 / K
 +"8"8":":%%''C
 $--(;6G333s=S=S7S888#@V@V:V K "&"4"4#66#..#22#*	 #5 #K ?OO**99<QA "1$K(()9)9>JC(--"s)F{{*#,#6#6syy{FNN#S#8*2K	 *
 ##"+PST "/1A!B'($M'%ooF-?)%V[[[$%{{,5#);;#5#5g#>D??+<==494! .@ "Q&M . ( )C0B,CC!B&&&U w ! &&CC7K 	F % OO**99<Qr!''!M s)   L* 3M **MMN'-NNc                sV   . pV P                  WV4      pV P                  W$V4      pV'       d   \        V4      ^ 8X  d>   V'       d   \        V4      ^ 8X  d&   V P                  P                  RVR RVR 24       . # Rp	V'       d   Tp	MV'       d   Tp	MR# ^p
RpV P                  \
        8X  d   \        pM&V P                  \        8X  d   \        p^p
RpM\        p^ p\        V	4       EF  w  rRpRpRpRpRpRpVP                  '       d   VP                  V,          '       d   RpVP                  R	,          pRpRpMRp VP                  V,          pV P                  V^4      pV P                  V^ 4      pV P                  VP                  ^,           \        4      p\        V4      '       g   R
pV P!                  VP                  ^,           4      pVP%                  4       pV P'                  V4      pW P(                  P*                  ,           W,          ,           pRp V'       dK   V'       dC   W~,          P                  W,          P                  8w  d   W,          P                  pW,          pMRp Vf   Vf   \#        R4      hVR
8X  d%   VR8  d   W8X  d   \#        R4      hV^,          pEK  V'       g   V'       g   EK  VP                  \/        V VVVVVP%                  4       VVVVVVXXR7      4       EK  	  V#   \"         d     EL>i ; i  \,         d    Rp Li ; i)zParse the imported symbols.

It will fill a list, which will be available as the dictionary
attribute "imports". Its keys will be the DLL names and the values
of all the symbols imported from that object.
z\Damaged Import Table information. ILT and/or IAT appear to be broken. OriginalFirstThunk: 0xr   z FirstThunk: 0xNr  l    FTrI  r  z"Invalid entries, aborting parsing.i  z)Too many invalid names, aborting parsing.)rf   rQ  rV  import_by_ordinalrG  rY  hintr   rW  rH  rJ  hint_name_table_rvathunk_offset	thunk_rva)get_import_tabler8   r  rw   rL  rM  rN  rO  rP  r   rS  r|   r  r  MAX_IMPORT_NAME_LENGTHr  r  ru   r   r  r   r  r  rF  )rT   Zoriginal_first_thunkZfirst_thunkZforwarder_chainrr   r
  Zimported_symbolsZiltZiattableZ
imp_offsetZaddress_maskr[  Znum_invalidr   Z	tbl_entryZimp_ordZimp_hintZimp_namerW  r  r  r"   r  r  Zimp_addressrV  Z	imp_bounds   &&&&&&                      r   r  ZPE.parse_importsY  s4     ## .@
 ##K=OP s3x1}sc#h!mOO""))=a(@ A!!,Q1 IEE
!<<33-L\\::/LJ-L
 .L'.NCGHHK"& %&&& **\99(,%'55>G#H"&K(-%.7.E.E.T+#}}-@!D#'#:#:4#C#'#9#9%33a79O$  6h??'3H&*&>&>%33a7'  )88: 44\B	 22<<<s?OO  J!338#9#9SX=S=S#S # 6 6I!$J $I 8#3#$HII
 <'%+*<'(STTq (( ''%.#-*; ''0'@'@'B%%$/' +,?%1"+[ /@  A ) $  ! 	!s2   BL#L3AL5LLLL('L(c                s   . pV P                   \        8X  d   \        pV P                  pM:V P                   \        8X  d   \
        pV P                  pM\        pV P                  p\        V4      P                  4       pRpRp	^p
^ p\        4       p\        4       pTpV'       Ed   Ve,   WV,           8  d   V P                  P                  R4        V# V P                  \        8  d6   V P                  P                  RV P                  \        3,          4        V# V ;P                  ^,          un        W8  d   . # VP                  4       V8  d   . # VP                  4       V8  d   . # Rp V P                  W4      pV'       g   \#        X4      V8w  d%   V P                  P                  RV,          4       R# V P%                  VVV P'                  V4      R7      pV'       d   V P)                  VP*                  4      Vn        V P)                  VP,                  4      Vn        V P)                  VP.                  4      Vn        V P)                  VP0                  4      Vn        V'       dH   VP*                  V8  d7   VP*                  V8:  d&   V P                  P                  RV,          4        V# V'       dl   VP*                  '       dZ   VP*                  pVV,          '       d   VR	,          R
8  d   . # M-VV	8  d   TpMTpVV9   d
   V^,          pVP3                  V4       V'       d   VP5                  4       '       d    V# VVP                  4       ,          pVP                  V4       EK  V#   \          d    Rp ELi ; i)r  Nz9Error parsing the import table. Entries go beyond bounds.z$Excessive number of imports %d (>%s)FTz9Error parsing the import table. Invalid data at RVA: 0x%xr}  z\Error parsing the import table. AddressOfData overlaps with THUNK_DATA for THUNK at RVA 0x%xr  rI             )rL  rM  rN  __IMAGE_THUNK_DATA_format__rO  rP  __IMAGE_THUNK_DATA64_format__r   r   rO   r  rw   r  r  rZ   r|   ru   r8   r  r  r  rS  rU  rT  rR  rW   r   )rT   r}   rr   r
  r  r[  rx   Zexpected_sizeZMAX_ADDRESS_SPREADZADDR_4GBZMAX_REPEATED_ADDRESSESZrepeated_addressZaddresses_of_data_set_64Zaddresses_of_data_set_32Z	start_rvaZfailedr"   Z
thunk_dataZaddr_of_dataZthe_sets   &&&&                r   r  ZPE.get_import_table  s]   
 <<33-L55F\\::/L77F
 .L55F!&)002(!##-< #-< 	c%#Z1G*G&&O B  **-??&&:224FGH t q ''1,'  9	
 (,,.1CC	',,.1CC	F}}S8 Tm3&&RUXX --$*B*B3*G . J
 "+/+C+C,,,
( .2-E-E...
* '+&>&>z?R?R&S
#%)%=%=j>P>P%Q
" ,,	9,,3&&(+.0
 > ; j666)77,.. $j069!	 : $x/":":#w.(A-(KK-!6!6!8!8 	 :$$&&CLL$M ! s   0M8 8N	N	c                s   Ve   V P                   pV P                  V4       V P                  pV P                   EF<  pVP                  ^ 8X  d   VP
                  ^ 8X  d   K(  VP
                  pV P                  VP                  4      pV P                  VP                  V P                  P                  V P                  P                  4      pV\        V P                   4      8  gA   V\        V P                   4      8  g'   Wg,           \        V P                   4      8  g   W8  d   K  V\        V4      ,
          p	V	^ 8  d   VRV	,          ,          pMV	^ 8  d   VRV	 pWEP                  4       ,          pEK?  	  Ve   XV n         V# )aD  Returns the data corresponding to the memory layout of the PE file.

The data includes the PE header and the sections loaded at offsets
corresponding to their relative virtual addresses. (the VirtualAddress
section header member).
Any offset in this data corresponds to the absolute memory address
ImageBase+offset.

The optional argument 'max_virtual_address' provides with means of limiting
which sections are processed.
Any section with their VirtualAddress beyond this value will be skipped.
Normally, sections with values beyond this range are just there to confuse
tools. It's a common trick to see in packed executables.

If the 'ImageBase' optional argument is supplied, the file's relocations
will be applied to the image by calling the 'relocate_image()' method. Beware
that the relocation information is applied permanently.
Nr   )r   relocate_imager=  r  r   r   r   r   r   r   r   r   r   r8   r|   )
rT   Zmax_virtual_addressr  Zoriginal_dataZmapped_datarj  ZsrdZprdr   rB  r  r   get_memory_mapped_imageZPE.get_memory_mapped_imagez  sV   ,   !MMM	* kk}}G ''1,1F1F!1K''C..w/G/GHC!%!=!=&&$$55$$22" c$--((T]]++9s4==11%</#k2BBN!u~55!#)/>:++--K; %B  )DMr   c                s   . p\        V R4      '       d   V P                  P                   F  p\        VR4      '       g   K  VP                  P                   F  p\        VR4      '       g   K  \        VP                  R4      '       g   K5  VP                  P                  '       g   KS  \        VP                  P                  P                  4       4       F  pVP                  V4       K  	  K  	  K  	  V# )zReturns a list of all the strings found within the resources (if any).

This method will scan all entries in the resources directory of the PE, if
there is one, and will return a [] with the strings.

An empty list will be returned otherwise.
DIRECTORY_ENTRY_RESOURCEr  r  )r   r&  rZ  r  r  rM  r  rw   )rT   Zresources_stringsres_typer  
res_string   &    r   get_resources_stringsZPE.get_resources_strings  s     4344 99AA8[11'/'9'9'A'A";<< '(=(=y I I$/$9$9$A$A$A26$/$9$9$A$A$H$H$J3"J %6$<$<Z$H3" (B B ! r   c                s*   V P                  V4      pVf   RpMW,           pV'       g\   V\        V P                  4      8  d   V P                  W # V\        V P                  4      8  d   V P                  W # \	        R4      hVP                  W4      # )zGet data regardless of the section where it lies on.

Given a RVA and the size of the chunk to retrieve, this method
will find the section where the data lies and return the data.
Nz-data at RVA can't be fetched. Corrupt header?)r>  r8   r=  r   ru   r|   )rT   r}   r~   r   r   rK   r   r|   ZPE.get_data  s     ##C(>C,CS%%{{3++ S''}}S-- OPPzz#&&r   c           
     sl   V P                  V4      pV'       g   V P                  '       ds   \        V P                   Uu. uFH  pV P                  VP                  V P
                  P                  V P
                  P                  4      NKJ  	  up4      pW8  d   V# R# V# VP                  V4      # u upi )z.Get the RVA corresponding to this file offset.N)	r  r  rR   r   r   r   r   r   r  )rT   r   r   Z
lowest_rvar5   r   r  ZPE.get_rva_from_offset  s     &&v.}}}  "& "/A 44,, 00AA 00>>
 "/	
 & "M$$V,,-s   AB1c                s    V P                  V4      pV'       g-   V\        V P                  4      8  d   V# \        RVR R24      hVP	                  V4      # )zGet the file offset corresponding to this RVA.

Given a RVA , this method will find the section where the
data lies and return the offset within the file.
zdata at RVA 0xr   z can't be fetched)r>  r8   r   ru   r  )rT   r}   r   rF   r   r  ZPE.get_offset_from_rva  sW     ##C(
 S''
.Q7H IJJ$$S))r   c                s    Vf   R# V P                  V4      pV'       g&   V P                  ^ V P                  WV,            4      # V P                  ^ VP                  WR7      4      # )z1Get an ASCII string located at the given address.N)r~   )r>  r  r   r|   )rT   r}   rr   r   r   r   r  ZPE.get_string_at_rva/  s^     ;##C(,,Qc*DT0UVV((AJJsJ,NOOr   c                st    V\        V4      8  d   R# W!R p\        V\        4      '       d   \        V4      # V# )r  r   N)r8   rA   r   rC   )rT   r   r"   r   r   r   get_bytes_from_dataZPE.get_bytes_from_data:  s5    CIMa##8Or   c                sb    V P                  W4      pVP                  R4      pV^ 8  d   VRV pV# )zGet an ASCII string from data.r   N)r+  rL  )rT   r   r"   r   r   rK   r   r  ZPE.get_string_from_dataC  s6    $$V2ffUm!8$3Ar   c                s   V^ 8X  d   R# V P                  V^4      pV^,          p\        VR4      pV P                  W4      pR	p VP                  RV^,           4      pVR	8X  d\   \        V4      pWu8  g   Wr8X  d   \        V4      ^,	          pMKW@P                  W,           W',
          4      ,          pV^,
          pTpK|  V^,          ^ 8X  g   K  V^,          p \        P
                  ! RP                  V4      VRV^,           4      pRP                  \        \        V4      4      p	V'       d   V	P                  VR4      # V	P                  RR4      # )
z3Get an Unicode string located at the given address.r   r  r  z<{:d}HNrn   r   rk   rK  )r|   rR   rL  r8   r9   r:   rx   r   Zmapr   r]  )
rT   r}   rr   r  r"   Z	requestedZ
null_indexZdata_lengthZuchrsr   r  r   rs   ZPE.get_string_u_at_rvaK  s2    ? }}S!$ 	q

C(	}}S,
;
Q?JR!$i*k.G!$TaJ c&79QRR&]
&	a1$q 
 hooj94@P*q.;QRGGCUO$88H&9::xx!455r   c                sb    V P                    F  pVP                  V4      '       g   K  Vu # 	  R# )z1Get the section containing the given file offset.N)r  r  )rT   r   rj  rF   r   r  ZPE.get_section_by_offsetv  s-     }}G&&v.. % r   c                s    V P                   e.   V P                   P                  V4      '       d   V P                   # V P                   F$  pVP                  V4      '       g   K  W n         Vu # 	  R# )z-Get the section containing the given address.N)r  r	  r  )rT   r}   rj  rF   r   r>  ZPE.get_section_by_rva  sb    
 --911>>sCC999}}G##C((5<2 %
 r   c                s"    V P                  4       # r   )	dump_inforY   r#   r   rl   Z
PE.__str__  s    ~~r   c                s    \        V R4      # )z.Checks if the PE file has relocation directoryDIRECTORY_ENTRY_BASERELOC)r   rY   r#   r   
has_relocsZPE.has_relocs  s    t899r   c                sf    \        V R 4      '       d   V P                  P                  '       d   R# R# )DIRECTORY_ENTRY_LOAD_CONFIGTF)r   r/  r  rY   r#   r   has_dynamic_relocsZPE.has_dynamic_relocs  s(    4677//CCCr   c                s<    \        V P                  VR7      4       R# )z=Print all the PE header information in a human readable from.r  N)rO  r,  )rT   r  r   r   
print_infoZPE.print_info  s    dnnhn/0r   c                s(3   Vf   \        4       pV P                  4       pV'       d<   VP                  R4       V F$  pVP                  V4       VP	                  4        K&  	  VP                  R4       VP                  V P                  P                  4       4       VP	                  4        VP                  R4       VP                  V P                  P                  4       4       VP	                  4        VP                  R4       VP                  V P                  P                  4       4       \        \        R4      pVP                  R4       . p\        V4       F@  p\        V P                  V^ ,          4      '       g   K(  VP                  V^ ,          4       KB  	  VP                  RP!                  V4      4       VP	                  4        \#        V R4      '       dI   V P$                  e;   VP                  R4       VP                  V P$                  P                  4       4       \        \&        R	4      pVP                  R
4       . p\        V4       F@  p\        V P$                  V^ ,          4      '       g   K(  VP                  V^ ,          4       KB  	  VP                  RP!                  V4      4       \        \(        R4      p	V	'       d   . p\#        V R4      '       d   V P*                  e   V P*                   Fz  p
V
P,                  P.                  \0        R,          8X  g   K+  \        V	4       F@  p\        V
P2                  V^ ,          4      '       g   K(  VP                  V^ ,          4       KB  	  K|  	  V'       d2   VP                  R4       VP                  RP!                  V4      4       VP	                  4        VP                  R4       \        \4        R4      pV P6                   EF  pVP                  VP                  4       4       VP                  R4       . p\        V4       F5  p\        W^ ,          4      '       g   K  VP                  V^ ,          4       K7  	  VP                  RP!                  V4      4       VP                  RP9                  VP;                  4       4      4       \<        e/   VP                  RP9                  VP?                  4       4      4       \@        e'   VP                  RVPC                  4       ,          4       \D        e'   VP                  RVPG                  4       ,          4       \H        e'   VP                  RVPK                  4       ,          4       VP	                  4        EK  	  \#        V R4      '       d   \#        V P$                  R4      '       dd   VP                  R4       V P$                  PL                   F(  pVf   K	  VP                  VP                  4       4       K*  	  VP	                  4        \#        V R4      '       Ed   \O        V PP                  4       EF  w  r\S        V PP                  4      ^8  d   VP                  RV^,            24       MVP                  R4       Ve    VP                  VP                  4       4       VP	                  4        \#        V R4      '       dA   VP                  V PT                  V,          P                  4       4       VP	                  4        \#        V R4      '       g   K  \S        V PV                  4      V8  g   EK  V PV                  V,           EFq  pVP                  VP                  4       4       VP	                  4        \#        VR4      '       Ed*   VPX                   EF  pVP                  4        Uu. uF  pVP                  RV,           4      NK  	   pVP                  RP9                  VPZ                  P]                  VR 4      4      4       VP	                  4        \        \_        VP`                  Pc                  4       4      4       FR  pVP                  R!P9                  V^ ,          P]                  VR 4      V^,          P]                  VR 4      4      4       KT  	  EK  	  VP	                  4        EKo  \#        VR"4      '       g   EK  VPd                   F  p\#        VR#4      '       g   K  VP                  4        Uu. uF  pVP                  RV,           4      NK  	   pVP                  R!P9                  \_        VP2                  Pg                  4       4      ^ ,          P]                  R$R 4      \_        VP2                  Pi                  4       4      ^ ,          4      4       K  	  VP	                  4        EKt  	  EK  	  \#        V R%4      '       Edl   VP                  R&4       VP                  V Pj                  P,                  P                  4       4       VP	                  4        VP                  R':R( R)R*:R( RR+: 24       V Pj                  Pl                   F  pVPn                  f   K  R,pVPp                  '       d   VPp                  pVP                  R-VPr                  VPn                  VP]                  V4      3,          4       VPt                  '       d=   VP                  R.P9                  VPt                  P]                  VR 4      4      4       K  VP	                  4        K  	  VP	                  4        \#        V R/4      '       Edk   VP                  R04       V Pv                   EFH  pVP                  VP,                  P                  4       4       VPx                  '       gd   VP                  R1P9                  V P{                  VP,                  P|                  4      P]                  VR 4      4      4       VP	                  4        VP	                  4        VPx                   EFu  pVP~                  R2J d   VPp                  e`   VP                  R3P9                  VP                  P]                  R$4      VPp                  P]                  R$4      VPr                  4      4       MVP                  R4P9                  VP                  P]                  R$4      VPr                  4      4       M`VP                  R5P9                  VP                  P]                  VR 4      VPp                  P]                  VR 4      VP                  4      4       VP                  '       d.   VP                  R6P9                  VP                  4      4       EKe  VP	                  4        EKx  	  VP	                  4        EKK  	  \#        V R74      '       Ed!   VP                  R84       V P                   F  pVP                  VP,                  P                  4       4       VP                  R9P9                  VPp                  P]                  VR 4      4      4       VP	                  4        VP`                   Fx  pVP                  VP,                  P                  4       ^4       VP                  R9P9                  VPp                  P]                  VR 4      4      ^4       VP	                  4        Kz  	  EK  	  \#        V R:4      '       Ed   VP                  R;4       V P                   EFf  pVP                  VP,                  P                  4       4       VP	                  4        VPx                   EF  pVP~                  R2J dG   VP                  R<P9                  VP                  P]                  VR 4      VPr                  4      4       M`VP                  R=P9                  VP                  P]                  VR 4      VPp                  P]                  VR 4      VP                  4      4       VP                  '       d-   VP                  R6P9                  VP                  4      4       K  VP	                  4        EK  	  VP	                  4        EKi  	  \#        V R>4      '       Ed   VP                  R?4       VP                  V P                  P,                  P                  4       4       V P                  P`                   EF  pVPp                  e4   VPp                  P]                  VR 4      pVP                  R@V RA2^4       MX\        P                  VP,                  P                  RB4      pVP                  RCVP,                  P                  RD REV RF2^4       VP                  VP,                  P                  4       ^4       \#        VRG4      '       Ed3   VP                  VP                  P,                  P                  4       ^4       VP                  P`                   EF  pVPp                  e4   VPp                  P]                  R$R 4      pVP                  R@V RA2^4       M+VP                  RCVP,                  P                  RD RA2^4       VP                  VP,                  P                  4       ^4       \#        VRG4      '       g   K  VP                  VP                  P,                  P                  4       ^4       VP                  P`                   EF  p\#        VRH4      '       g   K  VP                  RIVP                  P                  VP                  P                  \        P                  VP                  P                  RJ4      \        VP                  P                  VP                  P                  4      3,          ^4       VP                  VP,                  P                  4       ^
4       VP                  VP                  P,                  P                  4       ^4       EK  	  \#        VP                  RK4      '       g   EK1  VP                  P                  '       g   EKP  VP                  RL^
4       \_        \        VP                  P                  Pc                  4       4      4       FG  w  ppVP                  RMP9                  VVP                  RNRO4      P]                  RP4      4      ^4       KI  	  EK  	  VP	                  4        EK  	  VP	                  4        \#        V RQ4      '       d   V P                  '       dq   V P                  P,                  '       dU   VP                  RR4       VP                  V P                  P,                  P                  4       4       VP	                  4        \#        V RS4      '       d   V P                  '       dq   V P                  P,                  '       dU   VP                  RT4       VP                  V P                  P,                  P                  4       4       VP	                  4        \#        V R4      '       d   VP                  RU4       V P*                   F  p VP                  V P,                  P                  4       4        VP                  RV\0        V P,                  P.                  ,          ,           4       VP	                  4        V P2                  '       g   K  VP                  V P2                  P                  4       ^4       VP	                  4        K  	  V P                  4       '       d   VP                  RX4       V P                   F  p!VP                  V!P,                  P                  4       4       V!P`                   FE  p" VP                  RYV"P                  \        V"P                  ,          RZ,          3,          ^4       KG  	  VP	                  4        K  	  \#        V R\4      '       d   \S        V P                  4      ^ 8  d   VP                  R]4       V P                   Fz  p#VP                  V#P,                  P                  4       4       \#        V#R^4      '       g   K@  V#P                  f   KP  VP                  V#P                  P                  4       ^4       K|  	  VP                  4       # u upi u upi   \         d9    TP                  RWP9                  T P,                  P.                  4      4        ELMi ; i  \         d5    TP                  R[T"P                  T"P                  3,          ^4        EK  i ; i)_z>Dump all the PE header information into human readable string.Parsing Warningsr&  r*  r1  r  r  r  r   r  zDllCharacteristics: r  DIRECTORY_ENTRY_DEBUG&IMAGE_DEBUG_TYPE_EX_DLLCHARACTERISTICSzExDllCharacteristics: PE Sectionsr   z!Entropy: {0:f} (Min=0.0, Max=8.0)zMD5     hash: {0}zSHA-1   hash: %szSHA-256 hash: %szSHA-512 hash: %sr8  DirectoriesrW  zVersion Information Version Informationr  rX  rY  z  z  LangID: {0}r   z    {0}: {1}r  r  rk   r  Exported symbolsrR  Z10z   RVArg  s   Nonez%-10d 0x%08X    %sz forwarder: {0}r  Imported symbolsz  Name -> {0}Tz*{0}.{1} Ordinal[{2}] (Imported by Ordinal)z&{0} Ordinal[{1}] (Imported by Ordinal)z{0}.{1} Hint[{2:d}]z Bound: 0x{0:08X}DIRECTORY_ENTRY_BOUND_IMPORTBound importszDLL: {0}DIRECTORY_ENTRY_DELAY_IMPORTDelay Imported symbolsz({0} Ordinal[{1:d}] (Imported by Ordinal)z{0}.{1} Hint[{2}]r&  Resource directoryzName: [Z]r  zId: [0xr  z] (r  r  r"   z\--- LANG [%d,%d][%s,%s]r/   r  z	[STRINGS]z{0:6d}: {1}unicode-escaper   r  DIRECTORY_ENTRY_TLSTLSr/  LOAD_CONFIGDebug informationzType: zType: 0x{0:x}(Unknown)Base relocationsz%08Xh %sr  NNz0x%08X 0x%x(Unknown)DIRECTORY_ENTRY_EXCEPTIONz"Unwind data for exception handlingr  )\r   rv   r   r   r   r   r&  r   r*  r1  rG   r2  rW   Zsortedr   rw   r   r   r   r6  r  r3  r9   r  
DEBUG_TYPEr  r   r  rx   r  r   r  r   r  r   r  r   r  r8  r   rW  r8   r  rX  rY  r  r;   rM  rZ  r@  r  r@   r  r  r  rJ  r   rG  r_  r  r  r  rg  r  r   r  rH  r;  r=  r&  r  r1   r  r  r"   r  r  r0   r6   r  r]  rA  r/  r;  r.  r-  r}   RELOCATION_TYPErq  rG  r  r   )$rT   r   r  warningsrP  rA  rI   rE   rC  r  Zdebug_entryr   rj  r  r   Zvinfo_entryr  r`  r   	str_entry	var_entryexportr   moduler  bound_imp_descbound_imp_refr'  Zres_type_idr  r  r(  r  
base_relocrelocr  s$   &&&                                 r   r,  ZPE.dump_info  sQ    <6D$$&OO./#g&  " $ 	%t++-.%t++-.&t'',,./$%:MJ;'Dt''a11T!W% ( 	dii&'4*++0D0D0POO-.NN4//4467$2!<%
! 	'(45Dt++T!W55T!W% 6 	dii&''5"$B(
$ (E566..:#'#=#=K#**//%&NOP %++G$HD&{'8'8$q'BB %T!W 5 %I $> 12dii./&&'>M}}GNN7<<>*HHYE}-7G,,LLa) . MM$))E*+MM3::7;N;N;PQ 1889M9M9OPQ073H3H3JJK!073J3J3LLM!073J3J3LLM' %* 4*++  "21
 1
 OOM*!11@@	(NN9>>#34 A 4)**$-d.A.A$B t**+a/OO&:37)$DEOO$9:*NN;#3#3#56  "4!344NN4#8#8#=#B#B#DE$$&4,,T]]1Cc1I!%s!3!3uzz|4((*"5-88,1,=,=HP Xtd{!; X $$3$:$:(0(>(>,46I)*%&!" !% 0 0 217X=M=M=S=S=U8V1WI$(MM(6(=(=,5aL,?,?08:M-. -6aL,?,?08:M-.	)*	%& 2X ->. !,,.$UE22-2YY	#*9g#>#> 5>NN4D%&4DD )-dTk(B4D%& %)MM(6(=(=,01E1E1G,H,K,R,R079L-. -11G1G1I,J1,M	)*%& .7 !,,.] "4 %C| 4122OO./NN466==BBDEMME6JK55==>>-"D{{{%{{HH,!>>6>>4;;x;PQR '''-44 & 0 0 7 7BU V ((*! >$ 4122OO./55v}}1134~~~HH'.. 226==3E3EFMM (*= $$&  "$nnF//47!;;2 HH L S S$*JJ$5$5g$>$*KK$6$6w$?$*NN!" !HH H O O$*JJ$5$5g$>!" 188 &

 1 1(<O P & 2 28=P Q & |||&9&@&@&NO((*9 -:   "U 6X 4788OOO,"&"C"C~4499;<%%&++228=PQ
   "%3%;%;MNN=#7#7#<#<#>BMM")))..55h@ST 	 $$& &< #D& 4788OO45;;v}}1134  "$nnF//47FMM &

 1 1(<O P & /66 &

 1 1(<O P & 2 28=P Q & |||&9&@&@&NO((*) -*   "3 <6 4344OO01NN488??DDFG 99AA==,#==//:MNDMM!$q)
 #0"3"3HOO4F4F"LKMM!(//"4"4Q!7s;-qI
 x335q98[11NN8#5#5#<#<#A#A#CQG'/'9'9'A'A&++7#.#3#3#:#:7DW#XD MM")$q 1 !
 !MMGK4F4F4I4I!3LA*NPQR{'9'9'>'>'@!D";<< NN;+@+@+G+G+L+L+NPQR1<1F1F1N1N#*=&#A#A$(MM(C,9,>,>,C,C,9,>,>,F,F,0HH0=0B0B0G0G-. -F0=0B0B0G0G0=0B0B0J0J-.
+*)* )*%& %)NN=3G3G3L3L3NPR$S$(NN=3E3E3L3L3Q3Q3SUW$X% 2O( !((=(=y I I$/$9$9$A$A$A $k2 >7;$*;+@+@+H+H+N+N+P$Q8"OC %)MM(5(<(<,/,6,=,=0@BT-..4fWo	)* )+%&8"O (Bh   "O BR  D/00(((((///OOE"NN433::??AB D78800000777OOM*NN4;;BBGGIJ4011OO/011szz01TMM(Z

-H"HI   "999NN399>>#3Q7$$& 2 ??OO./"<<
z005578'//E&%))_UZZ5PQT5U)VV 0   " = D566D223a7OO@A44ryy~~/02|,,1JNN2==#5#5#7; 5
 }}Y	 !Y6%&`   TMM":"A"A#**//"RST" $ 2eii5LLa s?   !Ad
!Ad
[
7Ad_AAed?AeeAee:AffAfc           	     sN    / pV P                  4       pV'       d   W!R&   V P                  P                  4       VR&   V P                  P                  4       VR&   V P                  P                  4       VR&   \        \        R4      p. VR&   V FG  p\        V P                  V^ ,          4      '       g   K(  VR,          P                  V^ ,          4       KI  	  \        V R4      '       d,   V P                  e   V P                  P                  4       VR&   \        \        R4      p. VR	&   V FG  p\        V P                  V^ ,          4      '       g   K(  VR	,          P                  V^ ,          4       KI  	  . VR
&   \        \        R4      pV P                   F  pVP                  4       pVR
,          P                  V4       . VR&   V F<  p\        Wt^ ,          4      '       g   K  VR,          P                  V^ ,          4       K>  	  VP                  4       VR&   \        e   VP!                  4       VR&   \"        e   VP%                  4       VR&   \&        e   VP)                  4       VR&   \*        f   K  VP-                  4       VR&   K  	  \        V R4      '       dv   \        V P                  R4      '       dZ   . VR&   \/        V P                  P0                  4       F1  w  rV
f   K  VR,          P                  V
P                  4       4       K3  	  \        V R4      '       Ed   . VR&   \/        V P2                  4       EFd  w  r. pVP                  VP                  4       4       \        V R4      '       d1   VP                  V P4                  V	,          P                  4       4       \        V R4      '       Ed   \7        V P8                  4      V	8  Ed   . pVP                  V4       V P8                  V	,           EF  pVP                  VP                  4       4       \        VR4      '       d   / pVP:                   Fn  pVP=                  VP                  4       4       VP>                  VR&   \A        VPB                  PE                  4       4       F  pV^,          VV^ ,          &   K  	  Kp  	  VP                  V4       K  \        VR4      '       g   K  VPF                   F  p/ p\        VR4      '       g   K  VP=                  VP                  4       4       \A        VPH                  PK                  4       4      ^ ,          V\A        VPH                  PM                  4       4      ^ ,          &   VP                  V4       K  	  EK  	  VR,          P                  V4       EKg  	  \        V R4      '       d   . VR&   VR,          P                  V PN                  PP                  P                  4       4       V PN                  PR                   F  p/ pVPT                  eW   VPW                  RVPX                  RVPT                  RVPZ                  /4       VP\                  '       d   VP\                  VR &   VR,          P                  V4       K  	  \        V R!4      '       d   . VR"&   V P^                   F  p. pVR",          P                  V4       VP                  VPP                  P                  4       4       VP`                   F  p/ pVPb                  R#J d    VPd                  VR$&   VPX                  VR&   M-VPd                  VR$&   VPZ                  VR&   VPf                  VR%&   VPh                  '       d   VPh                  VR&&   VP                  V4       K  	  K  	  \        V R'4      '       d   . VR(&   V Pj                   F  p/ pVR(,          P                  V4       VPW                  VPP                  P                  4       4       VPZ                  VR$&   VPB                   F=  p/ pVPW                  VPP                  P                  4       4       VPZ                  VR$&   K?  	  K  	  \        V R)4      '       d   . VR*&   V Pl                   F  p. pVR*,          P                  V4       VP                  VPP                  P                  4       4       VP`                   F  p/ pVPb                  R#J d    VPd                  VR$&   VPX                  VR&   M-VPd                  VR$&   VPZ                  VR&   VPf                  VR%&   VPh                  '       d   VPh                  VR&&   VP                  V4       K  	  K  	  \        V R+4      '       Ed-   . VR,&   VR,,          P                  V Pn                  PP                  P                  4       4       V Pn                  PB                   EF  p/ p VPZ                  e   VPZ                  V R&   MCVPP                  Pp                  \r        Pu                  VPP                  Pp                  R-4      3V R.&   V PW                  VPP                  P                  4       4       VR,,          P                  V 4       \        VR/4      '       g   K  . p!V!P                  VPv                  PP                  P                  4       4       VR,,          P                  V!4       VPv                  PB                   EF  p"/ p#V"PZ                  e   V"PZ                  V#R&   MV"PP                  Pp                  V#R.&   V#PW                  V"PP                  P                  4       4       V!P                  V#4       \        V"R/4      '       g   K  . p$V$P                  V"Pv                  PP                  P                  4       4       V!P                  V$4       V"Pv                  PB                   EF  p%\        V%R04      '       g   K  / p&V%Px                  Pz                  V&R1&   V%Px                  P|                  V&R2&   \~        Pu                  V%Px                  Pz                  R34      V&R4&   \        V%Px                  Pz                  V%Px                  P|                  4      V&R5&   V&PW                  V%PP                  P                  4       4       V&PW                  V%Px                  PP                  P                  4       4       V$P                  V&4       EK   	  \        V"Pv                  R64      '       g   EK(  V"Pv                  P                  '       g   EKG  \A        V"Pv                  P                  PE                  4       4       F6  w  p	p'V$P                  V'P                  R7R84      P                  R94      4       K8  	  EK  	  EK  	  \        V R:4      '       dV   V P                  '       dD   V P                  PP                  '       d(   V P                  PP                  P                  4       VR;&   \        V R<4      '       dV   V P                  '       dD   V P                  PP                  '       d(   V P                  PP                  P                  4       VR=&   \        V R>4      '       d   . VR?&   V P                   F  p(/ p)VR?,          P                  V)4       V)PW                  V(PP                  P                  4       4       \        Pu                  V(PP                  P                  V(PP                  P                  4      V)R@&   K  	  V P                  4       '       d   . VRA&   V P                   F  p*. p+VRA,          P                  V+4       V+P                  V*PP                  P                  4       4       V*PB                   FG  p,/ p-V+P                  V-4       V,P                  V-R&    \        V,P                  ,          RB,          V-R@&   KI  	  K  	  V#   \         d    T,P                  T-R@&    Kn  i ; i)Cz5Dump all the PE header information into a dictionary.r2  r&  r*  r1  r  r  r   r  r7  r5  r   ZEntropyZMD5ZSHA1ZSHA256ZSHA512r8  r6  rW  r7  r  rX  rY  r  r  r  r  r8  rR  r9  rg  r_  r  r:  TZDLLZHintZBoundr;  r<  r=  r>  r&  r?  r  r  r  r"   r0   r2   r/   Z	LANG_NAMEZSUBLANG_NAMEr  r@  r   r  rA  rB  r/  rC  r3  rD  r  rE  rF  )Orv   r&  r   r*  r1  rG   r2  r   rw   r   r   r6  r   r  r  r   r  r   r  r   r  r   r  r   r8  rW  r  r8   rX  rY  r+  r  rM  rZ  r@  r  r  r  r@   r  r9   r  rJ  r  rG  r   r_  r  r  r  r   r  rH  r;  r=  r&  r  r  r1   r  r"   r  r  r0   r6   r  r]  r;   rA  r/  r3  rH  r  r.  r-  r}   rI  rq  r;  ).rT   r   rJ  rA  rE   rC  r   rj  Zsection_dictr   r  Zvs_vinfoZversion_info_listZfileinfo_listr  Zstringtable_dictr`  rK  rL  Zvar_dictrM  Zexport_dictrN  Zimport_listr  Zsymbol_dictrO  Zbound_imp_desc_dictrP  Zbound_imp_ref_dictZmodule_listr'  Zresource_type_dictZdirectory_listr  Zresource_id_dictZresource_id_listr  Zresource_lang_dictr(  r  Zdbg_dictrQ  Zbase_reloc_listrR  Z
reloc_dicts.   &                                             r   r   ZPE.dump_dictM  s    	$$&,4()"&//";";"=	,"&//";";"=	,#'#3#3#=#=#?	- $%:MJ	'Dt''a11'"))$q'2   4*++0D0D0P+/+?+?+I+I+KI'($2!<%
! +-	&'-Dt++T!W55./66tAw? . $&	- &'>M}}G",,.Lm$++L9$&L!%7G,, )00a9 & '.&9&9&;L#&-&:&:&<U#'.'<'<'>V$!)0)@)@)BX&!)0)@)@)BX&! %$ 4*++  "21
 1
 (*Im$"+D,@,@,O,O"P(m,33I4G4G4IJ #Q 4)**/1I+,!*4+>+>!?$&!!((););)=>4!344%,,T-B-B3-G-Q-Q-ST4,,T]]1Cc1I$&M%,,];!%s!3!3%,,U__->?"5-88/1,,1,=,= - 4 4X5G5G5I J=E__ 0 :15h6F6F6L6L6N1OIENq\$4Yq\$B 2P ->
 *001AB$UE22-2YY	+-#*9g#>#>$1$8$89L9L9N$OPT(1(>(>(@Q&&'Q)HT)//2F2F2H-I!-L$M %2$8$8$B .7 "4, /0778IJA "@D 4122,.I()()00++22<<> 55== >>-&&%v~~!6>>"FKK '''393C3CK0,-44[A > 4122,.I()55 ,-44[A""6==#:#:#<=$nnF"$K//47-3ZZE*17I.-3ZZE*.4kkF+.4kkF+|||/5||G,&&{3 -	 6$ 4788)+Io&"&"C"C&(#/*112EF#**>+@+@+J+J+LM-;-@-@#E*%3%;%;M)+&&--m.B.B.L.L.NO0=0B0B&u- &< #D 478824I./;; 23::;G""6==#:#:#<=$nnF"$K//47-3ZZE*17I.-3ZZE*.4kkF+.4kkF+|||/5||G,&&{3 - <& 4344.0I*+*+22--44>>@ !99AA%'"==,19&v. !**%))(//*<*<cB0&t,
 #))(//*C*C*EF./667IJ8[11%'N"))(*<*<*C*C*M*M*OP23::>J'/'9'9'A'A+-(&++77B7G7G,V45@5G5G5J5J,T2(//0B0B0L0L0NO&--.>?";<</1,,33 + 5 5 < < F F H +112BC1<1F1F1N1N#*=&#A#A9;$6ANASASAXAX$6v$> )6(:(:(B(B %7(1%& GKhh(5(:(:(?(?G&$6{$C
 )B(5(:(:(?(?(5(:(:(B(B)& %7(6%& %7$=$=(5(<(<(F(F(H%& %7$=$=(5(:(:(A(A(K(K(M%& %5$;$;<N$O- 2O0 !((=(=y I I$/$9$9$A$A$A7;$/$9$9$A$A$G$G$I8"OC %5$;$;(2(9(9,<>P)**0&/%&8"[ (B' BT D/00(((((///#77>>HHJIe D78800000777 0077AAC  4011-/I)*11-.55h?

 4 4 67#->>#**//3::??#S 	 2 ??,.I()"<<
"$,-44_E&&z'8'8'B'B'DE'//E!#J#**:6(-		Ju%8-<UZZ-H-M
6* 0	 =  $ 8-2ZZ
6*8s   !A@@A@$@#A@$c                sJ     V P                  V4      #   \         d     R# i ; i)z;Gets the physical address in the PE file from an RVA value.N)r  r"  r  r   r   get_physical_by_rvaZPE.get_physical_by_rvaq  s*    	++C00 		s    ""c                s>    \         P                  ! RVR,          4      # )zMReturn a four byte string representing the double word value (little endian).rE      r9   r   )rT   dwordr   r   get_data_from_dwordZPE.get_data_from_dword|  s    {{4!344r   c                s    V^,           ^,          \        V4      8  d   R# \        P                  ! RW^,          V^,           ^,           4      ^ ,          # )zConvert four bytes of data to a double word (little endian)

'offset' is assumed to index into a dword array. So setting it to
N will return a dword out of the data starting at offset N*4.

Returns None if the data can't be turned into a double word.
Nr  r8   r9   r:   rT   r"   r   r   r   r  ZPE.get_dword_from_data  D     QJ!c$i'}}T4
fqjA5E#FGJJr   c                sl     V P                  V P                  V^4      ^ 4      #   \         d     R# i ; i)zReturn the double word value at the given RVA.

Returns None if the value can't be read, i.e. the RVA can't be mapped
to a file offset.
N)r  r|   ru   r  r   r   r  ZPE.get_dword_at_rva  s7    	++DMM#q,A1EE 		s   !$ 33c                s    V^,           \        V P                  4      8  d   R# V P                  V P                  W^,            ^ 4      # )zFReturn the double word value at the given file offset. (little endian)N)r8   r   r  r   r   r   get_dword_from_offsetZPE.get_dword_from_offset  <     A:DMM**''fz(JANNr   c                B    V P                  WP                  V4      4      # )zLSet the double word value at the file offset corresponding to the given RVA.)set_bytes_at_rvarW  )rT   r}   rV  r   r   set_dword_at_rvaZPE.set_dword_at_rva      $$S*B*B5*IJJr   c                r]  )z3Set the double word value at the given file offset.)rZ  rW  )rT   r   rV  r   r   rX  ZPE.set_dword_at_offset      ''0H0H0OPPr   c                0    \         P                  ! RV4      # )zFReturn a two byte string representing the word value. (little endian).r{   rU  rT   ru  r   r   get_data_from_wordZPE.get_data_from_word      {{4&&r   c                s    V^,           ^,          \        V4      8  d   R# \        P                  ! RW^,          V^,           ^,           4      ^ ,          # )zConvert two bytes of data to a word (little endian)

'offset' is assumed to index into a word array. So setting it to
N will return a dword out of the data starting at offset N*2.

Returns None if the data can't be turned into a word.
Nr{   rX  rY  r   r   r  ZPE.get_word_from_data  rZ  r   c                x     V P                  V P                  V4      R,          ^ 4      #   \         d     R# i ; i)zReturn the word value at the given RVA.

Returns None if the value can't be read, i.e. the RVA can't be mapped
to a file offset.
:Nrp   NN)r  r|   ru   r  r   r   get_word_at_rvaZPE.get_word_at_rva  s:    	**4==+=b+A1EE 		   '* 99c                s    V^,           \        V P                  4      8  d   R# V P                  V P                  W^,            ^ 4      # )z?Return the word value at the given file offset. (little endian)N)r8   r   r  r   r   r   get_word_from_offsetZPE.get_word_from_offset  s<     A:DMM**&&t}}Vqj'I1MMr   c                r]  )zESet the word value at the file offset corresponding to the given RVA.)r^  rd  )rT   r}   ru  r   r   set_word_at_rvaZPE.set_word_at_rva  s    $$S*A*A$*GHHr   c                r]  )z,Set the word value at the given file offset.)rZ  rd  )rT   r   ru  r   r   r`  ZPE.set_word_at_offset  s    ''0G0G0MNNr   c                rb  )zMReturn an eight byte string representing the quad-word value (little endian).<QrU  rc  r   r   get_data_from_qwordZPE.get_data_from_qword  re  r   c                s    V^,           ^,          \        V4      8  d   R# \        P                  ! RW^,          V^,           ^,           4      ^ ,          # )zConvert eight bytes of data to a word (little endian)

'offset' is assumed to index into a word array. So setting it to
N will return a dword out of the data starting at offset N*8.

Returns None if the data can't be turned into a quad word.
Nrk  rX  rY  r   r   get_qword_from_dataZPE.get_qword_from_data  rZ  r   c                rf  )zReturn the quad-word value at the given RVA.

Returns None if the value can't be read, i.e. the RVA can't be mapped
to a file offset.
:Nr!  NN)rm  r|   ru   r  r   r   get_qword_at_rvaZPE.get_qword_at_rva  s:    	++DMM#,>r,BAFF 		rh  c                s    V^,           \        V P                  4      8  d   R# V P                  V P                  W^,            ^ 4      # )zDReturn the quad-word value at the given file offset. (little endian)N)r8   r   rm  r   r   r   get_qword_from_offsetZPE.get_qword_from_offset  r\  r   c                r]  )zJSet the quad-word value at the file offset corresponding to the given RVA.)r^  rl  )rT   r}   qwordr   r   set_qword_at_rvaZPE.set_qword_at_rva  r`  r   c                r]  )z1Set the quad-word value at the given file offset.)rZ  rl  )rT   r   rp  r   r   set_qword_at_offsetZPE.set_qword_at_offset
  ra  r   c                s    \        V\        4      '       g   \        R4      hV P                  V4      pV'       g   R# V P	                  W24      # )zOverwrite, with the given string, the bytes at the file offset corresponding
to the given RVA.

Return True if successful, False otherwise. It can fail if the
offset is outside the file's boundaries.
data should be of type: bytesF)rA   rC   	TypeErrorrS  rZ  )rT   r}   r"   r   r   r   r^  ZPE.set_bytes_at_rva  sD     $&&;<<))#.''55r   c                s    \        V\        4      '       g   \        R4      h^ Tu;8:  d   \        V P                  4      8  d   M R# V P                  W4       R# R# )zOverwrite the bytes at the given file offset with the given string.

Return True if successful, False otherwise. It can fail if the
offset is outside the file's boundaries.
rs  FT)rA   rC   rt  r8   r   set_data_bytes)rT   r   r"   r   r   rZ  ZPE.set_bytes_at_offset#  sR     $&&;<<+T]]++  -  r   c                s&   < V ^8  d   QhRS[ RS[/# )rp   r   r"   )r   rC   r   r   r   r   ZPE.__annotate__4  s     : :S : :r   c                s    \        V P                  \        4      '       g,   \        V P                  4      pV P                  4        W0n        W P                  W\	        V4      ,           % R # r   )rA   r   r   r  r8   )rT   r   r"   new_datar   r   ru  ZPE.set_data_bytes4  sG    $--33 /H$M59fD	12r   c                s4   V P                    F  pV P                  VP                  4      pW!P                  ,           pV\	        V P
                  4      8  g   KL  V\	        V P
                  4      8  g   Kh  V P                  W!P                  4       4       K  	  R# )zUUpdate the PE image content with any individual section data that has been
modified.
N)r  r   r   r   r8   r   ru  r|   )rT   rj  Zsection_data_startZsection_data_endr   r   merge_modified_section_dataZPE.merge_modified_section_data<  sz    
 }}G!%!=!=g>V>V!W14I4II!C$66;KcO < ##$68H8H8JK %r   c                sJ   WP                   P                  ,
          p\        V P                   P                  4      ^8  E	d   V P                   P                  ^,          P                  '       E	d   \        V R4      '       g   V P                  \        R,          .R7       \        V R4      '       g   V P                  P                  R4       EMV P                   EF  p^ pV\        VP                  4      8  g   K"  VP                  V,          pV^,          pVP                  \        R,          8X  d   KV  VP                  \        R,          8X  dM   V P                  VP                  V P!                  VP                  4      V,           ^,	          R,          4       K  VP                  \        R,          8X  dG   V P                  VP                  V P!                  VP                  4      V,           R,          4       EK   VP                  \        R	,          8X  d@   V P#                  VP                  V P%                  VP                  4      V,           4       EK{  VP                  \        R
,          8X  d   V\        VP                  4      8X  d   EK  VP                  V,          pV^,          pV P                  VP                  V P!                  VP                  4      ^,          VP                  ,           V,           R,          ^,	          4       EK5  VP                  \        R,          8X  g   EKT  V P'                  VP                  V P)                  VP                  4      V,           4       EK  	  WP                   n        \        V R4      '       d@   V P*                   F/  pVP,                   F  pV;P.                  V,          un        K  	  K1  	  \        V R4      '       d   V P0                  P2                  ;P4                  V,          un        V P0                  P2                  ;P6                  V,          un        V P0                  P2                  ;P8                  V,          un        V P0                  P2                  ;P:                  V,          un        \        V R4      '       Edp   V P<                  P2                  p	\        V	R4      '       d,   V	P>                  '       d   V	;P>                  V,          un        \        V	R4      '       d,   V	P@                  '       d   V	;P@                  V,          un         \        V	R4      '       d,   V	PB                  '       d   V	;PB                  V,          un!        \        V	R4      '       d,   V	PD                  '       d   V	;PD                  V,          un"        \        V	R4      '       d,   V	PF                  '       d   V	;PF                  V,          un#        \        V	R4      '       d,   V	PH                  '       d   V	;PH                  V,          un$        \        V	R4      '       d,   V	PJ                  '       d   V	;PJ                  V,          un%        \        V	R4      '       d,   V	PL                  '       d   V	;PL                  V,          un&        \        V	R4      '       d,   V	PN                  '       d   V	;PN                  V,          un'        \        V	R4      '       d,   V	PP                  '       d   V	;PP                  V,          un(        V PR                  \T        8X  d>   \        V	R4      '       d,   V	PV                  '       d   V	;PV                  V,          un+        \        V	R4      '       d,   V	PX                  '       d   V	;PX                  V,          un,        \        V	R4      '       d,   V	PZ                  '       d   V	;P\                  V,          un.        \        V	R4      '       d,   V	P\                  '       d   V	;P\                  V,          un.        \        V	R4      '       d,   V	P^                  '       d   V	;P^                  V,          un/        \        V	R4      '       d,   V	P`                  '       d   V	;P`                  V,          un0        \        V	R 4      '       d,   V	Pb                  '       d   V	;Pb                  V,          un1        \        V	R!4      '       d,   V	Pd                  '       d   V	;Pd                  V,          un2        \        V	R"4      '       d,   V	Pf                  '       d   V	;Pf                  V,          un3        \        V	R#4      '       d,   V	Ph                  '       d   V	;Ph                  V,          un4        \        V	R$4      '       d,   V	Pj                  '       d   V	;Pj                  V,          un5        \        V	R%4      '       d0   V	Pl                  '       d   V	;Pl                  V,          un6        R&# R&# R&# R&# R&# R&# )'a  Apply the relocation information to the image using the provided image base.

This method will apply the relocation information to the image. Given the new
base, all the relocations will be processed and both the raw data and the
section's data will be fixed accordingly.
The resulting image can be retrieved as well through the method:

    get_memory_mapped_image()

In order to get something that would more closely match what could be found in
memory once the Windows loader finished its work.
r-  rp  r  zZRelocating image but PE does not have (or pefile cannot parse) a DIRECTORY_ENTRY_BASERELOCIMAGE_REL_BASED_ABSOLUTEIMAGE_REL_BASED_HIGHrI  IMAGE_REL_BASED_LOWIMAGE_REL_BASED_HIGHLOWIMAGE_REL_BASED_HIGHADJr  IMAGE_REL_BASED_DIR64r  rA  r/  LockPrefixTableEditListSecurityCookieSEHandlerTableGuardCFCheckFunctionPointerGuardCFDispatchFunctionPointerGuardCFFunctionTableGuardAddressTakenIatEntryTableGuardLongJumpTargetTableDynamicValueRelocTableCHPEMetadataPointerGuardRFFailureRoutine$GuardRFFailureRoutineFunctionPointer(GuardRFVerifyStackPointerFunctionPointerEnclaveConfigurationPointerVolatileMetadataPointerGuardEHContinuationTableGuardXFGCheckFunctionPointerGuardXFGDispatchFunctionPointer$GuardXFGTableDispatchFunctionPointer CastGuardOsDeterminedFailureModeGuardMemcpyFunctionPointerN)7r   r  r8   r8  r  r   rT  r:  r  rw   r-  rZ  rq  rI  rj  r}   rg  r_  r  rq  rn  r  r  rJ  rA  r9   ZStartAddressOfRawDataZEndAddressOfRawDataZAddressOfIndexZAddressOfCallBacksr/  r  r  r  r  r  r  r  r  r  r  rL  rO  r  r  r  r  r  r  r  r  r  r  r  r  )
rT   Znew_ImageBaseZrelocation_differencerR  Z	entry_idxr  Z
next_entryr   ZfuncZload_configrk  r   r$  ZPE.relocate_imageI  s    !.0D0D0N0N N $$3349$$33A6;;;4!<==++!01R!S T ,  4!<==&&9
 ";;E
 !"I#c%--&88 %i 8!Q	 ::9S)TT "ZZ?;Q+RR !00 %		$($8$8$C&;%<')%* #)!) #ZZ?;P+QQ !00 %		$($8$8$C&;%< #)	!) #ZZ?;T+UU
 !11 %		 $ 5 5eii @"7!8 #ZZ?;T+UU  )C,>> %).y)AJ%NI 00 %		%)%9%9%))%D%J&0nn%5&;%< '1%1
 $&!&	 #ZZ?;R+SS !11 %		 $ 5 5eii @"7!8m <x .;  * t56666C #(== !, 7 t233((//EE)E ((//CC)C ((//>>BWW>((//BB)B t:;;">>EEK):;;#333//3HH/;
338L8L8L((,AA(K)9::#222..2GG.K)9::#222..2GG.K)FGG#???;;?TT;K)IJJ#BBB>>BWW>K)?@@#888448MM4K)IJJ#BBB>>BWW>K)CDD#<<<88<QQ8K)ABB#:::66:OO6LL$AA-BCC#777337LL3K)@AA#999559NN5K)OPP#HHHHH-H K)STT#LLLHH-H K)FGG#???;;?TT;K)BCC#;;;77;PP7K)CDD#<<<88<QQ8K)GHH#@@@<<@UU<K)JKK#CCC??CXX?K)OPP#HHHDD-D K)KLL#DDD@@-@ K)EFF#>>>::>SS: ? Ge <u < :r   c                sP    V P                   P                  V P                  4       8H  # r   )r   ZCheckSumgenerate_checksumrY   r#   r   verify_checksumZPE.verify_checksumL  s"    ##,,0F0F0HHHr   c                s   V P                  4       pV P                  4        Wn        V P                  P	                  4       ^@,           p^ p\        V P                  4      ^,          p\        V P                  4      ^V,
          V^ 8g  ,          ,           p\        V^,          4       F  pWb^,          8X  d   K  V^,           V^,          8X  dQ   V'       dI   \        P                  ! RV P                  V^,          R R^V,
          ,          ,           4      ^ ,          pM@\        P                  ! RV P                  V^,          V^,          ^,            4      ^ ,          pW7,          pVR8  g   K  VR,          V^ ,	          ,           pK  	  VR,          V^,	          ,           pW3^,	          ,           pVR,          pV\        V P                  4      ,           # )r  r   Nr   rT  rI  r!  )	r^  r  r   r   r   r8   r1  r9   r:   )rT   rv  Zchecksum_offsetrI  Z	remainderZdata_lenr=   rV  r>  r   r  ZPE.generate_checksumO  sr    ::<  ..>>@4G &*	t}}%!i-IN)KLx1}%Aq((1uQ'Iq1uw/5A	M3JK c4==QQ+KLQOH5 $z1h"nE & v%(b.9R0f$ #dmm,,,r   c                s    \         R,          pV P                  4       '       g:   V P                  4       '       g$   WP                  P                  ,          V8X  d   R# R# )zCheck whether the file is a standard executable.

This will return true only if the file has the IMAGE_FILE_EXECUTABLE_IMAGE flag
set and the IMAGE_FILE_DLL not set and the file does not appear to be a driver
either.
IMAGE_FILE_EXECUTABLE_IMAGETF)r2  is_dllrh  r1  r   )rT   ZEXE_flagr-   r   is_exeZ	PE.is_exe  sF     ))FG ^^%%,,<<<Ir   c                sf    \         R,          pWP                  P                  ,          V8X  d   R# R# )ztCheck whether the file is a standard DLL.

This will return true only if the image has the IMAGE_FILE_DLL flag set.
IMAGE_FILE_DLLTF)r2  r1  r   )rT   ZDLL_flagr-   r   r  Z	PE.is_dll  s,     ))9:''777HDr   c                s^   \        V R4      '       g   V P                  \        R,          .R7       \        V R4      '       g   R# 0 RmpTP                  V P                   Uu0 uF  q"P
                  P                  4       kK  	  up4      '       d   R# RR0pTP                  V P                   Uu0 uF+  qDP                  P                  4       P                  R4      kK-  	  up4      '       d6   V P                  P                  \        R	,          \        R
,          39   d   R# R# u upi u upi )zCheck whether the file is a Windows driver.

This will return true only if there are reliable indicators of the image
being a driver.
r  rl  rx  FTs   pages   pagedr   IMAGE_SUBSYSTEM_NATIVEIMAGE_SUBSYSTEM_NATIVE_WINDOWS>   s   hal.dlls   ndis.syss	   kdcom.dlls   bootvid.dlls   ntoskrnl.exe)r   rT  r:  Zintersectionr  r   r  r  rg  r   r   Z	SubsystemSUBSYSTEM_TYPE)rT   Zsystem_DLLsr  Zdriver_like_section_namesrj  r)  r   rh  ZPE.is_driver  s   , t566'',-KLM (  t566

 ##(,(C(CD(CWW]]_(CD
 
 %,h$7!$11AEOg\\!((1O
 
   **78?@ ! E Ps   ""D%01D*c                s  a Ro\        V P                  4      3V3R llp\        V R4      '       d7   V! V P                  P	                  4       V P
                  P                  34      oV P                   F!  pV! VP                  VP                  34      oK#  	  \        R,          .p\        V P                  P                  4       F;  w  rEWC9   d   K   V! V P                  VP                  4      VP                  34      oK=  	  \        V P                  4      \#        S4      8  d   \#        S4      # R#   \          d     K}  i ; i)zgGet the offset of data appended to the file and not contained within
the area described in the headers.c                 sV   < \        S4      \        V 4      u;8  d
   V8:  d    V #  S# S# r   )sum)Zoffset_and_sizeZ	file_sizelargest_offset_and_sizerX   r   'update_if_sum_is_larger_and_within_fileZQPE.get_overlay_data_start_offset.<locals>.update_if_sum_is_larger_and_within_file  s5     *+c/.BOiO&& P****r   r   IMAGE_DIRECTORY_ENTRY_SECURITYN)r    r    )r8   r   r   r   r   r1  r3  r  r   r   r:  r   r8  r  r   r  ru   r  )rT   r  rj  Zskip_directoriesr   r  r  s   &     @r   get_overlay_data_start_offsetZ PE.get_overlay_data_start_offset  s/    #) (+4=='9	+ 4*++&M((88:$$99'# }}G&M))7+@+@A'# %
 ,,LMN'(<(<(K(KLNC&*Q--i.F.FGX+'	 M t}}$; <<.// ! s   -D55EEc                sL    V P                  4       pVe   V P                  VR # R# )z]Get the data appended to the file and not contained within the area described
in the headers.Nr  r   rT   Zoverlay_data_offsetr-   r   get_overlayZPE.get_overlay
  s/     #@@B*==!4!566r   c                sn    V P                  4       pVe   V P                  RV # V P                  R,          # )zKReturn the just data defined by the PE headers, removing any overlaid data.N:NNNr  r  r-   r   trimZPE.trim  s;     #@@B*==!5"566}}Qr   c                s6   V P                   P                  \        8  ds   V P                  R J dc   \	        V P                   P                  4      '       g>   V P
                  P                  RV P                   P                  ,          4       RV n        VR,          # )Fz=If FileAlignment > 0x200 it should be a power of 2. Value: %xTi )r   r   MIN_VALID_FILE_ALIGNMENTr  rN   r  rw   )rT   r   r   r   r   ZPE.adjust_PointerToRawData%  s    --1II))U2<$$22< < &&S++99; .2* V|r   c                s    VR 8  dB   W28w  d<   V P                   RJ d,   V P                  P                  RVR RVR R24       RV n         \        WV4      # )r   FzIf SectionAlignment(0xr   z+) < 0x1000 it should equal FileAlignment(0xr  T)r   r  rw   r   )rT   r   r   r   r  r   r   ZPE.adjust_SectionAlignment:  sj     v%311U:&&,->q,A B--;A,>aA 15-,S^TTr   )r&  r1  r  rX  r*  r   rL  rU  r   r  rW  r   Z__from_fileZ__resource_size_limit_reachedZ!__resource_size_limit_upperboundsr  Z__total_import_symbolsZ__total_resource_bytesZ__total_resource_entries_countZ
__warningsr  r  r!  r=  r  r  r  )ZIMAGE_DOS_HEADER)z	H,e_magiczH,e_cblpzH,e_cpzH,e_crlczH,e_cparhdrzH,e_minalloczH,e_maxalloczH,e_sszH,e_spzH,e_csumzH,e_ipzH,e_csz
H,e_lfarlczH,e_ovnoz8s,e_resz	H,e_oemidzH,e_oeminfoz
20s,e_res2z
I,e_lfanew)ZIMAGE_FILE_HEADER)z	H,MachinezH,NumberOfSectionsI,TimeDateStampzI,PointerToSymbolTablezI,NumberOfSymbolszH,SizeOfOptionalHeaderzH,Characteristics)ZIMAGE_DATA_DIRECTORY)I,VirtualAddressI,Size)ZIMAGE_OPTIONAL_HEADER)H,MagicB,MajorLinkerVersionB,MinorLinkerVersionI,SizeOfCodeI,SizeOfInitializedDataI,SizeOfUninitializedDataI,AddressOfEntryPointI,BaseOfCodezI,BaseOfDatazI,ImageBaseI,SectionAlignmentI,FileAlignmentH,MajorOperatingSystemVersionH,MinorOperatingSystemVersionH,MajorImageVersionH,MinorImageVersionH,MajorSubsystemVersionH,MinorSubsystemVersionI,Reserved1I,SizeOfImageI,SizeOfHeaders
I,CheckSumH,SubsystemH,DllCharacteristicszI,SizeOfStackReservezI,SizeOfStackCommitzI,SizeOfHeapReservezI,SizeOfHeapCommitI,LoaderFlagsI,NumberOfRvaAndSizes)ZIMAGE_OPTIONAL_HEADER64)r  r  r  r  r  r  r  r  zQ,ImageBaser  r  r  r  r  r  r  r  r  r  r  r  r  r  zQ,SizeOfStackReservezQ,SizeOfStackCommitzQ,SizeOfHeapReservezQ,SizeOfHeapCommitr  r  )ZIMAGE_NT_HEADERS)r  )ZIMAGE_SECTION_HEADER)
z8s,Namez,I,Misc,Misc_PhysicalAddress,Misc_VirtualSizer  zI,SizeOfRawDataI,PointerToRawDatazI,PointerToRelocationszI,PointerToLinenumberszH,NumberOfRelocationszH,NumberOfLinenumbersI,Characteristics)ZIMAGE_DELAY_IMPORT_DESCRIPTOR)z	I,grAttrszI,szNamezI,phmodzI,pIATzI,pINTzI,pBoundIATzI,pUnloadIATzI,dwTimeStamp)ZIMAGE_IMPORT_DESCRIPTOR)z$I,OriginalFirstThunk,Characteristicsr  zI,ForwarderChainI,NamezI,FirstThunk)ZIMAGE_EXPORT_DIRECTORY)r  r  H,MajorVersionH,MinorVersionr  zI,BasezI,NumberOfFunctionszI,NumberOfNameszI,AddressOfFunctionszI,AddressOfNameszI,AddressOfNameOrdinals)ZIMAGE_RESOURCE_DIRECTORY)r  r  r  r  zH,NumberOfNamedEntrieszH,NumberOfIdEntries)ZIMAGE_RESOURCE_DIRECTORY_ENTRY)r  I,OffsetToData)ZIMAGE_RESOURCE_DATA_ENTRY)r  r  z
I,CodePagez
I,Reserved)rW  zH,LengthzH,ValueLengthzH,Type)r  )r  zI,StrucVersionzI,FileVersionMSzI,FileVersionLSzI,ProductVersionMSzI,ProductVersionLSzI,FileFlagsMaskzI,FileFlagszI,FileOSz
I,FileTypezI,FileSubtypezI,FileDateMSzI,FileDateLS)ZStringFileInfor  )rY  r  )ZStringr  )r  r  )IMAGE_THUNK_DATA)z0I,ForwarderString,Function,Ordinal,AddressOfData)r  )z0Q,ForwarderString,Function,Ordinal,AddressOfData)ZIMAGE_DEBUG_DIRECTORY)r  r  r  r  zI,TypezI,SizeOfDatazI,AddressOfRawDatar  )ZIMAGE_BASE_RELOCATION)r  zI,SizeOfBlock)ZIMAGE_BASE_RELOCATION_ENTRY)zH,Data)Z0IMAGE_IMPORT_CONTROL_TRANSFER_DYNAMIC_RELOCATION)zI:12,PageRelativeOffsetzI:1,IndirectCallzI:19,IATIndex)Z/IMAGE_INDIR_CONTROL_TRANSFER_DYNAMIC_RELOCATION)H:12,PageRelativeOffsetzH:1,IndirectCallzH:1,RexWPrefixzH:1,CfgCheckzH:1,Reserved)Z+IMAGE_SWITCHTABLE_BRANCH_DYNAMIC_RELOCATION)r  zH:4,RegisterNumber)ZIMAGE_FUNCTION_OVERRIDE_HEADER)zI,FuncOverrideSize)Z*IMAGE_FUNCTION_OVERRIDE_DYNAMIC_RELOCATION)zI,OriginalRvazI,BDDOffsetz	I,RvaSizeI,BaseRelocSize)ZIMAGE_BDD_INFO)	I,Versionz	I,BDDSize)ZIMAGE_BDD_DYNAMIC_RELOCATION)zH,LeftzH,RightzI,Value)IMAGE_TLS_DIRECTORY)zI,StartAddressOfRawDatazI,EndAddressOfRawDatazI,AddressOfIndexzI,AddressOfCallBacksI,SizeOfZeroFillr  )r  )zQ,StartAddressOfRawDatazQ,EndAddressOfRawDatazQ,AddressOfIndexzQ,AddressOfCallBacksr  r  )IMAGE_LOAD_CONFIG_DIRECTORY)4r  r  r  r  I,GlobalFlagsClearI,GlobalFlagsSetI,CriticalSectionDefaultTimeoutzI,DeCommitFreeBlockThresholdzI,DeCommitTotalFreeThresholdzI,LockPrefixTablezI,MaximumAllocationSizezI,VirtualMemoryThresholdI,ProcessHeapFlagszI,ProcessAffinityMaskH,CSDVersionH,DependentLoadFlagsz
I,EditListzI,SecurityCookiezI,SEHandlerTablezI,SEHandlerCountzI,GuardCFCheckFunctionPointerz I,GuardCFDispatchFunctionPointerzI,GuardCFFunctionTablezI,GuardCFFunctionCountI,GuardFlagsH,CodeIntegrityFlagsH,CodeIntegrityCatalogI,CodeIntegrityCatalogOffsetI,CodeIntegrityReservedz I,GuardAddressTakenIatEntryTablez I,GuardAddressTakenIatEntryCountzI,GuardLongJumpTargetTablezI,GuardLongJumpTargetCountzI,DynamicValueRelocTablezI,CHPEMetadataPointerzI,GuardRFFailureRoutinez&I,GuardRFFailureRoutineFunctionPointerI,DynamicValueRelocTableOffsetH,DynamicValueRelocTableSectionr  z*I,GuardRFVerifyStackPointerFunctionPointerI,HotPatchTableOffsetI,Reserved3zI,EnclaveConfigurationPointerzI,VolatileMetadataPointerzI,GuardEHContinuationTablezI,GuardEHContinuationCountzI,GuardXFGCheckFunctionPointerz!I,GuardXFGDispatchFunctionPointerz&I,GuardXFGTableDispatchFunctionPointerz"I,CastGuardOsDeterminedFailureModezI,GuardMemcpyFunctionPointer)r  )4r  r  r  r  r  r  r  zQ,DeCommitFreeBlockThresholdzQ,DeCommitTotalFreeThresholdzQ,LockPrefixTablezQ,MaximumAllocationSizezQ,VirtualMemoryThresholdzQ,ProcessAffinityMaskr  r  r  z
Q,EditListzQ,SecurityCookiezQ,SEHandlerTablezQ,SEHandlerCountzQ,GuardCFCheckFunctionPointerz Q,GuardCFDispatchFunctionPointerzQ,GuardCFFunctionTablezQ,GuardCFFunctionCountr  r  r  r  r  z Q,GuardAddressTakenIatEntryTablez Q,GuardAddressTakenIatEntryCountzQ,GuardLongJumpTargetTablezQ,GuardLongJumpTargetCountzQ,DynamicValueRelocTablezQ,CHPEMetadataPointerzQ,GuardRFFailureRoutinez&Q,GuardRFFailureRoutineFunctionPointerr  r  r  z*Q,GuardRFVerifyStackPointerFunctionPointerr  r  zQ,EnclaveConfigurationPointerzQ,VolatileMetadataPointerzQ,GuardEHContinuationTablezQ,GuardEHContinuationCountzQ,GuardXFGCheckFunctionPointerz!Q,GuardXFGDispatchFunctionPointerz&Q,GuardXFGTableDispatchFunctionPointerz"Q,CastGuardOsDeterminedFailureModezQ,GuardMemcpyFunctionPointer)ZIMAGE_DYNAMIC_RELOCATION_TABLE)r  r  )ZIMAGE_DYNAMIC_RELOCATION)I,Symbolr  )ZIMAGE_DYNAMIC_RELOCATION64)Q,Symbolr  )ZIMAGE_DYNAMIC_RELOCATION_V2)I,HeaderSizeI,FixupInfoSizer  I,SymbolGroupI,Flags)ZIMAGE_DYNAMIC_RELOCATION64_V2)r  r  r  r  r  )ZIMAGE_BOUND_IMPORT_DESCRIPTOR)r  H,OffsetModuleNamezH,NumberOfModuleForwarderRefs)ZIMAGE_BOUND_FORWARDER_REF)r  r  z
H,Reserved)ZRUNTIME_FUNCTION)zI,BeginAddresszI,EndAddresszI,UnwindDatar   )NFF)r    Nr    NF)r   r.  )rb  N)r    N)   N)rk   )Nr  )r[   r\   r]   r^   r   r%  r0  r9  r4  r5  r)  rf  r  r  r  r  r  r  r  r  r  r  r  r  r"  r#  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  Z&__IMAGE_DYNAMIC_RELOCATION_V2_format__Z(__IMAGE_DYNAMIC_RELOCATION64_V2_format__r  r  r  MAX_SYMBOL_EXPORT_COUNTrQ   r
  r  r  r	  r  r  r  rN  rv   rQ  r?  r^  r<  rT  r  r  r~  r  r  r  r}  r  r  r  r|  r{  r  r  r  rz  r  r  r  r  r  r  ry  r  r  r%  r*  r|   r  r  r  r  r+  r  rs   r  r>  rl   r.  r0  r1  r,  r   rS  rW  r  r  r[  r_  rX  rd  r  rg  ri  rj  r`  rl  rm  rn  ro  rq  rr  r^  rZ  ru  rw  r$  r  r  r  r  rh  r  r  r  r   r   r_   r`   r   r   r   r  r  	  s    BP#2$ '#
"($H!*&F #I'# 0,	*&)%"
+'1-
,(
!
#&!
 VKEN#
%!
($($
.*
C?
	B>>:
1-
=9!
/+

&"
($8.*t80,t1-
+'
-)
.*
0,
0,
,(
# 23j,,]~
Sj	 $22#hKZ]4~Xtun*83
jd#LU'n@
9v)V%NGRo'b	0>j$XF
PH	kZ?.;`?2hT\ |AFCJ!6 'D->*( 1B 	P)6V  :1jXbH	5K
OKQ'K
NIO'K
OKQ6"": :LATFI0-d&;z*X	  *U Ur   r  c                  s\   ^ RI p RpV P                  R,          '       g   \        V4       R# V P                  ^,          R8X  d   V P                  R,          '       g   V P                  R4       \	        V P                  ^,          4      pVP
                  P                   FR  p\        \        VP                  P                  VP                  ,           4      VP                  VP                  4       KT  	  R# \        \	        V P                  ^,          4      P                  4       4       R# )r    Nz1pefile.py <filename>
pefile.py exports <filename>:r*   NNr  :rp   NNzerror: <filename> required)r  ZargvrO  Zexitr  r  r  r  r   r  rJ  r   rG  r,  )r  Zusagerf   r  s       r   mainr  K  s     E 88B<<e	!		!xx||HH12_,,44CB&&003;;>?3;; 5
 	b!o'')*r   Z__main__)r  FF))rm  r    )rl  r*   )rn  rp   )ru  r  )r  rJ  )rp     )ro  rx  )ZIMAGE_DIRECTORY_ENTRY_COPYRIGHT   )ZIMAGE_DIRECTORY_ENTRY_GLOBALPTRr!  )rq  	   )rr  
   )rt     )ZIMAGE_DIRECTORY_ENTRY_IAT   )rs     )Z$IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR   )ZIMAGE_DIRECTORY_ENTRY_RESERVED   ))ZIMAGE_FILE_RELOCS_STRIPPEDr*   )r  rp   )ZIMAGE_FILE_LINE_NUMS_STRIPPEDrJ  )ZIMAGE_FILE_LOCAL_SYMS_STRIPPEDr!  )ZIMAGE_FILE_AGGRESIVE_WS_TRIMr  )ZIMAGE_FILE_LARGE_ADDRESS_AWARE    )ZIMAGE_FILE_16BIT_MACHINEr  )ZIMAGE_FILE_BYTES_REVERSED_LOr  )ZIMAGE_FILE_32BIT_MACHINEr  )ZIMAGE_FILE_DEBUG_STRIPPEDr'   )Z"IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP   )ZIMAGE_FILE_NET_RUN_FROM_SWAPr   )ZIMAGE_FILE_SYSTEMr   )r  r&   )ZIMAGE_FILE_UP_SYSTEM_ONLY @  )ZIMAGE_FILE_BYTES_REVERSED_HIr(   )ZIMAGE_SCN_TYPE_REGr    )ZIMAGE_SCN_TYPE_DSECTr*   )ZIMAGE_SCN_TYPE_NOLOADrp   )ZIMAGE_SCN_TYPE_GROUPrJ  )ZIMAGE_SCN_TYPE_NO_PADr!  )ZIMAGE_SCN_TYPE_COPYr  )ZIMAGE_SCN_CNT_CODEr  )ZIMAGE_SCN_CNT_INITIALIZED_DATAr  )Z IMAGE_SCN_CNT_UNINITIALIZED_DATAr  )ZIMAGE_SCN_LNK_OTHERr  )ZIMAGE_SCN_LNK_INFOr'   )ZIMAGE_SCN_LNK_OVERr  )ZIMAGE_SCN_LNK_REMOVEr   )ZIMAGE_SCN_LNK_COMDATr   )ZIMAGE_SCN_MEM_PROTECTEDr  )ZIMAGE_SCN_NO_DEFER_SPEC_EXCr  )ZIMAGE_SCN_GPRELr(   )ZIMAGE_SCN_MEM_FARDATAr(   )ZIMAGE_SCN_MEM_SYSHEAPr  )ZIMAGE_SCN_MEM_PURGEABLE   )ZIMAGE_SCN_MEM_16BITr  )ZIMAGE_SCN_MEM_LOCKEDi   )ZIMAGE_SCN_MEM_PRELOADi   )ZIMAGE_SCN_ALIGN_1BYTESr%   )ZIMAGE_SCN_ALIGN_2BYTESi    )ZIMAGE_SCN_ALIGN_4BYTESi  0 )ZIMAGE_SCN_ALIGN_8BYTESi  @ )ZIMAGE_SCN_ALIGN_16BYTESi  P )ZIMAGE_SCN_ALIGN_32BYTESi  ` )ZIMAGE_SCN_ALIGN_64BYTESi  p )ZIMAGE_SCN_ALIGN_128BYTESi   )ZIMAGE_SCN_ALIGN_256BYTESi   )ZIMAGE_SCN_ALIGN_512BYTESi   )ZIMAGE_SCN_ALIGN_1024BYTESi   )ZIMAGE_SCN_ALIGN_2048BYTESi   )ZIMAGE_SCN_ALIGN_4096BYTESi   )ZIMAGE_SCN_ALIGN_8192BYTESi   )ZIMAGE_SCN_ALIGN_MASKi   )ZIMAGE_SCN_LNK_NRELOC_OVFLi   )ZIMAGE_SCN_MEM_DISCARDABLEi   )ZIMAGE_SCN_MEM_NOT_CACHEDi   )ZIMAGE_SCN_MEM_NOT_PAGEDr   )ZIMAGE_SCN_MEM_SHAREDrb  )rd  i    )ZIMAGE_SCN_MEM_READi   @)rc  r)   ))ZIMAGE_DEBUG_TYPE_UNKNOWNr    )ZIMAGE_DEBUG_TYPE_COFFr*   )ZIMAGE_DEBUG_TYPE_CODEVIEWrp   )ZIMAGE_DEBUG_TYPE_FPOr  )ZIMAGE_DEBUG_TYPE_MISCrJ  )ZIMAGE_DEBUG_TYPE_EXCEPTIONr  )ZIMAGE_DEBUG_TYPE_FIXUPrx  )ZIMAGE_DEBUG_TYPE_OMAP_TO_SRCr  )ZIMAGE_DEBUG_TYPE_OMAP_FROM_SRCr!  )ZIMAGE_DEBUG_TYPE_BORLANDr  )ZIMAGE_DEBUG_TYPE_RESERVED10r  )ZIMAGE_DEBUG_TYPE_CLSIDr  )ZIMAGE_DEBUG_TYPE_VC_FEATUREr  )ZIMAGE_DEBUG_TYPE_POGOr  )ZIMAGE_DEBUG_TYPE_ILTCGr  )ZIMAGE_DEBUG_TYPE_MPXr  )ZIMAGE_DEBUG_TYPE_REPROr  )r4     ))ZIMAGE_SUBSYSTEM_UNKNOWNr    )r  r*   )ZIMAGE_SUBSYSTEM_WINDOWS_GUIrp   )ZIMAGE_SUBSYSTEM_WINDOWS_CUIr  )ZIMAGE_SUBSYSTEM_OS2_CUIr  )ZIMAGE_SUBSYSTEM_POSIX_CUIr  )r  r!  )ZIMAGE_SUBSYSTEM_WINDOWS_CE_GUIr  )ZIMAGE_SUBSYSTEM_EFI_APPLICATIONr  )Z'IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVERr  )Z"IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVERr  )ZIMAGE_SUBSYSTEM_EFI_ROMr  )ZIMAGE_SUBSYSTEM_XBOXr  )Z(IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATIONr  )ZIMAGE_FILE_MACHINE_UNKNOWNr    )r  iL  )ZIMAGE_FILE_MACHINE_R3000ib  )ZIMAGE_FILE_MACHINE_R4000if  )ZIMAGE_FILE_MACHINE_R10000ih  )ZIMAGE_FILE_MACHINE_WCEMIPSV2ii  )ZIMAGE_FILE_MACHINE_ALPHAi  )ZIMAGE_FILE_MACHINE_SH3i  )ZIMAGE_FILE_MACHINE_SH3DSPi  )ZIMAGE_FILE_MACHINE_SH3Ei  )ZIMAGE_FILE_MACHINE_SH4i  )ZIMAGE_FILE_MACHINE_SH5i  )ZIMAGE_FILE_MACHINE_ARMi  )ZIMAGE_FILE_MACHINE_THUMBi  )ZIMAGE_FILE_MACHINE_ARMNTi  )ZIMAGE_FILE_MACHINE_AM33i  )ZIMAGE_FILE_MACHINE_POWERPCi  )ZIMAGE_FILE_MACHINE_POWERPCFPi  )r  r'   )ZIMAGE_FILE_MACHINE_MIPS16if  )ZIMAGE_FILE_MACHINE_ALPHA64  )ZIMAGE_FILE_MACHINE_AXP64r  )ZIMAGE_FILE_MACHINE_MIPSFPUif  )ZIMAGE_FILE_MACHINE_MIPSFPU16if  )ZIMAGE_FILE_MACHINE_TRICOREi   )ZIMAGE_FILE_MACHINE_CEFi  )ZIMAGE_FILE_MACHINE_EBCi  )ZIMAGE_FILE_MACHINE_RISCV32i2P  )ZIMAGE_FILE_MACHINE_RISCV64idP  )ZIMAGE_FILE_MACHINE_RISCV128i(Q  )ZIMAGE_FILE_MACHINE_LOONGARCH32i2b  )ZIMAGE_FILE_MACHINE_LOONGARCH64idb  )r  id  )ZIMAGE_FILE_MACHINE_M32RiA  )ZIMAGE_FILE_MACHINE_ARM64id  )ZIMAGE_FILE_MACHINE_CEEi  ))ry  r    )rz  r*   )r{  rp   )r|  r  )r}  rJ  )ZIMAGE_REL_BASED_MIPS_JMPADDRr  )ZIMAGE_REL_BASED_SECTIONrx  )ZIMAGE_REL_BASED_RELr  )ZIMAGE_REL_BASED_MIPS_JMPADDR16r  )ZIMAGE_REL_BASED_IA64_IMM64r  )r~  r  )ZIMAGE_REL_BASED_HIGH3ADJr  ))ZIMAGE_LIBRARY_PROCESS_INITr*   )ZIMAGE_LIBRARY_PROCESS_TERMrp   )ZIMAGE_LIBRARY_THREAD_INITrJ  )ZIMAGE_LIBRARY_THREAD_TERMr!  )Z(IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VAr  )Z%IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASEr  )Z(IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITYr  )Z"IMAGE_DLLCHARACTERISTICS_NX_COMPATr  )Z%IMAGE_DLLCHARACTERISTICS_NO_ISOLATIONr'   )ZIMAGE_DLLCHARACTERISTICS_NO_SEHr  )Z IMAGE_DLLCHARACTERISTICS_NO_BINDr   )Z%IMAGE_DLLCHARACTERISTICS_APPCONTAINERr   )Z#IMAGE_DLLCHARACTERISTICS_WDM_DRIVERr&   )Z!IMAGE_DLLCHARACTERISTICS_GUARD_CFr  )Z.IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWAREr(   ))Z&IMAGE_DLLCHARACTERISTICS_EX_CET_COMPATr*   )Z2IMAGE_DLLCHARACTERISTICS_EX_CET_COMPAT_STRICT_MODErp   )ZFIMAGE_DLLCHARACTERISTICS_EX_CET_SET_CONTEXT_IP_VALIDATION_RELAXED_MODErJ  )Z:IMAGE_DLLCHARACTERISTICS_EX_CET_DYNAMIC_APIS_ALLOW_IN_PROCr!  )Z*IMAGE_DLLCHARACTERISTICS_EX_CET_RESERVED_1r  )Z*IMAGE_DLLCHARACTERISTICS_EX_CET_RESERVED_2r  ))r  r*   )r  rp   )r  rJ  ))ZRAXr    )ZRCXr*   )ZRDXrp   )ZRBXr  )ZRSPrJ  )ZRBPr  )ZRSIrx  )ZRDIr  )ZR8r!  )ZR9r  )ZR10r  )ZR11r  )ZR12r  )ZR13r  )ZR14r  )ZR15r  ))Z	RT_CURSORr*   )Z	RT_BITMAPrp   )ZRT_ICONr  )ZRT_MENUrJ  )Z	RT_DIALOGr  )r  rx  )Z
RT_FONTDIRr  )ZRT_FONTr!  )ZRT_ACCELERATORr  )Z	RT_RCDATAr  )ZRT_MESSAGETABLEr  )ZRT_GROUP_CURSORr  )ZRT_GROUP_ICONr  )r  r  )ZRT_DLGINCLUDE   )ZRT_PLUGPLAY   )ZRT_VXDr  )ZRT_ANICURSOR   )Z
RT_ANIICON   )ZRT_HTML   )ZRT_MANIFEST   )ZLANG_NEUTRALr    )ZLANG_INVARIANTi   )ZLANG_AFRIKAANSi6   )ZLANG_ALBANIANi   )ZLANG_ARABICr*   )ZLANG_ARMENIANi+   )ZLANG_ASSAMESEiM   )Z
LANG_AZERIi,   )ZLANG_BASQUEi-   )ZLANG_BELARUSIANi#   )ZLANG_BENGALIiE   )ZLANG_BULGARIANrp   )ZLANG_CATALANr  )ZLANG_CHINESErJ  )ZLANG_CROATIAN   )Z
LANG_CZECHr  )ZLANG_DANISHrx  )ZLANG_DIVEHIie   )Z
LANG_DUTCHr  )ZLANG_ENGLISHr  )ZLANG_ESTONIANi%   )ZLANG_FAEROESEi8   )Z
LANG_FARSIi)   )ZLANG_FINNISHr  )ZLANG_FRENCHr  )ZLANG_GALICIANiV   )ZLANG_GEORGIANi7   )ZLANG_GERMANr  )Z
LANG_GREEKr!  )ZLANG_GUJARATIiG   )ZLANG_HEBREWr  )Z
LANG_HINDIi9   )ZLANG_HUNGARIANr  )ZLANG_ICELANDICr  )ZLANG_INDONESIANi!   )ZLANG_ITALIANr  )ZLANG_JAPANESEr  )ZLANG_KANNADAiK   )ZLANG_KASHMIRIi`   )Z
LANG_KAZAKi?   )ZLANG_KONKANIiW   )ZLANG_KOREAN   )ZLANG_KYRGYZr  )ZLANG_LATVIANi&   )ZLANG_LITHUANIANi'   )ZLANG_MACEDONIANi/   )Z
LANG_MALAYi>   )ZLANG_MALAYALAMiL   )ZLANG_MANIPURIiX   )ZLANG_MARATHIiN   )ZLANG_MONGOLIANiP   )ZLANG_NEPALIia   )ZLANG_NORWEGIANr  )Z
LANG_ORIYAiH   )ZLANG_POLISHr  )ZLANG_PORTUGUESEr  )ZLANG_PUNJABIiF   )ZLANG_ROMANIANr  )ZLANG_RUSSIANi   )ZLANG_SANSKRITiO   )ZLANG_SERBIANr   )ZLANG_SINDHIiY   )ZLANG_SLOVAKi   )ZLANG_SLOVENIANi$   )ZLANG_SPANISHr  )ZLANG_SWAHILIiA   )ZLANG_SWEDISHi   )ZLANG_SYRIACiZ   )Z
LANG_TAMILiI   )Z
LANG_TATARiD   )ZLANG_TELUGUiJ   )Z	LANG_THAIi   )ZLANG_TURKISHi   )ZLANG_UKRAINIANi"   )Z	LANG_URDUr  )Z
LANG_UZBEKiC   )ZLANG_VIETNAMESEi*   )ZLANG_GAELICi<   )ZLANG_MALTESEi:   )Z
LANG_MAORIi(   )ZLANG_RHAETO_ROMANCEr  )Z
LANG_SAAMIi;   )ZLANG_SORBIANi.   )Z	LANG_SUTUi0   )ZLANG_TSONGAi1   )ZLANG_TSWANAi2   )Z
LANG_VENDAi3   )Z
LANG_XHOSAi4   )Z	LANG_ZULUi5   )ZLANG_ESPERANTOi   )Z
LANG_WALONi   )ZLANG_CORNISHi   )Z
LANG_WELSHi   )ZLANG_BRETONi   )ZSUBLANG_NEUTRALr    )ZSUBLANG_DEFAULTr*   )ZSUBLANG_SYS_DEFAULTrp   )ZSUBLANG_ARABIC_SAUDI_ARABIAr*   )ZSUBLANG_ARABIC_IRAQrp   )ZSUBLANG_ARABIC_EGYPTr  )ZSUBLANG_ARABIC_LIBYArJ  )ZSUBLANG_ARABIC_ALGERIAr  )ZSUBLANG_ARABIC_MOROCCOrx  )ZSUBLANG_ARABIC_TUNISIAr  )ZSUBLANG_ARABIC_OMANr!  )ZSUBLANG_ARABIC_YEMENr  )ZSUBLANG_ARABIC_SYRIAr  )ZSUBLANG_ARABIC_JORDANr  )ZSUBLANG_ARABIC_LEBANONr  )ZSUBLANG_ARABIC_KUWAITr  )ZSUBLANG_ARABIC_UAEr  )ZSUBLANG_ARABIC_BAHRAINr  )ZSUBLANG_ARABIC_QATARr  )ZSUBLANG_AZERI_LATINr*   )ZSUBLANG_AZERI_CYRILLICrp   )ZSUBLANG_CHINESE_TRADITIONALr*   )ZSUBLANG_CHINESE_SIMPLIFIEDrp   )ZSUBLANG_CHINESE_HONGKONGr  )ZSUBLANG_CHINESE_SINGAPORErJ  )ZSUBLANG_CHINESE_MACAUr  )ZSUBLANG_DUTCHr*   )ZSUBLANG_DUTCH_BELGIANrp   )ZSUBLANG_ENGLISH_USr*   )ZSUBLANG_ENGLISH_UKrp   )ZSUBLANG_ENGLISH_AUSr  )ZSUBLANG_ENGLISH_CANrJ  )ZSUBLANG_ENGLISH_NZr  )ZSUBLANG_ENGLISH_EIRErx  )ZSUBLANG_ENGLISH_SOUTH_AFRICAr  )ZSUBLANG_ENGLISH_JAMAICAr!  )ZSUBLANG_ENGLISH_CARIBBEANr  )ZSUBLANG_ENGLISH_BELIZEr  )ZSUBLANG_ENGLISH_TRINIDADr  )ZSUBLANG_ENGLISH_ZIMBABWEr  )ZSUBLANG_ENGLISH_PHILIPPINESr  )ZSUBLANG_FRENCHr*   )ZSUBLANG_FRENCH_BELGIANrp   )ZSUBLANG_FRENCH_CANADIANr  )ZSUBLANG_FRENCH_SWISSrJ  )ZSUBLANG_FRENCH_LUXEMBOURGr  )ZSUBLANG_FRENCH_MONACOrx  )ZSUBLANG_GERMANr*   )ZSUBLANG_GERMAN_SWISSrp   )ZSUBLANG_GERMAN_AUSTRIANr  )ZSUBLANG_GERMAN_LUXEMBOURGrJ  )ZSUBLANG_GERMAN_LIECHTENSTEINr  )ZSUBLANG_ITALIANr*   )ZSUBLANG_ITALIAN_SWISSrp   )ZSUBLANG_KASHMIRI_SASIArp   )ZSUBLANG_KASHMIRI_INDIArp   )ZSUBLANG_KOREANr*   )ZSUBLANG_LITHUANIANr*   )ZSUBLANG_MALAY_MALAYSIAr*   )ZSUBLANG_MALAY_BRUNEI_DARUSSALAMrp   )ZSUBLANG_NEPALI_INDIArp   )ZSUBLANG_NORWEGIAN_BOKMALr*   )ZSUBLANG_NORWEGIAN_NYNORSKrp   )ZSUBLANG_PORTUGUESErp   )ZSUBLANG_PORTUGUESE_BRAZILIANr*   )ZSUBLANG_SERBIAN_LATINrp   )ZSUBLANG_SERBIAN_CYRILLICr  )ZSUBLANG_SPANISHr*   )ZSUBLANG_SPANISH_MEXICANrp   )ZSUBLANG_SPANISH_MODERNr  )ZSUBLANG_SPANISH_GUATEMALArJ  )ZSUBLANG_SPANISH_COSTA_RICAr  )ZSUBLANG_SPANISH_PANAMArx  )Z"SUBLANG_SPANISH_DOMINICAN_REPUBLICr  )ZSUBLANG_SPANISH_VENEZUELAr!  )ZSUBLANG_SPANISH_COLOMBIAr  )ZSUBLANG_SPANISH_PERUr  )ZSUBLANG_SPANISH_ARGENTINAr  )ZSUBLANG_SPANISH_ECUADORr  )ZSUBLANG_SPANISH_CHILEr  )ZSUBLANG_SPANISH_URUGUAYr  )ZSUBLANG_SPANISH_PARAGUAYr  )ZSUBLANG_SPANISH_BOLIVIAr  )ZSUBLANG_SPANISH_EL_SALVADORr  )ZSUBLANG_SPANISH_HONDURASr  )ZSUBLANG_SPANISH_NICARAGUAr  )ZSUBLANG_SPANISH_PUERTO_RICOr  )ZSUBLANG_SWEDISHr*   )ZSUBLANG_SWEDISH_FINLANDrp   )ZSUBLANG_URDU_PAKISTANr*   )ZSUBLANG_URDU_INDIArp   )ZSUBLANG_UZBEK_LATINr*   )ZSUBLANG_UZBEK_CYRILLICrp   )ZSUBLANG_DUTCH_SURINAMr  )ZSUBLANG_ROMANIANr*   )ZSUBLANG_ROMANIAN_MOLDAVIArp   )ZSUBLANG_RUSSIANr*   )ZSUBLANG_RUSSIAN_MOLDAVIArp   )ZSUBLANG_CROATIANr*   )ZSUBLANG_LITHUANIAN_CLASSICrp   )ZSUBLANG_GAELICr*   )ZSUBLANG_GAELIC_SCOTTISHrp   )ZSUBLANG_GAELIC_MANXr  r  )r   Z
__author__Z__version__Z__contact__Zcodecsr  r
   r	   r   r  r  r  r  rh   r9   r   r  r    Zhashlibr   r   r   r   Ztypingr   r  Zregister_errorZlookup_errorr   r   r   r   r$   r  r  r  r  r  r  re  r  r  r  r(  r'  r+  r,  r-  r.  r/  Z IMAGE_NUMBEROF_DIRECTORY_ENTRIESrN  rP  rM  rO  r.   Zdirectory_entry_typesr:  Zimage_characteristicsr2  Zsection_characteristicsr   Zdebug_typesrH  Zsubsystem_typesr  Zmachine_typesr  Zrelocation_typesrI  Zdll_characteristicsr6  Zex_dll_characteristicsr  r  ZSECTOR_SIZEr  r  Z	registersr  r  r  r  r  r  r  r  r  r  r  Zresource_typer  r  r0   r  r2   r+   r4   r3   rw   r6   r?   rG   rL   rN   r  rO   re   r"  ru   r   r   r   r   r   r   r-  r)  r?  rB  rF  r]  r^  rd  rf  rg  rh  ri  rj  rl  rm  ro  rp  rv  rw  rx  ry  rz  r{  r  r  r  r  r  r  r  r  r  r  r  r  Zascii_lowercaseZascii_uppercaser   r]  r  r  r  r  r  r  r[   rM   r   r   <module>r     s    
%     	   	      - -     )6+>+>?Q+R S
" 4  	
             !        #%   )    % 7 ( 45 & %%:; /&/(/ */ )	/
 */ (/ '/ 3/ 5/ (/ '/ '/ )/ )/ ,/  0!/" $#/$ *%/& *'/( ,)/* (+/, )-/. *//0 +1/2 +3/4 +5/6 +7/8 ,9/: ,;/< ,=/> -?/@ -A/B -C/D .E/F .G/H .I/J .K/L )M/N .O/P .Q/R -S/T ,U/V )W/X *Y/Z '[/\ (]/ b ''>? * +&
" o.%'%'% )% )	%
 *% -% )% '% *% (% '% '% '% )% )%  (!%" +#%$ -%%& ('%( *)%* ++%, )-%. +/%0 -1%2 +3%4 '5%6 '7%8 +9%: +;%< ,=%> /?%@ /A%B )C%D (E%F )G%H 'I%N M*  /0 $ ##67   &&<=   
  !!23 	& #	         0 ]+___ _ 	_
 _ _ _ _ _ _ _ _ _ _ _  !_" #_$ %_& '_( )_* +_, -_. /_0 1_2 3_4 5_6 7_8 9_: ;_< =_> ?_@ A_B C_D E_F G_H I_J K_L M_N O_P Q_R S_T U_V W_X Y_Z [_\ ]_^ __` a_b c_d e_f g_h i_j k_l m_n o_p q_r s_t u_v w_x y_z {_| }_~ _@ A_B C_D E_F G_H I_J K_L M_N O_P Q_R S_T U_V W_X Y_Z [_\ ]_^ __` a_b "c_d e_f g_h i_j k_l m_n o_p q_r s_t u_v w_x y_z {_| }_B Dhhh "h *	h
 "h #h #h %h %h %h "h #h #h $h %h  $!h" !#h$ %%h& #'h( ")h* %+h, *-h. )/h0 '1h2 (3h4 $5h6 7h8 $9h: !;h< !=h> "?h@ "AhB !ChD #EhF +GhH &IhJ (KhL %MhN 'OhP 'QhR *ShT UhV %WhX &YhZ #[h\ (]h^ $_h` ahb #chd &ehf (ghh +ihj khl $mhn %ohp %qhr sht !uhv %whx .yhz #{h| '}h~ (h@ !AhB +ChD $EhF 'GhH IhJ &KhL %MhN (OhP )QhR %ShT 1UhV (WhX 'YhZ #[h\ (]h^ &_h` $ahb &chd 'ehf &ghh *ihj 'khl (mhn *ohp qhr &sht $uhv !whx "yhz %{h| $}h~ h@ (AhB ChD 'EhF GhH )IhJ KhL &MhN "OhT w
 w-#*L-%%l3".	 $+8*'/R RH HV I  &; &;T  & 4+ + 4d#' $'TA AHIy IX 4e$NX %NXbi,Y i,X% %] ;" ;"|CM C," ,"^m = *M  M = M }  "] "@m - &]  ] g$' g$TO O28N 8;~ ;8;~ ; 
. 
"XN X&Y~ Y&XN X&Y~ Y&Hn H;
 ;
|
 
F mm !! 	&( - V333fmmC&( 
 4
 
pXU pXUfq+* zF r   