Download Summary
Transcript
The Frontend Preprocessing The C/C++ preprocessor acts before any semantic analysis takes place and is responsible for expanding macros, including files, or skipping parts of the code by means of the preprocessor directives, which start with #. The preprocessor works in a tight dependence with the lexer, and they interact with each other continuously. Since it works early in the frontend, before the semantic analysis tries to extract any meaning from your code, you can do bizarre things with macros, such as change a function declaration with macro expansions. Notice that this allows us to promote a radical change in the syntax of the language. If it pleases you, you can even code like this: This is the code of Adrian Cable, one of the winners of the 22nd International Obfuscated C Code Contest (IOCCC), which, for our amusement, allows us to reproduce the contestants' source code under the Creative Commons Attribution-ShareAlike 3.0 license. It is an 8086 emulator. If you want to learn how to deobfuscate this code, read the ClangFormat section in Chapter 10, Clang Tools with LibTooling. To expand the macros, you can also run the compiler driver with the -E option, which will only run the preprocessor and then interrupt the compilation, without any further analyses. [ 88 ]