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   = ByteArrayDataReaderFactory.CreateReader(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     = (uint)(startOffset + offsets[i]);
                decryptedStrings[i] = reader.ReadSerializedString();
            }
        }
Beispiel #2
0
        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 #3
0
        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);
        }