mar*_*g11 6 c++ executable visual-studio-2012
因此,我使用visual 2012制作了一个应用程序,它可以使用图像和着色器(纯文本).但实际上,我不希望人们打开图像和着色器并乱七八糟.如何将所有这些外部文件压缩为单个或多个文件,但仍可由可执行文件读取?
这个问题难以权威地回答,因为没有防篡改硬件,基本上不可能保护内容免受复杂的黑客攻击.但是,如果澄清一个简单的威慑力就足够了,那么将内容作为资源嵌入可执行文件中呢?请注意,有一些工具可以从.exe文件中提取资源.
或者,您可以加密每个文件并在应用程序加载它时对其进行解密.加密可以像使用已知的常量字节对每个字节进行xor-ing一样简单,也可以使用像Microsoft CryptoAPI那样的真实加密算法.使用真实算法将改善混淆,但仍然不会真正安全.
这是一个简单的程序,它使用这个RC4实现(比CryptoAPI更容易使用)来加密或解密文件并将其写入stdout:
#include <algorithm>
#include <iostream>
#include <fstream>
#include <iterator>
#include <vector>
// insert RC4 implementation here
int main(int argc, char *argv[]) {
const std::string password = "no more secrets";
const std::string filename = argv[1];
// Read file into a buffer.
std::ifstream f(filename.c_str(), std::ios::in | std::ios::binary);
std::vector<char> buffer;
f >> std::noskipws;
std::copy(
std::istream_iterator<char>(f), std::istream_iterator<char>(),
std::back_inserter(buffer));
// Initialize the key from a password.
rc4_key key;
prepare_key((unsigned char *)password.data(), (int)password.size(), &key);
// Encrypt or decrypt (same operation).
rc4((unsigned char *)&buffer[0], (int)buffer.size(), &key);
// Write result to stdout.
std::cout.write(&buffer[0], buffer.size());
return 0;
}
Run Code Online (Sandbox Code Playgroud)
请注意,这不是使用RC4的安全方法,RC4算法本身不再被认为是安全的.
| 归档时间: |
|
| 查看次数: |
1073 次 |
| 最近记录: |