Skip to content

Instantly share code, notes, and snippets.

@david0
Created December 15, 2015 19:05
Show Gist options
  • Save david0/34d1bbd280610ee48255 to your computer and use it in GitHub Desktop.
Save david0/34d1bbd280610ee48255 to your computer and use it in GitHub Desktop.
magic install name fixing tool
#!/usr/bin/env python3
# Try to fix library names by looking them up
from subprocess import check_output
import re
from os import system
from os.path import basename, exists
from sys import argv
from glob import glob
if len(argv) < 3:
print("USAGE: %s [binary] [search directory for libs]" % argv[0])
exit(-1)
bin = argv[1]
libdir = argv[2]
print("Checking %s" % bin)
libs = {}
for lib in glob("%s/**/*.dylib" % libdir, recursive=True):
libs[basename(lib)] = lib
out = check_output("otool -L %s" % bin, shell=True).strip()
files = []
for line in out.decode('ascii').split("\n"):
if line.startswith("\t"):
files += [line.strip().split("(")[0].strip()]
for path in files:
if not exists(path):
name = basename(path)
if name in libs:
newPath = libs[name]
print("%s -> %s" % (path, newPath))
system("install_name_tool -change %s %s %s" % (path, newPath, bin))
else:
print("not fixed: %s" % path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment