簡體   English   中英

可執行文件(C ++)中的“隱藏”文件

[英]“Hide” files in executables (C++)

有什么辦法可以在可執行文件中“隱藏”東西嗎? 例如,將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

如果“隱藏”是指沒有人可以看到/理解可執行文件中的內容,則還應該加密文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM