utils/decrypt_sav/MAIN.C

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <string.h>
00003 #include <string.h>
00004 #include <io.h>
00005 #include <dos.h>
00006 #include <dir.h>
00007 #include <ctype.h>
00008 #include <mem.h>
00009 #include <stdlib.h>
00010 #include <stdarg.h>
00011 #include <alloc.h>
00012 #include <conio.h>
00013 #include <fcntl.h>
00014 #include <io.h>
00015 #include <time.h>
00016 #include <bios.h>
00017 #include <math.h>
00018 #include <sys/stat.h>
00019 #include <process.h>
00020 
00021 
00022 /*
00023   Utility function to decrypt old BARIS save games with old BC31 libs
00024 
00025   Quick and dirty, be happy to have it
00026 */
00027 
00028 #define __VERSION__ "0.5"
00029 #define BUFFER_SIZE 32000L
00030 
00031 struct SF {
00032   char ID[4],Name[23],PName[2][20],Country[2],Season,Year;
00033   unsigned int dSize,fSize;     // these are 16 bits in DOS-land
00034 } FDes;
00035 
00036 int
00037 main(int argc, char **argv)
00038 {
00039   FILE *fin = NULL;
00040   FILE *fout = NULL;
00041 
00042   unsigned long bytes = 0;
00043   unsigned char buffer[BUFFER_SIZE];
00044 
00045   printf("BARIS Save game decryption utility %s\n",__VERSION__);
00046 
00047   if (argc != 3)
00048   {
00049     printf("Usage: %s <infile> <outfile>\n\n");
00050     return EXIT_FAILURE;
00051   }
00052 
00053   printf("Reading BARIS Save game %s\n",argv[1]);
00054   printf("Writing to %s\n",argv[2]);
00055 
00056   fout=fopen(argv[2],"wb");
00057 
00058   fin=fopen(argv[1],"rb");
00059 
00060   bytes = fread(&FDes,1,sizeof (FDes), fin);
00061   printf("Signature is %4s\n",FDes.ID);
00062   FDes.ID[0] = 'P';
00063   FDes.ID[1] = 'S';
00064   FDes.ID[2] = 'i';
00065   FDes.ID[3] = 'R';
00066 
00067   bytes = fwrite(&FDes, 1, sizeof (FDes), fout);
00068 
00069   bytes = fread((char*)buffer, 1, FDes.fSize, fin);
00070 
00071   // No BARIS structs to compare against so trust it
00072   //if (FDes->dSize==sizeof(struct Players))
00073   {
00074     unsigned long i = 0;
00075     unsigned long left = 0;
00076     srand(FDes.fSize);      // Randomize based on compressed length
00077 
00078     // Decrypt magic
00079     for( i = 0; i < FDes.fSize ; i++ )
00080       buffer[i] ^= random(256);
00081 
00082     if (strncmp(buffer+1,"BOLO",4)!=0)
00083     {
00084         printf("%s is not an encrypted BARIS Save game\n");
00085         return EXIT_FAILURE;
00086     }
00087 
00088     bytes = fwrite((char*)buffer,1,FDes.fSize, fout);
00089 
00090     // Copy remainder of save file
00091     left = BUFFER_SIZE;
00092     while (left==BUFFER_SIZE) {
00093       left=fread((char*)buffer,1,BUFFER_SIZE,fin);
00094       bytes = fwrite((char*)buffer,1,left,fout);
00095     }
00096 
00097     fclose(fin);
00098     fclose(fout);
00099   }
00100 
00101   return EXIT_SUCCESS;
00102 }
00103 

Generated on Fri Sep 28 00:35:46 2007 for raceintospace by  doxygen 1.5.3