Make exe file using a cpp program

closed account (Dy85Djzh)
Friends, i need to write a program that when run makes another exe file .
Eg: make a program named 'sxes' and compiled it. When i execute or run sxes a new exe file named 'new01.exe' is created. This new01.exe when executed must input two numbers and add them and print output.
I want to write a program same as installer file .
Please any body help me. I dont want any any software to do this . I want to code it myself.
Please help i was trying this for a long time
Sounds like your primary program will need to generate at least a .cpp file, which is subsequently compiled. If you know how to compile from command line (with/without using a makefile) this is doable.

You can create a new file using std::ofstream and std::system to perform command-line commands.

Good luck, Bilderbikkel

closed account (Dy85Djzh)
I don't understand . can you please explain in detail
I wrote a program , in which I created resultant exe fil in binary mode , and i inserted hex values of the program to it . but it didnt work and shows instruction error . This program succeeded in making exe file but failed to insert instructions. please help me. thanks for your replay.
Here is my program.

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<process.h>
int main()
{
textcolor(2);
clrscr();
ofstream k;
k.open("sid0199.exe",ios::binary); //create exe file
if(k.fail())
{
cout<<"cannot open exe\n";
getch();
exit(0);
}
cout<<"success\n"; //hex values of another exe file. I use a hex editor
char s[]={0x23,0x69,0x6E,0x63,0x6C,0x75,0x64,0x65,0x3C,0x69,0x6F,0x73,0x74,0x72,0x65,0x61,
0x6D,0x2E,0x68,0x3E,0x0D,0x0A,0x23,0x69,0x6E,0x63,0x6C,0x75,0x64,0x65,0x3C,0x63,
0x6F,0x6E,0x69,0x6F,0x2E,0x68,0x3E,0x0D,0x0A,0x76,0x6F,0x69,0x64,0x20,0x6D,0x61,
0x69,0x6E,0x28,0x29,0x0D,0x0A,0x7B,0x0D,0x0A,0x74,0x65,0x78,0x74,0x63,0x6F,0x6C,
0x6F,0x72,0x28,0x32,0x29,0x20,0x20,0x20,0x20,0x20,0x20,0x3B,0x0D,0x0A,0x74,0x65,
0x78,0x74,0x62,0x61,0x63,0x6B,0x67,0x72,0x6F,0x75,0x6E,0x64,0x28,0x39,0x29,0x3B,
0x0D,0x0A,0x63,0x6C,0x72,0x73,0x63,0x72,0x28,0x29,0x3B,0x0D,0x0A,0x69,0x6E,0x74,
0x20,0x69,0x2C,0x6A,0x2C,0x6B,0x3B,0x0D,0x0A,0x67,0x6F,0x74,0x6F,0x78,0x79,0x28,
0x35,0x2C,0x35,0x29,0x3B,0x0D,0x0A,0x63,0x6F,0x75,0x74,0x3C,0x3C,0x22,0x65,0x6E,
0x74,0x65,0x72,0x20,0x69,0x2C,0x6A,0x2C,0x6B,0x5C,0x6E,0x22,0x3B,0x0D,0x0A,0x67,
0x6F,0x74,0x6F,0x78,0x79,0x28,0x38,0x2C,0x38,0x29,0x20,0x3B,0x0D,0x0A,0x63,0x69,
0x6E,0x3E,0x3E,0x69,0x3B,0x0D,0x0A,0x67,0x6F,0x74,0x6F,0x78,0x79,0x28,0x38,0x2C,
0x39,0x29,0x3B,0x0D,0x0A,0x63,0x69,0x6E,0x3E,0x3E,0x6A,0x3B,0x0D,0x0A,0x67,0x6F,
0x74,0x6F,0x78,0x79,0x28,0x38,0x2C,0x31,0x30,0x29,0x3B,0x0D,0x0A,0x63,0x69,0x6E,
0x3E,0x3E,0x6B,0x3B,0x0D,0x0A,0x69,0x6E,0x74,0x20,0x64,0x3B,0x0D,0x0A,0x64,0x3D,
0x69,0x2B,0x6A,0x2B,0x6B,0x3B,0x0D,0x0A,0x67,0x6F,0x74,0x6F,0x78,0x79,0x28,0x35,
0x2C,0x31,0x32,0x29,0x3B,0x0D,0x0A,0x63,0x6F,0x75,0x74,0x3C,0x3C,0x22,0x64,0x3D,
0x73,0x75,0x6D,0x3D,0x22,0x3C,0x3C,0x64,0x3B,0x0D,0x0A,0x67,0x65,0x74,0x63,0x68,
0x28,0x29,0x3B,0x0D,0x0A,0x7D,0x00};
k.write((char*) &s,sizeof(s));
k.close();
cout<<s;

getch();
exit(0);
return(0);
}

Last edited on
I won't, because your references are against all C++ standards: 'void main' and '#include <iostream.h>' are examples of horrible style. Please find a good starting point first, like http://www.richelbilderbeek.nl/CppMain.htm . After posting proper code, it will be my pleasure to help.

Cheers, Bilderbikkel
Can you please explain why you need this type of functionality? This type of functionality is naturally used in viruses, in which case we will not provide assistance in the creation of software that is malicious.
closed account (Dy85Djzh)
I am very sorry about my programming knowledge . I was taught to program this way and when i write programms this way it doesn't show any error so i didn't try to learn that more . sorry . I understand that we should not use void main() . But I don't understand problem in using #include<iostream.h> . I use #include<iostream> and using namespace std; . But I got an error . Can you tell me more about that .
Actually I didn't mean to create a virus or something like that using this program . My friend and I programmed a simple c++ graphics game , as a project in my class , and we decided to create a installer file for it (just to learn) . At First we searched for some softwares to make installer file . But then we thought to program it , and started this. Please don't misunderstand .
We have been working this for a long time .. Please don.t dissapoint me .
Please help me

Installer files don't store the files they are installing inside their code, they store them as resources in their executable.
closed account (Dy85Djzh)
Can you tell me how to do that . I mean can you explain in detail
It depends on which compiler/IDE you use.
closed account (Dy85Djzh)
Iam using turbo cpp 3.0.
Can you tell me how to do that
Installers like NSIS or Inno Setup (that's what most application comes packed) store installation files packed at the end of the main .EXE itself, not stored as resources.

At runtime it opens itself, it knows somehow the offset to seek (I think is also stored somewhere in the EXE) and just unpack the content.
closed account (Dy85Djzh)
Yeah man this is the same thing i was looking for . I just need to know how to do it
thanks a lot
Topic archived. No new replies allowed.