home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / os / msdos / programm / 8175 < prev    next >
Encoding:
Text File  |  1992-07-30  |  3.0 KB  |  76 lines

  1. Newsgroups: comp.os.msdos.programmer
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!menudo.uh.edu!cosc16to
  3. From: cosc16to@menudo.uh.edu (Andy Hakim)
  4. Subject: Re: changes to exe (binary) file
  5. Message-ID: <1992Jul30.152020.8261@menudo.uh.edu>
  6. Organization: University of Houston
  7. References: <1992Jul29.125540.7401@hou.amoco.com>
  8. Date: Thu, 30 Jul 1992 15:20:20 GMT
  9. Lines: 65
  10.  
  11. In article <1992Jul29.125540.7401@hou.amoco.com> jim@n5ial.chi.il.us writes:
  12. >
  13. >I've seen lots of programs (usually shareware types) that allow you to
  14. >make configuration changes, insert registration info, etc., directly into
  15. >the compiled exe file.  that is, instead of having a config file hanging
  16. >around, the exe itself is modified to include the new config info.
  17. >how would one go about doing this?  btw, the program in question is in
  18. >C, and uses Turbo C++ version 1.0.
  19. I had written a shareware program that writes changes directly to the
  20. program file.  Here's how:  create a data structure holding all
  21. information you wish to change ( D in example), this allows all pertinent
  22. data to be stored in one place, and it can easily be read/written to disk.
  23.  
  24. To figure out the offset:  (DEFAULT_OFFSET in example)  compile the
  25. program, then use a program such as LIST to scan for a sequence of
  26. matching bytes ( 100 118 138 )  The HEX DUMP mode of LIST is handy.
  27. Next, go back to your source file, and update the correct offset.
  28. An alternative way to figure out the offset is to use info from .map files.
  29.  
  30. It's very important to keep the variable D initialized in the program
  31. because most compilers by default do not store un-initialized data as part
  32. of the exe (to reduce size).
  33.  
  34. Here are relevant pieces of code from my program:
  35. //------------------------------------------------------------------------
  36. #define DEFAULT_OFFSET 0xAA8A
  37. typedef struct
  38. {
  39.   char nr_factor;
  40.   unsigned minimum;
  41.   unsigned maximum;
  42.   unsigned duration;
  43.   long length;
  44.   char fancy;
  45.   char process;
  46.   char playfile;
  47.   char overwrite;
  48.   unsigned sbport;
  49.   char endpause;
  50. } DEFAULTS;
  51. //.........................................................................
  52. DEFAULTS D =       {100, 118, 138, 3600, 200, YES, YES, 3, NO, 0x220, YES};
  53. DEFAULTS FACTORY = {100, 118, 138, 3600, 200, YES, YES, 3, NO, 0x220, YES};
  54. //.........................................................................
  55. void fsavedefaults(char *program_name)
  56. {
  57.   FILE *fptr;
  58.   if ((fptr = fopen (program_name, "rb+")) != NULL)
  59.   {
  60.     printf ("Saving new defaults to %s\n", program_name);
  61.     fseek (fptr, DEFAULT_OFFSET, SEEK_SET);
  62.     fwrite (&D, sizeof(D), 1, fptr);
  63.   }
  64. else show_error (9, program_name);
  65.   fclose (fptr);
  66. }
  67. //------------------------------------------------------------------------
  68. The program  can be obtained from most ftp sites as nohiss10.zip.  I'd be
  69. happy to provide the full source code via email.  BTW, the complete
  70. path\program_name is stored in argv[0] (i believe you only get the path 
  71. from dos 3.0 or higher but that's good enough)
  72.  
  73. -Andy Hakim
  74. <cosc16to@menudo.uh.edu>
  75.  
  76.