Results 1 to 10 of 10

Thread: Increase file size

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2002
    Posts
    183

    Question Increase file size

    ARGH! Im going mad! I just cant work out how to increase the file of an executable without stopping it from working! Could somone please please (im despret) show me how i can make a program increase the size of "C:\file.exe" by 100 bytes?

    THANKS!
    When you ask a question, try and answer a few

  2. #2
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    What compiler are you using? Just put a lot of debugging information in your exe and it'll increase the file size by somewhat.
    PS: People actually try to decrease the file size and you're increasing it?
    Baaaaaaaaah

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2002
    Posts
    183

    .

    Im using dev C++, but i dont want to make a big program, i want a normal sized program that increases the size of a different program :P
    When you ask a question, try and answer a few

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169

    Re: Increase file size

    Originally posted by Evil_Cowgod
    ARGH! Im going mad! I just cant work out how to increase the file of an executable without stopping it from working! Could somone please please (im despret) show me how i can make a program increase the size of "C:\file.exe" by 100 bytes?

    THANKS!
    You should just be able to open it as a binary file then append 100 NULL bytes to it:
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main() {
        ofstream output("program.exe", ios::binary | ios::append);
        char block[100];
        memset(block, 0, 100); // i think this is the right way round...
    
        output.seekg(ios::end, 0);
    
        output.write(block, 100);
    }
    ...that's just typed straight into the reply box so I'm not sure if it'll compile -- the theory should work though. I did some work on self-extracting archives and never had any problems by just appending the data to a stub program.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362
    ***Time out***

    Explaine me that line please : put.seekg(ios::end, 0);

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    .seekg goes to a specific location in the file. You give a position and an offset, the position is either the start, end, or current position, and the offset is how far away from that.

    The documentation for seekg() will give you the details
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362
    seekg = input
    seekp = output

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  9. #9
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362
    Here is the program and it work but I have a problem by the determination of the size to increment. I wanted the user write the number of null character he wants in the third arguments but I wanted that in Ko so I *1024 but that doesn't increment well.

    PHP Code:
    #include <fstream>
    #include <iostream>
    #include <string>

    using namespace std;

    void main(int argccharargv[])
    {

        
    // 0 = name, 1 = file, 2 = size
        
    if (argc != 3)
        {
            
    cout << "Missing argument";
            exit(
    0);
        }
    //End if

        
        
    ofstream fileOut(argv[1], ios::binary ios::app);

        
    //Si le fichier n'existe pas alors on quitte
        
    if (!fileOut)
        {
            
    cout << "File not found";
            exit(
    0);
        }
    //End if
                    /****Problem is here to calculate in ko****/
        
    unsigned int iSize = (atoi(argv[2]))*1024;

        
        
    char *cData = new char[iSize];

        
    memset(cData0iSize);

        
    fileOut.seekp(0,ios::end);
        
    fileOut.write(cData,fileOut.tellp());
        
    fileOut.close();

    }
    //End Main 
    But that code can be compiled without problem.
    Daok

  10. #10
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362
    Here is the final version and all work correctly without any problem.

    PHP Code:
    #include <fstream>
    #include <iostream>
    #include <string>
    //#include <time.h>
    #include <windows.h>

    using namespace std;

    void main(int argccharargv[])
    {

        
    // 0 = name, 1 = file, 2 = size
        
    if (argc != 3)
        {
            
    cout << "Error : Missing argument" << endl;
            exit(
    0);
        }
    //End if

        
        
    ofstream fileOut(argv[1], ios::binary ios::app);

        
    //Si le fichier n'existe pas alors on quitte
        
    if (!fileOut)
        {
            
    cout << "Error : File not found" << endl;
            exit(
    0);
        }
    //End if

        
    if (atoi(argv[2]) > 10240)
        {
            
    cout << "Error : Can not enlarge more than 10 megs each time";
            exit(
    0);
        }
    //End if
        
    unsigned int iSize = (atoi(argv[2]) * 1024);

        
    char *cData = new char[iSize];

        
    memset(cData0iSize);

        
    fileOut.seekp(fileOut.tellp());
        
    fileOut.write(cData,iSize);
        
    fileOut.close();
        
    string cMessage[] = {"Copyright Daok","Daok Production""Daok Own Ya"};
        
        
    DWORD dwStart GetTickCount();

        
    /*srand((unsigned)time(NULL));
        cout << cMessage[rand() % 3] << endl;
        */
        
    cout << cMessage[dwStart 3] << endl;
        
    }
    //End Main 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width