相关疑难解决方法(0)

在编译时加密/混淆字符串文字

我想在编译时加密/编码一个字符串,以便原始字符串不会出现在已编译的可执行文件中.

我已经看过几个例子,但他们不能把字符串文字作为参数.请参阅以下示例:

template<char c> struct add_three {
    enum { value = c+3 };
};

template <char... Chars> struct EncryptCharsA {
    static const char value[sizeof...(Chars) + 1];
};

template<char... Chars>
char const EncryptCharsA<Chars...>::value[sizeof...(Chars) + 1] = {
    add_three<Chars>::value...
};

int main() {   
    std::cout << EncryptCharsA<'A','B','C'>::value << std::endl;
    // prints "DEF"
}
Run Code Online (Sandbox Code Playgroud)

我不想像它那样单独提供每个角色.我的目标是传递一个字符串文字,如下所示:

EncryptString<"String to encrypt">::value
Run Code Online (Sandbox Code Playgroud)

还有一些像这样的例子:

#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] + …
Run Code Online (Sandbox Code Playgroud)

c++ string templates metaprogramming compile-time

15
推荐指数
2
解决办法
6007
查看次数

使用constexpr编译时间字符串加密

我想要一个编译时字符串加密,这样我就可以在我的代码中编写:

const auto encryptedInvalidLicense = ENCRYPT("Invalid license");
std::cout << encryptedInvalidLicense.decrypt() << std::endl; // outputs "Invalid license"
Run Code Online (Sandbox Code Playgroud)

并且字符串"Invalid license"不会出现在二进制文件中.预构建可能是答案,但我正在寻找一个纯c ++ constexpr解决方案来解决这个问题,它将得到VS2015的支持.

有什么建议?


  1. 我已经研究过编译时字符串加密,它没有为问题提供constexpr解决方案.

  2. 我还研究了http://www.unknowncheats.me/forum/c-and-c/113715-compile-time-string-encryption.html.虽然它是一个constexpr解决方案,但VS2015仍然将字符串纯文本添加到二进制文件中.

c++ reverse-engineering constexpr c++11 c++14

15
推荐指数
1
解决办法
5835
查看次数

使用Variadic模板编译时"字符串"操作

嘿所有,我目前正在尝试编写一个编译时字符串加密(使用"字符串"和"加密"字样很松散)lib.

我到目前为止的内容如下:

// Cacluate narrow string length at compile-time
template <char... ArgsT>
struct CountArgs
{
 template <char... ArgsInnerT> struct Counter;

 template <char Cur, char... Tail>
 struct Counter<Cur, Tail...>
 {
  static unsigned long const Value = Counter<Tail...>::Value + 1;
 };

 template <char Cur>
 struct Counter<Cur>
 {
  static unsigned long const Value = 1;
 };

 static unsigned long const Value = Counter<ArgsT...>::Value;
};

// 'Encrypt' narrow string at compile-time
template <char... Chars>
struct EncryptCharsA
{
 static const char Value[CountArgs<Chars...>::Value + 1];
}; …
Run Code Online (Sandbox Code Playgroud)

c++ templates metaprogramming c++11

8
推荐指数
1
解决办法
3644
查看次数