public bool IsValid() { Position = 0; uint signature = ReadUInt32(); if ((signature & ~(uint)(MixFileFlags.Encrypted | MixFileFlags.Checksum)) != 0) return false; if ((signature & (uint)MixFileFlags.Encrypted) != 0) { byte[] keyblock = Read(80); byte[] blowfishKey = new BlowfishKeyProvider().DecryptKey(keyblock); uint[] h = ReadUints(this, 2); var fish = new Blowfish(blowfishKey); MemoryStream ms = Decrypt(h, fish); var reader2 = new BinaryReader(ms); ushort numFiles = reader2.ReadUInt16(); uint dataSize = reader2.ReadUInt32(); /*datasize*/ return numFiles > 0 && 84 + (6 + numFiles * 12 + 7 & ~7) + dataSize + ((signature & (uint)MixFileFlags.Checksum) != 0 ? 20 : 0) == Length; } else { ushort numFiles = ReadUInt16(); uint dataSize = ReadUInt32(); return numFiles > 0 && 4 + 6 + numFiles * 12 + dataSize + ((signature & (uint)MixFileFlags.Checksum) != 0 ? 20 : 0) == Length; } }
List<MixEntry> ParseRaHeader(VirtualFile reader, out long dataStart) { //BinaryReader reader = new BinaryReader(s); byte[] keyblock = reader.Read(80); byte[] blowfishKey = new BlowfishKeyProvider().DecryptKey(keyblock); uint[] h = ReadUints(reader, 2); var fish = new Blowfish(blowfishKey); MemoryStream ms = Decrypt(h, fish); var reader2 = new BinaryReader(ms); ushort numFiles = reader2.ReadUInt16(); reader2.ReadUInt32(); /*datasize*/ reader.Position = headerStart; int byteCount = 6 + numFiles * MixEntry.Size; h = ReadUints(reader, (byteCount + 3) / 4); ms = Decrypt(h, fish); dataStart = headerStart + byteCount + ((~byteCount + 1) & 7); long ds; return ParseTdHeader(new VirtualFile(ms), out ds); }