栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP

教你用php读取elf结构

PHP 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

教你用php读取elf结构

推荐:《PHP视频教程》

前提知识
  1. UNIX系统的可执行文件都采用ELF格式,类型分为目标文件、可执行文件和共享库
  2. ELF格式探析之三:sections
  3. 本例基于64位的小端序linux机器
以读取目标文件hello.o为例
#include 
void say_hello(char *who) {
    printf("hello, %s!n", who);
}
char *my_name = "wb";
int man() {
    say_hello(my_name);
    return 0;
}
// 执行gcc -c hello.c生成hello.o
目标文件elf结构主要有:
  1. ELF header,位于文件的0~64字节,存储文件的描述信息,Section header table的起始位置
  2. N个Section
  3. Section header table,每个条目64字节,对应一个Section的信息
  4. Program header table,可执行文件需要,本例的hello.o没有
进一步分析elf结构
  1. 首先用readelf命令读取elf信息:readelf -h hello.o。总结如下:
  2. ELF header占用64字节
  3. N个Section占用6488-64-1472=4952字节
  4. Section header table占用23*64=1472字节
readelf -h hello.o
ELF Header:
Class: ELF64
data:  2's complement, little endian
OS/ABI:UNIX - System V
Type:  REL (Relocatable file)
Machine:      Advanced Micro Devices X86-64
Start of program headers:   0 (bytes into file)
Start of section headers:   5016 (bytes into file) //Section header table的起始位置
Size of this header: 64 (bytes) //ELF header的占用大小
Size of program headers:    0 (bytes)  //hello.o没有program header table
Number of program headers:  0   //hello.o没有program header table
Size of section headers:    64 (bytes) //Section header table每个条目占用大小
Number of section headers:  23  //Section header table条目个数
Section header string table index: 22  //.shstrtab Section位于Section header table第22个条目
用php读取.shstrtab Section内容
  1. .shstrtab Section其实是存储的所有Section的名字

以上就是教你用php读取elf结构的详细内容,更多请关注考高分网其它相关文章!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/262636.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号