142
142
]
143
143
)
144
144
145
+ exec_magics = OrderedDict (
146
+ [
147
+ ("PE32 executable (DLL)" , "dll" ),
148
+ ("PE32+ executable (DLL)" , "dll" ),
149
+ ("MS-DOS executable PE32 executable (DLL)" , "dll" ),
150
+ ("PE32 executable" , "exe" ),
151
+ ("PE32+ executable" , "exe" ),
152
+ ("MS-DOS executable, MZ for MS-DOS" , "exe" ),
153
+ ]
154
+ )
155
+
145
156
magics = OrderedDict (
146
157
[
147
158
# ToDo msdos
@@ -609,6 +620,18 @@ def identify(f, check_shellcode: bool = False):
609
620
if not f .stream .read (0x1000 ):
610
621
return
611
622
623
+ if is_executable (f ):
624
+ # to reduce number of checks
625
+ for magic_types in exec_magics :
626
+ if f .magic .startswith (magic_types ):
627
+ # MS-DOS executable PE32 executable (DLL) (GUI) Intel 80386, for MS Windows
628
+ # MZ for MS-DOS -> MS-DOS executable
629
+ # MZ for MS-DOS -> but is DLL
630
+ package = exec_magics [magic_types ]
631
+ if package in ("exe" , "dll" ):
632
+ pe = pefile .PE (data = f .contents , fast_load = True )
633
+ return "dll" if pe .is_dll () else "exe"
634
+
612
635
if f .filename :
613
636
for package , extensions in file_extensions .items ():
614
637
if f .filename .endswith (extensions ) and not f .contents .startswith (b"MZ" ):
@@ -634,6 +657,7 @@ def identify(f, check_shellcode: bool = False):
634
657
package = identifier (f )
635
658
if package :
636
659
return package
660
+
637
661
for magic_types in magics :
638
662
if f .magic .startswith (magic_types ):
639
663
# MS-DOS executable PE32 executable (DLL) (GUI) Intel 80386, for MS Windows
0 commit comments