mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 02:33:24 -03:00
contrib: use LIEF in PE symbol checks
This commit is contained in:
parent
e93ac26b85
commit
2aa1631822
1 changed files with 3 additions and 15 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue