资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

用php读取elf结构的方法

这篇文章给大家分享的是有关用php读取elf结构的方法的内容。小编觉得挺实用的,因此分享给大家做个参考。一起跟随小编过来看看吧。

创新互联是一家专注于网站建设、成都网站建设与策划设计,点军网站建设哪家好?创新互联做网站,专注于网站建设十余年,网设计领域的专业建站公司;建站业务涵盖:点军等地区。点军做网站价格咨询:18982081108

前提知识
  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结构的方法就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到吧!


新闻标题:用php读取elf结构的方法
标题URL:http://cdkjz.cn/article/gdohhi.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220