c++ - 可执行文件中的 "Hide"文件 (C++)

标签 c++ file driver 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 的数字>

如果“隐藏”是指没有人可以看到/理解您的可执行文件中的内容,那么您还应该加密您的文件。

关于c++ - 可执行文件中的 "Hide"文件 (C++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42872754/

相关文章:

linux - Beaglebone Black ubuntu 编译驱动

c++ - 是否可以在 lambda 中捕获可变数量的参数?

C++ - 在 "for"函数中计算平均值

c - 尝试写入日志文件时权限被拒绝

file - 在 Windows 中使用批处理文件复制相同的文件

android - 没有华硕 MeMO Pad 的驱动程序可以使用 eclipse 进行应用程序调试

c++ - 智能指针应该如何向下转换?

c++ - 在 C++ 中为 3D 数组分配连续内存

C - 使用 StdIn 和 StdOut 通过逐位过程进行一次性密码本加密

arduino - macOS X Mojave 10.14 Beta FTDI USB 串行驱动程序