182 points · by omnibrain · 10y ago · 62 comments
C3
A Hello World is roughly 20 bytes, the bulk of it being the string itself: 95 BA 07 01 CD 21 C3 48 65 6C 6C 6F 20 77 6F 72 6C 64 21 24
The ELF in the article, which is 130 by my count, could be reduced to 45 with some tricks:http://www.muppetlabs.com/~breadbox/software/tiny/teensy.htm...
Also worth looking at is what the demoscene has done with binaries of 128 bytes or less:
http://www.pouet.net/prodlist.php?type%5B%5D=32b&type%5B%5D=...
Then I showed it to a security researcher I knew and he immediately replied "oh, this is so cool! also, you can replace the last four bytes with C3". Oh man, that hurt :-)
I'm pretty sure this was actually used in some Unix/Linux version, and they got bug reports due to the poor performance (executing a shell to do nothing), which makes for a lot of bugs per line of code. Unfortunately I can't find a reference. Instead I found that AT&T Unix implemented "true" as an empty file... with a copyright notice! See http://trillian.mit.edu/~jc/humor/ATT_Copyright_true.html
joey@darkstar:~>touch true
joey@darkstar:~>chmod +x true
joey@darkstar:~>ls -l true
-rwxr-xr-x 1 joey joey 0 Nov 18 10:53 true*
joey@darkstar:~>if ./true; then echo yay; fi
yay
Just saying. # which true
/usr/bin/which: no true in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
# true; echo $?
0the smallest prod on pouet is a zero byte com file. of course it errors. With C3 you have skewed the definition of a program, already, anyhow. Edit: Queue the story of the empty dos program that was nevertheless useful to prompt the OS's program loader to do some memory management with useful side effects
The real kicker is GNU false: http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/fals...
A sort of "reversed polarity", if you will.
/* Note true(1) will return EXIT_FAILURE in the edge case where writes fail with GNU specific options. */
If you can't program a bug free true(1), please stop with whatever you think you are doing. int
main (int argc, char **argv)
{
return EXIT_SUCCESS;
}
plus all the stuff required to handle --version and --help.But even compiling just that results in 60 kB on my system. What's in those other kilobytes, indeed!
Then if you open it in a hex editor (or use od -x), I'll bet you'll see pages and pages of zeroes, which are used for aligning it appropriately in RAM when it loads.
At least, those are all things that work on some systems, can't be sure about yours.
I also had to rebuild a partition table by hand once with only a copy of MSDOS debug on a boot floppy, and Peter Norton's excellent book on the PC.
(Note that 'gnu' in the story is GNU Emacs!)
...but in the best HN tradition, let me poke some holes into it ;).
C-based technology we are all used to has some set of particular paradigms, one of which being that programs are "write-only". You code, compile and ship the binary. It wasn't the case with many pre-C technologies though, and it isn't the case now.
So, looking just at the software I have on my PC right now, I wonder what this potent computer virus would do to all the programs I wrote in Common Lisp - they all ship a native compiler within them, that's accessible in runtime. Moreover, it's often essential in runtime for the program to work.
So I guess, if that virus came and wiped all the dev tools, the C world would die, while we'd be looking for any compiled Lisp application and working to break into the REPL ;).
Another challenging aspect is that just about every command shell can execute a scripting language, so they'd be included too. I mean, it's just a repl with easy access to the filesystem, right?
(cf. A Fire Upon the Deep, Virnor Vinge)
This would be a fun novel to read. An alien intelligence that can only act at a distance infects our computer systems, and we have to recover. A sort of post-apocalyptic scenario, except without the magic "engines don't work, but matches do" flavor. I hope Neal Stephenson is bored and looking for something to write.
I don't know if you're referring to "Revolutions" TV series here, but I've seen exactly those accusations of "magic" leveled against the show in the past, on HN. I decided to watch it anyway, and...
(spoiler alert)
...by the half of the first season it's becoming slowly revealed that there's no magic that happens to disable only electronics and combustion engines - it's omnipresent advanced nanotech explicitly designed to do just that.
For example, after the destruction of world wars, most industries bounced back quickly because the knowledge was still there. Of course, that wasn't complete stone age.
Our civilization depends on the complex supply chains - you need people mining materials, people refining materials, people quality checking those materials, people providing various precise tools, people providing various precise tools for making the precise tools, people providing food for everyone, people moving everything around, people making the stuff that moves everything around, etc. etd.
So I think the first generations would have to spend time slowly building up all the components of the supply chain, while furiously breeding to return the population to the levels that allow as big professional specialization as we have today.
Success
Also:
# rm /bin/true && true && echo success
successand we'd probably dust off the old PDP7s and stuff that are more suited to this kind of bootstrapping, instead of jumping straight to ELF and x86
I am sure most readers can figure that out from the elaborate set up. Reverse engineering shell code, or decompiling programs would be a more realistic application of the conveyed skill set.
#!/bin/sh
exit 0
? Similarly, why not use `sh` or one of those other interpreters to write the rest of the utilities? `cc` probably isn't that important after all. `chmod` and `sh` are!I don't think the author was seriously suggesting you use butterflies or a steady hand either.
echo ''
Since echo always returns true anyway :)
But that's just sidestepping the problem, in any case.