1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
Ë
Jñúh¹Gãóˆ—dZddlZddlZddlZddlZddlZddlZddlZdZ    ejZ
dZ Gd„de «Z d„Zd„Zd    „Zy)
z‚peutils, Portable Executable utilities module
 
 
Copyright (c) 2005-2023 Ero Carrera <ero.carrera@gmail.com>
 
All rights reserved.
éNz Ero Carrerazero.carrera@gmail.comcóh—eZdZdZdd„Zdd„Zdd„Z    dd„Zdd„Zdd„Z    d    „Z
dd
„Z dd „Z dd „Z dd „Zy)ÚSignatureDatabasea±This class loads and keeps a parsed PEiD signature database.
 
    Usage:
 
        sig_db = SignatureDatabase('/path/to/signature/file')
 
    and/or
 
        sig_db = SignatureDatabase()
        sig_db.load('/path/to/signature/file')
 
    Signature databases can be combined by performing multiple loads.
 
    The filename parameter can be a URL too. In that case the
    signature database will be downloaded from that location.
    Ncó—tjdtj«|_t    «|_d|_t    «|_d|_t    «|_    d|_
d|_ |j||¬«y)Nzh\[(.*?)\]\s+?signature\s*=\s*(.*?)(\s+\?\?)*\s*ep_only\s*=\s*(\w+)(?:\s*section_start_only\s*=\s*(\w+)|)r©ÚfilenameÚdata) ÚreÚcompileÚSÚ    parse_sigÚdictÚsignature_tree_eponly_trueÚsignature_count_eponly_trueÚsignature_tree_eponly_falseÚsignature_count_eponly_falseÚsignature_tree_section_startÚsignature_count_section_startÚ    max_depthÚ_SignatureDatabase__load©Úselfrrs   ú:H:\Change_password\venv_build\Lib\site-packages\peutils.pyÚ__init__zSignatureDatabase.__init__&so€ôŸ™Ø vÜ D‰Dó
ˆŒô"+/«&ˆÔ'Ø+,ˆÔ(Ü+/«6ˆÔ(Ø,-ˆÔ)Ü,0«FˆÔ)Ø-.ˆÔ*ðˆŒà  ‰ ˜X¨Dˆ Õ1óc ó¸—t«}t|j«D] \}}|j|krŒ|j}d||dzt |j«dj |jDcgc]}|tjvsŒ|‘Œc}«fz}    |j|j|||    dd|¬««Œ¢dj |«dzScc}w)aGenerates signatures for all the sections in a PE file.
 
        If the section contains any data a signature will be created
        for it. The signature name will be a combination of the
        parameter 'name' and the section number and its name.
        z%s Section(%d/%d,%s)éÚFT)Úep_onlyÚsection_start_onlyÚ
sig_lengthú
) ÚlistÚ    enumerateÚsectionsÚ SizeOfRawDataÚPointerToRawDataÚlenÚjoinÚNameÚstringÚ    printableÚappendÚ&_SignatureDatabase__generate_signature)
rÚpeÚnamer Úsection_signaturesÚidxÚsectionÚoffsetÚcÚsig_names
          rÚgenerate_section_signaturesz-SignatureDatabase.generate_section_signaturesHså€ô"›VÐä% b§k¡kÓ2ò    ‰LˆCà×$Ñ$ zÒ1Øð×-Ñ-ˆFà-ØØa‘ܐB—K‘KÓ Ø—‘ G§L¡LÖJ˜q°A¼×9IÑ9IÒ4IšÒJÓKð    1ñˆHð × %Ñ %Ø×)Ñ)ØØØØ!Ø'+Ø)ð *óõ     ð    ð4y‰yÐ+Ó,¨tÑ3Ð3ùòKs Á5C Ccóx—|j|jj«}|j|||d|¬«S)z°Generate signatures for the entry point of a PE file.
 
        Creates a signature whose name will be the parameter 'name'
        and the section number and its name.
        T)rr )Úget_offset_from_rvaÚOPTIONAL_HEADERÚAddressOfEntryPointr-)rr.r/r r3s     rÚgenerate_ep_signaturez'SignatureDatabase.generate_ep_signaturensC€ð×'Ñ'¨×(:Ñ(:×(NÑ(NÓOˆà×(Ñ(Ø ˜ d°zð)ó
