Beispiel #1
0
        void decryptStrings(uint[] key)
        {
            var data = stringDataField.InitialValue;

            var encryptedData = new uint[data.Length / 4];

            Buffer.BlockCopy(data, 0, encryptedData, 0, data.Length);
            DeobUtils.xxteaDecrypt(encryptedData, key);
            var decryptedData = new byte[data.Length];

            Buffer.BlockCopy(encryptedData, 0, decryptedData, 0, data.Length);

            var inflated       = DeobUtils.inflate(decryptedData, 0, decryptedData.Length, true);
            var reader         = MemoryImageStream.Create(inflated);
            int deflatedLength = (int)reader.ReadCompressedUInt32();
            int numStrings     = (int)reader.ReadCompressedUInt32();

            decryptedStrings = new string[numStrings];
            var offsets = new int[numStrings];

            for (int i = 0; i < numStrings; i++)
            {
                offsets[i] = (int)reader.ReadCompressedUInt32();
            }
            int startOffset = (int)reader.Position;

            for (int i = 0; i < numStrings; i++)
            {
                reader.Position     = startOffset + offsets[i];
                decryptedStrings[i] = reader.ReadString();
            }
        }
Beispiel #2
0
        void decryptStrings(uint[] key)
        {
            var data = stringDataField.InitialValue;

            var encryptedData = new uint[data.Length / 4];

            Buffer.BlockCopy(data, 0, encryptedData, 0, data.Length);
            DeobUtils.xxteaDecrypt(encryptedData, key);
            var decryptedData = new byte[data.Length];

            Buffer.BlockCopy(encryptedData, 0, decryptedData, 0, data.Length);

            var inflated       = DeobUtils.inflate(decryptedData, 0, decryptedData.Length, true);
            var reader         = new BinaryReader(new MemoryStream(inflated));
            int deflatedLength = DeobUtils.readVariableLengthInt32(reader);
            int numStrings     = DeobUtils.readVariableLengthInt32(reader);

            decryptedStrings = new string[numStrings];
            var offsets = new int[numStrings];

            for (int i = 0; i < numStrings; i++)
            {
                offsets[i] = DeobUtils.readVariableLengthInt32(reader);
            }
            int startOffset = (int)reader.BaseStream.Position;

            for (int i = 0; i < numStrings; i++)
            {
                reader.BaseStream.Position = startOffset + offsets[i];
                decryptedStrings[i]        = reader.ReadString();
            }
        }
        IBinaryReader decrypt(int length)
        {
            var block     = new uint[4];
            var decrypted = new byte[16];

            var outStream = new MemoryStream(length);

            while (reader.Position < reader.Length)
            {
                block[0] = reader.ReadUInt32();
                block[1] = reader.ReadUInt32();
                block[2] = reader.ReadUInt32();
                block[3] = reader.ReadUInt32();
                DeobUtils.xxteaDecrypt(block, key);
                Buffer.BlockCopy(block, 0, decrypted, 0, decrypted.Length);
                outStream.Write(decrypted, 0, decrypted.Length);
            }

            return(MemoryImageStream.Create(outStream.ToArray()));
        }
Beispiel #4
0
        Stream decrypt(int length)
        {
            var block     = new uint[4];
            var decrypted = new byte[16];

            var outStream = new MemoryStream(length);

            while (reader.BaseStream.Position < reader.BaseStream.Length)
            {
                block[0] = reader.ReadUInt32();
                block[1] = reader.ReadUInt32();
                block[2] = reader.ReadUInt32();
                block[3] = reader.ReadUInt32();
                DeobUtils.xxteaDecrypt(block, key);
                Buffer.BlockCopy(block, 0, decrypted, 0, decrypted.Length);
                outStream.Write(decrypted, 0, decrypted.Length);
            }

            outStream.Position = 0;
            return(outStream);
        }
        public ResourceInfo[] read()
        {
            if (reader.ReadUInt32() != 0xBEEFCACE)
            {
                throw new InvalidDataException("Invalid magic");
            }
            if (reader.ReadUInt32() <= 0)
            {
                throw new InvalidDataException("Invalid number");
            }
            reader.ReadUInt32();
            resourceReader = reader.ReadString();
            if (Utils.StartsWith(resourceReader, "System.Resources.ResourceReader", StringComparison.Ordinal))
            {
                throw new InvalidDataException("Resource isn't encrypted");
            }
            resourceSet = reader.ReadString();
            if (reader.ReadByte() != 1)
            {
                throw new ApplicationException("Invalid version");
            }

            int flags = reader.ReadByte();

            if ((flags & 0xFC) != 0)
            {
                throw new ApplicationException("Invalid flags");
            }
            bool inflateData = (flags & 1) != 0;
            bool encrypted   = (flags & 2) != 0;

            int numResources = reader.ReadInt32();

            if (numResources < 0)
            {
                throw new ApplicationException("Invalid number of resources");
            }

            var infos = new ResourceInfo[numResources];

            for (int i = 0; i < numResources; i++)
            {
                var  resourceName   = readResourceName(reader, encrypted);
                int  offset         = reader.ReadInt32();
                byte resourceFlags  = reader.ReadByte();
                int  resourceLength = (resourceFlags & 0x80) == 0 ? -1 : reader.ReadInt32();
                infos[i] = new ResourceInfo(resourceName, resourceFlags, offset, resourceLength);
            }

            var dataReader = reader;

            if (encrypted)
            {
                var key = new uint[4];
                key[0] = dataReader.ReadUInt32();
                key[1] = dataReader.ReadUInt32();
                int numDwords = dataReader.ReadInt32();
                if (numDwords < 0 || numDwords >= 0x40000000)
                {
                    throw new ApplicationException("Invalid number of encrypted dwords");
                }
                var encryptedData = new uint[numDwords];
                for (int i = 0; i < numDwords; i++)
                {
                    encryptedData[i] = dataReader.ReadUInt32();
                }
                key[2] = dataReader.ReadUInt32();
                key[3] = dataReader.ReadUInt32();
                DeobUtils.xxteaDecrypt(encryptedData, key);
                byte[] decryptedData = new byte[encryptedData.Length * 4];
                Buffer.BlockCopy(encryptedData, 0, decryptedData, 0, decryptedData.Length);
                dataReader = MemoryImageStream.Create(decryptedData);
            }

            if (inflateData)
            {
                var data = dataReader.ReadRemainingBytes();
                data       = DeobUtils.inflate(data, true);
                dataReader = MemoryImageStream.Create(data);
            }

            foreach (var info in infos)
            {
                info.dataReader = dataReader;
            }

            return(infos);
        }