TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

A minimal, complete, and correct ELF file

72 点作者 febeling超过 1 年前

6 条评论

aengelke超过 1 年前
Nice visualization of the ELF headers. However, the article has a few inaccuracies:<p>- ELF files are used not only for executables, but also object files, shared libraries, and also coredumps. Different parts of the ELF format serve different purposes, although there is a lot of overlap.<p>- The program headers don&#x27;t state the location of .text, but indicate the area of the file that should be mapped into memory.<p>- Dynamic linking doesn&#x27;t require section headers. The dynamic loader (ld.so) parses the program headers for a PT_DYNAMIC entry, which refers to the .dynamic section (which in turn refers to .dynsym, .dynstr, .rela.dyn, .init_array, etc.).<p>- Relocation sections (what is a relocation symbol?) are required for static linking, where every section with relocations gets its own relocation section, so .text gets .rela.text. Also, in object files, sections must use relocations to refer to other sections. Executables don&#x27;t need to have relocations.<p>- The alignment of PT_LOAD segments must be at least the page size: the kernel or loader will use mmap to map the file, so alignments smaller than the page size won&#x27;t work.<p>- The first section table entry must be of type SHT_NULL. The magic value SHN_UNDEF (=0) is used to refer to undefined symbols, so referring to the first section in, e.g., the symbol table, is not possible.<p>Although not required for a minimal file, any &quot;modern&quot; ELF executable should have a PT_GNU_STACK program header with flags read+write, otherwise the stack will get mapped as executable memory region, thereby creating a large and often avoidable attack vector.
评论 #39250973 未加载
bregma超过 1 年前
This ELF file is not minimal. A loadable ELF file needs no sections at all. The section header table can be empty and the .shrstr section does not need to be present. The .text entry is a just a pointer into one of the LOAD segments and can also be eliminated.
评论 #39249764 未加载
johndough超过 1 年前
When trying to run this binary on a 64 bit Debian system, I get an error:<p><pre><code> echo &#x27;f0VMRgIBAQAAAAAAAAAAAAIAPgABAAAA+ABAAAAAAAAAAQAAAAAAAEAAAAAAAAAAAAAAAEAAOAABAEAAAgABAAEAAAABAAAABgAAAAAAAAD4AEAAAAAAAPgAAAAAAAAADgAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAHAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAGAQAAAAAAABEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAQAAAAUAAAD4AAAAAAAAAPgAQAAAAAAA+ABAAAAAAAAOAAAAAAAAAA4AAAAAAAAAABAAAAAAAABIx8A8AAAAvyoAAAAPBQAudGV4dAAuc2hzdHJ0YWIA&#x27; | base64 -d &gt; main chmod +x main .&#x2F;main # bash: .&#x2F;main: cannot execute binary file: Exec format error </code></pre> Am I doing it incorrectly? I hope I copied the bytes correctly since copy &amp; pasting from the website is a bit challenging.
评论 #39250297 未加载
matheusmoreira超过 1 年前
Related:<p>The Really Teensy Linux ELF Executables Essays<p><a href="https:&#x2F;&#x2F;www.muppetlabs.com&#x2F;~breadbox&#x2F;software&#x2F;tiny&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.muppetlabs.com&#x2F;~breadbox&#x2F;software&#x2F;tiny&#x2F;</a>
llvnux超过 1 年前
This is an amazing animation!
评论 #39249604 未加载
a99c43f2d565504超过 1 年前
Very cool!