Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Rayman2SaveEncryption {
- class Program {
- static bool breakTheMold;
- static byte checkByte = 0;
- static uint checkDWord = 0;
- static uint importantSaveThing2 = 0;
- static byte importantSaveThing = 87;
- static void Main(string[] args) {
- if (args.Length > 0 || true) {
- //FileStream stream = File.OpenRead(args[0]);
- FileStream stream = File.OpenRead("test.sav");
- read(stream);
- Console.WriteLine("CheckByte now is "+checkByte);
- Console.WriteLine("CheckDWord now is " + checkDWord);
- Console.ReadKey();
- }
- else {
- Console.WriteLine("Enter a filename as the first argument");
- Console.ReadKey();
- }
- }
- static int saveDecryptMagic_1(FileStream File) {
- int nextCharInFile; // esi@2
- int result; // eax@4
- byte v4; // ST00_1@5
- nextCharInFile = File.ReadByte();
- result = nextCharInFile;
- if (nextCharInFile != -1) {
- v4 = importantSaveThing++;
- result = nextCharInFile ^ (byte)fuckUpTheByte(v4) ^ 0xB9;
- checkByte -= (byte)result;
- ++importantSaveThing2;
- }
- return result;
- }
- static byte fuckUpTheByte(byte theByte) {
- byte result; // al@1
- byte v2; // dl@1
- byte v3; // esi@1
- result = 0;
- v2 = 0;
- v3 = 7;
- do {
- result = (byte)(result | ((theByte >> v2++) & 1) << v3--);
- }
- while (v2 < 8u);
- return result;
- }
- static byte __SETS__(int x) {
- return (byte)((x < 0) ? 1 : 0);
- }
- static byte __OFSUB__(int x, int y) {
- int y2 = y;
- byte sx = __SETS__(x);
- return (byte)((sx ^ __SETS__(y2)) & (sx ^ __SETS__(x - y2)));
- }
- static void decreaseDWordAndCheck() { // Rayman2.exe sub_48D610
- if (--checkDWord < 0) {
- breakTheMold = true;
- }
- }
- static void read(FileStream stream) {
- int cheese = -1;
- int v3 = 0;
- int v5 = 0;
- int v6 = 0;
- int v8 = 0;
- int v9 = 0;
- int v10 = 0;
- int someVar;
- checkByte = getOneByteAndXorWith53(stream);
- checkDWord = getFourBytesAndXorWith0x54555657(stream);
- Console.WriteLine("CheckByte was " + checkByte);
- Console.WriteLine("CheckDWord was " + checkDWord);
- if (!breakTheMold) {
- while (true) {
- if (cheese == -1) {
- someVar = saveDecryptMagic_1(stream);
- if (someVar == -1) {
- breakTheMold = true;
- }
- else {
- v3 = saveDecryptMagic_1(stream);
- }
- }
- else {
- v5 = saveDecryptMagic_1(stream);
- someVar = v5;
- if (v5 == -1) {
- v6 = 0;
- do {
- v6++;
- decreaseDWordAndCheck();
- } while (v6 < 8);
- breakTheMold = true;
- }
- else {
- v3 = saveDecryptMagic_1(stream);
- if (v3 == -1) {
- for (int i=0;i<v5; ++i) {
- decreaseDWordAndCheck();
- }
- breakTheMold = true;
- }
- else {
- v8 = 0;
- do {
- v8++;
- decreaseDWordAndCheck();
- } while (v8 < 8);
- }
- }
- }
- if (breakTheMold) {
- break;
- }
- v9 = 0;
- do {
- if (v9 > 0) {
- v3 = saveDecryptMagic_1(stream);
- }
- v10 = v9 + 8;
- if ((__OFSUB__(v9, v9 + 8) ^ 1)!=0) {
- do {
- if ((((ulong)v3 >> 32) ^ (ulong)Math.Abs(v3) & 1) - ((ulong)v3 >> 32) == 1) {
- saveDecryptMagic_1(stream); // don't store as we don't give a shit
- }
- ++v9;
- v3 /= 2;
- }
- while (v9 < v10);
- }
- v9 = v10;
- }
- while (v10 < 8);
- if (breakTheMold) {
- break;
- }
- cheese = someVar;
- }
- }
- }
- private static uint getFourBytesAndXorWith0x54555657(FileStream stream) {
- byte[] DstBuf = new byte[4];
- stream.Read(DstBuf, 0, 4);
- int value = BitConverter.ToInt32(DstBuf, 0);
- return (uint)(value ^ 0x54555657);
- }
- private static byte getOneByteAndXorWith53(FileStream stream) {
- byte[] DstBuf = new byte[4];
- byte value = (byte)stream.ReadByte();
- return (byte)(value ^ 0x53);
- }
- }
- }
Add Comment
Please, Sign In to add comment