ð    
rc    óЗ|j|||z}dj|Dcgc]}dt|«z‘Œc}«}    |dk(rd}nd}|dk(rd}nd}d|›d|    ›d|›d    |›d
    }
|
Scc}w) Nú z%02xTÚtrueÚfalseú[z]
signature = z
ep_only = z
section_start_only = r!)Ú__data__r(Úord) rr.r3r/rrr rr4Úsignature_bytesÚ    signatures            rÚ__generate_signaturez&SignatureDatabase.__generate_signature{sƒ€ð{‰{˜6 F¨ZÑ$7Ð8ˆàŸ(™(¸TÖ#B¸ F¬S°«V£OÒ#BÓCˆà dŠ?؉GàˆGà  Ò %Ø!'Ñ à!(Ð øò Ú Ú Ú ð    
ˆ    ðÐùò'$Cs¢A#cóˆ—|j|||«}|r(|dk(r|Dcgc]}|d|ddf‘Œc}S|ddSycc}w)aMatches and returns the exact match(es).
 
        If ep_only is True the result will be a string with
        the packer name. Otherwise it will be a list of the
        form (file_offset, packer_name) specifying where
        in the file the signature was found.
        FrréÿÿÿÿN©Ú_SignatureDatabase__match)rr.rrÚmatchesÚmatchs      rrKzSignatureDatabase.match–s`€ð—,‘,˜r 7Ð,>Ó?ˆñ
ؘ%Òð?FÖF°U˜˜q™ 5¨¡8¨B¡<Ò0ÒFÐFà˜1‘:˜b‘>Ð !àùò    GsŸ?cóF—|j|||«}|r |dk(r|S|dSy)z+Matches and returns all the likely matches.FrNrH)rr.rrrJs     rÚ    match_allzSignatureDatabase.match_all¯s6€ð—,‘,˜r 7Ð,>Ó?ˆá ؘ%Òðà˜1‘:Ð àrcó@—|dur=    |j}|j}|jDcgc]}|j‘Œ}}ng|dur7    |j «}|j }|jj}    |    g}n,|j}|j}tt|««}g}
|D]:} |j||| | |jz«} | sŒ(|
j| | f«Œ<|dur|
r|
dS|
S#t$r}‚d}~wwxYwcc}w#t$r}‚d}~wwxYw)NTr)rAÚ    Exceptionrr$r&Úget_memory_mapped_imagerr9r:rÚranger'Ú(_SignatureDatabase__match_signature_treerr,) rr.rrrÚexcpÚ
signaturesr2Úscan_addressesÚeprJr1Úresults              rÚ__matchzSignatureDatabase.__match¿sJ€ð  Ñ %ð
 Ø—{‘{ð ×:Ñ:ˆJðGIÇkÁkÖR¸7˜g×6Ó6ÐRˆNÑRà ˜‰_ð
 Ø×1Ñ1Ó3ð ×8Ñ8ˆJð
×#Ñ#×7Ñ7ˆBð!˜T‰Nð—;‘;ˆDà×9Ñ9ˆJä"¤3 t£9Ó-ˆNðˆØ!ò    .ˆCØ×0Ñ0ؘD  s¨T¯^©^Ñ';Ð<óˆFòØ—‘  V˜}Õ-ð     .ð d‰?ÙØ˜q‘zÐ!àˆøôyò Øûð üòSøôò Øûð ús4† C7¬D    ÁDÃ7    DÄDÄDÄ    DÄDÄDcóê—|}dg}|dur |j}n|dur |j}g}|D]:}|j||||jz«}    |    sŒ(|j    ||    f«Œ<|dur|r|dS|S)NrT)rrrRrr,)
rÚ    code_datarrrrUrTrJr1rWs
          rÚ
match_datazSignatureDatabase.match_data
s¦€àˆØ˜ˆð  Ñ %ð×:Ñ:‰Jð
˜‰_ð×8Ñ8ˆJðˆØ!ò    .ˆCØ×0Ñ0ؘD  s¨T¯^©^Ñ';Ð<óˆFòØ—‘  V˜}Õ-ð     .ð d‰?ÙØ˜q‘zÐ!àˆrc    ó—t«}|}t|Dcgc]}t|t«r|n
t    |«‘Œ!c}«D]Ó\}}|€nÌ|j |d«}    dt|j ««vrSt«}
t|j««D]} | dŒ    |
j| d«Œ|j|
«d|vrD|j dd«} ||dzd} | r(|j|j| | ||zdz««|    }ŒÕ|ndt|j ««vrSt«}
t|j««D]} | dŒ    |
j| d«Œ|j|
«|Scc}w)a
Recursive function to find matches along the signature tree.
 
        signature_tree  is the part of the tree left to walk
        data    is the data being checked against the signature tree
        depth   keeps track of how far we have gone down the tree
        Nrrz??) r"r#Ú
isinstanceÚintrBÚgetÚvaluesÚitemsr,ÚextendrR)rÚsignature_treerÚdepthÚ matched_namesrKÚbr1ÚbyteÚ
match_nextÚnamesÚitemÚmatch_tree_alternateÚdata_remainings              rÚ__match_signature_treez(SignatureDatabase.__match_signature_tree6s™€ô›ˆ ؈ô
#ÐQUÖ#VÈA¬°A´sÔ);¡AÄÀQÃÑ$GÒ#VÓWò+    ‰IˆCðˆ}Ù🙠4¨Ó.ˆJð ”t˜EŸL™L›NÓ+Ñ+ô›ô ! §¡£Ó/ò.DؘA‘w‘ØŸ ™  T¨!¡WÕ-ð.ð×$Ñ$ UÔ+ð
u‰}Ø',§y¡y°°tÓ'<Ð$Ø!% c¨A¡g i Ù!Ø!×(Ñ(Ø×3Ñ3Ø0°.À#ÈÁ+ÐPQÁ/óôð ‰EðW+    ð` Ð  ¬¨e¯l©l«nÓ)=Ñ!=ä“FˆEܘUŸ[™[›]Ó+ò *Ø˜‘7‘?Ø—L‘L  a¡Õ)ð *ð ×  Ñ   Ô 'àÐùòq$Ws–$F    có*—|j||¬«y)znLoad a PEiD signature file.
 
        Invoking this method on different files combines the signatures.
        rN)rrs   rÚloadzSignatureDatabase.load~s€ð       ‰ ˜X¨Dˆ Õ1rcó¤—|Žtjj|«sA    tjj |«}|j «}|j«n0    t|d«}|j «}|j«n|}|syd„}|jj|«}|D]v\}}}    }
} |
j«j«}
|jdd«j«}|j«D cgc]
} || «‘Œ } } |
dk(rd}
nd}
| dk(rd} nd} d}| dur"|j }|xj"d    z c_nG|
dur"|j$}|xj&d    z c_n!|j(}|xj*d    z c_t-| «D]c\}}|d    zt/| «k(r&|j1|t3««||<d|||<n|j1|t3««||<||}|d    z }Œe||j4kDsŒp||_Œyy#t$r‚wxYw#t$r‚wxYwcc} w)
NÚrtcó&—d|vr|St|d«S)Nú?é)r^)Úvalues rÚto_bytez)SignatureDatabase.__load.<locals>.to_byte¨s€Øe‰|ؐ ܐu˜b“>Ð !rz\nrr>TFrr)ÚosÚpathÚexistsÚurllibÚrequestÚurlopenÚreadÚcloseÚIOErrorÚopenr ÚfindallÚstripÚlowerÚreplaceÚsplitrrrrrrr#r'r_r r)rrrÚsig_fÚsig_datarvrJÚ packer_namerDÚsuperfluous_wildcardsrrrfrCrdÚtreer1rgs                  rÚ__loadzSignatureDatabase.__load†sS€à Ð ô—7‘7—>‘> (Ô+ðÜ"ŸN™N×2Ñ2°8Ó<EØ$Ÿz™z›|HØ—K‘K•MðÜ  ¨4Ó0EØ$Ÿz™z›|HØ—K‘K•Mð
ˆHñ
Ø ò    "ð—.‘.×(Ñ(¨Ó2ˆðó 6    'ñ
Ø Ø Ø !Ø Ø ð—m‘m“o×+Ñ+Ó-ˆGà!×)Ñ)¨%°Ó4×:Ñ:Ó<ˆIà3<·?±?Ó3DÖE¨a™w qzÐEˆOÐEà˜&Ò Ø‘àà! VÒ+Ø%)Ñ"à%*Ð"àˆEà! TÑ)à×8Ñ8Ø×2Ò2°aÑ7Ö2ð˜d‘?Ø×:Ñ:DØ×4Ò4¸Ñ9Ö4à×;Ñ;DØ×5Ò5¸Ñ:Õ5ä& Ó7ò ‘    Tà˜‘7œc /Ó2Ò2à!%§¡¨$´³Ó!7D˜‘JØ.2D˜‘J˜{Ò+ð"&§¡¨$´³Ó!7D˜‘Jà˜D‘zØ˜‘
‘ð ðt—~‘~Ô%Ø!&–ñm6    'øôIòàðûôòàðüòLFs£?H1Á$,H?ÄI È1 H<È? I
)NN)é)FFrŒ)TF)r)Ú__name__Ú
__module__Ú __qualname__Ú__doc__rr6r;r-rKrMrIr[rRror©rrrrsM„ñó" 2óD$4óL 
ðUXóó6ó2ò IóV*óXFóP2ôd'rrcó—y)rNr‘)r.s rÚis_validr“ís€àrcój—d}d}t|d«r|jD]~}d}|jD]k}|j|jj
cxkr|jdzkrnnd}| ||jcxkr|dzkrnn|dz }|j}ŒmŒ€d}|j «}|r|y)zp
    unusual locations of import tables
    non recognized section names
    presence of long ASCII strings
    FrÚDIRECTORY_ENTRY_BASERELOCNéTr)Úhasattrr•ÚentriesÚrvar9r:Ú get_warnings)r.Úrelocations_overlap_entry_pointÚsequential_relocsÚ
