"Hide" 个可执行文件 (C++)
"Hide" files in executables (C++)
有什么方法可以在可执行文件中添加 "hide" 东西吗?
例如将 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
如果 'hide' 你的意思是没有人可以 see/understand 你的可执行文件中的内容,那么你也应该加密你的文件。
有什么方法可以在可执行文件中添加 "hide" 东西吗? 例如将 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
如果 'hide' 你的意思是没有人可以 see/understand 你的可执行文件中的内容,那么你也应该加密你的文件。