Last active
August 29, 2015 14:02
-
-
Save tingletech/97ebe2b618634fa02147 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import re | |
from collections import defaultdict | |
import sys | |
def sanity_check_ldd(path): | |
parse_ldd = re.compile('^\t(.*?)\\.') # parse ldd outout | |
d = defaultdict(bool) | |
# look for duplicate libraries | |
try: # ldd might not exist (as on OS X) | |
for line in subprocess.check_output(['ldd', path]).split('\n'): | |
if line == '': | |
break | |
lib = parse_ldd.search(line).group(0) | |
# http://youtu.be/SckD99B51IA?t=22s | |
assert not(lib in d), "dubious binary, ldd finds more than one {0}".format(lib) | |
d[lib] = True | |
except OSError: | |
# is this OSX? try running `otool`? | |
pass | |
if __name__ == "__main__": | |
sys.exit(sanity_check_ldd(sys.argv[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment