Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions contrib/devtools/symbol-check.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,18 @@ def check_MACHO_libraries(filename) -> bool:
ok = False
return ok

def check_MACHO_min_os(filename) -> bool:
binary = lief.parse(filename)
if binary.build_version.minos == [10,14,0]:
return True
return False

def check_MACHO_sdk(filename) -> bool:
binary = lief.parse(filename)
if binary.build_version.sdk == [10, 15, 6]:
return True
return False

def check_PE_libraries(filename) -> bool:
ok: bool = True
binary = lief.parse(filename)
Expand All @@ -221,17 +233,28 @@ def check_PE_libraries(filename) -> bool:
ok = False
return ok

def check_PE_subsystem_version(filename) -> bool:
binary = lief.parse(filename)
major: int = binary.optional_header.major_subsystem_version
minor: int = binary.optional_header.minor_subsystem_version
if major == 6 and minor == 1:
return True
return False

CHECKS = {
'ELF': [
('IMPORTED_SYMBOLS', check_imported_symbols),
('EXPORTED_SYMBOLS', check_exported_symbols),
('LIBRARY_DEPENDENCIES', check_ELF_libraries)
],
'MACHO': [
('DYNAMIC_LIBRARIES', check_MACHO_libraries)
('DYNAMIC_LIBRARIES', check_MACHO_libraries),
('MIN_OS', check_MACHO_min_os),
('SDK', check_MACHO_sdk),
],
'PE' : [
('DYNAMIC_LIBRARIES', check_PE_libraries)
('DYNAMIC_LIBRARIES', check_PE_libraries),
('SUBSYSTEM_VERSION', check_PE_subsystem_version),
]
}

Expand Down
35 changes: 31 additions & 4 deletions contrib/devtools/test-symbol-check.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_MACHO(self):

self.assertEqual(call_symbol_check(cc, source, executable, ['-lexpat']),
(1, 'libexpat.1.dylib is not in ALLOWED_LIBRARIES!\n' +
executable + ': failed DYNAMIC_LIBRARIES'))
f'{executable}: failed DYNAMIC_LIBRARIES MIN_OS SDK'))

source = 'test2.c'
executable = 'test2'
Expand All @@ -114,7 +114,20 @@ def test_MACHO(self):
''')

self.assertEqual(call_symbol_check(cc, source, executable, ['-framework', 'CoreGraphics']),
(0, ''))
(1, f'{executable}: failed MIN_OS SDK'))

source = 'test3.c'
executable = 'test3'
with open(source, 'w', encoding="utf8") as f:
f.write('''
int main()
{
return 0;
}
''')

self.assertEqual(call_symbol_check(cc, source, executable, ['-mmacosx-version-min=10.14']),
(1, f'{executable}: failed SDK'))

def test_PE(self):
source = 'test1.c'
Expand All @@ -132,12 +145,26 @@ def test_PE(self):
}
''')

self.assertEqual(call_symbol_check(cc, source, executable, ['-lpdh']),
self.assertEqual(call_symbol_check(cc, source, executable, ['-lpdh', '-Wl,--major-subsystem-version', '-Wl,6', '-Wl,--minor-subsystem-version', '-Wl,1']),
(1, 'pdh.dll is not in ALLOWED_LIBRARIES!\n' +
executable + ': failed DYNAMIC_LIBRARIES'))

source = 'test2.c'
executable = 'test2.exe'

with open(source, 'w', encoding="utf8") as f:
f.write('''
int main()
{
return 0;
}
''')

self.assertEqual(call_symbol_check(cc, source, executable, ['-Wl,--major-subsystem-version', '-Wl,9', '-Wl,--minor-subsystem-version', '-Wl,9']),
(1, executable + ': failed SUBSYSTEM_VERSION'))

source = 'test3.c'
executable = 'test3.exe'
with open(source, 'w', encoding="utf8") as f:
f.write('''
#include <windows.h>
Expand All @@ -149,7 +176,7 @@ def test_PE(self):
}
''')

self.assertEqual(call_symbol_check(cc, source, executable, ['-lole32']),
self.assertEqual(call_symbol_check(cc, source, executable, ['-lole32', '-Wl,--major-subsystem-version', '-Wl,6', '-Wl,--minor-subsystem-version', '-Wl,1']),
(0, ''))


Expand Down
2 changes: 1 addition & 1 deletion contrib/gitian-descriptors/gitian-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ script: |
done
}

pip3 install lief==0.11.4
pip3 install lief==0.11.5

# Faketime for depends so intermediate results are comparable
export PATH_orig=${PATH}
Expand Down
2 changes: 1 addition & 1 deletion contrib/gitian-descriptors/gitian-osx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ script: |
done
}

pip3 install lief==0.11.4
pip3 install lief==0.11.5

# Faketime for depends so intermediate results are comparable
export PATH_orig=${PATH}
Expand Down
2 changes: 1 addition & 1 deletion contrib/gitian-descriptors/gitian-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ script: |
done
}

pip3 install lief==0.11.4
pip3 install lief==0.11.5

# Faketime for depends so intermediate results are comparable
export PATH_orig=${PATH}
Expand Down
4 changes: 2 additions & 2 deletions contrib/guix/manifest.scm
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ chain for " target " development."))
(define-public lief
(package
(name "python-lief")
(version "0.11.4")
(version "0.11.5")
(source
(origin
(method git-fetch)
Expand All @@ -215,7 +215,7 @@ chain for " target " development."))
(file-name (git-file-name name version))
(sha256
(base32
"0h4kcwr9z478almjqhmils8imfpflzk0r7d05g4xbkdyknn162qf"))))
"0qahjfg1n0x76ps2mbyljvws1l3qhkqvmxqbahps4qgywl2hbdkj"))))
(build-system python-build-system)
(native-inputs
`(("cmake" ,cmake)))
Expand Down