Skip to content

Commit 061acf6

Browse files
committed
scripts: no-longer check for 32 bit windows in security-check.py
1 parent 04c0955 commit 061acf6

File tree

1 file changed

+10
-23
lines changed

1 file changed

+10
-23
lines changed

contrib/devtools/security-check.py

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -116,47 +116,34 @@ def check_ELF_Canary(executable):
116116
ok = True
117117
return ok
118118

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'''
125121
p = subprocess.Popen([OBJDUMP_CMD, '-x', executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True)
126122
(stdout, stderr) = p.communicate()
127123
if p.returncode:
128124
raise IOError('Error opening file')
129-
arch = ''
130125
bits = 0
131126
for line in stdout.splitlines():
132127
tokens = line.split()
133-
if len(tokens)>=2 and tokens[0] == 'architecture:':
134-
arch = tokens[1].rstrip(',')
135128
if len(tokens)>=2 and tokens[0] == 'DllCharacteristics':
136129
bits = int(tokens[1],16)
137-
return (arch,bits)
130+
return bits
138131

139132
IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA = 0x0020
140133
IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE = 0x0040
141134
IMAGE_DLL_CHARACTERISTICS_NX_COMPAT = 0x0100
142135

143136
def check_PE_DYNAMIC_BASE(executable):
144137
'''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
148140

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.
151143
def check_PE_HIGH_ENTROPY_VA(executable):
152144
'''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
160147

161148
def check_PE_RELOC_SECTION(executable) -> bool:
162149
'''Check for a reloc section. This is required for functional ASLR.'''
@@ -171,7 +158,7 @@ def check_PE_RELOC_SECTION(executable) -> bool:
171158

172159
def check_PE_NX(executable):
173160
'''NX: DllCharacteristics bit 0x100 signifies nxcompat (DEP)'''
174-
(arch,bits) = get_PE_dll_characteristics(executable)
161+
bits = get_PE_dll_characteristics(executable)
175162
return (bits & IMAGE_DLL_CHARACTERISTICS_NX_COMPAT) == IMAGE_DLL_CHARACTERISTICS_NX_COMPAT
176163

177164
def get_MACHO_executable_flags(executable):

0 commit comments

Comments
 (0)