[comp.lang.pascal] Modifying .exe files

cac@auc.UUCP (Clayton Collie) (12/06/89)

I've been working on a fairly large project ( written with TP 5.5 )  
and I'm currently trying to devise a configuration routine (or file) for
the program. I'm curious to find out if anyone on the net has any experience
writing configuration programs that modify the actual program executable  
e.g. the Tinst.exe utility that comes with the Turbo package.
 
  As far as I've gotten is to generate a map file listing the program 
variables and constants along with their segments and offsets. I figure that by using this information could seek to that particular location in the .exe 
and place the appropriate value at that point. 

  
  Is this incredibly difficult ? Any pointers would be appreciated.
BTW - answers don't necessarily have to be TP (or Pascal) specific.


                                      ----- THANX ------- 
                                      Clayton  Collie

 

taylorj@yvax.byu.edu (12/09/89)

My suggestions for patching .exe files:

Use typed constants for the stuff you want to modify.  Put them all together
in one clump so they'll be contiguous in memory.  Put a unique string (another
typed constant) at the start.  Something like this:

  var
    patchID : string[9] = '!Patches:';
    color   : byte = 14;
    limit   : integer = 125;
    ...

Then all you have to do is duplicate this in your program that does the
modification, change the values of the constants (isn't that against the laws
of math? :-), open up the .exe file as a file of bytes (or an untyped file),
search for the unique string, then write (or blockWrite) the contents of memory
at the location of the first constant (@color, in the example above) out to
the .exe file.  You'll have to determine by hand the number of bytes to write
(unless you want to get really tricky and subtract the address of the last
constant from the address of the patch string and add the size of the last
constant).

This way you can always find the correct location to patch no matter how your
.exe file has changed, and it's really easy to add new constants to hold new
customizeable information.

Hope this helps!


Jim Taylor
Microcomputer Support for Curriculum   |
Brigham Young University               |   Bitnet: taylorj@byuvax.bitnet
101 HRCB, Provo, UT  84602             |   Internet: taylorj@yvax.byu.edu