Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I would like to edit a file which gets loaded into memory via a different program.I can edit and save the actual physical file which is on the local hard drive but the problem is that the other program which opened the file will not refresh until it is closed and re-opened. Any ideas/suggestions will be greatly appreciated.
Example Program A loads 3 files into memory when fired up, the file will be stock , debtors and setup. I want to work with the setup file and change an entry. I can save the file on disk but will the file is in memory things like passwords, printer setting ect. stays the same. I'm using vb.net 2005.
Posted

It's possible, but with extreme difficulty.

You have to know where in memory the "file" is. But, chances are really good you're not going to find the "file" as a nice single object, like a string, in memory. In any case, you have to know how the application represents the file in memory and how to change whatever you need to change, poking your changes in byte by byte.

As an example, if the application stores a string in memory as a BSTR, you can add stuff to the end of the string, but you also have to go back and poke in a new length for the string just before the beginning of the string data.

You can open another process for kind of like a file, using the WinAPI function OpenProcess[^] and ReadProcessMemory[^]. You can also write bytes back with WriteProcessMemory[^].
 
Share this answer
 
it is most likely helpful if you can post also the code.However, refreshing it on your program might help you
 
Share this answer
 
Comments
DonaldDkk 8-Aug-14 6:06am    
Sorry I thought I made the question quite clear, but apparently not.

I don't load the files from MY program or code. The files are loaded by a different application which i have no control over.

So to get back to the original question: how do i go about editing something which is in memory.

To give you my code will thus be the same as giving you a blank piece of paper.
guardj 9-Aug-14 7:41am    
i see, try this

http://msdn.microsoft.com/en-us/library/dd997372(v=vs.110).aspx
DonaldDkk 10-Aug-14 7:22am    
Your suggestion looks like the real deal, however I have .net 2005 which to my understanding vb.net 2005 does not work with framework 4 or 4.5.
Having said that it does look like an answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900