-
Notifications
You must be signed in to change notification settings - Fork 11
/
check-so-resolves
executable file
·47 lines (38 loc) · 1.21 KB
/
check-so-resolves
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
#!/bin/bash
# Description: Recursively scans /opt for ELF files and checks for unresolvable shared object links.
source ./is_elf
check_dependencies() {
local file_path="$1"
# can't run ldd on non-executables
if [[ ! -x "$file_path" ]]; then
return
fi
# Use ldd to list dependencies; suppress standard error to handle broken links gracefully
ldd_output=$(ldd "$file_path" 2>&1)
ldd_status=$?
if [[ $ldd_status -ne 0 ]]; then
echo "Error: ldd failed for $file_path"
echo "ldd output: $ldd_output"
return
fi
# Check for "not found" in ldd output indicating unresolved dependencies
not_found=$(echo "$ldd_output" | grep "not found")
if [[ -n "$not_found" ]]; then
echo "Unresolvable shared objects in: $file_path"
echo "$not_found"
echo ""
fi
}
# Export functions and variables for use in subshells (if needed)
export -f is_elf
export -f check_dependencies
DIRS="/opt /usr/local"
for d in $DIRS
do
echo "Scanning $d for ELF files and checking dependencies..."
find $d -type f 2>/dev/null | while IFS= read -r file; do
if is_elf "$file" ; then
check_dependencies "$file"
fi
done
done