home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / pmqsiz.zip / PMWPTCH.CMD < prev    next >
OS/2 REXX Batch file  |  1995-04-24  |  4KB  |  103 lines

  1. EXTPROC CEnvi2
  2. //********************************************************
  3. //*** PMWPtch.cmd - Patch PMWIN.DLL for bigger queues. ***
  4. //********************************************************
  5.  
  6. #define MIN_QUEUE_SIZE 1
  7. #define MAX_QUEUE_SIZE 255
  8.  
  9. Instructions()
  10. {
  11.    printf("PMWPtch - Patch PMWIN.DLL for always big message queues.\n");
  12.    printf("USAGE: PMWPtch <PmWin.dll_spec> <queue_size>\n");
  13.    printf("WHERE: PmWin.dll_spec - location of PMWIN.DLL file\n");
  14.    printf("       queue_size - size of PM queue, from %d to %d\n",
  15.           MIN_QUEUE_SIZE,MAX_QUEUE_SIZE);
  16.    printf("EXAMPLE: PMWPtch C:\\OS2\\DLL\\PMWIN.DLL 222\n");
  17.    exit(1);
  18. }
  19.  
  20. OldCode32 = '\x53\x56\x57\x55\x8B\xC4\x16\x50\x8C\xD2\x83\xE2\x03\x80\xCA\x04'
  21.             '\xFF\x75\x08\x8B\x45\x0C\x0F\xBF\xC8\x3B\xC1\x0F\x85\x25\x00\x00'
  22.             '\x00\x66\x50\x66\x68\x01\x00\x8B\xC4\xC1\xC8\x10\xC1\xE0\x03\x0A'
  23. NewCode32 = '\x53\x56\x57\x55\x8B\xC4\x16\x50\x8C\xD2\x83\xE2\x03\x80\xCA\x04'
  24.             '\xFF\x75\x08\x31\xC0\xB0\xDE\x89\xC1\x39\xC8\x0F\x85\x25\x00\x00'
  25.             '\x00\x66\x50\x66\x68\x01\x00\x8B\xC4\xC1\xC8\x10\xC1\xE0\x03\x0A'
  26. CodeLength32 = GetArraySpan(OldCode32) + 1;
  27. //OldCode16 = '\x8E\xD8\xFF\x76\x0A\xFF\x76\x08\xFF\x76\x06\x6A\x00\x0E\xE8\x06'
  28. //            '\x00\x1F\xC9\xCA\x06\x00\x90\xC8\x0E\x00\x00\x57\x56\x1E\xB8'
  29. //NewCode16 = '\x8E\xD8\x6A\x00\x68\xDD\x00\x90\xFF\x76\x06\x6A\x00\x0E\xE8\x06'
  30. //            '\x00\x1F\xC9\xCA\x06\x00\x90\xC8\x0E\x00\x00\x57\x56\x1E\xB8'
  31. //CodeLength16 = GetArraySpan(OldCode16) + 1;
  32.  
  33.  
  34. PatchIt(FileName)
  35. {
  36.    if ( !(fp = fopen(FileName,"rb")) ) {
  37.       printf("Unable to open source file \"%s\".\nCannot patch!\n",FileName);
  38.       return;
  39.    }
  40.    BufSize = fread(buf,1000000,fp);
  41.    fclose(fp);
  42.    puts("find 32-bit old code");
  43.    if ( BufSize < 10  ||  1000000 <= BufSize
  44.      || !(CodeOffset32 = FindCodeOffset(buf,BufSize,OldCode32,CodeLength32)) ) {
  45.       printf("Could not find old 32-bit code in \"%s\"\nCannot Patch!\n",FileName);
  46.       return;
  47.    }
  48. //   puts("find 16-bit old code");
  49. //   if ( !(CodeOffset16 = FindCodeOffset(buf,BufSize,OldCode16,CodeLength16)) ) {
  50. //      printf("Could not find old 16-bit code in \"%s\"\nCannot Patch!\n",FileName);
  51. //      return;
  52. //   }
  53.    // replace old code with new
  54.    memcpy(buf+CodeOffset32,NewCode32,CodeLength32);
  55. //   memcpy(buf+CodeOffset16,NewCode16,CodeLength16);
  56.  
  57.    // give last chance
  58.    printf("About to ovewrite old version of %s. You should have a\n",FileName);
  59.    printf("backup.  Are you sure you want to overwrite? (Y/N) ");
  60.    while( kbhit() ) getch();
  61.    do {
  62.       answer = toupper(getch());
  63.    } while( answer != 'Y' && answer != 'N' );
  64.    printf("%c\n",answer);
  65.  
  66.    if ( 'Y' == answer ) {
  67.       fp = fopen(FileName,"wb");
  68.       if ( !fp  ||  (BufSize != fwrite(buf,BufSize,fp)) ) {
  69.          printf("Cannot open \"%s\" for writing.\nCannot patch.\n",FileName);
  70.          return;
  71.       }
  72.       fclose(fp);
  73.    }
  74. }
  75.  
  76. FindCodeOffset(buf,bufsize,code,codelen)
  77. {
  78.    FirstByte = code[0];
  79.    for ( next = buf, len = bufsize; 0 < len; next++, len-- ) {
  80.       if ( !(b = memchr(next,FirstByte,len)) )
  81.          return 0;
  82.       if ( !memcmp(b,code,codelen) ) {
  83.          printf("\nFOUND!!! at %08X\n",b-buf);
  84.          return b - buf;
  85.       }
  86.       len -= b - next;
  87.       next = b;
  88.    }
  89.    return 0;
  90. }
  91.  
  92. main(argc,argv)
  93. {
  94.    if ( argc != 3
  95.      || (QueueSize = atoi(argv[2])) < MIN_QUEUE_SIZE
  96.      || MAX_QUEUE_SIZE < QueueSize )
  97.       Instructions();
  98.  
  99.    NewCode32[0x16] = QueueSize;
  100.    PatchIt(argv[1]);
  101. }
  102.  
  103.