[英]Find all executable files that depend on the specified library in the specified directory
My goal is to write a shell script that uses "objdump -p" command to find all executable files that depend on the specified library in the specified directory.我的目标是编写一个 shell 脚本,该脚本使用“objdump -p”命令在指定目录中查找依赖于指定库的所有可执行文件。 (OpenBSD).
(OpenBSD)。 I try something like this:
我尝试这样的事情:
find $1 -perm -111 -print0 | xargs -r0 objdump -p | grep -l "NEEDED $2"
But this solution doesn't work because grep cannot figure out the filenames in which it found the given match.但是这个解决方案不起作用,因为 grep 无法找出它在其中找到给定匹配项的文件名。 The difficulty is to determine the names of the executable files in which grep found the specified library.
难点在于确定 grep 在其中找到指定库的可执行文件的名称。 Can anyone suggest a solution using the "objdump -p" command?
任何人都可以使用“objdump -p”命令提出解决方案吗?
The trick is to execute a shell script rather than a single command to be able to re-use the file name.诀窍是执行 shell 脚本而不是单个命令,以便能够重新使用文件名。
finddepend() {
# Arg 1: The directory where to find
# Arg 2: The library name
basedir=$1
libname=$2
find "$basedir" \
\( -perm -100 -o -perm -010 -o -perm -001 \) \
\( -type f -o -type l \) \
-exec sh -c '
# Arg 0: Is a dummy _ for this inline script
# Arg 1: The executable file path
# Arg 2: The library name
filepath=$1
libname=$2
objdump -p "$filepath" 2>/dev/null |
if grep -qF " NEEDED $libname"; then
printf %s\\n "${filepath##*/}"
fi
' _ {} "$libname" \;
}
Example usage:用法示例:
finddepend /bin libselinux.so
mv
systemctl
tar
sed
udevadm
ls
mknod
systemd
mkdir
ss
dir
vdir
cp
systemd-hwdb
netstat
Why do you want to use objdump
when you can use ldd
(List Dynamic Dependencies)?当您可以使用
ldd
(列出动态依赖项)时,为什么要使用objdump
? objdump
gives a complete summary, which you need to process in order only to get the information you're looking for, while ldd
only gives you that information. objdump
提供了一个完整的摘要,您需要对其进行处理才能获得您正在寻找的信息,而ldd
只为您提供该信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.