C ++:如何在编译时加密字符串? [英] C++: How to encrypt strings at compile time?

查看:1089
本文介绍了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 "\0\0\0\0\0\0\0\0") }
#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, '\0'

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

这篇关于C ++:如何在编译时加密字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