Esempio n. 1
0
        private void TestWadEntryDataHandleOperations(Wad wad)
        {
            foreach (WadEntry entry in wad.Entries.Values)
            {
                // Ignore file redirections
                if (entry.Type == WadEntryType.FileRedirection)
                {
                    return;
                }

                WadEntryDataHandle dataHandle             = entry.GetDataHandle();
                Stream             compressedDataStream   = null;
                Stream             decompressedDataStream = null;

                Assert.DoesNotThrow(delegate
                {
                    compressedDataStream = dataHandle.GetCompressedStream();
                }, "Failed to get compressed stream");

                Assert.DoesNotThrow(delegate
                {
                    decompressedDataStream = dataHandle.GetDecompressedStream();
                }, "Failed to get decompressed data stream");

                Assert.AreEqual((int)compressedDataStream.Length, entry.CompressedSize);
                Assert.AreEqual((int)decompressedDataStream.Length, entry.UncompressedSize);

                // Verify checksum
                if (entry.ChecksumType == WadEntryChecksumType.SHA256)
                {
                    using (SHA256 sha = SHA256.Create())
                    {
                        byte[] computedHash = sha.ComputeHash(compressedDataStream).Take(8).ToArray();

                        Assert.IsTrue(computedHash.SequenceEqual(entry.Checksum), $"Entry ({entry.XXHash}) SHA256 checksum does not match computed one");
                    }
                }
                else if (entry.ChecksumType == WadEntryChecksumType.XXHash3)
                {
                    byte[] compressedData = new byte[compressedDataStream.Length];

                    compressedDataStream.Seek(0, SeekOrigin.Begin);
                    compressedDataStream.Read(compressedData);

                    ulong  computedHash      = XXHash3.Hash64(compressedData);
                    byte[] computedHashBytes = BitConverter.GetBytes(computedHash);

                    Assert.IsTrue(computedHashBytes.SequenceEqual(entry.Checksum), $"Entry ({entry.XXHash}) XXHash3 checksum does not match computed one");
                }
            }
        }
Esempio n. 2
0
        internal void ComputeChecksum()
        {
            if (this.ChecksumType == WadEntryChecksumType.SHA256)
            {
                using (SHA256 sha = SHA256.Create())
                {
                    this.DataStream.Seek(0, SeekOrigin.Begin);

                    this.Checksum = sha.ComputeHash(this.DataStream).Take(8).ToArray();
                }
            }
            else if (this.ChecksumType == WadEntryChecksumType.XXHash3)
            {
                byte[] data = new byte[this.DataStream.Length];

                this.DataStream.Seek(0, SeekOrigin.Begin);
                this.DataStream.Read(data, 0, data.Length);

                this.Checksum = BitConverter.GetBytes(XXHash3.Hash64(data));
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            byte[] xx = File.ReadAllBytes(@"C:\Users\Crauzer\Desktop\test.xxx");

            XXHash3.Hash64(xx);
        }