home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: WPS_PM / WPS_PM.zip / lockupwd.zip / lockupwd.c next >
C/C++ Source or Header  |  2002-04-02  |  2KB  |  61 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. void main(int argc,char *argv[])
  5. {
  6.     FILE *f;
  7.     unsigned char *buf, *pass, xorValue;
  8.     size_t  i, j, len;
  9.  
  10.     puts("OS/2 PM Lockup Password Recovery");
  11.     if(argc != 2) puts("Usage: lockupwd [[drive:]\\path\\]os2.ini");
  12.     else
  13.     {
  14.         printf("Processing %s... ",argv[1]);
  15.         f = fopen(argv[1], "rb");
  16.         if (!f) puts("unable to open!");
  17.         else
  18.         {
  19.             fseek(f, 0, SEEK_END);
  20.             len = ftell(f);
  21.             fseek(f, 0, SEEK_SET);
  22.     
  23.             buf = (unsigned char *)malloc(len + 128);
  24.             if (!buf) printf("not enough memory!\n");
  25.             else
  26.             {
  27.                 if (fread(buf, 1, len, f) != len) puts("read error!");
  28.                 else
  29.                 {
  30.                     for (i = 0; i < len; i++)
  31.                     {
  32.                         if (!memcmp(&buf[i],      "PM_Lockup", 10) &&
  33.                             !memcmp(&buf[i + 34], "LockupOptions", 14))
  34.                         {
  35.                             i += 54;
  36.                             break;
  37.                         }
  38.                     }
  39.                     puts("done!");
  40.                     if (i >= len) puts("No lockup info found!");
  41.                     else
  42.                     {
  43.                         xorValue = (*(unsigned short*)&buf[i] - 0x24)/3;
  44.                         pass = &buf[i+=4];
  45.  
  46.                         do { buf[i++] ^= xorValue; } while(buf[i]);
  47.  
  48.                         printf("Password (text): \"%s\"\n",pass);
  49.  
  50.                         printf("Password (hex):");
  51.                         do { printf(" %02X", *pass++); } while(*pass);
  52.                         puts("");
  53.                     }
  54.                 }
  55.                 free(buf);
  56.             }
  57.             fclose(f);
  58.         }
  59.     }
  60. }
  61.