PDA

View Full Version : Storing data inside .exe



marmin
14-04-2008, 12:23 PM
I'd like to store some data inside the .exe (build). Some vars, and some records. Each time the program runs I 'd like to write to these addresses.
Using Delphi and Lazarus.

How would I proceed?

waran
14-04-2008, 12:57 PM
Not possible.
Binaries of running programs are locked.
... as far as I know :wink:

Edit:
Ok, I take it back. It actually *has* to be possible somehow.
However its not easy.

marmin
14-04-2008, 01:54 PM
I may ask it to the fpc developers. They will know it.

JernejL
14-04-2008, 04:14 PM
win32: writeprocessmemory, but you need to know the exact address of data and that may change a lot..

cairnswm
15-04-2008, 04:40 AM
Create a const record in your code:

Const
MyData = Record ID : String; Data : String; End = (ID:"My Unique ID";Data="Custom Data that is exactly XYZ in length);

In your code do a search through the EXE file (Using Block Read), until you find the ID string. Then at the correct offset for the Data block write your custom Data.

Its been YEARS since I last did that. If I remember the structure of an EXE file changed betwen DOS and Windows. In Dos the strings were stored at the start of the file (so reading from the front was faster) in windows (95 IIRC) ity was mnore efficient to start reading from the back of the file.

The EXE that is currently running can be changed as far as I remmeber.

marcov
15-04-2008, 09:17 AM
In general, don't. Windows' own security and 3rd party security software make this increasingly difficult to deploy, even if you pull it of. It's only a matter of time till only the windows installer (the thing that interprets .msi's) can write to c:\program files\

The next release of FPC/Lazarus will probably improve the resource system so it gets more similar to Delphi. (using "windows" resources on windows)

cronodragon
16-04-2008, 03:30 PM
Maybe a little late, but I found this Delphi unit called ExeMod. The download link is on top:

http://www.geocities.com/gacarpenter386/

The algorithms are quiet simple. :)

arthurprs
16-04-2008, 05:10 PM
cronodragon~ thanks for the link, it will help me :)