954,492 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Creating an Executable in runtime

Greetings all
How can i create an executable in run-time? (win32). i need a simple wrapper for different console commands. this is because i must have executable there is no way around it. so what i have come up with is passing the command that i want executed as a command line parameter and it will create an executable that will execute those commands upon execution. I know this is possible because i have seen it being used. How can i do this?
If any one could explain this to me or refer me to any kind of helpful documentation, it would be greatly appreciated.

astropirate
Newbie Poster
5 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

Follow up on old threads, before finding somewhere else to post.
http://cboard.cprogramming.com/windows-programming/117461-creating-executable-runtime.html

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

Example: "g++ -o out.a main.cpp"
If you want that to be executed inside a C or C++ program:
system("g++ -o out.a main.cpp");

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

Write an assembler, allocate some space and run the output as a function.

MosaicFuneral
Posting Virtuoso
1,691 posts since Nov 2008
Reputation Points: 888
Solved Threads: 116
 

the thing is that i want it to give me an executable not a function. now i was thinking to write to creat the exe first save it as a resource then get the input for the command from the command line then have that command replace the simple exe with the system() function.

astropirate
Newbie Poster
5 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 
int main()
{
	system("dummy text afgfdhhgfhjjg");
}


1. Compile this
2. Searching the executable for the string literal and note the offset
3. Use a binary fstream to overwrite that section in the executable producing executable.
4. Hope that overwriting with a larger string won't go over anything important.
5. Either PROFIT or RUNTIME ERROR.

:p

ganbree
Light Poster
28 posts since Apr 2007
Reputation Points: 17
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You