Home > OS >  Hide string in binary at compile time?
Hide string in binary at compile time?

Time:11-11

I want to obfuscate a particular string in the binary of a C program to make it harder to analyze. I know this will not prevent someone from seeing the string if running it in a debugger. Yes, this is merely obfuscation.

Every instance of obfuscation triggers a discussion saying it has no value whatsoever. So did this one! I am aware that a capable and determined attacker will be able to recover the string. For the sake of the argument let's say I'm writing a game for X year olds and the string to be hidden is a URL to be called only once they beat the game and their name will be added to the hall of fame. It's reasonable to assume that most X year olds will not have skills that go beyond opening the binary file in a hex editor. Thanks!

Is there some elegant way to do the hiding at compile time, perhaps using the C preprocessor and a macro?

What i have seen so far is a suggestion by Yuri Slobodyanyuk resulting in this:

#define HIDE_LETTER(a)   (a)   0x50
#define UNHIDE_STRING(str)  do { char * ptr = str ; while (*ptr) *ptr   -= 0x50; } while(0)

...

  char str1[] = { HIDE_LETTER('s'), HIDE_LETTER('e'), HIDE_LETTER('c'), HIDE_LETTER('r'), HIDE_LETTER('e'), 
    HIDE_LETTER('t'), '\0' };

  UNHIDE_STRING(str1);  // unmangle the string in-place

It works but it's a bit ugly.

  • Related