elf - DW_FORM_strp 值的位置
问题描述
我试图了解DW_FORM_strp
属性值实际存储在 ELF 文件中的位置(可在此处找到:https ://filebin.net/77bb8359o0ibqu67 )。
我找到了部分.debug_info
,.debug_abbrev
和.debug_str
。然后,我解析了 中的编译单元标题.debug_info
,并找到了编译单元的缩写表条目并迭代了它的缩写。第一个缩写是DW_AT_producer
with form DW_FORM_strp
。我想知道的是如何找到这个偏移量的位置?
从我读到的 DWARF4 规范中:Each debugging information entry begins with a code that represents an entry in a separate abbreviations table. This code is followed directly by a series of attribute values.
我对此的理解是,如果我回到编译单元头,跳过它的内容,我应该最终到达编译单元。它以 ULEB128(我对其进行解析)开始,之后应该出现属性值。但是,在我的 ELF 文件中,这些字节都是 0。我已经readelf -w
在文件上运行,我看到以下内容:
Contents of the .debug_info section:
Compilation Unit @ offset 0x0:
Length: 0xf6 (32-bit)
Version: 4
Abbrev Offset: 0x0
Pointer Size: 8
<0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
<c> DW_AT_producer : (indirect string, offset: 0x62): GNU C11 7.5.0 -mtune=generic -march=x86-64 -g -O0 -fstack-protector-strong
<10> DW_AT_language : 12 (ANSI C99)
<11> DW_AT_name : (indirect string, offset: 0xd9): elf.c
<15> DW_AT_comp_dir : (indirect string, offset: 0xad): /home//struct_analyzer
<19> DW_AT_low_pc : 0x0
<21> DW_AT_high_pc : 0x39
<29> DW_AT_stmt_list : 0x0
这告诉我字符串表的偏移量是0x62
,并且名称是偏移量0xd9
。但是,在解析ULEB128
任何 DIE 的第一部分后,接下来的 4 个字节(第一个属性的值)是0x00 00 00 00
. 这我不明白?
编辑为雇佣俄罗斯人:
是的,我知道偏移0x62
点进入该.debug_str
部分。但是,我想知道我在哪里找到这个0x62
值?
每个 DIE 都以 ULEB128 值(缩写表条目代码)开头,然后是属性。相应缩写表条目中的第一个属性是 aDW_AT_producer
形式DW_FORM_strp
。这意味着 DIE 中接下来的 4 个字节应该是.debug_str
. 但是,接下来的 4 个字节是0x00 00 00 00
,而不是0x62 00 00 00
我正在寻找的值。0x62
驻留在0x5c8
ELF 文件的偏移量处,而 DIE 的属性从偏移量开始,0x85
据我所知(请参阅所附图像以获取 hexdump(小端序) - 突出显示的字节是 ULEB128,以下字节是我期望的中的偏移量.debug_str
)。
编辑 2
我已经能够确定 form 的实际属性值DW_FORM_strp
位于.rela.debug_info
ELF 文件的部分中,因此我将不得不阅读更多相关信息。
解决方案
为此问题发布的特定 ELF 文件也有一个rela.debug_info
部分,其中包含该.debug_info
部分的重定位条目。从 ELF 规范:
.relaNAME
This section holds relocation information as described below.
If the file has a loadable segment that includes relocation,
the section's attributes will include the SHF_ALLOC bit. Oth‐
erwise, the bit will be off. By convention, "NAME" is sup‐
plied by the section to which the relocations apply. Thus a
relocation section for .text normally would have the name
.rela.text. This section is of type SHT_RELA.
此部分中的每个重定位条目(Elf64_Rela
在此特定情况下为类型)都应迭代,并且每个条目的值应与该.debug_info
部分中的相应值相加。
推荐阅读
- python - Python GUI使用(导入)excel文件中的数据替换word文档中的一些内容
- mysql - 如何从与 sequelize 的关联中获取所有数据
- azure-data-factory - 如何在 DF 数据流、数据集源选项中使用管道参数
- python - python 语法的建议 - 将实施什么?
- verilog - Verilog 编译错误:未识别的变量 2'b00
- typescript - TypeScript:如何将类型属性转换为类成员
- javascript - 如何停止 HTML 文本框中的特殊字符?
- javascript - 如何找到 9 周前的星期天,而不管今天是一周中的哪一天使用 JavaScript
- r - API 推特和推特
- maven - 如何将活动选择参数的选定值传递给构建脚本