Thread: change running .exe

  1. #16
    Registered User
    Join Date
    Sep 2001
    Posts
    37
    and... (it is not so easy for me to explain all the points)
    cause of desing reasons, it is very importand that there is only one file.
    as i wrote it before, i want to make something like a posti (maby it is not the correct word): something like a sheet of paper you can stick on desktop.
    the point why i want the exe and the text in one file is... i can take it (on floppy orso) and run it somewhere else.

    i hope you can understand now why i want to change a running exe.

  2. #17
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    >>I have a similar question. How does an update work. this is what I want to do. I have a program. and it checks over the internet to see if there is a new version available. if there is, download it and overwrite or change the current exe. can this be done with one exe?

    This is exactly what my program does. Uses FindFile() and checks file creation time. If newer than the current, WinExec() a program to copy the files and PostQuitMsg() to the main app and the .exe copies the new file to the folder then runs the original (calling) .exe again. Have DLL, configuration and data files so only some sleep the program.

    >>would a virus want to append code to itself,
    A list of infected files, routers or even local domains / IP ect (in the case of a zombie bot) allowing return info.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #18
    Registered User
    Join Date
    Sep 2001
    Posts
    37
    can it be???
    is there really no way to change a running file?


  4. #19
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    It is being used by another user at the time, Windows. As far as I know, NO.

    Try opening a text file and then trying to copy it with another app, then modify it and save as SAME name. Don't think you can do it. The file is in windows memory.

    Why is is so important to have only ONE file?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #20
    Registered User
    Join Date
    Sep 2001
    Posts
    37
    hm.
    because you can copy it and open it on another computer... without copying the exe and an additional textfile.
    it should be a compact unit.
    but it is not as importand as worldpeace

  6. #21
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    So put the .exe and the data file in a self extrcacting zip? How often do you see an application distibuted as a single .exe which is not such?
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  7. #22
    Registered User
    Join Date
    Sep 2001
    Posts
    37
    not really often. but isn´t that another reason for doing it

    since it seem to be impossible, i must think about doing a little fake.
    but i think i will go on working on that make-a-clone-and-let-him-do-the-work way.

    there was the trouble that i could not close the original prog before it builds the form.
    i´m working wit borland c++ builder and there is a funktion

    __fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)

    all the code in this function (don´t know if it is correctly a function) is executed before the for appears on screen. when i write an exit(0) in it, the form closes before it appears. i have tryed this with an emty form and with a little projekt with short code in this function. without problems.

    but in my posti-projekt there is lot of code in this function.. like creating a clone.. look for own status (orig. clon) andsoon. and the exit(0) causes an error by calling the function TCustomForm.Destroy in forms.hpp (which is something like a c++ builder class i think. because c++builder is doing that kind of things automatically)
    maby this is because he wants to close something not existing.

  8. #23
    Registered User
    Join Date
    Dec 2001
    Posts
    108
    can it be???
    is there really no way to change a running file?
    There probably is a way to modify the binary code of an open application file in the Windows OS. There are probably also programmers at Microsoft who do not want you to know how it is done.

  9. #24
    Registered User
    Join Date
    Sep 2001
    Posts
    37
    -DarkStar
    yesyes. but they can´t put me in jail for doing it


    is the memory location on disk, where the running file is located, locket during it´s execution? or does windows block only the write commands from things like (open, openf....)
    what i mean is: can i write directly to a location on disk (in my case the location of the exe) to change the file???

  10. #25
    Registered User
    Join Date
    Dec 2001
    Posts
    108
    can i write directly to a location on disk (in my case the location of the exe) to change the file???
    The only way you can overwrite an application file on disk, is while it is NOT running. An open application file cannot modify itself "on the fly", the stability of the Windows OS would be destroyed if you could.

  11. #26
    Registered User
    Join Date
    Sep 2001
    Posts
    37
    yo thanx to all for you patience
    think i got the point.

  12. #27
    Unregistered
    Guest
    What stability of the Windows OS?

    Also, I think this kind of "cant modify a file while its in memory" (file locking) thing is so that if you're running two programs at the same time that access the same file, it prevents file corruption with two/more processes writing to the file.

    Just my guess... =)

  13. #28
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    I dont think its possible....but I never tried....

    When a program is loaded, the system first creates a process object and creates an address space for the loaded program. The system then opens a file handle to the .exe with CreateFile()......then from that, a file mapping is created and mapped to a location in the virtual memory of the newly created process.....The contents of the file then exist in memory (variables, code, resources......). When a variable is altered, the change is not reflected in the exe because all memory changes happen to a copy of that variable...(this attribute is set when the system creates the mapping)......and these are discarded when the process ends and the exe file is closed....

    You can run multiple instances of an program, because that mapping is shared when the second (or third....) instance is loaded.....but then it will inherit the attributes of the shared map...and so you will still not be able to write back to disk.....

    One option is to create a seperate mapping of the exe and alter that....but I guess the system will have no sharing of the file, so you will have to use the shared map.....which of course cannot alter the file..........

    Maybe you can alter the attributes of the mapping??....DuplicateHandle()?????...but then as this handle is held by the system.....??????......??????

    I dont know cuz I have never tried, but I guess it wont work.....
    Last edited by Fordy; 03-21-2002 at 07:56 AM.

  14. #29
    ‡ †hë Ö†hÈr sîÐè ‡ Nor's Avatar
    Join Date
    Nov 2001
    Posts
    299
    Look at this
    hope it helps
    Try to help all less knowledgeable than yourself, within
    the limits provided by time, complexity and tolerance.
    - Nor

  15. #30
    Registered User
    Join Date
    May 2002
    Posts
    132
    I have made a system where a global variable held the name of a DLL that held all the different functions used for a certain system of functions for the program. Then I could select out of a menu "Update", which would request a filename and so I would enter the new DLL's filename/location. This program would then set another global variable that marked this "system" as shutoff. The program would then unload the old DLL, then load the new one (via the LoadLibrary() call). Then it would change the variable that would mark the "system" as on once again. This method worked as long as new functions were added, or old function prototypes/calls weren't changed. It only helped to update old functions with newer versions (perhaps faster code, or more reliability, stability or whatever reason provocked a new version).

    However, if prototypes/calls or the header file changed in anyway then it would require recompiling the program itself and changing the DLL (originally loaded).

    Another method of updating a file would require you to setup a program on the side, or make a clone like mentioned above and have this other program (or clone) update the old exe file with the new changes. Then have this other program or clone start the updated exe up, have the other program or clone shut itself down. Then perhaps have some sort of flag inside your main exe that will delete this update program or clone from the harddrive (if it's no longer needed and a new program would be created when the next update comes).

    These are the only methods, to date, that I know of how to update an EXE while it's running.

    Hope this helps,
    Tyouk

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reference parameters and calculating change
    By Cstudent2121 in forum C Programming
    Replies: 6
    Last Post: 11-04-2005, 03:19 PM
  2. Change this program so it uses function??
    By stormfront in forum C Programming
    Replies: 8
    Last Post: 11-01-2005, 08:55 AM
  3. Change Value in an array
    By beginner999 in forum C Programming
    Replies: 3
    Last Post: 01-18-2003, 07:16 AM
  4. Replies: 2
    Last Post: 11-08-2002, 03:22 AM
  5. Replies: 2
    Last Post: 09-04-2001, 02:12 PM