ELF段识别

发布于 2025-01-10 09:22:13 字数 118 浏览 2 评论 0原文

在 ELF 可执行文件中,我用零值字节覆盖了所有节名称。即使这样,该文件也可以正确链接和执行。操作系统如何识别文件中的各个部分,例如符号表等?我的印象是这些部分的名称就是为了这个目的。一个相关的问题是,那么节名有什么用呢?

In an ELF executable file, I over-wrote all the section names by zero-valued bytes. Even then, the file can be linked and executed correctly. How does the OS identify various sections like the symbols-table, etc. in the file? I was under the impression that the section names serve this purpose. A related question is that what is the use of section names then?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ま柒月 2025-01-17 09:22:13

我重写了所有部分的名称...

...文件可以正确链接...。

与 32 位 Windows 中使用的目标文件不同,如果不使用链接器脚本,则 ELF 目标文件中的节名称将被忽略。

每个“PROGBITS”部分都包含标志,指定该部分是否可写、可执行和/或什至不是映像的一部分(调试信息)。

(实际上,Windows使用的目标文件也有这样的标志,但它们通常设置为0,并且节名称用于区分代码节和数据节。)

对于其他节类型(例如符号表),很清楚如何无论如何,他们都必须得到处理。

...文件可以...正确执行。

对于可执行文件和共享库,这些部分无论如何都会被忽略。相反,使用文件的“程序头”。

“程序头”告诉操作系统必须将文件中的某个地址范围加载到内存中。一个“程序头”可以涵盖多个部分。而且“程序头”没有名称。

例子:

Sections:
    Name       Address    Offset in file    Length
    .text      0x10100    0x100             0x30    read-only
    .rodata    0x10130    0x130             0x20    read-only
    .data      0x20250    0x150             0x10    read-write
    .sdata     0x20260    0x160             0x10    read-write

Program headers:
    Address    Offset in file     Length
    0x10100    0x100              0x50     read-only
    0x20250    0x150              0x20     read-write

I over-wrote all the section names ...

... the file can be linked ... correctly.

Unlike the object files used in 32-bit Windows, the section names in ELF object files are ignored if no linker script is used.

Each "PROGBITS" section contains flags that specify if the section is writeable, executable and/or not even part of the image (debug information).

(Actually, the object files used by Windows also have such flags, but they are typically set to 0 and the section name is used to distinguish between code and data sections.)

For other section types (such as symbol tables) it is clear how they have to be handled anyway.

... the file can be ... executed correctly.

For executable files and shared libraries, the sections are ignored anyway. Instead, the "program headers" of the file are used.

A "program header" tells the OS that a certain address range in the file must be loaded to memory. A "program header" may cover multiple sections. And "program headers" don't have names.

Example:

Sections:
    Name       Address    Offset in file    Length
    .text      0x10100    0x100             0x30    read-only
    .rodata    0x10130    0x130             0x20    read-only
    .data      0x20250    0x150             0x10    read-write
    .sdata     0x20260    0x160             0x10    read-write

Program headers:
    Address    Offset in file     Length
    0x10100    0x100              0x50     read-only
    0x20250    0x150              0x20     read-write
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文