Created
February 9, 2014 08:11
-
-
Save drkibitz/8896013 to your computer and use it in GitHub Desktop.
Recursively list paths of shared libraries required by given binary. Usage: `otool-ls-r /bin/bash`
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
#!/bin/bash | |
list="" | |
otool_list() { | |
local lib="$1" | |
local libs="" | |
if [[ "$list" == "${list/:$lib/}" ]]; then | |
echo "$lib" | |
list="$list:$lib" | |
libs=$(otool -L "$lib" | sed -n 's/^ \(.*\) (compatibility version.*$/\1/p') | |
for lib in $libs | |
do | |
otool_list "$lib" | |
done | |
fi | |
} | |
otool_list "$@" |
Thanks for sharing this. It didn't work for me, but this did:
#!/usr/bin/env ruby
def otool(path)
`otool -L "#{path}"`.split("\n").grep(/compatibility version/).map { |l| l.strip.scan(/(.*?) \(compatibility version/)[0][0] }
end
def recurse(starting_point, found = {})
otool(starting_point).each do |shared_lib|
if !found[shared_lib]
found[shared_lib] = true
recurse(shared_lib, found)
end
end
found
end
found = recurse(ARGV[0])
puts found.keys.join("\n")
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Copy everything from list to current directory: