Extract resource file from exe

I am wrapping Visual C ++ 2008 files, I figured out how to implement them, but I can't figure out how to get them. I have experience in C ++, but none of them have Win32 or Visual C ++. The purpose of the wrapping is to run some code, and then, if everything is in order, it can run the embedded file.

I am wrapping many different files, so code reuse is key, and in all cases I will not know the name of the embedded file. But I could call exe the same as the wrapped file, therefore, if the program can get the name of itself, which will also work.

Some of the wrapped files will be exes, and the rest will be files designed to be run by an external program.

Edit: these files are embedded in the .res file, they are not just concatenated to the end of the exe.

+3
source share
2 answers

So, do you have a binary embedded as a resource in the EXE, and want to read the file?

Try something like this (very rude, look at the MSDN functions for the correct parameters):

HRSRC hResource = FindResource(NULL, MAKEINTRESOURCE(id), type);
HGLOBAL hGlobal = LoadResource(NULL, hResource);
BYTE* pData = (BYTE*)LockResource(hGlobal);
int size = SizeofResource(NULL, hResource);
// ... do something with pData and size, eg write to disk ...
FreeResource(hGlobal); // done with data

You need to add some error to it!

+5
source

The main thing you need to know (which should be present in the .RC file that compiles into the .res file) is the name of the resource. To do this, you can use FindResourceand LoadResourceto download data. You will obviously write this data to a temporary file and execute this file.

0
source

Source: https://habr.com/ru/post/1735434/


All Articles