10 ms·
A Magnetized Needle and a Steady Hand
- tomcam 10y agoThis article uses the ingenious technique of accreting a minimal executable file via the Unix echo command, which can indeed write binary output using C-style escape codes. A must for anyone interested in compiler writing because it does a decent job explaining the ELF format in terms of the data structures required ton hold one.
- mirimir 10y agoThere are analogous discussions about open-source hardware. How far back must one go to be assured that there are no backdoors? It's a hard problem.
- dmd 10y agoAh, but what if the man page for elf has been sneakily changed by your superhuman-intelligent adversary? (cf. A Fire Upon the Deep, Virnor Vinge)
- jedimastert 10y agoI think if there was a massive attack that infected a trusting trust attack on every computer on the planet, we'd just have to start from scratch
- pavel_lishin 10y agoSuper-scratch. We'd have to trash every processor manufacturing plant on the planet; Every single one almost certainly uses computer-controlled machinery working from computer-stored plans. 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.
- pjc50 10y ago"Three-body problem" has an interesting variant on this: an alien intelligence which can sabotage physics experiments, thereby preventing humanity from exceeding a particular level of development.
- pavel_lishin 10y agoI was definitely thinking of that when typing that out, although I think that the particular way the antagonists did this in Three Body Problem was like using a jet fighter to shield your infantry from the rain.
- TeMPOraL 10y agoIndeed they could have done much more "fun" stuff with the tool they used. It seems that they lacked the mentality of human trolls. (BTW. I just binge-read the entire trilogy within the past two weeks, thanks to HN recommendations of the first book. And I have to say, it's great sci-fi, totally worth the time it takes to read it.)
- pavel_lishin 10y agoI read the first one, and it was incredibly interesting, but mostly from the cultural and historical perspectives. The "magic" bit I referenced seemed ... overpowered and yet underused. It's incredibly difficult to imagine an intelligence that can come up with that, but not extrapolate any further. Potential spoiler alert: Using that particular plot device to fool scientists into believing the laws of physics weren't constant struck me as ludicrous. The part where physicists start committing suicide instead of seeing this as the start of a revolution in their understanding of the universe was almost plausible by comparison. I need to read the second two, but I heard that the translations aren't as good :/
- pjc50 10y agoTaking the plot device entirely literally misses the point of the book somewhat; it's so highly metaphorical and so much of it is told through the "VR" dream sequence exposition. It's really a book about the question: how do we know what we know? Specifically, how do we find truth when powerful forces have devoted themselves to obfuscating it for us? In other words, the "cultural revolution" in China. And by extension, the present day wǔmáo dǎng era.
- darklajid 10y agoWhat man page? What 'man'? Isn't the premise of the article, that all software's gone? Good luck reading anything digital. Even better if you only have PDF files..
- hga 10y agotl;dr: inspired in part by http://xkcd.com/378/ http://xkcd.com/378/ on writing the "true" program in machine code (that is, hex AKA binary bits). Using the echo program....
- lugus35 10y agoI don't understand when Chris Wellons find the time to write all those fine blog posts.
- userbinator 10y agoIt's interesting to compare with DOS, where a do-nothing program is a single byte: 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.html 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=64b&type%5B%5D=128b&page=1 http://www.pouet.net/prodlist.php?type%5B%5D=32b&type%5B%5D=...
- SonOfLilit 10y agoWhen working on this[1], I spent three sleepless days shaving bytes from the included Brainf*ck interpreter. The last byte probably took about 5 hours. 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 :-) [1] https://news.ycombinator.com/item?id=7943514 https://news.ycombinator.com/item?id=7943514
- joeyh 10y agojoey@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.
- deleted 10y ago[deleted]
- aexaey 10y agoAlso, you don't actually need a "true" binary for a shell of any reasonable vintage: # which true /usr/bin/which: no true in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin) # true; echo $? 0
- jkn 10y agoOn Unix, an empty file is a working implementation of the "true" command (provided that is in the PATH and set as executable). This is because it is interpreted as a shell script, and an empty script of course exits successfully. 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 http://trillian.mit.edu/~jc/humor/ATT_Copyright_true.html
- krallja 10y ago`echo` is a shell builtin on my machine. In that case, we certainly have access to an interpreter (the shell), which means we should have access to other interpreters. Why not define `true` as #!/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!
- MayeulC 10y agoI would alias it as echo '' Since echo always returns true anyway :) But that's just sidestepping the problem, in any case.
- pricechild 10y agoThis article isn't really about solving a silly problem with hands, arms & tongue tied behind your back. It's about learning a little bit more about the layers which put our systems together. I don't think the author was seriously suggesting you use butterflies or a steady hand either.
- corecoder 10y agoVery nice; tried it and got a 129 byte working true command. Now I have to understand what's in the 28896 bytes of the true command that comes with the distro I have here.
- oblio 10y agoGNU true: http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/true.c http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/true... The real kicker is GNU false: http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/false.c http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/fals... A sort of "reversed polarity", if you will.
- LeifCarrotson 10y agoSo it's basically 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!
- zokier 10y agoI'd guess most of code weight will be setting up and tearing down glibc, initializing stdio etc. Then there is all sorts of metadata that gcc (and ld etc) include by default. There are plenty of resources on how to create minimal C executables, but `-nostdlib` gcc option would be a good starting point as a low-hanging fruit.
- cheiVia0 10y agoPeople like to dig at the size of GNU's /bin/true and /bin/false, but the reality is - who cares? Does anyone actually ever use it? $ type true true is a shell builtin
- wyldfire 10y agoI've frequently bypassed tests/checks by replacing them with a symlink to /bin/true. So, yes. But no I don't care how big it is.
- pjc50 10y agoA long, long time ago I actually did this, in order to sneak a small exploit in a COM file onto the school's pre-internet Novell Netware system. 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.
- Beltiras 10y agoYe gods. Github was intermittently inaccessible the other day and ruined about half an hour of my time. World-wide EMP leaving all HDDs in ruins. Well, at least it would keep us occupied for a decade rebuilding everything .....
- minikites 10y agoI don't remember enough of the details to find a link, but I recall reading a story where some system error destroyed the binaries for most of the usual command line tools like cat and the author couldn't restart or rebuild the server so they hand entered the hex (or something) for enough tools to bootstrap themselves into a running system again.
- placebo 10y agoThis reminds me a bit of a thought I had regarding how long would it take civilisation to return to it's current level of technology if we'd all be magically transferred back to the stone age retaining only our memories.
- zentiggr 10y agoGeneration one would be almost completely occupied finding the most efficient way to archive as much of that knowledge as possible, IMO... I'd imagine it might take a dozen generations or so, or more, depending on how much could be archived before that first generation passed away and took that experience with it. I see apprenticeships rampant!
- burkaman 10y agoThis is basically the plot of the Foundation series.
- ktRolster 10y agoWouldn't it mostly depend on how many people died? 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.
- TeMPOraL 10y agoIndeed it would. 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.
- 10y ago
- ksherlock 10y ago$ touch true; chmod 777 true; ./true && echo Success Success
- ben_bai 10y agoCongrats: Your shell just spawned another shell to run an empty script. Also: # rm /bin/true && true && echo success success
- saurik 10y agoThe storyline backing this article is not just distracting, it is misinformative: it teaches people the wrong indirect lessons about software and engineering :/. If you don't have an assembler, you write an assembler, you don't just make do without and try to bootstrap directly from a C compiler; and if you have the luxury of extra hands and need people to work on stuff in parallel--stuff you can't run yet anyway as if you don't have really simple things like true coded I bet you don't have a shell (and there are only a scant couple reasons true would even exist if you don't have a shell that exposes branch comparisons as shell commands)--you don't set them to work building the binaries by hand, you give them a rough outline of a programming language you will have available at the right point in the development cycle (maybe you throw them a C89 manual, as manuals still seem to exist in this world?) and tell them to write it in that on the promise that it will be useful later.
- aji 10y agoit's obviously just a fun thought experiment. and 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
- posterboy 10y ago>it teaches people the wrong indirect lessons about software and engineering 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.
- agumonkey 10y agoonce again, kragen marathon comes to mind https://www.reddit.com/r/programming/comments/9x15g/programming_thought_experiment_stuck_in_a_room/c0ewj2c/ https://www.reddit.com/r/programming/comments/9x15g/programm...
- CGamesPlay 10y agoThis is really cool. Has anybody gameified this?
- TeMPOraL 10y agoThe background story is a fun thought experiment and obviously it requires some suspension of disbelief... ...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 ;).
- khedoros1 10y agoIt strikes me that a native compiler, accessible at runtime, would fit the definition of "software development tool", so either the entire program, or the portion contains the compiler, would be deleted. 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?
- deleted 10y ago[deleted]
- lutusp 10y agoFrom a modern perspective it's fun to think about the layers of sometimes-trivial complexity that we fly over with modern development tools, but when I wrote Apple Writer in 1978, I first had to write an assembler, and to do that, I first had to enter seemingly endless amounts of object code to get to the tipping point where I could enter comparatively efficient 6502 assembly-language mnemonics and actually get something accomplished. https://en.wikipedia.org/wiki/Apple_Writer https://en.wikipedia.org/wiki/Apple_Writer