예제 #1
0
        public void KeyEncryptionTest()
        {
            var randomIrdKey = new byte[16];
            var decryptedKey = Decrypter.DecryptDiscKey(randomIrdKey);

            Assert.That(randomIrdKey.ToHexString(), Is.Not.EqualTo(decryptedKey.ToHexString()));
            var encryptedKey = Decrypter.EncryptDiscKey(decryptedKey);

            Assert.That(encryptedKey.ToHexString(), Is.EqualTo(randomIrdKey.ToHexString()));
        }
예제 #2
0
        public async Task DiscDecryptionKeyTest(string productCode, string expectedKey)
        {
            var searchResults = await Client.SearchAsync(productCode, CancellationToken.None).ConfigureAwait(false);

            Assert.That(searchResults?.Data?.Count, Is.EqualTo(1));

            var ird = await Client.DownloadAsync(searchResults.Data[0], "ird", CancellationToken.None).ConfigureAwait(false);

            Assert.That(ird, Is.Not.Null);

            var decryptionKey = Decrypter.DecryptDiscKey(ird.Data1).ToHexString();

            Assert.That(decryptionKey, Does.StartWith(expectedKey.ToLowerInvariant()));
        }
        public static DiscInfo ToDiscInfo(this Ird ird)
        {
            List <FileRecord> fsInfo;
            var sectorSize = 2048L;

            using (var stream = new MemoryStream())
            {
                using (var headerStream = new MemoryStream(ird.Header))
                    using (var gzipStream = new GZipStream(headerStream, CompressionMode.Decompress))
                    {
                        gzipStream.CopyTo(stream);
                    }
                stream.Seek(0, SeekOrigin.Begin);
                var reader = new CDReader(stream, true, true);
                fsInfo     = reader.GetFilesystemStructure();
                sectorSize = reader.ClusterSize;
            }
            var checksums = ird.Files.ToDictionary(f => f.Offset, f => f.Md5Checksum.ToHexString());

            return(new DiscInfo
            {
                ProductCode = ird.ProductCode,
                DiscVersion = ird.GameVersion,
                DiscKeyRawData = ird.Data1.ToHexString(),
                DiscKey = Decrypter.DecryptDiscKey(ird.Data1).ToHexString(),
                Files = fsInfo.ToDictionary(
                    f => f.Filename,
                    f => new FileInfo
                {
                    Offset = f.StartSector * sectorSize,
                    Size = f.Length,
                    Hashes = new Dictionary <string, string>
                    {
                        ["MD5"] = checksums[f.StartSector],
                    }
                })
            });
        }