C++:如何在编译时加密字符串?

2022-01-05 00:00:00 windows visual-studio-2008 c++

我想在我的 .exe 中隐藏一些字符串,这样人们就不能简单地打开 .exe 并查看那里的所有字符串.我不关心加密方法的强度,所以我可能会使用 XOR 等.

I want to hide some strings in my .exe so people can't simply just open the .exe and look at all the strings there. I don't care about the strength of the encrypting method, so I will probably use XOR etc.

如何在编译时执行此操作?这样我的字符串就不会存储在 .exe 中,但加密版本会.然后,我每次都会使用我的解密功能在屏幕上显示这些字符串.

How can I do this at compile time? That way my strings won't be stored in the .exe but the encrypted versions would. Then, I would just use my decrypting function every time to display those strings on screen.

推荐答案

您可以使用宏对其进行加密或编写自己的预处理器

you can encrypt it using macros or write your own preprocessor

#define CRYPT8(str) { CRYPT8_(str "") }
#define CRYPT8_(str) (str)[0] + 1, (str)[1] + 2, (str)[2] + 3, (str)[3] + 4, (str)[4] + 5, (str)[5] + 6, (str)[6] + 7, (str)[7] + 8, ''

// calling it
const char str[] = CRYPT8("ntdll");

相关文章