gpt4 book ai didi

linux - readelf如何翻译入口点

转载 作者:太空狗 更新时间:2023-10-29 12:31:57 24 4
gpt4 key购买 nike

我有一个 elf 文件,当我使用 readelf -h 文件名时,我得到了入口点。现在,假设我想自己计算这个地址[使用汇编,但语言并不重要]。

我该怎么做?

我知道入口点是从文件中的偏移量 24 开始的 4 个字节,但我不知道如何将此数据转换为地址。

最佳答案

I know the the entry point is 4 bytes starting from offset 24 in the file, but I don't know how to translate this data into address.

当您在与构建可执行文件的目标相同的目标 (x86) 上运行时,无需翻译。

在伪代码中,省略了错误检查:

int fd = open(path, O_RDONLY);
lseek(fd, 24, SEEK_SET);
unsigned long entry_point;
read(fd, &entry_point, sizeof(entry_point));

printf("entry: 0x%lx\n", entry_point);

附言24 只是 Elf32 的正确偏移量;最好通过阅读整个 Elf32_EhdrElf64_Ehdr 来编写它(取决于字节 5 是 ELFCLASS32ELFCLASS64 ) 从偏移量 0 开始,然后使用 .e_entry 成员。

关于linux - readelf如何翻译入口点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24094671/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com