Reputation: 43
Is there any way to kind of "hide" things in executables? For example adding dll's to your project. These files such as a driver, a dll and another executable should somehow get extracted, be used and deleted after that. Im using VS2015 and I try to hide the files in a x86 c++ application.
Upvotes: 0
Views: 1284
Reputation: 572
Seems like you could use resources. FindResource is the main function for extracting the file from resources. I assume you want to insert a resource by hand, not programatically. And so:
Inserting binary resource in c++: In your .rc file of the project:
IDR_BIN BIN DISCARDABLE "file.exe"
Extracting binary resource in 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;
}
Where in this case strCustomResName
is "BIN"
and nResourceId
is what number you chose to #define IDR_BIN
If by 'hide' you mean that nobody could see/understand what's in your executable then you should also encrypt your file.
Upvotes: 1