
 Qc        h   @   st  d  Z  d Z d Z d e e d d ! Z d Z d d l Z d d l Z d d l Z d d l	 Z	 d d l
 Z
 d d l Z d d l Z d d l Z d d l Z dI\ Z Z Z Z y4 d d l Z e j Z e j Z e j Z e j Z Wnk e k
 rNy d d l Z e j Z Wn e k
 rn Xy d d l Z e j Z WqOe k
 rJqOXn Xy e Wn e k
 rsd	   Z n Xe Z d
 Z d Z d Z d Z d Z  d Z! d Z" d Z# d Z$ d Z% d Z& d Z' dJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYg Z( e) g  e( D] Z* e* d e* d f ^ qe(  Z+ dZd[d\d]d^d_d`dadbdcdddedfdgdhdig Z, e) g  e, D] Z* e* d e* d f ^ qie,  Z- djdkdldmdndodpdqdrdsdtdudvdwdxdydzd{d|d}d~ddddddddddddddg# Z. e) g  e. D] Z* e* d e* d f ^ q	e.  Z/ dddddddddddg Z0 e) g  e0 D] Z* e* d e* d f ^ qae0  Z1 ddddddddddddg Z2 e) g  e2 D] Z* e* d e* d f ^ qe2  Z3 ddddddddddddddddddddg Z4 e) g  e4 D] Z* e* d e* d f ^ q/e4  Z5 ddddddddddddg Z6 e) g  e6 D] Z* e* d e* d f ^ qe6  Z7 dddddddddddddg Z8 e) g  e8 D] Z* e* d e* d f ^ qe8  Z9 dddddddddddddddddddddg Z: e) g  e: D] Z* e* d e* d f ^ q^e:  Z; ddddddddddddddddddddddddddd ddddddddd	d
dddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCg^ Z< e) e< g  e< D] Z* e* d e* d f ^ q Z= dDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzd{d|d}d~ddddddddddddddddddddddddddddddddddddddddddddgg Z> e) e> g  e> D] Z* e* d e* d f ^ q Z? e) e>  Z? xD e> D]< \ Z@ ZA e? jB eA  re? eA jC e@  qUe@ g e? eA <qUWd  ZD d  ZE d  ZF d  ZG d	  ZH d
  ZI ddd    YZJ deK f d    YZL ddd    YZM i d d6d d6d d6d d6d d6d d6d d6d d6d d6d d6d d6d' d6d' d6d' d6d d6ZN d dd!    YZO d"eO f d#    YZP d$dd%    YZQ d&eQ f d'    YZR d(eQ f d)    YZS d*eQ f d+    YZT d,eQ f d-    YZU d.eQ f d/    YZV d0eQ f d1    YZW d2eQ f d3    YZX d4eQ f d5    YZY d6eQ f d7    YZZ d8eQ f d9    YZ[ d:eQ f d;    YZ\ d<eQ f d=    YZ] d>eQ f d?    YZ^ d@eQ f dA    YZ_ e j` e ja e jb dBdCjc g  ed d@ dB  D] Ze ef ee  ^ q Zg dD  Zh e j` e ja e jb dEZi dF  Zj dGddH    YZk d S(  s  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 the limits of valid PE headers, that is, malware.
Lots of packed malware attempt to abuse the format way beyond its standard use.
To the best of my knowledge most of the abuses are handled gracefully.

Copyright (c) 2005-2011 Ero Carrera <ero.carrera@gmail.com>

All rights reserved.

For detailed copyright information see the file COPYING in
the root of the distribution archive.
s   $LastChangedRevision: 102 $s   Ero Carreras	   1.2.10-%di   is   ero.carrera@gmail.comiNc         C   s(   t  |   } t t d t |   |  S(   Ni    (   t   listt   zipt   ranget   len(   t   itert   L(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt	   enumerate>   s    i   iMZ  iZM  iNE  iLE  iLX  iPE  i   l        l            i  i  t   IMAGE_DIRECTORY_ENTRY_EXPORTi    t   IMAGE_DIRECTORY_ENTRY_IMPORTi   t   IMAGE_DIRECTORY_ENTRY_RESOURCEi   t   IMAGE_DIRECTORY_ENTRY_EXCEPTIONi   t   IMAGE_DIRECTORY_ENTRY_SECURITYi   t   IMAGE_DIRECTORY_ENTRY_BASERELOCi   t   IMAGE_DIRECTORY_ENTRY_DEBUGi   t   IMAGE_DIRECTORY_ENTRY_COPYRIGHTi   t   IMAGE_DIRECTORY_ENTRY_GLOBALPTRi   t   IMAGE_DIRECTORY_ENTRY_TLSi	   t!   IMAGE_DIRECTORY_ENTRY_LOAD_CONFIGi
   t"   IMAGE_DIRECTORY_ENTRY_BOUND_IMPORTi   t   IMAGE_DIRECTORY_ENTRY_IATi   t"   IMAGE_DIRECTORY_ENTRY_DELAY_IMPORTi   t$   IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTORi   t   IMAGE_DIRECTORY_ENTRY_RESERVEDi   t   IMAGE_FILE_RELOCS_STRIPPEDt   IMAGE_FILE_EXECUTABLE_IMAGEt   IMAGE_FILE_LINE_NUMS_STRIPPEDt   IMAGE_FILE_LOCAL_SYMS_STRIPPEDt   IMAGE_FILE_AGGRESIVE_WS_TRIMt   IMAGE_FILE_LARGE_ADDRESS_AWAREi    t   IMAGE_FILE_16BIT_MACHINEi@   t   IMAGE_FILE_BYTES_REVERSED_LOi   t   IMAGE_FILE_32BIT_MACHINEi   t   IMAGE_FILE_DEBUG_STRIPPEDi   t"   IMAGE_FILE_REMOVABLE_RUN_FROM_SWAPi   t   IMAGE_FILE_NET_RUN_FROM_SWAPi   t   IMAGE_FILE_SYSTEMi   t   IMAGE_FILE_DLLi    t   IMAGE_FILE_UP_SYSTEM_ONLYi @  t   IMAGE_FILE_BYTES_REVERSED_HIi   t   IMAGE_SCN_CNT_CODEt   IMAGE_SCN_CNT_INITIALIZED_DATAt    IMAGE_SCN_CNT_UNINITIALIZED_DATAt   IMAGE_SCN_LNK_OTHERt   IMAGE_SCN_LNK_INFOt   IMAGE_SCN_LNK_REMOVEt   IMAGE_SCN_LNK_COMDATt   IMAGE_SCN_MEM_FARDATAt   IMAGE_SCN_MEM_PURGEABLEi   t   IMAGE_SCN_MEM_16BITt   IMAGE_SCN_MEM_LOCKEDi   t   IMAGE_SCN_MEM_PRELOADi   t   IMAGE_SCN_ALIGN_1BYTESt   IMAGE_SCN_ALIGN_2BYTESi    t   IMAGE_SCN_ALIGN_4BYTESi  0 t   IMAGE_SCN_ALIGN_8BYTESi  @ t   IMAGE_SCN_ALIGN_16BYTESi  P t   IMAGE_SCN_ALIGN_32BYTESi  ` t   IMAGE_SCN_ALIGN_64BYTESi  p t   IMAGE_SCN_ALIGN_128BYTESi   t   IMAGE_SCN_ALIGN_256BYTESi   t   IMAGE_SCN_ALIGN_512BYTESi   t   IMAGE_SCN_ALIGN_1024BYTESi   t   IMAGE_SCN_ALIGN_2048BYTESi   t   IMAGE_SCN_ALIGN_4096BYTESi   t   IMAGE_SCN_ALIGN_8192BYTESi   t   IMAGE_SCN_ALIGN_MASKi   t   IMAGE_SCN_LNK_NRELOC_OVFLi   t   IMAGE_SCN_MEM_DISCARDABLEi   t   IMAGE_SCN_MEM_NOT_CACHEDi   t   IMAGE_SCN_MEM_NOT_PAGEDi   t   IMAGE_SCN_MEM_SHAREDi   t   IMAGE_SCN_MEM_EXECUTEi    t   IMAGE_SCN_MEM_READi   @t   IMAGE_SCN_MEM_WRITEt   IMAGE_DEBUG_TYPE_UNKNOWNt   IMAGE_DEBUG_TYPE_COFFt   IMAGE_DEBUG_TYPE_CODEVIEWt   IMAGE_DEBUG_TYPE_FPOt   IMAGE_DEBUG_TYPE_MISCt   IMAGE_DEBUG_TYPE_EXCEPTIONt   IMAGE_DEBUG_TYPE_FIXUPt   IMAGE_DEBUG_TYPE_OMAP_TO_SRCt   IMAGE_DEBUG_TYPE_OMAP_FROM_SRCt   IMAGE_DEBUG_TYPE_BORLANDt   IMAGE_DEBUG_TYPE_RESERVED10t   IMAGE_SUBSYSTEM_UNKNOWNt   IMAGE_SUBSYSTEM_NATIVEt   IMAGE_SUBSYSTEM_WINDOWS_GUIt   IMAGE_SUBSYSTEM_WINDOWS_CUIt   IMAGE_SUBSYSTEM_OS2_CUIt   IMAGE_SUBSYSTEM_POSIX_CUIt   IMAGE_SUBSYSTEM_WINDOWS_CE_GUIt   IMAGE_SUBSYSTEM_EFI_APPLICATIONt'   IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVERt"   IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVERt   IMAGE_SUBSYSTEM_EFI_ROMt   IMAGE_SUBSYSTEM_XBOXt   IMAGE_FILE_MACHINE_UNKNOWNt   IMAGE_FILE_MACHINE_AM33i  t   IMAGE_FILE_MACHINE_AMD64id  t   IMAGE_FILE_MACHINE_ARMi  t   IMAGE_FILE_MACHINE_EBCi  t   IMAGE_FILE_MACHINE_I386iL  t   IMAGE_FILE_MACHINE_IA64t   IMAGE_FILE_MACHINE_MR32iA  t   IMAGE_FILE_MACHINE_MIPS16if  t   IMAGE_FILE_MACHINE_MIPSFPUif  t   IMAGE_FILE_MACHINE_MIPSFPU16if  t   IMAGE_FILE_MACHINE_POWERPCi  t   IMAGE_FILE_MACHINE_POWERPCFPi  t   IMAGE_FILE_MACHINE_R4000if  t   IMAGE_FILE_MACHINE_SH3i  t   IMAGE_FILE_MACHINE_SH3DSPi  t   IMAGE_FILE_MACHINE_SH4i  t   IMAGE_FILE_MACHINE_SH5i  t   IMAGE_FILE_MACHINE_THUMBi  t   IMAGE_FILE_MACHINE_WCEMIPSV2ii  t   IMAGE_REL_BASED_ABSOLUTEt   IMAGE_REL_BASED_HIGHt   IMAGE_REL_BASED_LOWt   IMAGE_REL_BASED_HIGHLOWt   IMAGE_REL_BASED_HIGHADJt   IMAGE_REL_BASED_MIPS_JMPADDRt   IMAGE_REL_BASED_SECTIONt   IMAGE_REL_BASED_RELt   IMAGE_REL_BASED_MIPS_JMPADDR16t   IMAGE_REL_BASED_IA64_IMM64t   IMAGE_REL_BASED_DIR64t   IMAGE_REL_BASED_HIGH3ADJt)   IMAGE_DLL_CHARACTERISTICS_RESERVED_0x0001t)   IMAGE_DLL_CHARACTERISTICS_RESERVED_0x0002t)   IMAGE_DLL_CHARACTERISTICS_RESERVED_0x0004t)   IMAGE_DLL_CHARACTERISTICS_RESERVED_0x0008t&   IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASEt)   IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITYt#   IMAGE_DLL_CHARACTERISTICS_NX_COMPATt&   IMAGE_DLL_CHARACTERISTICS_NO_ISOLATIONt    IMAGE_DLL_CHARACTERISTICS_NO_SEHt!   IMAGE_DLL_CHARACTERISTICS_NO_BINDt)   IMAGE_DLL_CHARACTERISTICS_RESERVED_0x1000t$   IMAGE_DLL_CHARACTERISTICS_WDM_DRIVERt/   IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWAREt	   RT_CURSORt	   RT_BITMAPt   RT_ICONt   RT_MENUt	   RT_DIALOGt	   RT_STRINGt
   RT_FONTDIRt   RT_FONTt   RT_ACCELERATORt	   RT_RCDATAt   RT_MESSAGETABLEt   RT_GROUP_CURSORt   RT_GROUP_ICONt
   RT_VERSIONt   RT_DLGINCLUDEi   t   RT_PLUGPLAYi   t   RT_VXDi   t   RT_ANICURSORt
   RT_ANIICONi   t   RT_HTMLi   t   RT_MANIFESTi   t   LANG_NEUTRALt   LANG_INVARIANTi   t   LANG_AFRIKAANSi6   t   LANG_ALBANIANi   t   LANG_ARABICt   LANG_ARMENIANi+   t   LANG_ASSAMESEiM   t
   LANG_AZERIi,   t   LANG_BASQUEi-   t   LANG_BELARUSIANi#   t   LANG_BENGALIiE   t   LANG_BULGARIANt   LANG_CATALANt   LANG_CHINESEt   LANG_CROATIANi   t
   LANG_CZECHt   LANG_DANISHt   LANG_DIVEHIie   t
   LANG_DUTCHt   LANG_ENGLISHt   LANG_ESTONIANi%   t   LANG_FAEROESEi8   t
   LANG_FARSIi)   t   LANG_FINNISHt   LANG_FRENCHt   LANG_GALICIANiV   t   LANG_GEORGIANi7   t   LANG_GERMANt
   LANG_GREEKt   LANG_GUJARATIiG   t   LANG_HEBREWt
   LANG_HINDIi9   t   LANG_HUNGARIANt   LANG_ICELANDICt   LANG_INDONESIANi!   t   LANG_ITALIANt   LANG_JAPANESEt   LANG_KANNADAiK   t   LANG_KASHMIRIi`   t
   LANG_KAZAKi?   t   LANG_KONKANIiW   t   LANG_KOREANi   t   LANG_KYRGYZt   LANG_LATVIANi&   t   LANG_LITHUANIANi'   t   LANG_MACEDONIANi/   t
   LANG_MALAYi>   t   LANG_MALAYALAMiL   t   LANG_MANIPURIiX   t   LANG_MARATHIiN   t   LANG_MONGOLIANiP   t   LANG_NEPALIia   t   LANG_NORWEGIANt
   LANG_ORIYAiH   t   LANG_POLISHt   LANG_PORTUGUESEt   LANG_PUNJABIiF   t   LANG_ROMANIANt   LANG_RUSSIANi   t   LANG_SANSKRITiO   t   LANG_SERBIANt   LANG_SINDHIiY   t   LANG_SLOVAKi   t   LANG_SLOVENIANi$   t   LANG_SPANISHt   LANG_SWAHILIiA   t   LANG_SWEDISHi   t   LANG_SYRIACiZ   t
   LANG_TAMILiI   t
   LANG_TATARiD   t   LANG_TELUGUiJ   t	   LANG_THAIi   t   LANG_TURKISHi   t   LANG_UKRAINIANi"   t	   LANG_URDUt
   LANG_UZBEKiC   t   LANG_VIETNAMESEi*   t   LANG_GAELICi<   t   LANG_MALTESEi:   t
   LANG_MAORIi(   t   LANG_RHAETO_ROMANCEt
   LANG_SAAMIi;   t   LANG_SORBIANi.   t	   LANG_SUTUi0   t   LANG_TSONGAi1   t   LANG_TSWANAi2   t
   LANG_VENDAi3   t
   LANG_XHOSAi4   t	   LANG_ZULUi5   t   LANG_ESPERANTOi   t
   LANG_WALONi   t   LANG_CORNISHi   t
   LANG_WELSHi   t   LANG_BRETONi   t   SUBLANG_NEUTRALt   SUBLANG_DEFAULTt   SUBLANG_SYS_DEFAULTt   SUBLANG_ARABIC_SAUDI_ARABIAt   SUBLANG_ARABIC_IRAQt   SUBLANG_ARABIC_EGYPTt   SUBLANG_ARABIC_LIBYAt   SUBLANG_ARABIC_ALGERIAt   SUBLANG_ARABIC_MOROCCOt   SUBLANG_ARABIC_TUNISIAt   SUBLANG_ARABIC_OMANt   SUBLANG_ARABIC_YEMENt   SUBLANG_ARABIC_SYRIAt   SUBLANG_ARABIC_JORDANt   SUBLANG_ARABIC_LEBANONt   SUBLANG_ARABIC_KUWAITt   SUBLANG_ARABIC_UAEt   SUBLANG_ARABIC_BAHRAINt   SUBLANG_ARABIC_QATARt   SUBLANG_AZERI_LATINt   SUBLANG_AZERI_CYRILLICt   SUBLANG_CHINESE_TRADITIONALt   SUBLANG_CHINESE_SIMPLIFIEDt   SUBLANG_CHINESE_HONGKONGt   SUBLANG_CHINESE_SINGAPOREt   SUBLANG_CHINESE_MACAUt   SUBLANG_DUTCHt   SUBLANG_DUTCH_BELGIANt   SUBLANG_ENGLISH_USt   SUBLANG_ENGLISH_UKt   SUBLANG_ENGLISH_AUSt   SUBLANG_ENGLISH_CANt   SUBLANG_ENGLISH_NZt   SUBLANG_ENGLISH_EIREt   SUBLANG_ENGLISH_SOUTH_AFRICAt   SUBLANG_ENGLISH_JAMAICAt   SUBLANG_ENGLISH_CARIBBEANt   SUBLANG_ENGLISH_BELIZEt   SUBLANG_ENGLISH_TRINIDADt   SUBLANG_ENGLISH_ZIMBABWEt   SUBLANG_ENGLISH_PHILIPPINESt   SUBLANG_FRENCHt   SUBLANG_FRENCH_BELGIANt   SUBLANG_FRENCH_CANADIANt   SUBLANG_FRENCH_SWISSt   SUBLANG_FRENCH_LUXEMBOURGt   SUBLANG_FRENCH_MONACOt   SUBLANG_GERMANt   SUBLANG_GERMAN_SWISSt   SUBLANG_GERMAN_AUSTRIANt   SUBLANG_GERMAN_LUXEMBOURGt   SUBLANG_GERMAN_LIECHTENSTEINt   SUBLANG_ITALIANt   SUBLANG_ITALIAN_SWISSt   SUBLANG_KASHMIRI_SASIAt   SUBLANG_KASHMIRI_INDIAt   SUBLANG_KOREANt   SUBLANG_LITHUANIANt   SUBLANG_MALAY_MALAYSIAt   SUBLANG_MALAY_BRUNEI_DARUSSALAMt   SUBLANG_NEPALI_INDIAt   SUBLANG_NORWEGIAN_BOKMALt   SUBLANG_NORWEGIAN_NYNORSKt   SUBLANG_PORTUGUESEt   SUBLANG_PORTUGUESE_BRAZILIANt   SUBLANG_SERBIAN_LATINt   SUBLANG_SERBIAN_CYRILLICt   SUBLANG_SPANISHt   SUBLANG_SPANISH_MEXICANt   SUBLANG_SPANISH_MODERNt   SUBLANG_SPANISH_GUATEMALAt   SUBLANG_SPANISH_COSTA_RICAt   SUBLANG_SPANISH_PANAMAt"   SUBLANG_SPANISH_DOMINICAN_REPUBLICt   SUBLANG_SPANISH_VENEZUELAt   SUBLANG_SPANISH_COLOMBIAt   SUBLANG_SPANISH_PERUt   SUBLANG_SPANISH_ARGENTINAt   SUBLANG_SPANISH_ECUADORt   SUBLANG_SPANISH_CHILEt   SUBLANG_SPANISH_URUGUAYt   SUBLANG_SPANISH_PARAGUAYt   SUBLANG_SPANISH_BOLIVIAt   SUBLANG_SPANISH_EL_SALVADORt   SUBLANG_SPANISH_HONDURASt   SUBLANG_SPANISH_NICARAGUAt   SUBLANG_SPANISH_PUERTO_RICOt   SUBLANG_SWEDISHt   SUBLANG_SWEDISH_FINLANDt   SUBLANG_URDU_PAKISTANt   SUBLANG_URDU_INDIAt   SUBLANG_UZBEK_LATINt   SUBLANG_UZBEK_CYRILLICt   SUBLANG_DUTCH_SURINAMt   SUBLANG_ROMANIANt   SUBLANG_ROMANIAN_MOLDAVIAt   SUBLANG_RUSSIANt   SUBLANG_RUSSIAN_MOLDAVIAt   SUBLANG_CROATIANt   SUBLANG_LITHUANIAN_CLASSICt   SUBLANG_GAELICt   SUBLANG_GAELIC_SCOTTISHt   SUBLANG_GAELIC_MANXc         C   sY   t  j |  d  } x- t j | t    D] } | | k r( | Sq( Wt j | d g  d S(   Ns	   *unknown*i    (   t   LANGt   gett   SUBLANGR    (   t
   lang_valuet   sublang_valuet	   lang_namet   sublang_name(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   get_sublang_name_for_lang   s
    c         C   s  d } d } x | t  |   k  r|  | | d !} t  |  d k  rH Pn  t j d |  d } | d 7} | d k r d | d k o t  |   k n r y& |  | | | d !j d  | | <Wn t k
 r | d 7} n X| d k r Pn  | | d 7} n  | d 7} q Wd  S(   Ni    i   s   <hs   utf-16i   i   (   R   t   structt   unpackt   decodet   UnicodeDecodeError(   t   datat   countert   lt   it   error_countt
   data_slicet   len_(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   parse_strings  s$    
2&
c         C   sQ   g  |  j    D]@ } t | d t  r | d j |  r | d | d f ^ q S(   s   Read 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".
    i    i   (   t   itemst
   isinstancet   strt
   startswith(   t	   flag_dictt   flag_filtert   f(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   retrieve_flags$  s    c         C   sH   xA | D]9 } | d | @r/ t  |  j | d <q t |  j | d <q Wd S(   s
  Will 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.
    i   i    N(   t   Truet   __dict__t   False(   t   objt
   flag_fieldt   flagst   flag(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt	   set_flags/  s    c         C   s   |  S(   N(    (   t   valt   file_aligment(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   adjust_FileAlignmentL  s    c         C   s5   | d k  r | } n  | r1 |  | r1 | |  | S|  S(   Ni   (    (   R  t   section_alignmentR  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   adjust_SectionAlignmentY  s
    	t!   UnicodeStringWrapperPostProcessorc           B   sh   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z RS(   s   This 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         C   s   | |  _  | |  _ d  |  _ d  S(   N(   t   pet   rva_ptrt   Nonet   string(   t   selfR  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   __init__o  s    		c         C   s   |  j  S(   s   Get the RVA of the string.(   R  (   R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   get_rvau  s    c         C   s?   d   } |  j  r; d j g  |  j  D] } | |  ^ q"  Sd S(   s6   Return the escaped ASCII representation of the string.c         S   s%   |  t  j k r |  Sd t |   Sd  S(   Ns   \x%02x(   R  t	   printablet   ord(   t   char(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   convert_char~  s    t    (   R  t   join(   R  R  t   c(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   __str__{  s    		)c         C   s
   d }  d S(   s>   Make this instance None, to express it's no known string type.N(   R  (   R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt
   invalidate  s    c         C   s,   |  j  j |  j d d |  j   |  _ d  S(   Ni   t
   max_length(   R  t   get_string_u_at_rvaR  t8   _UnicodeStringWrapperPostProcessor__get_pascal_16_lengthR  (   R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   render_pascal_16  s    	c         C   s8   |  j    } | | |  j d d k r4 | |  _ t St S(   s   The 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
        with the possible length contained in the first word.
        i   (   R  R  t   lengthR  R  (   R  t   next_rva_ptrR  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   ask_pascal_16  s
    	c         C   s   |  j  |  j  S(   N(   t9   _UnicodeStringWrapperPostProcessor__get_word_value_at_rvaR  (   R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   __get_pascal_16_length  s    c         C   s]   y |  j  j |  j d  } Wn t k
 r2 } t SXt |  d k  rI t St j d |  d S(   Ni   s   <Hi    (   R  t   get_dataR  t   PEFormatErrorR  R   Rp  Rq  (   R  t   rvaRt  t   e(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   __get_word_value_at_rva  s    c         C   s1   |  j  | d  d k r- | |  j |  _ t St S(   s   The 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.
        i   i    (   R  R  R  R  R  (   R  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   ask_unicode_16  s    c         C   s   |  j  j |  j  |  _ d S(   R  N(   R  R  R  R  (   R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   render_unicode_16  s    (   t   __name__t
   __module__t   __doc__R  R  R  R  R  R  R  R  R  R  (    (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR  i  s   									R  c           B   s    e  Z d  Z d   Z d   Z RS(   s"   Generic PE format error exception.c         C   s   | |  _  d  S(   N(   t   value(   R  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR    s    c         C   s   t  |  j  S(   N(   t   reprR  (   R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR    s    (   R  R  R  R  R  (    (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR    s   	t   Dumpc           B   sV   e  Z d  Z d   Z d d  Z d d  Z d d  Z d   Z d   Z d   Z	 RS(	   s1   Convenience class for dumping the PE information.c         C   s   t    |  _ d  S(   N(   R    t   text(   R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR    s    i    c         C   s%   x | D] } |  j  | |  q Wd S(   sm   Adds a list of lines.
        
        The list can be indented with the optional argument 'indent'.
        N(   t   add_line(   R  t   txtt   indentt   line(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt	   add_lines  s    c         C   s   |  j  | d |  d S(   sd   Adds a line.
        
        The line can be indented with the optional argument 'indent'.
        s   
N(   t   add(   R  R  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR    s    c         C   s   t  | t  r y t |  } Wq t k
 r g  } xL | D]D } y | j t |   Wq< t k
 r | j t |   q< Xq< Wd j |  } q Xn  |  j j d | |  d S(   s   Adds some text, no newline will be appended.
        
        The text can be indented with the optional argument 'indent'.
        R  t    N(   R}  t   unicodeR~  t   UnicodeEncodeErrort   appendR  R  R  (   R  R  R  t   sR  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR    s    c         C   s   |  j  d | d d  d S(   s   Adds a header element.t   -i
   s   
Ns
   ----------s
   ----------(   R  (   R  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt
   add_header
  s    c         C   s   |  j  j d  d S(   s   Adds a newline.s   
N(   R  R  (   R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   add_newline  s    c         C   s   d j  |  j  S(   s"   Get the text in its current state.R  (   R  R  (   R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   get_text  s    (
   R  R  R  R  R  R  R  R  R  R  (    (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR    s   					t   xR  t   bt   Bt   ht   HRw  t   IRv  R   R  t   qt   Qt   dR  t	   Structurec           B   s   e  Z d  Z d d d  Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z d d  Z RS(   s   Prepare structure object to extract members from data.
    
    Format is a list containing definitions for the elements
    of the structure.
    c         C   sv   d |  _  g  |  _ d |  _ t   |  _ |  j | d  t |  _ d  |  _	 | |  _
 | re | |  _ n | d |  _ d  S(   Nt   <i    i   (   t
   __format__t   __keys__t   __format_length__t   dictt   __field_offsets__t   __set_format__R  t   __all_zeroes__R  t   __unpacked_data_elms__t   __file_offset__t   name(   R  t   formatR  t   file_offset(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR  +  s    						c         C   s   |  j  S(   N(   R  (   R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   __get_format__<  s    c         C   s   |  j  |  j | S(   sL   Return the offset within the field for the requested field in the structure.(   R  R  (   R  t
   field_name(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   get_field_absolute_offset?  s    c         C   s   |  j  | S(   s?   Return the offset within the structure for the requested field.(   R  (   R  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   get_field_relative_offsetC  s    c         C   s   |  j  S(   N(   R  (   R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   get_file_offsetG  s    c         C   s   | |  _  d  S(   N(   R  (   R  t   offset(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   set_file_offsetJ  s    c         C   s   |  j  S(   s0   Returns true is the unpacked data is all zeroes.(   R  (   R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt
   all_zeroesM  s    c         C   s   d } | } | d t  j k r t d j g  | D] } | t  j k r/ | ^ q/   } d j g  | D] } | t  j k rc | ^ qc  } n  t | | S(   Ni   i    R  (   R  t   digitst   intR  t   STRUCT_SIZEOF_TYPES(   R  t   tt   countt   _tR  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   sizeof_typeR  s    74c         C   s$  d } x| D] } d | k r | j  d d  \ } } |  j | 7_ | j  d  } g  } x | D]{ } | |  j k r g  |  j D] } | t |   ^ q }	 |	 j |  }
 | d t |
  } n  | j |  | |  j | <qb W| |  j |  7} |  j j |  q q Wt	 j
 |  j  |  _ d  S(   Ni    t   ,i   t   _(   t   splitR  R  R   R  R~  R  R  R  Rp  t   calcsizeR  (   R  R  R  t   elmt   elm_typet   elm_namet	   elm_namest   namesR  t   search_listt	   occ_count(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR  [  s"    &c         C   s   |  j  S(   s   Return size of the structure.(   R  (   R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   sizeofw  s    c         C   s   t  |  |  j k r% | |  j  } n$ t  |  |  j k  rI t d   n  | j t d   t  |  k rv t |  _ n  t j |  j	 |  |  _
 xL t t  |  j
   D]5 } x, |  j | D] } t |  | |  j
 |  q Wq Wd  S(   Ns-   Data length less than expected header length.i    (   R   R  R  R  t   chrR  R  Rp  Rq  R  R  t   xrangeR  t   setattr(   R  Rt  Rw  t   key(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt
   __unpack__}  s    !c         C   s   g  } xn t  t |  j   D]W } xA |  j | D]2 } t |  |  } |  j | } | | k r0 Pq0 q0 W| j |  q Wt j |  j |  S(   N(	   R  R   R  R  t   getattrR  Rp  t   packR  (   R  t
   new_valuesRw  R  t   new_valt   old_val(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   __pack__  s    c         C   s   d j  |  j    S(   Ns   
(   R  t   dump(   R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR    s    c         C   s9   d d j  g  |  j   D] } d j  | j    ^ q  S(   Ns   <Structure: %s>R  (   R  R  R  (   R  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   __repr__  s    i    c      
   C   s6  g  } | j  d |  j  x|  j D]
} x| D] } t |  |  } t | t  sd t | t  r d | } | d k s | d k r y$ | d t j t j	 |   7} Wq t
 j k
 r } | d 7} q Xq n! d j t d   t |    } | j  d	 |  j | |  j |  j | | d
 | f  q1 Wq$ W| S(   s1   Returns a string representation of the structure.s   [%s]s   0x%-8Xt   TimeDateStampt   dwTimeStamps	    [%s UTC]s    [INVALID TIME]R  c         S   s
   |  d k S(   Nt    (    (   R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   <lambda>  s    s   0x%-8X 0x%-3X %-30s %st   :(   R  R  R  R  R}  R  t   longt   timet   asctimet   gmtimet
   exceptionst
   ValueErrorR  t   filterR~  R  R  (   R  t   indentationR  t   keysR  R  t   val_strR  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR    s"    
$!	$N(   R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  (    (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR  #  s    														t   SectionStructurec           B   s   e  Z d  Z d   Z d d d  Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z RS(   s#   Convenience section handling class.c         O   s:   d | k r# | d |  _  | d =n  t j |  | |  d  S(   NR  (   R  R  R  (   R  t   arglt   argd(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR    s    
c         C   s   t  |  j |  j j j  } t |  j |  j j j |  j j j  } | d k rW | } n | | | } | d k	 r~ | | } n | |  j	 } | |  j |  j	 k r |  j |  j	 } n  |  j j
 | | !S(   s  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 its real
        addresses as it would be if loaded.
        N(   R  t   PointerToRawDataR  t   OPTIONAL_HEADERt   FileAlignmentR  t   VirtualAddresst   SectionAlignmentR  t   SizeOfRawDatat   __data__(   R  t   startR  t   PointerToRawData_adjt   VirtualAddress_adjR  t   end(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR    s    				c         C   s   | d k r. t  t d  } t |  | |  nU d | k r t |  |  r | ri |  j d c t | O<q |  j d c t | N<n  | |  j | <d  S(   Nt   Characteristicst
   IMAGE_SCN_(   R  t   SECTION_CHARACTERISTICSR  t   hasattrR  (   R  R  R  t   section_flags(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   __setattr__  s    c         C   sB   | t  |  j |  j j j  t |  j |  j j j |  j j j  S(   N(   R  R  R  R  R  R  R  R  (   R  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   get_rva_from_offset  s    %c         C   sB   | t  |  j |  j j j |  j j j  t |  j |  j j j  S(   N(   R  R  R  R  R  R  R  R  (   R  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   get_offset_from_rva  s    c         C   s\   |  j  d k r t St |  j  |  j j j  | k oY t |  j  |  j j j  |  j k  SS(   s<   Check whether the section contains the file offset provided.N(   R  R  R  R  R  R  R  R  (   R  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   contains_offset  s    		c         C   s   t  |  j j  t |  j |  j j j  |  j k  r@ |  j } n t	 |  j |  j  } t
 |  j |  j j j |  j j j  } | | k o | | k  SS(   s8   Check whether the section contains the address provided.(   R   R  R  R  R  R  R  R  t   Misc_VirtualSizet   maxR  R  R  (   R  R  t   sizeR"  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   contains_rva+  s    	c         C   s   |  j  |  S(   N(   R0  (   R  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   containsE  s    c         C   s   |  j  |  j    S(   s1   Calculate and return the entropy for the section.(   t	   entropy_HR  (   R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   get_entropyP  s    c         C   s&   t  d k	 r" t  |  j    j   Sd S(   s/   Get the SHA-1 hex-digest of the section's data.N(   t   sha1R  R  t	   hexdigest(   R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   get_hash_sha1V  s    c         C   s&   t  d k	 r" t  |  j    j   Sd S(   s1   Get the SHA-256 hex-digest of the section's data.N(   t   sha256R  R  R5  (   R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   get_hash_sha256]  s    c         C   s&   t  d k	 r" t  |  j    j   Sd S(   s1   Get the SHA-512 hex-digest of the section's data.N(   t   sha512R  R  R5  (   R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   get_hash_sha512d  s    c         C   s&   t  d k	 r" t  |  j    j   Sd S(   s-   Get the MD5 hex-digest of the section's data.N(   t   md5R  R  R5  (   R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   get_hash_md5k  s    c         C   s   t  |  d k r d St j d d g d  } x$ | D] } | t |  c d 7<q6 Wd } xG | D]? } | rc t |  t  |  } | | t j | d  8} qc qc W| S(   s)   Calculate the entropy of a chunk of data.i    g        R   i   i   i   (   R   t   arrayR  t   floatt   matht   log(   R  Rt  t
   occurencesR  t   entropyt   p_x(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR2  r  s    !N(   R  R  R  R  R  R  R)  R*  R+  R,  R0  R1  R3  R6  R8  R:  R<  R2  (    (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR    s   	!											t   DataContainerc           B   s   e  Z d  Z d   Z RS(   s   Generic data container.c         K   s1   x* | j    D] \ } } t |  | |  q Wd  S(   N(   R|  R  (   R  t   argsR  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR    s    (   R  R  R  R  (    (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyRD    s   t   ImportDescDatac           B   s   e  Z d  Z RS(   s   Holds import descriptor information.
    
    dll:        name of the imported DLL
    imports:    list of imported symbols (ImportData instances)
    struct:     IMAGE_IMPORT_DESCRIPTOR structure
    (   R  R  R  (    (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyRF    s   t
   ImportDatac           B   s   e  Z d  Z d   Z RS(   s   Holds 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         C   s  t  |  d  rt  |  d  rt  |  d  r| d k r |  j j t k rT t } n |  j j t k ro t } n  | | d @B|  j _ |  j j |  j _	 |  j j |  j _
 |  j j |  j _ q| d k r|  j d  k	 r| |  j _	 |  j j	 |  j _	 |  j j	 |  j _
 |  j j	 |  j _ qq| d k rp| |  j _	 |  j j	 |  j _ |  j j	 |  j _
 |  j j	 |  j _ q| d k r|  j r|  j j |  j  } |  j j |  j d | B t |  t |  j  k rn  |  j j |  j |  qqn  | |  j | <d  S(	   Nt   ordinalt   boundR  i  t   addressi    i   i    (   R'  R  t   PE_TYPEt   OPTIONAL_HEADER_MAGIC_PEt   IMAGE_ORDINAL_FLAGt   OPTIONAL_HEADER_MAGIC_PE_PLUSt   IMAGE_ORDINAL_FLAG64t   struct_tablet   Ordinalt   AddressOfDatat   Functiont   ForwarderStringt
   struct_iatR  t   name_offsetR*  t   set_dword_at_offsett   ordinal_offsetR   R  t   set_bytes_at_offsetR  (   R  R  R  t   ordinal_flagt   name_rva(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR)    s:    -			(   R  R  R  R)  (    (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyRG    s   t   ExportDirDatac           B   s   e  Z d  Z RS(   s   Holds export directory information.
    
    struct:     IMAGE_EXPORT_DIRECTORY structure
    symbols:    list of exported symbols (ExportData instances)
(   R  R  R  (    (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR\    s   t
   ExportDatac           B   s   e  Z d  Z d   Z RS(   sh  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         C   s   t  |  d  rt  |  d  rt  |  d  rt  |  d  r| d k ra |  j j |  j |  q| d k r |  j j |  j |  q| d k r t |  t |  j  k r n  |  j j |  j	 |  q| d k rt |  t |  j
  k r n  |  j j |  j |  qn  | |  j | <d  S(   NRH  RJ  t	   forwarderR  (   R'  R  t   set_word_at_offsetRX  RW  t   address_offsetR   R  RY  RV  R^  t   forwarder_offsetR  (   R  R  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR)    s    <(   R  R  R  R)  (    (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR]    s   
t   ResourceDirDatac           B   s   e  Z d  Z RS(   s   Holds resource directory information.
    
    struct:     IMAGE_RESOURCE_DIRECTORY structure
    entries:    list of entries (ResourceDirEntryData instances)
    (   R  R  R  (    (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyRb     s   t   ResourceDirEntryDatac           B   s   e  Z d  Z RS(   sJ  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.)
    (   R  R  R  (    (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyRc    s   t   ResourceDataEntryDatac           B   s   e  Z d  Z RS(   s   Holds resource data entry information.
    
    struct:     IMAGE_RESOURCE_DATA_ENTRY structure
    lang:       Primary language ID
    sublang:    Sublanguage ID
    (   R  R  R  (    (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyRd    s   t	   DebugDatac           B   s   e  Z d  Z RS(   sR   Holds debug information.
    
    struct:     IMAGE_DEBUG_DIRECTORY structure
    (   R  R  R  (    (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyRe  #  s   t   BaseRelocationDatac           B   s   e  Z d  Z RS(   s   Holds base relocation information.
    
    struct:     IMAGE_BASE_RELOCATION structure
    entries:    list of relocation data (RelocationData instances)
    (   R  R  R  (    (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyRf  )  s   t   RelocationDatac           B   s   e  Z d  Z d   Z RS(   s   Holds relocation information.
    
    type:       Type of relocation
                The type string is can be obtained by
                RELOCATION_TYPE[type]
    rva:        RVA of the relocation
    c         C   s   t  |  d  r |  j j } | d k r< | d >| d @B} nC | d k r | |  j } | d k  rj d } n  | d @| d @B} n  | |  j _ n  | |  j | <d  S(   NRp  t   typei   i  R  i    i   (   R'  Rp  t   Datat   base_rvaR  (   R  R  R  t   wordR  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR)  8  s    	(   R  R  R  R)  (    (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyRg  0  s   t   TlsDatac           B   s   e  Z d  Z RS(   sN   Holds TLS information.
    
    struct:     IMAGE_TLS_DIRECTORY structure
    (   R  R  R  (    (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyRl  Q  s   t   BoundImportDescDatac           B   s   e  Z d  Z RS(   s  Holds bound import descriptor data.
    
    This directory entry will provide with information on the
    DLLs this PE files 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.
    (   R  R  R  (    (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyRm  W  s   t   LoadConfigDatac           B   s   e  Z d  Z RS(   sp   Holds Load Config data.
    
    struct:     IMAGE_LOAD_CONFIG_DIRECTORY structure
    name:       dll name
    (   R  R  R  (    (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyRn  i  s   t   BoundImportRefDatac           B   s   e  Z d  Z RS(   s   Holds 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
    (   R  R  R  (    (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyRo  p  s   s   !#$%&'()-@^_`{}~+,.;=[]R  c         C   sE   |  d  k s t |  t  r  t Sx |  D] } | t k r' t Sq' Wt S(   N(   R  R}  R~  R  t   allowed_filenameR  (   R  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   is_valid_dos_filename  s    s   _?@$()c         C   sE   |  d  k s t |  t  r  t Sx |  D] } | t k r' t Sq' Wt S(   N(   R  R}  R~  R  t   allowed_function_nameR  (   R  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   is_valid_function_name  s    t   PEc           B   s  e  Z d  Z d d d d d d d d d	 d
 d d d d d d d d d d f f Z d d d d d d d d f f Z d d d f f Z d  d! d" d# d$ d% d& d' d( d) d* d+ d, d- d. d/ d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 d: d; d< d= d> f f Z d? d! d" d# d$ d% d& d' d( d@ d+ d, d- d. d/ d0 d1 d2 d3 d4 d5 d6 d7 d8 dA dB dC dD d= d> f f Z dE dF f f Z dG dH dI d dJ dK dL dM dN dO dP f
 f Z	 dQ dR dS dT dU dV dW dX dY f f Z
 dZ d[ d d\ d] d^ f f Z d_ dP d d` da d] db dc dd de df dg f f Z dh dP d d` da di dj f f Z dk d] dl f f Z dm dl d dn do f f Z dp dq dr ds f f Z dt dF du dv dw dx dy dz d{ d| d} d~ d d f f Z d dq dr ds f f Z d dq dr ds f f Z d dq dr ds f f Z d dq dr ds f f Z d d f f Z d d f f Z d dP d d` da d d d dK f f Z d d d f f Z d d f f Z d d d d d d dP f f Z d d d d d d dP f f Z d d d d` da d d d d d d d d d d d d d d d d f f Z d d d d` da d d d d d d d d d d d d d d d d f f Z d d d d f f Z d d d d f f Z  e! e! e! d  Z" d   Z# d   Z$ d   Z% d   Z& d   Z' d   Z( e! d  Z) d   Z* e! d  Z+ d   Z, d   Z- d   Z. d   Z/ d   Z0 d   Z1 d e! d e! d  Z2 d   Z3 d   Z4 d   Z5 d   Z6 d   Z7 d   Z8 d   Z9 d   Z: d   Z; d e! d  Z< d   Z= d e! d  Z> d   Z? d   Z@ d   ZA d   ZB d d d  ZC d   ZD d   ZE d   ZF d   ZG e! d  ZH d   ZI d   ZJ d   ZK d   ZL d   ZM d   ZN d   ZO d   ZP d   ZQ d   ZR d   ZS d   ZT d   ZU d   ZV d   ZW d   ZX d   ZY d   ZZ d   Z[ d   Z\ d   Z] d   Z^ d   Z_ d   Z` d   Za d   Zb d   Zc d   Zd d  Ze d  Zf d  Zg RS(  s	  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 would be already
    available in a buffer the same could 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
    t   IMAGE_DOS_HEADERs	   H,e_magics   H,e_cblps   H,e_cps   H,e_crlcs   H,e_cparhdrs   H,e_minallocs   H,e_maxallocs   H,e_sss   H,e_sps   H,e_csums   H,e_ips   H,e_css
   H,e_lfarlcs   H,e_ovnos   8s,e_ress	   H,e_oemids   H,e_oeminfos
   20s,e_res2s
   I,e_lfanewt   IMAGE_FILE_HEADERs	   H,Machines   H,NumberOfSectionss   I,TimeDateStamps   I,PointerToSymbolTables   I,NumberOfSymbolss   H,SizeOfOptionalHeaders   H,Characteristicst   IMAGE_DATA_DIRECTORYs   I,VirtualAddresss   I,Sizet   IMAGE_OPTIONAL_HEADERs   H,Magics   B,MajorLinkerVersions   B,MinorLinkerVersions   I,SizeOfCodes   I,SizeOfInitializedDatas   I,SizeOfUninitializedDatas   I,AddressOfEntryPoints   I,BaseOfCodes   I,BaseOfDatas   I,ImageBases   I,SectionAlignments   I,FileAlignments   H,MajorOperatingSystemVersions   H,MinorOperatingSystemVersions   H,MajorImageVersions   H,MinorImageVersions   H,MajorSubsystemVersions   H,MinorSubsystemVersions   I,Reserved1s   I,SizeOfImages   I,SizeOfHeaderss
   I,CheckSums   H,Subsystems   H,DllCharacteristicss   I,SizeOfStackReserves   I,SizeOfStackCommits   I,SizeOfHeapReserves   I,SizeOfHeapCommits   I,LoaderFlagss   I,NumberOfRvaAndSizest   IMAGE_OPTIONAL_HEADER64s   Q,ImageBases   Q,SizeOfStackReserves   Q,SizeOfStackCommits   Q,SizeOfHeapReserves   Q,SizeOfHeapCommitt   IMAGE_NT_HEADERSs   I,Signaturet   IMAGE_SECTION_HEADERs   8s,Names,   I,Misc,Misc_PhysicalAddress,Misc_VirtualSizes   I,SizeOfRawDatas   I,PointerToRawDatas   I,PointerToRelocationss   I,PointerToLinenumberss   H,NumberOfRelocationss   H,NumberOfLinenumberss   I,Characteristicst   IMAGE_DELAY_IMPORT_DESCRIPTORs	   I,grAttrss   I,szNames   I,phmods   I,pIATs   I,pINTs   I,pBoundIATs   I,pUnloadIATs   I,dwTimeStampt   IMAGE_IMPORT_DESCRIPTORs$   I,OriginalFirstThunk,Characteristicss   I,ForwarderChains   I,Names   I,FirstThunkt   IMAGE_EXPORT_DIRECTORYs   H,MajorVersions   H,MinorVersions   I,Bases   I,NumberOfFunctionss   I,NumberOfNamess   I,AddressOfFunctionss   I,AddressOfNamess   I,AddressOfNameOrdinalst   IMAGE_RESOURCE_DIRECTORYs   H,NumberOfNamedEntriess   H,NumberOfIdEntriest   IMAGE_RESOURCE_DIRECTORY_ENTRYs   I,OffsetToDatat   IMAGE_RESOURCE_DATA_ENTRYs
   I,CodePages
   I,Reservedt   VS_VERSIONINFOs   H,Lengths   H,ValueLengths   H,Typet   VS_FIXEDFILEINFOs   I,StrucVersions   I,FileVersionMSs   I,FileVersionLSs   I,ProductVersionMSs   I,ProductVersionLSs   I,FileFlagsMasks   I,FileFlagss   I,FileOSs
   I,FileTypes   I,FileSubtypes   I,FileDateMSs   I,FileDateLSt   StringFileInfot   StringTablet   Stringt   Vart   IMAGE_THUNK_DATAs0   I,ForwarderString,Function,Ordinal,AddressOfDatas0   Q,ForwarderString,Function,Ordinal,AddressOfDatat   IMAGE_DEBUG_DIRECTORYs   I,Types   I,SizeOfDatas   I,AddressOfRawDatat   IMAGE_BASE_RELOCATIONs   I,SizeOfBlockt   IMAGE_BASE_RELOCATION_ENTRYs   H,Datat   IMAGE_TLS_DIRECTORYs   I,StartAddressOfRawDatas   I,EndAddressOfRawDatas   I,AddressOfIndexs   I,AddressOfCallBackss   I,SizeOfZeroFills   Q,StartAddressOfRawDatas   Q,EndAddressOfRawDatas   Q,AddressOfIndexs   Q,AddressOfCallBackst   IMAGE_LOAD_CONFIG_DIRECTORYs   I,GlobalFlagsClears   I,GlobalFlagsSets   I,CriticalSectionDefaultTimeouts   I,DeCommitFreeBlockThresholds   I,DeCommitTotalFreeThresholds   I,LockPrefixTables   I,MaximumAllocationSizes   I,VirtualMemoryThresholds   I,ProcessHeapFlagss   I,ProcessAffinityMasks   H,CSDVersions   H,Reserved1s
   I,EditLists   I,SecurityCookies   I,SEHandlerTables   I,SEHandlerCounts   Q,DeCommitFreeBlockThresholds   Q,DeCommitTotalFreeThresholds   Q,LockPrefixTables   Q,MaximumAllocationSizes   Q,VirtualMemoryThresholds   Q,ProcessAffinityMasks
   Q,EditLists   Q,SecurityCookies   Q,SEHandlerTables   Q,SEHandlerCountt   IMAGE_BOUND_IMPORT_DESCRIPTORs   H,OffsetModuleNames   H,NumberOfModuleForwarderRefst   IMAGE_BOUND_FORWARDER_REFs
   H,Reservedc         C   sc   g  |  _  g  |  _ d  |  _ | r- | r- d  Sg  |  _ | sL t   d } n  |  j | | |  d  S(   Nt	   fast_load(   t   sectionst   _PE__warningsR  RK  t   __structures__t   globalst	   __parse__(   R  R  Rt  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR    s    				c         C   su   t  | d | } y | j |  Wn; t k
 r` } |  j j d | d | t |  f  d SX|  j j |  | S(   s   Apply structure format to raw data.
        
        Returns and unpacked structure object if successful, None otherwise.
        R  s4   Corrupt header "%s" at file offset %d. Exception: %si    N(   R  R  R  R  R  R~  R  R  (   R  R  Rt  R  t	   structuret   err(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   __unpack_data__  s    	c         C   s  | rR t  | d  } | j   |  _ t j |  j d d t j |  _ | j   n | rd | |  _ n  |  j d  } t |  d k r t d   n  |  j |  j	 | d d |  _
 |  j
 j t k r t d   n  |  j
 s |  j
 j t k r t d   n  |  j
 j t |  j  k r&t d	   n  |  j
 j } |  j |  j |  j | | d
 !d | |  _ |  j su|  j j rt d   n  d |  j j @t k rt d   n  d |  j j @t k rt d   n  d |  j j @t k rt d   n  |  j j t k rt d   n  |  j |  j |  j | d | d d !d | d |  _ t t d  } |  j sst d   n  t |  j |  j j |  | d |  j j   } | |  j j }	 |  j |  j |  j | d | |  _ d }
 |  j d' k rPt |  j | | d ! |
 k rPd } |  j | | d !d | } |  j |  j | d | |  _ n  |  j d' k	 rB|  j j! t" k r}t" |  _# qB|  j j! t$ k rBt$ |  _# |  j |  j% |  j | | d !d | |  _ d( }
 |  j d' k r?t |  j | | d ! |
 k r?d } |  j | | d !d | } |  j |  j% | d | |  _ q?qBn  |  j sZt d   n  |  j# d' k sx|  j d' k rt d   n  t t& d  } t |  j |  j j' |  g  |  j _( | |  j j   } |  j |  j _ |  j |  j _ |  j j) d k r|  j* j+ d d |  j j)  n  d } xt, t- d |  j j) @  D] } t |  j  | d k rePn  t |  j  | d
 k  r|  j | d) } n |  j | | | !} |  j |  j. | d | } | d' k rPn  y t/ | | _0 Wn t1 t2 f k
 rPn X| | j   7} |  j j( j+ |  | | |  j j   d* k rBPqBqBW|  j3 |	  } g  |  j4 D]- } | j5 d k r^t6 | j5 |  j j7  ^ q^} t |  d k rt8 |  } n d' } | s| | k  r|  j |  |  _9 n |  j |  |  _9 |  j: |  j j;  d' k	 rW|  j< |  j j;  } | t |  j  k ru|  j* j+ d  d! |  j j;  qun |  j* j+ d" d! |  j j;  | s|  j=   d# d+ d$     Y} |  j>   } | r|   |  _? | j@ d% d'  |  j? _A | j@ d& d'  |  j? _B qd' |  _? n  d' S(,   s   Parse a Portable Executable file.
        
        Loads a PE file, parsing all its structures and making them available
        through the instance's attributes.
        t   rbi    t   accessi@   s9   Unable to read the DOS Header, possibly a truncated file.R  s)   Probably a ZM Executable (not a PE file).s   DOS Header magic not found.s.   Invalid e_lfanew value, probably not a PE filei   s   NT Headers not found.i  s0   Invalid NT Headers signature. Probably a NE files0   Invalid NT Headers signature. Probably a LE files0   Invalid NT Headers signature. Probably a LX files   Invalid NT Headers signature.i   i    t   IMAGE_FILE_s   File Header missingiE   i   i   R	  s4   No Optional Header found, invalid PE32 or PE32+ filet   IMAGE_DLL_CHARACTERISTICS_i   s7   Suspicious NumberOfRvaAndSizes in the Optional Header. s<   Normal values are never larger than 0x10, the value is: 0x%xi   l    sB   Possibly corrupt file. AddressOfEntryPoint lies outside the file. s   AddressOfEntryPoint: 0x%xs;   AddressOfEntryPoint lies outside the sections' boundaries. t
   RichHeaderc           B   s   e  Z RS(    (   R  R  (    (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR    s   t   checksumt   valuesNiI   t           i   (    (C   t   filet   filenot   mmapt   ACCESS_READR  t   closeR   R  R  t   __IMAGE_DOS_HEADER_format__t
   DOS_HEADERt   e_magict   IMAGE_DOSZM_SIGNATUREt   IMAGE_DOS_SIGNATUREt   e_lfanewt   __IMAGE_NT_HEADERS_format__t
   NT_HEADERSt	   Signaturet   IMAGE_NE_SIGNATUREt   IMAGE_LE_SIGNATUREt   IMAGE_LX_SIGNATUREt   IMAGE_NT_SIGNATUREt   __IMAGE_FILE_HEADER_format__t   FILE_HEADERR  t   IMAGE_CHARACTERISTICSR  R$  R  t   SizeOfOptionalHeadert    __IMAGE_OPTIONAL_HEADER_format__R  R  t   MagicRL  RK  RN  t"   __IMAGE_OPTIONAL_HEADER64_format__t   DLL_CHARACTERISTICSt   DllCharacteristicst   DATA_DIRECTORYt   NumberOfRvaAndSizesR  R  R  R  t   __IMAGE_DATA_DIRECTORY_format__t   DIRECTORY_ENTRYR  t   KeyErrort   AttributeErrort   parse_sectionsR  R  R  R  t   mint   headert   get_section_by_rvat   AddressOfEntryPointR+  t   parse_data_directoriest   parse_rich_headert   RICH_HEADERRi  R  R  (   R  t   fnameRt  R  t   fdt   dos_header_datat   nt_headers_offsett   image_flagst   optional_header_offsett   sections_offsett&   MINIMUM_VALID_OPTIONAL_HEADER_RAW_SIZEt   padding_lengtht   padded_datat   dll_characteristics_flagsR  t)   MAX_ASSUMED_VALID_NUMBER_OF_RVA_AND_SIZESRw  t	   dir_entryR  t   rawDataPointerst   lowest_section_offsett	   ep_offsetR  t   rich_header(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR    s(   !							#	
:		
c         C   s<  d } d } y( t  t j d |  j d d    } Wn d SX| d } | d | A| k s} | d | k s} | d | k r d Si | d	 6} g  } | | d
 <| d } x t t |  d  D]u } | d | | k r| d | d | k r|  j j d  n  Pn  | | d | | A| d | d | Ag 7} q W| S(   s*  Parses the rich header
        see http://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   <32Ii   i   i    i   i   R  R  i   s   Rich Header corruptedN(	   R    Rp  Rq  R  R  R  R   R  R  (   R  t   DANSt   RICHRt  R  t   resultt   headervaluesRw  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR    s,    (


0c         C   s   |  j  S(   s   Return 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  (   R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   get_warnings  s    c         C   s!   x |  j  D] } d G| GHq
 Wd S(   s   Print 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.
        t   >N(   R  (   R  t   warning(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   show_warnings  s    c         C   s   |  j    d S(   s   Process the data directories.
        
        This method will load the data directories which might not have
        been loaded if the "fast_load" option was used.
        N(   R  (   R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt	   full_load*  s    c      	   C   s"  t  |  j  } xF |  j D]; } t  | j    } | j   } | | | | t |  +q Wt |  d  rt |  d  rxA|  j D]3} t | d  r x| j D]} x| j	 j
   D]\ } } | j | }	 | j | }
 t |  |
 d k rt    } x t |  D]w \ } } t |  d k r_| j t t |  d @ t t |  d @d ? g  q| j t t |   d	 g  qW| | |	 d |	 d |
 d d
 +q t    } x t |  D]w \ } } t |  d k r| j t t |  d @ t t |  d @d ? g  q| j t t |   d	 g  qW| | |	 d |	 d t |  d
 +|
 d t |  } d g | d
 | |	 d t |  d
 |	 d |
 d d
 +q Wq Wq q Wqn  d j g  | D] } t t |   ^ q } | rt | d  } | j |  | j   n | Sd S(   s  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.
        R  t   FileInfoR  i   i   i   i   i   R	  i   u    R  s   wb+N(   R    R  R  R  R  R   R'  R  R  t   entriesR|  t   entries_offsetst   entries_lengthsR   R  t   extendR  R  R  t   writeR  (   R  t   filenamet	   file_dataR  t   struct_dataR  t   entryt   st_entryR  t   offsetst   lengthsRv  t   idxR  t	   remaindert   new_file_dataR  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR  4  sD    	:#$	:##O.c         C   s  g  |  _  x9t |  j j  D]%} t |  j d |  } | sA Pn  | | j   | } | j |  | j |  j	 | | | j   ! |  j
 j |  | j t |  j	  k r |  j j d | d  n  t | j |  j j  t |  j	  k r|  j j d | d  n  | j d k r2|  j j d | d  n  t | j |  j j |  j j  d k rt|  j j d | d  n  |  j j d	 k r| j |  j j d	 k r|  j j d | d
 d d d  n  t t d  } t | | j |  | j j d t  r1| j j d t  r1|  j j d | d d  n  |  j  j |  q W|  j j d	 k r|  j  r| |  j  d	 j   |  j j S| Sd S(   s7  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.
        R  s   Error parsing section %d. s"   SizeOfRawData is larger than file.s3   PointerToRawData points beyond the end of the file.i   s+   Suspicious value found parsing section %d. s(   VirtualSize is extremely large > 256MiB.s$   VirtualAddress is beyond 0x10000000.i    s;   Suspicious value for FileAlignment in the Optional Header. s@   Normally the PointerToRawData entry of the sections' structures s:   is a multiple of FileAlignment, this might imply the file s7   is trying to confuse tools which parse this incorrectlyR%  RI   RG   s%   Suspicious flags set for section %d. s<   Both IMAGE_SCN_MEM_WRITE and IMAGE_SCN_MEM_EXECUTE are set. s(   This might indicate a packed executable.N(   R  R  R  t   NumberOfSectionsR  t   __IMAGE_SECTION_HEADER_format__R  R  R  R  R  R  R  R   R  R  R  R  R  R-  R  R  R  R  R&  R  R$  R  Ri  R  (   R  R  Rw  t   sectiont   section_offsetR(  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR  y  sV    	!								c      
   C   s  d |  j  f d |  j f d |  j f d |  j f d |  j f d |  j f d |  j f d |  j f d	 |  j f f	 } | d k	 r t
 | t t f  s | g } q n  x | D] } y" t | d
 } |  j j | } Wn t k
 r Pn X| d k s | | k rG| j rG| d | j | j  } | rDt |  | d
 d |  qDqGn  | d k	 r t
 | t  r | d
 | k r | j |  q q Wd S(   s  Parse and process the PE file's data directories.
        
        If the optional argument 'directories' is given, only
        the directories at the specified indices 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.
        R   R   R	   R   R   R   R   R   R   i    i   i   N(   t   parse_import_directoryt   parse_export_directoryt   parse_resources_directoryt   parse_debug_directoryt   parse_relocations_directoryt   parse_directory_tlst   parse_directory_load_configt   parse_delay_import_directoryt   parse_directory_bound_importsR  R}  t   tupleR    R  R  R  t
   IndexErrorR  t   SizeR  t   remove(   R  t   directoriest   directory_parsingR  t   directory_indexR  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR    s2    	!+c         C   s  t  |  j  } | j   } | } g  } xt r|  j |  j |  j | | | !d | } | d k ry |  j j d  d S| j	   r Pn  | | j   7} g  } x t
 | j  D] } |  j |  j |  j | | | !d | }	 |	 s t d   n  | |	 j   7} | |	 j }
 |  j d |  j |
 |
 t ! } | s:Pn  | j t d |	 d |   q W| | j }
 |  j d |  j |
 |
 t ! } | sPn  | j t d | d | d |   q* W| S(	   R  R  s7   The Bound Imports directory exists but can't be parsed.Ns(   IMAGE_BOUND_FORWARDER_REF cannot be readi    Rp  R  R  (   R  t(   __IMAGE_BOUND_IMPORT_DESCRIPTOR_format__R  R  R  R  R  R  R  R  R  t   NumberOfModuleForwarderRefst$   __IMAGE_BOUND_FORWARDER_REF_format__R  t   OffsetModuleNamet   get_string_from_datat   MAX_STRING_LENGTHRo  Rm  (   R  R  R/  t	   bnd_descrt   bnd_descr_sizeR   t   bound_importst   forwarder_refsR  t   bnd_frwd_refR  t   name_str(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR   	  sZ    				c         C   s   |  j  t k r |  j } n |  j  t k r6 |  j } n  y= |  j | |  j | t |  j    d |  j	 |  } Wn/ t
 k
 r |  j j d d |  d } n X| s d St d |  S(   R  R  s$   Invalid TLS information. Can't read s   data at RVA: 0x%xRp  N(   RK  RL  t   __IMAGE_TLS_DIRECTORY_format__RN  t    __IMAGE_TLS_DIRECTORY64_format__R  R  R  R  R+  R  R  R  R  Rl  (   R  R  R/  R  t
   tls_struct(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR  W	  s"    	
c         C   s   |  j  t k r |  j } n |  j  t k r6 |  j } n  y= |  j | |  j | t |  j    d |  j	 |  } Wn/ t
 k
 r |  j j d d |  d } n X| s d St d |  S(   R  R  s,   Invalid LOAD_CONFIG information. Can't read s   data at RVA: 0x%xRp  N(   RK  RL  t&   __IMAGE_LOAD_CONFIG_DIRECTORY_format__RN  t(   __IMAGE_LOAD_CONFIG_DIRECTORY64_format__R  R  R  R  R+  R  R  R  R  Rn  (   R  R  R/  R  t   load_config_struct(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR  q	  s"    	
c         C   s  t  |  j  j   } | | } g  } x | | k  r y4 |  j |  j |  j | |  d |  j |  } Wn/ t k
 r |  j j d d |  d } n X| s Pn  |  j
 | | | j | j |  } | j t d | d |   | j s Pn  | | j 7} q( W| S(   R  R  s+   Invalid relocation information. Can't read s   data at RVA: 0x%xRp  R  N(   R  t    __IMAGE_BASE_RELOCATION_format__R  R  R  R+  R  R  R  R  t   parse_relocationsR  t   SizeOfBlockRf  (   R  R  R/  t   rlc_sizeR#  t   relocationst   rlct   reloc_entries(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR  	  s4    
	

	c         C   s   |  j  | |  } |  j |  } g  } x t t |  d  D] } |  j |  j | | d | d d !d | } | s| Pn  | j }	 |	 d ?}
 |	 d @} | j t d | d |
 d | d	 | |   | | j	   7} q> W| S(
   R  i   i   R  i   i  Rp  Rh  Rj  R  (
   R  R+  R  R   R  t&   __IMAGE_BASE_RELOCATION_ENTRY_format__Ri  R  Rg  R  (   R  t   data_rvaR  R/  Rt  R  R  R  R  Rk  t
   reloc_typet   reloc_offset(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR  	  s*    		

c   	   	   C   s   t  |  j  j   } g  } x t | |  D] } y |  j | | | |  } Wn, t k
 r~ } |  j j d d |  d SX|  j	 |  j | d |  j
 | | |  } | s d S| j t d |   q, W| S(   R  s&   Invalid debug information. Can't read s   data at RVA: 0x%xR  Rp  N(   R  t    __IMAGE_DEBUG_DIRECTORY_format__R  R  R  R  R  R  R  R  R+  Re  (	   R  R  R/  t   dbg_sizet   debugR  Rt  R  t   dbg(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR  	  s&    	 i    c   $      C   s   | d k r | g } n  | d k r- | } n  |  j |  } y% |  j | t |  j  j    } Wn, t k
 r } |  j j d d |  d SX|  j	 |  j | d |  j
 |  }	 |	 d k r |  j j d d |  d Sg  }
 | |	 j   7} |	 j |	 j } d } | | k r2|  j j d | | f  d St   } xyt |  D]k} |  j |  } | d k r|  j j d | | f  Pn  d } d } | |	 j k r| j } nW | | j } y  t |  |  } | j |  Wn' t k
 r} |  j j d |  n X| j r| | j | k r%PnE |  j | | j | | | d	 | d
 | d d | | | j g } | stPn  d } | t d k rvt   } x | j D] } t | d  rx | j j D] } t   } | j j j } | j j j } | j } | j j j d k s| j d k rqn  |  j | |  } t  | t! |  d d |  | j" |  qW| | j _# qqWn  |
 j t$ d | d | d | d |   nq |  j% | | j  } | rt& d | d | j d @d | j d ? } |
 j t$ d | d | d | d |   n P| d k r| j' t d k rt( |
  d k rP|
 d } n  d }  y$ | j j d j j d j j }  Wn n X|  d k	 r|  j) |   qn  | | j   7} qHWg  | D] }! |! j*   ^ q}" |" j+   x$ t, |  D] \ } }! |! j-   qWt. d |	 d |
  }# |# S(   s  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.
        s(   Invalid resources directory. Can't read s   directory data at RVA: 0x%xR  s)   Invalid resources directory. Can't parse i   sN   Error parsing the resources directory, The directory contains %d entries (>%s)sH   Error parsing the resources directory, Entry %d is invalid, RVA = 0x%x. sn   Error parsing the resources directory, attempting to read entry name. Can't read unicode string at offset 0x%xRj  t   leveli   t   dirsR   t	   directoryi   Rp  R  t   idt   langi  t   sublangi
   Rt  i    R   iR  N(/   R  R  R  R  t#   __IMAGE_RESOURCE_DIRECTORY_format__R  R  R  R  R  R+  t   NumberOfNamedEntriest   NumberOfIdEntriesR    R  t   parse_resource_entryt   Namet
   NameOffsetR  t   DataIsDirectoryt   OffsetToDirectoryR  t   RESOURCE_TYPER  R  R'  R+  Rt  Rp  t   OffsetToDataR  R,  R{  R  t   updatet   stringsRc  t   parse_resource_data_entryRd  t   IdR   t   parse_version_informationR  t   sortR   R  Rb  ($   R  R  R/  Rj  R)  R*  t   resources_sectionRt  R  t   resource_dirt   dir_entriest   number_of_entriest   MAX_ALLOWED_ENTRIESt   strings_to_postprocessR  t   rest
   entry_namet   entry_idt   ustr_offsett   excpt   entry_directoryR:  t   resource_idt   resource_langt   resource_stringst   string_entry_rvat   string_entry_sizet   string_entry_idt   string_entry_dataRp  t
   entry_datat
   last_entryt   rt_version_structR  t   string_rvast   resource_directory_data(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR  	  s    	%		
					
			$$
	c         C   s|   y% |  j  | t |  j  j    } Wn, t k
 rS } |  j j d d |  d SX|  j |  j | d |  j	 |  } | S(   s0   Parse a data entry from the resources directory.s/   Error parsing a resource directory data entry, s   the RVA is invalid: 0x%xR  N(
   R  R  t$   __IMAGE_RESOURCE_DATA_ENTRY_format__R  R  R  R  R  R  R+  (   R  R  Rt  RI  t
   data_entry(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR;  
  s    %	c         C   s   y% |  j  | t |  j  j    } Wn t k
 r; } d SX|  j |  j | d |  j |  } | d k rp d S| j d @| _	 | j d @| _
 | j d @| _ | j d @d ?| _ | j d @| _ | S(   s5   Parse a directory entry from the resources directory.R  l    l      l    l        i   N(   R  R  t)   __IMAGE_RESOURCE_DIRECTORY_ENTRY_format__R  R  R  R  R+  R3  R4  t   _PE__padR<  R8  R5  R6  (   R  R  Rt  RI  t   resource(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR2  
  s    %c   "   	   C   s  |  j  | j  } |  j | | | j !} |  j |  j | d | } | d k rT d S| j | j   } y |  j |  } Wn5 t	 k
 r } |  j
 j d d d |  d } n X| d k r |  j
 j d  d S| |  _ | |  j _ |  j | j   d t |  d	 | j  } |  j |  j | | d | | }	 |	 sAd S|	 |  _ |  j | |	 j   | j  }
 |
 } t   |  _ x8t r|  j |  j | |
 d | |
 } | d k r|  j
 j d
  d S| j |
 | j   } y |  j |  } Wn0 t	 k
 r#} |  j
 j d d d |  Pn X| | _ |  j j |  | r5| j d  r5| j d	 k rt| j d k rt|  j |
 | j   d t |  d	 | j  } t   | _ xt r.|  j |  j | | d | | } | sPn  | j | | j   } y |  j |  } Wn0 t	 k
 r?} |  j
 j d d d |  Pn X| | _ t   | _ t   | _ t   | _ | j j |  |  j | | j   d t |  d	 | j  } x5| | | j  k  r|  j |  j! | | d | | } | sPn  | j | | j   } y" |  j |  } |  j  |  } Wn0 t	 k
 r\} |  j
 j d d d |  Pn X|  j d t |  d	 | | j   | j  } | j | } y+ |  j | d | j } |  j  |  } Wn0 t	 k
 r} |  j
 j d d d |  Pn X| j  d k r| | j  } n |  j | j  | | j  } g  } xG | D]? } t" |  d k rs| j d t" |   qA| j |  qAWd j# |  } t$ | | |  | | j | <| | f | j | <t |  t |  f | j | <qW|  j | j  | | j  } | | k rPn  | } | | j  k rPqqWqtn?| rt| j d  rt| } d | _% | j d	 k rt| j d k rt|  j |
 | j   d t |  d	 | j  } t   | _& xt rm|  j |  j' | | d | | } | sPn  | j | | j   } y |  j |  } Wn0 t	 k
 rF} |  j
 j d d d |  Pn X| j& j |  |  j d t |  d	 | | j   | j  } | } x | | | j k  r6|  j( | | | d !d  }  |  j( | | d | d !d  }! | d 7} t) |  t* t+ f  rt) |  t* t+ f  ri d |  |! f | 6| _, qqW|  j | | j  | j  } | | | j  k rPqqWqtn  |  j | j  |
 | j  }
 | j  d k s|
 | j  k r~Pq~q~Wd S(   s  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.
        R  Ns'   Error parsing the version information, s1   attempting to read VS_VERSION_INFO string. Can't s"   read unicode string at offset 0x%xu   VS_VERSION_INFOs   Invalid VS_VERSION_INFO blocki   i   s/   Error parsing StringFileInfo/VarFileInfo structs0   attempting to read StringFileInfo string. Can't u   StringFileInfoi    s-   attempting to read StringTable string. Can't s1   attempting to read StringTable Key string. Can't R  s-   attempting to read StringTable Value string. s(   Can't read unicode string at offset 0x%xi   s   \x%02xR  u   VarFileInfot   VarFileInfos+   attempting to read VarFileInfo Var string. i   s   0x%04x 0x%04x(-   R+  R8  R  R  R  t   __VS_VERSIONINFO_format__R  R  R  R  R  R  R  t   Keyt   dword_alignR   t   __VS_FIXEDFILEINFO_format__R  R    R  R  t   __StringFileInfo_format__R  t   Typet   ValueLengthR  t   __StringTable_format__t   LangIDR  R  R  R  t   Lengtht   __String_format__R  R  R  R  R  t   __Var_format__t   get_word_from_dataR}  R  R  R  ("   R  t   version_structt   start_offsett   raw_datat   versioninfo_structRH  t   versioninfo_stringRI  t   fixedfileinfo_offsett   fixedfileinfo_structt   stringfileinfo_offsett   original_stringfileinfo_offsett   stringfileinfo_structt   stringfileinfo_stringt   stringtable_offsett   stringtable_structt   stringtable_stringt   entry_offsett   string_structR  t
   key_offsett   value_offsetR  t   key_as_charR  t   new_stringtable_offsett   varfileinfo_structt
   var_offsett
   var_structt
   var_stringt   varword_offsett   orig_varword_offsett   word1t   word2(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR=    st   			
	
		
				

		
			#
		

	
*!
c            s^  yC   j    j   j | t   j  j    d   j |  } Wn& t k
 rk   j j d |  d SX| sv d S  f d   } y   j | j	 t
 | | j	  | j d   }   j | j t
 | | j  | j d   }   j | j t
 | | j  | j d   } Wn& t k
 r;  j j d |  d SXg  } d }	 xt t
 | j | | j	  d   D]}
   j | |
  }   j |  } y   j |  } Wn. t k
 r|	 d 8}	 |	 d k rnPqnqnn X  j | |
  } | d t |  k  r  j | |  } n d S| d k sn| d k r8qnn  | | k r| | | k  r  j |  } y   j |  } Wqt k
 rqnqXn d } d } | j t d	   d
 | j | d   j | j d |
  d | d   j | j d |  d | d | d | d |  	 qnWg  | D] } | j ^ q} d }	 xt t
 | j | | j  d   D] } | | j | k r]y   j | |  } Wn t k
 rd } n X| d k r|	 d 8}	 |	 d k rPqn  | d k rq]n  | | k r| | | k  r  j |  } n d } | j t d
 | j | d | d d d |   q]q]Wt d | d |  S(   sR  Parse the export directory.
        
        Given the RVA of the export directory, it will process all
        its entries.
        
        The exports will be made available through a list "exports"
        containing a tuple with the following elements:
            
            (ordinal, symbol_address, symbol_name)
        
        And also through a dictionary "exports_by_ordinal" whose keys
        will be the ordinals and the values tuples of the from:
            
            (symbol_address, symbol_name)
        
        The symbol addresses are relative, not absolute.
        R  s+   Error parsing export directory at RVA: 0x%xNc            s   t    j    j |   S(   N(   R   R  R+  (   R  (   R  (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   length_until_eofz  s    i   i
   i   i    R  RH  RX  i   RJ  R`  R  RV  R^  Ra  Rp  t   symbols(   R  t!   __IMAGE_EXPORT_DIRECTORY_format__R  R  R  R+  R  R  R  t   AddressOfNamesR  t   NumberOfNamest   AddressOfNameOrdinalst   AddressOfFunctionst   NumberOfFunctionsR  t   get_dword_from_datat   get_string_at_rvaRi  R   R  R]  t   BaseRH  R\  (   R  R  R/  t
   export_dirR  t   address_of_namest   address_of_name_ordinalst   address_of_functionst   exportst#   max_failed_entries_before_giving_upRw  t   symbol_name_addresst   symbol_namet   symbol_name_offsett   symbol_ordinalt   symbol_addresst   forwarder_strRa  t   expt   ordinalsR  (    (   R  sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR  V  s    !	((,	,

,

c         C   s   | | d d @| d @S(   Ni   l    (    (   R  R  t   base(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR_    s    c   	   	   C   s^  g  } xQt  rYy% |  j | t |  j  j    } Wn( t k
 r^ } |  j j d |  Pn X|  j |  j | d |  j	 |  } | s | j
   r Pn  | | j   7} y |  j | j | j d	  } Wn, t k
 r } |  j j d d |  Pn X| sq	 n  |  j | j  } t |  s+d } n  | r	 | j t d | d | d |   q	 q	 W| S(
   s*   Walk and parse the delay import directory.s5   Error parsing the Delay import directory at RVA: 0x%xR  s*   Error parsing the Delay import directory. s    Invalid import data at RVA: 0x%xs	   *invalid*Rp  t   importst   dllN(   R  R  R  t(   __IMAGE_DELAY_IMPORT_DESCRIPTOR_format__R  R  R  R  R  R+  R  t   parse_importst   pINTt   pIATR  R  t   szNameRq  RF  (	   R  R  R/  t   import_descsRt  R  t   import_desct   import_dataR  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR    sH    	%			c      	   C   s+  g  } x`t  rhy% |  j | t |  j  j    } Wn( t k
 r^ } |  j j d |  Pn X|  j |  j | d |  j	 |  } | s | j
   r Pn  | | j   7} y" |  j | j | j | j  } Wn8 t k
 r} |  j j d d | t |  f  Pn X| sq	 n  |  j | j  }	 t |	  s:d }	 n  |	 r	 | j t d | d | d |	   q	 q	 Wt d	 d
 g  }
 d } d } xl | D]d } x[ | j D]P } x= |
 D]5 } | r| j r| j j |  r| d 7} PqqW| d 7} qWqW| t |
  k r'| d k  r'|  j j d  n  | S(   s$   Walk and parse the import directory.s/   Error parsing the import directory at RVA: 0x%xR  s$   Error parsing the import directory. s%   Invalid Import data at RVA: 0x%x (%s)s	   *invalid*Rp  R  R  t   LoadLibraryt   GetProcAddressi    i   i   s?   Imported symbols contain entries typical of packed executables.(   R  R  R  t"   __IMAGE_IMPORT_DESCRIPTOR_format__R  R  R  R  R  R+  R  R  t   OriginalFirstThunkt
   FirstThunkt   ForwarderChainR~  R  R3  Rq  RF  t   setR  R  R  R   (   R  R  R/  R  Rt  R  R  R  RI  R  t   suspicious_importst   suspicious_imports_countt   total_symbolst   imp_dllt   symbolt   suspicious_symbol(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR  '  sb    	%			!
	
c      '   C   s:  g  } |  j  |  } |  j  |  } | s= t |  d k ri | sV t |  d k ri t d d   n  d } | r~ | } n | r | } n d S|  j t k r t } n |  j t k r t } n  xrt	 t |   D]^}	 d }
 d } d } d } d } | |	 j
 r| |	 j
 | @r<t } | |	 j
 d @}
 d } d } n t } y | |	 j
 d @} |  j | d  } |  j | d  } |  j | |	 j
 d  } t |  sd } n  |  j | |	 j
 d  } Wn t k
 r} n X| |	 j   } |  j |  } n  | |  j j |	 d } d } yJ | r]| r]| |	 j
 | |	 j
 k r]| |	 j
 } | |	 } n d } Wn t k
 r}d } n X|
 d k r| d k rt d	   n  | d
 k r |
 s| r | j t d |  d | |	 d | d | d |
 d | |	 j   d | d | d | d | d | d | d | d |   q q W| S(   s   Parse 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
        all the symbols imported from that object.
        i    s"   Invalid Import Table information. s%   Both ILT and IAT appear to be broken.i  ii   s	   *invalid*i   s6   Invalid entries in the Import Table. Aborting parsing.R  R  RP  RU  t   import_by_ordinalRH  RX  t   hintR  RV  RI  RJ  t   hint_name_table_rvat   thunk_offsett	   thunk_rvaN(   t   get_import_tableR   R  R  RK  RL  RM  RN  RO  R  RR  R  R  R  Ri  R  Rs  R+  R  R*  R  t	   ImageBaseR  R  RG  (   R  t   original_first_thunkt   first_thunkt   forwarder_chaint   imported_symbolst   iltt   iatt   tableRZ  R  t   imp_ordt   imp_hintt   imp_nameRV  R  R  Rt  R  R  R  t   imp_addressRU  t	   imp_bound(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR  m  s    2						&


c         C   s>  g  } |  j  t k r' t } |  j } n! |  j  t k rH t } |  j } n  x t r9| r9y" |  j | t	 |  j
    } Wn, t k
 r } |  j j d d |  d  SX|  j | | d |  j |  } | r| j r| j | @r| j d @d k r g  Sqn  | s| j   rPn  | | j
   7} | j |  qK W| S(   Ns    Error parsing the import table. s   Invalid data at RVA: 0x%xR  ii  (   RK  RL  RM  t   __IMAGE_THUNK_DATA_format__RN  RO  t   __IMAGE_THUNK_DATA64_format__R  R  R  R  R  R  R  R  R  R+  RR  R  (   R  R  R  RZ  R  Rt  R  t
   thunk_data(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR    s4    "	
i   c         C   s[  | d k	 r% |  j } |  j |  n  d |  j } x	|  j D] } | j d k s= | j d k rg q= n  | j t |  j  k r q= n  t | j |  j	 j
  t |  j  k r q= n  t | j |  j	 j |  j	 j
  } | | k r q= n  | t |  } | d k r| d | 7} n | d k  r+| |  } n  | | j   7} q= W| d k	 rW| |  _ n  | S(   s  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 section 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.
        R  i    R	  N(   R  R  t   relocate_imageR  R-  R  R   R  R  R  R  R  R  R  R  (   R  t   max_virtual_addressR  t   original_datat   mapped_dataR  R"  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   get_memory_mapped_image  s2    			c         C   s   t    } t |  d  r x |  j j D] } t | d  r% xt | j j D]c } t | d  rG t | j d  r | j j r x* | j j j   D] } | j |  q Wq qG qG Wq% q% Wn  | S(   s(  Returns a list of all the strings found withing 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 list() with the strings.
        
        An empty list will be returned otherwise.
        t   DIRECTORY_ENTRY_RESOURCER+  R:  (   R    R'  R  R  R+  R:  R  R  (   R  t   resources_stringst   resource_typeRK  t
   res_string(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   get_resources_stringsg  s    		%c         C   s   |  j  |  } | r" | | } n d } | s | t |  j  k  rQ |  j | | !S| t |  j  k  rt |  j | | !St d  n  | j | |  S(   s   Get 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.
        s-   data at RVA can't be fetched. Corrupt header?N(   R  R  R   R  R  R  R  (   R  R  R  R  R#  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR    s    c         C   s   |  j  |  } | su |  j rn t g  |  j D]' } t | j |  j j |  j j  ^ q+  } | | k  rr | Squ | Sn  | j |  S(   s/   Get the RVA corresponding to this file offset. (	   t   get_section_by_offsetR  R  R  R  R  R  R  R*  (   R  R  R  t
   lowest_rva(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR*    s    	7	c         C   sG   |  j  |  } | s: | t |  j  k  r. | St d  n  | j |  S(   s   Get 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.
        s-   data at RVA can't be fetched. Corrupt header?(   R  R   R  R  R+  (   R  R  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR+    s    c         C   sR   |  j  |  } | s3 |  j d |  j | | t ! S|  j d | j | d t  S(   s1   Get an ASCII string located at the given address.i    R  (   R  R  R  R  R  (   R  R  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR    s    c         C   s}   d } y | | } Wn t k
 r( d SXd } xG t |  rx | | 7} | d 7} y | | } Wq2 t k
 rt Pq2 Xq2 W| S(   s)   Get an ASCII string from within the data.R  i   N(   R  R  R  (   R  R  Rt  R  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR    s    

	i   i   c         C   s   y |  j  | d  } Wn t k
 r, } d SXd } x t |  D]r } y. t j d |  j  | d | d   d } Wn t j k
 r Pn Xt |  d k r Pn  | t |  7} q@ W| S(   s3   Get an Unicode string located at the given address.i   u    s   <Hi    u    N(   R  R  R  R  Rp  Rq  t   errort   unichr(   R  R  R  Rt  R  R  R  t   uchr(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR    s    .c         C   s=   g  |  j  D] } | j |  r
 | ^ q
 } | r9 | d Sd S(   s1   Get the section containing the given file offset.i    N(   R  R,  R  (   R  R  R  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR  
  s    +c         C   s=   g  |  j  D] } | j |  r
 | ^ q
 } | r9 | d Sd S(   s-   Get the section containing the given address.i    N(   R  R0  R  (   R  R  R  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR    s    +c         C   s
   |  j    S(   N(   t	   dump_info(   R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR    s    c         C   s   |  j    GHd S(   s=   Print all the PE header information in a human readable from.N(   R  (   R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt
   print_info#  s    c            s  | dU k r t   } n  |  j   } | rb | j d  x( | D] } | j |  | j   q> Wn  | j d  | j |  j j    | j   | j d  | j |  j	 j    | j   | j d  | j |  j
 j    t t d  } | j d  g  } x8 | D]0 } t |  j
 | d  r| j | d  qqW| j d j |   | j   t |  d	  r|  j dU k	 r| j d	  | j |  j j    n  t t d
  } | j d  g  } x8 | D]0 } t |  j | d  r| j | d  qqW| j d j |   | j   | j d  t t d  } x>|  j D]3}	 | j |	 j    | j d  g  } x5 | D]- } t |	 | d  rv| j | d  qvqvW| j d j |   | j d |	 j    t dU k	 r| j d |	 j    n  t dU k	 r | j d |	 j    n  t dU k	 rF| j d |	 j    n  t dU k	 rl| j d |	 j    n  | j   qCWt |  d	  rt |  j d  r| j d  xC t t  |  j j!   D]) }
 |  j j! |
 } | j | j    qW| j   n  d       f d   } t |  d  r+| j d  | j |  j" j    | j   t |  d  r| j |  j# j    | j   n  t |  d  r+x|  j$ D]} | j | j    | j   t | d  r|x | j% D] } g  | j   D] } | j d |  ^ q| j d | j&  | j   xD | j' j(   D]3 } | j d | | d  d | | d    q4WqW| j   qt | d!  rx | j) D]{ } t | d"  rg  | j   D] } | j d |  ^ q| j d | | j* j+   d  d | j* j,   d  qqW| j   qqWq+n  t |  d#  r| j d$  | j |  j- j. j    | j   | j d% dV  xs |  j- j/ D]e } | j0 dU k	 r| j d) | j1 | j0 | j2 f  | j3 r| j d* | j3  q| j   qqW| j   n  t |  d+  r| j d,  x |  j4 D] } | j | j. j    | j   x | j5 D] } | j6 t7 k r| j d- | j8 t9 | j1  f  n) | j d. | j8 | j2 t9 | j:  f  | j; r| j d/ | j;  qT| j   qTW| j   q$Wn  t |  d0  r| j d1  x |  j< D] } | j | j. j    | j d2 | j2  | j   xK | j' D]@ } | j | j. j   d3  | j d2 | j2 d3  | j   qaWqWn  t |  d4  r	| j d5  x |  j= D] } | j | j. j    | j   x | j5 D] } | j6 t7 k r=	| j d- | j8 t9 | j1  f  n) | j d. | j8 | j2 t9 | j:  f  | j; r	| j d/ | j;  q	| j   q	W| j   qWn  t |  d6  rp| j d7  | j |  j> j. j    x|  j> j' D]x} | j2 dU k	 r
| j d8 | j2 d9  n2 | j d: | j. j? t@ jA | j. j? d;  f d9  | j | j. j   d9  t | d<  rU| j | jB j. j   d3  x| jB j' D]} | j2 dU k	 r
| j d8 | j2 d=  n | j d> | j. j? d=  | j | j. j   d=  t | d<  r
| j | jB j. j   d?  x | jB j' D] } t | d@  r3| j dA | jC jD | jC jE tF jA | jC jD dB  tG | jC jD | jC jE  f d?  | j | j. j   dC  | j | jC j. j   dD  q3q3Wt | jB dE  rN| jB jH rN| j dF dC  xC | jB jH j(   D], \ }
 } | j dG |
 | |  f dD  qWqNq
q
Wn  | j   q	W| j   n  t |  dH  r|  jI r|  jI j. r| j dI  | j |  jI j. j    | j   n  t |  dJ  r|  jJ r|  jJ j. r| j dK  | j |  jJ j. j    | j   n  t |  dL  r| j dM  x~ |  jK D]p } | j | j. j    y | j dN tL | j. jM  Wn( tN k
 r| j dO | j. jM  n X| j   qDWn  t |  dP  r| j dQ  x |  jO D] } | j | j. j    xq | j' D]f } y, | j dR | jP tQ | jR dS f d3  WqtN k
 rl| j dT | jP | jR f d3  qXqW| j   qWn  | jS   S(W   s>   Dump all the PE header information into human readable string.s   Parsing WarningsR  R  R  R  s   Flags: i    s   , R  R  s   DllCharacteristics: s   PE SectionsR%  s   Entropy: %f (Min=0.0, Max=8.0)s   MD5     hash: %ss   SHA-1   hash: %ss   SHA-256 hash: %ss   SHA-512 hash: %sR  t   Directoriesc         S   sR   |  t  j k s< |  t  j k s< |  t  j k s< |  t  j k r@ |  Sd t |   Sd  S(   Ns   \x%02x(   R  t   ascii_lettersR  t   punctuationt
   whitespaceR  (   R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR  ~  s    <c            s&   d j  g  |  D] }   |  ^ q  S(   NR  (   R  (   R  R  (   R  (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   convert_to_printable  s    R  s   Version InformationR  R  R  s     s
     LangID: s       s   : i   R  R  t   DIRECTORY_ENTRY_EXPORTs   Exported symbolss   %-10s   %-10s  %sRQ  t   RVAR3  s   %-10d 0x%08Xh    %ss    forwarder: %st   DIRECTORY_ENTRY_IMPORTs   Imported symbolss$   %s Ordinal[%s] (Imported by Ordinal)s   %s.%s Hint[%s]s    Bound: 0x%08Xt   DIRECTORY_ENTRY_BOUND_IMPORTs   Bound importss   DLL: %si   t   DIRECTORY_ENTRY_DELAY_IMPORTs   Delay Imported symbolsR  s   Resource directorys
   Name: [%s]i   s   Id: [0x%X] (%s)R  R+  i   s
   Id: [0x%X]i   Rt  s   \--- LANG [%d,%d][%s,%s]s	   *unknown*i
   i   R:  s	   [STRINGS]s   %6d: %st   DIRECTORY_ENTRY_TLSt   TLSt   DIRECTORY_ENTRY_LOAD_CONFIGt   LOAD_CONFIGt   DIRECTORY_ENTRY_DEBUGs   Debug informations   Type: s   Type: 0x%x(Unknown)t   DIRECTORY_ENTRY_BASERELOCs   Base relocationss   %08Xh %si   s   0x%08X 0x%x(Unknown)N(   s   OrdinalR  s   Name(T   R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R'  R  R  R&  R  R3  R;  R<  R4  R6  R7  R8  R9  R:  R  R   R  R  R  R  R  Re  R  R|  R  R  R  R  R  Rp  R  RJ  RH  R  R^  R  R  R  R  R  R~  R  RI  R  R  R  R<  R7  Ri  R+  Rt  R-  R.  Rh  Ro  R:  R  R  R  t
   DEBUG_TYPERb  R  R  R  t   RELOCATION_TYPERh  R  (   R  R  t   warningsR  R  R  R  R  R(  R  R  R+  R  R  R  R  t	   str_entryt	   var_entryt   exportt   moduleR  t   bound_imp_desct   bound_imp_refR  RK  RL  R  R(  t
   base_reloct   reloc(    (   R  sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR  (  s   



	

*
*:
		
		 	

		 					##1			#	c         C   s*   y |  j  |  SWn t k
 r% d SXd S(   s;   Gets the physical address in the PE file from an RVA value.N(   R+  t	   ExceptionR  (   R  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   get_physical_by_rvaX  s    c         C   s   t  j d | d @ S(   sN   Return a four byte string representing the double word value. (little endian).s   <Ll    (   Rp  R   (   R  t   dword(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   get_data_from_dwordd  s    c         C   sE   | d d t  |  k r d St j d | | d | d d ! d S(   s+  Convert 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.
        i   i   s   <Ii    N(   R   R  Rp  Rq  (   R  Rt  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR  i  s    	c         C   s:   y! |  j  |  j |  d  d  SWn t k
 r5 d SXd S(   s   Return 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.
        i   i    N(   R  R  R  R  (   R  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   get_dword_at_rvax  s    !c         C   s;   | d t  |  j  k r d S|  j |  j | | d !d  S(   sF   Return the double word value at the given file offset. (little endian)i   i    N(   R   R  R  R  (   R  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   get_dword_from_offset  s    c         C   s   |  j  | |  j |   S(   sL   Set the double word value at the file offset corresponding to the given RVA.(   t   set_bytes_at_rvaR  (   R  R  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   set_dword_at_rva  s    c         C   s   |  j  | |  j |   S(   s3   Set the double word value at the given file offset.(   RY  R  (   R  R  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyRW    s    c         C   s   t  j d |  S(   sF   Return a two byte string representing the word value. (little endian).s   <H(   Rp  R   (   R  Rk  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   get_data_from_word  s    c         C   sE   | d d t  |  k r d St j d | | d | d d ! d S(   s  Convert 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.
        i   i   s   <Hi    N(   R   R  Rp  Rq  (   R  Rt  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyRi    s    	c         C   s:   y! |  j  |  j |  d  d  SWn t k
 r5 d SXd S(   s   Return 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.
        i   i    N(   Ri  R  R  R  (   R  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   get_word_at_rva  s    !c         C   s;   | d t  |  j  k r d S|  j |  j | | d !d  S(   s?   Return the word value at the given file offset. (little endian)i   i    N(   R   R  R  Ri  (   R  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   get_word_from_offset  s    c         C   s   |  j  | |  j |   S(   sE   Set the word value at the file offset corresponding to the given RVA.(   R  R  (   R  R  Rk  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   set_word_at_rva  s    c         C   s   |  j  | |  j |   S(   s,   Set the word value at the given file offset.(   RY  R  (   R  R  Rk  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR_    s    c         C   s   t  j d |  S(   sM   Return a eight byte string representing the quad-word value. (little endian).s   <Q(   Rp  R   (   R  Rk  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   get_data_from_qword  s    c         C   sE   | d d t  |  k r d St j d | | d | d d ! d S(   s"  Convert 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.
        i   i   s   <Qi    N(   R   R  Rp  Rq  (   R  Rt  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   get_qword_from_data  s    	c         C   s:   y! |  j  |  j |  d  d  SWn t k
 r5 d SXd S(   s   Return 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.
        i   i    N(   R  R  R  R  (   R  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   get_qword_at_rva  s    !c         C   s;   | d t  |  j  k r d S|  j |  j | | d !d  S(   sD   Return the quad-word value at the given file offset. (little endian)i   i    N(   R   R  R  R  (   R  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   get_qword_from_offset  s    c         C   s   |  j  | |  j |   S(   sJ   Set the quad-word value at the file offset corresponding to the given RVA.(   R  R  (   R  R  t   qword(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   set_qword_at_rva  s    c         C   s   |  j  | |  j |   S(   s1   Set the quad-word value at the given file offset.(   RY  R  (   R  R  R	  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   set_qword_at_offset  s    c         C   s.   |  j  |  } | s t  n  |  j | |  S(   s   Overwrite, 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.
        (   R  R  RY  (   R  R  Rt  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR    s    	c         C   ss   t  | t  s t d   n  | d k rk | t |  j  k  rk |  j |  | |  j | t |  |  _ n t St S(   s   Overwrite 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.
        s   data should be of type: stri    (   R}  R~  t	   TypeErrorR   R  R  R  (   R  R  Rt  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyRY    s    !,c         C   s   x |  j  D]} } t | j |  j j  } | | j } | t |  j  k  r
 | t |  j  k  r
 |  j |  | j   |  j | |  _ q
 q
 Wd S(   sT   Update the PE image content with any individual section data that has been modified.N(	   R  R  R  R  R  R  R   R  R  (   R  R  t   section_data_startt   section_data_end(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   merge_modified_section_data/  s    	*c   	      C   s  | |  j  j } x|  j D]} | j j } | j j } d } x| t | j  k  r| j | } | d 7} | j t	 d k r qA | j t	 d k r |  j
 | j |  j | j  | d ?d @ qA | j t	 d k r|  j
 | j |  j | j  | d @ qA | j t	 d k r:|  j | j |  j | j  |  qA | j t	 d	 k r| t | j  k rfPn  | j | } | d 7} |  j
 | j |  j | j  d >| j | d
 @d ? qA | j t	 d k rA |  j | j |  j | j  |  qA qA Wq Wd S(   sR  Apply the relocation information to the image using the provided new 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.
        i    i   Ru   Rv   i   i  Rw   Rx   Ry   l      R   N(   R  R  R  Rp  R  R  R   R  Rh  R  R  R  R  R   R  R
  R  (	   R  t   new_ImageBaset   relocation_differenceR  t   virtual_addresst   size_of_blockt	   entry_idxR  t
   next_entry(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR  :  sD    
"
c         C   s   |  j  j |  j   k S(   N(   R  t   CheckSumt   generate_checksum(   R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   verify_checksum  s    c         C   s)  |  j    |  _ |  j j d } d } t |  j  d } |  j d d | | d k } x t t |  d  D]| } | | d k r qn n  t j d | | d | d d ! d } | d @| | d ?} | d k rn | d @| d ?} qn qn W| d	 @| d
 ?} | | d
 ?} | d	 @} | t |  j  S(   Ni@   i    i   R	  R  l    i    i   i  i   l        (   R  R  R  R  R   R   Rp  Rq  (   R  t   checksum_offsetR  R  Rt  Rw  R  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR    s     )
c         C   sB   t  d } |  j   r> |  j   r> | |  j j @| k r> t St S(   s   Check 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.
        R   (   R  t   is_dllt	   is_driverR  R$  R  R  (   R  t   EXE_flag(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   is_exe  s
    
c         C   s(   t  d } | |  j j @| k r$ t St S(   s   Check whether the file is a standard DLL.
        
        This will return true only if the image has the IMAGE_FILE_DLL flag set.
        R$   (   R  R  R$  R  R  (   R  t   DLL_flag(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR    s    
c         C   sN   t  |  d  rJ t d  j g  |  j D] } | j j   ^ q%  rJ t Sn  t S(   s   Check whether the file is a Windows driver.
        
        This will return true only if there are reliable indicators of the image
        being a driver.
        R  s   ntoskrnl.exes   hal.dlls   ndis.syss   bootvid.dlls	   kdcom.dll(   s   ntoskrnl.exes   hal.dlls   ndis.syss   bootvid.dlls	   kdcom.dll(   R'  R  t   intersectionR  R  t   lowerR  R  (   R  t   imp(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyR    s    4c         C   s   d } d } xe |  j  D]Z } | j | j t |  j  k rA q n  | j | j | | k r | j } | j } q q Wt |  j  | | k r | | Sd S(   sg   Get the offset of data appended to the file and not contained within the area described in the headers.i    N(   R  R  R  R   R  R  (   R  t   highest_PointerToRawDatat   highest_SizeOfRawDataR  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   get_overlay_data_start_offset  s    	c         C   s'   |  j    } | d k	 r# |  j | Sd S(   s]   Get the data appended to the file and not contained within the area described in the headers.N(   R$  R  R  (   R  t   overlay_data_offset(    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   get_overlay  s    c         C   s+   |  j    } | d k	 r# |  j |  S|  j S(   sL   Return the just data defined by the PE headers, removing any overlayed data.N(   R$  R  R  (   R  R%  (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   trim#  s    (h   R  R  R  R  R  R  R  R  R  R  R  R  R  R/  RY  RW  R]  R`  Ra  Rd  Rg  Rh  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;  R2  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   RW  R  Ri  R  R  R  R_  R  R  R  R  R
  R  R  RY  R  R  R  R  R  R  R  R$  R&  R'  (    (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyRt    s  C																 #	8			
E	]=	D			*					 U			8	F		-I	#			
			
		 1								
																			^		)					(   NNNN(   s   IMAGE_DIRECTORY_ENTRY_EXPORTi    (   s   IMAGE_DIRECTORY_ENTRY_IMPORTi   (   s   IMAGE_DIRECTORY_ENTRY_RESOURCEi   (   R
   i   (   R   i   (   s   IMAGE_DIRECTORY_ENTRY_BASERELOCi   (   s   IMAGE_DIRECTORY_ENTRY_DEBUGi   (   R   i   (   R   i   (   s   IMAGE_DIRECTORY_ENTRY_TLSi	   (   s!   IMAGE_DIRECTORY_ENTRY_LOAD_CONFIGi
   (   s"   IMAGE_DIRECTORY_ENTRY_BOUND_IMPORTi   (   R   i   (   s"   IMAGE_DIRECTORY_ENTRY_DELAY_IMPORTi   (   R   i   (   R   i   (   R   i   (   s   IMAGE_FILE_EXECUTABLE_IMAGEi   (   R   i   (   R   i   (   R   i   (   R   i    (   R   i@   (   R   i   (   R   i   (   R    i   (   R!   i   (   R"   i   (   R#   i   (   s   IMAGE_FILE_DLLi    (   R%   i @  (   R&   i   (   R'   i    (   R(   i@   (   R)   i   (   R*   i   (   R+   i   (   R,   i   (   R-   i   (   R.   i   (   R/   i   (   R0   i   (   R1   i   (   R2   i   (   R3   i   (   R4   i    (   R5   i  0 (   R6   i  @ (   R7   i  P (   R8   i  ` (   R9   i  p (   R:   i   (   R;   i   (   R<   i   (   R=   i   (   R>   i   (   R?   i   (   R@   i   (   RA   i   (   RB   i   (   RC   i   (   RD   i   (   RE   i   (   RF   i   (   s   IMAGE_SCN_MEM_EXECUTEi    (   RH   i   @(   s   IMAGE_SCN_MEM_WRITEl        (   s   IMAGE_DEBUG_TYPE_UNKNOWNi    (   s   IMAGE_DEBUG_TYPE_COFFi   (   s   IMAGE_DEBUG_TYPE_CODEVIEWi   (   s   IMAGE_DEBUG_TYPE_FPOi   (   s   IMAGE_DEBUG_TYPE_MISCi   (   s   IMAGE_DEBUG_TYPE_EXCEPTIONi   (   s   IMAGE_DEBUG_TYPE_FIXUPi   (   s   IMAGE_DEBUG_TYPE_OMAP_TO_SRCi   (   s   IMAGE_DEBUG_TYPE_OMAP_FROM_SRCi   (   RS   i	   (   RT   i
   (   RU   i    (   RV   i   (   RW   i   (   RX   i   (   RY   i   (   RZ   i   (   R[   i	   (   R\   i
   (   R]   i   (   R^   i   (   R_   i   (   R`   i   (   s   IMAGE_FILE_MACHINE_UNKNOWNi    (   Rb   i  (   Rc   id  (   Rd   i  (   Re   i  (   Rf   iL  (   Rg   i   (   Rh   iA  (   Ri   if  (   Rj   if  (   Rk   if  (   Rl   i  (   Rm   i  (   Rn   if  (   Ro   i  (   Rp   i  (   Rq   i  (   Rr   i  (   Rs   i  (   Rt   ii  (   s   IMAGE_REL_BASED_ABSOLUTEi    (   s   IMAGE_REL_BASED_HIGHi   (   s   IMAGE_REL_BASED_LOWi   (   s   IMAGE_REL_BASED_HIGHLOWi   (   s   IMAGE_REL_BASED_HIGHADJi   (   s   IMAGE_REL_BASED_MIPS_JMPADDRi   (   R{   i   (   R|   i   (   R}   i	   (   R~   i	   (   s   IMAGE_REL_BASED_DIR64i
   (   R   i   (   R   i   (   R   i   (   R   i   (   R   i   (   R   i@   (   R   i   (   R   i   (   R   i   (   R   i   (   R   i   (   R   i   (   R   i    (   R   i   (   s	   RT_CURSORi   (   s	   RT_BITMAPi   (   s   RT_ICONi   (   s   RT_MENUi   (   s	   RT_DIALOGi   (   s	   RT_STRINGi   (   s
   RT_FONTDIRi   (   s   RT_FONTi   (   s   RT_ACCELERATORi	   (   s	   RT_RCDATAi
   (   s   RT_MESSAGETABLEi   (   s   RT_GROUP_CURSORi   (   s   RT_GROUP_ICONi   (   s
   RT_VERSIONi   (   s   RT_DLGINCLUDEi   (   s   RT_PLUGPLAYi   (   s   RT_VXDi   (   s   RT_ANICURSORi   (   s
   RT_ANIICONi   (   s   RT_HTMLi   (   s   RT_MANIFESTi   (   s   LANG_NEUTRALi    (   R   i   (   R   i6   (   R   i   (   R   i   (   R   i+   (   R   iM   (   R   i,   (   R   i-   (   R   i#   (   R   iE   (   s   LANG_BULGARIANi   (   R   i   (   s   LANG_CHINESEi   (   s   LANG_CROATIANi   (   s
   LANG_CZECHi   (   s   LANG_DANISHi   (   R   ie   (   s
   LANG_DUTCHi   (   s   LANG_ENGLISHi	   (   R   i%   (   R   i8   (   R   i)   (   s   LANG_FINNISHi   (   s   LANG_FRENCHi   (   R   iV   (   R   i7   (   s   LANG_GERMANi   (   s
   LANG_GREEKi   (   R   iG   (   R   i   (   R   i9   (   s   LANG_HUNGARIANi   (   s   LANG_ICELANDICi   (   R   i!   (   s   LANG_ITALIANi   (   s   LANG_JAPANESEi   (   R   iK   (   R   i`   (   R   i?   (   R   iW   (   s   LANG_KOREANi   (   R   i@   (   R   i&   (   R   i'   (   R   i/   (   R   i>   (   R   iL   (   R   iX   (   R   iN   (   R   iP   (   R   ia   (   s   LANG_NORWEGIANi   (   R   iH   (   s   LANG_POLISHi   (   s   LANG_PORTUGUESEi   (   R   iF   (   s   LANG_ROMANIANi   (   s   LANG_RUSSIANi   (   R   iO   (   R   i   (   R   iY   (   s   LANG_SLOVAKi   (   s   LANG_SLOVENIANi$   (   s   LANG_SPANISHi
   (   R   iA   (   s   LANG_SWEDISHi   (   R   iZ   (   R   iI   (   R   iD   (   R   iJ   (   R   i   (   s   LANG_TURKISHi   (   R   i"   (   R   i    (   R   iC   (   R   i*   (   R   i<   (   R   i:   (   R   i(   (   R   i   (   R   i;   (   R   i.   (   R   i0   (   R   i1   (   R   i2   (   R   i3   (   R   i4   (   R   i5   (   R   i   (   R   i   (   R   i   (   R   i   (   R   i   (   s   SUBLANG_NEUTRALi    (   s   SUBLANG_DEFAULTi   (   s   SUBLANG_SYS_DEFAULTi   (   R  i   (   R  i   (   R  i   (   R  i   (   R  i   (   R	  i   (   R
  i   (   R  i   (   R  i	   (   R  i
   (   R  i   (   R  i   (   R  i   (   R  i   (   R  i   (   R  i   (   R  i   (   R  i   (   s   SUBLANG_CHINESE_TRADITIONALi   (   s   SUBLANG_CHINESE_SIMPLIFIEDi   (   s   SUBLANG_CHINESE_HONGKONGi   (   s   SUBLANG_CHINESE_SINGAPOREi   (   R  i   (   s   SUBLANG_DUTCHi   (   s   SUBLANG_DUTCH_BELGIANi   (   s   SUBLANG_ENGLISH_USi   (   s   SUBLANG_ENGLISH_UKi   (   s   SUBLANG_ENGLISH_AUSi   (   s   SUBLANG_ENGLISH_CANi   (   s   SUBLANG_ENGLISH_NZi   (   s   SUBLANG_ENGLISH_EIREi   (   R#  i   (   R$  i   (   R%  i	   (   R&  i
   (   R'  i   (   R(  i   (   R)  i   (   s   SUBLANG_FRENCHi   (   s   SUBLANG_FRENCH_BELGIANi   (   s   SUBLANG_FRENCH_CANADIANi   (   s   SUBLANG_FRENCH_SWISSi   (   R.  i   (   R/  i   (   s   SUBLANG_GERMANi   (   s   SUBLANG_GERMAN_SWISSi   (   s   SUBLANG_GERMAN_AUSTRIANi   (   R3  i   (   R4  i   (   s   SUBLANG_ITALIANi   (   s   SUBLANG_ITALIAN_SWISSi   (   R7  i   (   R8  i   (   R9  i   (   R:  i   (   R;  i   (   R<  i   (   R=  i   (   s   SUBLANG_NORWEGIAN_BOKMALi   (   s   SUBLANG_NORWEGIAN_NYNORSKi   (   s   SUBLANG_PORTUGUESEi   (   s   SUBLANG_PORTUGUESE_BRAZILIANi   (   RB  i   (   RC  i   (   s   SUBLANG_SPANISHi   (   s   SUBLANG_SPANISH_MEXICANi   (   s   SUBLANG_SPANISH_MODERNi   (   RG  i   (   RH  i   (   RI  i   (   RJ  i   (   RK  i   (   RL  i	   (   RM  i
   (   RN  i   (   RO  i   (   RP  i   (   RQ  i   (   RR  i   (   RS  i   (   RT  i   (   RU  i   (   RV  i   (   RW  i   (   RX  i   (   RY  i   (   RZ  i   (   R[  i   (   R\  i   (   R]  i   (   R^  i   (   R_  i   (   R`  i   (   Ra  i   (   Rb  i   (   Rc  i   (   Rd  i   (   Re  i   (   Rf  i   (   Rg  i   (    (    (    (    (    (l   R  t   __revision__t
   __author__R  t   __version__t   __contact__t   osRp  R  R?  t   reR  R  R=  R  R  R4  R7  R9  R;  t   hashlibt   ImportErrort   shat   newR   t	   NameErrorR  R  R  R  R  R  R  R  R  t    IMAGE_NUMBEROF_DIRECTORY_ENTRIESRM  RO  RL  RN  t   directory_entry_typesR  R  R  t   image_characteristicsR  t   section_characteristicsR&  t   debug_typesR  t   subsystem_typest   SUBSYSTEM_TYPEt   machine_typest   MACHINE_TYPEt   relocation_typesR  t   dll_characteristicsR  R  R7  R-  Rh  R.  Rj  Rn  Rl  t   has_keyR  Ro  R{  R  R  R  R  R  R  R  R  R  R  R  RD  RF  RG  R\  R]  Rb  Rc  Rd  Re  Rf  Rg  Rl  Rm  Rn  Ro  t	   lowercaset	   uppercaseR  R  R   Rw  R  Rp  Rq  Rr  Rs  Rt  (    (    (    sY   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\lib\pefile.pyt   <module>   s  				1	+	+	1	1	1	1	1	1	1	1						h
A#
	9(!J		
