我如何#包括使用加密字符串的文件? [英] How can I #include a file with encrypted string?
问题描述
我写在Windows上一个C程序使用MinGW / GCC。我需要使用#include指令,包括一个包含加密的字符串的文件。该字符串将在运行时解密。我想这样做,因此,如果寻找与十六进制编辑器可执行文件中的字符串是不可见的。
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.
推荐答案
如果你安装了,当你安装了MinGW的,你应该能够访问一个名为的 XXD
,这需要一个文件的十六进制转储。通过使用 -i
命令行标志,就可以得到它的输出C-友好的文件,你可以方便地导入。
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 -i
command line flag, you can get it to output a C-friendly file which you can easily import.
一个例子电话是:
xxd -i in_file output.h
中的内容 output.h
然后将如下所示:
unsigned char in_file[] = {
0x68, 0x65, 0x6c, 0x6c, 0x6f
};
unsigned int in_file_len = 5;
您就可以包含这个文件到您的C源$ C $ c和访问它:
You can then include that file into your C source code and have access to it:
#include "output.h"
unsigned int i;
for(i = 0; i < in_file_len; i++)
{
printf("%c", in_file[i]);
}
这篇关于我如何#包括使用加密字符串的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!