Mephzara - Andreas Kardin

Software Entwicklung

Sometimes you want to embed data within a executable. If the data is know at compile time you can store the data in resources or use a component of the JCL?. But sometimes you want to have somekind of an editor exe that can "compile" player or loader exes with different data.

How does it work?

A very comfortable but also a litte strange aspect (in my eyes) of the executable format used under windows is that you can simply append data to the end of the file. You don't have to care about file markers, blocks, checksums or other stuff.

One problem after appending data is that you have to find out where the additional data starts in the exe file. A simple solution is to write the start offset of the appended data to the end of the file. My class here writes also a marker to the end of the file. It is used to detect if there is appended data or not.

Data layout in the executable file...

Offset Description
0 Start of the exe file
n-1 End of the exe file
n Start of the appended data
... End of the appended data
eof-16 Start position (Int64) of the appended data (n)
eof-8 Signature string (8 bytes)

How to use it?

You'll find two Delphi projects within the archive. One is the creator that allows to load a JPG file and to append the JPG file to a player exe. The second project is the player that loads the embedded jpg and displays it.

You have to compile the player first before you can use the creator!

The interesting stuff is in the unit ApplicationDataStream. You'll find a stream class that can be used like a normal Delphi stream and also utility function to append and extract an entire file to and from an executable.

License

The code is public domain. If you have a great idea to make the thing better you'll free to leave a comment here in the Wiki or even to upload your own enhancement of the code here.

What you need

  • Delphi 6 (works probably also with earlier and later Delphi versions)
  • This