How a file can edit itself after the run?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Thread: How a file can edit itself after the run?

  1. #1
    Join Date
    Jan 2013
    Posts
    5

    Question How a file can edit itself after the run?

    Hi all.
    I am trying to create an exe file that can write data in itself.
    For example i made an exe file by VB6 with name F1.EXE and it's size is 27356 bytes. there is another file including 3 bytes with name 3b.dat .
    I joined both files together at by name of previous exe by this method :

    copy /b F1.exe + 3b.dat F1.exe

    So i have new exe file with size 27359 bytes.in spite of adding these new three bytes at the bottom of F1.exe file , it is working truly in run.
    now i am asking can F1.exe change these three bytes at the end of itself after run?
    my goal is storing data in that three bytes !!!
    of course i know that it is not natural but i need to storing data like this.
    any solution?
    thanks everybody.

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,984

    Re: How a file can edit itself after the run?

    You'd have to open as BINARY, but what your are doing will hide the files from other processes and the OS in some instances.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,844

    Re: How a file can edit itself after the run?

    Well perhaps the phrasing is wrong in the question but as worded the simple answer is NO. A program can not do anything after it is run. It can only do something while it is running.
    Always use [code][/code] tags when posting code.

  4. #4
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: How a file can edit itself after the run?

    other problem is that you cannot edit the EXE while it is running... (windows Locks file access to Special access read only)..
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  5. #5
    Join Date
    Jan 2013
    Posts
    5

    Re: How a file can edit itself after the run?

    Quote Originally Posted by DataMiser View Post
    Well perhaps the phrasing is wrong in the question but as worded the simple answer is NO. A program can not do anything after it is run. It can only do something while it is running.
    Of course I am aware what you're saying about the limitations for an exe file after run in windows.
    my final goal is just adding some bytes at the end of file not exactly editing exe table !
    and i know this adding action , doesn't causes to destruction the exe file for run! i just wanna add bytes after run!

    Now let's examine this issue from two vision.

    1)
    changing the summary properties of the exe file after the run.
    look at this picture:


    if you try to edit summary properties of a file after run ,you will see it is quite possible.
    Some changes like this is possible after the run. I myself checked it and it was right.
    this example shows us there is some locations in exe file that we can change them even after the run!
    so I realize that this is quite possible, so why we can not add some byte at the end of file after run?

    2)
    of course Windows can set or unset the lock for the file !
    why we can not change our file at the same time that windows is saving summary information?

  6. #6
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,844

    Re: How a file can edit itself after the run?

    I assume that when you keep saying after run you actually mean during run. Clearly no program can do anything if it is not running.

    If you really mean after it has ran then of course you can do anything you want to it from an external source because it is not running. The program however can not do anything unless it is running.

    As for the second question.. umm because Windows has the file open and locked.
    Always use [code][/code] tags when posting code.

  7. #7
    Join Date
    Jan 2013
    Posts
    5

    Question Re: How a file can edit itself after the run?

    Quote Originally Posted by DataMiser View Post
    I assume that when you keep saying after run you actually mean during run. Clearly no program can do anything if it is not running.

    If you really mean after it has ran then of course you can do anything you want to it from an external source because it is not running. The program however can not do anything unless it is running.

    As for the second question.. umm because Windows has the file open and locked.
    Yes of course i mean during run.
    so as the result ,all of this topic users believe that exe file during run could not be change ever?

  8. #8
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,844

    Re: How a file can edit itself after the run?

    It helps when you use the correct words, after and during are two totally different things and imply something much different.

    To the best of my knowledge Windows locks program files while they are running making them read only.
    This was not the case in DOS which loaded the entire exe into memory and would allow you to write to it or even delete it while running.

    I am not aware of anyway to do this under Windows but have never experimented with it as I see no reason to bother doing it.
    Always use [code][/code] tags when posting code.

  9. #9
    Join Date
    Jul 2005
    Posts
    1,074

    Re: How a file can edit itself after the run?

    Maybe if the OP explains well why he needs to write to the exe somebody would help to resolve the problem.
    Maybe he need to keep some kind of log; who and when the exe was used, etc.
    Maybe he could use the registry instead...
    JG


    ... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

  10. #10
    Join Date
    Jan 2013
    Posts
    5

    Re: How a file can edit itself after the run?

    I added 8 extra bytes at the end of file deliberately!
    and decided to save the password in this area(last 8 bytes)!
    i think this is the best way to save and protect the password if windows does not preventing manipulating that last 8 bytes during run!
    anyway I was going to use my last 8 bytes at the end of exe file .... perhaps either it is impossible or there is a hack we never seen it yet...

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center