base_relocÚlast_reloc_rvaÚrelocÚwarnings_while_parsingÚwarningss        rÚ is_suspiciousr¢òsˀð',Ð#ØÐô ˆrÐ.Ô/Ø×6Ñ6ò     +ˆJØ!ˆNØ#×+Ñ+ò
+Ø—9‘9 × 2Ñ 2× FÑ FÔWÈ%Ï)É)ÐVWÉ-ÕWØ6:Ð3ð#Ð.Ø&¨%¯)©)ÔI°~ÈÑ7IÕIà%¨Ñ*Ð%à!&§¡‘ñ
+ð     +ð&#Ðð‰Ó €HÙÙð    rcóä—t|j««}|syd}d}|jD]6}|j«}t|j    ««}|dkDsŒ2||z }Œ8||z dkDrd}|S)a8Returns True is there is a high likelihood that a file is packed or contains compressed data.
 
    The sections of the PE file will be analyzed, if enough sections
    look like containing compressed data and the data makes
    up for more than 20% of the total file size, the function will
    return True.
    TFrgš™™™™™@gš™™™™™É?)r'Útrimr$Ú get_entropyÚget_data)r.Útotal_pe_data_lengthÚ)has_significant_amount_of_compressed_dataÚtotal_compressed_datar2Ú    s_entropyÚs_lengths       rÚis_probably_packedr¬(sŒ€ô˜rŸw™w›y›>Ðá ØØ05Ð-ð
ÐØ—;‘;ò.ˆØ×'Ñ'Ó)ˆ    Üw×'Ñ'Ó)Ó*ˆð s‹?Ø ! XÑ -Ñ !ð .ð    Р4Ñ4¸Ò;Ø48Ð1à 4Ð4r)rrwr    r*Úurllib.requestrzÚ urllib.parseÚ urllib.errorÚpefileÚ
__author__Ú __version__Ú __contact__Úobjectrr“r¢r¬r‘rrú<module>rµsRðñó
Û    Û ß1Ó1Û à €
Ø× Ñ € Ø%€ ôV'˜ôV'òr    ò
3    ól!5r