Hacker News new | ask | show | jobs
by ManDeJan 2140 days ago
213 bytes! :) Sure there's a few more to shave

  7f454c4602010100000000000000000002003e0001000000820001000000
  000040000000000000000000000000000000000000004000380001004000
  000000000100000005000000800000000000000080000100000000008000
  010000000000550000000000000055000000000000001000000000000000
  0000000000000000200a4c8b0c2449ffc94d39d17441eb0eb00140b701be
  80000100b2010f054e8b44d41041807c100100488d520175f4b00140b701
  4c89c60f0549ffc24d39ca75cfb00140b701be81000100b2010f05b03c31
  ff0f05
1 comments

It's definitely the case that some of the ELF header fields can be repurposed to store additional data, the following articles all address that optimization:

http://www.muppetlabs.com/~breadbox/software/tiny/teensy.htm... https://www.pimzero.com/2020/04/19/golf_so.html https://rpis.ec/blog/plaidctf-golfso/

There are also a few instructions in the article that are size-suboptimal (e.g. "movl $4, %eax" is 5 bytes (b804000000), while the equivalent "xor %eax, %eax; movb $4, %al" is only 4 bytes (31c0b004)).

I tried to do it as optimal as possible, but I think there is indeed more to be saved with putting code in the elf header, i'm not very familiar with the elf format. This is as small as I could get it without doing that, just using yasm, ld and strip.