Пример #1
0
        private string DecodeStringASCII(sbyte len)
        {
            int actualLen;

            if (len == -128)
            {
                actualLen = ReadInt32();
            }
            else
            {
                actualLen = -len;
            }

            var bytes = ReadBytes(actualLen).ApplyStringXor(false);

            _encryption.TryDecryptString(bytes, y =>
            {
                var oddCharacters = y.Any(x => x < 0x20 && x != '\n' && x != '\r' && x != '\t');
                if (oddCharacters)
                {
                    return(false);
                }

                if (IsLegalUnicode(Encoding.UTF8.GetString(y)))
                {
                    return(true);
                }

                var converted             = Encoding.Convert(Encoding.UTF8, Encoding.ASCII, y);
                var specialCharacterCount = converted.Count(x => x == '?');
                if (specialCharacterCount * 100 / converted.Length >= 50)
                {
                    if (converted.Length > 5)
                    {
                        Console.WriteLine("Found {0} special characters on a string of {1} characters... wut.",
                                          specialCharacterCount, converted.Length);
                    }

                    return(false);
                }

                return(true);
            }, true);

            return(Encoding.ASCII.GetString(Encoding.Convert(Encoding.UTF8, Encoding.ASCII, bytes)));
        }
        private static string DecodeStringUnicode(this BinaryReader reader, sbyte len)
        {
            int actualLen = len;

            if (len == 127)
            {
                actualLen = reader.ReadInt32();
            }
            actualLen *= 2;

            var bytes = reader.ReadBytes(actualLen).ApplyStringXor(true);

            WzEncryption.TryDecryptString(bytes, null);

            return(Encoding.Unicode.GetString(bytes));
        }
        private static string DecodeStringASCII(this BinaryReader reader, sbyte len)
        {
            int actualLen;

            if (len == -128)
            {
                actualLen = reader.ReadInt32();
            }
            else
            {
                actualLen = -len;
            }

            var bytes = reader.ReadBytes(actualLen).ApplyStringXor(false);

            WzEncryption.TryDecryptString(bytes, y => !y.Any(x => x < 0x20 && x != '\n' && x != '\r' && x != '\t'));

            return(Encoding.ASCII.GetString(Encoding.Convert(Encoding.UTF8, Encoding.ASCII, bytes)));
        }