1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import subprocess
import sys
null = open(os.devnull, "w")
def otool(name):
try:
return subprocess.check_output(["otool", "-L", name], stderr=null).decode(
"utf-8"
)
except Exception:
return ""
def process(name, seen, depth=0):
if name in seen:
return
seen.add(name)
if name.endswith(".dylib"):
print(f"{' ' * depth}{name}")
deps = otool(name)
for line in deps.split("\n"):
line = line.strip()
if line.endswith(":"):
continue
bits = line.split()
if len(bits) < 1:
continue
lib = bits[0]
if lib.startswith("@"):
continue
if name == lib:
continue
process(lib, seen, depth + 2)
for n in sys.argv[1:]:
process(n, set())
|