有什么方法可以在可执行文件中“隐藏”东西吗? 例如将 dll 添加到您的项目中。 这些文件,如驱动程序、dll 和另一个可执行文件应该以某种方式被提取、使用和删除。 我使用 VS2015 并尝试将文件隐藏在 x86 c++ 应用程序中。
最佳答案
看来你可以使用资源。 FindResource是从资源中提取文件的主要功能。我假设您想手动插入资源,而不是以编程方式。所以:
在 C++ 中插入二进制资源: 在项目的 .rc 文件中:
IDR_BIN BIN DISCARDABLE "file.exe"
在 C++ 中提取二进制资源:
bool ExtractBinResource( std::string strCustomResName, int nResourceId, std::wstring strOutputName )
{
HGLOBAL hResourceLoaded = NULL; // handle to loaded resource
HRSRC hRes = NULL; // handle/ptr. to res. info.
char *lpResLock = NULL; // pointer to resource data
DWORD dwSizeRes;
// find location of the resource and get handle to it
hRes = FindResourceA( NULL, MAKEINTRESOURCEA(nResourceId), strCustomResName.c_str() );
if (hRes == NULL) return false;
// loads the specified resource into global memory.
hResourceLoaded = LoadResource( NULL, hRes );
if (hResourceLoaded == NULL) return false;
// get a pointer to the loaded resource!
lpResLock = (char*)LockResource( hResourceLoaded );
if (lpResLock == NULL) return false;
// determine the size of the resource, so we know how much to write out to file!
dwSizeRes = SizeofResource( NULL, hRes );
std::ofstream outputFile(strOutputName.c_str(), std::ios::binary);
outputFile.write((const char*)lpResLock, dwSizeRes);
outputFile.close();
return true;
}
在这种情况下,strCustomResName
是 "BIN"
而 nResourceId
是您选择#define IDR_BIN
的数字>
如果“隐藏”是指没有人可以看到/理解您的可执行文件中的内容,那么您还应该加密您的文件。
关于c++ - 可执行文件中的 "Hide"文件 (C++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42872754/