De-obfuscate Jim Hague preprocessor “maze”.

Issam Sebri
2 min readMar 9, 2020
Photo by Luemen Carlson on Unsplash

C pre-processor directives

Using a pre-processor directives in our C program is a crucial techniques to avoid some repetition and simplify a debugging and maintenance of our code, even it’s the only way to include file inside another which level up of code de-fragmentation.

In the International Obfuscated C Code Contest (IOCCC) Jim hague in1986 win the contest with a maze use of the C programming directives and macros what we try to De-obfuscated today, begin with showing the code:

Compile after the preprocessing stage

First thing we need to do is looking how the compiler read the program and to see that w compile it and we stop after the preprocessing stage using “-E” flag of the “gcc”:

gcc -E hague.c > prehague.c

After that we try to fix alignment for the readability of the code to look like the following one:

As we see for the first look we distinguish three functions main, _DIT, __DAH and a global variable array _DAH_[].

the _DIT function is no doubt is from the output family especially the famous int putchar(int). and there is something unusual about the __DAH function, it call itself what is obviously a recursion behavior. with a base statement that the variable DIT_ > 3, unless it’s true the function shifting on left the variable DIT_ by one, what make on binary form.

Also in there is a main function which hold a three lays of nested loops starting with the most inner one:

So this is a loop with two argument counter for more explicit way *x and y with two initial value 2 ans z.

And after some sophisticated name changes the program become more explicit and more comprehensible:

--

--