学习笔记:ELF开源库 - ELFIO库(C++)和jelf库(java)

一、ELF标准

1、wiki官方定义

参考: Executable and Linkable Format

2、标准格式

ELF结构

查看命令

1.ELF Header

readelf -h

2.Program header table

readelf -l

3.Section(s)

4.Section header table

readelf -S

二、解析ELF开源库

1、C++开源库:ELFIO库

2、java开源库:jelf库

三、ELF文件(hello_word.out)定制,重构writerELF功能

1、整体ELF结构变化

整体结构发生变化,各offset需要最后重新计算

  • 原始结构

1.ELF Header

2.Program header table

3.Section(s)

4.Section header table

readelf -h hello_word.out查看:

  • 新的结构

1.ELF Header

2.Program header table

3.Section header table

4.Section(s)

readelf -h hello_word.out查看:

2、section结构变化

  • 原始结构,根据Address来排序

readelf -SW hello_word.out查看:

  • 新的结构,.shstrtab内容需要根据新的sections结构重新实现

1.mandatory_sections(2个)

【0】

【1】.shstrtab(是用来记录每个Section的名称的,每个Section Header Table的sh_name字段记录的就是这个Section的名称在.shstrtab中的偏移)

2.alloc sections(14个)

【运行是需要runtime】

【2】.text

【3】.eh_frame

【4】nuksymstr

【5】nuksymtab

【6】nusymstr

【7】nusymtab

【8】nuusymstr

【9】nuusymtab

【10】.rodata

【11】.rtl.data

【12】.rtl.bss

【13】.data

【14】.noinit

【15】.bss

3.non-alloc sections(13个)

【运行时不需要,linker、debug等工具使用,可以通过strip移除】

【16】meminfo

【17】.debug_info

【18】.debug_abbrev

【19】.debug_aranges

【20】.debug_ranges

【21】.debug_macro

【22】.debug_line

【23】.debug_str

【24】.comment

【25】.debug_frame

【26】.debug_loc

【27】.symtab

【28】.strtab

readelf -SW hello_word.out查看:

3、Program Header 更新

  • 原始结构

readelf -l hello_word.out查看:

  • 新的结构:根据新的sections重新计算得出

readelf -l hello_word.out查看:

4、.symtab section的st_shndx字段更新

readelf -sW hello_word.out查看(内容比较多,保存到文件里面),Ndx对应section id,由于sections架构重新调整,这边Ndx的id需要和新的section id一一对应

四、参考资料

1、ELF的介绍

可以参考:

ELF 详解1 – ELF Header

ELF 详解2 – Section Header & Section

ELF 详解3 – Symbol Table & Symbol

ELF 详解4 – 深入 Symbol

2、readelf命令使用方法

可以参考:ELF格式文件符号表全解析及readelf命令使用方法

  • 27
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值