Skip to content

Commit e93ac26

Browse files
committed
contrib: use LIEF in macOS symbol checks
1 parent a632cbc commit e93ac26

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

contrib/devtools/symbol-check.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import os
1616
from typing import List, Optional
1717

18+
import lief
1819
import pixie
1920

2021
# Debian 8 (Jessie) EOL: 2020. https://wiki.debian.org/DebianReleases#Production_Releases
@@ -53,7 +54,6 @@
5354
}
5455
CPPFILT_CMD = os.getenv('CPPFILT', '/usr/bin/c++filt')
5556
OBJDUMP_CMD = os.getenv('OBJDUMP', '/usr/bin/objdump')
56-
OTOOL_CMD = os.getenv('OTOOL', '/usr/bin/otool')
5757

5858
# Allowed NEEDED libraries
5959
ELF_ALLOWED_LIBRARIES = {
@@ -203,24 +203,13 @@ def check_ELF_libraries(filename) -> bool:
203203
ok = False
204204
return ok
205205

206-
def macho_read_libraries(filename) -> List[str]:
207-
p = subprocess.Popen([OTOOL_CMD, '-L', filename], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True)
208-
(stdout, stderr) = p.communicate()
209-
if p.returncode:
210-
raise IOError('Error opening file')
211-
libraries = []
212-
for line in stdout.splitlines():
213-
tokens = line.split()
214-
if len(tokens) == 1: # skip executable name
215-
continue
216-
libraries.append(tokens[0].split('/')[-1])
217-
return libraries
218-
219206
def check_MACHO_libraries(filename) -> bool:
220207
ok: bool = True
221-
for dylib in macho_read_libraries(filename):
222-
if dylib not in MACHO_ALLOWED_LIBRARIES:
223-
print('{} is not in ALLOWED_LIBRARIES!'.format(dylib))
208+
binary = lief.parse(filename)
209+
for dylib in binary.libraries:
210+
split = dylib.name.split('/')
211+
if split[-1] not in MACHO_ALLOWED_LIBRARIES:
212+
print(f'{split[-1]} is not in ALLOWED_LIBRARIES!')
224213
ok = False
225214
return ok
226215

0 commit comments

Comments
 (0)