判断 elf 文件是可执行文件还是库文件
Determining whether an elf file is executable or a library
我有以下问题:我有一个 elf 文件,我想知道该 elf 文件是否可以 运行 作为独立的可执行文件。因此,对于共享库,例如 .so
文件,我希望得到 False
作为结果,对于准备好的 运行 二进制文件,我希望 True
作为输出。我试图利用 file
来实现这一点,但显然提供的信息还不够。考虑
file /usr/bin/sudo
/usr/bin/sudo: setuid ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=3e4fbfd5a73126630bcc22d5dee68c32e2813566, stripped
我实际期望的输出是 ELF 64-bit LSB executable
,就像 gcc
编译器一样:
file /usr/bin/gcc-5
/usr/bin/gcc-5: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=b3417f0bc306e9b0afe35e778b5e4702f2d22b26, stripped
我在这里错过了什么,还有其他方法可以实现我的目标吗?
I want to have False as a result and for ready-to-run binaries I want True as an output.
一般来说,您的目标是无法实现的:可以构建一个准备好 运行 的库(例如 Linux 上的 /lib64/libc.so.6
),也可以构建一个可执行文件尽管报告 ELF 64-bit LSB executable
.
仍会在启动时崩溃
还建议尝试运行任何二进制文件,除非您知道该二进制文件来自何处以及其预期的执行结果是什么。
What am I missing here
正如 所解释的,许多最近的 Linux 发行版默认构建 PIE 可执行文件。
are there any other ways to achieve my goal?
见this answer。
我有以下问题:我有一个 elf 文件,我想知道该 elf 文件是否可以 运行 作为独立的可执行文件。因此,对于共享库,例如 .so
文件,我希望得到 False
作为结果,对于准备好的 运行 二进制文件,我希望 True
作为输出。我试图利用 file
来实现这一点,但显然提供的信息还不够。考虑
file /usr/bin/sudo
/usr/bin/sudo: setuid ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=3e4fbfd5a73126630bcc22d5dee68c32e2813566, stripped
我实际期望的输出是 ELF 64-bit LSB executable
,就像 gcc
编译器一样:
file /usr/bin/gcc-5
/usr/bin/gcc-5: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=b3417f0bc306e9b0afe35e778b5e4702f2d22b26, stripped
我在这里错过了什么,还有其他方法可以实现我的目标吗?
I want to have False as a result and for ready-to-run binaries I want True as an output.
一般来说,您的目标是无法实现的:可以构建一个准备好 运行 的库(例如 Linux 上的 /lib64/libc.so.6
),也可以构建一个可执行文件尽管报告 ELF 64-bit LSB executable
.
还建议尝试运行任何二进制文件,除非您知道该二进制文件来自何处以及其预期的执行结果是什么。
What am I missing here
正如
are there any other ways to achieve my goal?
见this answer。