I am writing a C app on Windows with MinGW/gcc. I need to use the #include directive to include a file that contains an encrypted string. The string will be decrypted at runtime. I want to do this so the string will not be visible if looking at the executable with a hex editor.
I tried this, but it doesn’t work. You get the idea, though:
char *hidden_str =
#include "encrypted_text.dat"
There may be unescaped stuff in there that’s confusing the compiler. I don’t know. I don’t know what happens to it after it’s encrypted.
If there’s a better approach to this, I’m open to it.
If you installed and configured MSYS when you installed MinGW, you should have access to a command called
xxd, which takes a hex dump of a file. By using the-icommand line flag, you can get it to output a C-friendly file which you can easily import.An example call would be:
The contents of
output.hwould then look like:You can then include that file into your C source code and have access to it: