this program is a mess, but was my workbench for trying to decode the FrankensteinAdventure binary. First I tried to see if the text values were offset, but then noticed using bmore that there were a ton of 0xDF entries, which is the binary inverse of 0x20, which is space. Aha, the answer was the data is stored inverted.
#include <stdio.h>

int match_test(int offset, int echo)
{
   FILE *inputFile;
   int done = 0;
   int matched_chars = 0;
   unsigned char mod_char;
   unsigned char thisChar;
// char match[] = "MeSSAGE";
   char match[] = "SAFE";
   char* ptr;
   int found_one = 0;
   int printable = 0;
   int make_space = 1;

   inputFile = fopen("/usr/server_drive/junk/LEGACY.EXE", "rb");

   if (inputFile == NULL)
   {  printf(" failed!  Can't find or open the file.\n");
      return 1;
   }

   ptr = match;
   while (!done)
   {
      if (!fread(&thisChar, 1, 1, inputFile))
      {  done = 1;
      }
      else
      {  mod_char = thisChar ^= 0xff;

         if (mod_char == *ptr || mod_char + 32 == *ptr || mod_char == *ptr + 32)
         {
            matched_chars++;
            if (matched_chars == strlen(match))
            {  printf ("found w/ offset %d\n", offset);
               ptr = match;
               matched_chars = 0;
               found_one = 1;
            }
            else
            {
               ptr++;
            }
         }
         else
         {
            ptr = match;
            matched_chars = 0;
         }

         if (mod_char >=32 && mod_char <=126)
         {  if (echo)
            {  printf ("%c", mod_char);
               make_space = 1;
            }
            printable++;
         }
         else if (echo && make_space)
         {  printf(".");
            make_space = 0;
         }

      }

   }

   fclose(inputFile);

   return found_one;
}

int main(int argc, char** argv)
{
/* if (argc >= 2)
   {  match_test(atoi(argv[1]));
   }*/
   int i;
   int printable;

   match_test(0, 1);
   return;

   for (i = 0; i < 0xFF; i++)
   {  if (match_test(i, 0))
      {
         printf("found one! at offset %d\n", i);
      }
   }
   return 1;
}

-- MattWalsh - 16 Apr 2004
Topic revision: r1 - 17 Apr 2004 - MattWalsh
 
This site is powered by the TWiki collaboration platformCopyright © 2008-2012 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback