Skip to content

Commit 2aa1631

Browse files
committed
contrib: use LIEF in PE symbol checks
1 parent e93ac26 commit 2aa1631

File tree

1 file changed

+3
-15
lines changed

1 file changed

+3
-15
lines changed

contrib/devtools/symbol-check.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
'environ', '_environ', '__environ',
5454
}
5555
CPPFILT_CMD = os.getenv('CPPFILT', '/usr/bin/c++filt')
56-
OBJDUMP_CMD = os.getenv('OBJDUMP', '/usr/bin/objdump')
5756

5857
# Allowed NEEDED libraries
5958
ELF_ALLOWED_LIBRARIES = {
@@ -213,23 +212,12 @@ def check_MACHO_libraries(filename) -> bool:
213212
ok = False
214213
return ok
215214

216-
def pe_read_libraries(filename) -> List[str]:
217-
p = subprocess.Popen([OBJDUMP_CMD, '-x', filename], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True)
218-
(stdout, stderr) = p.communicate()
219-
if p.returncode:
220-
raise IOError('Error opening file')
221-
libraries = []
222-
for line in stdout.splitlines():
223-
if 'DLL Name:' in line:
224-
tokens = line.split(': ')
225-
libraries.append(tokens[1])
226-
return libraries
227-
228215
def check_PE_libraries(filename) -> bool:
229216
ok: bool = True
230-
for dylib in pe_read_libraries(filename):
217+
binary = lief.parse(filename)
218+
for dylib in binary.libraries:
231219
if dylib not in PE_ALLOWED_LIBRARIES:
232-
print('{} is not in ALLOWED_LIBRARIES!'.format(dylib))
220+
print(f'{dylib} is not in ALLOWED_LIBRARIES!')
233221
ok = False
234222
return ok
235223

0 commit comments

Comments
 (0)