Let's say I have a string that I would like to obfuscate in my code. (This example is just for learning.)
My plan is to wrap the string literal with a macro, e.g.
#define MY_STRING "lol"
const char *get_string() { return _MY_ENCRYPTION_MACRO(MY_STRING); }
and, as a pre-build step, to run my source file through my own preprocessor to look for all usages of _MY_ENCRYPTION_MACRO
and obfuscate the strings accordingly.
How would I go about doing this preprocessing with Visual C++?
If you used a recent GCC (i.e. GCC 4.6) on Linux, you could also have a plugin which provides a builtin function to "encrypt" compile time strings, or you could even make it a GCC MELT extension (MELT is a high-level domain specific language to extend GCC).
If you use some other C++, you might have your own pre-processing scripts finding your macros. You might for instance have some program which scan every occurrence of
ENCRYPTSTRING("anyconstantstring")
in all your C++ sources, and generate amycrypt.h
file which you#include "mycrypt.h"
in your C++ code. Then you might do tricks likeand have your generated
"mycrypt.h"
contain things likeetc. The
"mycrypt.h"
generator could be anawk
orpython
orocaml
(etc...) script.