home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / DATPATCH.ZIP / DATPATCH.C next >
Text File  |  1991-01-11  |  2KB  |  91 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <time.h>
  4. #include <ctype.h>
  5. #include <io.h>
  6.  
  7.  
  8.  
  9.   char        filename[80];
  10.   char        inbuf[28];
  11.   char        outstr[] = "COMPILED ON %02d/%02d/%02d - %02d:%02d";
  12.   char        teststr[] = "COMPILED ON MM/DD/YY - HH:MM";
  13.   FILE       *infile;
  14.   long        offset = 0L;
  15.   time_t      t;
  16.   struct      tm       *now;
  17.  
  18.  
  19.  
  20. main(argc,argv)
  21.     int       argc;
  22.     char     *argv[];
  23.   {
  24.     char      loopsw = 0;
  25.     int       x;
  26.     long      l;
  27.  
  28.                                        /*  check argument count:     */
  29.                                        /*  must be 2!                */
  30.     if (argc != 2)
  31.        {
  32.        printf("USAGE: DATPATCH filename\n");
  33.        return(0);
  34.        }
  35.  
  36.                                        /*  open the .EXE for update  */
  37.     strcpy(filename,argv[1]);
  38.     infile = fopen(filename,"rb+");
  39.     if (infile == NULL)
  40.        {
  41.        printf("ERROR: Unable to open %s\n",filename);
  42.        fclose(infile);
  43.        return(0);
  44.        }
  45.  
  46.                                        /*  begin scanning for the    */
  47.                                        /*  target string             */
  48.     printf("Scanning %s...\n",filename);
  49.     while(loopsw == 0)
  50.       {
  51.       memset(inbuf,0x00,sizeof(inbuf));
  52.       fseek(infile,offset,SEEK_SET);
  53.       fread(inbuf,sizeof(inbuf),1,infile);
  54.       if (memcmp(inbuf,teststr,sizeof(inbuf)) != 0)
  55.          {
  56.          l = sizeof(inbuf);
  57.          for(x = 1; x < sizeof(inbuf); x++)
  58.            {
  59.            if ((inbuf[x] == 'C') && (inbuf[x + 1] == 'O'))
  60.               l = x;
  61.            }
  62.          offset += l;
  63.          }
  64.         else
  65.          loopsw = 2;
  66.  
  67.       if (feof(infile) != 0)
  68.          loopsw = 1;
  69.       }
  70.  
  71.                                        /*  if the target was found,  */
  72.                                        /*  patch in the new string   */
  73.     if (loopsw == 2)
  74.        {
  75.        printf("Patching %s at offset %lx\n",filename,offset);
  76.        time(&t);
  77.        now = localtime(&t);
  78.        sprintf(inbuf,outstr,(now->tm_mon + 1),now->tm_mday,now->tm_year,
  79.                now->tm_hour,now->tm_min);
  80.        fseek(infile,offset,SEEK_SET);
  81.        fwrite(inbuf,sizeof(inbuf),1,infile);
  82.        }
  83.       else
  84.        printf("Could not find target in %s\n",filename);
  85.  
  86.     fclose(infile);
  87.  
  88.     return(0);
  89.   }
  90. 
  91.