Sign in to follow this  

Exe files as resources

This topic is 4837 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How would i import an exe as a resource? I haven't tried, but my guess is to use define it as a custom resource. Also, how would i access that resource and turn it back into an exe on a computer? For instance, how do setup.exes place files on a computer. C++ is the language by the way. Like, if i made a game, how would i have it place the resources in a directory as files. Thx for any help. (please provice example code if you have the time. If not, still any help i appreciate.)

Share this post


Link to post
Share on other sites
Right. Import it as a custom resource.


To get it out use:

FindResource
SizeOfResource
LoadResource
LockResource
CreateFile (or fopen, or streams)
WriteFile (or fwrite, or streams)

Then you'll be set. To change the directories and whatnot, use SetCurrentDirectory.

Share this post


Link to post
Share on other sites
Is there any way to easily extract an exe to RAM and run it from there? Creating a file makes it easy since there are several windows API functions that execute a file, but how would you execute it from RAM (besides doing all the fixups normally done by the OS and then using an assembly call or jmp etc?)

Share this post


Link to post
Share on other sites
Quote:
Original post by Extrarius
Is there any way to easily extract an exe to RAM and run it from there? Creating a file makes it easy since there are several windows API functions that execute a file, but how would you execute it from RAM (besides doing all the fixups normally done by the OS and then using an assembly call or jmp etc?)


Extracting the executable and calling ShellExecute() will run the exe.

If you dont want to extract the exe, then an exe is not a good solution. Put the exe source code into a function and put the function in your program or a dll.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Maega
Right. Import it as a custom resource.


To get it out use:

FindResource
SizeOfResource
LoadResource
LockResource
CreateFile (or fopen, or streams)
WriteFile (or fwrite, or streams)

Then you'll be set. To change the directories and whatnot, use SetCurrentDirectory.


hey its ackpacket again, can't log in. Anyways, i looked into the functions you said at msdn. It says that write file would expect a buffer.. i'm not that experienced with working with memory. Could you maybe tell me which parameters would come from where for write file?

Share this post


Link to post
Share on other sites
Quote:

BOOL WriteFile(
HANDLE hFile, // handle to file to write to
LPCVOID lpBuffer, // pointer to data to write to file
DWORD nNumberOfBytesToWrite, // number of bytes to write
LPDWORD lpNumberOfBytesWritten, // pointer to number of bytes written
LPOVERLAPPED lpOverlapped // pointer to structure for overlapped I/O
);

Just what the comments say [wink]
hFile is from CreateFile(), lpBuffer is the data to write, nNumberOfBytesToWrite is the length of the buffer, and lpNumberOfBytesWritten is a pointer to a DWORD that gets filled with the actual length of data written (should be the same as nNumberOfBytesToWrite unless you run out of disk space or something). lpOverlapped can be NULL unless you want to do async file writing.

You can get a pointer to the resource using LockResource(), and pass that returned value to WriteFile() as the lpBuffer parameter. The nNumberOfBytesToWrite parameter would be the return value of SizeOfResource().

Share this post


Link to post
Share on other sites

This topic is 4837 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this