Ejemplo n.º 1
0
        public static CryptoResult ReadFile(string path, CryptoProvider provider)
        {
            byte[] buffer;
            using (FileStream fileStream = File.OpenRead(path))
            {
                using (GZipStream gzipStream = new GZipStream((Stream)fileStream, CompressionMode.Decompress, false))
                {
                    using (MemoryStream memoryStream = new MemoryStream())
                    {
                        gzipStream.CopyTo((Stream)memoryStream);
                        buffer = memoryStream.GetBuffer();
                    }
                }
            }
            string str1   = Encoding.UTF8.GetString(buffer, 0, buffer.Length);
            int    length = str1.IndexOf("\n", StringComparison.Ordinal);
            string str2   = str1.Substring(length + 1);

            if (length == -1)
            {
                return(new CryptoResult(str2, false));
            }
            string strB    = str1.Substring(0, length);
            bool   isValid = string.Compare(provider.GetSignature(str2, false), strB, StringComparison.Ordinal) == 0;

            return(new CryptoResult(str2, isValid));
        }
Ejemplo n.º 2
0
        public override int Run(string[] remainingArguments)
        {
            if (this.OutputPath == null)
            {
                this.OutputPath = this.InputPath + ".txt";
            }
            CryptoProvider cryptoProvider = CryptoFactory.GetCryptoProvider(this.Game);
            CryptoResult   cryptoResult;

            try
            {
                cryptoResult = CryptoFileReader.ReadFile(this.InputPath, cryptoProvider);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Can't open input file");
                return(1);
            }
            FileStream fileStream;

            try
            {
                fileStream = File.Open(this.OutputPath, FileMode.Create, FileAccess.Write);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Can't create output file");
                return(1);
            }
            if (!cryptoResult.IsSignatureValid)
            {
                Console.WriteLine("Warning: signature is invalid");
            }
            string str = cryptoResult.Result;

            if (this.Prettify)
            {
                try
                {
                    str = this.GetPrettyString(str);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Warning: data is not valid JSON");
                }
            }
            byte[] bytes = Encoding.UTF8.GetBytes(str);
            fileStream.Write(bytes, 0, bytes.Length);
            fileStream.Close();
            return(0);
        }
Ejemplo n.º 3
0
        public static void Write(string path, string data, bool overwrite, CryptoProvider provider)
        {
            FileMode      mode          = overwrite ? FileMode.Create : FileMode.CreateNew;
            string        signature     = provider.GetSignature(data, false);
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append(signature);
            stringBuilder.Append('\n');
            stringBuilder.Append(data);
            byte[] bytes = Encoding.UTF8.GetBytes(stringBuilder.ToString());
            using (FileStream fileStream = File.Open(path, mode))
            {
                using (GZipStream gzipStream = new GZipStream((Stream)fileStream, CompressionMode.Compress, false))
                    gzipStream.Write(bytes, 0, bytes.Length);
            }
        }
Ejemplo n.º 4
0
        public override int Run(string[] remainingArguments)
        {
            if (this.OutputPath == null)
            {
                this.OutputPath = this.InputPath + ".sav";
            }
            FileStream fileStream;

            try
            {
                fileStream = File.OpenRead(this.InputPath);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Can't open input file");
                return(1);
            }
            byte[] numArray = new byte[fileStream.Length];
            fileStream.Read(numArray, 0, (int)fileStream.Length);
            fileStream.Close();
            string minifiedString = Encoding.UTF8.GetString(numArray, 0, numArray.Length);

            if (this.Minify)
            {
                try
                {
                    minifiedString = this.GetMinifiedString(minifiedString);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Warning: data is not valid JSON");
                }
            }
            CryptoProvider cryptoProvider = CryptoFactory.GetCryptoProvider(this.Game);

            try
            {
                CryptoFileWriter.Write(this.OutputPath, minifiedString, false, cryptoProvider);
            }
            catch (IOException ex)
            {
                Console.WriteLine("Can't create output file");
                return(1);
            }
            return(0);
        }
Ejemplo n.º 5
0
 public string GetSignature(string data, bool online)
 {
     using (HMACSHA1 hmacshA1 = new HMACSHA1(this.GetEncryptionKey(online)))
         return(CryptoProvider.HexStr(hmacshA1.ComputeHash(Encoding.UTF8.GetBytes(data))));
 }