Skip to content

Instantly share code, notes, and snippets.

@rootmos
Last active May 22, 2019 05:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rootmos/fda9ad6c3a72c6b2fce2b89f8c5267b2 to your computer and use it in GitHub Desktop.
Save rootmos/fda9ad6c3a72c6b2fce2b89f8c5267b2 to your computer and use it in GitHub Desktop.
Usage: ld-finder-outer.sh python -c 'print("hello?")'
#!/bin/bash
set -o nounset -o pipefail -o errexit
TRACE=$(mktemp)
trap "rm -f $TRACE" EXIT
EXEC=$(which "$1")
shift 1
interpreter() {
readelf --program-headers "$1" |
grep -o '\[Requesting program interpreter:\s\+[^]]\+\]' |
sed 's/\[Requesting program interpreter:\s\+\([^]]\+\)]/\1/'
}
set +o errexit
strace -D -o "$TRACE" -f -e trace=%file \
$(interpreter "$EXEC") "$EXEC" "$@"
EXIT=$?
set -o errexit
grep -o '"[^"]\+\.so[^"]*"' "$TRACE" \
| sed 's/^"\(.*\)"/\1/' | sort -u \
| while read f; do
if ldd "$f" &>/dev/null; then
echo "$f"
fi
done
exit $EXIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment