@@ -116,47 +116,34 @@ def check_ELF_Canary(executable):
116
116
ok = True
117
117
return ok
118
118
119
- def get_PE_dll_characteristics (executable ):
120
- '''
121
- Get PE DllCharacteristics bits.
122
- Returns a tuple (arch,bits) where arch is 'i386:x86-64' or 'i386'
123
- and bits is the DllCharacteristics value.
124
- '''
119
+ def get_PE_dll_characteristics (executable ) -> int :
120
+ '''Get PE DllCharacteristics bits'''
125
121
p = subprocess .Popen ([OBJDUMP_CMD , '-x' , executable ], stdout = subprocess .PIPE , stderr = subprocess .PIPE , stdin = subprocess .PIPE , universal_newlines = True )
126
122
(stdout , stderr ) = p .communicate ()
127
123
if p .returncode :
128
124
raise IOError ('Error opening file' )
129
- arch = ''
130
125
bits = 0
131
126
for line in stdout .splitlines ():
132
127
tokens = line .split ()
133
- if len (tokens )>= 2 and tokens [0 ] == 'architecture:' :
134
- arch = tokens [1 ].rstrip (',' )
135
128
if len (tokens )>= 2 and tokens [0 ] == 'DllCharacteristics' :
136
129
bits = int (tokens [1 ],16 )
137
- return ( arch , bits )
130
+ return bits
138
131
139
132
IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA = 0x0020
140
133
IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE = 0x0040
141
134
IMAGE_DLL_CHARACTERISTICS_NX_COMPAT = 0x0100
142
135
143
136
def check_PE_DYNAMIC_BASE (executable ):
144
137
'''PIE: DllCharacteristics bit 0x40 signifies dynamicbase (ASLR)'''
145
- (arch ,bits ) = get_PE_dll_characteristics (executable )
146
- reqbits = IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE
147
- return (bits & reqbits ) == reqbits
138
+ bits = get_PE_dll_characteristics (executable )
139
+ return (bits & IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE ) == IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE
148
140
149
- # On 64 bit, must support high-entropy 64-bit address space layout randomization in addition to DYNAMIC_BASE
150
- # to have secure ASLR.
141
+ # Must support high-entropy 64-bit address space layout randomization
142
+ # in addition to DYNAMIC_BASE to have secure ASLR.
151
143
def check_PE_HIGH_ENTROPY_VA (executable ):
152
144
'''PIE: DllCharacteristics bit 0x20 signifies high-entropy ASLR'''
153
- (arch ,bits ) = get_PE_dll_characteristics (executable )
154
- if arch == 'i386:x86-64' :
155
- reqbits = IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA
156
- else : # Unnecessary on 32-bit
157
- assert (arch == 'i386' )
158
- reqbits = 0
159
- return (bits & reqbits ) == reqbits
145
+ bits = get_PE_dll_characteristics (executable )
146
+ return (bits & IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA ) == IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA
160
147
161
148
def check_PE_RELOC_SECTION (executable ) -> bool :
162
149
'''Check for a reloc section. This is required for functional ASLR.'''
@@ -171,7 +158,7 @@ def check_PE_RELOC_SECTION(executable) -> bool:
171
158
172
159
def check_PE_NX (executable ):
173
160
'''NX: DllCharacteristics bit 0x100 signifies nxcompat (DEP)'''
174
- ( arch , bits ) = get_PE_dll_characteristics (executable )
161
+ bits = get_PE_dll_characteristics (executable )
175
162
return (bits & IMAGE_DLL_CHARACTERISTICS_NX_COMPAT ) == IMAGE_DLL_CHARACTERISTICS_NX_COMPAT
176
163
177
164
def get_MACHO_executable_flags (executable ):
0 commit comments