Skip to content

Instantly share code, notes, and snippets.

@tingletech
Last active August 29, 2015 14:02
Show Gist options
  • Save tingletech/97ebe2b618634fa02147 to your computer and use it in GitHub Desktop.
Save tingletech/97ebe2b618634fa02147 to your computer and use it in GitHub Desktop.
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