-
Notifications
You must be signed in to change notification settings - Fork 34
/
elf-deps
executable file
·72 lines (59 loc) · 1.38 KB
/
elf-deps
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
usage() {
bin=$(basename $0)
echo >&2 "Usage: $bin { objdump-deps | objdump-pkgs | ldd-deep | ldd-deep-pkgs } [args]"
exit ${1:-0}
}
[[ -z "$1" || "$1" = -h || "$1" = --help ]] && usage
cmd=$1; shift
resolve_pkgs=
set -e -o pipefail
export LC_ALL=C
if [[ "$cmd" =~ ^objdump-(deps|pkgs)$ ]]; then
libs=( $(
for p in "$@"; do
objdump -x "$p" |
awk '$1=="NEEDED" {print $2}' |
xargs locate
done ) )
[[ "$cmd" != objdump-deps ]] || {
for lib in "${libs[@]}"; do echo "$lib"; done | sort -u
exit 0
}
resolve_pkgs=t
fi
if [[ "$cmd" =~ ^ldd-deep(-pkgs)?$ ]]; then
declare -A deps
echo_deps() {
while read dep
do
k="$(basename "$dep")"
[[ -z "${deps[$k]}" ]] || continue
deps[$k]=$dep
echo "$dep"
echo_deps "$dep"
done < <(
set -o pipefail
ldd "$1" 2>/dev/null |
awk '/linux-gate/ {next}
$3 {print $3; next}
match($1,/^\//) {print $1}'
[[ $? -ne 0 ]] && echo "${1}-ldd-fail" )
}
libs=( $(for p in "$@"; do echo_deps "$p"; done) )
[[ "$cmd" != ldd-deep ]] || {
for lib in "${libs[@]}"; do echo "$lib"; done | sort -u
exit 0
}
resolve_pkgs=t
fi
[[ -z "$resolve_pkgs" ]] || {
for lib in "${libs[@]}"; do
[[ "$lib" =~ ^/usr ]] || continue
pacman -Qo "$lib" |
awk 'match($0,/is owned by (\S+)\s/,m) {print m[1]; exit 0} {print; exit 1}' ||:
done | sort -u
exit 0
}
echo >&2 "Unrecognized command: $cmd"
exit 1