From 2aa1631822b2fdbc6cf7a3dcd99adaf4d2745ed4 Mon Sep 17 00:00:00 2001 From: fanquake Date: Tue, 6 Apr 2021 10:18:07 +0800 Subject: contrib: use LIEF in PE symbol checks --- contrib/devtools/symbol-check.py | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) (limited to 'contrib') diff --git a/contrib/devtools/symbol-check.py b/contrib/devtools/symbol-check.py index a4ada73573..d740a94560 100755 --- a/contrib/devtools/symbol-check.py +++ b/contrib/devtools/symbol-check.py @@ -53,7 +53,6 @@ IGNORE_EXPORTS = { 'environ', '_environ', '__environ', } CPPFILT_CMD = os.getenv('CPPFILT', '/usr/bin/c++filt') -OBJDUMP_CMD = os.getenv('OBJDUMP', '/usr/bin/objdump') # Allowed NEEDED libraries ELF_ALLOWED_LIBRARIES = { @@ -213,23 +212,12 @@ def check_MACHO_libraries(filename) -> bool: ok = False return ok -def pe_read_libraries(filename) -> List[str]: - p = subprocess.Popen([OBJDUMP_CMD, '-x', filename], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True) - (stdout, stderr) = p.communicate() - if p.returncode: - raise IOError('Error opening file') - libraries = [] - for line in stdout.splitlines(): - if 'DLL Name:' in line: - tokens = line.split(': ') - libraries.append(tokens[1]) - return libraries - def check_PE_libraries(filename) -> bool: ok: bool = True - for dylib in pe_read_libraries(filename): + binary = lief.parse(filename) + for dylib in binary.libraries: if dylib not in PE_ALLOWED_LIBRARIES: - print('{} is not in ALLOWED_LIBRARIES!'.format(dylib)) + print(f'{dylib} is not in ALLOWED_LIBRARIES!') ok = False return ok -- cgit v1.2.3