Ejemplo n.º 1
0
        const UInt32 decryptionMultKey = 0x0019660D; // 1664525
        private byte[] DecryptArchiveHeader(FileStream fileStream)
        {
            fileStream.Seek(0, SeekOrigin.Begin);
            UInt32 encryptedHeaderSize = fileStream.ReadUInt32LE(0);
            UInt32 headerSize          = (encryptedHeaderSize ^ decryptionAddKey);
            var    fileEnd             = fileStream.Seek(0, SeekOrigin.End);

            if (headerSize > fileEnd)
            {
                throw new Exception("Header size is larger than file, something went wrong");
            }

            var headerBuffer = CopyHeader(fileStream, headerSize, 4);

            UInt32 currentKey = 0;

            byte[] copyBuffer = new byte[4];
            UInt32 value      = 0;

            int offset = 0;

            for (uint i = 0; i < headerSize; i++)
            {
                offset = (int)i * 4;

                currentKey += decryptionAddKey;

                copyBuffer[0] = headerBuffer[offset];
                copyBuffer[1] = headerBuffer[offset + 1];
                copyBuffer[2] = headerBuffer[offset + 2];
                copyBuffer[3] = headerBuffer[offset + 3];
                value         = BitConverter.ToUInt32(copyBuffer, 0);

                value = value ^ currentKey;
                value.CopyToByteArrayLE(headerBuffer, offset);

                currentKey *= decryptionMultKey;
            }
            return(headerBuffer);
        }