Worst abuse of the C preprocessor

Leopoldo Luna
2 min readOct 20, 2020

--

In order to understand the code presented we have to clarify the concept of obfuscation. So the obfuscation in programming is the act of create code or machine code difficult to understand. This practice is used for protect the intellectual property or difficult the realization of reverse engineering.

The code below was created by Jim Hague, In 1986, he created this C Code that is able to translate morse code from ASCII code, which was selected for the 1987 t-shirt collection as “The worst abuse of the C preprocessor”.

Our objective in this blog is to understand this C code, and try to figure out what all these DIT, DAT, _, … are use for.

what this program does?

This program translate ASCII code to morse code, so change words to morse.

how it works?

  1. save the code in a file in this case we are going to save it in hague.c
  2. run the code with this command: “ gcc hague.c -o h”
  3. run the executable “./h”
  4. it will wait until you write a word or words
  5. get your morse code from the string or strings that you enter.
  6. go here and try your string in this audio translator

De-obfuscation!!

So the first thing that we know is that inside the code there are macros with its respective tokens, as we know in the compiling process, the preprocessor swap all the macros for its tokens, so the first thing that we have to do is run the compiler till the preprocessing phase.

in order to get the file in the preprocessing phase we have to run this command: “gcc -E hague.c -o h” where hague.c is our .c file or the file that contains the above code, -o h means that the output is going to be stored in h, and -E flag is to stop in the preprocessor.

--

--