diff options
-rwxr-xr-x | find-sodeps.sh | 21 | ||||
-rwxr-xr-x | find-soprovides.sh | 30 |
2 files changed, 31 insertions, 20 deletions
diff --git a/find-sodeps.sh b/find-sodeps.sh index 8836906..b522cee 100755 --- a/find-sodeps.sh +++ b/find-sodeps.sh @@ -22,17 +22,22 @@ in_array() { return 1 # Not Found } - find . -type f | while read filename do - soarch=$(objdump -a "$filename" 2>/dev/null | sed -rn 's/.* file format (.*)$/\1/p' | tr - _) + # get architecture of the file; if soarch is empty it's not an ELF binary + soarch=$(LC_ALL=C readelf -h "$filename" 2>/dev/null | sed -n 's/.*Class.*ELF\(32\|64\)/\1/p') [ -n "$soarch" ] || continue - for sofile in $(readelf -d "$filename" 2> /dev/null | sed -nr 's/.*Shared library: \[(.*)\].*/\1/p') + # process all libraries needed by the binary + for sofile in $(LC_ALL=C readelf -d "$filename" 2>/dev/null | sed -nr 's/.*Shared library: \[(.*)\].*/\1/p') do - soname=$(sed -rn 's/(.*)\.so.*/\1.so/p' <<< "$sofile") - if ! in_array "${soname}" ${sodepends[@]}; then - echo "${soname}" - sodepends=(${sodepends[@]} "${soname}") - fi + # extract the library name: libfoo.so + soname="${sofile%%\.so\.*}.so" + # extract the major version: 1 + soversion="${sofile##*\.so\.}" + if ! in_array "${soname}=${soversion}-${soarch}" ${sodepends[@]}; then + # libfoo.so=1-64 + echo "${soname}=${soversion}-${soarch}" + sodepends=(${sodepends[@]} "${soname}=${soversion}-${soarch}") + fi done done diff --git a/find-soprovides.sh b/find-soprovides.sh index dee1078..452af1a 100755 --- a/find-soprovides.sh +++ b/find-soprovides.sh @@ -21,19 +21,25 @@ in_array() { done return 1 # Not Found } - find . -type f -name \*.so\* | while read filename do - if readelf -h "$filename" 2>/dev/null | grep -q '.*Type:.*DYN (Shared object file).*'; then - soarch=$(objdump -a "$filename" 2>/dev/null | sed -rn 's/.* file format (.*)$/\1/p' | tr - _) - sofile=$(readelf -d "$filename" 2>/dev/null | sed -nr 's/.*Library soname: \[(.*)\].*/\1/p') - [ -z "$sofile" ] && sofile="$(basename "$filename")" - - soname=$(sed -rn 's/(.*)\.so.*/\1.so/p' <<< "$sofile") - if ! in_array "${soname}" ${soprovides[@]}; then - echo "${soname}" - soprovides=(${soprovides[@]} "${soname}") - fi - fi + # check if we really have a shared object + if LC_ALL=C readelf -h "$filename" 2>/dev/null | grep -q '.*Type:.*DYN (Shared object file).*'; then + # 64 + soarch=$(LC_ALL=C readelf -h "$filename" | sed -n 's/.*Class.*ELF\(32\|64\)/\1/p') + # get the string binaries link to: libfoo.so.1.2 -> libfoo.so.1 + sofile=$(LC_ALL=C readelf -d "$filename" 2>/dev/null | sed -n 's/.*Library soname: \[\(.*\)\].*/\1/p') + [ -z "$sofile" ] && sofile="${$filename##*/}" + + # extract the library name: libfoo.so + soname="${sofile%%\.so\.*}.so" + # extract the major version: 1 + soversion="${sofile##*\.so\.}" + if ! in_array "${soname}=${soversion}-${soarch}" ${soprovides[@]}; then + # libfoo.so=1-64 + echo "${soname}=${soversion}-${soarch}" + soprovides=(${soprovides[@]} "${soname}=${soversion}-${soarch}") + fi + fi done |