public void Read() { byte[] buffer = new byte[0]; Errno error = _fs.Read("49470015", 0, 0, ref buffer); Assert.AreEqual(Errno.IsDirectory, error); error = _fs.Read("49470015/TitleImage", 0, 0, ref buffer); Assert.AreEqual(Errno.NoSuchFile, error); error = _fs.Read("49470015/7AC2FE88C908/savedata.dat", 0, 0, ref buffer); Assert.AreEqual(Errno.NoError, error); Assert.AreEqual(0, buffer.Length); Assert.AreEqual("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", Sha256Context.Data(buffer, out _)); error = _fs.Read("49470015/7AC2FE88C908/savedata.dat", 1, 16, ref buffer); Assert.AreEqual(Errno.NoError, error); Assert.AreEqual(16, buffer.Length); Assert.AreEqual("ff82559d2d0c610ac25b78dcb53a8312e32b56192044deb1f01540581bd54e80", Sha256Context.Data(buffer, out _)); error = _fs.Read("49470015/7AC2FE88C908/savedata.dat", 248, 131072, ref buffer); Assert.AreEqual(Errno.NoError, error); Assert.AreEqual(61996, buffer.Length); Assert.AreEqual("2eb0d62a96ad28473ce0dd67052efdfae31f371992e1d8309beeeff6f2b46a59", Sha256Context.Data(buffer, out _)); error = _fs.Read("49470015/7AC2FE88C908/savedata.dat", 131072, 0, ref buffer); Assert.AreEqual(Errno.InvalidArgument, error); }
internal Checksum() { _crc32Ctx = new Crc32Context(); _md5Ctx = new Md5Context(); _sha1Ctx = new Sha1Context(); _sha256Ctx = new Sha256Context(); _sha384Ctx = new Sha384Context(); _sha512Ctx = new Sha512Context(); _crc32Thread = new Thread(UpdateCrc32); _md5Thread = new Thread(UpdateMd5); _sha1Thread = new Thread(UpdateSha1); _sha256Thread = new Thread(UpdateSha256); _sha384Thread = new Thread(UpdateSha384); _sha512Thread = new Thread(UpdateSha512); _crc32Pkt = new Crc32Packet(); _md5Pkt = new Md5Packet(); _sha1Pkt = new Sha1Packet(); _sha256Pkt = new Sha256Packet(); _sha384Pkt = new Sha384Packet(); _sha512Pkt = new Sha512Packet(); _crc32Pkt.context = _crc32Ctx; _md5Pkt.context = _md5Ctx; _sha1Pkt.context = _sha1Ctx; _sha256Pkt.context = _sha256Ctx; _sha384Pkt.context = _sha384Ctx; _sha512Pkt.context = _sha512Ctx; }
public void Read() { byte[] buffer = new byte[0]; Errno error = _fs.Read("Content/0000000000000000/FFFE07DF/00040000", 0, 0, ref buffer); Assert.AreEqual(Errno.IsDirectory, error); error = _fs.Read("Content/0000000000000000/FFFE07DF/00040000/ContentCache", 0, 0, ref buffer); Assert.AreEqual(Errno.NoSuchFile, error); error = _fs.Read("Content/0000000000000000/FFFE07DF/00040000/ContentCache.pkg", 0, 0, ref buffer); Assert.AreEqual(Errno.NoError, error); Assert.AreEqual(0, buffer.Length); Assert.AreEqual("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", Sha256Context.Data(buffer, out _)); error = _fs.Read("Content/0000000000000000/FFFE07DF/00040000/ContentCache.pkg", 1, 16, ref buffer); Assert.AreEqual(Errno.NoError, error); Assert.AreEqual(16, buffer.Length); Assert.AreEqual("f73a941675b8df16b0fc908f242c3c51382c5b159e709e0f9ffc1e5aac35f77d", Sha256Context.Data(buffer, out _)); error = _fs.Read("Content/0000000000000000/FFFE07DF/00040000/ContentCache.pkg", 248, 131072, ref buffer); Assert.AreEqual(Errno.NoError, error); Assert.AreEqual(85768, buffer.Length); Assert.AreEqual("19caf1365e1b7d5446ca0c2518d15e94c3ab0faaf2f8f3b31c9e1656dff57bd9", Sha256Context.Data(buffer, out _)); error = _fs.Read("Content/0000000000000000/FFFE07DF/00040000/ContentCache.pkg", 131072, 0, ref buffer); Assert.AreEqual(Errno.InvalidArgument, error); }
public void Sha256RandomData() { byte[] data = new byte[1048576]; FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open, FileAccess.Read); fs.Read(data, 0, 1048576); fs.Close(); fs.Dispose(); Sha256Context.Data(data, out byte[] result); Assert.AreEqual(ExpectedRandom, result); }
public void EmptyData() { byte[] data = new byte[1048576]; var fs = new FileStream(Path.Combine(Consts.TEST_FILES_ROOT, "Checksum test files", "empty"), FileMode.Open, FileAccess.Read); fs.Read(data, 0, 1048576); fs.Close(); fs.Dispose(); Sha256Context.Data(data, out byte[] result); result.Should().BeEquivalentTo(_expectedEmpty); }
public void Sha256RandomData() { byte[] data = new byte[1048576]; var fs = new FileStream(Path.Combine(Consts.TEST_FILES_ROOT, "Checksum test files", "random"), FileMode.Open, FileAccess.Read); fs.Read(data, 0, 1048576); fs.Close(); fs.Dispose(); Sha256Context.Data(data, out byte[] result); Assert.AreEqual(_expectedRandom, result); }
internal Checksum() { adler32ctx = new Adler32Context(); crc16ctx = new Crc16Context(); crc32ctx = new Crc32Context(); crc64ctx = new Crc64Context(); md5ctx = new Md5Context(); ripemd160ctx = new Ripemd160Context(); sha1ctx = new Sha1Context(); sha256ctx = new Sha256Context(); sha384ctx = new Sha384Context(); sha512ctx = new Sha512Context(); ssctx = new SpamSumContext(); adlerThread = new Thread(updateAdler); crc16Thread = new Thread(updateCRC16); crc32Thread = new Thread(updateCRC32); crc64Thread = new Thread(updateCRC64); md5Thread = new Thread(updateMD5); ripemd160Thread = new Thread(updateRIPEMD160); sha1Thread = new Thread(updateSHA1); sha256Thread = new Thread(updateSHA256); sha384Thread = new Thread(updateSHA384); sha512Thread = new Thread(updateSHA512); spamsumThread = new Thread(updateSpamSum); adlerPkt = new adlerPacket(); crc16Pkt = new crc16Packet(); crc32Pkt = new crc32Packet(); crc64Pkt = new crc64Packet(); md5Pkt = new md5Packet(); ripemd160Pkt = new ripemd160Packet(); sha1Pkt = new sha1Packet(); sha256Pkt = new sha256Packet(); sha384Pkt = new sha384Packet(); sha512Pkt = new sha512Packet(); spamsumPkt = new spamsumPacket(); adlerPkt.context = adler32ctx; crc16Pkt.context = crc16ctx; crc32Pkt.context = crc32ctx; crc64Pkt.context = crc64ctx; md5Pkt.context = md5ctx; ripemd160Pkt.context = ripemd160ctx; sha1Pkt.context = sha1ctx; sha256Pkt.context = sha256ctx; sha384Pkt.context = sha384ctx; sha512Pkt.context = sha512ctx; spamsumPkt.context = ssctx; }
public void Sha256EmptyInstance() { byte[] data = new byte[1048576]; FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open, FileAccess.Read); fs.Read(data, 0, 1048576); fs.Close(); fs.Dispose(); IChecksum ctx = new Sha256Context(); ctx.Update(data); byte[] result = ctx.Final(); Assert.AreEqual(ExpectedEmpty, result); }
public void EmptyInstance() { byte[] data = new byte[1048576]; var fs = new FileStream(Path.Combine(Consts.TEST_FILES_ROOT, "Checksum test files", "empty"), FileMode.Open, FileAccess.Read); fs.Read(data, 0, 1048576); fs.Close(); fs.Dispose(); IChecksum ctx = new Sha256Context(); ctx.Update(data); byte[] result = ctx.Final(); result.Should().BeEquivalentTo(_expectedEmpty); }
public void Sha256RandomInstance() { byte[] data = new byte[1048576]; var fs = new FileStream(Path.Combine(Consts.TEST_FILES_ROOT, "Checksum test files", "random"), FileMode.Open, FileAccess.Read); fs.Read(data, 0, 1048576); fs.Close(); fs.Dispose(); IChecksum ctx = new Sha256Context(); ctx.Update(data); byte[] result = ctx.Final(); Assert.AreEqual(_expectedRandom, result); }
internal static List <ChecksumType> GetChecksums(byte[] data, EnableChecksum enabled = EnableChecksum.All) { IChecksum adler32CtxData = null; IChecksum crc16CtxData = null; IChecksum crc32CtxData = null; IChecksum crc64CtxData = null; IChecksum md5CtxData = null; IChecksum sha1CtxData = null; IChecksum sha256CtxData = null; IChecksum sha384CtxData = null; IChecksum sha512CtxData = null; IChecksum ssctxData = null; IChecksum f16CtxData = null; IChecksum f32CtxData = null; var adlerThreadData = new Thread(UpdateHash); var crc16ThreadData = new Thread(UpdateHash); var crc32ThreadData = new Thread(UpdateHash); var crc64ThreadData = new Thread(UpdateHash); var md5ThreadData = new Thread(UpdateHash); var sha1ThreadData = new Thread(UpdateHash); var sha256ThreadData = new Thread(UpdateHash); var sha384ThreadData = new Thread(UpdateHash); var sha512ThreadData = new Thread(UpdateHash); var spamsumThreadData = new Thread(UpdateHash); var f16ThreadData = new Thread(UpdateHash); var f32ThreadData = new Thread(UpdateHash); if (enabled.HasFlag(EnableChecksum.Adler32)) { adler32CtxData = new Adler32Context(); var adlerPktData = new HashPacket { Context = adler32CtxData, Data = data }; adlerThreadData.Start(adlerPktData); } if (enabled.HasFlag(EnableChecksum.Crc16)) { crc16CtxData = new CRC16IBMContext(); var crc16PktData = new HashPacket { Context = crc16CtxData, Data = data }; crc16ThreadData.Start(crc16PktData); } if (enabled.HasFlag(EnableChecksum.Crc32)) { crc32CtxData = new Crc32Context(); var crc32PktData = new HashPacket { Context = crc32CtxData, Data = data }; crc32ThreadData.Start(crc32PktData); } if (enabled.HasFlag(EnableChecksum.Crc64)) { crc64CtxData = new Crc64Context(); var crc64PktData = new HashPacket { Context = crc64CtxData, Data = data }; crc64ThreadData.Start(crc64PktData); } if (enabled.HasFlag(EnableChecksum.Md5)) { md5CtxData = new Md5Context(); var md5PktData = new HashPacket { Context = md5CtxData, Data = data }; md5ThreadData.Start(md5PktData); } if (enabled.HasFlag(EnableChecksum.Sha1)) { sha1CtxData = new Sha1Context(); var sha1PktData = new HashPacket { Context = sha1CtxData, Data = data }; sha1ThreadData.Start(sha1PktData); } if (enabled.HasFlag(EnableChecksum.Sha256)) { sha256CtxData = new Sha256Context(); var sha256PktData = new HashPacket { Context = sha256CtxData, Data = data }; sha256ThreadData.Start(sha256PktData); } if (enabled.HasFlag(EnableChecksum.Sha384)) { sha384CtxData = new Sha384Context(); var sha384PktData = new HashPacket { Context = sha384CtxData, Data = data }; sha384ThreadData.Start(sha384PktData); } if (enabled.HasFlag(EnableChecksum.Sha512)) { sha512CtxData = new Sha512Context(); var sha512PktData = new HashPacket { Context = sha512CtxData, Data = data }; sha512ThreadData.Start(sha512PktData); } if (enabled.HasFlag(EnableChecksum.SpamSum)) { ssctxData = new SpamSumContext(); var spamsumPktData = new HashPacket { Context = ssctxData, Data = data }; spamsumThreadData.Start(spamsumPktData); } if (enabled.HasFlag(EnableChecksum.Fletcher16)) { f16CtxData = new Fletcher16Context(); var f16PktData = new HashPacket { Context = f16CtxData, Data = data }; f16ThreadData.Start(f16PktData); } if (enabled.HasFlag(EnableChecksum.Fletcher32)) { f32CtxData = new Fletcher32Context(); var f32PktData = new HashPacket { Context = f32CtxData, Data = data }; f32ThreadData.Start(f32PktData); } while (adlerThreadData.IsAlive || crc16ThreadData.IsAlive || crc32ThreadData.IsAlive || crc64ThreadData.IsAlive || md5ThreadData.IsAlive || sha1ThreadData.IsAlive || sha256ThreadData.IsAlive || sha384ThreadData.IsAlive || sha512ThreadData.IsAlive || spamsumThreadData.IsAlive || f16ThreadData.IsAlive || f32ThreadData.IsAlive) { } List <ChecksumType> dataChecksums = new List <ChecksumType>(); ChecksumType chk; if (enabled.HasFlag(EnableChecksum.Adler32)) { chk = new ChecksumType { type = ChecksumTypeType.adler32, Value = adler32CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Crc16)) { chk = new ChecksumType { type = ChecksumTypeType.crc16, Value = crc16CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Crc32)) { chk = new ChecksumType { type = ChecksumTypeType.crc32, Value = crc32CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Crc64)) { chk = new ChecksumType { type = ChecksumTypeType.crc64, Value = crc64CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Md5)) { chk = new ChecksumType { type = ChecksumTypeType.md5, Value = md5CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Sha1)) { chk = new ChecksumType { type = ChecksumTypeType.sha1, Value = sha1CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Sha256)) { chk = new ChecksumType { type = ChecksumTypeType.sha256, Value = sha256CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Sha384)) { chk = new ChecksumType { type = ChecksumTypeType.sha384, Value = sha384CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Sha512)) { chk = new ChecksumType { type = ChecksumTypeType.sha512, Value = sha512CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.SpamSum)) { chk = new ChecksumType { type = ChecksumTypeType.spamsum, Value = ssctxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Fletcher16)) { chk = new ChecksumType { type = ChecksumTypeType.fletcher16, Value = f16CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Fletcher32)) { chk = new ChecksumType { type = ChecksumTypeType.fletcher32, Value = f32CtxData.End() }; dataChecksums.Add(chk); } return(dataChecksums); }
internal static List <ChecksumType> GetChecksums(byte[] data, EnableChecksum enabled = EnableChecksum.All) { IChecksum adler32CtxData = null; IChecksum crc16CtxData = null; IChecksum crc32CtxData = null; IChecksum crc64CtxData = null; IChecksum md5CtxData = null; #if !NETSTANDARD2_0 IChecksum ripemd160CtxData = null; #endif IChecksum sha1CtxData = null; IChecksum sha256CtxData = null; IChecksum sha384CtxData = null; IChecksum sha512CtxData = null; IChecksum ssctxData = null; IChecksum f16CtxData = null; IChecksum f32CtxData = null; Thread adlerThreadData = new Thread(UpdateHash); Thread crc16ThreadData = new Thread(UpdateHash); Thread crc32ThreadData = new Thread(UpdateHash); Thread crc64ThreadData = new Thread(UpdateHash); Thread md5ThreadData = new Thread(UpdateHash); #if !NETSTANDARD2_0 Thread ripemd160ThreadData = new Thread(UpdateHash); #endif Thread sha1ThreadData = new Thread(UpdateHash); Thread sha256ThreadData = new Thread(UpdateHash); Thread sha384ThreadData = new Thread(UpdateHash); Thread sha512ThreadData = new Thread(UpdateHash); Thread spamsumThreadData = new Thread(UpdateHash); Thread f16ThreadData = new Thread(UpdateHash); Thread f32ThreadData = new Thread(UpdateHash); if (enabled.HasFlag(EnableChecksum.Adler32)) { adler32CtxData = new Adler32Context(); HashPacket adlerPktData = new HashPacket { Context = adler32CtxData, Data = data }; adlerThreadData.Start(adlerPktData); } if (enabled.HasFlag(EnableChecksum.Crc16)) { crc16CtxData = new Crc16Context(); HashPacket crc16PktData = new HashPacket { Context = crc16CtxData, Data = data }; crc16ThreadData.Start(crc16PktData); } if (enabled.HasFlag(EnableChecksum.Crc32)) { crc32CtxData = new Crc32Context(); HashPacket crc32PktData = new HashPacket { Context = crc32CtxData, Data = data }; crc32ThreadData.Start(crc32PktData); } if (enabled.HasFlag(EnableChecksum.Crc64)) { crc64CtxData = new Crc64Context(); HashPacket crc64PktData = new HashPacket { Context = crc64CtxData, Data = data }; crc64ThreadData.Start(crc64PktData); } if (enabled.HasFlag(EnableChecksum.Md5)) { md5CtxData = new Md5Context(); HashPacket md5PktData = new HashPacket { Context = md5CtxData, Data = data }; md5ThreadData.Start(md5PktData); } #if !NETSTANDARD2_0 if (enabled.HasFlag(EnableChecksum.Ripemd160)) { ripemd160CtxData = new Ripemd160Context(); HashPacket ripemd160PktData = new HashPacket { Context = ripemd160CtxData, Data = data }; ripemd160ThreadData.Start(ripemd160PktData); } #endif if (enabled.HasFlag(EnableChecksum.Sha1)) { sha1CtxData = new Sha1Context(); HashPacket sha1PktData = new HashPacket { Context = sha1CtxData, Data = data }; sha1ThreadData.Start(sha1PktData); } if (enabled.HasFlag(EnableChecksum.Sha256)) { sha256CtxData = new Sha256Context(); HashPacket sha256PktData = new HashPacket { Context = sha256CtxData, Data = data }; sha256ThreadData.Start(sha256PktData); } if (enabled.HasFlag(EnableChecksum.Sha384)) { sha384CtxData = new Sha384Context(); HashPacket sha384PktData = new HashPacket { Context = sha384CtxData, Data = data }; sha384ThreadData.Start(sha384PktData); } if (enabled.HasFlag(EnableChecksum.Sha512)) { sha512CtxData = new Sha512Context(); HashPacket sha512PktData = new HashPacket { Context = sha512CtxData, Data = data }; sha512ThreadData.Start(sha512PktData); } if (enabled.HasFlag(EnableChecksum.SpamSum)) { ssctxData = new SpamSumContext(); HashPacket spamsumPktData = new HashPacket { Context = ssctxData, Data = data }; spamsumThreadData.Start(spamsumPktData); } if (enabled.HasFlag(EnableChecksum.Fletcher16)) { f16CtxData = new Fletcher16Context(); HashPacket f16PktData = new HashPacket { Context = f16CtxData, Data = data }; f16ThreadData.Start(f16PktData); } if (enabled.HasFlag(EnableChecksum.Fletcher32)) { f32CtxData = new Fletcher32Context(); HashPacket f32PktData = new HashPacket { Context = f32CtxData, Data = data }; f32ThreadData.Start(f32PktData); } while (adlerThreadData.IsAlive || crc16ThreadData.IsAlive || crc32ThreadData.IsAlive || crc64ThreadData.IsAlive || md5ThreadData.IsAlive || #if !NETSTANDARD2_0 ripemd160ThreadData.IsAlive || #endif sha1ThreadData.IsAlive || sha256ThreadData.IsAlive || sha384ThreadData.IsAlive || sha512ThreadData.IsAlive || spamsumThreadData.IsAlive || f16ThreadData.IsAlive || f32ThreadData.IsAlive) { } List <ChecksumType> dataChecksums = new List <ChecksumType>(); ChecksumType chk; if (enabled.HasFlag(EnableChecksum.Adler32)) { chk = new ChecksumType { type = ChecksumTypeType.adler32, Value = adler32CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Crc16)) { chk = new ChecksumType { type = ChecksumTypeType.crc16, Value = crc16CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Crc32)) { chk = new ChecksumType { type = ChecksumTypeType.crc32, Value = crc32CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Crc64)) { chk = new ChecksumType { type = ChecksumTypeType.crc64, Value = crc64CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Md5)) { chk = new ChecksumType { type = ChecksumTypeType.md5, Value = md5CtxData.End() }; dataChecksums.Add(chk); } #if !NETSTANDARD2_0 if (enabled.HasFlag(EnableChecksum.Ripemd160)) { chk = new ChecksumType { type = ChecksumTypeType.ripemd160, Value = ripemd160CtxData.End() }; dataChecksums.Add(chk); } #endif if (enabled.HasFlag(EnableChecksum.Sha1)) { chk = new ChecksumType { type = ChecksumTypeType.sha1, Value = sha1CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Sha256)) { chk = new ChecksumType { type = ChecksumTypeType.sha256, Value = sha256CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Sha384)) { chk = new ChecksumType { type = ChecksumTypeType.sha384, Value = sha384CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Sha512)) { chk = new ChecksumType { type = ChecksumTypeType.sha512, Value = sha512CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.SpamSum)) { chk = new ChecksumType { type = ChecksumTypeType.spamsum, Value = ssctxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Fletcher16)) { chk = new ChecksumType { type = ChecksumTypeType.fletcher16, Value = f16CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Fletcher32)) { chk = new ChecksumType { type = ChecksumTypeType.fletcher32, Value = f32CtxData.End() }; dataChecksums.Add(chk); } return(dataChecksums); }
public void Sha256EmptyFile() { byte[] result = Sha256Context.File(Path.Combine(Consts.TEST_FILES_ROOT, "Checksum test files", "empty")); Assert.AreEqual(_expectedEmpty, result); }
public void Sha256RandomFile() { byte[] result = Sha256Context.File(Path.Combine(Consts.TEST_FILES_ROOT, "Checksum test files", "random")); Assert.AreEqual(_expectedRandom, result); }
public static BenchmarkResults Do(int bufferSize, int blockSize) { BenchmarkResults results = new BenchmarkResults { Entries = new Dictionary <string, BenchmarkEntry>(), MinMemory = long.MaxValue, MaxMemory = 0, SeparateTime = 0 }; MemoryStream ms = new MemoryStream(bufferSize); Random rnd = new Random(); DateTime start; DateTime end; start = DateTime.Now; InitProgress(); for (int i = 0; i < bufferSize / blockSize; i++) { UpdateProgress("Writing block {0} of {1} with random data.", i + 1, bufferSize / blockSize); byte[] tmp = new byte[blockSize]; rnd.NextBytes(tmp); ms.Write(tmp, 0, blockSize); } EndProgress(); end = DateTime.Now; results.FillTime = (end - start).TotalSeconds; results.FillSpeed = bufferSize / 1048576.0 / (end - start).TotalSeconds; ms.Seek(0, SeekOrigin.Begin); long mem = GC.GetTotalMemory(false); if (mem > results.MaxMemory) { results.MaxMemory = mem; } if (mem < results.MinMemory) { results.MinMemory = mem; } start = DateTime.Now; InitProgress(); for (int i = 0; i < bufferSize / blockSize; i++) { UpdateProgress("Reading block {0} of {1}.", i + 1, bufferSize / blockSize); byte[] tmp = new byte[blockSize]; ms.Read(tmp, 0, blockSize); } EndProgress(); end = DateTime.Now; mem = GC.GetTotalMemory(false); if (mem > results.MaxMemory) { results.MaxMemory = mem; } if (mem < results.MinMemory) { results.MinMemory = mem; } results.ReadTime = (end - start).TotalSeconds; results.ReadSpeed = bufferSize / 1048576.0 / (end - start).TotalSeconds; #region Adler32 IChecksum ctx = new Adler32Context(); ms.Seek(0, SeekOrigin.Begin); mem = GC.GetTotalMemory(false); if (mem > results.MaxMemory) { results.MaxMemory = mem; } if (mem < results.MinMemory) { results.MinMemory = mem; } start = DateTime.Now; InitProgress(); for (int i = 0; i < bufferSize / blockSize; i++) { UpdateProgress("Checksumming block {0} of {1} with Adler32.", i + 1, bufferSize / blockSize); byte[] tmp = new byte[blockSize]; ms.Read(tmp, 0, blockSize); ctx.Update(tmp); } EndProgress(); ctx.End(); end = DateTime.Now; mem = GC.GetTotalMemory(false); if (mem > results.MaxMemory) { results.MaxMemory = mem; } if (mem < results.MinMemory) { results.MinMemory = mem; } results.Entries.Add("Adler32", new BenchmarkEntry { TimeSpan = (end - start).TotalSeconds, Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds }); results.SeparateTime += (end - start).TotalSeconds; #endregion Adler32 #region Fletcher16 ctx = new Fletcher16Context(); ms.Seek(0, SeekOrigin.Begin); mem = GC.GetTotalMemory(false); if (mem > results.MaxMemory) { results.MaxMemory = mem; } if (mem < results.MinMemory) { results.MinMemory = mem; } start = DateTime.Now; InitProgress(); for (int i = 0; i < bufferSize / blockSize; i++) { UpdateProgress("Checksumming block {0} of {1} with Fletcher-16.", i + 1, bufferSize / blockSize); byte[] tmp = new byte[blockSize]; ms.Read(tmp, 0, blockSize); ctx.Update(tmp); } EndProgress(); ctx.End(); end = DateTime.Now; mem = GC.GetTotalMemory(false); if (mem > results.MaxMemory) { results.MaxMemory = mem; } if (mem < results.MinMemory) { results.MinMemory = mem; } results.Entries.Add("Fletcher16", new BenchmarkEntry { TimeSpan = (end - start).TotalSeconds, Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds }); results.SeparateTime += (end - start).TotalSeconds; #endregion Fletcher16 #region Fletcher32 ctx = new Fletcher32Context(); ms.Seek(0, SeekOrigin.Begin); mem = GC.GetTotalMemory(false); if (mem > results.MaxMemory) { results.MaxMemory = mem; } if (mem < results.MinMemory) { results.MinMemory = mem; } start = DateTime.Now; InitProgress(); for (int i = 0; i < bufferSize / blockSize; i++) { UpdateProgress("Checksumming block {0} of {1} with Fletcher-32.", i + 1, bufferSize / blockSize); byte[] tmp = new byte[blockSize]; ms.Read(tmp, 0, blockSize); ctx.Update(tmp); } EndProgress(); ctx.End(); end = DateTime.Now; mem = GC.GetTotalMemory(false); if (mem > results.MaxMemory) { results.MaxMemory = mem; } if (mem < results.MinMemory) { results.MinMemory = mem; } results.Entries.Add("Fletcher32", new BenchmarkEntry { TimeSpan = (end - start).TotalSeconds, Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds }); results.SeparateTime += (end - start).TotalSeconds; #endregion Fletcher32 #region CRC16 ctx = new Crc16Context(); ms.Seek(0, SeekOrigin.Begin); mem = GC.GetTotalMemory(false); if (mem > results.MaxMemory) { results.MaxMemory = mem; } if (mem < results.MinMemory) { results.MinMemory = mem; } start = DateTime.Now; InitProgress(); for (int i = 0; i < bufferSize / blockSize; i++) { UpdateProgress("Checksumming block {0} of {1} with CRC16.", i + 1, bufferSize / blockSize); byte[] tmp = new byte[blockSize]; ms.Read(tmp, 0, blockSize); ctx.Update(tmp); } EndProgress(); ctx.End(); end = DateTime.Now; mem = GC.GetTotalMemory(false); if (mem > results.MaxMemory) { results.MaxMemory = mem; } if (mem < results.MinMemory) { results.MinMemory = mem; } results.Entries.Add("CRC16", new BenchmarkEntry { TimeSpan = (end - start).TotalSeconds, Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds }); results.SeparateTime += (end - start).TotalSeconds; #endregion CRC16 #region CRC32 ctx = new Crc32Context(); ms.Seek(0, SeekOrigin.Begin); mem = GC.GetTotalMemory(false); if (mem > results.MaxMemory) { results.MaxMemory = mem; } if (mem < results.MinMemory) { results.MinMemory = mem; } start = DateTime.Now; InitProgress(); for (int i = 0; i < bufferSize / blockSize; i++) { UpdateProgress("Checksumming block {0} of {1} with CRC32.", i + 1, bufferSize / blockSize); byte[] tmp = new byte[blockSize]; ms.Read(tmp, 0, blockSize); ctx.Update(tmp); } EndProgress(); ctx.End(); end = DateTime.Now; mem = GC.GetTotalMemory(false); if (mem > results.MaxMemory) { results.MaxMemory = mem; } if (mem < results.MinMemory) { results.MinMemory = mem; } results.Entries.Add("CRC32", new BenchmarkEntry { TimeSpan = (end - start).TotalSeconds, Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds }); results.SeparateTime += (end - start).TotalSeconds; #endregion CRC32 #region CRC64 ctx = new Crc64Context(); ms.Seek(0, SeekOrigin.Begin); mem = GC.GetTotalMemory(false); if (mem > results.MaxMemory) { results.MaxMemory = mem; } if (mem < results.MinMemory) { results.MinMemory = mem; } start = DateTime.Now; InitProgress(); for (int i = 0; i < bufferSize / blockSize; i++) { UpdateProgress("Checksumming block {0} of {1} with CRC64.", i + 1, bufferSize / blockSize); byte[] tmp = new byte[blockSize]; ms.Read(tmp, 0, blockSize); ctx.Update(tmp); } EndProgress(); ctx.End(); end = DateTime.Now; mem = GC.GetTotalMemory(false); if (mem > results.MaxMemory) { results.MaxMemory = mem; } if (mem < results.MinMemory) { results.MinMemory = mem; } results.Entries.Add("CRC64", new BenchmarkEntry { TimeSpan = (end - start).TotalSeconds, Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds }); results.SeparateTime += (end - start).TotalSeconds; #endregion CRC64 #region MD5 ctx = new Md5Context(); ms.Seek(0, SeekOrigin.Begin); mem = GC.GetTotalMemory(false); if (mem > results.MaxMemory) { results.MaxMemory = mem; } if (mem < results.MinMemory) { results.MinMemory = mem; } start = DateTime.Now; InitProgress(); for (int i = 0; i < bufferSize / blockSize; i++) { UpdateProgress("Checksumming block {0} of {1} with MD5.", i + 1, bufferSize / blockSize); byte[] tmp = new byte[blockSize]; ms.Read(tmp, 0, blockSize); ctx.Update(tmp); } EndProgress(); ctx.End(); end = DateTime.Now; mem = GC.GetTotalMemory(false); if (mem > results.MaxMemory) { results.MaxMemory = mem; } if (mem < results.MinMemory) { results.MinMemory = mem; } results.Entries.Add("MD5", new BenchmarkEntry { TimeSpan = (end - start).TotalSeconds, Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds }); results.SeparateTime += (end - start).TotalSeconds; #endregion MD5 #if !NETSTANDARD2_0 #region RIPEMD160 ctx = new Ripemd160Context(); ms.Seek(0, SeekOrigin.Begin); mem = GC.GetTotalMemory(false); if (mem > results.MaxMemory) { results.MaxMemory = mem; } if (mem < results.MinMemory) { results.MinMemory = mem; } start = DateTime.Now; InitProgress(); for (int i = 0; i < bufferSize / blockSize; i++) { UpdateProgress("Checksumming block {0} of {1} with RIPEMD160.", i + 1, bufferSize / blockSize); byte[] tmp = new byte[blockSize]; ms.Read(tmp, 0, blockSize); ctx.Update(tmp); } EndProgress(); ctx.End(); end = DateTime.Now; mem = GC.GetTotalMemory(false); if (mem > results.MaxMemory) { results.MaxMemory = mem; } if (mem < results.MinMemory) { results.MinMemory = mem; } results.Entries.Add("RIPEMD160", new BenchmarkEntry { TimeSpan = (end - start).TotalSeconds, Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds }); results.SeparateTime += (end - start).TotalSeconds; #endregion RIPEMD160 #endif #region SHA1 ctx = new Sha1Context(); ms.Seek(0, SeekOrigin.Begin); mem = GC.GetTotalMemory(false); if (mem > results.MaxMemory) { results.MaxMemory = mem; } if (mem < results.MinMemory) { results.MinMemory = mem; } start = DateTime.Now; InitProgress(); for (int i = 0; i < bufferSize / blockSize; i++) { UpdateProgress("Checksumming block {0} of {1} with SHA1.", i + 1, bufferSize / blockSize); byte[] tmp = new byte[blockSize]; ms.Read(tmp, 0, blockSize); ctx.Update(tmp); } EndProgress(); ctx.End(); end = DateTime.Now; mem = GC.GetTotalMemory(false); if (mem > results.MaxMemory) { results.MaxMemory = mem; } if (mem < results.MinMemory) { results.MinMemory = mem; } results.Entries.Add("SHA1", new BenchmarkEntry { TimeSpan = (end - start).TotalSeconds, Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds }); results.SeparateTime += (end - start).TotalSeconds; #endregion SHA1 #region SHA256 ctx = new Sha256Context(); ms.Seek(0, SeekOrigin.Begin); mem = GC.GetTotalMemory(false); if (mem > results.MaxMemory) { results.MaxMemory = mem; } if (mem < results.MinMemory) { results.MinMemory = mem; } start = DateTime.Now; InitProgress(); for (int i = 0; i < bufferSize / blockSize; i++) { UpdateProgress("Checksumming block {0} of {1} with SHA256.", i + 1, bufferSize / blockSize); byte[] tmp = new byte[blockSize]; ms.Read(tmp, 0, blockSize); ctx.Update(tmp); } EndProgress(); ctx.End(); end = DateTime.Now; mem = GC.GetTotalMemory(false); if (mem > results.MaxMemory) { results.MaxMemory = mem; } if (mem < results.MinMemory) { results.MinMemory = mem; } results.Entries.Add("SHA256", new BenchmarkEntry { TimeSpan = (end - start).TotalSeconds, Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds }); results.SeparateTime += (end - start).TotalSeconds; #endregion SHA256 #region SHA384 ctx = new Sha384Context(); ms.Seek(0, SeekOrigin.Begin); mem = GC.GetTotalMemory(false); if (mem > results.MaxMemory) { results.MaxMemory = mem; } if (mem < results.MinMemory) { results.MinMemory = mem; } start = DateTime.Now; InitProgress(); for (int i = 0; i < bufferSize / blockSize; i++) { UpdateProgress("Checksumming block {0} of {1} with SHA384.", i + 1, bufferSize / blockSize); byte[] tmp = new byte[blockSize]; ms.Read(tmp, 0, blockSize); ctx.Update(tmp); } EndProgress(); ctx.End(); end = DateTime.Now; mem = GC.GetTotalMemory(false); if (mem > results.MaxMemory) { results.MaxMemory = mem; } if (mem < results.MinMemory) { results.MinMemory = mem; } results.Entries.Add("SHA384", new BenchmarkEntry { TimeSpan = (end - start).TotalSeconds, Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds }); results.SeparateTime += (end - start).TotalSeconds; #endregion SHA384 #region SHA512 ctx = new Sha512Context(); ms.Seek(0, SeekOrigin.Begin); mem = GC.GetTotalMemory(false); if (mem > results.MaxMemory) { results.MaxMemory = mem; } if (mem < results.MinMemory) { results.MinMemory = mem; } start = DateTime.Now; InitProgress(); for (int i = 0; i < bufferSize / blockSize; i++) { UpdateProgress("Checksumming block {0} of {1} with SHA512.", i + 1, bufferSize / blockSize); byte[] tmp = new byte[blockSize]; ms.Read(tmp, 0, blockSize); ctx.Update(tmp); } EndProgress(); ctx.End(); end = DateTime.Now; mem = GC.GetTotalMemory(false); if (mem > results.MaxMemory) { results.MaxMemory = mem; } if (mem < results.MinMemory) { results.MinMemory = mem; } results.Entries.Add("SHA512", new BenchmarkEntry { TimeSpan = (end - start).TotalSeconds, Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds }); results.SeparateTime += (end - start).TotalSeconds; #endregion SHA512 #region SpamSum ctx = new SpamSumContext(); ms.Seek(0, SeekOrigin.Begin); mem = GC.GetTotalMemory(false); if (mem > results.MaxMemory) { results.MaxMemory = mem; } if (mem < results.MinMemory) { results.MinMemory = mem; } start = DateTime.Now; InitProgress(); for (int i = 0; i < bufferSize / blockSize; i++) { UpdateProgress("Checksumming block {0} of {1} with SpamSum.", i + 1, bufferSize / blockSize); byte[] tmp = new byte[blockSize]; ms.Read(tmp, 0, blockSize); ctx.Update(tmp); } EndProgress(); ctx.End(); end = DateTime.Now; mem = GC.GetTotalMemory(false); if (mem > results.MaxMemory) { results.MaxMemory = mem; } if (mem < results.MinMemory) { results.MinMemory = mem; } results.Entries.Add("SpamSum", new BenchmarkEntry { TimeSpan = (end - start).TotalSeconds, Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds }); results.SeparateTime += (end - start).TotalSeconds; #endregion SpamSum #region Entropy ulong[] entTable = new ulong[256]; ms.Seek(0, SeekOrigin.Begin); mem = GC.GetTotalMemory(false); if (mem > results.MaxMemory) { results.MaxMemory = mem; } if (mem < results.MinMemory) { results.MinMemory = mem; } start = DateTime.Now; InitProgress(); for (int i = 0; i < bufferSize / blockSize; i++) { UpdateProgress("Entropying block {0} of {1}.", i + 1, bufferSize / blockSize); byte[] tmp = new byte[blockSize]; ms.Read(tmp, 0, blockSize); foreach (byte b in tmp) { entTable[b]++; } } EndProgress(); end = DateTime.Now; mem = GC.GetTotalMemory(false); if (mem > results.MaxMemory) { results.MaxMemory = mem; } if (mem < results.MinMemory) { results.MinMemory = mem; } results.EntropyTime = (end - start).TotalSeconds; results.EntropySpeed = bufferSize / 1048576.0 / (end - start).TotalSeconds; #endregion Entropy /* #region Multitasking * start = DateTime.Now; * Checksum allChecksums = new Checksum(); * InitProgress(); * for(int i = 0; i < bufferSize / blockSize; i++) * { * UpdateProgress("Checksumming block {0} of {1} with all algorithms at the same time.", i + 1, * bufferSize / blockSize); * byte[] tmp = new byte[blockSize]; * ms.Read(tmp, 0, blockSize); * * allChecksums.Update(tmp); * } * * EndProgress(); * * allChecksums.End(); * end = DateTime.Now; * mem = GC.GetTotalMemory(false); * if(mem > results.MaxMemory) results.MaxMemory = mem; * if(mem < results.MinMemory) results.MinMemory = mem; * * results.TotalTime = (end - start).TotalSeconds; * results.TotalSpeed = bufferSize / 1048576.0 / results.TotalTime; #endregion */ results.SeparateSpeed = bufferSize / 1048576.0 / results.SeparateTime; return(results); }
public void EmptyFile() { byte[] result = Sha256Context.File(Path.Combine(Consts.TEST_FILES_ROOT, "Checksum test files", "empty")); result.Should().BeEquivalentTo(_expectedEmpty); }
public void Sha256RandomFile() { byte[] result = Sha256Context.File(Path.Combine(Consts.TestFilesRoot, "checksums", "random")); Assert.AreEqual(ExpectedRandom, result); }
public void Sha256EmptyFile() { byte[] result = Sha256Context.File(Path.Combine(Consts.TestFilesRoot, "checksums", "empty")); Assert.AreEqual(ExpectedEmpty, result); }
internal static List <ChecksumType> GetChecksums(byte[] data) { Adler32Context adler32ctxData = new Adler32Context(); Crc16Context crc16ctxData = new Crc16Context(); Crc32Context crc32ctxData = new Crc32Context(); Crc64Context crc64ctxData = new Crc64Context(); Md5Context md5ctxData = new Md5Context(); Ripemd160Context ripemd160ctxData = new Ripemd160Context(); Sha1Context sha1ctxData = new Sha1Context(); Sha256Context sha256ctxData = new Sha256Context(); Sha384Context sha384ctxData = new Sha384Context(); Sha512Context sha512ctxData = new Sha512Context(); SpamSumContext ssctxData = new SpamSumContext(); Thread adlerThreadData = new Thread(updateAdler); Thread crc16ThreadData = new Thread(updateCRC16); Thread crc32ThreadData = new Thread(updateCRC32); Thread crc64ThreadData = new Thread(updateCRC64); Thread md5ThreadData = new Thread(updateMD5); Thread ripemd160ThreadData = new Thread(updateRIPEMD160); Thread sha1ThreadData = new Thread(updateSHA1); Thread sha256ThreadData = new Thread(updateSHA256); Thread sha384ThreadData = new Thread(updateSHA384); Thread sha512ThreadData = new Thread(updateSHA512); Thread spamsumThreadData = new Thread(updateSpamSum); adlerPacket adlerPktData = new adlerPacket(); crc16Packet crc16PktData = new crc16Packet(); crc32Packet crc32PktData = new crc32Packet(); crc64Packet crc64PktData = new crc64Packet(); md5Packet md5PktData = new md5Packet(); ripemd160Packet ripemd160PktData = new ripemd160Packet(); sha1Packet sha1PktData = new sha1Packet(); sha256Packet sha256PktData = new sha256Packet(); sha384Packet sha384PktData = new sha384Packet(); sha512Packet sha512PktData = new sha512Packet(); spamsumPacket spamsumPktData = new spamsumPacket(); adler32ctxData.Init(); adlerPktData.context = adler32ctxData; crc16ctxData.Init(); crc16PktData.context = crc16ctxData; crc32ctxData.Init(); crc32PktData.context = crc32ctxData; crc64ctxData.Init(); crc64PktData.context = crc64ctxData; md5ctxData.Init(); md5PktData.context = md5ctxData; ripemd160ctxData.Init(); ripemd160PktData.context = ripemd160ctxData; sha1ctxData.Init(); sha1PktData.context = sha1ctxData; sha256ctxData.Init(); sha256PktData.context = sha256ctxData; sha384ctxData.Init(); sha384PktData.context = sha384ctxData; sha512ctxData.Init(); sha512PktData.context = sha512ctxData; ssctxData.Init(); spamsumPktData.context = ssctxData; adlerPktData.data = data; adlerThreadData.Start(adlerPktData); crc16PktData.data = data; crc16ThreadData.Start(crc16PktData); crc32PktData.data = data; crc32ThreadData.Start(crc32PktData); crc64PktData.data = data; crc64ThreadData.Start(crc64PktData); md5PktData.data = data; md5ThreadData.Start(md5PktData); ripemd160PktData.data = data; ripemd160ThreadData.Start(ripemd160PktData); sha1PktData.data = data; sha1ThreadData.Start(sha1PktData); sha256PktData.data = data; sha256ThreadData.Start(sha256PktData); sha384PktData.data = data; sha384ThreadData.Start(sha384PktData); sha512PktData.data = data; sha512ThreadData.Start(sha512PktData); spamsumPktData.data = data; spamsumThreadData.Start(spamsumPktData); while (adlerThreadData.IsAlive || crc16ThreadData.IsAlive || crc32ThreadData.IsAlive || crc64ThreadData.IsAlive || md5ThreadData.IsAlive || ripemd160ThreadData.IsAlive || sha1ThreadData.IsAlive || sha256ThreadData.IsAlive || sha384ThreadData.IsAlive || sha512ThreadData.IsAlive || spamsumThreadData.IsAlive) { } List <ChecksumType> dataChecksums = new List <ChecksumType>(); ChecksumType chk = new ChecksumType { type = ChecksumTypeType.adler32, Value = adler32ctxData.End() }; dataChecksums.Add(chk); chk = new ChecksumType { type = ChecksumTypeType.crc16, Value = crc16ctxData.End() }; dataChecksums.Add(chk); chk = new ChecksumType { type = ChecksumTypeType.crc32, Value = crc32ctxData.End() }; dataChecksums.Add(chk); chk = new ChecksumType { type = ChecksumTypeType.crc64, Value = crc64ctxData.End() }; dataChecksums.Add(chk); chk = new ChecksumType { type = ChecksumTypeType.md5, Value = md5ctxData.End() }; dataChecksums.Add(chk); chk = new ChecksumType { type = ChecksumTypeType.ripemd160, Value = ripemd160ctxData.End() }; dataChecksums.Add(chk); chk = new ChecksumType { type = ChecksumTypeType.sha1, Value = sha1ctxData.End() }; dataChecksums.Add(chk); chk = new ChecksumType { type = ChecksumTypeType.sha256, Value = sha256ctxData.End() }; dataChecksums.Add(chk); chk = new ChecksumType { type = ChecksumTypeType.sha384, Value = sha384ctxData.End() }; dataChecksums.Add(chk); chk = new ChecksumType { type = ChecksumTypeType.sha512, Value = sha512ctxData.End() }; dataChecksums.Add(chk); chk = new ChecksumType { type = ChecksumTypeType.spamsum, Value = ssctxData.End() }; dataChecksums.Add(chk); return(dataChecksums); }
public static void DetectDiscType(ref MediaType mediaType, int sessions, FullTOC.CDFullTOC?decodedToc, Device dev, out bool hiddenTrack, out bool hiddenData, int firstTrackLastSession) { uint startOfFirstDataTrack = uint.MaxValue; byte[] cmdBuf; bool sense; byte secondSessionFirstTrack = 0; byte[] sector0; byte[] sector1 = null; byte[] ps2BootSectors = null; byte[] playdia1 = null; byte[] playdia2 = null; byte[] firstDataSectorNotZero = null; byte[] secondDataSectorNotZero = null; byte[] firstTrackSecondSession = null; byte[] firstTrackSecondSessionAudio = null; byte[] videoNowColorFrame; hiddenTrack = false; hiddenData = false; if (decodedToc.HasValue) { if (decodedToc.Value.TrackDescriptors.Any(t => t.SessionNumber == 2)) { secondSessionFirstTrack = decodedToc.Value.TrackDescriptors.Where(t => t.SessionNumber == 2).Min(t => t.POINT); } } if (mediaType == MediaType.CD || mediaType == MediaType.CDROMXA) { bool hasDataTrack = false; bool hasAudioTrack = false; bool allFirstSessionTracksAreAudio = true; bool hasVideoTrack = false; if (decodedToc.HasValue) { foreach (FullTOC.TrackDataDescriptor track in decodedToc.Value.TrackDescriptors) { if (track.TNO == 1 && ((TocControl)(track.CONTROL & 0x0D) == TocControl.DataTrack || (TocControl)(track.CONTROL & 0x0D) == TocControl.DataTrackIncremental)) { allFirstSessionTracksAreAudio &= firstTrackLastSession != 1; } if ((TocControl)(track.CONTROL & 0x0D) == TocControl.DataTrack || (TocControl)(track.CONTROL & 0x0D) == TocControl.DataTrackIncremental) { uint startAddress = (uint)(((track.PHOUR * 3600 * 75) + (track.PMIN * 60 * 75) + (track.PSEC * 75) + track.PFRAME) - 150); if (startAddress < startOfFirstDataTrack) { startOfFirstDataTrack = startAddress; } hasDataTrack = true; allFirstSessionTracksAreAudio &= track.POINT >= firstTrackLastSession; } else { hasAudioTrack = true; } hasVideoTrack |= track.ADR == 4; } } if (hasDataTrack && hasAudioTrack && allFirstSessionTracksAreAudio && sessions == 2) { mediaType = MediaType.CDPLUS; } if (!hasDataTrack && hasAudioTrack && sessions == 1) { mediaType = MediaType.CDDA; } if (hasDataTrack && !hasAudioTrack && sessions == 1) { mediaType = MediaType.CDROM; } if (hasVideoTrack && !hasDataTrack && sessions == 1) { mediaType = MediaType.CDV; } } if (secondSessionFirstTrack != 0 && decodedToc.HasValue && decodedToc.Value.TrackDescriptors.Any(t => t.POINT == secondSessionFirstTrack)) { FullTOC.TrackDataDescriptor secondSessionFirstTrackTrack = decodedToc.Value.TrackDescriptors.First(t => t.POINT == secondSessionFirstTrack); uint firstSectorSecondSessionFirstTrack = (uint)(((secondSessionFirstTrackTrack.PHOUR * 3600 * 75) + (secondSessionFirstTrackTrack.PMIN * 60 * 75) + (secondSessionFirstTrackTrack.PSEC * 75) + secondSessionFirstTrackTrack.PFRAME) - 150); sense = dev.ReadCd(out cmdBuf, out _, firstSectorSecondSessionFirstTrack, 2352, 1, MmcSectorTypes.AllTypes, false, false, true, MmcHeaderCodes.AllHeaders, true, true, MmcErrorField.None, MmcSubchannel.None, dev.Timeout, out _); if (!sense && !dev.Error) { firstTrackSecondSession = cmdBuf; } else { sense = dev.ReadCd(out cmdBuf, out _, firstSectorSecondSessionFirstTrack, 2352, 1, MmcSectorTypes.Cdda, false, false, true, MmcHeaderCodes.None, true, true, MmcErrorField.None, MmcSubchannel.None, dev.Timeout, out _); if (!sense && !dev.Error) { firstTrackSecondSession = cmdBuf; } } sense = dev.ReadCd(out cmdBuf, out _, firstSectorSecondSessionFirstTrack - 1, 2352, 3, MmcSectorTypes.AllTypes, false, false, true, MmcHeaderCodes.AllHeaders, true, true, MmcErrorField.None, MmcSubchannel.None, dev.Timeout, out _); if (!sense && !dev.Error) { firstTrackSecondSessionAudio = cmdBuf; } else { sense = dev.ReadCd(out cmdBuf, out _, firstSectorSecondSessionFirstTrack - 1, 2352, 3, MmcSectorTypes.Cdda, false, false, true, MmcHeaderCodes.None, true, true, MmcErrorField.None, MmcSubchannel.None, dev.Timeout, out _); if (!sense && !dev.Error) { firstTrackSecondSessionAudio = cmdBuf; } } } videoNowColorFrame = new byte[9 * 2352]; for (int i = 0; i < 9; i++) { sense = dev.ReadCd(out cmdBuf, out _, (uint)i, 2352, 1, MmcSectorTypes.AllTypes, false, false, true, MmcHeaderCodes.AllHeaders, true, true, MmcErrorField.None, MmcSubchannel.None, dev.Timeout, out _); if (sense || dev.Error) { sense = dev.ReadCd(out cmdBuf, out _, (uint)i, 2352, 1, MmcSectorTypes.Cdda, false, false, true, MmcHeaderCodes.None, true, true, MmcErrorField.None, MmcSubchannel.None, dev.Timeout, out _); if (sense || !dev.Error) { videoNowColorFrame = null; break; } } Array.Copy(cmdBuf, 0, videoNowColorFrame, i * 2352, 2352); } if (decodedToc.HasValue) { FullTOC.TrackDataDescriptor firstTrack = decodedToc.Value.TrackDescriptors.FirstOrDefault(t => t.POINT == 1); if (firstTrack.POINT == 1) { uint firstTrackSector = (uint)(((firstTrack.PHOUR * 3600 * 75) + (firstTrack.PMIN * 60 * 75) + (firstTrack.PSEC * 75) + firstTrack.PFRAME) - 150); // Check for hidden data before start of track 1 if (firstTrackSector > 0) { sense = dev.ReadCd(out sector0, out _, 0, 2352, 1, MmcSectorTypes.AllTypes, false, false, true, MmcHeaderCodes.AllHeaders, true, true, MmcErrorField.None, MmcSubchannel.None, dev.Timeout, out _); if (!dev.Error && !sense) { hiddenTrack = true; hiddenData = IsData(sector0); if (hiddenData) { sense = dev.ReadCd(out byte[] sector16, out _, 16, 2352, 1, MmcSectorTypes.AllTypes, false, false, true, MmcHeaderCodes.AllHeaders, true, true, MmcErrorField.None, MmcSubchannel.None, dev.Timeout, out _); if (IsCdi(sector0, sector16)) { mediaType = MediaType.CDIREADY; } } } } } } sector0 = null; switch (mediaType) { case MediaType.CD: case MediaType.CDDA: case MediaType.CDPLUS: case MediaType.CDROM: case MediaType.CDROMXA: { sense = dev.ReadCd(out cmdBuf, out _, 0, 2352, 1, MmcSectorTypes.AllTypes, false, false, true, MmcHeaderCodes.AllHeaders, true, true, MmcErrorField.None, MmcSubchannel.None, dev.Timeout, out _); if (!sense && !dev.Error) { sector0 = new byte[2048]; Array.Copy(cmdBuf, 16, sector0, 0, 2048); sense = dev.ReadCd(out cmdBuf, out _, 1, 2352, 1, MmcSectorTypes.AllTypes, false, false, true, MmcHeaderCodes.AllHeaders, true, true, MmcErrorField.None, MmcSubchannel.None, dev.Timeout, out _); if (!sense && !dev.Error) { sector1 = new byte[2048]; Array.Copy(cmdBuf, 16, sector1, 0, 2048); } sense = dev.ReadCd(out cmdBuf, out _, 4200, 2352, 1, MmcSectorTypes.AllTypes, false, false, true, MmcHeaderCodes.AllHeaders, true, true, MmcErrorField.None, MmcSubchannel.None, dev.Timeout, out _); if (!sense && !dev.Error) { playdia1 = new byte[2048]; Array.Copy(cmdBuf, 24, playdia1, 0, 2048); } sense = dev.ReadCd(out cmdBuf, out _, 4201, 2352, 1, MmcSectorTypes.AllTypes, false, false, true, MmcHeaderCodes.AllHeaders, true, true, MmcErrorField.None, MmcSubchannel.None, dev.Timeout, out _); if (!sense && !dev.Error) { playdia2 = new byte[2048]; Array.Copy(cmdBuf, 24, playdia2, 0, 2048); } if (startOfFirstDataTrack != uint.MaxValue) { sense = dev.ReadCd(out cmdBuf, out _, startOfFirstDataTrack, 2352, 1, MmcSectorTypes.AllTypes, false, false, true, MmcHeaderCodes.AllHeaders, true, true, MmcErrorField.None, MmcSubchannel.None, dev.Timeout, out _); if (!sense && !dev.Error) { firstDataSectorNotZero = new byte[2048]; Array.Copy(cmdBuf, 16, firstDataSectorNotZero, 0, 2048); } sense = dev.ReadCd(out cmdBuf, out _, startOfFirstDataTrack + 1, 2352, 1, MmcSectorTypes.AllTypes, false, false, true, MmcHeaderCodes.AllHeaders, true, true, MmcErrorField.None, MmcSubchannel.None, dev.Timeout, out _); if (!sense && !dev.Error) { secondDataSectorNotZero = new byte[2048]; Array.Copy(cmdBuf, 16, secondDataSectorNotZero, 0, 2048); } } var ps2Ms = new MemoryStream(); for (uint p = 0; p < 12; p++) { sense = dev.ReadCd(out cmdBuf, out _, p, 2352, 1, MmcSectorTypes.AllTypes, false, false, true, MmcHeaderCodes.AllHeaders, true, true, MmcErrorField.None, MmcSubchannel.None, dev.Timeout, out _); if (sense || dev.Error) { break; } ps2Ms.Write(cmdBuf, cmdBuf[0x0F] == 0x02 ? 24 : 16, 2048); } if (ps2Ms.Length == 0x6000) { ps2BootSectors = ps2Ms.ToArray(); } } else { sense = dev.ReadCd(out cmdBuf, out _, 0, 2324, 1, MmcSectorTypes.Mode2, false, false, true, MmcHeaderCodes.None, true, true, MmcErrorField.None, MmcSubchannel.None, dev.Timeout, out _); if (!sense && !dev.Error) { sector0 = new byte[2048]; Array.Copy(cmdBuf, 0, sector0, 0, 2048); sense = dev.ReadCd(out cmdBuf, out _, 1, 2324, 1, MmcSectorTypes.Mode2, false, false, true, MmcHeaderCodes.None, true, true, MmcErrorField.None, MmcSubchannel.None, dev.Timeout, out _); if (!sense && !dev.Error) { sector1 = new byte[2048]; Array.Copy(cmdBuf, 1, sector0, 0, 2048); } sense = dev.ReadCd(out cmdBuf, out _, 4200, 2324, 1, MmcSectorTypes.Mode2, false, false, true, MmcHeaderCodes.None, true, true, MmcErrorField.None, MmcSubchannel.None, dev.Timeout, out _); if (!sense && !dev.Error) { playdia1 = new byte[2048]; Array.Copy(cmdBuf, 0, playdia1, 0, 2048); } sense = dev.ReadCd(out cmdBuf, out _, 4201, 2324, 1, MmcSectorTypes.Mode2, false, false, true, MmcHeaderCodes.None, true, true, MmcErrorField.None, MmcSubchannel.None, dev.Timeout, out _); if (!sense && !dev.Error) { playdia2 = new byte[2048]; Array.Copy(cmdBuf, 0, playdia2, 0, 2048); } if (startOfFirstDataTrack != uint.MaxValue) { sense = dev.ReadCd(out cmdBuf, out _, startOfFirstDataTrack, 2324, 1, MmcSectorTypes.Mode2, false, false, true, MmcHeaderCodes.None, true, true, MmcErrorField.None, MmcSubchannel.None, dev.Timeout, out _); if (!sense && !dev.Error) { firstDataSectorNotZero = new byte[2048]; Array.Copy(cmdBuf, 0, firstDataSectorNotZero, 0, 2048); } sense = dev.ReadCd(out cmdBuf, out _, startOfFirstDataTrack + 1, 2324, 1, MmcSectorTypes.Mode2, false, false, true, MmcHeaderCodes.None, true, true, MmcErrorField.None, MmcSubchannel.None, dev.Timeout, out _); if (!sense && !dev.Error) { secondDataSectorNotZero = new byte[2048]; Array.Copy(cmdBuf, 0, secondDataSectorNotZero, 0, 2048); } } var ps2Ms = new MemoryStream(); for (uint p = 0; p < 12; p++) { sense = dev.ReadCd(out cmdBuf, out _, p, 2324, 1, MmcSectorTypes.Mode2, false, false, true, MmcHeaderCodes.None, true, true, MmcErrorField.None, MmcSubchannel.None, dev.Timeout, out _); if (sense || dev.Error) { break; } ps2Ms.Write(cmdBuf, 0, 2048); } if (ps2Ms.Length == 0x6000) { ps2BootSectors = ps2Ms.ToArray(); } } else { sense = dev.ReadCd(out cmdBuf, out _, 0, 2048, 1, MmcSectorTypes.Mode1, false, false, true, MmcHeaderCodes.None, true, true, MmcErrorField.None, MmcSubchannel.None, dev.Timeout, out _); if (!sense && !dev.Error) { sector0 = cmdBuf; sense = dev.ReadCd(out cmdBuf, out _, 0, 2048, 1, MmcSectorTypes.Mode1, false, false, true, MmcHeaderCodes.None, true, true, MmcErrorField.None, MmcSubchannel.None, dev.Timeout, out _); if (!sense && !dev.Error) { sector1 = cmdBuf; } sense = dev.ReadCd(out cmdBuf, out _, 0, 2048, 12, MmcSectorTypes.Mode1, false, false, true, MmcHeaderCodes.None, true, true, MmcErrorField.None, MmcSubchannel.None, dev.Timeout, out _); if (!sense && !dev.Error) { ps2BootSectors = cmdBuf; } if (startOfFirstDataTrack != uint.MaxValue) { sense = dev.ReadCd(out cmdBuf, out _, startOfFirstDataTrack, 2048, 1, MmcSectorTypes.Mode1, false, false, true, MmcHeaderCodes.None, true, true, MmcErrorField.None, MmcSubchannel.None, dev.Timeout, out _); if (!sense && !dev.Error) { firstDataSectorNotZero = cmdBuf; } sense = dev.ReadCd(out cmdBuf, out _, startOfFirstDataTrack + 1, 2048, 1, MmcSectorTypes.Mode1, false, false, true, MmcHeaderCodes.None, true, true, MmcErrorField.None, MmcSubchannel.None, dev.Timeout, out _); if (!sense && !dev.Error) { secondDataSectorNotZero = cmdBuf; } } } else { goto case MediaType.DVDROM; } } } break; } // TODO: Check for CD-i Ready case MediaType.CDI: break; case MediaType.DVDROM: case MediaType.HDDVDROM: case MediaType.BDROM: case MediaType.Unknown: sense = dev.Read16(out cmdBuf, out _, 0, false, true, false, 0, 2048, 0, 1, false, dev.Timeout, out _); if (!sense && !dev.Error) { sector0 = cmdBuf; sense = dev.Read16(out cmdBuf, out _, 0, false, true, false, 1, 2048, 0, 1, false, dev.Timeout, out _); if (!sense && !dev.Error) { sector1 = cmdBuf; } sense = dev.Read16(out cmdBuf, out _, 0, false, true, false, 0, 2048, 0, 12, false, dev.Timeout, out _); if (!sense && !dev.Error && cmdBuf.Length == 0x6000) { ps2BootSectors = cmdBuf; } } else { sense = dev.Read12(out cmdBuf, out _, 0, false, true, false, false, 0, 2048, 0, 1, false, dev.Timeout, out _); if (!sense && !dev.Error) { sector0 = cmdBuf; sense = dev.Read12(out cmdBuf, out _, 0, false, true, false, false, 1, 2048, 0, 1, false, dev.Timeout, out _); if (!sense && !dev.Error) { sector1 = cmdBuf; } sense = dev.Read12(out cmdBuf, out _, 0, false, true, false, false, 0, 2048, 0, 12, false, dev.Timeout, out _); if (!sense && !dev.Error && cmdBuf.Length == 0x6000) { ps2BootSectors = cmdBuf; } } else { sense = dev.Read10(out cmdBuf, out _, 0, false, true, false, false, 0, 2048, 0, 1, dev.Timeout, out _); if (!sense && !dev.Error) { sector0 = cmdBuf; sense = dev.Read10(out cmdBuf, out _, 0, false, true, false, false, 1, 2048, 0, 1, dev.Timeout, out _); if (!sense && !dev.Error) { sector1 = cmdBuf; } sense = dev.Read10(out cmdBuf, out _, 0, false, true, false, false, 0, 2048, 0, 12, dev.Timeout, out _); if (!sense && !dev.Error && cmdBuf.Length == 0x6000) { ps2BootSectors = cmdBuf; } } else { sense = dev.Read6(out cmdBuf, out _, 0, 2048, 1, dev.Timeout, out _); if (!sense && !dev.Error) { sector0 = cmdBuf; sense = dev.Read6(out cmdBuf, out _, 1, 2048, 1, dev.Timeout, out _); if (!sense && !dev.Error) { sector1 = cmdBuf; } sense = dev.Read6(out cmdBuf, out _, 0, 2048, 12, dev.Timeout, out _); if (!sense && !dev.Error && cmdBuf.Length == 0x6000) { ps2BootSectors = cmdBuf; } } } } } break; // Recordables will not be checked case MediaType.CDR: case MediaType.CDRW: case MediaType.CDMRW: case MediaType.DDCDR: case MediaType.DDCDRW: case MediaType.DVDR: case MediaType.DVDRW: case MediaType.DVDPR: case MediaType.DVDPRW: case MediaType.DVDPRWDL: case MediaType.DVDRDL: case MediaType.DVDPRDL: case MediaType.DVDRAM: case MediaType.DVDRWDL: case MediaType.DVDDownload: case MediaType.HDDVDRAM: case MediaType.HDDVDR: case MediaType.HDDVDRW: case MediaType.HDDVDRDL: case MediaType.HDDVDRWDL: case MediaType.BDR: case MediaType.BDRE: case MediaType.BDRXL: case MediaType.BDREXL: return; } if (sector0 == null) { return; } switch (mediaType) { case MediaType.CD: case MediaType.CDDA: case MediaType.CDPLUS: case MediaType.CDROM: case MediaType.CDROMXA: // TODO: CDTV requires reading the filesystem, searching for a file called "/CDTV.TM" // TODO: CD32 requires reading the filesystem, searching for a file called "/CD32.TM" // TODO: Neo-Geo CD requires reading the filesystem and checking that the file "/IPL.TXT" is correct // TODO: Pippin requires interpreting Apple Partition Map, reading HFS and checking for Pippin signatures { if (CD.DecodeIPBin(sector0).HasValue) { mediaType = MediaType.MEGACD; return; } if (Saturn.DecodeIPBin(sector0).HasValue) { mediaType = MediaType.SATURNCD; } // Are GDR detectable ??? if (Dreamcast.DecodeIPBin(sector0).HasValue) { mediaType = MediaType.GDROM; } if (ps2BootSectors != null && ps2BootSectors.Length == 0x6000) { // The decryption key is applied as XOR. As first byte is originally always NULL, it gives us the key :) byte decryptByte = ps2BootSectors[0]; for (int i = 0; i < 0x6000; i++) { ps2BootSectors[i] ^= decryptByte; } string ps2BootSectorsHash = Sha256Context.Data(ps2BootSectors, out _); DicConsole.DebugWriteLine("Media-info Command", "PlayStation 2 boot sectors SHA256: {0}", ps2BootSectorsHash); if (ps2BootSectorsHash == PS2_PAL_HASH || ps2BootSectorsHash == PS2_NTSC_HASH || ps2BootSectorsHash == PS2_JAPANESE_HASH) { mediaType = MediaType.PS2CD; } } if (sector0 != null) { byte[] syncBytes = new byte[7]; Array.Copy(sector0, 0, syncBytes, 0, 7); if (_operaId.SequenceEqual(syncBytes)) { mediaType = MediaType.ThreeDO; } if (_fmTownsBootId.SequenceEqual(syncBytes)) { mediaType = MediaType.FMTOWNS; } } if (playdia1 != null && playdia2 != null) { byte[] pd1 = new byte[_playdiaCopyright.Length]; byte[] pd2 = new byte[_playdiaCopyright.Length]; Array.Copy(playdia1, 38, pd1, 0, pd1.Length); Array.Copy(playdia2, 0, pd2, 0, pd1.Length); if (_playdiaCopyright.SequenceEqual(pd1) && _playdiaCopyright.SequenceEqual(pd2)) { mediaType = MediaType.Playdia; } } if (secondDataSectorNotZero != null) { byte[] pce = new byte[_pcEngineSignature.Length]; Array.Copy(secondDataSectorNotZero, 32, pce, 0, pce.Length); if (_pcEngineSignature.SequenceEqual(pce)) { mediaType = MediaType.SuperCDROM2; } } if (firstDataSectorNotZero != null) { byte[] pcfx = new byte[_pcFxSignature.Length]; Array.Copy(firstDataSectorNotZero, 0, pcfx, 0, pcfx.Length); if (_pcFxSignature.SequenceEqual(pcfx)) { mediaType = MediaType.PCFX; } } if (firstTrackSecondSessionAudio != null) { byte[] jaguar = new byte[_atariSignature.Length]; for (int i = 0; i + jaguar.Length <= firstTrackSecondSessionAudio.Length; i += 2) { Array.Copy(firstTrackSecondSessionAudio, i, jaguar, 0, jaguar.Length); if (!_atariSignature.SequenceEqual(jaguar)) { continue; } mediaType = MediaType.JaguarCD; break; } } if (firstTrackSecondSession != null) { if (firstTrackSecondSession.Length >= 2336) { byte[] milcd = new byte[2048]; Array.Copy(firstTrackSecondSession, 24, milcd, 0, 2048); if (Dreamcast.DecodeIPBin(milcd).HasValue) { mediaType = MediaType.MilCD; } } } // TODO: Detect black and white VideoNow // TODO: Detect VideoNow XP if (IsVideoNowColor(videoNowColorFrame)) { mediaType = MediaType.VideoNowColor; } break; } // TODO: Check for CD-i Ready case MediaType.CDI: break; case MediaType.DVDROM: case MediaType.HDDVDROM: case MediaType.BDROM: case MediaType.Unknown: // TODO: Nuon requires reading the filesystem, searching for a file called "/NUON/NUON.RUN" if (ps2BootSectors != null && ps2BootSectors.Length == 0x6000) { // The decryption key is applied as XOR. As first byte is originally always NULL, it gives us the key :) byte decryptByte = ps2BootSectors[0]; for (int i = 0; i < 0x6000; i++) { ps2BootSectors[i] ^= decryptByte; } string ps2BootSectorsHash = Sha256Context.Data(ps2BootSectors, out _); DicConsole.DebugWriteLine("Media-info Command", "PlayStation 2 boot sectors SHA256: {0}", ps2BootSectorsHash); if (ps2BootSectorsHash == PS2_PAL_HASH || ps2BootSectorsHash == PS2_NTSC_HASH || ps2BootSectorsHash == PS2_JAPANESE_HASH) { mediaType = MediaType.PS2DVD; } } if (sector1 != null) { byte[] tmp = new byte[_ps3Id.Length]; Array.Copy(sector1, 0, tmp, 0, tmp.Length); if (tmp.SequenceEqual(_ps3Id)) { switch (mediaType) { case MediaType.BDROM: mediaType = MediaType.PS3BD; break; case MediaType.DVDROM: mediaType = MediaType.PS3DVD; break; } } tmp = new byte[_ps4Id.Length]; Array.Copy(sector1, 512, tmp, 0, tmp.Length); if (tmp.SequenceEqual(_ps4Id) && mediaType == MediaType.BDROM) { mediaType = MediaType.PS4BD; } } // TODO: Identify discs that require reading tracks (PC-FX, PlayStation, Sega, etc) break; } }