readelf -Ws ./a.out,举例,并且解释
时间: 2024-05-22 18:14:12 浏览: 12
这是一个技术问题,属于二进制可执行文件的解析。readelf是一个命令行工具,可以读取ELF(Executable and Linkable Format)文件的头部信息、节表和符号表等内容,并以可读的形式打印出来。-Ws选项表示显示符号表。./a.out是要解析的二进制文件。举例来说,假设我们有一个名为test.c的C语言源文件,我们可以通过以下命令编译它:gcc -c test.c -o test.o,然后再将test.o嵌入一个可执行文件中:gcc test.o -o test。最后,我们可以使用readelf -Ws ./test命令打印出test可执行文件的符号表。该命令将会输出该可执行文件中的所有符号以及它们的地址、大小、类型等信息。
相关问题
readelf -h /usr/local/lib/libleveldb.a
`readelf` 是一个用于查看二进制文件的工具,在这里用于查看静态库文件 `/usr/local/lib/libleveldb.a` 的头部信息。
执行以下命令以查看头部信息:
```
readelf -h /usr/local/lib/libleveldb.a
```
其中,参数 `-h` 表示查看文件头部信息。
输出类似以下内容:
```
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: REL (Relocatable file)
Machine: Advanced Micro Devices X86-64
Version: 0x1
Entry point address: 0x0
Start of program headers: 0 (bytes into file)
Start of section headers: 688 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 0 (bytes)
Number of program headers: 0
Size of section headers: 64 (bytes)
Number of section headers: 12
Section header string table index: 11
```
其中,我们可以看到一些重要的信息,比如:
- 类型 `Type` 是 `REL`,表示是一个可重定位文件。
- 机器架构 `Machine` 是 `Advanced Micro Devices X86-64`,即 x86-64 架构。
- 文件头部大小 `Size of this header` 是 `64` 字节。
- 节头部数量 `Number of section headers` 是 `12`。
- 节头部字符串表索引 `Section header string table index` 是 `11`,表示节头部字符串表在第 11 个位置。
需要注意的是,这里查看的是静态库文件,因此 `Entry point address` 和 `Start of program headers` 等信息都是 0。
readelf -W -l ~/2065500101/infosec-lab10/badfile | grep GNU_STACK readelf:错误: 不是 ELF 文件 - 它开头的 magic 字节错误
这个错误可能是因为你指定的文件不是一个ELF二进制文件,或者文件路径不正确。请确保你指定的文件路径正确,并且文件确实是一个ELF格式的二进制文件。
你可以使用"file"命令来检查文件类型,例如:
```
file /path/to/binary/file
```
如果输出结果中包含"ELF"字样,说明该文件是一个ELF格式的二进制文件,可以使用"readelf"命令来检查其ELF头部信息。如果输出结果中不包含"ELF"字样,则说明该文件不是一个ELF二进制文件,此时就无法使用"readelf"命令来检查其ELF头部信息了。
一些其他的命令也可以检查文件是否为ELF格式,例如:
```
objdump -h /path/to/binary/file
```
如果输出结果包含".text"段,说明该文件是一个ELF格式的二进制文件。如果输出结果中没有".text"段,则说明该文件不是一个ELF二进制文件。
相关推荐
![tar](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)