Skip to content

Instantly share code, notes, and snippets.

@gonoph
Last active July 23, 2024 14:43
Show Gist options
  • Save gonoph/84bbd137fb62a6a2c1d5ba1b27e635e6 to your computer and use it in GitHub Desktop.
Save gonoph/84bbd137fb62a6a2c1d5ba1b27e635e6 to your computer and use it in GitHub Desktop.
getldd - script to recursively extract all the shared libraries of an elf executable
#!/bin/sh
# usage: ./getldd mybinary
# will hard copy all the shared libs to
DEPS=/tmp/deps.txt
getldd() {
for i in $(ldd $1 | grep / | xargs echo) ; do
test -r "$i" && realpath "$i" && getldd $i
done
}
realpath $1 > $DEPS
getldd $1 | sort -u >> $DEPS
cat<<EOF
All the deps:
######
$(cat $DEPS)
######
To copy all the deps, do something like:
for i in \$(cat $DEPS) ; do mkdir -p /tmp/mydest/\$(dirname \$i) && cp -va \$i /tmp/mydest/\$i ; done
EOF
@gonoph
Copy link
Author

gonoph commented Jul 23, 2024

modified script to use the absolute filename.

Also included the binary on the command line as part of the list of dependencies to simplify the output logic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment