将整个自我可执行文件复制到内存 C++

copy entire self executable to memory c++

我有一个 C++ 可执行文件,我将它的最后一部分与图像连接起来。 想要将整个可执行文件加载到内存中,然后将连接的图像分解为一个 unsigned char * 以在同一个可执行文件中加载。

假设可执行文件本身大小为47104,图像大小为13216。 因此将这两个连接起来,可执行文件大约为 60320 (47104 + 13216)。 我在想:

unsigned char * entireExe;
unsigned char * img;

memcpy(entireExe, how to load the entire executable to memory???, 60320);
memcpy(img, entireExe + 47104, 13216);
displayImage(img); // using any method available (opencv/poco/devilIL/opengl,etc)

为什么不加载一个DLL到内存中,并使用它的地址space来保存图像信息呢?它应该分配足够的 space 来做你需要做的任何事情。或者,如果需要,您可以在 DLL 创建的 window 中显示图像。如果您尝试编辑可执行文件本身,我建议您使用 IDA 或任何其他逆向工程工具查看它的 PE struct/memory 页面并从那里开始。

这是一个很好的资源: https://github.com/67-6f-64/Firefly/blob/master/Firefly%20Library/pe_structs.hpp