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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Show HN: A (marginally) useful x86-64 ELF executable in 466 bytes

85 点作者 meribold大约 1 年前

8 条评论

meribold大约 1 年前
This project is a rewrite of a Bash script that I started to teach myself a little bit of x86 assembly. I still don&#x27;t know much, but I did learn that ELF executables can be surprisingly small and simple for a very basic program. A 64-byte file header and a single 56-byte program header are the only &quot;overhead&quot; that is really mandatory (and it&#x27;s even possible to make those overlap a little).<p>But it&#x27;s difficult to stop the linker from adding extra stuff, which is why I eventually specified the headers (and three addresses) by hand in the assembly file and stopped using a linker.
评论 #39846266 未加载
评论 #39845762 未加载
fear91大约 1 年前
You can shrink it further by doing xorl reg, reg. On x86, the upper 32 bits are cleared for you when using 32 bit opcodes. No need to do a 64-bit reg, reg xor.<p>Instead of doing cmp $0, %eax, you can use test eax, eax - that&#x27;s another low hanging fruit.<p>It seems that you could also preset a dedicated reg to 0 and another to 1, further shaving a few bytes.
评论 #39845444 未加载
评论 #39846249 未加载
im3w1l大约 1 年前
This is kind of a tangent, but there are two types of programming that seem like fun little games. On the one hand low-level assembly and on the other hand high-level code that uses logic or type system trickery to prove various correctness or at least some nice properties of the program.<p>I just hope that someone at some point figures out how to combine these two things, so we can pursue the best possible way of writing a program, and then prove it correct too. This would be a sort-of immortal program that would never need updating. Well, until it becomes obsolete because the world has changed around it.
评论 #39847686 未加载
kitd大约 1 年前
Love the installation instructions. No downloads, the instruction <i>is</i> the binary.
评论 #39848548 未加载
Kluggy大约 1 年前
So this just reads &#x2F;sys&#x2F;class&#x2F;power_supply&#x2F;BAT0&#x2F;energy_now (or charge_now) and &#x2F;sys&#x2F;class&#x2F;power_supply&#x2F;BAT0&#x2F;charge_full and outputs it nicely. While the asm is cool, how large would the bash script to do it?
评论 #39845275 未加载
bregma大约 1 年前
One is really hard-pressed to argue these little loadable executables are ELF files. They do not conform to the ELF standard. They&#x27;re simply tiny loadable Linux executables because they exploit the Linux kernel loader&#x27;s slackness in interpreting ELF binaries.
qweqwe14大约 1 年前
Prior art: <a href="http:&#x2F;&#x2F;www.muppetlabs.com&#x2F;~breadbox&#x2F;software&#x2F;tiny&#x2F;return42.html" rel="nofollow">http:&#x2F;&#x2F;www.muppetlabs.com&#x2F;~breadbox&#x2F;software&#x2F;tiny&#x2F;return42.h...</a>
benterix大约 1 年前
Funny how the tech world comes full circle. I remember writing a similar program (for CPUID) as a COM file in mid-90s and it definitely had less than 466 bytes, maybe 1&#x2F;10th of it.