Skip to content

Instantly share code, notes, and snippets.

@jorsn
Last active April 13, 2020 14:46
Show Gist options
  • Save jorsn/bc1570c6f65911c1acc7ef14bb9c1d11 to your computer and use it in GitHub Desktop.
Save jorsn/bc1570c6f65911c1acc7ef14bb9c1d11 to your computer and use it in GitHub Desktop.
#!/bin/sh
self="$(basename "$0")"
warn() {
# !!! WARNING: don't ever feed user-supplied args into this function !!!
fmt="${1%\\n}\\n"
shift
# disable warning about variables in format string
# shellcheck disable=SC2059
printf "$fmt" "$@" >&2
}
error() {
e="${1:-1}"
fmt="%s: $2"
shift; shift
warn "$fmt" "$self" "$@"
exit "$e"
}
usage() {
warn '\e[1mUsage\e[0m: %s [-d|--dereference] \e[4mfile\e[0m \e[4mlibs\e[0m' "$self"
warn ' check whether \e[4mfile\e[0m is linked against \e[4mlibs\e[0m (egrep regex)'
exit "${1:-0}"
}
case "$1" in
-h | --help )
usage
;;
-d | --dereference )
deref_arg="$1"
shift
;;
esac
if [ "$#" != 2 ]; then
usage 1
fi
file="$1"
libs="$2"
if [ ! -e "$file" ]; then
error 2 '%s: file not found' "$file"
elif ! iself $deref_arg "$file"; then
error 3 '%s: not an ELF file' "$file"
fi
ldd "$file" | grep -Eo "$libs" | sort -u
#!/bin/sh
self="$(basename "$0")"
warn() {
# !!! WARNING: don't ever feed user-supplied args into this function !!!
fmt="${1%\\n}\\n"
shift
# disable warning about variables in format string
# shellcheck disable=SC2059
printf "$fmt" "$@" >&2
}
error() {
e="${1:-1}"
fmt="%s: $2"
shift; shift
warn "$fmt" "$self" "$@"
exit "$e"
}
usage() {
warn '\e[1mUsage\e[0m: %s [-d|--dereference] \e[4mfile\e[0m' "$self"
exit "${1:-0}"
}
deref=false
case "$1" in
-h | --help )
usage
;;
-d | --dereference )
deref=true
shift
;;
esac
if [ "$#" != 1 ]; then
usage 1
fi
file="$1"
[ -f "$file" ] && ( $deref || [ ! -L "$file" ] ) && [ "$(dd status=none bs=1 skip=1 count=3 if="$file")" = ELF ]
exit $?
#!/bin/sh
self="$(basename "$0")"
warn() {
# !!! WARNING: don't ever feed user-supplied args into this function !!!
fmt="${1%\\n}\\n"
shift
# disable warning about variables in format string
# shellcheck disable=SC2059
printf "$@" >&2
}
error() {
e="${1:-1}"
fmt="%s: $2"
shift; shift
warn "$fmt" "$self" "$@"
exit "$e"
}
usage() {
warn '\e[1mUsage\e[0m: %s \e[4mpackage\e[0m \e[4mlibs\e[0m' "$self"
warn ' check whether binaries or libraries in \e[4mpackage\e[0m'
warn ' are linked against \e[4mlibs\e[0m (egrep regex)'
exit "${1:-0}"
}
if [ "$1" = -h ] || [ "$1" = --help ]; then
usage
elif [ "$#" != 2 ]; then
usage 1
fi
pkg="$1"
libs="$2"
if ! files="$(pacman -Ql "$pkg")"; then
error 4 '%s: package query failed' "$pkg"
fi
files="$(echo "$files" | awk '{print $2}' | grep -E '(/bin/|.+\.so)')"
for file in $files; do
iself "$file" || continue
# disable warning about expansion of $bsubs as it is no shell variable
# shellcheck disable=SC2016
linked="$(checklibs "$file" "$libs" | sed -e :loop -e '$bsubs' -e N -e bloop -e :subs -e 's/\n/ /g' -e 's/^\s\+$//g')"
if [ -n "$linked" ]; then
echo "${file}: $linked"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment