Beispiel #1
0
        public void TestEntryDecrypt()
        {
            var e = SaveReader.GetSaveFileEntry((byte[])Entry000_0.Clone(), 0, 0);

            e.Magic.Should().Be(0x9B7A0B7C);
            e.AdlerChecksum.Should().Be(Adler32.ComputeChecksum(e.Data));
            e.Crc32Checksum.Should().Be(Crc32.ComputeChecksum(e.Data));
            e.DataSize.Should().Be(e.Data.Length);
            e.DataSizeDuplicate.Should().Be(e.Data.Length);
        }
Beispiel #2
0
        public void TestDecryptFull()
        {
            const string dir = @"E:\snap\save\";

            for (var index = 0; index < 16; ++index)
            {
                var name = SaveReader.SaveFileNames[index];
                var file = Path.Combine(dir, name);
                if (!File.Exists(file))
                {
                    continue;
                }

                var encsave = File.ReadAllBytes(file);

                var h = SaveReader.GetSaveFileHeader(new ReadOnlySpan <byte>(encsave, 0, 0x30), index);

                var decsave   = new byte[0x20 + (h.EntryCount * h.DecryptedEntrySize)];
                var encHeader = encsave.AsSpan(..0x30);
                SaveReader.DecryptHeader(encHeader, SaveReader.SaveFileKeys[index], SaveReader.HeaderKey).CopyTo(decsave, 0);

                for (var i = 0; i < h.EntryCount; ++i)
                {
                    var start = 0x30 + (i * h.EncryptedEntrySize);
                    if (BitConverter.ToUInt64(encsave, start) == 0)
                    {
                        continue;
                    }

                    var encEntry = encsave.AsSpan(start, h.EncryptedEntrySize);

                    var e = SaveReader.GetSaveFileEntry(encEntry, index, i);

                    var region = e.Data.AsSpan(..h.DecryptedEntrySize);

                    e.AdlerChecksum.Should().Be(Adler32.ComputeChecksum(region));
                    e.Crc32Checksum.Should().Be(Crc32.ComputeChecksum(region));
                    e.Magic.Should().Be(0x9B7A0B7C);
                    e.DataSize.Should().BeLessOrEqualTo(e.Data.Length);
                    e.DataSizeDuplicate.Should().BeLessOrEqualTo(e.Data.Length);
                    e.Data.Length.Should().Be((h.DecryptedEntrySize + 15) & ~15);

                    var decDest = decsave.AsSpan(0x20 + (i * h.DecryptedEntrySize));
                    region.CopyTo(decDest);
                }

                var dest = Path.Combine(dir, $"{name}.dec");
                File.WriteAllBytes(dest, decsave);
            }
        }