Jump to content

  • Log In with Google      Sign In   
  • Create Account


Generating EXEs from a program.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 mikenovemberoscar   Members   -  Reputation: 215

Like
0Likes
Like

Posted 28 February 2013 - 03:30 PM

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



Sponsor:

#2 Paradigm Shifter   Crossbones+   -  Reputation: 5130

Like
2Likes
Like

Posted 28 February 2013 - 03:39 PM

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...


"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

#3 Bacterius   Crossbones+   -  Reputation: 8157

Like
3Likes
Like

Posted 28 February 2013 - 03:40 PM

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.


The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#4 mikenovemberoscar   Members   -  Reputation: 215

Like
0Likes
Like

Posted 02 March 2013 - 05:37 AM

In that case, how do I neatly bundle a resource file in with my exe?



#5 Bacterius   Crossbones+   -  Reputation: 8157

Like
1Likes
Like

Posted 02 March 2013 - 05:41 AM

In that case, how do I neatly bundle a resource file in with my exe?

 

 

See this link for how to include resources: http://msdn.microsoft.com/en-nz/library/windows/desktop/aa380599(v=vs.85).aspx

 

And this one for how to extract them: http://stackoverflow.com/questions/11388134/extract-file-from-resource-in-windows-module


The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#6 mikenovemberoscar   Members   -  Reputation: 215

Like
0Likes
Like

Posted 02 March 2013 - 04:02 PM

Thanks very much!






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS