搜索 32 位 ELF 文件

搜索 32 位 ELF 文件

我想知道是否有可能通过在文件系统中使用单个命令来查找 32 位 ELF 对象的文件?我实际上在 fedora 23 64 位中工作,无法找到任何这些文件,但我尝试做的练习准确地说它必须是 32 位 ELF 文件。谢谢你的帮助。

答案1

您需要做的就是检查文件中的前 5 个字节是否为 7f 45 4c 46 01(就是这样file)。所以你只需要读取每个文件的 5 个字节:

PERLIO=:raw find . -type f -size +51c -exec perl -lne '
  BEGIN{$/=\5};print $ARGV if $_ eq "\x7f\x45\x4c\x46\x01"; close ARGV' {} +

这里只检查至少 52 字节的常规文件,因为这是ELF 标头对于 32 位 ELF 文件,尽管 ELF 文件通常会比这大得多。

答案2

尝试这个:

find . -type f -exec file '{}' \; | grep -i 'elf 32'

答案3

你的意思是像file这样使用的命令吗?

$ which ls
/bin/ls
$ file /bin/ls
/bin/ls: ELF 32-bit LSB  executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=cecbb9e27978d91bc6fe2cc4d46d0cd58deafdb2, stripped
$ 

您可以执行如下find命令:file

$ find /bin -type f -exec file '{}' \; | grep -c "ELF 32-bit LSB  executable" 
88
$ find /bin -type f -exec file '{}' \; 2>&1  | grep  "ELF 32-bit LSB  executable" | head -2
/bin/bzip2: ELF 32-bit LSB  executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=8ec5364bf1b5aae5a29b02aaa89db511e988f26a, stripped
/bin/more: ELF 32-bit LSB  executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=2cf8c3651ba3e5dd6a053d40a969b4b7bca9cac0, stripped
$

答案4

您可以使用find来获取文件,然后file获取文件信息并在的输出中grep搜索字符串:32-bitfile

find /bin /usr/bin -type f -exec sh -c '{ file -L "$1" | grep -q 32-bit ;} \
      && echo "$1"' _ {} \;

更改/添加搜索位置以满足您的需要。

例子:

% find /usr/bin -type f -exec sh -c '{ file -L "$1" | grep -q 32-bit ;} && echo "$1"' _ {} \; 
/usr/bin/unix2dos
/usr/bin/dos2unix

相关内容