home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 6 / FM Towns Free Software Collection 6.iso / ms_dos / uxpatch / uxpatch.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-08  |  1.2 KB  |  54 lines

  1. /*  UXPATCH.C              (c) S.Enjoji
  2.  *
  3.  *  次のデータ列の最後の 0x4a -> 0x90 にパッチ当てする
  4.  *  0F 20 C0 66 A9 04 00 75 07 66 A9 10 00 74 01 4A
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9.  
  10. char bin[16] = {
  11.     0x0F,0x20,0xC0,0x66,0xA9,0x04,0x00,0x75,
  12.     0x07,0x66,0xA9,0x10,0x00,0x74,0x01,0x4A
  13. };
  14.  
  15. main(int argc,char *argv[])
  16. {
  17.     int i,j,d,f;
  18.     FILE *fp;
  19.  
  20.     for(i=0; i<argc; i++) {
  21.     }
  22.     if (argc<2) {
  23.         puts("ファイル名を付けてください。\a");
  24.         exit(1);
  25.     }
  26.     for(i=1; i<argc; i++) {
  27.         f = 0;
  28.         printf("%12s: ",argv[i]);
  29.         if((fp=fopen(argv[i],"r+b")) == NULL) {
  30.             puts("読み書きモードでオープンできません。\a");
  31.             continue;
  32.         }
  33.         if(fseek(fp,0x200L,SEEK_SET)) {f = 1; goto file_close;}
  34. search:
  35.         do {
  36.             if((d = getc(fp)) == EOF) {f = 1; goto file_close;}
  37.         } while(d != bin[0]);
  38.         for(j=1; j<15; j++) {
  39.             if((d = getc(fp)) == EOF) {f = 1; goto file_close;}
  40.             if(d != bin[j]) goto search;
  41.         }
  42.         if((d = getc(fp)) == bin[15]) {
  43.             fseek(fp,-1L,SEEK_CUR);
  44.             putc('\x90',fp);
  45.             puts("書き換えました。");
  46.         } else {
  47.             printf("データが違います。[%02X]\n",d);
  48.         }
  49. file_close:
  50.         fclose(fp);
  51.         if(f) puts("データが有りません。");
  52.     }
  53. }
  54.