Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // decryptor.cpp : Defines the entry point for the console application.
- //
- /*
- ** The encryption algorithm used by Anti RGSS Decryptor is pathetic. It leaked way too much info, that made it extremely trivial to
- ** black box reverse engineer. :)
- **
- ** For one, the worst info leaked, was in launcher.dat. It had plaintext carraige return line feeds, and 2, its encryption
- ** was simply add string length plus 3, to each byte of the string.
- **
- ** Second, since this encryptor did NOT validate the contents of the files to be encrypted, I was able to
- ** stuff some controlled values into the "black box", and analyze the output. This is pretty much an 8-bit block cipher, with no
- ** real key expansion whatsoever, other than that there are 3 sboxes, all of which are trivially computed.
- */
- #include "stdafx.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- unsigned char sbox[3][256];
- unsigned char *password;
- int decode_string(unsigned char *str, FILE *f, int max_len)
- {
- int i,slen=0;
- i=fgetc(f);
- if(i == EOF)
- return i;
- str[slen++]=i;
- str[slen++]=fgetc(f);
- str[slen++]=fgetc(f);
- while (((str[slen-2] != 0x0D) || (str[slen-1] != 0x0A)) && (slen < max_len))
- str[slen++]=fgetc(f);
- slen-=2;
- str[slen]=0;
- for(i=0;i<slen;i++)
- str[i] -= ((slen + 3) & 0xFF);
- return slen;
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- FILE *f, *g;
- unsigned char *filedata;
- char filename[260];
- int flen=0;
- int psize=0;
- int plen=0;
- int i, j;
- unsigned char low, high;
- for(i=0;i<16;i++)
- {
- for(j=0;j<16;j++)
- {
- high = (i+((j<9)?0:1)) % 16;
- high = (8 - (high & 0xC) + (high & 0x3)) << 4;
- low = (j-1)%16;
- low = (3 + (low & 0xC) - (low & 0x3));
- sbox[0][(i*16)+j]=high|low;
- low += 8;
- low %= 16;
- sbox[2][(i*16)+j]=high|low;
- if(low&1)
- low-=1;
- else
- low+=1;
- low %= 16;
- sbox[1][(i*16)+j]=high|low;
- }
- }
- f = fopen("Launcher.dat","rb");
- if(f==NULL)
- {
- printf("Failed to open Launcher.dat\n");
- return 1;
- }
- fseek(f,0,SEEK_END);
- psize=ftell(f);
- fseek(f,0,SEEK_SET);
- password=(unsigned char*)malloc(psize);
- if(password == NULL)
- {
- fclose(f);
- return 1;
- }
- flen=decode_string((unsigned char*)filename,f,260);
- plen=decode_string(password,f,psize);
- while(flen != EOF)
- {
- g=fopen(filename,"rb");
- if(g == NULL)
- {
- fclose(f);
- free(password);
- return 1;
- }
- fseek(g,0,SEEK_END);
- j=ftell(g);
- fseek(g,0,SEEK_SET);
- filedata=(unsigned char*)malloc(j);
- if (filedata == NULL)
- {
- fclose(f);
- fclose(g);
- free(password);
- return 1;
- }
- fread(filedata,1,j,g);
- fclose(g);
- g=NULL;
- j-=5;
- for(i=0;i<j;i++)
- {
- filedata[i] -= password[i%plen];
- filedata[i] = sbox[i%3][filedata[i]+0x39];
- }
- g=fopen(filename,"wb");
- if(g!=NULL)
- {
- fwrite(filedata,1,j,g);
- fclose(g);
- g=NULL;
- }
- free(filedata);
- filedata=NULL;
- sprintf(filename,"Audio\\");
- flen=decode_string((unsigned char*)&filename[6],f,254);
- }
- fclose(f);
- f=NULL;
- //Now that we fully decrypted the game, there is no longer a need for launcher.dat or the launcher program.
- unlink("Launcher.dat");
- f=fopen("ARD Launcher RC2.exe","rb");
- if(f!=NULL)
- {
- fclose(f);
- unlink("ARD Launcher RC2.exe");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment