🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.ibm.pc
Article #8343

Re: Modifying .exe files

#8343
From: Gene McManus
Date: Fri, 08 Dec 1989 15:13
68 lines
2943 bytes
From article <32336@auc.UUCP>, by cac@auc.UUCP (Clayton Collie):
   [ ... ]
> 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.
>  
> 
>   
>   Is this incredibly difficult ? Any pointers would be appreciated.
> BTW - answers don't necessarily have to be TP (or Pascal) specific.
> 
> 
>                                       ----- THANX ------- 
>                                       Clayton  Collie
> 
>  

I've used a technique (using M'soft C) that goes something like this:

First, define your configuration data (best in a header file):

   struct _config
      {
      /* whatever is necessary for your configuration data */
      unsigned int checksum;          /* .EXE files must checksum to zero */
      } CONFIG;

Then, to write the initial config data in your .EXE file:

   CONFIG ConfigData, *p;
   int i;
   unsigned int sum;

   /* compute a checksum for the configuration structure so that the
      net sum is zero. This is necessary to ensure that MS-DOS doesn't
      choke on the .EXE file at run time, thinking it's corrupted.
   */
 
   p = &ConfigData;                /* beginning address of structure       */
   for(i = 0, sum = 0; i < sizeof(CONFIG); i++, p++)
      sum += *p;                   /* accumulate sum of bytes in structure */
   ConfigData.checksum = -sum;     /* store negative sum                   */

   handle = open("program.exe", O_APPEND);   /* assumes file exists        */
   write(handle, ConfigData, sizeof(CONFIG));/* adds to end of .EXE file   */
   close(handle);

Finally, to read the config data when your program runs:

   CONFIG ConfigData;

   handle = open(argv[0], O_RDONLY);
   lseek(handle, sizeof(CONFIG), SET_END); /* look this up for correct order */
   read(handle, ConfigData, sizeof(CONFIG));/* read the config data           */
   close(handle);

I can't take any credit for inventing this. The general technique came from
one of the magazines I subscribe to, can't remember which.

Good Luck, regards,
Gene


Gene McManus @ Defense Logistics Agency Systems Automation Center,
               Columbus, OH 43215 (614) 238-9403,    Autovon 850-
Internet:      gmcmanus@dsac.dla.mil  (131.78.1.1)
UUCP:          {uunet!gould,cbosgd!osu-cis}!dsacg1!gmcmanus
The views expressed are my own, not those of the Agency, or Dept. of Defense
Technical Details
Message-ID: <1600@dsac.dla.mil>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!dsac.dla.mil!nts0699
References: <32336@auc.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!dsac.dla.mil!nts0699
From: nts0699@dsac.dla.mil (Gene McManus)
Newsgroups: comp.sys.ibm.pc
Subject: Re: Modifying .exe files
Message-ID: <1600@dsac.dla.mil>
Date: 8 Dec 89 15:13:07 GMT
References: <32336@auc.UUCP>
Distribution: usa
Organization: Defense Logistics Agency Systems Automation Center, Columbus
Lines: 68