home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2MISC / PMODE12S.ZIP / SRC / PMODE / EHDRFIX.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-29  |  1.2 KB  |  43 lines

  1. /* EXE file header fixer, code taken from Morten Welinder */
  2.  
  3. #include <stdio.h>
  4. #include <fcntl.h>
  5.  
  6. static char copyright[] =
  7.  "\r\n%s is Copyright (C) 1996 Charles W. Sandmann (sandmann@clio.rice.edu)\r\n"
  8.  "Copyright (c) 1994 Thomas Pytel, Copyright (c) 1996 Matthias Grimrath.\r\n"
  9.  "ABSOLUTELY NO WARRANTY.\r\n"
  10.  "Use for any purpose allowed provided this copyright remains unmodified.\r\n%c";
  11.  
  12. int main(int argc, char **argv)
  13. {
  14.   int f;
  15.   unsigned short us, test;
  16.   char msg[512];
  17.  
  18.   if(argc != 2) {
  19.     printf("Usage: ehdrfix pmodetsr.exe\n      Updates heap size in exe header\n");
  20.     exit(1);
  21.   }
  22.  
  23.   f = open(argv[1], O_RDWR | O_BINARY);
  24.   if (f < 0) {
  25.     perror(argv[1]);
  26.     exit(1);
  27.   }
  28.  
  29.   lseek(f, 0x0aL, SEEK_SET);
  30.   read(f, &us, sizeof(us));
  31.   read(f, &test, sizeof(us));
  32.   if(test == 0xffff) {        /* Not set yet */
  33.     lseek(f, 0x0cL, SEEK_SET);
  34.     write(f, &us, sizeof(us));    /* Update max memory */
  35.     sprintf(msg,copyright,argv[1],26);
  36.     msg[256] = 0;        /* Make sure we don't overwrite code */
  37.     /* Assume here that fixups leave the last 256 bytes of the header empty */
  38.     lseek(f, 256L, SEEK_SET);
  39.     write(f, msg, strlen(msg));
  40.   }
  41.   return close(f);
  42. }
  43.