Back in the good old days, you could leave your door unlocked at night, music made sense, and writing computer programs was simply a case of putting s

Delve into ELF Binary Magic

submited by
Style Pass
2022-08-13 17:30:06

Back in the good old days, you could leave your door unlocked at night, music made sense, and writing computer programs was simply a case of putting some CPU instructions in the right order. Today, we have a mammoth range of libraries, toolkits, abstraction layers, and other things that make writing large programs easier – but it's increasingly difficult to understand what the CPU is actually doing. Open up LibreOffice, for example, and type a dot (period) character. What exactly happens here? How many CPU instructions are being executed between your finger hitting the key and that dot appearing on the screen?

Now, we don't want to sound like old codgers who think that everything should be written in assembly language. There's a reason why we have these layers of abstraction, to make software safer, easier to understand, and more portable. But sometimes it's good to go low-level and interact more closely with the CPU and operating system, to better understand what's going on. So, in this article, we'll get down and dirty with CPU instructions, the ELF executable format, and reverse-engineering binary files so you can see what they do.

As you'd expect, our "test" program simply prints the word "Ciao" on the screen, using the standard C library's puts (put string) routine – no surprises there. But enter ls -l test, and you'll notice something odd: The program is around 8KB in size! Sure, that may sound trivial in today's world of terabyte hard drives, but 8KB is actually huge for a program so simple. (Consider that space exploration classic Elite, back in 1984, was squeezed into 22KB of RAM [1]. That included a whole galaxy to explore, 3D spacecraft, missions, trading, and more. And yet our "Ciao" program is a third of the size.)

Leave a Comment