• Advertisement
Sign in to follow this  

Generating EXEs from a program.

This topic is 1788 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

Hi all,

 

I'll cut to the chase. 

Essentially the idea of my C++ program is that it stores the binary data of a pre compiled EXE program in it's memory, and then dumps that EXE into the user's folder. The idea is that my program will create an executable file on disk.

 

I have written programs which copy EXEs, so I have two questions:

 

1. How would I store the data pure EXE file in my C++ program? I know if I have the memory I can just dump it into a new file.

 

2. I have a few string constants at the start of my EXE (#defines in the original c++ code). Can I edit these on the programs copy of the EXE file before writing the data to disk? I know I could make a seperate file containing the constants and have the generated EXE read these in, but I'd rather it was created with the data embedded.

 

I have tried my best to explain my predicament but if there is anything you think I should expand I would be happy to do so.

Thanks in advance,

 

 

Mike

Share this post


Link to post
Share on other sites
Advertisement

I'm guessing antivirus software might get alarmed if you dump exes to people's hard drives.

 

You can't replace a #define in an exe without recompiling since it just pastes the macro expansion into the source code text wherever it occurs. You'd be better off reading the strings from a configuration file instead and load them when the program starts up...

Share this post


Link to post
Share on other sites

1. How would I store the data pure EXE file in my C++ program? I know if I have the memory I can just dump it into a new file.

 

If you're under Windows, you can store the executable as a binary resource inside the larger executable, and then extract it as needed.

 

2. I have a few string constants at the start of my EXE (#defines in the original c++ code). Can I edit these on the programs copy of the EXE file before writing the data to disk? I know I could make a seperate file containing the constants and have the generated EXE read these in, but I'd rather it was created with the data embedded.

 

Maybe yes, maybe no. In any case, the new string contents will probably have to be the same size as the old one, or you'll likely break everything. In general, this is not good design. What's wrong with a resource file? Clearly if the strings are capable of changing they aren't meant to be constants.

 

I understand the concept in the first point (for a self-contained installer, for instance) but the second point doesn't make sense to me. If this is for localization, there are better solutions than hammering in different text inside the executable. But I don't know.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement