🐛Move checksum initializers to instance constructors.

This commit is contained in:
2018-02-03 17:39:49 +00:00
parent 4b4671b4ef
commit b50b6c29ca
61 changed files with 1429 additions and 1599 deletions

View File

@@ -42,12 +42,12 @@ namespace DiscImageChef.Checksums
public class Adler32Context : IChecksum public class Adler32Context : IChecksum
{ {
const ushort ADLER_MODULE = 65521; const ushort ADLER_MODULE = 65521;
ushort sum1, sum2; ushort sum1, sum2;
/// <summary> /// <summary>
/// Initializes the Adler-32 sums /// Initializes the Adler-32 sums
/// </summary> /// </summary>
public void Init() public Adler32Context()
{ {
sum1 = 1; sum1 = 1;
sum2 = 0; sum2 = 0;
@@ -63,7 +63,7 @@ namespace DiscImageChef.Checksums
for(int i = 0; i < len; i++) for(int i = 0; i < len; i++)
{ {
sum1 = (ushort)((sum1 + data[i]) % ADLER_MODULE); sum1 = (ushort)((sum1 + data[i]) % ADLER_MODULE);
sum2 = (ushort)((sum2 + sum1) % ADLER_MODULE); sum2 = (ushort)((sum2 + sum1) % ADLER_MODULE);
} }
} }
@@ -81,7 +81,7 @@ namespace DiscImageChef.Checksums
/// </summary> /// </summary>
public byte[] Final() public byte[] Final()
{ {
uint finalSum = (uint)((sum2 << 16) | sum1); uint finalSum = (uint)((sum2 << 16) | sum1);
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
return BigEndianBitConverter.GetBytes(finalSum); return BigEndianBitConverter.GetBytes(finalSum);
} }
@@ -91,7 +91,7 @@ namespace DiscImageChef.Checksums
/// </summary> /// </summary>
public string End() public string End()
{ {
uint finalSum = (uint)((sum2 << 16) | sum1); uint finalSum = (uint)((sum2 << 16) | sum1);
StringBuilder adlerOutput = new StringBuilder(); StringBuilder adlerOutput = new StringBuilder();
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
@@ -119,8 +119,8 @@ namespace DiscImageChef.Checksums
public static string File(string filename, out byte[] hash) public static string File(string filename, out byte[] hash)
{ {
FileStream fileStream = new FileStream(filename, FileMode.Open); FileStream fileStream = new FileStream(filename, FileMode.Open);
ushort localSum1, localSum2; ushort localSum1, localSum2;
uint finalSum; uint finalSum;
localSum1 = 1; localSum1 = 1;
localSum2 = 0; localSum2 = 0;
@@ -128,13 +128,13 @@ namespace DiscImageChef.Checksums
for(int i = 0; i < fileStream.Length; i++) for(int i = 0; i < fileStream.Length; i++)
{ {
localSum1 = (ushort)((localSum1 + fileStream.ReadByte()) % ADLER_MODULE); localSum1 = (ushort)((localSum1 + fileStream.ReadByte()) % ADLER_MODULE);
localSum2 = (ushort)((localSum2 + localSum1) % ADLER_MODULE); localSum2 = (ushort)((localSum2 + localSum1) % ADLER_MODULE);
} }
finalSum = (uint)((localSum2 << 16) | localSum1); finalSum = (uint)((localSum2 << 16) | localSum1);
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
hash = BigEndianBitConverter.GetBytes(finalSum); hash = BigEndianBitConverter.GetBytes(finalSum);
StringBuilder adlerOutput = new StringBuilder(); StringBuilder adlerOutput = new StringBuilder();
@@ -154,21 +154,21 @@ namespace DiscImageChef.Checksums
public static string Data(byte[] data, uint len, out byte[] hash) public static string Data(byte[] data, uint len, out byte[] hash)
{ {
ushort localSum1, localSum2; ushort localSum1, localSum2;
uint finalSum; uint finalSum;
localSum1 = 1; localSum1 = 1;
localSum2 = 0; localSum2 = 0;
for(int i = 0; i < len; i++) for(int i = 0; i < len; i++)
{ {
localSum1 = (ushort)((localSum1 + data[i]) % ADLER_MODULE); localSum1 = (ushort)((localSum1 + data[i]) % ADLER_MODULE);
localSum2 = (ushort)((localSum2 + localSum1) % ADLER_MODULE); localSum2 = (ushort)((localSum2 + localSum1) % ADLER_MODULE);
} }
finalSum = (uint)((localSum2 << 16) | localSum1); finalSum = (uint)((localSum2 << 16) | localSum1);
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
hash = BigEndianBitConverter.GetBytes(finalSum); hash = BigEndianBitConverter.GetBytes(finalSum);
StringBuilder adlerOutput = new StringBuilder(); StringBuilder adlerOutput = new StringBuilder();

View File

@@ -43,14 +43,14 @@ namespace DiscImageChef.Checksums
{ {
const ushort CRC16_POLY = 0xA001; const ushort CRC16_POLY = 0xA001;
const ushort CRC16_SEED = 0x0000; const ushort CRC16_SEED = 0x0000;
ushort hashInt;
ushort[] table; readonly ushort[] table;
ushort hashInt;
/// <summary> /// <summary>
/// Initializes the CRC16 table and seed /// Initializes the CRC16 table and seed
/// </summary> /// </summary>
public void Init() public Crc16Context()
{ {
hashInt = CRC16_SEED; hashInt = CRC16_SEED;
@@ -58,9 +58,11 @@ namespace DiscImageChef.Checksums
for(int i = 0; i < 256; i++) for(int i = 0; i < 256; i++)
{ {
ushort entry = (ushort)i; ushort entry = (ushort)i;
for(int j = 0; j < 8; j++) for(int j = 0; j < 8; j++)
if((entry & 1) == 1) entry = (ushort)((entry >> 1) ^ CRC16_POLY); if((entry & 1) == 1)
else entry = (ushort)(entry >> 1); entry = (ushort)((entry >> 1) ^ CRC16_POLY);
else
entry = (ushort)(entry >> 1);
table[i] = entry; table[i] = entry;
} }
@@ -102,7 +104,7 @@ namespace DiscImageChef.Checksums
StringBuilder crc16Output = new StringBuilder(); StringBuilder crc16Output = new StringBuilder();
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
for(int i = 0; i < BigEndianBitConverter.GetBytes(hashInt ^ CRC16_SEED).Length; i++) for(int i = 0; i < BigEndianBitConverter.GetBytes(hashInt ^ CRC16_SEED).Length; i++)
crc16Output.Append(BigEndianBitConverter.GetBytes(hashInt ^ CRC16_SEED)[i].ToString("x2")); crc16Output.Append(BigEndianBitConverter.GetBytes(hashInt ^ CRC16_SEED)[i].ToString("x2"));
return crc16Output.ToString(); return crc16Output.ToString();
@@ -126,7 +128,7 @@ namespace DiscImageChef.Checksums
public static string File(string filename, out byte[] hash) public static string File(string filename, out byte[] hash)
{ {
FileStream fileStream = new FileStream(filename, FileMode.Open); FileStream fileStream = new FileStream(filename, FileMode.Open);
ushort localhashInt; ushort localhashInt;
localhashInt = CRC16_SEED; localhashInt = CRC16_SEED;
@@ -134,9 +136,11 @@ namespace DiscImageChef.Checksums
for(int i = 0; i < 256; i++) for(int i = 0; i < 256; i++)
{ {
ushort entry = (ushort)i; ushort entry = (ushort)i;
for(int j = 0; j < 8; j++) for(int j = 0; j < 8; j++)
if((entry & 1) == 1) entry = (ushort)((entry >> 1) ^ CRC16_POLY); if((entry & 1) == 1)
else entry = (ushort)(entry >> 1); entry = (ushort)((entry >> 1) ^ CRC16_POLY);
else
entry = (ushort)(entry >> 1);
localTable[i] = entry; localTable[i] = entry;
} }
@@ -146,7 +150,7 @@ namespace DiscImageChef.Checksums
(ushort)((localhashInt >> 8) ^ localTable[fileStream.ReadByte() ^ (localhashInt & 0xff)]); (ushort)((localhashInt >> 8) ^ localTable[fileStream.ReadByte() ^ (localhashInt & 0xff)]);
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
hash = BigEndianBitConverter.GetBytes(localhashInt); hash = BigEndianBitConverter.GetBytes(localhashInt);
StringBuilder crc16Output = new StringBuilder(); StringBuilder crc16Output = new StringBuilder();
@@ -186,9 +190,11 @@ namespace DiscImageChef.Checksums
for(int i = 0; i < 256; i++) for(int i = 0; i < 256; i++)
{ {
ushort entry = (ushort)i; ushort entry = (ushort)i;
for(int j = 0; j < 8; j++) for(int j = 0; j < 8; j++)
if((entry & 1) == 1) entry = (ushort)((entry >> 1) ^ polynomial); if((entry & 1) == 1)
else entry = (ushort)(entry >> 1); entry = (ushort)((entry >> 1) ^ polynomial);
else
entry = (ushort)(entry >> 1);
localTable[i] = entry; localTable[i] = entry;
} }
@@ -197,7 +203,7 @@ namespace DiscImageChef.Checksums
localhashInt = (ushort)((localhashInt >> 8) ^ localTable[data[i] ^ (localhashInt & 0xff)]); localhashInt = (ushort)((localhashInt >> 8) ^ localTable[data[i] ^ (localhashInt & 0xff)]);
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
hash = BigEndianBitConverter.GetBytes(localhashInt); hash = BigEndianBitConverter.GetBytes(localhashInt);
StringBuilder crc16Output = new StringBuilder(); StringBuilder crc16Output = new StringBuilder();

View File

@@ -43,14 +43,14 @@ namespace DiscImageChef.Checksums
{ {
const uint CRC32_POLY = 0xEDB88320; const uint CRC32_POLY = 0xEDB88320;
const uint CRC32_SEED = 0xFFFFFFFF; const uint CRC32_SEED = 0xFFFFFFFF;
uint hashInt;
uint[] table; readonly uint[] table;
uint hashInt;
/// <summary> /// <summary>
/// Initializes the CRC32 table and seed /// Initializes the CRC32 table and seed
/// </summary> /// </summary>
public void Init() public Crc32Context()
{ {
hashInt = CRC32_SEED; hashInt = CRC32_SEED;
@@ -58,9 +58,11 @@ namespace DiscImageChef.Checksums
for(int i = 0; i < 256; i++) for(int i = 0; i < 256; i++)
{ {
uint entry = (uint)i; uint entry = (uint)i;
for(int j = 0; j < 8; j++) for(int j = 0; j < 8; j++)
if((entry & 1) == 1) entry = (entry >> 1) ^ CRC32_POLY; if((entry & 1) == 1)
else entry = entry >> 1; entry = (entry >> 1) ^ CRC32_POLY;
else
entry = entry >> 1;
table[i] = entry; table[i] = entry;
} }
@@ -102,7 +104,7 @@ namespace DiscImageChef.Checksums
StringBuilder crc32Output = new StringBuilder(); StringBuilder crc32Output = new StringBuilder();
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
for(int i = 0; i < BigEndianBitConverter.GetBytes(hashInt ^ CRC32_SEED).Length; i++) for(int i = 0; i < BigEndianBitConverter.GetBytes(hashInt ^ CRC32_SEED).Length; i++)
crc32Output.Append(BigEndianBitConverter.GetBytes(hashInt ^ CRC32_SEED)[i].ToString("x2")); crc32Output.Append(BigEndianBitConverter.GetBytes(hashInt ^ CRC32_SEED)[i].ToString("x2"));
return crc32Output.ToString(); return crc32Output.ToString();
@@ -126,7 +128,7 @@ namespace DiscImageChef.Checksums
public static string File(string filename, out byte[] hash) public static string File(string filename, out byte[] hash)
{ {
FileStream fileStream = new FileStream(filename, FileMode.Open); FileStream fileStream = new FileStream(filename, FileMode.Open);
uint localhashInt; uint localhashInt;
localhashInt = CRC32_SEED; localhashInt = CRC32_SEED;
@@ -134,25 +136,27 @@ namespace DiscImageChef.Checksums
for(int i = 0; i < 256; i++) for(int i = 0; i < 256; i++)
{ {
uint entry = (uint)i; uint entry = (uint)i;
for(int j = 0; j < 8; j++) for(int j = 0; j < 8; j++)
if((entry & 1) == 1) entry = (entry >> 1) ^ CRC32_POLY; if((entry & 1) == 1)
else entry = entry >> 1; entry = (entry >> 1) ^ CRC32_POLY;
else
entry = entry >> 1;
localTable[i] = entry; localTable[i] = entry;
} }
for(int i = 0; i < fileStream.Length; i++) for(int i = 0; i < fileStream.Length; i++)
{ {
localhashInt = (localhashInt >> 8) ^ localTable[fileStream.ReadByte() ^ (localhashInt & 0xff)]; localhashInt = (localhashInt >> 8) ^
if((localhashInt ^ CRC32_SEED) == 0xB883C628 || (localhashInt ^CRC32_SEED) == 0x28C683B8) localTable[fileStream.ReadByte() ^ (localhashInt & 0xff)];
{ if((localhashInt ^ CRC32_SEED) == 0xB883C628 ||
(localhashInt ^ CRC32_SEED) == 0x28C683B8)
System.Console.WriteLine("CRC found at position {0}", fileStream.Position); System.Console.WriteLine("CRC found at position {0}", fileStream.Position);
}
} }
localhashInt ^= CRC32_SEED; localhashInt ^= CRC32_SEED;
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
hash = BigEndianBitConverter.GetBytes(localhashInt); hash = BigEndianBitConverter.GetBytes(localhashInt);
StringBuilder crc32Output = new StringBuilder(); StringBuilder crc32Output = new StringBuilder();
@@ -192,9 +196,11 @@ namespace DiscImageChef.Checksums
for(int i = 0; i < 256; i++) for(int i = 0; i < 256; i++)
{ {
uint entry = (uint)i; uint entry = (uint)i;
for(int j = 0; j < 8; j++) for(int j = 0; j < 8; j++)
if((entry & 1) == 1) entry = (entry >> 1) ^ polynomial; if((entry & 1) == 1)
else entry = entry >> 1; entry = (entry >> 1) ^ polynomial;
else
entry = entry >> 1;
localTable[i] = entry; localTable[i] = entry;
} }
@@ -202,9 +208,9 @@ namespace DiscImageChef.Checksums
for(int i = 0; i < len; i++) for(int i = 0; i < len; i++)
localhashInt = (localhashInt >> 8) ^ localTable[data[i] ^ (localhashInt & 0xff)]; localhashInt = (localhashInt >> 8) ^ localTable[data[i] ^ (localhashInt & 0xff)];
localhashInt ^= CRC32_SEED; localhashInt ^= CRC32_SEED;
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
hash = BigEndianBitConverter.GetBytes(localhashInt); hash = BigEndianBitConverter.GetBytes(localhashInt);
StringBuilder crc32Output = new StringBuilder(); StringBuilder crc32Output = new StringBuilder();

View File

@@ -43,14 +43,14 @@ namespace DiscImageChef.Checksums
{ {
const ulong CRC64_POLY = 0xC96C5795D7870F42; const ulong CRC64_POLY = 0xC96C5795D7870F42;
const ulong CRC64_SEED = 0xFFFFFFFFFFFFFFFF; const ulong CRC64_SEED = 0xFFFFFFFFFFFFFFFF;
ulong hashInt;
ulong[] table; readonly ulong[] table;
ulong hashInt;
/// <summary> /// <summary>
/// Initializes the CRC64 table and seed /// Initializes the CRC64 table and seed
/// </summary> /// </summary>
public void Init() public Crc64Context()
{ {
hashInt = CRC64_SEED; hashInt = CRC64_SEED;
@@ -58,9 +58,11 @@ namespace DiscImageChef.Checksums
for(int i = 0; i < 256; i++) for(int i = 0; i < 256; i++)
{ {
ulong entry = (ulong)i; ulong entry = (ulong)i;
for(int j = 0; j < 8; j++) for(int j = 0; j < 8; j++)
if((entry & 1) == 1) entry = (entry >> 1) ^ CRC64_POLY; if((entry & 1) == 1)
else entry = entry >> 1; entry = (entry >> 1) ^ CRC64_POLY;
else
entry = entry >> 1;
table[i] = entry; table[i] = entry;
} }
@@ -126,7 +128,7 @@ namespace DiscImageChef.Checksums
public static string File(string filename, out byte[] hash) public static string File(string filename, out byte[] hash)
{ {
FileStream fileStream = new FileStream(filename, FileMode.Open); FileStream fileStream = new FileStream(filename, FileMode.Open);
ulong localhashInt; ulong localhashInt;
localhashInt = CRC64_SEED; localhashInt = CRC64_SEED;
@@ -134,9 +136,11 @@ namespace DiscImageChef.Checksums
for(int i = 0; i < 256; i++) for(int i = 0; i < 256; i++)
{ {
ulong entry = (ulong)i; ulong entry = (ulong)i;
for(int j = 0; j < 8; j++) for(int j = 0; j < 8; j++)
if((entry & 1) == 1) entry = (entry >> 1) ^ CRC64_POLY; if((entry & 1) == 1)
else entry = entry >> 1; entry = (entry >> 1) ^ CRC64_POLY;
else
entry = entry >> 1;
localTable[i] = entry; localTable[i] = entry;
} }
@@ -144,9 +148,9 @@ namespace DiscImageChef.Checksums
for(int i = 0; i < fileStream.Length; i++) for(int i = 0; i < fileStream.Length; i++)
localhashInt = (localhashInt >> 8) ^ localTable[(ulong)fileStream.ReadByte() ^ (localhashInt & 0xffL)]; localhashInt = (localhashInt >> 8) ^ localTable[(ulong)fileStream.ReadByte() ^ (localhashInt & 0xffL)];
localhashInt ^= CRC64_SEED; localhashInt ^= CRC64_SEED;
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
hash = BigEndianBitConverter.GetBytes(localhashInt); hash = BigEndianBitConverter.GetBytes(localhashInt);
StringBuilder crc64Output = new StringBuilder(); StringBuilder crc64Output = new StringBuilder();
@@ -186,9 +190,11 @@ namespace DiscImageChef.Checksums
for(int i = 0; i < 256; i++) for(int i = 0; i < 256; i++)
{ {
ulong entry = (ulong)i; ulong entry = (ulong)i;
for(int j = 0; j < 8; j++) for(int j = 0; j < 8; j++)
if((entry & 1) == 1) entry = (entry >> 1) ^ polynomial; if((entry & 1) == 1)
else entry = entry >> 1; entry = (entry >> 1) ^ polynomial;
else
entry = entry >> 1;
localTable[i] = entry; localTable[i] = entry;
} }
@@ -196,9 +202,9 @@ namespace DiscImageChef.Checksums
for(int i = 0; i < len; i++) for(int i = 0; i < len; i++)
localhashInt = (localhashInt >> 8) ^ localTable[data[i] ^ (localhashInt & 0xff)]; localhashInt = (localhashInt >> 8) ^ localTable[data[i] ^ (localhashInt & 0xff)];
localhashInt ^= CRC64_SEED; localhashInt ^= CRC64_SEED;
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
hash = BigEndianBitConverter.GetBytes(localhashInt); hash = BigEndianBitConverter.GetBytes(localhashInt);
StringBuilder crc64Output = new StringBuilder(); StringBuilder crc64Output = new StringBuilder();

View File

@@ -40,19 +40,19 @@ namespace DiscImageChef.Checksums
{ {
public class Fletcher32Context : IChecksum public class Fletcher32Context : IChecksum
{ {
bool inodd; bool inodd;
byte oddValue; byte oddValue;
ushort sum1, sum2; ushort sum1, sum2;
/// <summary> /// <summary>
/// Initializes the Fletcher32 sums /// Initializes the Fletcher32 sums
/// </summary> /// </summary>
public void Init() public Fletcher32Context()
{ {
sum1 = 0xFFFF; sum1 = 0xFFFF;
sum2 = 0xFFFF; sum2 = 0xFFFF;
oddValue = 0; oddValue = 0;
inodd = false; inodd = false;
} }
/// <summary> /// <summary>
@@ -67,13 +67,13 @@ namespace DiscImageChef.Checksums
if(len % 2 != 0) if(len % 2 != 0)
{ {
oddValue = data[len - 1]; oddValue = data[len - 1];
inodd = true; inodd = true;
for(int i = 0; i < len - 1; i += 2) for(int i = 0; i < len - 1; i += 2)
{ {
block = BigEndianBitConverter.ToUInt16(data, i); block = BigEndianBitConverter.ToUInt16(data, i);
sum1 = (ushort)((sum1 + block) % 0xFFFF); sum1 = (ushort)((sum1 + block) % 0xFFFF);
sum2 = (ushort)((sum2 + sum1) % 0xFFFF); sum2 = (ushort)((sum2 + sum1) % 0xFFFF);
} }
} }
else else
@@ -82,32 +82,32 @@ namespace DiscImageChef.Checksums
for(int i = 0; i < len; i += 2) for(int i = 0; i < len; i += 2)
{ {
block = BigEndianBitConverter.ToUInt16(data, i); block = BigEndianBitConverter.ToUInt16(data, i);
sum1 = (ushort)((sum1 + block) % 0xFFFF); sum1 = (ushort)((sum1 + block) % 0xFFFF);
sum2 = (ushort)((sum2 + sum1) % 0xFFFF); sum2 = (ushort)((sum2 + sum1) % 0xFFFF);
} }
} }
// Carrying odd // Carrying odd
else else
{ {
byte[] oddData = new byte[2]; byte[] oddData = new byte[2];
oddData[0] = oddValue; oddData[0] = oddValue;
oddData[1] = data[0]; oddData[1] = data[0];
block = BigEndianBitConverter.ToUInt16(oddData, 0); block = BigEndianBitConverter.ToUInt16(oddData, 0);
sum1 = (ushort)((sum1 + block) % 0xFFFF); sum1 = (ushort)((sum1 + block) % 0xFFFF);
sum2 = (ushort)((sum2 + sum1) % 0xFFFF); sum2 = (ushort)((sum2 + sum1) % 0xFFFF);
// Even size, carrying odd // Even size, carrying odd
if(len % 2 == 0) if(len % 2 == 0)
{ {
oddValue = data[len - 1]; oddValue = data[len - 1];
inodd = true; inodd = true;
for(int i = 1; i < len - 1; i += 2) for(int i = 1; i < len - 1; i += 2)
{ {
block = BigEndianBitConverter.ToUInt16(data, i); block = BigEndianBitConverter.ToUInt16(data, i);
sum1 = (ushort)((sum1 + block) % 0xFFFF); sum1 = (ushort)((sum1 + block) % 0xFFFF);
sum2 = (ushort)((sum2 + sum1) % 0xFFFF); sum2 = (ushort)((sum2 + sum1) % 0xFFFF);
} }
} }
else else
@@ -116,8 +116,8 @@ namespace DiscImageChef.Checksums
for(int i = 1; i < len; i += 2) for(int i = 1; i < len; i += 2)
{ {
block = BigEndianBitConverter.ToUInt16(data, i); block = BigEndianBitConverter.ToUInt16(data, i);
sum1 = (ushort)((sum1 + block) % 0xFFFF); sum1 = (ushort)((sum1 + block) % 0xFFFF);
sum2 = (ushort)((sum2 + sum1) % 0xFFFF); sum2 = (ushort)((sum2 + sum1) % 0xFFFF);
} }
} }
} }
@@ -146,7 +146,7 @@ namespace DiscImageChef.Checksums
/// </summary> /// </summary>
public string End() public string End()
{ {
uint finalSum = (uint)(sum1 + (sum2 << 16)); uint finalSum = (uint)(sum1 + (sum2 << 16));
StringBuilder fletcherOutput = new StringBuilder(); StringBuilder fletcherOutput = new StringBuilder();
for(int i = 0; i < BigEndianBitConverter.GetBytes(finalSum).Length; i++) for(int i = 0; i < BigEndianBitConverter.GetBytes(finalSum).Length; i++)
@@ -173,20 +173,20 @@ namespace DiscImageChef.Checksums
public static string File(string filename, out byte[] hash) public static string File(string filename, out byte[] hash)
{ {
FileStream fileStream = new FileStream(filename, FileMode.Open); FileStream fileStream = new FileStream(filename, FileMode.Open);
ushort localSum1, localSum2, block; ushort localSum1, localSum2, block;
uint finalSum; uint finalSum;
byte[] blockBytes; byte[] blockBytes;
localSum1 = 0xFFFF; localSum1 = 0xFFFF;
localSum2 = 0xFFFF; localSum2 = 0xFFFF;
if(fileStream.Length % 2 == 0) if(fileStream.Length % 2 == 0)
for(int i = 0; i < fileStream.Length; i += 2) for(int i = 0; i < fileStream.Length; i += 2)
{ {
blockBytes = new byte[2]; blockBytes = new byte[2];
fileStream.Read(blockBytes, 0, 2); fileStream.Read(blockBytes, 0, 2);
block = BigEndianBitConverter.ToUInt16(blockBytes, 0); block = BigEndianBitConverter.ToUInt16(blockBytes, 0);
localSum1 = (ushort)((localSum1 + block) % 0xFFFF); localSum1 = (ushort)((localSum1 + block) % 0xFFFF);
localSum2 = (ushort)((localSum2 + localSum1) % 0xFFFF); localSum2 = (ushort)((localSum2 + localSum1) % 0xFFFF);
} }
else else
@@ -195,17 +195,17 @@ namespace DiscImageChef.Checksums
{ {
blockBytes = new byte[2]; blockBytes = new byte[2];
fileStream.Read(blockBytes, 0, 2); fileStream.Read(blockBytes, 0, 2);
block = BigEndianBitConverter.ToUInt16(blockBytes, 0); block = BigEndianBitConverter.ToUInt16(blockBytes, 0);
localSum1 = (ushort)((localSum1 + block) % 0xFFFF); localSum1 = (ushort)((localSum1 + block) % 0xFFFF);
localSum2 = (ushort)((localSum2 + localSum1) % 0xFFFF); localSum2 = (ushort)((localSum2 + localSum1) % 0xFFFF);
} }
byte[] oddData = new byte[2]; byte[] oddData = new byte[2];
oddData[0] = (byte)fileStream.ReadByte(); oddData[0] = (byte)fileStream.ReadByte();
oddData[1] = 0; oddData[1] = 0;
block = BigEndianBitConverter.ToUInt16(oddData, 0); block = BigEndianBitConverter.ToUInt16(oddData, 0);
localSum1 = (ushort)((localSum1 + block) % 0xFFFF); localSum1 = (ushort)((localSum1 + block) % 0xFFFF);
localSum2 = (ushort)((localSum2 + localSum1) % 0xFFFF); localSum2 = (ushort)((localSum2 + localSum1) % 0xFFFF);
} }
@@ -229,33 +229,33 @@ namespace DiscImageChef.Checksums
public static string Data(byte[] data, uint len, out byte[] hash) public static string Data(byte[] data, uint len, out byte[] hash)
{ {
ushort localSum1, localSum2, block; ushort localSum1, localSum2, block;
uint finalSum; uint finalSum;
localSum1 = 0xFFFF; localSum1 = 0xFFFF;
localSum2 = 0xFFFF; localSum2 = 0xFFFF;
if(len % 2 == 0) if(len % 2 == 0)
for(int i = 0; i < len; i += 2) for(int i = 0; i < len; i += 2)
{ {
block = BigEndianBitConverter.ToUInt16(data, i); block = BigEndianBitConverter.ToUInt16(data, i);
localSum1 = (ushort)((localSum1 + block) % 0xFFFF); localSum1 = (ushort)((localSum1 + block) % 0xFFFF);
localSum2 = (ushort)((localSum2 + localSum1) % 0xFFFF); localSum2 = (ushort)((localSum2 + localSum1) % 0xFFFF);
} }
else else
{ {
for(int i = 0; i < len - 1; i += 2) for(int i = 0; i < len - 1; i += 2)
{ {
block = BigEndianBitConverter.ToUInt16(data, i); block = BigEndianBitConverter.ToUInt16(data, i);
localSum1 = (ushort)((localSum1 + block) % 0xFFFF); localSum1 = (ushort)((localSum1 + block) % 0xFFFF);
localSum2 = (ushort)((localSum2 + localSum1) % 0xFFFF); localSum2 = (ushort)((localSum2 + localSum1) % 0xFFFF);
} }
byte[] oddData = new byte[2]; byte[] oddData = new byte[2];
oddData[0] = data[len - 1]; oddData[0] = data[len - 1];
oddData[1] = 0; oddData[1] = 0;
block = BigEndianBitConverter.ToUInt16(oddData, 0); block = BigEndianBitConverter.ToUInt16(oddData, 0);
localSum1 = (ushort)((localSum1 + block) % 0xFFFF); localSum1 = (ushort)((localSum1 + block) % 0xFFFF);
localSum2 = (ushort)((localSum2 + localSum1) % 0xFFFF); localSum2 = (ushort)((localSum2 + localSum1) % 0xFFFF);
} }
@@ -304,7 +304,7 @@ namespace DiscImageChef.Checksums
for(int i = 0; i < len; i++) for(int i = 0; i < len; i++)
{ {
sum1 = (byte)((sum1 + data[i]) % 0xFF); sum1 = (byte)((sum1 + data[i]) % 0xFF);
sum2 = (byte)((sum2 + sum1) % 0xFF); sum2 = (byte)((sum2 + sum1) % 0xFF);
} }
} }
@@ -331,7 +331,7 @@ namespace DiscImageChef.Checksums
/// </summary> /// </summary>
public string End() public string End()
{ {
ushort finalSum = (ushort)(sum1 + (sum2 << 8)); ushort finalSum = (ushort)(sum1 + (sum2 << 8));
StringBuilder fletcherOutput = new StringBuilder(); StringBuilder fletcherOutput = new StringBuilder();
for(int i = 0; i < BigEndianBitConverter.GetBytes(finalSum).Length; i++) for(int i = 0; i < BigEndianBitConverter.GetBytes(finalSum).Length; i++)
@@ -358,16 +358,16 @@ namespace DiscImageChef.Checksums
public static string File(string filename, out byte[] hash) public static string File(string filename, out byte[] hash)
{ {
FileStream fileStream = new FileStream(filename, FileMode.Open); FileStream fileStream = new FileStream(filename, FileMode.Open);
byte localSum1, localSum2, block; byte localSum1, localSum2, block;
ushort finalSum; ushort finalSum;
localSum1 = 0xFF; localSum1 = 0xFF;
localSum2 = 0xFF; localSum2 = 0xFF;
for(int i = 0; i < fileStream.Length; i += 2) for(int i = 0; i < fileStream.Length; i += 2)
{ {
block = (byte)fileStream.ReadByte(); block = (byte)fileStream.ReadByte();
localSum1 = (byte)((localSum1 + block) % 0xFF); localSum1 = (byte)((localSum1 + block) % 0xFF);
localSum2 = (byte)((localSum2 + localSum1) % 0xFF); localSum2 = (byte)((localSum2 + localSum1) % 0xFF);
} }
@@ -390,7 +390,7 @@ namespace DiscImageChef.Checksums
/// <param name="hash">Byte array of the hash value.</param> /// <param name="hash">Byte array of the hash value.</param>
public static string Data(byte[] data, uint len, out byte[] hash) public static string Data(byte[] data, uint len, out byte[] hash)
{ {
byte localSum1, localSum2; byte localSum1, localSum2;
ushort finalSum; ushort finalSum;
localSum1 = 0xFF; localSum1 = 0xFF;
@@ -398,7 +398,7 @@ namespace DiscImageChef.Checksums
for(int i = 0; i < len; i++) for(int i = 0; i < len; i++)
{ {
localSum1 = (byte)((localSum1 + data[i]) % 0xFF); localSum1 = (byte)((localSum1 + data[i]) % 0xFF);
localSum2 = (byte)((localSum2 + localSum1) % 0xFF); localSum2 = (byte)((localSum2 + localSum1) % 0xFF);
} }

View File

@@ -34,11 +34,6 @@ namespace DiscImageChef.Checksums
{ {
public interface IChecksum public interface IChecksum
{ {
/// <summary>
/// Initializes the algorithm
/// </summary>
void Init();
/// <summary> /// <summary>
/// Updates the hash with data. /// Updates the hash with data.
/// </summary> /// </summary>

View File

@@ -46,7 +46,7 @@ namespace DiscImageChef.Checksums
/// <summary> /// <summary>
/// Initializes the MD5 hash provider /// Initializes the MD5 hash provider
/// </summary> /// </summary>
public void Init() public Md5Context()
{ {
md5Provider = MD5.Create(); md5Provider = MD5.Create();
} }
@@ -99,7 +99,7 @@ namespace DiscImageChef.Checksums
public byte[] File(string filename) public byte[] File(string filename)
{ {
FileStream fileStream = new FileStream(filename, FileMode.Open); FileStream fileStream = new FileStream(filename, FileMode.Open);
byte[] result = md5Provider.ComputeHash(fileStream); byte[] result = md5Provider.ComputeHash(fileStream);
fileStream.Close(); fileStream.Close();
return result; return result;
} }
@@ -111,8 +111,8 @@ namespace DiscImageChef.Checksums
/// <param name="hash">Byte array of the hash value.</param> /// <param name="hash">Byte array of the hash value.</param>
public string File(string filename, out byte[] hash) public string File(string filename, out byte[] hash)
{ {
FileStream fileStream = new FileStream(filename, FileMode.Open); FileStream fileStream = new FileStream(filename, FileMode.Open);
hash = md5Provider.ComputeHash(fileStream); hash = md5Provider.ComputeHash(fileStream);
StringBuilder md5Output = new StringBuilder(); StringBuilder md5Output = new StringBuilder();
foreach(byte h in hash) md5Output.Append(h.ToString("x2")); foreach(byte h in hash) md5Output.Append(h.ToString("x2"));
@@ -130,7 +130,7 @@ namespace DiscImageChef.Checksums
/// <param name="hash">Byte array of the hash value.</param> /// <param name="hash">Byte array of the hash value.</param>
public string Data(byte[] data, uint len, out byte[] hash) public string Data(byte[] data, uint len, out byte[] hash)
{ {
hash = md5Provider.ComputeHash(data, 0, (int)len); hash = md5Provider.ComputeHash(data, 0, (int)len);
StringBuilder md5Output = new StringBuilder(); StringBuilder md5Output = new StringBuilder();
foreach(byte h in hash) md5Output.Append(h.ToString("x2")); foreach(byte h in hash) md5Output.Append(h.ToString("x2"));

View File

@@ -46,7 +46,7 @@ namespace DiscImageChef.Checksums
/// <summary> /// <summary>
/// Initializes the RIPEMD160 hash provider /// Initializes the RIPEMD160 hash provider
/// </summary> /// </summary>
public void Init() public Ripemd160Context()
{ {
ripemd160Provider = RIPEMD160.Create(); ripemd160Provider = RIPEMD160.Create();
} }
@@ -99,7 +99,7 @@ namespace DiscImageChef.Checksums
public byte[] File(string filename) public byte[] File(string filename)
{ {
FileStream fileStream = new FileStream(filename, FileMode.Open); FileStream fileStream = new FileStream(filename, FileMode.Open);
byte[] result = ripemd160Provider.ComputeHash(fileStream); byte[] result = ripemd160Provider.ComputeHash(fileStream);
fileStream.Close(); fileStream.Close();
return result; return result;
} }
@@ -111,8 +111,8 @@ namespace DiscImageChef.Checksums
/// <param name="hash">Byte array of the hash value.</param> /// <param name="hash">Byte array of the hash value.</param>
public string File(string filename, out byte[] hash) public string File(string filename, out byte[] hash)
{ {
FileStream fileStream = new FileStream(filename, FileMode.Open); FileStream fileStream = new FileStream(filename, FileMode.Open);
hash = ripemd160Provider.ComputeHash(fileStream); hash = ripemd160Provider.ComputeHash(fileStream);
StringBuilder ripemd160Output = new StringBuilder(); StringBuilder ripemd160Output = new StringBuilder();
foreach(byte h in hash) ripemd160Output.Append(h.ToString("x2")); foreach(byte h in hash) ripemd160Output.Append(h.ToString("x2"));
@@ -130,7 +130,7 @@ namespace DiscImageChef.Checksums
/// <param name="hash">Byte array of the hash value.</param> /// <param name="hash">Byte array of the hash value.</param>
public string Data(byte[] data, uint len, out byte[] hash) public string Data(byte[] data, uint len, out byte[] hash)
{ {
hash = ripemd160Provider.ComputeHash(data, 0, (int)len); hash = ripemd160Provider.ComputeHash(data, 0, (int)len);
StringBuilder ripemd160Output = new StringBuilder(); StringBuilder ripemd160Output = new StringBuilder();
foreach(byte h in hash) ripemd160Output.Append(h.ToString("x2")); foreach(byte h in hash) ripemd160Output.Append(h.ToString("x2"));

View File

@@ -46,7 +46,7 @@ namespace DiscImageChef.Checksums
/// <summary> /// <summary>
/// Initializes the SHA1 hash provider /// Initializes the SHA1 hash provider
/// </summary> /// </summary>
public void Init() public Sha1Context()
{ {
sha1Provider = SHA1.Create(); sha1Provider = SHA1.Create();
} }
@@ -99,7 +99,7 @@ namespace DiscImageChef.Checksums
public byte[] File(string filename) public byte[] File(string filename)
{ {
FileStream fileStream = new FileStream(filename, FileMode.Open); FileStream fileStream = new FileStream(filename, FileMode.Open);
byte[] result = sha1Provider.ComputeHash(fileStream); byte[] result = sha1Provider.ComputeHash(fileStream);
fileStream.Close(); fileStream.Close();
return result; return result;
} }
@@ -111,8 +111,8 @@ namespace DiscImageChef.Checksums
/// <param name="hash">Byte array of the hash value.</param> /// <param name="hash">Byte array of the hash value.</param>
public string File(string filename, out byte[] hash) public string File(string filename, out byte[] hash)
{ {
FileStream fileStream = new FileStream(filename, FileMode.Open); FileStream fileStream = new FileStream(filename, FileMode.Open);
hash = sha1Provider.ComputeHash(fileStream); hash = sha1Provider.ComputeHash(fileStream);
StringBuilder sha1Output = new StringBuilder(); StringBuilder sha1Output = new StringBuilder();
foreach(byte h in hash) sha1Output.Append(h.ToString("x2")); foreach(byte h in hash) sha1Output.Append(h.ToString("x2"));
@@ -130,7 +130,7 @@ namespace DiscImageChef.Checksums
/// <param name="hash">Byte array of the hash value.</param> /// <param name="hash">Byte array of the hash value.</param>
public string Data(byte[] data, uint len, out byte[] hash) public string Data(byte[] data, uint len, out byte[] hash)
{ {
hash = sha1Provider.ComputeHash(data, 0, (int)len); hash = sha1Provider.ComputeHash(data, 0, (int)len);
StringBuilder sha1Output = new StringBuilder(); StringBuilder sha1Output = new StringBuilder();
foreach(byte h in hash) sha1Output.Append(h.ToString("x2")); foreach(byte h in hash) sha1Output.Append(h.ToString("x2"));

View File

@@ -46,7 +46,7 @@ namespace DiscImageChef.Checksums
/// <summary> /// <summary>
/// Initializes the SHA256 hash provider /// Initializes the SHA256 hash provider
/// </summary> /// </summary>
public void Init() public Sha256Context()
{ {
sha256Provider = SHA256.Create(); sha256Provider = SHA256.Create();
} }
@@ -99,7 +99,7 @@ namespace DiscImageChef.Checksums
public byte[] File(string filename) public byte[] File(string filename)
{ {
FileStream fileStream = new FileStream(filename, FileMode.Open); FileStream fileStream = new FileStream(filename, FileMode.Open);
byte[] result = sha256Provider.ComputeHash(fileStream); byte[] result = sha256Provider.ComputeHash(fileStream);
fileStream.Close(); fileStream.Close();
return result; return result;
} }
@@ -111,8 +111,8 @@ namespace DiscImageChef.Checksums
/// <param name="hash">Byte array of the hash value.</param> /// <param name="hash">Byte array of the hash value.</param>
public string File(string filename, out byte[] hash) public string File(string filename, out byte[] hash)
{ {
FileStream fileStream = new FileStream(filename, FileMode.Open); FileStream fileStream = new FileStream(filename, FileMode.Open);
hash = sha256Provider.ComputeHash(fileStream); hash = sha256Provider.ComputeHash(fileStream);
StringBuilder sha256Output = new StringBuilder(); StringBuilder sha256Output = new StringBuilder();
foreach(byte h in hash) sha256Output.Append(h.ToString("x2")); foreach(byte h in hash) sha256Output.Append(h.ToString("x2"));
@@ -130,7 +130,7 @@ namespace DiscImageChef.Checksums
/// <param name="hash">Byte array of the hash value.</param> /// <param name="hash">Byte array of the hash value.</param>
public string Data(byte[] data, uint len, out byte[] hash) public string Data(byte[] data, uint len, out byte[] hash)
{ {
hash = sha256Provider.ComputeHash(data, 0, (int)len); hash = sha256Provider.ComputeHash(data, 0, (int)len);
StringBuilder sha256Output = new StringBuilder(); StringBuilder sha256Output = new StringBuilder();
foreach(byte h in hash) sha256Output.Append(h.ToString("x2")); foreach(byte h in hash) sha256Output.Append(h.ToString("x2"));

View File

@@ -46,7 +46,7 @@ namespace DiscImageChef.Checksums
/// <summary> /// <summary>
/// Initializes the SHA384 hash provider /// Initializes the SHA384 hash provider
/// </summary> /// </summary>
public void Init() public Sha384Context()
{ {
sha384Provider = SHA384.Create(); sha384Provider = SHA384.Create();
} }
@@ -99,7 +99,7 @@ namespace DiscImageChef.Checksums
public byte[] File(string filename) public byte[] File(string filename)
{ {
FileStream fileStream = new FileStream(filename, FileMode.Open); FileStream fileStream = new FileStream(filename, FileMode.Open);
byte[] result = sha384Provider.ComputeHash(fileStream); byte[] result = sha384Provider.ComputeHash(fileStream);
fileStream.Close(); fileStream.Close();
return result; return result;
} }
@@ -111,8 +111,8 @@ namespace DiscImageChef.Checksums
/// <param name="hash">Byte array of the hash value.</param> /// <param name="hash">Byte array of the hash value.</param>
public string File(string filename, out byte[] hash) public string File(string filename, out byte[] hash)
{ {
FileStream fileStream = new FileStream(filename, FileMode.Open); FileStream fileStream = new FileStream(filename, FileMode.Open);
hash = sha384Provider.ComputeHash(fileStream); hash = sha384Provider.ComputeHash(fileStream);
StringBuilder sha384Output = new StringBuilder(); StringBuilder sha384Output = new StringBuilder();
foreach(byte h in hash) sha384Output.Append(h.ToString("x2")); foreach(byte h in hash) sha384Output.Append(h.ToString("x2"));
@@ -130,7 +130,7 @@ namespace DiscImageChef.Checksums
/// <param name="hash">Byte array of the hash value.</param> /// <param name="hash">Byte array of the hash value.</param>
public string Data(byte[] data, uint len, out byte[] hash) public string Data(byte[] data, uint len, out byte[] hash)
{ {
hash = sha384Provider.ComputeHash(data, 0, (int)len); hash = sha384Provider.ComputeHash(data, 0, (int)len);
StringBuilder sha384Output = new StringBuilder(); StringBuilder sha384Output = new StringBuilder();
foreach(byte h in hash) sha384Output.Append(h.ToString("x2")); foreach(byte h in hash) sha384Output.Append(h.ToString("x2"));

View File

@@ -46,7 +46,7 @@ namespace DiscImageChef.Checksums
/// <summary> /// <summary>
/// Initializes the SHA512 hash provider /// Initializes the SHA512 hash provider
/// </summary> /// </summary>
public void Init() public Sha512Context()
{ {
sha512Provider = SHA512.Create(); sha512Provider = SHA512.Create();
} }
@@ -99,7 +99,7 @@ namespace DiscImageChef.Checksums
public byte[] File(string filename) public byte[] File(string filename)
{ {
FileStream fileStream = new FileStream(filename, FileMode.Open); FileStream fileStream = new FileStream(filename, FileMode.Open);
byte[] result = sha512Provider.ComputeHash(fileStream); byte[] result = sha512Provider.ComputeHash(fileStream);
fileStream.Close(); fileStream.Close();
return result; return result;
} }
@@ -111,8 +111,8 @@ namespace DiscImageChef.Checksums
/// <param name="hash">Byte array of the hash value.</param> /// <param name="hash">Byte array of the hash value.</param>
public string File(string filename, out byte[] hash) public string File(string filename, out byte[] hash)
{ {
FileStream fileStream = new FileStream(filename, FileMode.Open); FileStream fileStream = new FileStream(filename, FileMode.Open);
hash = sha512Provider.ComputeHash(fileStream); hash = sha512Provider.ComputeHash(fileStream);
StringBuilder sha512Output = new StringBuilder(); StringBuilder sha512Output = new StringBuilder();
foreach(byte h in hash) sha512Output.Append(h.ToString("x2")); foreach(byte h in hash) sha512Output.Append(h.ToString("x2"));
@@ -130,7 +130,7 @@ namespace DiscImageChef.Checksums
/// <param name="hash">Byte array of the hash value.</param> /// <param name="hash">Byte array of the hash value.</param>
public string Data(byte[] data, uint len, out byte[] hash) public string Data(byte[] data, uint len, out byte[] hash)
{ {
hash = sha512Provider.ComputeHash(data, 0, (int)len); hash = sha512Provider.ComputeHash(data, 0, (int)len);
StringBuilder sha512Output = new StringBuilder(); StringBuilder sha512Output = new StringBuilder();
foreach(byte h in hash) sha512Output.Append(h.ToString("x2")); foreach(byte h in hash) sha512Output.Append(h.ToString("x2"));

View File

@@ -49,12 +49,12 @@ namespace DiscImageChef.Checksums
/// </summary> /// </summary>
public class SpamSumContext : IChecksum public class SpamSumContext : IChecksum
{ {
const uint ROLLING_WINDOW = 7; const uint ROLLING_WINDOW = 7;
const uint MIN_BLOCKSIZE = 3; const uint MIN_BLOCKSIZE = 3;
const uint HASH_PRIME = 0x01000193; const uint HASH_PRIME = 0x01000193;
const uint HASH_INIT = 0x28021967; const uint HASH_INIT = 0x28021967;
const uint NUM_BLOCKHASHES = 31; const uint NUM_BLOCKHASHES = 31;
const uint SPAMSUM_LENGTH = 64; const uint SPAMSUM_LENGTH = 64;
const uint FUZZY_MAX_RESULT = 2 * SPAMSUM_LENGTH + 20; const uint FUZZY_MAX_RESULT = 2 * SPAMSUM_LENGTH + 20;
//"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; //"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
readonly byte[] b64 = readonly byte[] b64 =
@@ -67,30 +67,70 @@ namespace DiscImageChef.Checksums
FuzzyState self; FuzzyState self;
void roll_init()
{
self.Roll = new RollState {Window = new byte[ROLLING_WINDOW]};
}
/// <summary> /// <summary>
/// Initializes the SpamSum structures /// Initializes the SpamSum structures
/// </summary> /// </summary>
public void Init() public SpamSumContext()
{ {
self = new FuzzyState {Bh = new BlockhashContext[NUM_BLOCKHASHES]}; self =
new FuzzyState {Bh = new BlockhashContext[NUM_BLOCKHASHES]};
for(int i = 0; i < NUM_BLOCKHASHES; i++) self.Bh[i].Digest = new byte[SPAMSUM_LENGTH]; for(int i = 0; i < NUM_BLOCKHASHES; i++) self.Bh[i].Digest = new byte[SPAMSUM_LENGTH];
self.Bhstart = 0; self.Bhstart = 0;
self.Bhend = 1; self.Bhend = 1;
self.Bh[0].H = HASH_INIT; self.Bh[0].H = HASH_INIT;
self.Bh[0].Halfh = HASH_INIT; self.Bh[0].Halfh = HASH_INIT;
self.Bh[0].Digest[0] = 0; self.Bh[0].Digest[0] = 0;
self.Bh[0].Halfdigest = 0; self.Bh[0].Halfdigest = 0;
self.Bh[0].Dlen = 0; self.Bh[0].Dlen = 0;
self.TotalSize = 0; self.TotalSize = 0;
roll_init(); roll_init();
} }
/// <summary>
/// Updates the hash with data.
/// </summary>
/// <param name="data">Data buffer.</param>
/// <param name="len">Length of buffer to hash.</param>
public void Update(byte[] data, uint len)
{
self.TotalSize += len;
for(int i = 0; i < len; i++) fuzzy_engine_step(data[i]);
}
/// <summary>
/// Updates the hash with data.
/// </summary>
/// <param name="data">Data buffer.</param>
public void Update(byte[] data)
{
Update(data, (uint)data.Length);
}
/// <summary>
/// Returns a byte array of the hash value.
/// </summary>
public byte[] Final()
{
// SpamSum does not have a binary representation, or so it seems
throw new NotImplementedException("SpamSum does not have a binary representation.");
}
/// <summary>
/// Returns a base64 representation of the hash value.
/// </summary>
public string End()
{
FuzzyDigest(out byte[] result);
return CToString(result);
}
void roll_init()
{
self.Roll = new RollState {Window = new byte[ROLLING_WINDOW]};
}
/* /*
* a rolling hash, based on the Adler checksum. By using a rolling hash * a rolling hash, based on the Adler checksum. By using a rolling hash
* we can perform auto resynchronisation after inserts/deletes * we can perform auto resynchronisation after inserts/deletes
@@ -116,7 +156,7 @@ namespace DiscImageChef.Checksums
* in theory should have no effect. This AND has been removed * in theory should have no effect. This AND has been removed
* for performance (jk) */ * for performance (jk) */
self.Roll.H3 <<= 5; self.Roll.H3 <<= 5;
self.Roll.H3 ^= c; self.Roll.H3 ^= c;
} }
uint roll_sum() uint roll_sum()
@@ -144,13 +184,13 @@ namespace DiscImageChef.Checksums
if(self.Bhend == 0) // assert if(self.Bhend == 0) // assert
throw new Exception("Assertion failed"); throw new Exception("Assertion failed");
obh = self.Bhend - 1; obh = self.Bhend - 1;
nbh = self.Bhend; nbh = self.Bhend;
self.Bh[nbh].H = self.Bh[obh].H; self.Bh[nbh].H = self.Bh[obh].H;
self.Bh[nbh].Halfh = self.Bh[obh].Halfh; self.Bh[nbh].Halfh = self.Bh[obh].Halfh;
self.Bh[nbh].Digest[0] = 0; self.Bh[nbh].Digest[0] = 0;
self.Bh[nbh].Halfdigest = 0; self.Bh[nbh].Halfdigest = 0;
self.Bh[nbh].Dlen = 0; self.Bh[nbh].Dlen = 0;
++self.Bhend; ++self.Bhend;
} }
@@ -165,6 +205,7 @@ namespace DiscImageChef.Checksums
* blocksize. */ return; * blocksize. */ return;
if(self.Bh[self.Bhstart + 1].Dlen < SPAMSUM_LENGTH / 2) if(self.Bh[self.Bhstart + 1].Dlen < SPAMSUM_LENGTH / 2)
/* Estimate adjustment would select this blocksize. */ return; /* Estimate adjustment would select this blocksize. */ return;
/* At this point we are clearly no longer interested in the /* At this point we are clearly no longer interested in the
* start_blocksize. Get rid of it. */ * start_blocksize. Get rid of it. */
++self.Bhstart; ++self.Bhstart;
@@ -173,7 +214,7 @@ namespace DiscImageChef.Checksums
void fuzzy_engine_step(byte c) void fuzzy_engine_step(byte c)
{ {
ulong h; ulong h;
uint i; uint i;
/* At each character we update the rolling hash and the normal hashes. /* At each character we update the rolling hash and the normal hashes.
* When the rolling hash hits a reset value then we emit a normal hash * When the rolling hash hits a reset value then we emit a normal hash
* as a element of the signature and reset the normal hash. */ * as a element of the signature and reset the normal hash. */
@@ -182,7 +223,7 @@ namespace DiscImageChef.Checksums
for(i = self.Bhstart; i < self.Bhend; ++i) for(i = self.Bhstart; i < self.Bhend; ++i)
{ {
self.Bh[i].H = sum_hash(c, self.Bh[i].H); self.Bh[i].H = sum_hash(c, self.Bh[i].H);
self.Bh[i].Halfh = sum_hash(c, self.Bh[i].Halfh); self.Bh[i].Halfh = sum_hash(c, self.Bh[i].Halfh);
} }
@@ -193,12 +234,13 @@ namespace DiscImageChef.Checksums
/* Once this condition is false for one bs, it is /* Once this condition is false for one bs, it is
* automatically false for all further bs. I.e. if * automatically false for all further bs. I.e. if
* h === -1 (mod 2*bs) then h === -1 (mod bs). */ break; * h === -1 (mod 2*bs) then h === -1 (mod bs). */ break;
/* We have hit a reset point. We now emit hashes which are /* We have hit a reset point. We now emit hashes which are
* based on all characters in the piece of the message between * based on all characters in the piece of the message between
* the last reset point and this one */ * the last reset point and this one */
if(0 == self.Bh[i].Dlen) fuzzy_try_fork_blockhash(); if(0 == self.Bh[i].Dlen) fuzzy_try_fork_blockhash();
self.Bh[i].Digest[self.Bh[i].Dlen] = b64[self.Bh[i].H % 64]; self.Bh[i].Digest[self.Bh[i].Dlen] = b64[self.Bh[i].H % 64];
self.Bh[i].Halfdigest = b64[self.Bh[i].Halfh % 64]; self.Bh[i].Halfdigest = b64[self.Bh[i].Halfh % 64];
if(self.Bh[i].Dlen < SPAMSUM_LENGTH - 1) if(self.Bh[i].Dlen < SPAMSUM_LENGTH - 1)
{ {
/* We can have a problem with the tail overflowing. The /* We can have a problem with the tail overflowing. The
@@ -208,45 +250,25 @@ namespace DiscImageChef.Checksums
* last few pieces of the message into a single piece * last few pieces of the message into a single piece
* */ * */
self.Bh[i].Digest[++self.Bh[i].Dlen] = 0; self.Bh[i].Digest[++self.Bh[i].Dlen] = 0;
self.Bh[i].H = HASH_INIT; self.Bh[i].H = HASH_INIT;
if(self.Bh[i].Dlen >= SPAMSUM_LENGTH / 2) continue; if(self.Bh[i].Dlen >= SPAMSUM_LENGTH / 2) continue;
self.Bh[i].Halfh = HASH_INIT; self.Bh[i].Halfh = HASH_INIT;
self.Bh[i].Halfdigest = 0; self.Bh[i].Halfdigest = 0;
} }
else fuzzy_try_reduce_blockhash(); else fuzzy_try_reduce_blockhash();
} }
} }
/// <summary>
/// Updates the hash with data.
/// </summary>
/// <param name="data">Data buffer.</param>
/// <param name="len">Length of buffer to hash.</param>
public void Update(byte[] data, uint len)
{
self.TotalSize += len;
for(int i = 0; i < len; i++) fuzzy_engine_step(data[i]);
}
/// <summary>
/// Updates the hash with data.
/// </summary>
/// <param name="data">Data buffer.</param>
public void Update(byte[] data)
{
Update(data, (uint)data.Length);
}
// CLAUNIA: Flags seems to never be used in ssdeep, so I just removed it for code simplicity // CLAUNIA: Flags seems to never be used in ssdeep, so I just removed it for code simplicity
uint FuzzyDigest(out byte[] result) uint FuzzyDigest(out byte[] result)
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
uint bi = self.Bhstart; uint bi = self.Bhstart;
uint h = roll_sum(); uint h = roll_sum();
int i, resultOff; int i, resultOff;
int remain = (int)(FUZZY_MAX_RESULT - 1); /* Exclude terminating '\0'. */ int remain = (int)(FUZZY_MAX_RESULT - 1); /* Exclude terminating '\0'. */
result = new byte[FUZZY_MAX_RESULT]; result = new byte[FUZZY_MAX_RESULT];
/* Verify that our elimination was not overeager. */ /* Verify that our elimination was not overeager. */
if(!(bi == 0 || (ulong)SSDEEP_BS(bi) / 2 * SPAMSUM_LENGTH < self.TotalSize)) if(!(bi == 0 || (ulong)SSDEEP_BS(bi) / 2 * SPAMSUM_LENGTH < self.TotalSize))
throw new Exception("Assertion failed"); throw new Exception("Assertion failed");
@@ -259,6 +281,7 @@ namespace DiscImageChef.Checksums
++bi; ++bi;
if(bi >= NUM_BLOCKHASHES) throw new OverflowException("The input exceeds data types."); if(bi >= NUM_BLOCKHASHES) throw new OverflowException("The input exceeds data types.");
} }
/* Adapt blocksize guess to actual digest length. */ /* Adapt blocksize guess to actual digest length. */
while(bi >= self.Bhend) --bi; while(bi >= self.Bhend) --bi;
while(bi > self.Bhstart && self.Bh[bi].Dlen < SPAMSUM_LENGTH / 2) --bi; while(bi > self.Bhstart && self.Bh[bi].Dlen < SPAMSUM_LENGTH / 2) --bi;
@@ -282,14 +305,15 @@ namespace DiscImageChef.Checksums
Array.Copy(self.Bh[bi].Digest, 0, result, resultOff, i); Array.Copy(self.Bh[bi].Digest, 0, result, resultOff, i);
resultOff += i; resultOff += i;
remain -= i; remain -= i;
if(h != 0) if(h != 0)
{ {
if(remain <= 0) throw new Exception("Assertion failed"); if(remain <= 0) throw new Exception("Assertion failed");
result[resultOff] = b64[self.Bh[bi].H % 64]; result[resultOff] = b64[self.Bh[bi].H % 64];
if(i < 3 || result[resultOff] != result[resultOff - 1] || result[resultOff] != result[resultOff - 2] || if(i < 3 || result[resultOff] != result[resultOff - 1] ||
result[resultOff] != result[resultOff - 3]) result[resultOff] != result[resultOff - 2] ||
result[resultOff] != result[resultOff - 3])
{ {
++resultOff; ++resultOff;
--remain; --remain;
@@ -300,8 +324,9 @@ namespace DiscImageChef.Checksums
if(remain <= 0) throw new Exception("Assertion failed"); if(remain <= 0) throw new Exception("Assertion failed");
result[resultOff] = self.Bh[bi].Digest[i]; result[resultOff] = self.Bh[bi].Digest[i];
if(i < 3 || result[resultOff] != result[resultOff - 1] || result[resultOff] != result[resultOff - 2] || if(i < 3 || result[resultOff] != result[resultOff - 1] ||
result[resultOff] != result[resultOff - 3]) result[resultOff] != result[resultOff - 2] ||
result[resultOff] != result[resultOff - 3])
{ {
++resultOff; ++resultOff;
--remain; --remain;
@@ -320,16 +345,17 @@ namespace DiscImageChef.Checksums
Array.Copy(self.Bh[bi].Digest, 0, result, resultOff, i); Array.Copy(self.Bh[bi].Digest, 0, result, resultOff, i);
resultOff += i; resultOff += i;
remain -= i; remain -= i;
if(h != 0) if(h != 0)
{ {
if(remain <= 0) throw new Exception("Assertion failed"); if(remain <= 0) throw new Exception("Assertion failed");
h = self.Bh[bi].Halfh; h = self.Bh[bi].Halfh;
result[resultOff] = b64[h % 64]; result[resultOff] = b64[h % 64];
if(i < 3 || result[resultOff] != result[resultOff - 1] || if(i < 3 || result[resultOff] != result[resultOff - 1] ||
result[resultOff] != result[resultOff - 2] || result[resultOff] != result[resultOff - 3]) result[resultOff] != result[resultOff - 2] ||
result[resultOff] != result[resultOff - 3])
{ {
++resultOff; ++resultOff;
--remain; --remain;
@@ -343,8 +369,9 @@ namespace DiscImageChef.Checksums
if(remain <= 0) throw new Exception("Assertion failed"); if(remain <= 0) throw new Exception("Assertion failed");
result[resultOff] = (byte)i; result[resultOff] = (byte)i;
if(i < 3 || result[resultOff] != result[resultOff - 1] || if(i < 3 || result[resultOff] != result[resultOff - 1] ||
result[resultOff] != result[resultOff - 2] || result[resultOff] != result[resultOff - 3]) result[resultOff] != result[resultOff - 2] ||
result[resultOff] != result[resultOff - 3])
{ {
++resultOff; ++resultOff;
--remain; --remain;
@@ -355,7 +382,7 @@ namespace DiscImageChef.Checksums
else if(h != 0) else if(h != 0)
{ {
if(self.Bh[bi].Dlen != 0) throw new Exception("Assertion failed"); if(self.Bh[bi].Dlen != 0) throw new Exception("Assertion failed");
if(remain <= 0) throw new Exception("Assertion failed"); if(remain <= 0) throw new Exception("Assertion failed");
result[resultOff++] = b64[self.Bh[bi].H % 64]; result[resultOff++] = b64[self.Bh[bi].H % 64];
/* No need to bother with FUZZY_FLAG_ELIMSEQ, because this /* No need to bother with FUZZY_FLAG_ELIMSEQ, because this
@@ -367,25 +394,6 @@ namespace DiscImageChef.Checksums
return 0; return 0;
} }
/// <summary>
/// Returns a byte array of the hash value.
/// </summary>
public byte[] Final()
{
// SpamSum does not have a binary representation, or so it seems
throw new NotImplementedException("SpamSum does not have a binary representation.");
}
/// <summary>
/// Returns a base64 representation of the hash value.
/// </summary>
public string End()
{
FuzzyDigest(out byte[] result);
return CToString(result);
}
/// <summary> /// <summary>
/// Gets the hash of a file /// Gets the hash of a file
/// </summary> /// </summary>
@@ -417,7 +425,6 @@ namespace DiscImageChef.Checksums
public static string Data(byte[] data, uint len, out byte[] hash) public static string Data(byte[] data, uint len, out byte[] hash)
{ {
SpamSumContext fuzzyContext = new SpamSumContext(); SpamSumContext fuzzyContext = new SpamSumContext();
fuzzyContext.Init();
fuzzyContext.Update(data, len); fuzzyContext.Update(data, len);
@@ -469,8 +476,8 @@ namespace DiscImageChef.Checksums
* output hash to stay compatible with ssdeep output. */ * output hash to stay compatible with ssdeep output. */
struct BlockhashContext struct BlockhashContext
{ {
public uint H; public uint H;
public uint Halfh; public uint Halfh;
public byte[] Digest; public byte[] Digest;
// SPAMSUM_LENGTH // SPAMSUM_LENGTH
public byte Halfdigest; public byte Halfdigest;
@@ -479,11 +486,11 @@ namespace DiscImageChef.Checksums
struct FuzzyState struct FuzzyState
{ {
public uint Bhstart; public uint Bhstart;
public uint Bhend; public uint Bhend;
public BlockhashContext[] Bh; public BlockhashContext[] Bh;
//NUM_BLOCKHASHES //NUM_BLOCKHASHES
public ulong TotalSize; public ulong TotalSize;
public RollState Roll; public RollState Roll;
} }
} }

View File

@@ -33,26 +33,25 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using DiscImageChef.Checksums; using DiscImageChef.Checksums;
namespace DiscImageChef.Core namespace DiscImageChef.Core
{ {
public struct BenchmarkResults public struct BenchmarkResults
{ {
public double FillTime; public double FillTime;
public double FillSpeed; public double FillSpeed;
public double ReadTime; public double ReadTime;
public double ReadSpeed; public double ReadSpeed;
public double EntropyTime; public double EntropyTime;
public double EntropySpeed; public double EntropySpeed;
public Dictionary<string, BenchmarkEntry> Entries; public Dictionary<string, BenchmarkEntry> Entries;
public long MinMemory; public long MinMemory;
public long MaxMemory; public long MaxMemory;
public double SeparateTime; public double SeparateTime;
public double SeparateSpeed; public double SeparateSpeed;
public double TotalTime; public double TotalTime;
public double TotalSpeed; public double TotalSpeed;
} }
public struct BenchmarkEntry public struct BenchmarkEntry
@@ -66,9 +65,9 @@ namespace DiscImageChef.Core
/// </summary> /// </summary>
public static class Benchmark public static class Benchmark
{ {
public static event InitProgressHandler InitProgressEvent; public static event InitProgressHandler InitProgressEvent;
public static event UpdateProgressHandler UpdateProgressEvent; public static event UpdateProgressHandler UpdateProgressEvent;
public static event EndProgressHandler EndProgressEvent; public static event EndProgressHandler EndProgressEvent;
static void InitProgress() static void InitProgress()
{ {
@@ -89,16 +88,16 @@ namespace DiscImageChef.Core
{ {
BenchmarkResults results = new BenchmarkResults BenchmarkResults results = new BenchmarkResults
{ {
Entries = new Dictionary<string, BenchmarkEntry>(), Entries = new Dictionary<string, BenchmarkEntry>(),
MinMemory = long.MaxValue, MinMemory = long.MaxValue,
MaxMemory = 0, MaxMemory = 0,
SeparateTime = 0 SeparateTime = 0
}; };
MemoryStream ms = new MemoryStream(bufferSize); MemoryStream ms = new MemoryStream(bufferSize);
Random rnd = new Random(); Random rnd = new Random();
DateTime start; DateTime start;
DateTime end; DateTime end;
long mem; long mem;
start = DateTime.Now; start = DateTime.Now;
InitProgress(); InitProgress();
@@ -113,14 +112,14 @@ namespace DiscImageChef.Core
EndProgress(); EndProgress();
end = DateTime.Now; end = DateTime.Now;
results.FillTime = (end - start).TotalSeconds; results.FillTime = (end - start).TotalSeconds;
results.FillSpeed = bufferSize / 1048576.0 / (end - start).TotalSeconds; results.FillSpeed = bufferSize / 1048576.0 / (end - start).TotalSeconds;
ms.Seek(0, SeekOrigin.Begin); ms.Seek(0, SeekOrigin.Begin);
mem = GC.GetTotalMemory(false); mem = GC.GetTotalMemory(false);
if(mem > results.MaxMemory) results.MaxMemory = mem; if(mem > results.MaxMemory) results.MaxMemory = mem;
if(mem < results.MinMemory) results.MinMemory = mem; if(mem < results.MinMemory) results.MinMemory = mem;
start = DateTime.Now; start = DateTime.Now;
InitProgress(); InitProgress();
for(int i = 0; i < bufferSize / blockSize; i++) for(int i = 0; i < bufferSize / blockSize; i++)
{ {
@@ -130,22 +129,21 @@ namespace DiscImageChef.Core
} }
EndProgress(); EndProgress();
end = DateTime.Now; end = DateTime.Now;
mem = GC.GetTotalMemory(false); mem = GC.GetTotalMemory(false);
if(mem > results.MaxMemory) results.MaxMemory = mem; if(mem > results.MaxMemory) results.MaxMemory = mem;
if(mem < results.MinMemory) results.MinMemory = mem; if(mem < results.MinMemory) results.MinMemory = mem;
results.ReadTime = (end - start).TotalSeconds; results.ReadTime = (end - start).TotalSeconds;
results.ReadSpeed = bufferSize / 1048576.0 / (end - start).TotalSeconds; results.ReadSpeed = bufferSize / 1048576.0 / (end - start).TotalSeconds;
#region Adler32 #region Adler32
IChecksum ctx = new Adler32Context(); IChecksum ctx = new Adler32Context();
ctx.Init();
ms.Seek(0, SeekOrigin.Begin); ms.Seek(0, SeekOrigin.Begin);
mem = GC.GetTotalMemory(false); mem = GC.GetTotalMemory(false);
if(mem > results.MaxMemory) results.MaxMemory = mem; if(mem > results.MaxMemory) results.MaxMemory = mem;
if(mem < results.MinMemory) results.MinMemory = mem; if(mem < results.MinMemory) results.MinMemory = mem;
start = DateTime.Now; start = DateTime.Now;
InitProgress(); InitProgress();
for(int i = 0; i < bufferSize / blockSize; i++) for(int i = 0; i < bufferSize / blockSize; i++)
{ {
@@ -157,28 +155,27 @@ namespace DiscImageChef.Core
EndProgress(); EndProgress();
ctx.End(); ctx.End();
end = DateTime.Now; end = DateTime.Now;
mem = GC.GetTotalMemory(false); mem = GC.GetTotalMemory(false);
if(mem > results.MaxMemory) results.MaxMemory = mem; if(mem > results.MaxMemory) results.MaxMemory = mem;
if(mem < results.MinMemory) results.MinMemory = mem; if(mem < results.MinMemory) results.MinMemory = mem;
results.Entries.Add("Adler32", results.Entries.Add("Adler32",
new BenchmarkEntry new BenchmarkEntry
{ {
TimeSpan = (end - start).TotalSeconds, TimeSpan = (end - start).TotalSeconds,
Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds
}); });
results.SeparateTime += (end - start).TotalSeconds; results.SeparateTime += (end - start).TotalSeconds;
#endregion Adler32 #endregion Adler32
#region CRC16 #region CRC16
ctx = new Crc16Context(); ctx = new Crc16Context();
ctx.Init();
ms.Seek(0, SeekOrigin.Begin); ms.Seek(0, SeekOrigin.Begin);
mem = GC.GetTotalMemory(false); mem = GC.GetTotalMemory(false);
if(mem > results.MaxMemory) results.MaxMemory = mem; if(mem > results.MaxMemory) results.MaxMemory = mem;
if(mem < results.MinMemory) results.MinMemory = mem; if(mem < results.MinMemory) results.MinMemory = mem;
start = DateTime.Now; start = DateTime.Now;
InitProgress(); InitProgress();
for(int i = 0; i < bufferSize / blockSize; i++) for(int i = 0; i < bufferSize / blockSize; i++)
{ {
@@ -190,28 +187,27 @@ namespace DiscImageChef.Core
EndProgress(); EndProgress();
ctx.End(); ctx.End();
end = DateTime.Now; end = DateTime.Now;
mem = GC.GetTotalMemory(false); mem = GC.GetTotalMemory(false);
if(mem > results.MaxMemory) results.MaxMemory = mem; if(mem > results.MaxMemory) results.MaxMemory = mem;
if(mem < results.MinMemory) results.MinMemory = mem; if(mem < results.MinMemory) results.MinMemory = mem;
results.Entries.Add("CRC16", results.Entries.Add("CRC16",
new BenchmarkEntry new BenchmarkEntry
{ {
TimeSpan = (end - start).TotalSeconds, TimeSpan = (end - start).TotalSeconds,
Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds
}); });
results.SeparateTime += (end - start).TotalSeconds; results.SeparateTime += (end - start).TotalSeconds;
#endregion CRC16 #endregion CRC16
#region CRC32 #region CRC32
ctx = new Crc32Context(); ctx = new Crc32Context();
ctx.Init();
ms.Seek(0, SeekOrigin.Begin); ms.Seek(0, SeekOrigin.Begin);
mem = GC.GetTotalMemory(false); mem = GC.GetTotalMemory(false);
if(mem > results.MaxMemory) results.MaxMemory = mem; if(mem > results.MaxMemory) results.MaxMemory = mem;
if(mem < results.MinMemory) results.MinMemory = mem; if(mem < results.MinMemory) results.MinMemory = mem;
start = DateTime.Now; start = DateTime.Now;
InitProgress(); InitProgress();
for(int i = 0; i < bufferSize / blockSize; i++) for(int i = 0; i < bufferSize / blockSize; i++)
{ {
@@ -223,28 +219,27 @@ namespace DiscImageChef.Core
EndProgress(); EndProgress();
ctx.End(); ctx.End();
end = DateTime.Now; end = DateTime.Now;
mem = GC.GetTotalMemory(false); mem = GC.GetTotalMemory(false);
if(mem > results.MaxMemory) results.MaxMemory = mem; if(mem > results.MaxMemory) results.MaxMemory = mem;
if(mem < results.MinMemory) results.MinMemory = mem; if(mem < results.MinMemory) results.MinMemory = mem;
results.Entries.Add("CRC32", results.Entries.Add("CRC32",
new BenchmarkEntry new BenchmarkEntry
{ {
TimeSpan = (end - start).TotalSeconds, TimeSpan = (end - start).TotalSeconds,
Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds
}); });
results.SeparateTime += (end - start).TotalSeconds; results.SeparateTime += (end - start).TotalSeconds;
#endregion CRC32 #endregion CRC32
#region CRC64 #region CRC64
ctx = new Crc64Context(); ctx = new Crc64Context();
ctx.Init();
ms.Seek(0, SeekOrigin.Begin); ms.Seek(0, SeekOrigin.Begin);
mem = GC.GetTotalMemory(false); mem = GC.GetTotalMemory(false);
if(mem > results.MaxMemory) results.MaxMemory = mem; if(mem > results.MaxMemory) results.MaxMemory = mem;
if(mem < results.MinMemory) results.MinMemory = mem; if(mem < results.MinMemory) results.MinMemory = mem;
start = DateTime.Now; start = DateTime.Now;
InitProgress(); InitProgress();
for(int i = 0; i < bufferSize / blockSize; i++) for(int i = 0; i < bufferSize / blockSize; i++)
{ {
@@ -256,28 +251,27 @@ namespace DiscImageChef.Core
EndProgress(); EndProgress();
ctx.End(); ctx.End();
end = DateTime.Now; end = DateTime.Now;
mem = GC.GetTotalMemory(false); mem = GC.GetTotalMemory(false);
if(mem > results.MaxMemory) results.MaxMemory = mem; if(mem > results.MaxMemory) results.MaxMemory = mem;
if(mem < results.MinMemory) results.MinMemory = mem; if(mem < results.MinMemory) results.MinMemory = mem;
results.Entries.Add("CRC64", results.Entries.Add("CRC64",
new BenchmarkEntry new BenchmarkEntry
{ {
TimeSpan = (end - start).TotalSeconds, TimeSpan = (end - start).TotalSeconds,
Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds
}); });
results.SeparateTime += (end - start).TotalSeconds; results.SeparateTime += (end - start).TotalSeconds;
#endregion CRC64 #endregion CRC64
#region MD5 #region MD5
ctx = new Md5Context(); ctx = new Md5Context();
ctx.Init();
ms.Seek(0, SeekOrigin.Begin); ms.Seek(0, SeekOrigin.Begin);
mem = GC.GetTotalMemory(false); mem = GC.GetTotalMemory(false);
if(mem > results.MaxMemory) results.MaxMemory = mem; if(mem > results.MaxMemory) results.MaxMemory = mem;
if(mem < results.MinMemory) results.MinMemory = mem; if(mem < results.MinMemory) results.MinMemory = mem;
start = DateTime.Now; start = DateTime.Now;
InitProgress(); InitProgress();
for(int i = 0; i < bufferSize / blockSize; i++) for(int i = 0; i < bufferSize / blockSize; i++)
{ {
@@ -289,28 +283,27 @@ namespace DiscImageChef.Core
EndProgress(); EndProgress();
ctx.End(); ctx.End();
end = DateTime.Now; end = DateTime.Now;
mem = GC.GetTotalMemory(false); mem = GC.GetTotalMemory(false);
if(mem > results.MaxMemory) results.MaxMemory = mem; if(mem > results.MaxMemory) results.MaxMemory = mem;
if(mem < results.MinMemory) results.MinMemory = mem; if(mem < results.MinMemory) results.MinMemory = mem;
results.Entries.Add("MD5", results.Entries.Add("MD5",
new BenchmarkEntry new BenchmarkEntry
{ {
TimeSpan = (end - start).TotalSeconds, TimeSpan = (end - start).TotalSeconds,
Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds
}); });
results.SeparateTime += (end - start).TotalSeconds; results.SeparateTime += (end - start).TotalSeconds;
#endregion MD5 #endregion MD5
#region RIPEMD160 #region RIPEMD160
ctx = new Ripemd160Context(); ctx = new Ripemd160Context();
ctx.Init();
ms.Seek(0, SeekOrigin.Begin); ms.Seek(0, SeekOrigin.Begin);
mem = GC.GetTotalMemory(false); mem = GC.GetTotalMemory(false);
if(mem > results.MaxMemory) results.MaxMemory = mem; if(mem > results.MaxMemory) results.MaxMemory = mem;
if(mem < results.MinMemory) results.MinMemory = mem; if(mem < results.MinMemory) results.MinMemory = mem;
start = DateTime.Now; start = DateTime.Now;
InitProgress(); InitProgress();
for(int i = 0; i < bufferSize / blockSize; i++) for(int i = 0; i < bufferSize / blockSize; i++)
{ {
@@ -322,28 +315,27 @@ namespace DiscImageChef.Core
EndProgress(); EndProgress();
ctx.End(); ctx.End();
end = DateTime.Now; end = DateTime.Now;
mem = GC.GetTotalMemory(false); mem = GC.GetTotalMemory(false);
if(mem > results.MaxMemory) results.MaxMemory = mem; if(mem > results.MaxMemory) results.MaxMemory = mem;
if(mem < results.MinMemory) results.MinMemory = mem; if(mem < results.MinMemory) results.MinMemory = mem;
results.Entries.Add("RIPEMD160", results.Entries.Add("RIPEMD160",
new BenchmarkEntry new BenchmarkEntry
{ {
TimeSpan = (end - start).TotalSeconds, TimeSpan = (end - start).TotalSeconds,
Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds
}); });
results.SeparateTime += (end - start).TotalSeconds; results.SeparateTime += (end - start).TotalSeconds;
#endregion RIPEMD160 #endregion RIPEMD160
#region SHA1 #region SHA1
ctx = new Sha1Context(); ctx = new Sha1Context();
ctx.Init();
ms.Seek(0, SeekOrigin.Begin); ms.Seek(0, SeekOrigin.Begin);
mem = GC.GetTotalMemory(false); mem = GC.GetTotalMemory(false);
if(mem > results.MaxMemory) results.MaxMemory = mem; if(mem > results.MaxMemory) results.MaxMemory = mem;
if(mem < results.MinMemory) results.MinMemory = mem; if(mem < results.MinMemory) results.MinMemory = mem;
start = DateTime.Now; start = DateTime.Now;
InitProgress(); InitProgress();
for(int i = 0; i < bufferSize / blockSize; i++) for(int i = 0; i < bufferSize / blockSize; i++)
{ {
@@ -355,28 +347,27 @@ namespace DiscImageChef.Core
EndProgress(); EndProgress();
ctx.End(); ctx.End();
end = DateTime.Now; end = DateTime.Now;
mem = GC.GetTotalMemory(false); mem = GC.GetTotalMemory(false);
if(mem > results.MaxMemory) results.MaxMemory = mem; if(mem > results.MaxMemory) results.MaxMemory = mem;
if(mem < results.MinMemory) results.MinMemory = mem; if(mem < results.MinMemory) results.MinMemory = mem;
results.Entries.Add("SHA1", results.Entries.Add("SHA1",
new BenchmarkEntry new BenchmarkEntry
{ {
TimeSpan = (end - start).TotalSeconds, TimeSpan = (end - start).TotalSeconds,
Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds
}); });
results.SeparateTime += (end - start).TotalSeconds; results.SeparateTime += (end - start).TotalSeconds;
#endregion SHA1 #endregion SHA1
#region SHA256 #region SHA256
ctx = new Sha256Context(); ctx = new Sha256Context();
ctx.Init();
ms.Seek(0, SeekOrigin.Begin); ms.Seek(0, SeekOrigin.Begin);
mem = GC.GetTotalMemory(false); mem = GC.GetTotalMemory(false);
if(mem > results.MaxMemory) results.MaxMemory = mem; if(mem > results.MaxMemory) results.MaxMemory = mem;
if(mem < results.MinMemory) results.MinMemory = mem; if(mem < results.MinMemory) results.MinMemory = mem;
start = DateTime.Now; start = DateTime.Now;
InitProgress(); InitProgress();
for(int i = 0; i < bufferSize / blockSize; i++) for(int i = 0; i < bufferSize / blockSize; i++)
{ {
@@ -388,28 +379,27 @@ namespace DiscImageChef.Core
EndProgress(); EndProgress();
ctx.End(); ctx.End();
end = DateTime.Now; end = DateTime.Now;
mem = GC.GetTotalMemory(false); mem = GC.GetTotalMemory(false);
if(mem > results.MaxMemory) results.MaxMemory = mem; if(mem > results.MaxMemory) results.MaxMemory = mem;
if(mem < results.MinMemory) results.MinMemory = mem; if(mem < results.MinMemory) results.MinMemory = mem;
results.Entries.Add("SHA256", results.Entries.Add("SHA256",
new BenchmarkEntry new BenchmarkEntry
{ {
TimeSpan = (end - start).TotalSeconds, TimeSpan = (end - start).TotalSeconds,
Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds
}); });
results.SeparateTime += (end - start).TotalSeconds; results.SeparateTime += (end - start).TotalSeconds;
#endregion SHA256 #endregion SHA256
#region SHA384 #region SHA384
ctx = new Sha384Context(); ctx = new Sha384Context();
ctx.Init();
ms.Seek(0, SeekOrigin.Begin); ms.Seek(0, SeekOrigin.Begin);
mem = GC.GetTotalMemory(false); mem = GC.GetTotalMemory(false);
if(mem > results.MaxMemory) results.MaxMemory = mem; if(mem > results.MaxMemory) results.MaxMemory = mem;
if(mem < results.MinMemory) results.MinMemory = mem; if(mem < results.MinMemory) results.MinMemory = mem;
start = DateTime.Now; start = DateTime.Now;
InitProgress(); InitProgress();
for(int i = 0; i < bufferSize / blockSize; i++) for(int i = 0; i < bufferSize / blockSize; i++)
{ {
@@ -421,28 +411,27 @@ namespace DiscImageChef.Core
EndProgress(); EndProgress();
ctx.End(); ctx.End();
end = DateTime.Now; end = DateTime.Now;
mem = GC.GetTotalMemory(false); mem = GC.GetTotalMemory(false);
if(mem > results.MaxMemory) results.MaxMemory = mem; if(mem > results.MaxMemory) results.MaxMemory = mem;
if(mem < results.MinMemory) results.MinMemory = mem; if(mem < results.MinMemory) results.MinMemory = mem;
results.Entries.Add("SHA384", results.Entries.Add("SHA384",
new BenchmarkEntry new BenchmarkEntry
{ {
TimeSpan = (end - start).TotalSeconds, TimeSpan = (end - start).TotalSeconds,
Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds
}); });
results.SeparateTime += (end - start).TotalSeconds; results.SeparateTime += (end - start).TotalSeconds;
#endregion SHA384 #endregion SHA384
#region SHA512 #region SHA512
ctx = new Sha512Context(); ctx = new Sha512Context();
ctx.Init();
ms.Seek(0, SeekOrigin.Begin); ms.Seek(0, SeekOrigin.Begin);
mem = GC.GetTotalMemory(false); mem = GC.GetTotalMemory(false);
if(mem > results.MaxMemory) results.MaxMemory = mem; if(mem > results.MaxMemory) results.MaxMemory = mem;
if(mem < results.MinMemory) results.MinMemory = mem; if(mem < results.MinMemory) results.MinMemory = mem;
start = DateTime.Now; start = DateTime.Now;
InitProgress(); InitProgress();
for(int i = 0; i < bufferSize / blockSize; i++) for(int i = 0; i < bufferSize / blockSize; i++)
{ {
@@ -454,28 +443,27 @@ namespace DiscImageChef.Core
EndProgress(); EndProgress();
ctx.End(); ctx.End();
end = DateTime.Now; end = DateTime.Now;
mem = GC.GetTotalMemory(false); mem = GC.GetTotalMemory(false);
if(mem > results.MaxMemory) results.MaxMemory = mem; if(mem > results.MaxMemory) results.MaxMemory = mem;
if(mem < results.MinMemory) results.MinMemory = mem; if(mem < results.MinMemory) results.MinMemory = mem;
results.Entries.Add("SHA512", results.Entries.Add("SHA512",
new BenchmarkEntry new BenchmarkEntry
{ {
TimeSpan = (end - start).TotalSeconds, TimeSpan = (end - start).TotalSeconds,
Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds
}); });
results.SeparateTime += (end - start).TotalSeconds; results.SeparateTime += (end - start).TotalSeconds;
#endregion SHA512 #endregion SHA512
#region SpamSum #region SpamSum
ctx = new SpamSumContext(); ctx = new SpamSumContext();
ctx.Init();
ms.Seek(0, SeekOrigin.Begin); ms.Seek(0, SeekOrigin.Begin);
mem = GC.GetTotalMemory(false); mem = GC.GetTotalMemory(false);
if(mem > results.MaxMemory) results.MaxMemory = mem; if(mem > results.MaxMemory) results.MaxMemory = mem;
if(mem < results.MinMemory) results.MinMemory = mem; if(mem < results.MinMemory) results.MinMemory = mem;
start = DateTime.Now; start = DateTime.Now;
InitProgress(); InitProgress();
for(int i = 0; i < bufferSize / blockSize; i++) for(int i = 0; i < bufferSize / blockSize; i++)
{ {
@@ -487,16 +475,16 @@ namespace DiscImageChef.Core
EndProgress(); EndProgress();
ctx.End(); ctx.End();
end = DateTime.Now; end = DateTime.Now;
mem = GC.GetTotalMemory(false); mem = GC.GetTotalMemory(false);
if(mem > results.MaxMemory) results.MaxMemory = mem; if(mem > results.MaxMemory) results.MaxMemory = mem;
if(mem < results.MinMemory) results.MinMemory = mem; if(mem < results.MinMemory) results.MinMemory = mem;
results.Entries.Add("SpamSum", results.Entries.Add("SpamSum",
new BenchmarkEntry new BenchmarkEntry
{ {
TimeSpan = (end - start).TotalSeconds, TimeSpan = (end - start).TotalSeconds,
Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds Speed = bufferSize / 1048576.0 / (end - start).TotalSeconds
}); });
results.SeparateTime += (end - start).TotalSeconds; results.SeparateTime += (end - start).TotalSeconds;
#endregion SpamSum #endregion SpamSum
@@ -504,10 +492,10 @@ namespace DiscImageChef.Core
#region Entropy #region Entropy
ulong[] entTable = new ulong[256]; ulong[] entTable = new ulong[256];
ms.Seek(0, SeekOrigin.Begin); ms.Seek(0, SeekOrigin.Begin);
mem = GC.GetTotalMemory(false); mem = GC.GetTotalMemory(false);
if(mem > results.MaxMemory) results.MaxMemory = mem; if(mem > results.MaxMemory) results.MaxMemory = mem;
if(mem < results.MinMemory) results.MinMemory = mem; if(mem < results.MinMemory) results.MinMemory = mem;
start = DateTime.Now; start = DateTime.Now;
InitProgress(); InitProgress();
for(int i = 0; i < bufferSize / blockSize; i++) for(int i = 0; i < bufferSize / blockSize; i++)
{ {
@@ -518,20 +506,18 @@ namespace DiscImageChef.Core
} }
EndProgress(); EndProgress();
double entropy = entTable.Select(l => (double)l / (double)bufferSize)
.Select(frequency => -(frequency * Math.Log(frequency, 2))).Sum();
end = DateTime.Now; end = DateTime.Now;
mem = GC.GetTotalMemory(false); mem = GC.GetTotalMemory(false);
if(mem > results.MaxMemory) results.MaxMemory = mem; if(mem > results.MaxMemory) results.MaxMemory = mem;
if(mem < results.MinMemory) results.MinMemory = mem; if(mem < results.MinMemory) results.MinMemory = mem;
results.EntropyTime = (end - start).TotalSeconds; results.EntropyTime = (end - start).TotalSeconds;
results.EntropySpeed = bufferSize / 1048576.0 / (end - start).TotalSeconds; results.EntropySpeed = bufferSize / 1048576.0 / (end - start).TotalSeconds;
#endregion Entropy #endregion Entropy
#region Multitasking #region Multitasking
start = DateTime.Now; start = DateTime.Now;
Checksum allChecksums = new Checksum(); Checksum allChecksums = new Checksum();
InitProgress(); InitProgress();
for(int i = 0; i < bufferSize / blockSize; i++) for(int i = 0; i < bufferSize / blockSize; i++)
@@ -547,12 +533,12 @@ namespace DiscImageChef.Core
EndProgress(); EndProgress();
allChecksums.End(); allChecksums.End();
end = DateTime.Now; end = DateTime.Now;
mem = GC.GetTotalMemory(false); mem = GC.GetTotalMemory(false);
if(mem > results.MaxMemory) results.MaxMemory = mem; if(mem > results.MaxMemory) results.MaxMemory = mem;
if(mem < results.MinMemory) results.MinMemory = mem; if(mem < results.MinMemory) results.MinMemory = mem;
results.TotalTime = (end - start).TotalSeconds; results.TotalTime = (end - start).TotalSeconds;
results.TotalSpeed = bufferSize / 1048576.0 / results.TotalTime; results.TotalSpeed = bufferSize / 1048576.0 / results.TotalTime;
#endregion #endregion

View File

@@ -41,18 +41,18 @@ namespace DiscImageChef.Core
[Flags] [Flags]
public enum EnableChecksum public enum EnableChecksum
{ {
Adler32 = 1, Adler32 = 1,
Crc16 = 2, Crc16 = 2,
Crc32 = 4, Crc32 = 4,
Crc64 = 8, Crc64 = 8,
Md5 = 16, Md5 = 16,
Ripemd160 = 32, Ripemd160 = 32,
Sha1 = 64, Sha1 = 64,
Sha256 = 128, Sha256 = 128,
Sha384 = 256, Sha384 = 256,
Sha512 = 512, Sha512 = 512,
SpamSum = 1024, SpamSum = 1024,
All = Adler32 | Crc16 | Crc32 | Crc64 | Md5 | Ripemd160 | Sha1 | Sha256 | Sha384 | Sha512 | SpamSum All = Adler32 | Crc16 | Crc32 | Crc64 | Md5 | Ripemd160 | Sha1 | Sha256 | Sha384 | Sha512 | SpamSum
} }
/// <summary> /// <summary>
@@ -60,40 +60,40 @@ namespace DiscImageChef.Core
/// </summary> /// </summary>
public class Checksum public class Checksum
{ {
IChecksum adler32Ctx; IChecksum adler32Ctx;
HashPacket adlerPkt; HashPacket adlerPkt;
Thread adlerThread; Thread adlerThread;
IChecksum crc16Ctx; IChecksum crc16Ctx;
HashPacket crc16Pkt; HashPacket crc16Pkt;
Thread crc16Thread; Thread crc16Thread;
IChecksum crc32Ctx; IChecksum crc32Ctx;
HashPacket crc32Pkt; HashPacket crc32Pkt;
Thread crc32Thread; Thread crc32Thread;
IChecksum crc64Ctx; IChecksum crc64Ctx;
HashPacket crc64Pkt; HashPacket crc64Pkt;
Thread crc64Thread; Thread crc64Thread;
EnableChecksum enabled; EnableChecksum enabled;
IChecksum md5Ctx; IChecksum md5Ctx;
HashPacket md5Pkt; HashPacket md5Pkt;
Thread md5Thread; Thread md5Thread;
IChecksum ripemd160Ctx; IChecksum ripemd160Ctx;
HashPacket ripemd160Pkt; HashPacket ripemd160Pkt;
Thread ripemd160Thread; Thread ripemd160Thread;
IChecksum sha1Ctx; IChecksum sha1Ctx;
HashPacket sha1Pkt; HashPacket sha1Pkt;
Thread sha1Thread; Thread sha1Thread;
IChecksum sha256Ctx; IChecksum sha256Ctx;
HashPacket sha256Pkt; HashPacket sha256Pkt;
Thread sha256Thread; Thread sha256Thread;
IChecksum sha384Ctx; IChecksum sha384Ctx;
HashPacket sha384Pkt; HashPacket sha384Pkt;
Thread sha384Thread; Thread sha384Thread;
IChecksum sha512Ctx; IChecksum sha512Ctx;
HashPacket sha512Pkt; HashPacket sha512Pkt;
Thread sha512Thread; Thread sha512Thread;
HashPacket spamsumPkt; HashPacket spamsumPkt;
Thread spamsumThread; Thread spamsumThread;
IChecksum ssctx; IChecksum ssctx;
public Checksum(EnableChecksum enabled = EnableChecksum.All) public Checksum(EnableChecksum enabled = EnableChecksum.All)
{ {
@@ -102,102 +102,80 @@ namespace DiscImageChef.Core
if(enabled.HasFlag(EnableChecksum.Adler32)) if(enabled.HasFlag(EnableChecksum.Adler32))
{ {
adler32Ctx = new Adler32Context(); adler32Ctx = new Adler32Context();
adlerPkt = new HashPacket(); adlerPkt = new HashPacket {Context = adler32Ctx};
adler32Ctx.Init();
adlerPkt.Context = adler32Ctx;
} }
if(enabled.HasFlag(EnableChecksum.Crc16)) if(enabled.HasFlag(EnableChecksum.Crc16))
{ {
crc16Ctx = new Crc16Context(); crc16Ctx = new Crc16Context();
crc16Pkt = new HashPacket(); crc16Pkt = new HashPacket {Context = crc16Ctx};
crc16Ctx.Init();
crc16Pkt.Context = crc16Ctx;
} }
if(enabled.HasFlag(EnableChecksum.Crc32)) if(enabled.HasFlag(EnableChecksum.Crc32))
{ {
crc32Ctx = new Crc32Context(); crc32Ctx = new Crc32Context();
crc32Pkt = new HashPacket(); crc32Pkt = new HashPacket {Context = crc32Ctx};
crc32Ctx.Init();
crc32Pkt.Context = crc32Ctx;
} }
if(enabled.HasFlag(EnableChecksum.Crc64)) if(enabled.HasFlag(EnableChecksum.Crc64))
{ {
crc64Ctx = new Crc64Context(); crc64Ctx = new Crc64Context();
crc64Pkt = new HashPacket(); crc64Pkt = new HashPacket {Context = crc64Ctx};
crc64Ctx.Init();
crc64Pkt.Context = crc64Ctx;
} }
if(enabled.HasFlag(EnableChecksum.Md5)) if(enabled.HasFlag(EnableChecksum.Md5))
{ {
md5Ctx = new Md5Context(); md5Ctx = new Md5Context();
md5Pkt = new HashPacket(); md5Pkt = new HashPacket {Context = md5Ctx};
md5Ctx.Init();
md5Pkt.Context = md5Ctx;
} }
if(enabled.HasFlag(EnableChecksum.Ripemd160)) if(enabled.HasFlag(EnableChecksum.Ripemd160))
{ {
ripemd160Ctx = new Ripemd160Context(); ripemd160Ctx = new Ripemd160Context();
ripemd160Pkt = new HashPacket(); ripemd160Pkt = new HashPacket {Context = ripemd160Ctx};
ripemd160Ctx.Init();
ripemd160Pkt.Context = ripemd160Ctx;
} }
if(enabled.HasFlag(EnableChecksum.Sha1)) if(enabled.HasFlag(EnableChecksum.Sha1))
{ {
sha1Ctx = new Sha1Context(); sha1Ctx = new Sha1Context();
sha1Pkt = new HashPacket(); sha1Pkt = new HashPacket {Context = sha1Ctx};
sha1Ctx.Init();
sha1Pkt.Context = sha1Ctx;
} }
if(enabled.HasFlag(EnableChecksum.Sha256)) if(enabled.HasFlag(EnableChecksum.Sha256))
{ {
sha256Ctx = new Sha256Context(); sha256Ctx = new Sha256Context();
sha256Pkt = new HashPacket(); sha256Pkt = new HashPacket {Context = sha256Ctx};
sha256Ctx.Init();
sha256Pkt.Context = sha256Ctx;
} }
if(enabled.HasFlag(EnableChecksum.Sha384)) if(enabled.HasFlag(EnableChecksum.Sha384))
{ {
sha384Ctx = new Sha384Context(); sha384Ctx = new Sha384Context();
sha384Pkt = new HashPacket(); sha384Pkt = new HashPacket {Context = sha384Ctx};
sha384Ctx.Init();
sha384Pkt.Context = sha384Ctx;
} }
if(enabled.HasFlag(EnableChecksum.Sha512)) if(enabled.HasFlag(EnableChecksum.Sha512))
{ {
sha512Ctx = new Sha512Context(); sha512Ctx = new Sha512Context();
sha512Pkt = new HashPacket(); sha512Pkt = new HashPacket {Context = sha512Ctx};
sha512Ctx.Init();
sha512Pkt.Context = sha512Ctx;
} }
if(enabled.HasFlag(EnableChecksum.SpamSum)) if(enabled.HasFlag(EnableChecksum.SpamSum))
{ {
ssctx = new SpamSumContext(); ssctx = new SpamSumContext();
spamsumPkt = new HashPacket(); spamsumPkt = new HashPacket {Context = ssctx};
ssctx.Init();
spamsumPkt.Context = ssctx;
} }
adlerThread = new Thread(UpdateHash); adlerThread = new Thread(UpdateHash);
crc16Thread = new Thread(UpdateHash); crc16Thread = new Thread(UpdateHash);
crc32Thread = new Thread(UpdateHash); crc32Thread = new Thread(UpdateHash);
crc64Thread = new Thread(UpdateHash); crc64Thread = new Thread(UpdateHash);
md5Thread = new Thread(UpdateHash); md5Thread = new Thread(UpdateHash);
ripemd160Thread = new Thread(UpdateHash); ripemd160Thread = new Thread(UpdateHash);
sha1Thread = new Thread(UpdateHash); sha1Thread = new Thread(UpdateHash);
sha256Thread = new Thread(UpdateHash); sha256Thread = new Thread(UpdateHash);
sha384Thread = new Thread(UpdateHash); sha384Thread = new Thread(UpdateHash);
sha512Thread = new Thread(UpdateHash); sha512Thread = new Thread(UpdateHash);
spamsumThread = new Thread(UpdateHash); spamsumThread = new Thread(UpdateHash);
} }
public void Update(byte[] data) public void Update(byte[] data)
@@ -213,6 +191,7 @@ namespace DiscImageChef.Core
crc16Pkt.Data = data; crc16Pkt.Data = data;
crc16Thread.Start(crc16Pkt); crc16Thread.Start(crc16Pkt);
} }
if(enabled.HasFlag(EnableChecksum.Crc32)) if(enabled.HasFlag(EnableChecksum.Crc32))
{ {
crc32Pkt.Data = data; crc32Pkt.Data = data;
@@ -267,21 +246,21 @@ namespace DiscImageChef.Core
spamsumThread.Start(spamsumPkt); spamsumThread.Start(spamsumPkt);
} }
while(adlerThread.IsAlive || crc16Thread.IsAlive || crc32Thread.IsAlive || crc64Thread.IsAlive || while(adlerThread.IsAlive || crc16Thread.IsAlive || crc32Thread.IsAlive || crc64Thread.IsAlive ||
md5Thread.IsAlive || ripemd160Thread.IsAlive || sha1Thread.IsAlive || sha256Thread.IsAlive || md5Thread.IsAlive || ripemd160Thread.IsAlive || sha1Thread.IsAlive || sha256Thread.IsAlive ||
sha384Thread.IsAlive || sha512Thread.IsAlive || spamsumThread.IsAlive) { } sha384Thread.IsAlive || sha512Thread.IsAlive || spamsumThread.IsAlive) { }
if(enabled.HasFlag(EnableChecksum.SpamSum)) adlerThread = new Thread(UpdateHash); if(enabled.HasFlag(EnableChecksum.SpamSum)) adlerThread = new Thread(UpdateHash);
if(enabled.HasFlag(EnableChecksum.SpamSum)) crc16Thread = new Thread(UpdateHash); if(enabled.HasFlag(EnableChecksum.SpamSum)) crc16Thread = new Thread(UpdateHash);
if(enabled.HasFlag(EnableChecksum.SpamSum)) crc32Thread = new Thread(UpdateHash); if(enabled.HasFlag(EnableChecksum.SpamSum)) crc32Thread = new Thread(UpdateHash);
if(enabled.HasFlag(EnableChecksum.SpamSum)) crc64Thread = new Thread(UpdateHash); if(enabled.HasFlag(EnableChecksum.SpamSum)) crc64Thread = new Thread(UpdateHash);
if(enabled.HasFlag(EnableChecksum.SpamSum)) md5Thread = new Thread(UpdateHash); if(enabled.HasFlag(EnableChecksum.SpamSum)) md5Thread = new Thread(UpdateHash);
if(enabled.HasFlag(EnableChecksum.SpamSum)) ripemd160Thread = new Thread(UpdateHash); if(enabled.HasFlag(EnableChecksum.SpamSum)) ripemd160Thread = new Thread(UpdateHash);
if(enabled.HasFlag(EnableChecksum.SpamSum)) sha1Thread = new Thread(UpdateHash); if(enabled.HasFlag(EnableChecksum.SpamSum)) sha1Thread = new Thread(UpdateHash);
if(enabled.HasFlag(EnableChecksum.SpamSum)) sha256Thread = new Thread(UpdateHash); if(enabled.HasFlag(EnableChecksum.SpamSum)) sha256Thread = new Thread(UpdateHash);
if(enabled.HasFlag(EnableChecksum.SpamSum)) sha384Thread = new Thread(UpdateHash); if(enabled.HasFlag(EnableChecksum.SpamSum)) sha384Thread = new Thread(UpdateHash);
if(enabled.HasFlag(EnableChecksum.SpamSum)) sha512Thread = new Thread(UpdateHash); if(enabled.HasFlag(EnableChecksum.SpamSum)) sha512Thread = new Thread(UpdateHash);
if(enabled.HasFlag(EnableChecksum.SpamSum)) spamsumThread = new Thread(UpdateHash); if(enabled.HasFlag(EnableChecksum.SpamSum)) spamsumThread = new Thread(UpdateHash);
} }
public List<ChecksumType> End() public List<ChecksumType> End()
@@ -360,147 +339,114 @@ namespace DiscImageChef.Core
internal static List<ChecksumType> GetChecksums(byte[] data, EnableChecksum enabled = EnableChecksum.All) internal static List<ChecksumType> GetChecksums(byte[] data, EnableChecksum enabled = EnableChecksum.All)
{ {
IChecksum adler32CtxData = null; IChecksum adler32CtxData = null;
IChecksum crc16CtxData = null; IChecksum crc16CtxData = null;
IChecksum crc32CtxData = null; IChecksum crc32CtxData = null;
IChecksum crc64CtxData = null; IChecksum crc64CtxData = null;
IChecksum md5CtxData = null; IChecksum md5CtxData = null;
IChecksum ripemd160CtxData = null; IChecksum ripemd160CtxData = null;
IChecksum sha1CtxData = null; IChecksum sha1CtxData = null;
IChecksum sha256CtxData = null; IChecksum sha256CtxData = null;
IChecksum sha384CtxData = null; IChecksum sha384CtxData = null;
IChecksum sha512CtxData = null; IChecksum sha512CtxData = null;
IChecksum ssctxData = null; IChecksum ssctxData = null;
Thread adlerThreadData = new Thread(UpdateHash); Thread adlerThreadData = new Thread(UpdateHash);
Thread crc16ThreadData = new Thread(UpdateHash); Thread crc16ThreadData = new Thread(UpdateHash);
Thread crc32ThreadData = new Thread(UpdateHash); Thread crc32ThreadData = new Thread(UpdateHash);
Thread crc64ThreadData = new Thread(UpdateHash); Thread crc64ThreadData = new Thread(UpdateHash);
Thread md5ThreadData = new Thread(UpdateHash); Thread md5ThreadData = new Thread(UpdateHash);
Thread ripemd160ThreadData = new Thread(UpdateHash); Thread ripemd160ThreadData = new Thread(UpdateHash);
Thread sha1ThreadData = new Thread(UpdateHash); Thread sha1ThreadData = new Thread(UpdateHash);
Thread sha256ThreadData = new Thread(UpdateHash); Thread sha256ThreadData = new Thread(UpdateHash);
Thread sha384ThreadData = new Thread(UpdateHash); Thread sha384ThreadData = new Thread(UpdateHash);
Thread sha512ThreadData = new Thread(UpdateHash); Thread sha512ThreadData = new Thread(UpdateHash);
Thread spamsumThreadData = new Thread(UpdateHash); Thread spamsumThreadData = new Thread(UpdateHash);
if(enabled.HasFlag(EnableChecksum.SpamSum)) if(enabled.HasFlag(EnableChecksum.SpamSum))
{ {
adler32CtxData = new Adler32Context(); adler32CtxData = new Adler32Context();
HashPacket adlerPktData = new HashPacket(); HashPacket adlerPktData = new HashPacket {Context = adler32CtxData, Data = data};
adler32CtxData.Init();
adlerPktData.Context = adler32CtxData;
adlerPktData.Data = data;
adlerThreadData.Start(adlerPktData); adlerThreadData.Start(adlerPktData);
} }
if(enabled.HasFlag(EnableChecksum.SpamSum)) if(enabled.HasFlag(EnableChecksum.SpamSum))
{ {
HashPacket crc16PktData = new HashPacket(); crc16CtxData = new Crc16Context();
crc16CtxData = new Crc16Context(); HashPacket crc16PktData = new HashPacket {Context = crc16CtxData, Data = data};
crc16CtxData.Init();
crc16PktData.Context = crc16CtxData;
crc16PktData.Data = data;
crc16ThreadData.Start(crc16PktData); crc16ThreadData.Start(crc16PktData);
} }
if(enabled.HasFlag(EnableChecksum.SpamSum)) if(enabled.HasFlag(EnableChecksum.SpamSum))
{ {
HashPacket crc32PktData = new HashPacket(); crc32CtxData = new Crc32Context();
crc32CtxData = new Crc32Context(); HashPacket crc32PktData = new HashPacket {Context = crc32CtxData, Data = data};
crc32CtxData.Init();
crc32PktData.Context = crc32CtxData;
crc32PktData.Data = data;
crc32ThreadData.Start(crc32PktData); crc32ThreadData.Start(crc32PktData);
} }
if(enabled.HasFlag(EnableChecksum.SpamSum)) if(enabled.HasFlag(EnableChecksum.SpamSum))
{ {
HashPacket crc64PktData = new HashPacket(); crc64CtxData = new Crc64Context();
crc64CtxData = new Crc64Context(); HashPacket crc64PktData = new HashPacket {Context = crc64CtxData, Data = data};
crc64CtxData.Init();
crc64PktData.Context = crc64CtxData;
crc64PktData.Data = data;
crc64ThreadData.Start(crc64PktData); crc64ThreadData.Start(crc64PktData);
} }
if(enabled.HasFlag(EnableChecksum.SpamSum)) if(enabled.HasFlag(EnableChecksum.SpamSum))
{ {
HashPacket md5PktData = new HashPacket(); md5CtxData = new Md5Context();
md5CtxData = new Md5Context(); HashPacket md5PktData = new HashPacket {Context = md5CtxData, Data = data};
md5CtxData.Init();
md5PktData.Context = md5CtxData;
md5PktData.Data = data;
md5ThreadData.Start(md5PktData); md5ThreadData.Start(md5PktData);
} }
if(enabled.HasFlag(EnableChecksum.SpamSum)) if(enabled.HasFlag(EnableChecksum.SpamSum))
{ {
HashPacket ripemd160PktData = new HashPacket(); ripemd160CtxData = new Ripemd160Context();
ripemd160CtxData = new Ripemd160Context(); HashPacket ripemd160PktData = new HashPacket {Context = ripemd160CtxData, Data = data};
ripemd160CtxData.Init();
ripemd160PktData.Context = ripemd160CtxData;
ripemd160PktData.Data = data;
ripemd160ThreadData.Start(ripemd160PktData); ripemd160ThreadData.Start(ripemd160PktData);
} }
if(enabled.HasFlag(EnableChecksum.SpamSum)) if(enabled.HasFlag(EnableChecksum.SpamSum))
{ {
HashPacket sha1PktData = new HashPacket(); sha1CtxData = new Sha1Context();
sha1CtxData = new Sha1Context(); HashPacket sha1PktData = new HashPacket {Context = sha1CtxData, Data = data};
sha1CtxData.Init();
sha1PktData.Context = sha1CtxData;
sha1PktData.Data = data;
sha1ThreadData.Start(sha1PktData); sha1ThreadData.Start(sha1PktData);
} }
if(enabled.HasFlag(EnableChecksum.SpamSum)) if(enabled.HasFlag(EnableChecksum.SpamSum))
{ {
HashPacket sha256PktData = new HashPacket(); sha256CtxData = new Sha256Context();
sha256CtxData = new Sha256Context(); HashPacket sha256PktData = new HashPacket {Context = sha256CtxData, Data = data};
sha256CtxData.Init();
sha256PktData.Context = sha256CtxData;
sha256PktData.Data = data;
sha256ThreadData.Start(sha256PktData); sha256ThreadData.Start(sha256PktData);
} }
if(enabled.HasFlag(EnableChecksum.SpamSum)) if(enabled.HasFlag(EnableChecksum.SpamSum))
{ {
HashPacket sha384PktData = new HashPacket(); sha384CtxData = new Sha384Context();
sha384CtxData = new Sha384Context(); HashPacket sha384PktData = new HashPacket {Context = sha384CtxData, Data = data};
sha384CtxData.Init();
sha384PktData.Context = sha384CtxData;
sha384PktData.Data = data;
sha384ThreadData.Start(sha384PktData); sha384ThreadData.Start(sha384PktData);
} }
if(enabled.HasFlag(EnableChecksum.SpamSum)) if(enabled.HasFlag(EnableChecksum.SpamSum))
{ {
HashPacket sha512PktData = new HashPacket(); sha512CtxData = new Sha512Context();
sha512CtxData = new Sha512Context(); HashPacket sha512PktData = new HashPacket {Context = sha512CtxData, Data = data};
sha512CtxData.Init();
sha512PktData.Context = sha512CtxData;
sha512PktData.Data = data;
sha512ThreadData.Start(sha512PktData); sha512ThreadData.Start(sha512PktData);
} }
if(enabled.HasFlag(EnableChecksum.SpamSum)) if(enabled.HasFlag(EnableChecksum.SpamSum))
{ {
HashPacket spamsumPktData = new HashPacket(); ssctxData = new SpamSumContext();
ssctxData = new SpamSumContext(); HashPacket spamsumPktData = new HashPacket {Context = ssctxData, Data = data};
ssctxData.Init();
spamsumPktData.Context = ssctxData;
spamsumPktData.Data = data;
spamsumThreadData.Start(spamsumPktData); spamsumThreadData.Start(spamsumPktData);
} }
while(adlerThreadData.IsAlive || crc16ThreadData.IsAlive || crc32ThreadData.IsAlive || while(adlerThreadData.IsAlive || crc16ThreadData.IsAlive || crc32ThreadData.IsAlive ||
crc64ThreadData.IsAlive || md5ThreadData.IsAlive || ripemd160ThreadData.IsAlive || crc64ThreadData.IsAlive || md5ThreadData.IsAlive || ripemd160ThreadData.IsAlive ||
sha1ThreadData.IsAlive || sha256ThreadData.IsAlive || sha384ThreadData.IsAlive || sha1ThreadData.IsAlive || sha256ThreadData.IsAlive || sha384ThreadData.IsAlive ||
sha512ThreadData.IsAlive || spamsumThreadData.IsAlive) { } sha512ThreadData.IsAlive || spamsumThreadData.IsAlive) { }
List<ChecksumType> dataChecksums = new List<ChecksumType>(); List<ChecksumType> dataChecksums = new List<ChecksumType>();
ChecksumType chk; ChecksumType chk;
if(enabled.HasFlag(EnableChecksum.Adler32)) if(enabled.HasFlag(EnableChecksum.Adler32))
{ {
@@ -574,7 +520,7 @@ namespace DiscImageChef.Core
struct HashPacket struct HashPacket
{ {
public IChecksum Context; public IChecksum Context;
public byte[] Data; public byte[] Data;
} }
static void UpdateHash(object packet) static void UpdateHash(object packet)

View File

@@ -1318,7 +1318,6 @@ namespace DiscImageChef.DiscImages
if(mapVersion >= 3) if(mapVersion >= 3)
{ {
Sha1Context sha1Ctx = new Sha1Context(); Sha1Context sha1Ctx = new Sha1Context();
sha1Ctx.Init();
for(uint i = 0; i < totalHunks; i++) sha1Ctx.Update(GetHunk(i)); for(uint i = 0; i < totalHunks; i++) sha1Ctx.Update(GetHunk(i));
calculated = sha1Ctx.Final(); calculated = sha1Ctx.Final();
@@ -1326,7 +1325,6 @@ namespace DiscImageChef.DiscImages
else else
{ {
Md5Context md5Ctx = new Md5Context(); Md5Context md5Ctx = new Md5Context();
md5Ctx.Init();
for(uint i = 0; i < totalHunks; i++) md5Ctx.Update(GetHunk(i)); for(uint i = 0; i < totalHunks; i++) md5Ctx.Update(GetHunk(i));
calculated = md5Ctx.Final(); calculated = md5Ctx.Final();
@@ -1713,7 +1711,7 @@ namespace DiscImageChef.DiscImages
if(!sectorCache.TryGetValue(sectorAddress, out byte[] sector)) if(!sectorCache.TryGetValue(sectorAddress, out byte[] sector))
{ {
track = GetTrack(sectorAddress); track = GetTrack(sectorAddress);
uint sectorSize = (uint)track.TrackRawBytesPerSector; uint sectorSize = (uint)track.TrackRawBytesPerSector;
ulong hunkNo = sectorAddress / sectorsPerHunk; ulong hunkNo = sectorAddress / sectorsPerHunk;

View File

@@ -1770,7 +1770,6 @@ namespace DiscImageChef.DiscImages
Marshal.FreeHGlobal(structurePointer); Marshal.FreeHGlobal(structurePointer);
crcVerify = new Crc64Context(); crcVerify = new Crc64Context();
crcVerify.Init();
readBytes = 0; readBytes = 0;
DicConsole.DebugWriteLine("DiscImageChef format plugin", DicConsole.DebugWriteLine("DiscImageChef format plugin",
@@ -1807,7 +1806,6 @@ namespace DiscImageChef.DiscImages
Marshal.FreeHGlobal(structurePointer); Marshal.FreeHGlobal(structurePointer);
crcVerify = new Crc64Context(); crcVerify = new Crc64Context();
crcVerify.Init();
readBytes = 0; readBytes = 0;
DicConsole.DebugWriteLine("DiscImageChef format plugin", DicConsole.DebugWriteLine("DiscImageChef format plugin",
@@ -2524,29 +2522,13 @@ namespace DiscImageChef.DiscImages
imageStream.WriteByte(0); imageStream.WriteByte(0);
} }
if(doMd5) if(doMd5) md5Provider = new Md5Context();
{
md5Provider = new Md5Context();
md5Provider.Init();
}
if(doSha1) if(doSha1) sha1Provider = new Sha1Context();
{
sha1Provider = new Sha1Context();
sha1Provider.Init();
}
if(doSha256) if(doSha256) sha256Provider = new Sha256Context();
{
sha256Provider = new Sha256Context();
sha256Provider.Init();
}
if(doSpamsum) if(doSpamsum) spamsumProvider = new SpamSumContext();
{
spamsumProvider = new SpamSumContext();
spamsumProvider.Init();
}
} }
DicConsole.DebugWriteLine("DiscImageChef format plugin", "In memory DDT?: {0}", inMemoryDdt); DicConsole.DebugWriteLine("DiscImageChef format plugin", "In memory DDT?: {0}", inMemoryDdt);
@@ -2689,7 +2671,6 @@ namespace DiscImageChef.DiscImages
currentBlockHeader.crc64 = BitConverter.ToUInt64(crc64.Final(), 0); currentBlockHeader.crc64 = BitConverter.ToUInt64(crc64.Final(), 0);
Crc64Context cmpCrc64Context = new Crc64Context(); Crc64Context cmpCrc64Context = new Crc64Context();
cmpCrc64Context.Init();
byte[] lzmaProperties = new byte[0]; byte[] lzmaProperties = new byte[0];
@@ -2777,7 +2758,6 @@ namespace DiscImageChef.DiscImages
flakeWriter = new FlakeWriter("", blockStream, flakeWriterSettings) {DoSeekTable = false}; flakeWriter = new FlakeWriter("", blockStream, flakeWriterSettings) {DoSeekTable = false};
else lzmaBlockStream = new LzmaStream(lzmaEncoderProperties, false, blockStream); else lzmaBlockStream = new LzmaStream(lzmaEncoderProperties, false, blockStream);
crc64 = new Crc64Context(); crc64 = new Crc64Context();
crc64.Init();
} }
ulong ddtEntry = (ulong)((imageStream.Position << shift) + currentBlockOffset); ulong ddtEntry = (ulong)((imageStream.Position << shift) + currentBlockOffset);
@@ -3111,7 +3091,6 @@ namespace DiscImageChef.DiscImages
currentBlockHeader.crc64 = BitConverter.ToUInt64(crc64.Final(), 0); currentBlockHeader.crc64 = BitConverter.ToUInt64(crc64.Final(), 0);
Crc64Context cmpCrc64Context = new Crc64Context(); Crc64Context cmpCrc64Context = new Crc64Context();
cmpCrc64Context.Init();
byte[] lzmaProperties = new byte[0]; byte[] lzmaProperties = new byte[0];
@@ -3227,7 +3206,6 @@ namespace DiscImageChef.DiscImages
{ {
tagData = blockStream.ToArray(); tagData = blockStream.ToArray();
Crc64Context crc64Ctx = new Crc64Context(); Crc64Context crc64Ctx = new Crc64Context();
crc64Ctx.Init();
crc64Ctx.Update(lzmaProperties); crc64Ctx.Update(lzmaProperties);
crc64Ctx.Update(tagData); crc64Ctx.Update(tagData);
tagCrc = crc64Ctx.Final(); tagCrc = crc64Ctx.Final();
@@ -3569,7 +3547,6 @@ namespace DiscImageChef.DiscImages
blockStream = new MemoryStream(); blockStream = new MemoryStream();
lzmaBlockStream = new LzmaStream(lzmaEncoderProperties, false, blockStream); lzmaBlockStream = new LzmaStream(lzmaEncoderProperties, false, blockStream);
crc64 = new Crc64Context(); crc64 = new Crc64Context();
crc64.Init();
for(ulong i = 0; i < (ulong)userDataDdt.LongLength; i++) for(ulong i = 0; i < (ulong)userDataDdt.LongLength; i++)
{ {
byte[] ddtEntry = BitConverter.GetBytes(userDataDdt[i]); byte[] ddtEntry = BitConverter.GetBytes(userDataDdt[i]);
@@ -3581,7 +3558,6 @@ namespace DiscImageChef.DiscImages
lzmaBlockStream.Close(); lzmaBlockStream.Close();
ddtHeader.cmpLength = (uint)blockStream.Length + LZMA_PROPERTIES_LENGTH; ddtHeader.cmpLength = (uint)blockStream.Length + LZMA_PROPERTIES_LENGTH;
Crc64Context cmpCrc64Context = new Crc64Context(); Crc64Context cmpCrc64Context = new Crc64Context();
cmpCrc64Context.Init();
cmpCrc64Context.Update(lzmaProperties); cmpCrc64Context.Update(lzmaProperties);
cmpCrc64Context.Update(blockStream.ToArray()); cmpCrc64Context.Update(blockStream.ToArray());
ddtHeader.cmpCrc64 = BitConverter.ToUInt64(cmpCrc64Context.Final(), 0); ddtHeader.cmpCrc64 = BitConverter.ToUInt64(cmpCrc64Context.Final(), 0);
@@ -3629,15 +3605,15 @@ namespace DiscImageChef.DiscImages
crc64 = BitConverter.ToUInt64(blockCrc, 0), crc64 = BitConverter.ToUInt64(blockCrc, 0),
sectorSize = 16 sectorSize = 16
}; };
byte[] lzmaProperties = null; byte[] lzmaProperties = null;
if(nocompress) if(nocompress)
{ {
prefixBlock.compression = CompressionType.None; prefixBlock.compression = CompressionType.None;
prefixBlock.cmpCrc64 = prefixBlock.crc64; prefixBlock.cmpCrc64 = prefixBlock.crc64;
prefixBlock.cmpLength = prefixBlock.length; prefixBlock.cmpLength = prefixBlock.length;
blockStream = new MemoryStream(sectorPrefix); blockStream = new MemoryStream(sectorPrefix);
} }
else else
{ {
@@ -3664,7 +3640,6 @@ namespace DiscImageChef.DiscImages
if(prefixBlock.compression == CompressionType.Lzma) if(prefixBlock.compression == CompressionType.Lzma)
imageStream.Write(lzmaProperties, 0, lzmaProperties.Length); imageStream.Write(lzmaProperties, 0, lzmaProperties.Length);
imageStream.Write(blockStream.ToArray(), 0, (int)blockStream.Length); imageStream.Write(blockStream.ToArray(), 0, (int)blockStream.Length);
index.RemoveAll(t => t.blockType == BlockType.DataBlock && index.RemoveAll(t => t.blockType == BlockType.DataBlock &&
t.dataType == DataType.CdSectorPrefix); t.dataType == DataType.CdSectorPrefix);
@@ -3762,7 +3737,7 @@ namespace DiscImageChef.DiscImages
subchannelBlock.compression = CompressionType.None; subchannelBlock.compression = CompressionType.None;
subchannelBlock.cmpCrc64 = subchannelBlock.crc64; subchannelBlock.cmpCrc64 = subchannelBlock.crc64;
subchannelBlock.cmpLength = subchannelBlock.length; subchannelBlock.cmpLength = subchannelBlock.length;
blockStream = new MemoryStream(sectorSubchannel); blockStream = new MemoryStream(sectorSubchannel);
} }
else else
{ {
@@ -3928,7 +3903,7 @@ namespace DiscImageChef.DiscImages
} }
byte[] lzmaProperties = null; byte[] lzmaProperties = null;
if(nocompress) if(nocompress)
{ {
subchannelBlock.compression = CompressionType.None; subchannelBlock.compression = CompressionType.None;

View File

@@ -774,9 +774,7 @@ namespace DiscImageChef.DiscImages
currentChunk = new BlockChunk(); currentChunk = new BlockChunk();
currentSector = 0; currentSector = 0;
dataForkChecksum = new Crc32Context(); dataForkChecksum = new Crc32Context();
dataForkChecksum.Init(); masterChecksum = new Crc32Context();
masterChecksum = new Crc32Context();
masterChecksum.Init();
IsWriting = true; IsWriting = true;
ErrorMessage = null; ErrorMessage = null;

View File

@@ -370,7 +370,6 @@ namespace DiscImageChef.DiscImages
thisDateTime = thisDateTime.AddSeconds(thisFooter.Timestamp); thisDateTime = thisDateTime.AddSeconds(thisFooter.Timestamp);
Sha1Context sha1Ctx = new Sha1Context(); Sha1Context sha1Ctx = new Sha1Context();
sha1Ctx.Init();
sha1Ctx.Update(thisFooter.Reserved); sha1Ctx.Update(thisFooter.Reserved);
DicConsole.DebugWriteLine("VirtualPC plugin", "footer.cookie = 0x{0:X8}", thisFooter.Cookie); DicConsole.DebugWriteLine("VirtualPC plugin", "footer.cookie = 0x{0:X8}", thisFooter.Cookie);
@@ -590,7 +589,6 @@ namespace DiscImageChef.DiscImages
parentDateTime = parentDateTime.AddSeconds(thisDynamic.ParentTimestamp); parentDateTime = parentDateTime.AddSeconds(thisDynamic.ParentTimestamp);
sha1Ctx = new Sha1Context(); sha1Ctx = new Sha1Context();
sha1Ctx.Init();
sha1Ctx.Update(thisDynamic.Reserved2); sha1Ctx.Update(thisDynamic.Reserved2);
DicConsole.DebugWriteLine("VirtualPC plugin", "dynamic.cookie = 0x{0:X8}", thisDynamic.Cookie); DicConsole.DebugWriteLine("VirtualPC plugin", "dynamic.cookie = 0x{0:X8}", thisDynamic.Cookie);

View File

@@ -44,16 +44,16 @@ namespace DiscImageChef.Filesystems
{ {
public class AmigaDOSPlugin : IFilesystem public class AmigaDOSPlugin : IFilesystem
{ {
const uint FFS_MASK = 0x444F5300; const uint FFS_MASK = 0x444F5300;
const uint MUFS_MASK = 0x6D754600; const uint MUFS_MASK = 0x6D754600;
const uint TYPE_HEADER = 2; const uint TYPE_HEADER = 2;
const uint SUBTYPE_ROOT = 1; const uint SUBTYPE_ROOT = 1;
public FileSystemType XmlFsType { get; private set; } public FileSystemType XmlFsType { get; private set; }
public string Name => "Amiga DOS filesystem"; public string Name => "Amiga DOS filesystem";
public Guid Id => new Guid("3c882400-208c-427d-a086-9119852a1bc7"); public Guid Id => new Guid("3c882400-208c-427d-a086-9119852a1bc7");
public Encoding Encoding { get; private set; } public Encoding Encoding { get; private set; }
public bool Identify(IMediaImage imagePlugin, Partition partition) public bool Identify(IMediaImage imagePlugin, Partition partition)
{ {
@@ -67,15 +67,15 @@ namespace DiscImageChef.Filesystems
// However while you can set a block size different from the sector size on formatting, the bootblock block // However while you can set a block size different from the sector size on formatting, the bootblock block
// size for floppies is the sector size, and for RDB is usually is the hard disk sector size, // size for floppies is the sector size, and for RDB is usually is the hard disk sector size,
// so this is not entirely wrong... // so this is not entirely wrong...
byte[] sector = imagePlugin.ReadSectors(0 + partition.Start, 2); byte[] sector = imagePlugin.ReadSectors(0 + partition.Start, 2);
BootBlock bblk = BigEndianMarshal.ByteArrayToStructureBigEndian<BootBlock>(sector); BootBlock bblk = BigEndianMarshal.ByteArrayToStructureBigEndian<BootBlock>(sector);
// AROS boot floppies... // AROS boot floppies...
if(sector.Length >= 512 && sector[510] == 0x55 && sector[511] == 0xAA && if(sector.Length >= 512 && sector[510] == 0x55 && sector[511] == 0xAA &&
(bblk.diskType & FFS_MASK) != FFS_MASK && (bblk.diskType & MUFS_MASK) != MUFS_MASK) (bblk.diskType & FFS_MASK) != FFS_MASK && (bblk.diskType & MUFS_MASK) != MUFS_MASK)
{ {
sector = imagePlugin.ReadSectors(1 + partition.Start, 2); sector = imagePlugin.ReadSectors(1 + partition.Start, 2);
bblk = BigEndianMarshal.ByteArrayToStructureBigEndian<BootBlock>(sector); bblk = BigEndianMarshal.ByteArrayToStructureBigEndian<BootBlock>(sector);
} }
// Not FFS or MuFS? // Not FFS or MuFS?
@@ -86,7 +86,7 @@ namespace DiscImageChef.Filesystems
uint bsum = AmigaBootChecksum(sector); uint bsum = AmigaBootChecksum(sector);
DicConsole.DebugWriteLine("AmigaDOS plugin", "bblk.checksum = 0x{0:X8}", bblk.checksum); DicConsole.DebugWriteLine("AmigaDOS plugin", "bblk.checksum = 0x{0:X8}", bblk.checksum);
DicConsole.DebugWriteLine("AmigaDOS plugin", "bsum = 0x{0:X8}", bsum); DicConsole.DebugWriteLine("AmigaDOS plugin", "bsum = 0x{0:X8}", bsum);
ulong bRootPtr = 0; ulong bRootPtr = 0;
@@ -99,10 +99,10 @@ namespace DiscImageChef.Filesystems
ulong[] rootPtrs = ulong[] rootPtrs =
{ {
bRootPtr + partition.Start, (partition.End - partition.Start + 1) / 2 + partition.Start - 2, bRootPtr + partition.Start, (partition.End - partition.Start + 1) / 2 + partition.Start - 2,
(partition.End - partition.Start + 1) / 2 + partition.Start - 1, (partition.End - partition.Start + 1) / 2 + partition.Start - 1,
(partition.End - partition.Start + 1) / 2 + partition.Start, (partition.End - partition.Start + 1) / 2 + partition.Start,
(partition.End - partition.Start + 1) / 2 + partition.Start + 4 (partition.End - partition.Start + 1) / 2 + partition.Start + 4
}; };
RootBlock rblk = new RootBlock(); RootBlock rblk = new RootBlock();
@@ -122,10 +122,10 @@ namespace DiscImageChef.Filesystems
DicConsole.DebugWriteLine("AmigaDOS plugin", "rblk.hashTableSize = {0}", rblk.hashTableSize); DicConsole.DebugWriteLine("AmigaDOS plugin", "rblk.hashTableSize = {0}", rblk.hashTableSize);
uint blockSize = (rblk.hashTableSize + 56) * 4; uint blockSize = (rblk.hashTableSize + 56) * 4;
uint sectorsPerBlock = (uint)(blockSize / sector.Length); uint sectorsPerBlock = (uint)(blockSize / sector.Length);
DicConsole.DebugWriteLine("AmigaDOS plugin", "blockSize = {0}", blockSize); DicConsole.DebugWriteLine("AmigaDOS plugin", "blockSize = {0}", blockSize);
DicConsole.DebugWriteLine("AmigaDOS plugin", "sectorsPerBlock = {0}", sectorsPerBlock); DicConsole.DebugWriteLine("AmigaDOS plugin", "sectorsPerBlock = {0}", sectorsPerBlock);
if(blockSize % sector.Length > 0) sectorsPerBlock++; if(blockSize % sector.Length > 0) sectorsPerBlock++;
@@ -136,11 +136,11 @@ namespace DiscImageChef.Filesystems
// Clear checksum on sector // Clear checksum on sector
rblk.checksum = BigEndianBitConverter.ToUInt32(sector, 20); rblk.checksum = BigEndianBitConverter.ToUInt32(sector, 20);
sector[20] = sector[21] = sector[22] = sector[23] = 0; sector[20] = sector[21] = sector[22] = sector[23] = 0;
uint rsum = AmigaChecksum(sector); uint rsum = AmigaChecksum(sector);
DicConsole.DebugWriteLine("AmigaDOS plugin", "rblk.checksum = 0x{0:X8}", rblk.checksum); DicConsole.DebugWriteLine("AmigaDOS plugin", "rblk.checksum = 0x{0:X8}", rblk.checksum);
DicConsole.DebugWriteLine("AmigaDOS plugin", "rsum = 0x{0:X8}", rsum); DicConsole.DebugWriteLine("AmigaDOS plugin", "rsum = 0x{0:X8}", rsum);
rblk.sec_type = BigEndianBitConverter.ToUInt32(sector, sector.Length - 4); rblk.sec_type = BigEndianBitConverter.ToUInt32(sector, sector.Length - 4);
DicConsole.DebugWriteLine("AmigaDOS plugin", "rblk.sec_type = {0}", rblk.sec_type); DicConsole.DebugWriteLine("AmigaDOS plugin", "rblk.sec_type = {0}", rblk.sec_type);
@@ -152,21 +152,21 @@ namespace DiscImageChef.Filesystems
} }
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information, public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information,
Encoding encoding) Encoding encoding)
{ {
Encoding = encoding ?? Encoding.GetEncoding("iso-8859-1"); Encoding = encoding ?? Encoding.GetEncoding("iso-8859-1");
StringBuilder sbInformation = new StringBuilder(); StringBuilder sbInformation = new StringBuilder();
XmlFsType = new FileSystemType(); XmlFsType = new FileSystemType();
information = null; information = null;
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
byte[] bootBlockSectors = imagePlugin.ReadSectors(0 + partition.Start, 2); byte[] bootBlockSectors = imagePlugin.ReadSectors(0 + partition.Start, 2);
BootBlock bootBlk = BigEndianMarshal.ByteArrayToStructureBigEndian<BootBlock>(bootBlockSectors); BootBlock bootBlk = BigEndianMarshal.ByteArrayToStructureBigEndian<BootBlock>(bootBlockSectors);
bootBlk.bootCode = new byte[bootBlockSectors.Length - 12]; bootBlk.bootCode = new byte[bootBlockSectors.Length - 12];
Array.Copy(bootBlockSectors, 12, bootBlk.bootCode, 0, bootBlk.bootCode.Length); Array.Copy(bootBlockSectors, 12, bootBlk.bootCode, 0, bootBlk.bootCode.Length);
bootBlockSectors[4] = bootBlockSectors[5] = bootBlockSectors[6] = bootBlockSectors[7] = 0; bootBlockSectors[4] = bootBlockSectors[5] = bootBlockSectors[6] = bootBlockSectors[7] = 0;
uint bsum = AmigaBootChecksum(bootBlockSectors); uint bsum = AmigaBootChecksum(bootBlockSectors);
ulong bRootPtr = 0; ulong bRootPtr = 0;
@@ -179,14 +179,14 @@ namespace DiscImageChef.Filesystems
ulong[] rootPtrs = ulong[] rootPtrs =
{ {
bRootPtr + partition.Start, (partition.End - partition.Start + 1) / 2 + partition.Start - 2, bRootPtr + partition.Start, (partition.End - partition.Start + 1) / 2 + partition.Start - 2,
(partition.End - partition.Start + 1) / 2 + partition.Start - 1, (partition.End - partition.Start + 1) / 2 + partition.Start - 1,
(partition.End - partition.Start + 1) / 2 + partition.Start, (partition.End - partition.Start + 1) / 2 + partition.Start,
(partition.End - partition.Start + 1) / 2 + partition.Start + 4 (partition.End - partition.Start + 1) / 2 + partition.Start + 4
}; };
RootBlock rootBlk = new RootBlock(); RootBlock rootBlk = new RootBlock();
byte[] rootBlockSector = null; byte[] rootBlockSector = null;
bool rootFound = false; bool rootFound = false;
uint blockSize = 0; uint blockSize = 0;
@@ -206,10 +206,10 @@ namespace DiscImageChef.Filesystems
DicConsole.DebugWriteLine("AmigaDOS plugin", "rootBlk.hashTableSize = {0}", rootBlk.hashTableSize); DicConsole.DebugWriteLine("AmigaDOS plugin", "rootBlk.hashTableSize = {0}", rootBlk.hashTableSize);
blockSize = (rootBlk.hashTableSize + 56) * 4; blockSize = (rootBlk.hashTableSize + 56) * 4;
uint sectorsPerBlock = (uint)(blockSize / rootBlockSector.Length); uint sectorsPerBlock = (uint)(blockSize / rootBlockSector.Length);
DicConsole.DebugWriteLine("AmigaDOS plugin", "blockSize = {0}", blockSize); DicConsole.DebugWriteLine("AmigaDOS plugin", "blockSize = {0}", blockSize);
DicConsole.DebugWriteLine("AmigaDOS plugin", "sectorsPerBlock = {0}", sectorsPerBlock); DicConsole.DebugWriteLine("AmigaDOS plugin", "sectorsPerBlock = {0}", sectorsPerBlock);
if(blockSize % rootBlockSector.Length > 0) sectorsPerBlock++; if(blockSize % rootBlockSector.Length > 0) sectorsPerBlock++;
@@ -219,12 +219,12 @@ namespace DiscImageChef.Filesystems
rootBlockSector = imagePlugin.ReadSectors(rootPtr, sectorsPerBlock); rootBlockSector = imagePlugin.ReadSectors(rootPtr, sectorsPerBlock);
// Clear checksum on sector // Clear checksum on sector
rootBlk.checksum = BigEndianBitConverter.ToUInt32(rootBlockSector, 20); rootBlk.checksum = BigEndianBitConverter.ToUInt32(rootBlockSector, 20);
rootBlockSector[20] = rootBlockSector[21] = rootBlockSector[22] = rootBlockSector[23] = 0; rootBlockSector[20] = rootBlockSector[21] = rootBlockSector[22] = rootBlockSector[23] = 0;
uint rsum = AmigaChecksum(rootBlockSector); uint rsum = AmigaChecksum(rootBlockSector);
DicConsole.DebugWriteLine("AmigaDOS plugin", "rootBlk.checksum = 0x{0:X8}", rootBlk.checksum); DicConsole.DebugWriteLine("AmigaDOS plugin", "rootBlk.checksum = 0x{0:X8}", rootBlk.checksum);
DicConsole.DebugWriteLine("AmigaDOS plugin", "rsum = 0x{0:X8}", rsum); DicConsole.DebugWriteLine("AmigaDOS plugin", "rsum = 0x{0:X8}", rsum);
rootBlk.sec_type = BigEndianBitConverter.ToUInt32(rootBlockSector, rootBlockSector.Length - 4); rootBlk.sec_type = BigEndianBitConverter.ToUInt32(rootBlockSector, rootBlockSector.Length - 4);
DicConsole.DebugWriteLine("AmigaDOS plugin", "rootBlk.sec_type = {0}", rootBlk.sec_type); DicConsole.DebugWriteLine("AmigaDOS plugin", "rootBlk.sec_type = {0}", rootBlk.sec_type);
@@ -232,7 +232,7 @@ namespace DiscImageChef.Filesystems
if(rootBlk.sec_type != SUBTYPE_ROOT || rootBlk.checksum != rsum) continue; if(rootBlk.sec_type != SUBTYPE_ROOT || rootBlk.checksum != rsum) continue;
rootBlockSector = imagePlugin.ReadSectors(rootPtr, sectorsPerBlock); rootBlockSector = imagePlugin.ReadSectors(rootPtr, sectorsPerBlock);
rootFound = true; rootFound = true;
break; break;
} }
@@ -287,7 +287,6 @@ namespace DiscImageChef.Filesystems
if(bootBlk.checksum == bsum) if(bootBlk.checksum == bsum)
{ {
Sha1Context sha1Ctx = new Sha1Context(); Sha1Context sha1Ctx = new Sha1Context();
sha1Ctx.Init();
sha1Ctx.Update(bootBlk.bootCode); sha1Ctx.Update(bootBlk.bootCode);
sbInformation.AppendLine("Volume is bootable"); sbInformation.AppendLine("Volume is bootable");
sbInformation.AppendFormat("Boot code SHA1 is {0}", sha1Ctx.End()).AppendLine(); sbInformation.AppendFormat("Boot code SHA1 is {0}", sha1Ctx.End()).AppendLine();
@@ -304,7 +303,7 @@ namespace DiscImageChef.Filesystems
long blocks = (long)((partition.End - partition.Start + 1) * imagePlugin.Info.SectorSize / blockSize); long blocks = (long)((partition.End - partition.Start + 1) * imagePlugin.Info.SectorSize / blockSize);
sbInformation.AppendFormat("Volume block size is {0} bytes", blockSize).AppendLine(); sbInformation.AppendFormat("Volume block size is {0} bytes", blockSize).AppendLine();
sbInformation.AppendFormat("Volume has {0} blocks", blocks).AppendLine(); sbInformation.AppendFormat("Volume has {0} blocks", blocks).AppendLine();
sbInformation.AppendFormat("Volume created on {0}", sbInformation.AppendFormat("Volume created on {0}",
DateHandlers.AmigaToDateTime(rootBlk.cDays, rootBlk.cMins, rootBlk.cTicks)) DateHandlers.AmigaToDateTime(rootBlk.cDays, rootBlk.cMins, rootBlk.cTicks))
.AppendLine(); .AppendLine();
@@ -317,15 +316,17 @@ namespace DiscImageChef.Filesystems
sbInformation.AppendFormat("Root block checksum is 0x{0:X8}", rootBlk.checksum).AppendLine(); sbInformation.AppendFormat("Root block checksum is 0x{0:X8}", rootBlk.checksum).AppendLine();
information = sbInformation.ToString(); information = sbInformation.ToString();
XmlFsType.CreationDate = DateHandlers.AmigaToDateTime(rootBlk.cDays, rootBlk.cMins, rootBlk.cTicks); XmlFsType.CreationDate =
DateHandlers.AmigaToDateTime(rootBlk.cDays, rootBlk.cMins, rootBlk.cTicks);
XmlFsType.CreationDateSpecified = true; XmlFsType.CreationDateSpecified = true;
XmlFsType.ModificationDate = DateHandlers.AmigaToDateTime(rootBlk.vDays, rootBlk.vMins, rootBlk.vTicks); XmlFsType.ModificationDate =
DateHandlers.AmigaToDateTime(rootBlk.vDays, rootBlk.vMins, rootBlk.vTicks);
XmlFsType.ModificationDateSpecified = true; XmlFsType.ModificationDateSpecified = true;
XmlFsType.Dirty = rootBlk.bitmapFlag != 0xFFFFFFFF; XmlFsType.Dirty = rootBlk.bitmapFlag != 0xFFFFFFFF;
XmlFsType.Clusters = blocks; XmlFsType.Clusters = blocks;
XmlFsType.ClusterSize = (int)blockSize; XmlFsType.ClusterSize = (int)blockSize;
XmlFsType.VolumeName = diskName; XmlFsType.VolumeName = diskName;
XmlFsType.Bootable = bsum == bootBlk.checksum; XmlFsType.Bootable = bsum == bootBlk.checksum;
// Useful as a serial // Useful as a serial
XmlFsType.VolumeSerial = $"{rootBlk.checksum:X8}"; XmlFsType.VolumeSerial = $"{rootBlk.checksum:X8}";
} }
@@ -333,10 +334,10 @@ namespace DiscImageChef.Filesystems
static RootBlock MarshalRootBlock(byte[] block) static RootBlock MarshalRootBlock(byte[] block)
{ {
byte[] tmp = new byte[228]; byte[] tmp = new byte[228];
Array.Copy(block, 0, tmp, 0, 24); Array.Copy(block, 0, tmp, 0, 24);
Array.Copy(block, block.Length - 200, tmp, 28, 200); Array.Copy(block, block.Length - 200, tmp, 28, 200);
RootBlock root = BigEndianMarshal.ByteArrayToStructureBigEndian<RootBlock>(tmp); RootBlock root = BigEndianMarshal.ByteArrayToStructureBigEndian<RootBlock>(tmp);
root.hashTable = new uint[(block.Length - 224) / 4]; root.hashTable = new uint[(block.Length - 224) / 4];
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
for(int i = 0; i < root.hashTable.Length; i++) for(int i = 0; i < root.hashTable.Length; i++)
root.hashTable[i] = BigEndianBitConverter.ToUInt32(block, 24 + i * 4); root.hashTable[i] = BigEndianBitConverter.ToUInt32(block, 24 + i * 4);
@@ -390,7 +391,8 @@ namespace DiscImageChef.Filesystems
/// <summary> /// <summary>
/// Offset 0x0C, Boot code, til completion. Size is intentionally incorrect to allow marshaling to work. /// Offset 0x0C, Boot code, til completion. Size is intentionally incorrect to allow marshaling to work.
/// </summary> /// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public byte[] bootCode; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public byte[] bootCode;
} }
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
@@ -424,7 +426,8 @@ namespace DiscImageChef.Filesystems
/// Offset 0x18, Hashtable, size = (block size / 4) - 56 or size = hashTableSize. /// Offset 0x18, Hashtable, size = (block size / 4) - 56 or size = hashTableSize.
/// Size intentionally bad to allow marshalling to work. /// Size intentionally bad to allow marshalling to work.
/// </summary> /// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public uint[] hashTable; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public uint[] hashTable;
/// <summary> /// <summary>
/// Offset 0x18+hashTableSize*4+0, bitmap flag, 0xFFFFFFFF if valid /// Offset 0x18+hashTableSize*4+0, bitmap flag, 0xFFFFFFFF if valid
/// </summary> /// </summary>
@@ -432,7 +435,8 @@ namespace DiscImageChef.Filesystems
/// <summary> /// <summary>
/// Offset 0x18+hashTableSize*4+4, bitmap pages, 25 entries /// Offset 0x18+hashTableSize*4+4, bitmap pages, 25 entries
/// </summary> /// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 25)] public uint[] bitmapPages; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 25)]
public uint[] bitmapPages;
/// <summary> /// <summary>
/// Offset 0x18+hashTableSize*4+104, pointer to bitmap extension block /// Offset 0x18+hashTableSize*4+104, pointer to bitmap extension block
/// </summary> /// </summary>
@@ -452,7 +456,8 @@ namespace DiscImageChef.Filesystems
/// <summary> /// <summary>
/// Offset 0x18+hashTableSize*4+120, disk name, pascal string, 31 bytes /// Offset 0x18+hashTableSize*4+120, disk name, pascal string, 31 bytes
/// </summary> /// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 31)] public byte[] diskName; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 31)]
public byte[] diskName;
/// <summary> /// <summary>
/// Offset 0x18+hashTableSize*4+151, unused /// Offset 0x18+hashTableSize*4+151, unused
/// </summary> /// </summary>

View File

@@ -705,7 +705,6 @@ namespace DiscImageChef.Filesystems
string extraInfo = null; string extraInfo = null;
string bootChk = null; string bootChk = null;
Sha1Context sha1Ctx = new Sha1Context(); Sha1Context sha1Ctx = new Sha1Context();
sha1Ctx.Init();
// This is needed because for FAT16, GEMDOS increases bytes per sector count instead of using big_sectors field. // This is needed because for FAT16, GEMDOS increases bytes per sector count instead of using big_sectors field.
uint sectorsPerRealSector; uint sectorsPerRealSector;
@@ -1527,7 +1526,6 @@ namespace DiscImageChef.Filesystems
byte[] bootCode = new byte[512 - sigSize - bpbSector[1] - 2]; byte[] bootCode = new byte[512 - sigSize - bpbSector[1] - 2];
Array.Copy(bpbSector, bpbSector[1] + 2, bootCode, 0, bootCode.Length); Array.Copy(bpbSector, bpbSector[1] + 2, bootCode, 0, bootCode.Length);
sha1Ctx = new Sha1Context(); sha1Ctx = new Sha1Context();
sha1Ctx.Init();
sha1Ctx.Update(bootCode); sha1Ctx.Update(bootCode);
bootChk = sha1Ctx.End(); bootChk = sha1Ctx.End();
} }
@@ -1539,7 +1537,6 @@ namespace DiscImageChef.Filesystems
Array.Copy(bpbSector, BitConverter.ToUInt16(bpbSector, 1) + 3, bootCode, 0, Array.Copy(bpbSector, BitConverter.ToUInt16(bpbSector, 1) + 3, bootCode, 0,
bootCode.Length); bootCode.Length);
sha1Ctx = new Sha1Context(); sha1Ctx = new Sha1Context();
sha1Ctx.Init();
sha1Ctx.Update(bootCode); sha1Ctx.Update(bootCode);
bootChk = sha1Ctx.End(); bootChk = sha1Ctx.End();
} }

View File

@@ -44,28 +44,26 @@ namespace DiscImageChef.Filesystems
public class HPFS : IFilesystem public class HPFS : IFilesystem
{ {
public FileSystemType XmlFsType { get; private set; } public FileSystemType XmlFsType { get; private set; }
public Encoding Encoding { get; private set; } public Encoding Encoding { get; private set; }
public string Name => "OS/2 High Performance File System"; public string Name => "OS/2 High Performance File System";
public Guid Id => new Guid("33513B2C-f590-4acb-8bf2-0b1d5e19dec5"); public Guid Id => new Guid("33513B2C-f590-4acb-8bf2-0b1d5e19dec5");
public bool Identify(IMediaImage imagePlugin, Partition partition) public bool Identify(IMediaImage imagePlugin, Partition partition)
{ {
if(16 + partition.Start >= partition.End) return false; if(16 + partition.Start >= partition.End) return false;
uint magic1, magic2;
byte[] hpfsSbSector = byte[] hpfsSbSector =
imagePlugin.ReadSector(16 + partition.Start); // Seek to superblock, on logical sector 16 imagePlugin.ReadSector(16 + partition.Start); // Seek to superblock, on logical sector 16
magic1 = BitConverter.ToUInt32(hpfsSbSector, 0x000); uint magic1 = BitConverter.ToUInt32(hpfsSbSector, 0x000);
magic2 = BitConverter.ToUInt32(hpfsSbSector, 0x004); uint magic2 = BitConverter.ToUInt32(hpfsSbSector, 0x004);
return magic1 == 0xF995E849 && magic2 == 0xFA53E9C5; return magic1 == 0xF995E849 && magic2 == 0xFA53E9C5;
} }
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information, public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information,
Encoding encoding) Encoding encoding)
{ {
Encoding = encoding ?? Encoding.GetEncoding("ibm850"); Encoding = encoding ?? Encoding.GetEncoding("ibm850");
information = ""; information = "";
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@@ -94,7 +92,8 @@ namespace DiscImageChef.Filesystems
Marshal.FreeHGlobal(spPtr); Marshal.FreeHGlobal(spPtr);
if(StringHandlers.CToString(hpfsBpb.fs_type) != "HPFS " || hpfsSb.magic1 != 0xF995E849 || if(StringHandlers.CToString(hpfsBpb.fs_type) != "HPFS " || hpfsSb.magic1 != 0xF995E849 ||
hpfsSb.magic2 != 0xFA53E9C5 || hpfsSp.magic1 != 0xF9911849 || hpfsSp.magic2 != 0xFA5229C5) hpfsSb.magic2 != 0xFA53E9C5 || hpfsSp.magic1 != 0xF9911849 ||
hpfsSp.magic2 != 0xFA5229C5)
{ {
sb.AppendLine("This may not be HPFS, following information may be not correct."); sb.AppendLine("This may not be HPFS, following information may be not correct.");
sb.AppendFormat("File system type: \"{0}\" (Should be \"HPFS \")", hpfsBpb.fs_type).AppendLine(); sb.AppendFormat("File system type: \"{0}\" (Should be \"HPFS \")", hpfsBpb.fs_type).AppendLine();
@@ -104,7 +103,7 @@ namespace DiscImageChef.Filesystems
sb.AppendFormat("Spareblock magic2: 0x{0:X8} (Should be 0xFA5229C5)", hpfsSp.magic2).AppendLine(); sb.AppendFormat("Spareblock magic2: 0x{0:X8} (Should be 0xFA5229C5)", hpfsSp.magic2).AppendLine();
} }
sb.AppendFormat("OEM name: {0}", StringHandlers.CToString(hpfsBpb.oem_name)).AppendLine(); sb.AppendFormat("OEM name: {0}", StringHandlers.CToString(hpfsBpb.oem_name)).AppendLine();
sb.AppendFormat("{0} bytes per sector", hpfsBpb.bps).AppendLine(); sb.AppendFormat("{0} bytes per sector", hpfsBpb.bps).AppendLine();
// sb.AppendFormat("{0} sectors per cluster", hpfs_bpb.spc).AppendLine(); // sb.AppendFormat("{0} sectors per cluster", hpfs_bpb.spc).AppendLine();
// sb.AppendFormat("{0} reserved sectors", hpfs_bpb.rsectors).AppendLine(); // sb.AppendFormat("{0} reserved sectors", hpfs_bpb.rsectors).AppendLine();
@@ -115,85 +114,91 @@ namespace DiscImageChef.Filesystems
// sb.AppendFormat("{0} sectors per FAT", hpfs_bpb.spfat).AppendLine(); // sb.AppendFormat("{0} sectors per FAT", hpfs_bpb.spfat).AppendLine();
// sb.AppendFormat("{0} sectors per track", hpfs_bpb.sptrk).AppendLine(); // sb.AppendFormat("{0} sectors per track", hpfs_bpb.sptrk).AppendLine();
// sb.AppendFormat("{0} heads", hpfs_bpb.heads).AppendLine(); // sb.AppendFormat("{0} heads", hpfs_bpb.heads).AppendLine();
sb.AppendFormat("{0} sectors hidden before BPB", hpfsBpb.hsectors).AppendLine(); sb.AppendFormat("{0} sectors hidden before BPB", hpfsBpb.hsectors).AppendLine();
sb.AppendFormat("{0} sectors on volume ({1} bytes)", hpfsSb.sectors, hpfsSb.sectors * hpfsBpb.bps) sb.AppendFormat("{0} sectors on volume ({1} bytes)", hpfsSb.sectors, hpfsSb.sectors * hpfsBpb.bps)
.AppendLine(); .AppendLine();
// sb.AppendFormat("{0} sectors on volume ({1} bytes)", hpfs_bpb.big_sectors, hpfs_bpb.big_sectors * hpfs_bpb.bps).AppendLine(); // sb.AppendFormat("{0} sectors on volume ({1} bytes)", hpfs_bpb.big_sectors, hpfs_bpb.big_sectors * hpfs_bpb.bps).AppendLine();
sb.AppendFormat("BIOS Drive Number: 0x{0:X2}", hpfsBpb.drive_no).AppendLine(); sb.AppendFormat("BIOS Drive Number: 0x{0:X2}", hpfsBpb.drive_no).AppendLine();
sb.AppendFormat("NT Flags: 0x{0:X2}", hpfsBpb.nt_flags).AppendLine(); sb.AppendFormat("NT Flags: 0x{0:X2}", hpfsBpb.nt_flags).AppendLine();
sb.AppendFormat("Signature: 0x{0:X2}", hpfsBpb.signature).AppendLine(); sb.AppendFormat("Signature: 0x{0:X2}", hpfsBpb.signature).AppendLine();
sb.AppendFormat("Serial number: 0x{0:X8}", hpfsBpb.serial_no).AppendLine(); sb.AppendFormat("Serial number: 0x{0:X8}", hpfsBpb.serial_no).AppendLine();
sb.AppendFormat("Volume label: {0}", StringHandlers.CToString(hpfsBpb.volume_label, Encoding)).AppendLine(); sb.AppendFormat("Volume label: {0}", StringHandlers.CToString(hpfsBpb.volume_label, Encoding))
.AppendLine();
// sb.AppendFormat("Filesystem type: \"{0}\"", hpfs_bpb.fs_type).AppendLine(); // sb.AppendFormat("Filesystem type: \"{0}\"", hpfs_bpb.fs_type).AppendLine();
DateTime lastChk = DateHandlers.UnixToDateTime(hpfsSb.last_chkdsk); DateTime lastChk = DateHandlers.UnixToDateTime(hpfsSb.last_chkdsk);
DateTime lastOptim = DateHandlers.UnixToDateTime(hpfsSb.last_optim); DateTime lastOptim = DateHandlers.UnixToDateTime(hpfsSb.last_optim);
sb.AppendFormat("HPFS version: {0}", hpfsSb.version).AppendLine(); sb.AppendFormat("HPFS version: {0}", hpfsSb.version)
sb.AppendFormat("Functional version: {0}", hpfsSb.func_version).AppendLine(); .AppendLine();
sb.AppendFormat("Sector of root directory FNode: {0}", hpfsSb.root_fnode).AppendLine(); sb.AppendFormat("Functional version: {0}", hpfsSb.func_version)
sb.AppendFormat("{0} sectors are marked bad", hpfsSb.badblocks).AppendLine(); .AppendLine();
sb.AppendFormat("Sector of free space bitmaps: {0}", hpfsSb.bitmap_lsn).AppendLine(); sb.AppendFormat("Sector of root directory FNode: {0}", hpfsSb.root_fnode)
sb.AppendFormat("Sector of bad blocks list: {0}", hpfsSb.badblock_lsn).AppendLine(); .AppendLine();
sb.AppendFormat("{0} sectors are marked bad", hpfsSb.badblocks)
.AppendLine();
sb.AppendFormat("Sector of free space bitmaps: {0}", hpfsSb.bitmap_lsn)
.AppendLine();
sb.AppendFormat("Sector of bad blocks list: {0}", hpfsSb.badblock_lsn)
.AppendLine();
if(hpfsSb.last_chkdsk > 0) sb.AppendFormat("Date of last integrity check: {0}", lastChk).AppendLine(); if(hpfsSb.last_chkdsk > 0) sb.AppendFormat("Date of last integrity check: {0}", lastChk).AppendLine();
else sb.AppendLine("Filesystem integrity has never been checked"); else sb.AppendLine("Filesystem integrity has never been checked");
if(hpfsSb.last_optim > 0) sb.AppendFormat("Date of last optimization {0}", lastOptim).AppendLine(); if(hpfsSb.last_optim > 0) sb.AppendFormat("Date of last optimization {0}", lastOptim).AppendLine();
else sb.AppendLine("Filesystem has never been optimized"); else sb.AppendLine("Filesystem has never been optimized");
sb.AppendFormat("Directory band has {0} sectors", hpfsSb.dband_sectors).AppendLine(); sb.AppendFormat("Directory band has {0} sectors", hpfsSb.dband_sectors).AppendLine();
sb.AppendFormat("Directory band starts at sector {0}", hpfsSb.dband_start).AppendLine(); sb.AppendFormat("Directory band starts at sector {0}", hpfsSb.dband_start).AppendLine();
sb.AppendFormat("Directory band ends at sector {0}", hpfsSb.dband_last).AppendLine(); sb.AppendFormat("Directory band ends at sector {0}", hpfsSb.dband_last).AppendLine();
sb.AppendFormat("Sector of directory band bitmap: {0}", hpfsSb.dband_bitmap).AppendLine(); sb.AppendFormat("Sector of directory band bitmap: {0}", hpfsSb.dband_bitmap).AppendLine();
sb.AppendFormat("Sector of ACL directory: {0}", hpfsSb.acl_start).AppendLine(); sb.AppendFormat("Sector of ACL directory: {0}", hpfsSb.acl_start).AppendLine();
sb.AppendFormat("Sector of Hotfix directory: {0}", hpfsSp.hotfix_start).AppendLine(); sb.AppendFormat("Sector of Hotfix directory: {0}", hpfsSp.hotfix_start).AppendLine();
sb.AppendFormat("{0} used Hotfix entries", hpfsSp.hotfix_used).AppendLine(); sb.AppendFormat("{0} used Hotfix entries", hpfsSp.hotfix_used).AppendLine();
sb.AppendFormat("{0} total Hotfix entries", hpfsSp.hotfix_entries).AppendLine(); sb.AppendFormat("{0} total Hotfix entries", hpfsSp.hotfix_entries).AppendLine();
sb.AppendFormat("{0} free spare DNodes", hpfsSp.spare_dnodes_free).AppendLine(); sb.AppendFormat("{0} free spare DNodes", hpfsSp.spare_dnodes_free).AppendLine();
sb.AppendFormat("{0} total spare DNodes", hpfsSp.spare_dnodes).AppendLine(); sb.AppendFormat("{0} total spare DNodes", hpfsSp.spare_dnodes).AppendLine();
sb.AppendFormat("Sector of codepage directory: {0}", hpfsSp.codepage_lsn).AppendLine(); sb.AppendFormat("Sector of codepage directory: {0}", hpfsSp.codepage_lsn).AppendLine();
sb.AppendFormat("{0} codepages used in the volume", hpfsSp.codepages).AppendLine(); sb.AppendFormat("{0} codepages used in the volume", hpfsSp.codepages).AppendLine();
sb.AppendFormat("SuperBlock CRC32: {0:X8}", hpfsSp.sb_crc32).AppendLine(); sb.AppendFormat("SuperBlock CRC32: {0:X8}", hpfsSp.sb_crc32).AppendLine();
sb.AppendFormat("SpareBlock CRC32: {0:X8}", hpfsSp.sp_crc32).AppendLine(); sb.AppendFormat("SpareBlock CRC32: {0:X8}", hpfsSp.sp_crc32).AppendLine();
sb.AppendLine("Flags:"); sb.AppendLine("Flags:");
sb.AppendLine((hpfsSp.flags1 & 0x01) == 0x01 ? "Filesystem is dirty." : "Filesystem is clean."); sb.AppendLine((hpfsSp.flags1 & 0x01) == 0x01 ? "Filesystem is dirty." : "Filesystem is clean.");
if((hpfsSp.flags1 & 0x02) == 0x02) sb.AppendLine("Spare directory blocks are in use"); if((hpfsSp.flags1 & 0x02) == 0x02) sb.AppendLine("Spare directory blocks are in use");
if((hpfsSp.flags1 & 0x04) == 0x04) sb.AppendLine("Hotfixes are in use"); if((hpfsSp.flags1 & 0x04) == 0x04) sb.AppendLine("Hotfixes are in use");
if((hpfsSp.flags1 & 0x08) == 0x08) sb.AppendLine("Disk contains bad sectors"); if((hpfsSp.flags1 & 0x08) == 0x08) sb.AppendLine("Disk contains bad sectors");
if((hpfsSp.flags1 & 0x10) == 0x10) sb.AppendLine("Disk has a bad bitmap"); if((hpfsSp.flags1 & 0x10) == 0x10) sb.AppendLine("Disk has a bad bitmap");
if((hpfsSp.flags1 & 0x20) == 0x20) sb.AppendLine("Filesystem was formatted fast"); if((hpfsSp.flags1 & 0x20) == 0x20) sb.AppendLine("Filesystem was formatted fast");
if((hpfsSp.flags1 & 0x40) == 0x40) sb.AppendLine("Unknown flag 0x40 on flags1 is active"); if((hpfsSp.flags1 & 0x40) == 0x40) sb.AppendLine("Unknown flag 0x40 on flags1 is active");
if((hpfsSp.flags1 & 0x80) == 0x80) sb.AppendLine("Filesystem has been mounted by an old IFS"); if((hpfsSp.flags1 & 0x80) == 0x80) sb.AppendLine("Filesystem has been mounted by an old IFS");
if((hpfsSp.flags2 & 0x01) == 0x01) sb.AppendLine("Install DASD limits"); if((hpfsSp.flags2 & 0x01) == 0x01) sb.AppendLine("Install DASD limits");
if((hpfsSp.flags2 & 0x02) == 0x02) sb.AppendLine("Resync DASD limits"); if((hpfsSp.flags2 & 0x02) == 0x02) sb.AppendLine("Resync DASD limits");
if((hpfsSp.flags2 & 0x04) == 0x04) sb.AppendLine("DASD limits are operational"); if((hpfsSp.flags2 & 0x04) == 0x04) sb.AppendLine("DASD limits are operational");
if((hpfsSp.flags2 & 0x08) == 0x08) sb.AppendLine("Multimedia is active"); if((hpfsSp.flags2 & 0x08) == 0x08) sb.AppendLine("Multimedia is active");
if((hpfsSp.flags2 & 0x10) == 0x10) sb.AppendLine("DCE ACLs are active"); if((hpfsSp.flags2 & 0x10) == 0x10) sb.AppendLine("DCE ACLs are active");
if((hpfsSp.flags2 & 0x20) == 0x20) sb.AppendLine("DASD limits are dirty"); if((hpfsSp.flags2 & 0x20) == 0x20) sb.AppendLine("DASD limits are dirty");
if((hpfsSp.flags2 & 0x40) == 0x40) sb.AppendLine("Unknown flag 0x40 on flags2 is active"); if((hpfsSp.flags2 & 0x40) == 0x40) sb.AppendLine("Unknown flag 0x40 on flags2 is active");
if((hpfsSp.flags2 & 0x80) == 0x80) sb.AppendLine("Unknown flag 0x80 on flags2 is active"); if((hpfsSp.flags2 & 0x80) == 0x80) sb.AppendLine("Unknown flag 0x80 on flags2 is active");
XmlFsType = new FileSystemType(); XmlFsType = new FileSystemType();
// Theoretically everything from BPB to SB is boot code, should I hash everything or only the sector loaded by BIOS itself? // Theoretically everything from BPB to SB is boot code, should I hash everything or only the sector loaded by BIOS itself?
if(hpfsBpb.jump[0] == 0xEB && hpfsBpb.jump[1] > 0x3C && hpfsBpb.jump[1] < 0x80 && if(hpfsBpb.jump[0] == 0xEB && hpfsBpb.jump[1] > 0x3C && hpfsBpb.jump[1] < 0x80 &&
hpfsBpb.signature2 == 0xAA55) hpfsBpb.signature2 == 0xAA55)
{ {
XmlFsType.Bootable = true; XmlFsType.Bootable = true;
Sha1Context sha1Ctx = new Sha1Context(); Sha1Context sha1Ctx = new Sha1Context();
sha1Ctx.Init(); string bootChk = sha1Ctx.Data(hpfsBpb.boot_code, out byte[] sha1_out);
string bootChk = sha1Ctx.Data(hpfsBpb.boot_code, out byte[] sha1_out);
sb.AppendLine("Volume is bootable"); sb.AppendLine("Volume is bootable");
sb.AppendFormat("Boot code's SHA1: {0}", bootChk).AppendLine(); sb.AppendFormat("Boot code's SHA1: {0}", bootChk).AppendLine();
} }
XmlFsType.Dirty |= (hpfsSp.flags1 & 0x01) == 0x01; XmlFsType.Dirty |= (hpfsSp.flags1 & 0x01) == 0x01;
XmlFsType.Clusters = hpfsSb.sectors; XmlFsType.Clusters = hpfsSb.sectors;
XmlFsType.ClusterSize = hpfsBpb.bps; XmlFsType.ClusterSize = hpfsBpb.bps;
XmlFsType.Type = "HPFS"; XmlFsType.Type = "HPFS";
XmlFsType.VolumeName = StringHandlers.CToString(hpfsBpb.volume_label, Encoding); XmlFsType.VolumeName = StringHandlers.CToString(hpfsBpb.volume_label, Encoding);
XmlFsType.VolumeSerial = $"{hpfsBpb.serial_no:X8}"; XmlFsType.VolumeSerial = $"{hpfsBpb.serial_no:X8}";
XmlFsType.SystemIdentifier = StringHandlers.CToString(hpfsBpb.oem_name); XmlFsType.SystemIdentifier = StringHandlers.CToString(hpfsBpb.oem_name);
information = sb.ToString(); information = sb.ToString();
} }
@@ -205,9 +210,11 @@ namespace DiscImageChef.Filesystems
struct HPFS_BIOSParameterBlock struct HPFS_BIOSParameterBlock
{ {
/// <summary>0x000, Jump to boot code</summary> /// <summary>0x000, Jump to boot code</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] public byte[] jump; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public byte[] jump;
/// <summary>0x003, OEM Name, 8 bytes, space-padded</summary> /// <summary>0x003, OEM Name, 8 bytes, space-padded</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public byte[] oem_name; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public byte[] oem_name;
/// <summary>0x00B, Bytes per sector</summary> /// <summary>0x00B, Bytes per sector</summary>
public ushort bps; public ushort bps;
/// <summary>0x00D, Sectors per cluster</summary> /// <summary>0x00D, Sectors per cluster</summary>
@@ -241,11 +248,14 @@ namespace DiscImageChef.Filesystems
/// <summary>0x02B, Volume serial number</summary> /// <summary>0x02B, Volume serial number</summary>
public uint serial_no; public uint serial_no;
/// <summary>0x02F, Volume label, 11 bytes, space-padded</summary> /// <summary>0x02F, Volume label, 11 bytes, space-padded</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 11)] public byte[] volume_label; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 11)]
public byte[] volume_label;
/// <summary>0x03A, Filesystem type, 8 bytes, space-padded ("HPFS ")</summary> /// <summary>0x03A, Filesystem type, 8 bytes, space-padded ("HPFS ")</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public byte[] fs_type; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public byte[] fs_type;
/// <summary>Boot code.</summary> /// <summary>Boot code.</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 448)] public byte[] boot_code; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 448)]
public byte[] boot_code;
/// <summary>0x1FE, 0xAA55</summary> /// <summary>0x1FE, 0xAA55</summary>
public ushort signature2; public ushort signature2;
} }

View File

@@ -569,7 +569,6 @@ namespace DiscImageChef.Filesystems.ISO9660
{ {
vdSector = imagePlugin.ReadSector(torito.Value.catalog_sector + partition.Start); vdSector = imagePlugin.ReadSector(torito.Value.catalog_sector + partition.Start);
Sha1Context sha1Ctx = new Sha1Context(); Sha1Context sha1Ctx = new Sha1Context();
sha1Ctx.Init();
int toritoOff = 0; int toritoOff = 0;

View File

@@ -44,17 +44,15 @@ namespace DiscImageChef.Filesystems
public class NTFS : IFilesystem public class NTFS : IFilesystem
{ {
public FileSystemType XmlFsType { get; private set; } public FileSystemType XmlFsType { get; private set; }
public Encoding Encoding { get; private set; } public Encoding Encoding { get; private set; }
public string Name => "New Technology File System (NTFS)"; public string Name => "New Technology File System (NTFS)";
public Guid Id => new Guid("33513B2C-1e6d-4d21-a660-0bbc789c3871"); public Guid Id => new Guid("33513B2C-1e6d-4d21-a660-0bbc789c3871");
public bool Identify(IMediaImage imagePlugin, Partition partition) public bool Identify(IMediaImage imagePlugin, Partition partition)
{ {
if(2 + partition.Start >= partition.End) return false; if(2 + partition.Start >= partition.End) return false;
byte[] eigthBytes = new byte[8]; byte[] eigthBytes = new byte[8];
byte fatsNo;
ushort spFat, signature;
byte[] ntfsBpb = imagePlugin.ReadSector(0 + partition.Start); byte[] ntfsBpb = imagePlugin.ReadSector(0 + partition.Start);
@@ -63,23 +61,20 @@ namespace DiscImageChef.Filesystems
if(oemName != "NTFS ") return false; if(oemName != "NTFS ") return false;
fatsNo = ntfsBpb[0x010]; byte fatsNo = ntfsBpb[0x010];
ushort spFat = BitConverter.ToUInt16(ntfsBpb, 0x016);
ushort signature = BitConverter.ToUInt16(ntfsBpb, 0x1FE);
if(fatsNo != 0) return false; if(fatsNo != 0) return false;
if(spFat != 0) return false;
spFat = BitConverter.ToUInt16(ntfsBpb, 0x016);
if(spFat != 0) return false;
signature = BitConverter.ToUInt16(ntfsBpb, 0x1FE);
return signature == 0xAA55; return signature == 0xAA55;
} }
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information, public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information,
Encoding encoding) Encoding encoding)
{ {
Encoding = Encoding.Unicode; Encoding = Encoding.Unicode;
information = ""; information = "";
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@@ -91,7 +86,7 @@ namespace DiscImageChef.Filesystems
NtfsBootBlock ntfsBb = (NtfsBootBlock)Marshal.PtrToStructure(bpbPtr, typeof(NtfsBootBlock)); NtfsBootBlock ntfsBb = (NtfsBootBlock)Marshal.PtrToStructure(bpbPtr, typeof(NtfsBootBlock));
Marshal.FreeHGlobal(bpbPtr); Marshal.FreeHGlobal(bpbPtr);
sb.AppendFormat("{0} bytes per sector", ntfsBb.bps).AppendLine(); sb.AppendFormat("{0} bytes per sector", ntfsBb.bps).AppendLine();
sb.AppendFormat("{0} sectors per cluster ({1} bytes)", ntfsBb.spc, ntfsBb.spc * ntfsBb.bps).AppendLine(); sb.AppendFormat("{0} sectors per cluster ({1} bytes)", ntfsBb.spc, ntfsBb.spc * ntfsBb.bps).AppendLine();
// sb.AppendFormat("{0} reserved sectors", ntfs_bb.rsectors).AppendLine(); // sb.AppendFormat("{0} reserved sectors", ntfs_bb.rsectors).AppendLine();
// sb.AppendFormat("{0} FATs", ntfs_bb.fats_no).AppendLine(); // sb.AppendFormat("{0} FATs", ntfs_bb.fats_no).AppendLine();
@@ -99,8 +94,8 @@ namespace DiscImageChef.Filesystems
// sb.AppendFormat("{0} sectors on volume (small)", ntfs_bb.sml_sectors).AppendLine(); // sb.AppendFormat("{0} sectors on volume (small)", ntfs_bb.sml_sectors).AppendLine();
sb.AppendFormat("Media descriptor: 0x{0:X2}", ntfsBb.media).AppendLine(); sb.AppendFormat("Media descriptor: 0x{0:X2}", ntfsBb.media).AppendLine();
// sb.AppendFormat("{0} sectors per FAT", ntfs_bb.spfat).AppendLine(); // sb.AppendFormat("{0} sectors per FAT", ntfs_bb.spfat).AppendLine();
sb.AppendFormat("{0} sectors per track", ntfsBb.sptrk).AppendLine(); sb.AppendFormat("{0} sectors per track", ntfsBb.sptrk).AppendLine();
sb.AppendFormat("{0} heads", ntfsBb.heads).AppendLine(); sb.AppendFormat("{0} heads", ntfsBb.heads).AppendLine();
sb.AppendFormat("{0} hidden sectors before filesystem", ntfsBb.hsectors).AppendLine(); sb.AppendFormat("{0} hidden sectors before filesystem", ntfsBb.hsectors).AppendLine();
// sb.AppendFormat("{0} sectors on volume (big)", ntfs_bb.big_sectors).AppendLine(); // sb.AppendFormat("{0} sectors on volume (big)", ntfs_bb.big_sectors).AppendLine();
sb.AppendFormat("BIOS drive number: 0x{0:X2}", ntfsBb.drive_no).AppendLine(); sb.AppendFormat("BIOS drive number: 0x{0:X2}", ntfsBb.drive_no).AppendLine();
@@ -108,7 +103,7 @@ namespace DiscImageChef.Filesystems
// sb.AppendFormat("Signature 1: 0x{0:X2}", ntfs_bb.signature1).AppendLine(); // sb.AppendFormat("Signature 1: 0x{0:X2}", ntfs_bb.signature1).AppendLine();
sb.AppendFormat("{0} sectors on volume ({1} bytes)", ntfsBb.sectors, ntfsBb.sectors * ntfsBb.bps) sb.AppendFormat("{0} sectors on volume ({1} bytes)", ntfsBb.sectors, ntfsBb.sectors * ntfsBb.bps)
.AppendLine(); .AppendLine();
sb.AppendFormat("Cluster where $MFT starts: {0}", ntfsBb.mft_lsn).AppendLine(); sb.AppendFormat("Cluster where $MFT starts: {0}", ntfsBb.mft_lsn).AppendLine();
sb.AppendFormat("Cluster where $MFTMirr starts: {0}", ntfsBb.mftmirror_lsn).AppendLine(); sb.AppendFormat("Cluster where $MFTMirr starts: {0}", ntfsBb.mftmirror_lsn).AppendLine();
if(ntfsBb.mft_rc_clusters > 0) if(ntfsBb.mft_rc_clusters > 0)
@@ -127,18 +122,17 @@ namespace DiscImageChef.Filesystems
if(ntfsBb.jump[0] == 0xEB && ntfsBb.jump[1] > 0x4E && ntfsBb.jump[1] < 0x80 && ntfsBb.signature2 == 0xAA55) if(ntfsBb.jump[0] == 0xEB && ntfsBb.jump[1] > 0x4E && ntfsBb.jump[1] < 0x80 && ntfsBb.signature2 == 0xAA55)
{ {
XmlFsType.Bootable = true; XmlFsType.Bootable = true;
Sha1Context sha1Ctx = new Sha1Context(); Sha1Context sha1Ctx = new Sha1Context();
sha1Ctx.Init(); string bootChk = sha1Ctx.Data(ntfsBb.boot_code, out _);
string bootChk = sha1Ctx.Data(ntfsBb.boot_code, out _);
sb.AppendLine("Volume is bootable"); sb.AppendLine("Volume is bootable");
sb.AppendFormat("Boot code's SHA1: {0}", bootChk).AppendLine(); sb.AppendFormat("Boot code's SHA1: {0}", bootChk).AppendLine();
} }
XmlFsType.ClusterSize = ntfsBb.spc * ntfsBb.bps; XmlFsType.ClusterSize = ntfsBb.spc * ntfsBb.bps;
XmlFsType.Clusters = ntfsBb.sectors / ntfsBb.spc; XmlFsType.Clusters = ntfsBb.sectors / ntfsBb.spc;
XmlFsType.VolumeSerial = $"{ntfsBb.serial_no:X16}"; XmlFsType.VolumeSerial = $"{ntfsBb.serial_no:X16}";
XmlFsType.Type = "NTFS"; XmlFsType.Type = "NTFS";
information = sb.ToString(); information = sb.ToString();
} }
@@ -151,9 +145,11 @@ namespace DiscImageChef.Filesystems
{ {
// Start of BIOS Parameter Block // Start of BIOS Parameter Block
/// <summary>0x000, Jump to boot code</summary> /// <summary>0x000, Jump to boot code</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] public byte[] jump; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public byte[] jump;
/// <summary>0x003, OEM Name, 8 bytes, space-padded, must be "NTFS "</summary> /// <summary>0x003, OEM Name, 8 bytes, space-padded, must be "NTFS "</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public byte[] oem_name; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public byte[] oem_name;
/// <summary>0x00B, Bytes per sector</summary> /// <summary>0x00B, Bytes per sector</summary>
public ushort bps; public ushort bps;
/// <summary>0x00D, Sectors per cluster</summary> /// <summary>0x00D, Sectors per cluster</summary>
@@ -210,7 +206,8 @@ namespace DiscImageChef.Filesystems
/// <summary>0x048, Volume serial number</summary> /// <summary>0x048, Volume serial number</summary>
public ulong serial_no; public ulong serial_no;
/// <summary>Boot code.</summary> /// <summary>Boot code.</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 430)] public byte[] boot_code; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 430)]
public byte[] boot_code;
/// <summary>0x1FE, 0xAA55</summary> /// <summary>0x1FE, 0xAA55</summary>
public ushort signature2; public ushort signature2;
} }

View File

@@ -42,21 +42,21 @@ namespace DiscImageChef.Partitions
{ {
public class AtariPartitions : IPartition public class AtariPartitions : IPartition
{ {
const uint TypeGEMDOS = 0x0047454D; const uint TypeGEMDOS = 0x0047454D;
const uint TypeBigGEMDOS = 0x0042474D; const uint TypeBigGEMDOS = 0x0042474D;
const uint TypeExtended = 0x0058474D; const uint TypeExtended = 0x0058474D;
const uint TypeLinux = 0x004C4E58; const uint TypeLinux = 0x004C4E58;
const uint TypeSwap = 0x00535750; const uint TypeSwap = 0x00535750;
const uint TypeRAW = 0x00524157; const uint TypeRAW = 0x00524157;
const uint TypeNetBSD = 0x004E4244; const uint TypeNetBSD = 0x004E4244;
const uint TypeNetBSDSwap = 0x004E4253; const uint TypeNetBSDSwap = 0x004E4253;
const uint TypeSysV = 0x00554E58; const uint TypeSysV = 0x00554E58;
const uint TypeMac = 0x004D4143; const uint TypeMac = 0x004D4143;
const uint TypeMinix = 0x004D4958; const uint TypeMinix = 0x004D4958;
const uint TypeMinix2 = 0x004D4E58; const uint TypeMinix2 = 0x004D4E58;
public string Name => "Atari partitions"; public string Name => "Atari partitions";
public Guid Id => new Guid("d1dd0f24-ec39-4c4d-9072-be31919a3b5e"); public Guid Id => new Guid("d1dd0f24-ec39-4c4d-9072-be31919a3b5e");
public bool GetInformation(IMediaImage imagePlugin, out List<Partition> partitions, ulong sectorOffset) public bool GetInformation(IMediaImage imagePlugin, out List<Partition> partitions, ulong sectorOffset)
{ {
@@ -70,18 +70,18 @@ namespace DiscImageChef.Partitions
AtariTable table = new AtariTable AtariTable table = new AtariTable
{ {
boot = new byte[342], boot = new byte[342],
icdEntries = new AtariEntry[8], icdEntries = new AtariEntry[8],
unused = new byte[12], unused = new byte[12],
entries = new AtariEntry[4] entries = new AtariEntry[4]
}; };
Array.Copy(sector, 0, table.boot, 0, 342); Array.Copy(sector, 0, table.boot, 0, 342);
for(int i = 0; i < 8; i++) for(int i = 0; i < 8; i++)
{ {
table.icdEntries[i].type = BigEndianBitConverter.ToUInt32(sector, 342 + i * 12 + 0); table.icdEntries[i].type = BigEndianBitConverter.ToUInt32(sector, 342 + i * 12 + 0);
table.icdEntries[i].start = BigEndianBitConverter.ToUInt32(sector, 342 + i * 12 + 4); table.icdEntries[i].start = BigEndianBitConverter.ToUInt32(sector, 342 + i * 12 + 4);
table.icdEntries[i].length = BigEndianBitConverter.ToUInt32(sector, 342 + i * 12 + 8); table.icdEntries[i].length = BigEndianBitConverter.ToUInt32(sector, 342 + i * 12 + 8);
} }
@@ -91,17 +91,16 @@ namespace DiscImageChef.Partitions
for(int i = 0; i < 4; i++) for(int i = 0; i < 4; i++)
{ {
table.entries[i].type = BigEndianBitConverter.ToUInt32(sector, 454 + i * 12 + 0); table.entries[i].type = BigEndianBitConverter.ToUInt32(sector, 454 + i * 12 + 0);
table.entries[i].start = BigEndianBitConverter.ToUInt32(sector, 454 + i * 12 + 4); table.entries[i].start = BigEndianBitConverter.ToUInt32(sector, 454 + i * 12 + 4);
table.entries[i].length = BigEndianBitConverter.ToUInt32(sector, 454 + i * 12 + 8); table.entries[i].length = BigEndianBitConverter.ToUInt32(sector, 454 + i * 12 + 8);
} }
table.badStart = BigEndianBitConverter.ToUInt32(sector, 502); table.badStart = BigEndianBitConverter.ToUInt32(sector, 502);
table.badLength = BigEndianBitConverter.ToUInt32(sector, 506); table.badLength = BigEndianBitConverter.ToUInt32(sector, 506);
table.checksum = BigEndianBitConverter.ToUInt16(sector, 510); table.checksum = BigEndianBitConverter.ToUInt16(sector, 510);
Sha1Context sha1Ctx = new Sha1Context(); Sha1Context sha1Ctx = new Sha1Context();
sha1Ctx.Init();
sha1Ctx.Update(table.boot); sha1Ctx.Update(table.boot);
DicConsole.DebugWriteLine("Atari partition plugin", "Boot code SHA1: {0}", sha1Ctx.End()); DicConsole.DebugWriteLine("Atari partition plugin", "Boot code SHA1: {0}", sha1Ctx.End());
@@ -131,11 +130,11 @@ namespace DiscImageChef.Partitions
table.entries[i].length); table.entries[i].length);
} }
DicConsole.DebugWriteLine("Atari partition plugin", "table.badStart = {0}", table.badStart); DicConsole.DebugWriteLine("Atari partition plugin", "table.badStart = {0}", table.badStart);
DicConsole.DebugWriteLine("Atari partition plugin", "table.badLength = {0}", table.badLength); DicConsole.DebugWriteLine("Atari partition plugin", "table.badLength = {0}", table.badLength);
DicConsole.DebugWriteLine("Atari partition plugin", "table.checksum = 0x{0:X4}", table.checksum); DicConsole.DebugWriteLine("Atari partition plugin", "table.checksum = 0x{0:X4}", table.checksum);
bool validTable = false; bool validTable = false;
ulong partitionSequence = 0; ulong partitionSequence = 0;
for(int i = 0; i < 4; i++) for(int i = 0; i < 4; i++)
{ {
@@ -162,24 +161,24 @@ namespace DiscImageChef.Partitions
DicConsole.DebugWriteLine("Atari partition plugin", DicConsole.DebugWriteLine("Atari partition plugin",
"WARNING: End of partition goes beyond device size"); "WARNING: End of partition goes beyond device size");
ulong sectorSize = imagePlugin.Info.SectorSize; ulong sectorSize = imagePlugin.Info.SectorSize;
if(sectorSize == 2448 || sectorSize == 2352) sectorSize = 2048; if(sectorSize == 2448 || sectorSize == 2352) sectorSize = 2048;
byte[] partType = new byte[3]; byte[] partType = new byte[3];
partType[0] = (byte)((type & 0xFF0000) >> 16); partType[0] = (byte)((type & 0xFF0000) >> 16);
partType[1] = (byte)((type & 0x00FF00) >> 8); partType[1] = (byte)((type & 0x00FF00) >> 8);
partType[2] = (byte)(type & 0x0000FF); partType[2] = (byte)(type & 0x0000FF);
Partition part = new Partition Partition part = new Partition
{ {
Size = table.entries[i].length * sectorSize, Size = table.entries[i].length * sectorSize,
Length = table.entries[i].length, Length = table.entries[i].length,
Sequence = partitionSequence, Sequence = partitionSequence,
Name = "", Name = "",
Offset = table.entries[i].start * sectorSize, Offset = table.entries[i].start * sectorSize,
Start = table.entries[i].start, Start = table.entries[i].start,
Type = Encoding.ASCII.GetString(partType), Type = Encoding.ASCII.GetString(partType),
Scheme = Name Scheme = Name
}; };
switch(type) switch(type)
{ {
@@ -225,9 +224,9 @@ namespace DiscImageChef.Partitions
break; break;
case TypeExtended: case TypeExtended:
byte[] extendedSector = imagePlugin.ReadSector(table.entries[i].start); byte[] extendedSector = imagePlugin.ReadSector(table.entries[i].start);
AtariTable extendedTable = new AtariTable(); AtariTable extendedTable = new AtariTable();
extendedTable.entries = new AtariEntry[4]; extendedTable.entries = new AtariEntry[4];
for(int j = 0; j < 4; j++) for(int j = 0; j < 4; j++)
{ {
@@ -244,9 +243,11 @@ namespace DiscImageChef.Partitions
uint extendedType = extendedTable.entries[j].type & 0x00FFFFFF; uint extendedType = extendedTable.entries[j].type & 0x00FFFFFF;
if(extendedType != TypeGEMDOS && extendedType != TypeBigGEMDOS && if(extendedType != TypeGEMDOS && extendedType != TypeBigGEMDOS &&
extendedType != TypeLinux && extendedType != TypeSwap && extendedType != TypeRAW && extendedType != TypeLinux && extendedType != TypeSwap &&
extendedType != TypeRAW &&
extendedType != TypeNetBSD && extendedType != TypeNetBSDSwap && extendedType != TypeNetBSD && extendedType != TypeNetBSDSwap &&
extendedType != TypeSysV && extendedType != TypeMac && extendedType != TypeMinix && extendedType != TypeSysV && extendedType != TypeMac &&
extendedType != TypeMinix &&
extendedType != TypeMinix2) continue; extendedType != TypeMinix2) continue;
validTable = true; validTable = true;
@@ -257,24 +258,24 @@ namespace DiscImageChef.Partitions
DicConsole.DebugWriteLine("Atari partition plugin", DicConsole.DebugWriteLine("Atari partition plugin",
"WARNING: End of partition goes beyond device size"); "WARNING: End of partition goes beyond device size");
ulong sectorSize = imagePlugin.Info.SectorSize; ulong sectorSize = imagePlugin.Info.SectorSize;
if(sectorSize == 2448 || sectorSize == 2352) sectorSize = 2048; if(sectorSize == 2448 || sectorSize == 2352) sectorSize = 2048;
byte[] partType = new byte[3]; byte[] partType = new byte[3];
partType[0] = (byte)((extendedType & 0xFF0000) >> 16); partType[0] = (byte)((extendedType & 0xFF0000) >> 16);
partType[1] = (byte)((extendedType & 0x00FF00) >> 8); partType[1] = (byte)((extendedType & 0x00FF00) >> 8);
partType[2] = (byte)(extendedType & 0x0000FF); partType[2] = (byte)(extendedType & 0x0000FF);
Partition part = new Partition Partition part = new Partition
{ {
Size = extendedTable.entries[j].length * sectorSize, Size = extendedTable.entries[j].length * sectorSize,
Length = extendedTable.entries[j].length, Length = extendedTable.entries[j].length,
Sequence = partitionSequence, Sequence = partitionSequence,
Name = "", Name = "",
Offset = extendedTable.entries[j].start * sectorSize, Offset = extendedTable.entries[j].start * sectorSize,
Start = extendedTable.entries[j].start, Start = extendedTable.entries[j].start,
Type = Encoding.ASCII.GetString(partType), Type = Encoding.ASCII.GetString(partType),
Scheme = Name Scheme = Name
}; };
switch(extendedType) switch(extendedType)
{ {
@@ -328,9 +329,9 @@ namespace DiscImageChef.Partitions
{ {
uint type = table.icdEntries[i].type & 0x00FFFFFF; uint type = table.icdEntries[i].type & 0x00FFFFFF;
if(type != TypeGEMDOS && type != TypeBigGEMDOS && type != TypeLinux && type != TypeSwap && if(type != TypeGEMDOS && type != TypeBigGEMDOS && type != TypeLinux && type != TypeSwap &&
type != TypeRAW && type != TypeNetBSD && type != TypeNetBSDSwap && type != TypeSysV && type != TypeRAW && type != TypeNetBSD && type != TypeNetBSDSwap && type != TypeSysV &&
type != TypeMac && type != TypeMinix && type != TypeMinix2) continue; type != TypeMac && type != TypeMinix && type != TypeMinix2) continue;
if(table.icdEntries[i].start > imagePlugin.Info.Sectors) continue; if(table.icdEntries[i].start > imagePlugin.Info.Sectors) continue;
@@ -338,24 +339,24 @@ namespace DiscImageChef.Partitions
DicConsole.DebugWriteLine("Atari partition plugin", DicConsole.DebugWriteLine("Atari partition plugin",
"WARNING: End of partition goes beyond device size"); "WARNING: End of partition goes beyond device size");
ulong sectorSize = imagePlugin.Info.SectorSize; ulong sectorSize = imagePlugin.Info.SectorSize;
if(sectorSize == 2448 || sectorSize == 2352) sectorSize = 2048; if(sectorSize == 2448 || sectorSize == 2352) sectorSize = 2048;
byte[] partType = new byte[3]; byte[] partType = new byte[3];
partType[0] = (byte)((type & 0xFF0000) >> 16); partType[0] = (byte)((type & 0xFF0000) >> 16);
partType[1] = (byte)((type & 0x00FF00) >> 8); partType[1] = (byte)((type & 0x00FF00) >> 8);
partType[2] = (byte)(type & 0x0000FF); partType[2] = (byte)(type & 0x0000FF);
Partition part = new Partition Partition part = new Partition
{ {
Size = table.icdEntries[i].length * sectorSize, Size = table.icdEntries[i].length * sectorSize,
Length = table.icdEntries[i].length, Length = table.icdEntries[i].length,
Sequence = partitionSequence, Sequence = partitionSequence,
Name = "", Name = "",
Offset = table.icdEntries[i].start * sectorSize, Offset = table.icdEntries[i].start * sectorSize,
Start = table.icdEntries[i].start, Start = table.icdEntries[i].start,
Type = Encoding.ASCII.GetString(partType), Type = Encoding.ASCII.GetString(partType),
Scheme = Name Scheme = Name
}; };
switch(type) switch(type)
{ {

View File

@@ -276,14 +276,14 @@ namespace DiscImageChef.Partitions
const uint FLAGS_NO_AUTOMOUNT = 0x00000002; const uint FLAGS_NO_AUTOMOUNT = 0x00000002;
public string Name => "Amiga Rigid Disk Block"; public string Name => "Amiga Rigid Disk Block";
public Guid Id => new Guid("8D72ED97-1854-4170-9CE4-6E8446FD9863"); public Guid Id => new Guid("8D72ED97-1854-4170-9CE4-6E8446FD9863");
public bool GetInformation(IMediaImage imagePlugin, out List<Partition> partitions, ulong sectorOffset) public bool GetInformation(IMediaImage imagePlugin, out List<Partition> partitions, ulong sectorOffset)
{ {
partitions = new List<Partition>(); partitions = new List<Partition>();
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
ulong rdbBlock = 0; ulong rdbBlock = 0;
bool foundRdb = false; bool foundRdb = false;
while(rdbBlock < 16) while(rdbBlock < 16)
{ {
@@ -292,7 +292,7 @@ namespace DiscImageChef.Partitions
if(rdbBlock + sectorOffset >= imagePlugin.Info.Sectors) break; if(rdbBlock + sectorOffset >= imagePlugin.Info.Sectors) break;
byte[] tmpSector = imagePlugin.ReadSector(rdbBlock + sectorOffset); byte[] tmpSector = imagePlugin.ReadSector(rdbBlock + sectorOffset);
uint magic = BigEndianBitConverter.ToUInt32(tmpSector, 0); uint magic = BigEndianBitConverter.ToUInt32(tmpSector, 0);
DicConsole.DebugWriteLine("Amiga RDB plugin", "Possible magic at block {0} is 0x{1:X8}", rdbBlock, DicConsole.DebugWriteLine("Amiga RDB plugin", "Possible magic at block {0} is 0x{1:X8}", rdbBlock,
magic); magic);
@@ -316,64 +316,64 @@ namespace DiscImageChef.Partitions
byte[] sector = imagePlugin.ReadSector(rdbBlock); byte[] sector = imagePlugin.ReadSector(rdbBlock);
rdb.Magic = BigEndianBitConverter.ToUInt32(sector, 0x00); rdb.Magic = BigEndianBitConverter.ToUInt32(sector, 0x00);
rdb.Size = BigEndianBitConverter.ToUInt32(sector, 0x04); rdb.Size = BigEndianBitConverter.ToUInt32(sector, 0x04);
rdb.Checksum = BigEndianBitConverter.ToInt32(sector, 0x08); rdb.Checksum = BigEndianBitConverter.ToInt32(sector, 0x08);
rdb.TargetId = BigEndianBitConverter.ToUInt32(sector, 0x0C); rdb.TargetId = BigEndianBitConverter.ToUInt32(sector, 0x0C);
rdb.BlockSize = BigEndianBitConverter.ToUInt32(sector, 0x10); rdb.BlockSize = BigEndianBitConverter.ToUInt32(sector, 0x10);
rdb.Flags = BigEndianBitConverter.ToUInt32(sector, 0x04); rdb.Flags = BigEndianBitConverter.ToUInt32(sector, 0x04);
rdb.BadblockPtr = BigEndianBitConverter.ToUInt32(sector, 0x18); rdb.BadblockPtr = BigEndianBitConverter.ToUInt32(sector, 0x18);
rdb.PartitionPtr = BigEndianBitConverter.ToUInt32(sector, 0x1C); rdb.PartitionPtr = BigEndianBitConverter.ToUInt32(sector, 0x1C);
rdb.FsheaderPtr = BigEndianBitConverter.ToUInt32(sector, 0x20); rdb.FsheaderPtr = BigEndianBitConverter.ToUInt32(sector, 0x20);
rdb.Driveinitcode = BigEndianBitConverter.ToUInt32(sector, 0x24); rdb.Driveinitcode = BigEndianBitConverter.ToUInt32(sector, 0x24);
rdb.Reserved1 = BigEndianBitConverter.ToUInt32(sector, 0x28); rdb.Reserved1 = BigEndianBitConverter.ToUInt32(sector, 0x28);
rdb.Reserved2 = BigEndianBitConverter.ToUInt32(sector, 0x2C); rdb.Reserved2 = BigEndianBitConverter.ToUInt32(sector, 0x2C);
rdb.Reserved3 = BigEndianBitConverter.ToUInt32(sector, 0x30); rdb.Reserved3 = BigEndianBitConverter.ToUInt32(sector, 0x30);
rdb.Reserved4 = BigEndianBitConverter.ToUInt32(sector, 0x34); rdb.Reserved4 = BigEndianBitConverter.ToUInt32(sector, 0x34);
rdb.Reserved5 = BigEndianBitConverter.ToUInt32(sector, 0x38); rdb.Reserved5 = BigEndianBitConverter.ToUInt32(sector, 0x38);
rdb.Reserved6 = BigEndianBitConverter.ToUInt32(sector, 0x3C); rdb.Reserved6 = BigEndianBitConverter.ToUInt32(sector, 0x3C);
rdb.Cylinders = BigEndianBitConverter.ToUInt32(sector, 0x40); rdb.Cylinders = BigEndianBitConverter.ToUInt32(sector, 0x40);
rdb.Spt = BigEndianBitConverter.ToUInt32(sector, 0x44); rdb.Spt = BigEndianBitConverter.ToUInt32(sector, 0x44);
rdb.Heads = BigEndianBitConverter.ToUInt32(sector, 0x48); rdb.Heads = BigEndianBitConverter.ToUInt32(sector, 0x48);
rdb.Interleave = BigEndianBitConverter.ToUInt32(sector, 0x4C); rdb.Interleave = BigEndianBitConverter.ToUInt32(sector, 0x4C);
rdb.Parking = BigEndianBitConverter.ToUInt32(sector, 0x50); rdb.Parking = BigEndianBitConverter.ToUInt32(sector, 0x50);
rdb.Reserved7 = BigEndianBitConverter.ToUInt32(sector, 0x54); rdb.Reserved7 = BigEndianBitConverter.ToUInt32(sector, 0x54);
rdb.Reserved8 = BigEndianBitConverter.ToUInt32(sector, 0x58); rdb.Reserved8 = BigEndianBitConverter.ToUInt32(sector, 0x58);
rdb.Reserved9 = BigEndianBitConverter.ToUInt32(sector, 0x5C); rdb.Reserved9 = BigEndianBitConverter.ToUInt32(sector, 0x5C);
rdb.Writeprecomp = BigEndianBitConverter.ToUInt32(sector, 0x60); rdb.Writeprecomp = BigEndianBitConverter.ToUInt32(sector, 0x60);
rdb.Reducedwrite = BigEndianBitConverter.ToUInt32(sector, 0x64); rdb.Reducedwrite = BigEndianBitConverter.ToUInt32(sector, 0x64);
rdb.Steprate = BigEndianBitConverter.ToUInt32(sector, 0x68); rdb.Steprate = BigEndianBitConverter.ToUInt32(sector, 0x68);
rdb.Reserved10 = BigEndianBitConverter.ToUInt32(sector, 0x6C); rdb.Reserved10 = BigEndianBitConverter.ToUInt32(sector, 0x6C);
rdb.Reserved11 = BigEndianBitConverter.ToUInt32(sector, 0x70); rdb.Reserved11 = BigEndianBitConverter.ToUInt32(sector, 0x70);
rdb.Reserved12 = BigEndianBitConverter.ToUInt32(sector, 0x74); rdb.Reserved12 = BigEndianBitConverter.ToUInt32(sector, 0x74);
rdb.Reserved13 = BigEndianBitConverter.ToUInt32(sector, 0x78); rdb.Reserved13 = BigEndianBitConverter.ToUInt32(sector, 0x78);
rdb.Reserved14 = BigEndianBitConverter.ToUInt32(sector, 0x7C); rdb.Reserved14 = BigEndianBitConverter.ToUInt32(sector, 0x7C);
rdb.RdbBlockLow = BigEndianBitConverter.ToUInt32(sector, 0x80); rdb.RdbBlockLow = BigEndianBitConverter.ToUInt32(sector, 0x80);
rdb.RdbBlockHigh = BigEndianBitConverter.ToUInt32(sector, 0x84); rdb.RdbBlockHigh = BigEndianBitConverter.ToUInt32(sector, 0x84);
rdb.LowCylinder = BigEndianBitConverter.ToUInt32(sector, 0x88); rdb.LowCylinder = BigEndianBitConverter.ToUInt32(sector, 0x88);
rdb.HighCylinder = BigEndianBitConverter.ToUInt32(sector, 0x8C); rdb.HighCylinder = BigEndianBitConverter.ToUInt32(sector, 0x8C);
rdb.CylBlocks = BigEndianBitConverter.ToUInt32(sector, 0x90); rdb.CylBlocks = BigEndianBitConverter.ToUInt32(sector, 0x90);
rdb.AutoParkSeconds = BigEndianBitConverter.ToUInt32(sector, 0x94); rdb.AutoParkSeconds = BigEndianBitConverter.ToUInt32(sector, 0x94);
rdb.HighCylinder = BigEndianBitConverter.ToUInt32(sector, 0x98); rdb.HighCylinder = BigEndianBitConverter.ToUInt32(sector, 0x98);
rdb.Reserved15 = BigEndianBitConverter.ToUInt32(sector, 0x9C); rdb.Reserved15 = BigEndianBitConverter.ToUInt32(sector, 0x9C);
byte[] tmpString = new byte[8]; byte[] tmpString = new byte[8];
Array.Copy(sector, 0xA0, tmpString, 0, 8); Array.Copy(sector, 0xA0, tmpString, 0, 8);
rdb.DiskVendor = StringHandlers.SpacePaddedToString(tmpString); rdb.DiskVendor = StringHandlers.SpacePaddedToString(tmpString);
tmpString = new byte[16]; tmpString = new byte[16];
Array.Copy(sector, 0xA8, tmpString, 0, 16); Array.Copy(sector, 0xA8, tmpString, 0, 16);
rdb.DiskProduct = StringHandlers.SpacePaddedToString(tmpString); rdb.DiskProduct = StringHandlers.SpacePaddedToString(tmpString);
tmpString = new byte[4]; tmpString = new byte[4];
Array.Copy(sector, 0xB8, tmpString, 0, 4); Array.Copy(sector, 0xB8, tmpString, 0, 4);
rdb.DiskRevision = StringHandlers.SpacePaddedToString(tmpString); rdb.DiskRevision = StringHandlers.SpacePaddedToString(tmpString);
tmpString = new byte[8]; tmpString = new byte[8];
Array.Copy(sector, 0xBC, tmpString, 0, 8); Array.Copy(sector, 0xBC, tmpString, 0, 8);
rdb.ControllerVendor = StringHandlers.SpacePaddedToString(tmpString); rdb.ControllerVendor = StringHandlers.SpacePaddedToString(tmpString);
tmpString = new byte[16]; tmpString = new byte[16];
Array.Copy(sector, 0xC4, tmpString, 0, 16); Array.Copy(sector, 0xC4, tmpString, 0, 16);
rdb.ControllerProduct = StringHandlers.SpacePaddedToString(tmpString); rdb.ControllerProduct = StringHandlers.SpacePaddedToString(tmpString);
tmpString = new byte[4]; tmpString = new byte[4];
Array.Copy(sector, 0xD4, tmpString, 0, 4); Array.Copy(sector, 0xD4, tmpString, 0, 4);
rdb.ControllerRevision = StringHandlers.SpacePaddedToString(tmpString); rdb.ControllerRevision = StringHandlers.SpacePaddedToString(tmpString);
@@ -388,73 +388,73 @@ namespace DiscImageChef.Partitions
rdb.Reserved24 = BigEndianBitConverter.ToUInt32(sector, 0xF8); rdb.Reserved24 = BigEndianBitConverter.ToUInt32(sector, 0xF8);
rdb.Reserved25 = BigEndianBitConverter.ToUInt32(sector, 0xFC); rdb.Reserved25 = BigEndianBitConverter.ToUInt32(sector, 0xFC);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.magic = 0x{0:X8}", rdb.Magic); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.magic = 0x{0:X8}", rdb.Magic);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.size = {0} longs, {1} bytes", rdb.Size, rdb.Size * 4); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.size = {0} longs, {1} bytes", rdb.Size, rdb.Size * 4);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.checksum = 0x{0:X8}", rdb.Checksum); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.checksum = 0x{0:X8}", rdb.Checksum);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.targetID = {0}", rdb.TargetId); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.targetID = {0}", rdb.TargetId);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.block_size = {0}", rdb.BlockSize); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.block_size = {0}", rdb.BlockSize);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.badblock_ptr = {0}", rdb.BadblockPtr); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.badblock_ptr = {0}", rdb.BadblockPtr);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.partition_ptr = {0}", rdb.PartitionPtr); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.partition_ptr = {0}", rdb.PartitionPtr);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.fsheader_ptr = {0}", rdb.FsheaderPtr); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.fsheader_ptr = {0}", rdb.FsheaderPtr);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.driveinitcode = {0}", rdb.Driveinitcode); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.driveinitcode = {0}", rdb.Driveinitcode);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved1 = 0x{0:X8}", rdb.Reserved1); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved1 = 0x{0:X8}", rdb.Reserved1);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved2 = 0x{0:X8}", rdb.Reserved2); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved2 = 0x{0:X8}", rdb.Reserved2);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved3 = 0x{0:X8}", rdb.Reserved3); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved3 = 0x{0:X8}", rdb.Reserved3);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved4 = 0x{0:X8}", rdb.Reserved4); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved4 = 0x{0:X8}", rdb.Reserved4);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved5 = 0x{0:X8}", rdb.Reserved5); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved5 = 0x{0:X8}", rdb.Reserved5);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved6 = 0x{0:X8}", rdb.Reserved6); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved6 = 0x{0:X8}", rdb.Reserved6);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.cylinders = {0}", rdb.Cylinders); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.cylinders = {0}", rdb.Cylinders);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.spt = {0}", rdb.Spt); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.spt = {0}", rdb.Spt);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.heads = {0}", rdb.Heads); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.heads = {0}", rdb.Heads);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.interleave = {0}", rdb.Interleave); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.interleave = {0}", rdb.Interleave);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.parking = {0}", rdb.Parking); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.parking = {0}", rdb.Parking);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved7 = 0x{0:X8}", rdb.Reserved7); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved7 = 0x{0:X8}", rdb.Reserved7);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved8 = 0x{0:X8}", rdb.Reserved8); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved8 = 0x{0:X8}", rdb.Reserved8);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved9 = 0x{0:X8}", rdb.Reserved9); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved9 = 0x{0:X8}", rdb.Reserved9);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.writeprecomp = {0}", rdb.Writeprecomp); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.writeprecomp = {0}", rdb.Writeprecomp);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reducedwrite = {0}", rdb.Reducedwrite); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reducedwrite = {0}", rdb.Reducedwrite);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.steprate = {0}", rdb.Steprate); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.steprate = {0}", rdb.Steprate);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved10 = 0x{0:X8}", rdb.Reserved10); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved10 = 0x{0:X8}", rdb.Reserved10);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved11 = 0x{0:X8}", rdb.Reserved11); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved11 = 0x{0:X8}", rdb.Reserved11);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved12 = 0x{0:X8}", rdb.Reserved12); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved12 = 0x{0:X8}", rdb.Reserved12);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved13 = 0x{0:X8}", rdb.Reserved13); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved13 = 0x{0:X8}", rdb.Reserved13);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved14 = 0x{0:X8}", rdb.Reserved14); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved14 = 0x{0:X8}", rdb.Reserved14);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.RDBBlockLow = {0}", rdb.RdbBlockLow); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.RDBBlockLow = {0}", rdb.RdbBlockLow);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.RDBBlockHigh = {0}", rdb.RdbBlockHigh); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.RDBBlockHigh = {0}", rdb.RdbBlockHigh);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.LowCylinder = {0}", rdb.LowCylinder); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.LowCylinder = {0}", rdb.LowCylinder);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.HighCylinder = {0}", rdb.HighCylinder); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.HighCylinder = {0}", rdb.HighCylinder);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.CylBlocks = {0}", rdb.CylBlocks); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.CylBlocks = {0}", rdb.CylBlocks);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.AutoParkSeconds = {0}", rdb.AutoParkSeconds); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.AutoParkSeconds = {0}", rdb.AutoParkSeconds);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.HighCylinder = {0}", rdb.HighCylinder); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.HighCylinder = {0}", rdb.HighCylinder);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved15 = 0x{0:X8}", rdb.Reserved15); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved15 = 0x{0:X8}", rdb.Reserved15);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.diskVendor = \"{0}\"", rdb.DiskVendor); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.diskVendor = \"{0}\"", rdb.DiskVendor);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.diskProduct = \"{0}\"", rdb.DiskProduct); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.diskProduct = \"{0}\"", rdb.DiskProduct);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.diskRevision = \"{0}\"", rdb.DiskRevision); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.diskRevision = \"{0}\"", rdb.DiskRevision);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.controllerVendor = \"{0}\"", rdb.ControllerVendor); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.controllerVendor = \"{0}\"", rdb.ControllerVendor);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.controllerProduct = \"{0}\"", rdb.ControllerProduct); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.controllerProduct = \"{0}\"", rdb.ControllerProduct);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.controllerRevision = \"{0}\"", rdb.ControllerRevision); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.controllerRevision = \"{0}\"", rdb.ControllerRevision);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved16 = 0x{0:X8}", rdb.Reserved16); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved16 = 0x{0:X8}", rdb.Reserved16);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved17 = 0x{0:X8}", rdb.Reserved17); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved17 = 0x{0:X8}", rdb.Reserved17);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved18 = 0x{0:X8}", rdb.Reserved18); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved18 = 0x{0:X8}", rdb.Reserved18);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved19 = 0x{0:X8}", rdb.Reserved19); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved19 = 0x{0:X8}", rdb.Reserved19);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved20 = 0x{0:X8}", rdb.Reserved20); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved20 = 0x{0:X8}", rdb.Reserved20);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved21 = 0x{0:X8}", rdb.Reserved21); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved21 = 0x{0:X8}", rdb.Reserved21);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved22 = 0x{0:X8}", rdb.Reserved22); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved22 = 0x{0:X8}", rdb.Reserved22);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved23 = 0x{0:X8}", rdb.Reserved23); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved23 = 0x{0:X8}", rdb.Reserved23);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved24 = 0x{0:X8}", rdb.Reserved24); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved24 = 0x{0:X8}", rdb.Reserved24);
DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved25 = 0x{0:X8}", rdb.Reserved25); DicConsole.DebugWriteLine("Amiga RDB plugin", "RDB.reserved25 = 0x{0:X8}", rdb.Reserved25);
ulong nextBlock; ulong nextBlock;
// Reading BadBlock list // Reading BadBlock list
List<BadBlockList> badBlockChain = new List<BadBlockList>(); List<BadBlockList> badBlockChain = new List<BadBlockList>();
nextBlock = rdb.BadblockPtr; nextBlock = rdb.BadblockPtr;
while(nextBlock != 0xFFFFFFFF) while(nextBlock != 0xFFFFFFFF)
{ {
DicConsole.DebugWriteLine("Amiga RDB plugin", "Going to block {0} in search of a BadBlock block", DicConsole.DebugWriteLine("Amiga RDB plugin", "Going to block {0} in search of a BadBlock block",
nextBlock); nextBlock);
sector = imagePlugin.ReadSector(nextBlock); sector = imagePlugin.ReadSector(nextBlock);
uint magic = BigEndianBitConverter.ToUInt32(sector, 0); uint magic = BigEndianBitConverter.ToUInt32(sector, 0);
if(magic != BAD_BLOCK_LIST_MAGIC) break; if(magic != BAD_BLOCK_LIST_MAGIC) break;
@@ -463,27 +463,28 @@ namespace DiscImageChef.Partitions
BadBlockList chainEntry = new BadBlockList BadBlockList chainEntry = new BadBlockList
{ {
Magic = BigEndianBitConverter.ToUInt32(sector, 0x00), Magic = BigEndianBitConverter.ToUInt32(sector, 0x00),
Size = BigEndianBitConverter.ToUInt32(sector, 0x04), Size = BigEndianBitConverter.ToUInt32(sector, 0x04),
Checksum = BigEndianBitConverter.ToInt32(sector, 0x08), Checksum = BigEndianBitConverter.ToInt32(sector, 0x08),
TargetId = BigEndianBitConverter.ToUInt32(sector, 0x0C), TargetId = BigEndianBitConverter.ToUInt32(sector, 0x0C),
NextPtr = BigEndianBitConverter.ToUInt32(sector, 0x10), NextPtr = BigEndianBitConverter.ToUInt32(sector, 0x10),
Reserved = BigEndianBitConverter.ToUInt32(sector, 0x14) Reserved = BigEndianBitConverter.ToUInt32(sector, 0x14)
}; };
ulong entries = (chainEntry.Size - 6) / 2; ulong entries = (chainEntry.Size - 6) / 2;
chainEntry.BlockPairs = new BadBlockEntry[entries]; chainEntry.BlockPairs = new BadBlockEntry[entries];
DicConsole.DebugWriteLine("Amiga RDB plugin", "chainEntry.magic = 0x{0:X8}", chainEntry.Magic); DicConsole.DebugWriteLine("Amiga RDB plugin", "chainEntry.magic = 0x{0:X8}", chainEntry.Magic);
DicConsole.DebugWriteLine("Amiga RDB plugin", "chainEntry.size = {0} longs, {1} bytes", chainEntry.Size, DicConsole.DebugWriteLine("Amiga RDB plugin", "chainEntry.size = {0} longs, {1} bytes", chainEntry.Size,
chainEntry.Size * 4); chainEntry.Size * 4);
DicConsole.DebugWriteLine("Amiga RDB plugin", "chainEntry.checksum = 0x{0:X8}", chainEntry.Checksum); DicConsole.DebugWriteLine("Amiga RDB plugin", "chainEntry.checksum = 0x{0:X8}", chainEntry.Checksum);
DicConsole.DebugWriteLine("Amiga RDB plugin", "chainEntry.targetID = {0}", chainEntry.TargetId); DicConsole.DebugWriteLine("Amiga RDB plugin", "chainEntry.targetID = {0}", chainEntry.TargetId);
DicConsole.DebugWriteLine("Amiga RDB plugin", "chainEntry.next_ptr = {0}", chainEntry.NextPtr); DicConsole.DebugWriteLine("Amiga RDB plugin", "chainEntry.next_ptr = {0}", chainEntry.NextPtr);
DicConsole.DebugWriteLine("Amiga RDB plugin", "chainEntry.reserved = 0x{0:X8}", chainEntry.Reserved); DicConsole.DebugWriteLine("Amiga RDB plugin", "chainEntry.reserved = 0x{0:X8}", chainEntry.Reserved);
for(ulong i = 0; i < entries; i++) for(ulong i = 0; i < entries; i++)
{ {
chainEntry.BlockPairs[i].BadBlock = BigEndianBitConverter.ToUInt32(sector, (int)(0x18 + i * 8 + 0)); chainEntry.BlockPairs[i].BadBlock =
BigEndianBitConverter.ToUInt32(sector, (int)(0x18 + i * 8 + 0));
chainEntry.BlockPairs[i].GoodBlock = chainEntry.BlockPairs[i].GoodBlock =
BigEndianBitConverter.ToUInt32(sector, (int)(0x18 + i * 8 + 4)); BigEndianBitConverter.ToUInt32(sector, (int)(0x18 + i * 8 + 4));
@@ -497,13 +498,13 @@ namespace DiscImageChef.Partitions
// Reading BadBlock list // Reading BadBlock list
List<PartitionEntry> partitionEntries = new List<PartitionEntry>(); List<PartitionEntry> partitionEntries = new List<PartitionEntry>();
nextBlock = rdb.PartitionPtr; nextBlock = rdb.PartitionPtr;
while(nextBlock != 0xFFFFFFFF) while(nextBlock != 0xFFFFFFFF)
{ {
DicConsole.DebugWriteLine("Amiga RDB plugin", "Going to block {0} in search of a PartitionEntry block", DicConsole.DebugWriteLine("Amiga RDB plugin", "Going to block {0} in search of a PartitionEntry block",
nextBlock + sectorOffset); nextBlock + sectorOffset);
sector = imagePlugin.ReadSector(nextBlock + sectorOffset); sector = imagePlugin.ReadSector(nextBlock + sectorOffset);
uint magic = BigEndianBitConverter.ToUInt32(sector, 0); uint magic = BigEndianBitConverter.ToUInt32(sector, 0);
if(magic != PARTITION_BLOCK_MAGIC) break; if(magic != PARTITION_BLOCK_MAGIC) break;
@@ -512,53 +513,53 @@ namespace DiscImageChef.Partitions
PartitionEntry partEntry = new PartitionEntry PartitionEntry partEntry = new PartitionEntry
{ {
Magic = BigEndianBitConverter.ToUInt32(sector, 0x00), Magic = BigEndianBitConverter.ToUInt32(sector, 0x00),
Size = BigEndianBitConverter.ToUInt32(sector, 0x04), Size = BigEndianBitConverter.ToUInt32(sector, 0x04),
Checksum = BigEndianBitConverter.ToInt32(sector, 0x08), Checksum = BigEndianBitConverter.ToInt32(sector, 0x08),
TargetId = BigEndianBitConverter.ToUInt32(sector, 0x0C), TargetId = BigEndianBitConverter.ToUInt32(sector, 0x0C),
NextPtr = BigEndianBitConverter.ToUInt32(sector, 0x10), NextPtr = BigEndianBitConverter.ToUInt32(sector, 0x10),
Flags = BigEndianBitConverter.ToUInt32(sector, 0x14), Flags = BigEndianBitConverter.ToUInt32(sector, 0x14),
Reserved1 = BigEndianBitConverter.ToUInt32(sector, 0x18), Reserved1 = BigEndianBitConverter.ToUInt32(sector, 0x18),
Reserved2 = BigEndianBitConverter.ToUInt32(sector, 0x1C), Reserved2 = BigEndianBitConverter.ToUInt32(sector, 0x1C),
DevFlags = BigEndianBitConverter.ToUInt32(sector, 0x20), DevFlags = BigEndianBitConverter.ToUInt32(sector, 0x20),
DriveNameLen = sector[0x24], DriveNameLen = sector[0x24],
Reserved3 = BigEndianBitConverter.ToUInt32(sector, 0x44), Reserved3 = BigEndianBitConverter.ToUInt32(sector, 0x44),
Reserved4 = BigEndianBitConverter.ToUInt32(sector, 0x48), Reserved4 = BigEndianBitConverter.ToUInt32(sector, 0x48),
Reserved5 = BigEndianBitConverter.ToUInt32(sector, 0x4C), Reserved5 = BigEndianBitConverter.ToUInt32(sector, 0x4C),
Reserved6 = BigEndianBitConverter.ToUInt32(sector, 0x50), Reserved6 = BigEndianBitConverter.ToUInt32(sector, 0x50),
Reserved7 = BigEndianBitConverter.ToUInt32(sector, 0x54), Reserved7 = BigEndianBitConverter.ToUInt32(sector, 0x54),
Reserved8 = BigEndianBitConverter.ToUInt32(sector, 0x58), Reserved8 = BigEndianBitConverter.ToUInt32(sector, 0x58),
Reserved9 = BigEndianBitConverter.ToUInt32(sector, 0x5C), Reserved9 = BigEndianBitConverter.ToUInt32(sector, 0x5C),
Reserved10 = BigEndianBitConverter.ToUInt32(sector, 0x60), Reserved10 = BigEndianBitConverter.ToUInt32(sector, 0x60),
Reserved11 = BigEndianBitConverter.ToUInt32(sector, 0x64), Reserved11 = BigEndianBitConverter.ToUInt32(sector, 0x64),
Reserved12 = BigEndianBitConverter.ToUInt32(sector, 0x68), Reserved12 = BigEndianBitConverter.ToUInt32(sector, 0x68),
Reserved13 = BigEndianBitConverter.ToUInt32(sector, 0x6C), Reserved13 = BigEndianBitConverter.ToUInt32(sector, 0x6C),
Reserved14 = BigEndianBitConverter.ToUInt32(sector, 0x70), Reserved14 = BigEndianBitConverter.ToUInt32(sector, 0x70),
Reserved15 = BigEndianBitConverter.ToUInt32(sector, 0x74), Reserved15 = BigEndianBitConverter.ToUInt32(sector, 0x74),
Reserved16 = BigEndianBitConverter.ToUInt32(sector, 0x78), Reserved16 = BigEndianBitConverter.ToUInt32(sector, 0x78),
Reserved17 = BigEndianBitConverter.ToUInt32(sector, 0x7C), Reserved17 = BigEndianBitConverter.ToUInt32(sector, 0x7C),
DosEnvVec = new DosEnvironmentVector DosEnvVec = new DosEnvironmentVector
{ {
Size = BigEndianBitConverter.ToUInt32(sector, 0x80), Size = BigEndianBitConverter.ToUInt32(sector, 0x80),
BlockSize = BigEndianBitConverter.ToUInt32(sector, 0x84), BlockSize = BigEndianBitConverter.ToUInt32(sector, 0x84),
SecOrg = BigEndianBitConverter.ToUInt32(sector, 0x88), SecOrg = BigEndianBitConverter.ToUInt32(sector, 0x88),
Surfaces = BigEndianBitConverter.ToUInt32(sector, 0x8C), Surfaces = BigEndianBitConverter.ToUInt32(sector, 0x8C),
Spb = BigEndianBitConverter.ToUInt32(sector, 0x90), Spb = BigEndianBitConverter.ToUInt32(sector, 0x90),
Bpt = BigEndianBitConverter.ToUInt32(sector, 0x94), Bpt = BigEndianBitConverter.ToUInt32(sector, 0x94),
Reservedblocks = BigEndianBitConverter.ToUInt32(sector, 0x98), Reservedblocks = BigEndianBitConverter.ToUInt32(sector, 0x98),
Prealloc = BigEndianBitConverter.ToUInt32(sector, 0x9C), Prealloc = BigEndianBitConverter.ToUInt32(sector, 0x9C),
Interleave = BigEndianBitConverter.ToUInt32(sector, 0xA0), Interleave = BigEndianBitConverter.ToUInt32(sector, 0xA0),
LowCylinder = BigEndianBitConverter.ToUInt32(sector, 0xA4), LowCylinder = BigEndianBitConverter.ToUInt32(sector, 0xA4),
HighCylinder = BigEndianBitConverter.ToUInt32(sector, 0xA8), HighCylinder = BigEndianBitConverter.ToUInt32(sector, 0xA8),
NumBuffer = BigEndianBitConverter.ToUInt32(sector, 0xAC), NumBuffer = BigEndianBitConverter.ToUInt32(sector, 0xAC),
BufMemType = BigEndianBitConverter.ToUInt32(sector, 0xB0), BufMemType = BigEndianBitConverter.ToUInt32(sector, 0xB0),
MaxTransfer = BigEndianBitConverter.ToUInt32(sector, 0xB4), MaxTransfer = BigEndianBitConverter.ToUInt32(sector, 0xB4),
Mask = BigEndianBitConverter.ToUInt32(sector, 0xB8), Mask = BigEndianBitConverter.ToUInt32(sector, 0xB8),
BootPriority = BigEndianBitConverter.ToUInt32(sector, 0xBC), BootPriority = BigEndianBitConverter.ToUInt32(sector, 0xBC),
DosType = BigEndianBitConverter.ToUInt32(sector, 0xC0), DosType = BigEndianBitConverter.ToUInt32(sector, 0xC0),
Baud = BigEndianBitConverter.ToUInt32(sector, 0xC4), Baud = BigEndianBitConverter.ToUInt32(sector, 0xC4),
Control = BigEndianBitConverter.ToUInt32(sector, 0xC8), Control = BigEndianBitConverter.ToUInt32(sector, 0xC8),
BootBlocks = BigEndianBitConverter.ToUInt32(sector, 0xCC) BootBlocks = BigEndianBitConverter.ToUInt32(sector, 0xCC)
} }
}; };
@@ -569,22 +570,23 @@ namespace DiscImageChef.Partitions
DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.magic = 0x{0:X8}", partEntry.Magic); DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.magic = 0x{0:X8}", partEntry.Magic);
DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.size = {0} longs, {1} bytes", partEntry.Size, DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.size = {0} longs, {1} bytes", partEntry.Size,
partEntry.Size * 4); partEntry.Size * 4);
DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.checksum = 0x{0:X8}", partEntry.Checksum); DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.checksum = 0x{0:X8}", partEntry.Checksum);
DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.targetID = {0}", partEntry.TargetId); DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.targetID = {0}", partEntry.TargetId);
DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.next_ptr = {0}", partEntry.NextPtr); DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.next_ptr = {0}", partEntry.NextPtr);
DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.flags = 0x{0:X8}", partEntry.Flags); DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.flags = 0x{0:X8}", partEntry.Flags);
DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.reserved1 = 0x{0:X8}", partEntry.Reserved1); DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.reserved1 = 0x{0:X8}", partEntry.Reserved1);
DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.reserved2 = 0x{0:X8}", partEntry.Reserved2); DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.reserved2 = 0x{0:X8}", partEntry.Reserved2);
DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.devFlags = 0x{0:X8}", partEntry.DevFlags); DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.devFlags = 0x{0:X8}", partEntry.DevFlags);
DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.driveNameLen = {0}", partEntry.DriveNameLen); DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.driveNameLen = {0}",
DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.driveName = \"{0}\"", partEntry.DriveName); partEntry.DriveNameLen);
DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.reserved3 = 0x{0:X8}", partEntry.Reserved3); DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.driveName = \"{0}\"", partEntry.DriveName);
DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.reserved4 = 0x{0:X8}", partEntry.Reserved4); DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.reserved3 = 0x{0:X8}", partEntry.Reserved3);
DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.reserved5 = 0x{0:X8}", partEntry.Reserved5); DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.reserved4 = 0x{0:X8}", partEntry.Reserved4);
DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.reserved6 = 0x{0:X8}", partEntry.Reserved6); DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.reserved5 = 0x{0:X8}", partEntry.Reserved5);
DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.reserved7 = 0x{0:X8}", partEntry.Reserved7); DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.reserved6 = 0x{0:X8}", partEntry.Reserved6);
DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.reserved8 = 0x{0:X8}", partEntry.Reserved8); DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.reserved7 = 0x{0:X8}", partEntry.Reserved7);
DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.reserved9 = 0x{0:X8}", partEntry.Reserved9); DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.reserved8 = 0x{0:X8}", partEntry.Reserved8);
DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.reserved9 = 0x{0:X8}", partEntry.Reserved9);
DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.reserved10 = 0x{0:X8}", partEntry.Reserved10); DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.reserved10 = 0x{0:X8}", partEntry.Reserved10);
DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.reserved11 = 0x{0:X8}", partEntry.Reserved11); DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.reserved11 = 0x{0:X8}", partEntry.Reserved11);
DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.reserved12 = 0x{0:X8}", partEntry.Reserved12); DicConsole.DebugWriteLine("Amiga RDB plugin", "partEntry.reserved12 = 0x{0:X8}", partEntry.Reserved12);
@@ -638,15 +640,15 @@ namespace DiscImageChef.Partitions
} }
// Reading BadBlock list // Reading BadBlock list
List<FileSystemHeader> fshdEntries = new List<FileSystemHeader>(); List<FileSystemHeader> fshdEntries = new List<FileSystemHeader>();
List<LoadSegment> segmentEntries = new List<LoadSegment>(); List<LoadSegment> segmentEntries = new List<LoadSegment>();
nextBlock = rdb.FsheaderPtr; nextBlock = rdb.FsheaderPtr;
while(nextBlock != 0xFFFFFFFF) while(nextBlock != 0xFFFFFFFF)
{ {
DicConsole.DebugWriteLine("Amiga RDB plugin", DicConsole.DebugWriteLine("Amiga RDB plugin",
"Going to block {0} in search of a FileSystemHeader block", nextBlock); "Going to block {0} in search of a FileSystemHeader block", nextBlock);
sector = imagePlugin.ReadSector(nextBlock); sector = imagePlugin.ReadSector(nextBlock);
uint magic = BigEndianBitConverter.ToUInt32(sector, 0); uint magic = BigEndianBitConverter.ToUInt32(sector, 0);
if(magic != FILESYSTEM_HEADER_MAGIC) break; if(magic != FILESYSTEM_HEADER_MAGIC) break;
@@ -655,65 +657,66 @@ namespace DiscImageChef.Partitions
FileSystemHeader fshd = new FileSystemHeader FileSystemHeader fshd = new FileSystemHeader
{ {
Magic = BigEndianBitConverter.ToUInt32(sector, 0x00), Magic = BigEndianBitConverter.ToUInt32(sector, 0x00),
Size = BigEndianBitConverter.ToUInt32(sector, 0x04), Size = BigEndianBitConverter.ToUInt32(sector, 0x04),
Checksum = BigEndianBitConverter.ToInt32(sector, 0x08), Checksum = BigEndianBitConverter.ToInt32(sector, 0x08),
TargetId = BigEndianBitConverter.ToUInt32(sector, 0x0C), TargetId = BigEndianBitConverter.ToUInt32(sector, 0x0C),
NextPtr = BigEndianBitConverter.ToUInt32(sector, 0x10), NextPtr = BigEndianBitConverter.ToUInt32(sector, 0x10),
Flags = BigEndianBitConverter.ToUInt32(sector, 0x14), Flags = BigEndianBitConverter.ToUInt32(sector, 0x14),
Reserved1 = BigEndianBitConverter.ToUInt32(sector, 0x18), Reserved1 = BigEndianBitConverter.ToUInt32(sector, 0x18),
Reserved2 = BigEndianBitConverter.ToUInt32(sector, 0x1C), Reserved2 = BigEndianBitConverter.ToUInt32(sector, 0x1C),
DosType = BigEndianBitConverter.ToUInt32(sector, 0x20), DosType = BigEndianBitConverter.ToUInt32(sector, 0x20),
Version = BigEndianBitConverter.ToUInt32(sector, 0x24), Version = BigEndianBitConverter.ToUInt32(sector, 0x24),
PatchFlags = BigEndianBitConverter.ToUInt32(sector, 0x28), PatchFlags = BigEndianBitConverter.ToUInt32(sector, 0x28),
Dnode = new DeviceNode Dnode = new DeviceNode
{ {
Type = BigEndianBitConverter.ToUInt32(sector, 0x2C), Type = BigEndianBitConverter.ToUInt32(sector, 0x2C),
Task = BigEndianBitConverter.ToUInt32(sector, 0x30), Task = BigEndianBitConverter.ToUInt32(sector, 0x30),
Locked = BigEndianBitConverter.ToUInt32(sector, 0x34), Locked = BigEndianBitConverter.ToUInt32(sector, 0x34),
Handler = BigEndianBitConverter.ToUInt32(sector, 0x38), Handler = BigEndianBitConverter.ToUInt32(sector, 0x38),
StackSize = BigEndianBitConverter.ToUInt32(sector, 0x3C), StackSize = BigEndianBitConverter.ToUInt32(sector, 0x3C),
Priority = BigEndianBitConverter.ToUInt32(sector, 0x40), Priority = BigEndianBitConverter.ToUInt32(sector, 0x40),
Startup = BigEndianBitConverter.ToUInt32(sector, 0x44), Startup = BigEndianBitConverter.ToUInt32(sector, 0x44),
SeglistPtr = BigEndianBitConverter.ToUInt32(sector, 0x48), SeglistPtr = BigEndianBitConverter.ToUInt32(sector, 0x48),
GlobalVec = BigEndianBitConverter.ToUInt32(sector, 0x4C) GlobalVec = BigEndianBitConverter.ToUInt32(sector, 0x4C)
} }
}; };
DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.magic = 0x{0:X8}", fshd.Magic); DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.magic = 0x{0:X8}", fshd.Magic);
DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.size = {0} longs, {1} bytes", fshd.Size, DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.size = {0} longs, {1} bytes", fshd.Size,
fshd.Size * 4); fshd.Size * 4);
DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.checksum = 0x{0:X8}", fshd.Checksum); DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.checksum = 0x{0:X8}", fshd.Checksum);
DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.targetID = {0}", fshd.TargetId); DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.targetID = {0}", fshd.TargetId);
DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.next_ptr = {0}", fshd.NextPtr); DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.next_ptr = {0}", fshd.NextPtr);
DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.flags = 0x{0:X8}", fshd.Flags); DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.flags = 0x{0:X8}", fshd.Flags);
DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.reserved1 = 0x{0:X8}", fshd.Reserved1); DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.reserved1 = 0x{0:X8}", fshd.Reserved1);
DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.reserved2 = 0x{0:X8}", fshd.Reserved2); DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.reserved2 = 0x{0:X8}", fshd.Reserved2);
DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.dosType = {0}", AmigaDosTypeToString(fshd.DosType)); DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.dosType = {0}",
AmigaDosTypeToString(fshd.DosType));
DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.version = {0:D2}.{1:D2} (0x{2:X8})", DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.version = {0:D2}.{1:D2} (0x{2:X8})",
(fshd.Version & 0xFFFF0000) >> 16, fshd.Version & 0xFFFF, fshd.Version); (fshd.Version & 0xFFFF0000) >> 16, fshd.Version & 0xFFFF, fshd.Version);
DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.patchFlags = 0x{0:X8}", fshd.PatchFlags); DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.patchFlags = 0x{0:X8}", fshd.PatchFlags);
DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.dnode.type = {0}", fshd.Dnode.Type); DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.dnode.type = {0}", fshd.Dnode.Type);
DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.dnode.task = {0}", fshd.Dnode.Task); DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.dnode.task = {0}", fshd.Dnode.Task);
DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.dnode.locked = {0}", fshd.Dnode.Locked); DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.dnode.locked = {0}", fshd.Dnode.Locked);
DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.dnode.handler = {0}", fshd.Dnode.Handler); DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.dnode.handler = {0}", fshd.Dnode.Handler);
DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.dnode.stackSize = {0}", fshd.Dnode.StackSize); DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.dnode.stackSize = {0}", fshd.Dnode.StackSize);
DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.dnode.priority = {0}", fshd.Dnode.Priority); DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.dnode.priority = {0}", fshd.Dnode.Priority);
DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.dnode.startup = {0}", fshd.Dnode.Startup); DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.dnode.startup = {0}", fshd.Dnode.Startup);
DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.dnode.seglist_ptr = {0}", fshd.Dnode.SeglistPtr); DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.dnode.seglist_ptr = {0}",
fshd.Dnode.SeglistPtr);
DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.dnode.global_vec = 0x{0:X8}", fshd.Dnode.GlobalVec); DicConsole.DebugWriteLine("Amiga RDB plugin", "FSHD.dnode.global_vec = 0x{0:X8}", fshd.Dnode.GlobalVec);
nextBlock = fshd.Dnode.SeglistPtr; nextBlock = fshd.Dnode.SeglistPtr;
bool thereAreLoadSegments = false; bool thereAreLoadSegments = false;
Sha1Context sha1Ctx = new Sha1Context(); Sha1Context sha1Ctx = new Sha1Context();
sha1Ctx.Init();
while(nextBlock != 0xFFFFFFFF) while(nextBlock != 0xFFFFFFFF)
{ {
DicConsole.DebugWriteLine("Amiga RDB plugin", "Going to block {0} in search of a LoadSegment block", DicConsole.DebugWriteLine("Amiga RDB plugin", "Going to block {0} in search of a LoadSegment block",
nextBlock); nextBlock);
sector = imagePlugin.ReadSector(nextBlock); sector = imagePlugin.ReadSector(nextBlock);
uint magicSeg = BigEndianBitConverter.ToUInt32(sector, 0); uint magicSeg = BigEndianBitConverter.ToUInt32(sector, 0);
if(magicSeg != LOAD_SEG_MAGIC) break; if(magicSeg != LOAD_SEG_MAGIC) break;
@@ -721,23 +724,23 @@ namespace DiscImageChef.Partitions
DicConsole.DebugWriteLine("Amiga RDB plugin", "Found LoadSegment block"); DicConsole.DebugWriteLine("Amiga RDB plugin", "Found LoadSegment block");
thereAreLoadSegments = true; thereAreLoadSegments = true;
LoadSegment loadSeg = new LoadSegment LoadSegment loadSeg = new LoadSegment
{ {
Magic = BigEndianBitConverter.ToUInt32(sector, 0x00), Magic = BigEndianBitConverter.ToUInt32(sector, 0x00),
Size = BigEndianBitConverter.ToUInt32(sector, 0x04), Size = BigEndianBitConverter.ToUInt32(sector, 0x04),
Checksum = BigEndianBitConverter.ToInt32(sector, 0x08), Checksum = BigEndianBitConverter.ToInt32(sector, 0x08),
TargetId = BigEndianBitConverter.ToUInt32(sector, 0x0C), TargetId = BigEndianBitConverter.ToUInt32(sector, 0x0C),
NextPtr = BigEndianBitConverter.ToUInt32(sector, 0x10) NextPtr = BigEndianBitConverter.ToUInt32(sector, 0x10)
}; };
loadSeg.LoadData = new byte[(loadSeg.Size - 5) * 4]; loadSeg.LoadData = new byte[(loadSeg.Size - 5) * 4];
Array.Copy(sector, 0x14, loadSeg.LoadData, 0, (loadSeg.Size - 5) * 4); Array.Copy(sector, 0x14, loadSeg.LoadData, 0, (loadSeg.Size - 5) * 4);
DicConsole.DebugWriteLine("Amiga RDB plugin", "loadSeg.magic = 0x{0:X8}", loadSeg.Magic); DicConsole.DebugWriteLine("Amiga RDB plugin", "loadSeg.magic = 0x{0:X8}", loadSeg.Magic);
DicConsole.DebugWriteLine("Amiga RDB plugin", "loadSeg.size = {0} longs, {1} bytes", loadSeg.Size, DicConsole.DebugWriteLine("Amiga RDB plugin", "loadSeg.size = {0} longs, {1} bytes", loadSeg.Size,
loadSeg.Size * 4); loadSeg.Size * 4);
DicConsole.DebugWriteLine("Amiga RDB plugin", "loadSeg.checksum = 0x{0:X8}", loadSeg.Checksum); DicConsole.DebugWriteLine("Amiga RDB plugin", "loadSeg.checksum = 0x{0:X8}", loadSeg.Checksum);
DicConsole.DebugWriteLine("Amiga RDB plugin", "loadSeg.targetID = {0}", loadSeg.TargetId); DicConsole.DebugWriteLine("Amiga RDB plugin", "loadSeg.targetID = {0}", loadSeg.TargetId);
DicConsole.DebugWriteLine("Amiga RDB plugin", "loadSeg.next_ptr = {0}", loadSeg.NextPtr); DicConsole.DebugWriteLine("Amiga RDB plugin", "loadSeg.next_ptr = {0}", loadSeg.NextPtr);
segmentEntries.Add(loadSeg); segmentEntries.Add(loadSeg);
nextBlock = loadSeg.NextPtr; nextBlock = loadSeg.NextPtr;
@@ -759,21 +762,23 @@ namespace DiscImageChef.Partitions
foreach(Partition entry in partitionEntries.Select(rdbEntry => new Partition foreach(Partition entry in partitionEntries.Select(rdbEntry => new Partition
{ {
Description = AmigaDosTypeToDescriptionString(rdbEntry.DosEnvVec.DosType), Description = AmigaDosTypeToDescriptionString(rdbEntry.DosEnvVec.DosType),
Name = rdbEntry.DriveName, Name = rdbEntry.DriveName,
Sequence = sequence, Sequence = sequence,
Length = Length =
(rdbEntry.DosEnvVec.HighCylinder + 1 - rdbEntry.DosEnvVec.LowCylinder) * (rdbEntry.DosEnvVec.HighCylinder + 1 - rdbEntry.DosEnvVec.LowCylinder) *
rdbEntry.DosEnvVec.Surfaces * rdbEntry.DosEnvVec.Bpt, rdbEntry.DosEnvVec.Surfaces * rdbEntry.DosEnvVec.Bpt,
Start = Start =
rdbEntry.DosEnvVec.LowCylinder * rdbEntry.DosEnvVec.Surfaces * rdbEntry.DosEnvVec.Bpt + rdbEntry.DosEnvVec.LowCylinder * rdbEntry.DosEnvVec.Surfaces * rdbEntry.DosEnvVec.Bpt +
sectorOffset, sectorOffset,
Type = AmigaDosTypeToString(rdbEntry.DosEnvVec.DosType), Type = AmigaDosTypeToString(rdbEntry.DosEnvVec.DosType),
Scheme = Name, Scheme = Name,
Offset = Offset =
(rdbEntry.DosEnvVec.LowCylinder * rdbEntry.DosEnvVec.Surfaces * rdbEntry.DosEnvVec.Bpt + (rdbEntry.DosEnvVec.LowCylinder *
sectorOffset) * rdb.BlockSize, rdbEntry.DosEnvVec.Surfaces * rdbEntry.DosEnvVec.Bpt +
sectorOffset) * rdb.BlockSize,
Size = (rdbEntry.DosEnvVec.HighCylinder + 1 - rdbEntry.DosEnvVec.LowCylinder) * Size = (rdbEntry.DosEnvVec.HighCylinder + 1 - rdbEntry.DosEnvVec.LowCylinder) *
rdbEntry.DosEnvVec.Surfaces * rdbEntry.DosEnvVec.Bpt * rdb.BlockSize rdbEntry.DosEnvVec.Surfaces * rdbEntry.DosEnvVec.Bpt *
rdb.BlockSize
})) }))
{ {
partitions.Add(entry); partitions.Add(entry);
@@ -787,28 +792,28 @@ namespace DiscImageChef.Partitions
{ {
switch(amigaDosType) switch(amigaDosType)
{ {
case TYPEID_OFS: return "Amiga Original File System"; case TYPEID_OFS: return "Amiga Original File System";
case TYPEID_FFS: return "Amiga Fast File System"; case TYPEID_FFS: return "Amiga Fast File System";
case TYPEID_OFS_INTL: return "Amiga Original File System with international characters"; case TYPEID_OFS_INTL: return "Amiga Original File System with international characters";
case TYPEID_FFS_INTL: return "Amiga Fast File System with international characters"; case TYPEID_FFS_INTL: return "Amiga Fast File System with international characters";
case TYPEID_OFS_CACHE: return "Amiga Original File System with directory cache"; case TYPEID_OFS_CACHE: return "Amiga Original File System with directory cache";
case TYPEID_FFS_CACHE: return "Amiga Fast File System with directory cache"; case TYPEID_FFS_CACHE: return "Amiga Fast File System with directory cache";
case TYPEID_OFS2: return "Amiga Original File System with long filenames"; case TYPEID_OFS2: return "Amiga Original File System with long filenames";
case TYPEID_FFS2: return "Amiga Fast File System with long filenames"; case TYPEID_FFS2: return "Amiga Fast File System with long filenames";
case TYPEID_AMIX_SYSV: return "Amiga UNIX System V filesystem"; case TYPEID_AMIX_SYSV: return "Amiga UNIX System V filesystem";
case TYPEID_AMIX_BOOT: return "Amiga UNIX boot filesystem"; case TYPEID_AMIX_BOOT: return "Amiga UNIX boot filesystem";
case TYPEID_AMIX_FFS: return "Amiga UNIX BSD filesystem"; case TYPEID_AMIX_FFS: return "Amiga UNIX BSD filesystem";
case TYPEID_AMIX_RESERVED: return "Amiga UNIX Reserved partition (swap)"; case TYPEID_AMIX_RESERVED: return "Amiga UNIX Reserved partition (swap)";
case TYPEID_PFS: case TYPEID_PFS:
case TYPEID_PFS2: case TYPEID_PFS2:
case TYPEID_PFS_MUSER: case TYPEID_PFS_MUSER:
case TYPEID_AFS: return "ProfessionalFileSystem"; case TYPEID_AFS: return "ProfessionalFileSystem";
case TYPEID_SFS: return "SmartFileSystem v1"; case TYPEID_SFS: return "SmartFileSystem v1";
case TYPEID_SFS2: return "SmartFileSystem v2"; case TYPEID_SFS2: return "SmartFileSystem v2";
case TYPEID_JXFS: return "JXFS"; case TYPEID_JXFS: return "JXFS";
case TYPEID_CROSS_DOS: return "FAT, as set by CrossDOS"; case TYPEID_CROSS_DOS: return "FAT, as set by CrossDOS";
case TYPEID_CROSS_MAC: return "HFS, as set by CrossMac"; case TYPEID_CROSS_MAC: return "HFS, as set by CrossMac";
case TYPEID_BFFS: return "4.2UFS, for BFFS"; case TYPEID_BFFS: return "4.2UFS, for BFFS";
case TYPEID_OFS_MUSER: return "Amiga Original File System with multi-user patches"; case TYPEID_OFS_MUSER: return "Amiga Original File System with multi-user patches";
case TYPEID_FFS_MUSER: return "Amiga Fast File System with multi-user patches"; case TYPEID_FFS_MUSER: return "Amiga Fast File System with multi-user patches";
case TYPEID_OFS_INTL_MUSER: case TYPEID_OFS_INTL_MUSER:
@@ -819,19 +824,19 @@ namespace DiscImageChef.Partitions
return "Amiga Original File System with directory cache and multi-user patches"; return "Amiga Original File System with directory cache and multi-user patches";
case TYPEID_FFS_CACHE_MUSER: case TYPEID_FFS_CACHE_MUSER:
return "Amiga Fast File System with directory cache and multi-user patches"; return "Amiga Fast File System with directory cache and multi-user patches";
case TYPEID_OLD_BSD_UNUSED: return "BSD unused"; case TYPEID_OLD_BSD_UNUSED: return "BSD unused";
case TYPEID_OLD_BSD_SWAP: return "BSD swap"; case TYPEID_OLD_BSD_SWAP: return "BSD swap";
case TYPEID_OLD_BSD42_FFS: return "BSD 4.2 FFS"; case TYPEID_OLD_BSD42_FFS: return "BSD 4.2 FFS";
case TYPEID_OLD_BSD44_LFS: return "BSD 4.4 LFS"; case TYPEID_OLD_BSD44_LFS: return "BSD 4.4 LFS";
case TYPEID_NETBSD_ROOT_UNUSED: return "NetBSD unused root partition"; case TYPEID_NETBSD_ROOT_UNUSED: return "NetBSD unused root partition";
case TYPEID_NETBSD_ROOT_42FFS: return "NetBSD 4.2 FFS root partition"; case TYPEID_NETBSD_ROOT_42FFS: return "NetBSD 4.2 FFS root partition";
case TYPEID_NETBSD_ROOT_44LFS: return "NetBSD 4.4 LFS root partition"; case TYPEID_NETBSD_ROOT_44LFS: return "NetBSD 4.4 LFS root partition";
case TYPEID_NETBSD_USER_UNUSED: return "NetBSD unused user partition"; case TYPEID_NETBSD_USER_UNUSED: return "NetBSD unused user partition";
case TYPEID_NETBSD_USER_42FFS: return "NetBSD 4.2 FFS user partition"; case TYPEID_NETBSD_USER_42FFS: return "NetBSD 4.2 FFS user partition";
case TYPEID_NETBSD_USER_44LFS: return "NetBSD 4.4 LFS user partition"; case TYPEID_NETBSD_USER_44LFS: return "NetBSD 4.4 LFS user partition";
case TYPEID_NETBSD_SWAP: return "NetBSD swap partition"; case TYPEID_NETBSD_SWAP: return "NetBSD swap partition";
case TYPEID_LINUX: return "Linux filesystem partition"; case TYPEID_LINUX: return "Linux filesystem partition";
case TYPEID_LINUX_SWAP: return "Linux swap partition"; case TYPEID_LINUX_SWAP: return "Linux swap partition";
case TYPEID_RAID_FRAME: case TYPEID_RAID_FRAME:
case TYPEID_RAID_FRAME0: return "RaidFrame partition"; case TYPEID_RAID_FRAME0: return "RaidFrame partition";
@@ -864,7 +869,7 @@ namespace DiscImageChef.Partitions
if((amigaDosType & TYPEID_NETBSD_SWAP) == TYPEID_NETBSD_SWAP) if((amigaDosType & TYPEID_NETBSD_SWAP) == TYPEID_NETBSD_SWAP)
return $"Unknown NetBSD swap filesystem type {AmigaDosTypeToString(amigaDosType)}"; return $"Unknown NetBSD swap filesystem type {AmigaDosTypeToString(amigaDosType)}";
if((amigaDosType & TYPEID_LINUX) == TYPEID_LINUX || if((amigaDosType & TYPEID_LINUX) == TYPEID_LINUX ||
(amigaDosType & TYPEID_LINUX_SWAP) == TYPEID_LINUX_SWAP) (amigaDosType & TYPEID_LINUX_SWAP) == TYPEID_LINUX_SWAP)
return $"Unknown Linux filesystem type {AmigaDosTypeToString(amigaDosType)}"; return $"Unknown Linux filesystem type {AmigaDosTypeToString(amigaDosType)}";

View File

@@ -35,7 +35,7 @@ namespace DiscImageChef.Tests.Checksums
[TestFixture] [TestFixture]
public class Adler32 public class Adler32
{ {
static readonly byte[] ExpectedEmpty = {0x00, 0xf0, 0x00, 0x01}; static readonly byte[] ExpectedEmpty = {0x00, 0xf0, 0x00, 0x01};
static readonly byte[] ExpectedRandom = {0x37, 0x28, 0xd1, 0x86}; static readonly byte[] ExpectedRandom = {0x37, 0x28, 0xd1, 0x86};
[Test] [Test]
@@ -48,9 +48,9 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Adler32EmptyData() public void Adler32EmptyData()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
@@ -61,14 +61,13 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Adler32EmptyInstance() public void Adler32EmptyInstance()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
IChecksum ctx = new Adler32Context(); IChecksum ctx = new Adler32Context();
ctx.Init();
ctx.Update(data); ctx.Update(data);
byte[] result = ctx.Final(); byte[] result = ctx.Final();
Assert.AreEqual(ExpectedEmpty, result); Assert.AreEqual(ExpectedEmpty, result);
@@ -84,9 +83,9 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Adler32RandomData() public void Adler32RandomData()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
@@ -97,14 +96,13 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Adler32RandomInstance() public void Adler32RandomInstance()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
IChecksum ctx = new Adler32Context(); IChecksum ctx = new Adler32Context();
ctx.Init();
ctx.Update(data); ctx.Update(data);
byte[] result = ctx.Final(); byte[] result = ctx.Final();
Assert.AreEqual(ExpectedRandom, result); Assert.AreEqual(ExpectedRandom, result);

View File

@@ -35,7 +35,7 @@ namespace DiscImageChef.Tests.Checksums
[TestFixture] [TestFixture]
public class Crc16 public class Crc16
{ {
static readonly byte[] ExpectedEmpty = {0x00, 0x00}; static readonly byte[] ExpectedEmpty = {0x00, 0x00};
static readonly byte[] ExpectedRandom = {0x2d, 0x6d}; static readonly byte[] ExpectedRandom = {0x2d, 0x6d};
[Test] [Test]
@@ -48,9 +48,9 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Crc16EmptyData() public void Crc16EmptyData()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
@@ -61,14 +61,13 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Crc16EmptyInstance() public void Crc16EmptyInstance()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
IChecksum ctx = new Crc16Context(); IChecksum ctx = new Crc16Context();
ctx.Init();
ctx.Update(data); ctx.Update(data);
byte[] result = ctx.Final(); byte[] result = ctx.Final();
Assert.AreEqual(ExpectedEmpty, result); Assert.AreEqual(ExpectedEmpty, result);
@@ -84,9 +83,9 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Crc16RandomData() public void Crc16RandomData()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
@@ -97,14 +96,13 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Crc16RandomInstance() public void Crc16RandomInstance()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
IChecksum ctx = new Crc16Context(); IChecksum ctx = new Crc16Context();
ctx.Init();
ctx.Update(data); ctx.Update(data);
byte[] result = ctx.Final(); byte[] result = ctx.Final();
Assert.AreEqual(ExpectedRandom, result); Assert.AreEqual(ExpectedRandom, result);

View File

@@ -35,7 +35,7 @@ namespace DiscImageChef.Tests.Checksums
[TestFixture] [TestFixture]
public class Crc32 public class Crc32
{ {
static readonly byte[] ExpectedEmpty = {0xa7, 0x38, 0xea, 0x1c}; static readonly byte[] ExpectedEmpty = {0xa7, 0x38, 0xea, 0x1c};
static readonly byte[] ExpectedRandom = {0x2b, 0x6e, 0x68, 0x54}; static readonly byte[] ExpectedRandom = {0x2b, 0x6e, 0x68, 0x54};
[Test] [Test]
@@ -48,9 +48,9 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Crc32EmptyData() public void Crc32EmptyData()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
@@ -61,14 +61,13 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Crc32EmptyInstance() public void Crc32EmptyInstance()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
IChecksum ctx = new Crc32Context(); IChecksum ctx = new Crc32Context();
ctx.Init();
ctx.Update(data); ctx.Update(data);
byte[] result = ctx.Final(); byte[] result = ctx.Final();
Assert.AreEqual(ExpectedEmpty, result); Assert.AreEqual(ExpectedEmpty, result);
@@ -84,9 +83,9 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Crc32RandomData() public void Crc32RandomData()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
@@ -97,14 +96,13 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Crc32RandomInstance() public void Crc32RandomInstance()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
IChecksum ctx = new Crc32Context(); IChecksum ctx = new Crc32Context();
ctx.Init();
ctx.Update(data); ctx.Update(data);
byte[] result = ctx.Final(); byte[] result = ctx.Final();
Assert.AreEqual(ExpectedRandom, result); Assert.AreEqual(ExpectedRandom, result);

View File

@@ -35,7 +35,7 @@ namespace DiscImageChef.Tests.Checksums
[TestFixture] [TestFixture]
public class Crc64 public class Crc64
{ {
static readonly byte[] ExpectedEmpty = {0x60, 0x6b, 0x70, 0xa2, 0x3e, 0xba, 0xf6, 0xc2}; static readonly byte[] ExpectedEmpty = {0x60, 0x6b, 0x70, 0xa2, 0x3e, 0xba, 0xf6, 0xc2};
static readonly byte[] ExpectedRandom = {0xbf, 0x09, 0x99, 0x2c, 0xc5, 0xed, 0xe3, 0x8e}; static readonly byte[] ExpectedRandom = {0xbf, 0x09, 0x99, 0x2c, 0xc5, 0xed, 0xe3, 0x8e};
[Test] [Test]
@@ -48,9 +48,9 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Crc64EmptyData() public void Crc64EmptyData()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
@@ -61,14 +61,13 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Crc64EmptyInstance() public void Crc64EmptyInstance()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
IChecksum ctx = new Crc64Context(); IChecksum ctx = new Crc64Context();
ctx.Init();
ctx.Update(data); ctx.Update(data);
byte[] result = ctx.Final(); byte[] result = ctx.Final();
Assert.AreEqual(ExpectedEmpty, result); Assert.AreEqual(ExpectedEmpty, result);
@@ -84,9 +83,9 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Crc64RandomData() public void Crc64RandomData()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
@@ -97,14 +96,13 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Crc64RandomInstance() public void Crc64RandomInstance()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
IChecksum ctx = new Crc64Context(); IChecksum ctx = new Crc64Context();
ctx.Init();
ctx.Update(data); ctx.Update(data);
byte[] result = ctx.Final(); byte[] result = ctx.Final();
Assert.AreEqual(ExpectedRandom, result); Assert.AreEqual(ExpectedRandom, result);

View File

@@ -43,23 +43,21 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Md5EmptyFile() public void Md5EmptyFile()
{ {
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); byte[] result = ctx.File(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"));
byte[] result = ctx.File(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"));
Assert.AreEqual(ExpectedEmpty, result); Assert.AreEqual(ExpectedEmpty, result);
} }
[Test] [Test]
public void Md5EmptyData() public void Md5EmptyData()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init();
ctx.Data(data, out byte[] result); ctx.Data(data, out byte[] result);
Assert.AreEqual(ExpectedEmpty, result); Assert.AreEqual(ExpectedEmpty, result);
} }
@@ -67,14 +65,13 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Md5EmptyInstance() public void Md5EmptyInstance()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
IChecksum ctx = new Md5Context(); IChecksum ctx = new Md5Context();
ctx.Init();
ctx.Update(data); ctx.Update(data);
byte[] result = ctx.Final(); byte[] result = ctx.Final();
Assert.AreEqual(ExpectedEmpty, result); Assert.AreEqual(ExpectedEmpty, result);
@@ -83,23 +80,21 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Md5RandomFile() public void Md5RandomFile()
{ {
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); byte[] result = ctx.File(Path.Combine(Consts.TestFilesRoot, "checksums", "random"));
byte[] result = ctx.File(Path.Combine(Consts.TestFilesRoot, "checksums", "random"));
Assert.AreEqual(ExpectedRandom, result); Assert.AreEqual(ExpectedRandom, result);
} }
[Test] [Test]
public void Md5RandomData() public void Md5RandomData()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init();
ctx.Data(data, out byte[] result); ctx.Data(data, out byte[] result);
Assert.AreEqual(ExpectedRandom, result); Assert.AreEqual(ExpectedRandom, result);
} }
@@ -107,14 +102,13 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Md5RandomInstance() public void Md5RandomInstance()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
IChecksum ctx = new Md5Context(); IChecksum ctx = new Md5Context();
ctx.Init();
ctx.Update(data); ctx.Update(data);
byte[] result = ctx.Final(); byte[] result = ctx.Final();
Assert.AreEqual(ExpectedRandom, result); Assert.AreEqual(ExpectedRandom, result);

View File

@@ -49,23 +49,21 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Ripemd160EmptyFile() public void Ripemd160EmptyFile()
{ {
Ripemd160Context ctx = new Ripemd160Context(); Ripemd160Context ctx = new Ripemd160Context();
ctx.Init(); byte[] result = ctx.File(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"));
byte[] result = ctx.File(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"));
Assert.AreEqual(ExpectedEmpty, result); Assert.AreEqual(ExpectedEmpty, result);
} }
[Test] [Test]
public void Ripemd160EmptyData() public void Ripemd160EmptyData()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
Ripemd160Context ctx = new Ripemd160Context(); Ripemd160Context ctx = new Ripemd160Context();
ctx.Init();
ctx.Data(data, out byte[] result); ctx.Data(data, out byte[] result);
Assert.AreEqual(ExpectedEmpty, result); Assert.AreEqual(ExpectedEmpty, result);
} }
@@ -73,14 +71,13 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Ripemd160EmptyInstance() public void Ripemd160EmptyInstance()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
IChecksum ctx = new Ripemd160Context(); IChecksum ctx = new Ripemd160Context();
ctx.Init();
ctx.Update(data); ctx.Update(data);
byte[] result = ctx.Final(); byte[] result = ctx.Final();
Assert.AreEqual(ExpectedEmpty, result); Assert.AreEqual(ExpectedEmpty, result);
@@ -89,23 +86,21 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Ripemd160RandomFile() public void Ripemd160RandomFile()
{ {
Ripemd160Context ctx = new Ripemd160Context(); Ripemd160Context ctx = new Ripemd160Context();
ctx.Init(); byte[] result = ctx.File(Path.Combine(Consts.TestFilesRoot, "checksums", "random"));
byte[] result = ctx.File(Path.Combine(Consts.TestFilesRoot, "checksums", "random"));
Assert.AreEqual(ExpectedRandom, result); Assert.AreEqual(ExpectedRandom, result);
} }
[Test] [Test]
public void Ripemd160RandomData() public void Ripemd160RandomData()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
Ripemd160Context ctx = new Ripemd160Context(); Ripemd160Context ctx = new Ripemd160Context();
ctx.Init();
ctx.Data(data, out byte[] result); ctx.Data(data, out byte[] result);
Assert.AreEqual(ExpectedRandom, result); Assert.AreEqual(ExpectedRandom, result);
} }
@@ -113,14 +108,13 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Ripemd160RandomInstance() public void Ripemd160RandomInstance()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
IChecksum ctx = new Ripemd160Context(); IChecksum ctx = new Ripemd160Context();
ctx.Init();
ctx.Update(data); ctx.Update(data);
byte[] result = ctx.Final(); byte[] result = ctx.Final();
Assert.AreEqual(ExpectedRandom, result); Assert.AreEqual(ExpectedRandom, result);

View File

@@ -49,23 +49,21 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Sha1EmptyFile() public void Sha1EmptyFile()
{ {
Sha1Context ctx = new Sha1Context(); Sha1Context ctx = new Sha1Context();
ctx.Init(); byte[] result = ctx.File(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"));
byte[] result = ctx.File(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"));
Assert.AreEqual(ExpectedEmpty, result); Assert.AreEqual(ExpectedEmpty, result);
} }
[Test] [Test]
public void Sha1EmptyData() public void Sha1EmptyData()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
Sha1Context ctx = new Sha1Context(); Sha1Context ctx = new Sha1Context();
ctx.Init();
ctx.Data(data, out byte[] result); ctx.Data(data, out byte[] result);
Assert.AreEqual(ExpectedEmpty, result); Assert.AreEqual(ExpectedEmpty, result);
} }
@@ -73,14 +71,13 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Sha1EmptyInstance() public void Sha1EmptyInstance()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
IChecksum ctx = new Sha1Context(); IChecksum ctx = new Sha1Context();
ctx.Init();
ctx.Update(data); ctx.Update(data);
byte[] result = ctx.Final(); byte[] result = ctx.Final();
Assert.AreEqual(ExpectedEmpty, result); Assert.AreEqual(ExpectedEmpty, result);
@@ -89,23 +86,21 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Sha1RandomFile() public void Sha1RandomFile()
{ {
Sha1Context ctx = new Sha1Context(); Sha1Context ctx = new Sha1Context();
ctx.Init(); byte[] result = ctx.File(Path.Combine(Consts.TestFilesRoot, "checksums", "random"));
byte[] result = ctx.File(Path.Combine(Consts.TestFilesRoot, "checksums", "random"));
Assert.AreEqual(ExpectedRandom, result); Assert.AreEqual(ExpectedRandom, result);
} }
[Test] [Test]
public void Sha1RandomData() public void Sha1RandomData()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
Sha1Context ctx = new Sha1Context(); Sha1Context ctx = new Sha1Context();
ctx.Init();
ctx.Data(data, out byte[] result); ctx.Data(data, out byte[] result);
Assert.AreEqual(ExpectedRandom, result); Assert.AreEqual(ExpectedRandom, result);
} }
@@ -113,14 +108,13 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Sha1RandomInstance() public void Sha1RandomInstance()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
IChecksum ctx = new Sha1Context(); IChecksum ctx = new Sha1Context();
ctx.Init();
ctx.Update(data); ctx.Update(data);
byte[] result = ctx.Final(); byte[] result = ctx.Final();
Assert.AreEqual(ExpectedRandom, result); Assert.AreEqual(ExpectedRandom, result);

View File

@@ -49,23 +49,21 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Sha256EmptyFile() public void Sha256EmptyFile()
{ {
Sha256Context ctx = new Sha256Context(); Sha256Context ctx = new Sha256Context();
ctx.Init(); byte[] result = ctx.File(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"));
byte[] result = ctx.File(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"));
Assert.AreEqual(ExpectedEmpty, result); Assert.AreEqual(ExpectedEmpty, result);
} }
[Test] [Test]
public void Sha256EmptyData() public void Sha256EmptyData()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
Sha256Context ctx = new Sha256Context(); Sha256Context ctx = new Sha256Context();
ctx.Init();
ctx.Data(data, out byte[] result); ctx.Data(data, out byte[] result);
Assert.AreEqual(ExpectedEmpty, result); Assert.AreEqual(ExpectedEmpty, result);
} }
@@ -73,14 +71,13 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Sha256EmptyInstance() public void Sha256EmptyInstance()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
IChecksum ctx = new Sha256Context(); IChecksum ctx = new Sha256Context();
ctx.Init();
ctx.Update(data); ctx.Update(data);
byte[] result = ctx.Final(); byte[] result = ctx.Final();
Assert.AreEqual(ExpectedEmpty, result); Assert.AreEqual(ExpectedEmpty, result);
@@ -89,23 +86,21 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Sha256RandomFile() public void Sha256RandomFile()
{ {
Sha256Context ctx = new Sha256Context(); Sha256Context ctx = new Sha256Context();
ctx.Init(); byte[] result = ctx.File(Path.Combine(Consts.TestFilesRoot, "checksums", "random"));
byte[] result = ctx.File(Path.Combine(Consts.TestFilesRoot, "checksums", "random"));
Assert.AreEqual(ExpectedRandom, result); Assert.AreEqual(ExpectedRandom, result);
} }
[Test] [Test]
public void Sha256RandomData() public void Sha256RandomData()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
Sha256Context ctx = new Sha256Context(); Sha256Context ctx = new Sha256Context();
ctx.Init();
ctx.Data(data, out byte[] result); ctx.Data(data, out byte[] result);
Assert.AreEqual(ExpectedRandom, result); Assert.AreEqual(ExpectedRandom, result);
} }
@@ -113,14 +108,13 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Sha256RandomInstance() public void Sha256RandomInstance()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
IChecksum ctx = new Sha256Context(); IChecksum ctx = new Sha256Context();
ctx.Init();
ctx.Update(data); ctx.Update(data);
byte[] result = ctx.Final(); byte[] result = ctx.Final();
Assert.AreEqual(ExpectedRandom, result); Assert.AreEqual(ExpectedRandom, result);

View File

@@ -51,23 +51,21 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Sha384EmptyFile() public void Sha384EmptyFile()
{ {
Sha384Context ctx = new Sha384Context(); Sha384Context ctx = new Sha384Context();
ctx.Init(); byte[] result = ctx.File(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"));
byte[] result = ctx.File(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"));
Assert.AreEqual(ExpectedEmpty, result); Assert.AreEqual(ExpectedEmpty, result);
} }
[Test] [Test]
public void Sha384EmptyData() public void Sha384EmptyData()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
Sha384Context ctx = new Sha384Context(); Sha384Context ctx = new Sha384Context();
ctx.Init();
ctx.Data(data, out byte[] result); ctx.Data(data, out byte[] result);
Assert.AreEqual(ExpectedEmpty, result); Assert.AreEqual(ExpectedEmpty, result);
} }
@@ -75,14 +73,13 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Sha384EmptyInstance() public void Sha384EmptyInstance()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
IChecksum ctx = new Sha384Context(); IChecksum ctx = new Sha384Context();
ctx.Init();
ctx.Update(data); ctx.Update(data);
byte[] result = ctx.Final(); byte[] result = ctx.Final();
Assert.AreEqual(ExpectedEmpty, result); Assert.AreEqual(ExpectedEmpty, result);
@@ -91,23 +88,21 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Sha384RandomFile() public void Sha384RandomFile()
{ {
Sha384Context ctx = new Sha384Context(); Sha384Context ctx = new Sha384Context();
ctx.Init(); byte[] result = ctx.File(Path.Combine(Consts.TestFilesRoot, "checksums", "random"));
byte[] result = ctx.File(Path.Combine(Consts.TestFilesRoot, "checksums", "random"));
Assert.AreEqual(ExpectedRandom, result); Assert.AreEqual(ExpectedRandom, result);
} }
[Test] [Test]
public void Sha384RandomData() public void Sha384RandomData()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
Sha384Context ctx = new Sha384Context(); Sha384Context ctx = new Sha384Context();
ctx.Init();
ctx.Data(data, out byte[] result); ctx.Data(data, out byte[] result);
Assert.AreEqual(ExpectedRandom, result); Assert.AreEqual(ExpectedRandom, result);
} }
@@ -115,14 +110,13 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Sha384RandomInstance() public void Sha384RandomInstance()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
IChecksum ctx = new Sha384Context(); IChecksum ctx = new Sha384Context();
ctx.Init();
ctx.Update(data); ctx.Update(data);
byte[] result = ctx.Final(); byte[] result = ctx.Final();
Assert.AreEqual(ExpectedRandom, result); Assert.AreEqual(ExpectedRandom, result);

View File

@@ -53,23 +53,21 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Sha512EmptyFile() public void Sha512EmptyFile()
{ {
Sha512Context ctx = new Sha512Context(); Sha512Context ctx = new Sha512Context();
ctx.Init(); byte[] result = ctx.File(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"));
byte[] result = ctx.File(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"));
Assert.AreEqual(ExpectedEmpty, result); Assert.AreEqual(ExpectedEmpty, result);
} }
[Test] [Test]
public void Sha512EmptyData() public void Sha512EmptyData()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
Sha512Context ctx = new Sha512Context(); Sha512Context ctx = new Sha512Context();
ctx.Init();
ctx.Data(data, out byte[] result); ctx.Data(data, out byte[] result);
Assert.AreEqual(ExpectedEmpty, result); Assert.AreEqual(ExpectedEmpty, result);
} }
@@ -77,14 +75,13 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Sha512EmptyInstance() public void Sha512EmptyInstance()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
IChecksum ctx = new Sha512Context(); IChecksum ctx = new Sha512Context();
ctx.Init();
ctx.Update(data); ctx.Update(data);
byte[] result = ctx.Final(); byte[] result = ctx.Final();
Assert.AreEqual(ExpectedEmpty, result); Assert.AreEqual(ExpectedEmpty, result);
@@ -93,23 +90,21 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Sha512RandomFile() public void Sha512RandomFile()
{ {
Sha512Context ctx = new Sha512Context(); Sha512Context ctx = new Sha512Context();
ctx.Init(); byte[] result = ctx.File(Path.Combine(Consts.TestFilesRoot, "checksums", "random"));
byte[] result = ctx.File(Path.Combine(Consts.TestFilesRoot, "checksums", "random"));
Assert.AreEqual(ExpectedRandom, result); Assert.AreEqual(ExpectedRandom, result);
} }
[Test] [Test]
public void Sha512RandomData() public void Sha512RandomData()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
Sha512Context ctx = new Sha512Context(); Sha512Context ctx = new Sha512Context();
ctx.Init();
ctx.Data(data, out byte[] result); ctx.Data(data, out byte[] result);
Assert.AreEqual(ExpectedRandom, result); Assert.AreEqual(ExpectedRandom, result);
} }
@@ -117,14 +112,13 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void Sha512RandomInstance() public void Sha512RandomInstance()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
IChecksum ctx = new Sha512Context(); IChecksum ctx = new Sha512Context();
ctx.Init();
ctx.Update(data); ctx.Update(data);
byte[] result = ctx.Final(); byte[] result = ctx.Final();
Assert.AreEqual(ExpectedRandom, result); Assert.AreEqual(ExpectedRandom, result);

View File

@@ -35,15 +35,15 @@ namespace DiscImageChef.Tests.Checksums
[TestFixture] [TestFixture]
public class SpamSum public class SpamSum
{ {
const string EXPECTED_EMPTY = "3::"; const string EXPECTED_EMPTY = "3::";
const string EXPECTED_RANDOM = "24576:3dvzuAsHTQ16pc7O1Q/gS9qze+Swwn9s6IX:8/TQQpaVqze+JN6IX"; const string EXPECTED_RANDOM = "24576:3dvzuAsHTQ16pc7O1Q/gS9qze+Swwn9s6IX:8/TQQpaVqze+JN6IX";
[Test] [Test]
public void SpamSumEmptyData() public void SpamSumEmptyData()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
@@ -54,14 +54,13 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void SpamSumEmptyInstance() public void SpamSumEmptyInstance()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
IChecksum ctx = new SpamSumContext(); IChecksum ctx = new SpamSumContext();
ctx.Init();
ctx.Update(data); ctx.Update(data);
string result = ctx.End(); string result = ctx.End();
Assert.AreEqual(EXPECTED_EMPTY, result); Assert.AreEqual(EXPECTED_EMPTY, result);
@@ -70,9 +69,9 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void SpamSumRandomData() public void SpamSumRandomData()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
@@ -83,14 +82,13 @@ namespace DiscImageChef.Tests.Checksums
[Test] [Test]
public void SpamSumRandomInstance() public void SpamSumRandomInstance()
{ {
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open, FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open,
FileAccess.Read); FileAccess.Read);
fs.Read(data, 0, 1048576); fs.Read(data, 0, 1048576);
fs.Close(); fs.Close();
fs.Dispose(); fs.Dispose();
IChecksum ctx = new SpamSumContext(); IChecksum ctx = new SpamSumContext();
ctx.Init();
ctx.Update(data); ctx.Update(data);
string result = ctx.End(); string result = ctx.End();
Assert.AreEqual(EXPECTED_RANDOM, result); Assert.AreEqual(EXPECTED_RANDOM, result);

View File

@@ -36,30 +36,28 @@ namespace DiscImageChef.Tests.Filters
[TestFixture] [TestFixture]
public class AppleDoubleDave public class AppleDoubleDave
{ {
const string EXPECTED_FILE = "c2be571406cf6353269faa59a4a8c0a4"; const string EXPECTED_FILE = "c2be571406cf6353269faa59a4a8c0a4";
const string EXPECTED_SIDECAR = "7b0c25bf8cb70f6fb1a15eca31585250"; const string EXPECTED_SIDECAR = "7b0c25bf8cb70f6fb1a15eca31585250";
const string EXPECTED_CONTENTS = "c2be571406cf6353269faa59a4a8c0a4"; const string EXPECTED_CONTENTS = "c2be571406cf6353269faa59a4a8c0a4";
const string EXPECTED_RESOURCE = "a972d27c44193a7587b21416c0953cc3"; const string EXPECTED_RESOURCE = "a972d27c44193a7587b21416c0953cc3";
readonly string location; readonly string location;
readonly string sidecar; readonly string sidecar;
public AppleDoubleDave() public AppleDoubleDave()
{ {
location = Path.Combine(Consts.TestFilesRoot, "filters", "appledouble", "dave", "DOS_720.dmg"); location = Path.Combine(Consts.TestFilesRoot, "filters", "appledouble", "dave", "DOS_720.dmg");
sidecar = Path.Combine(Consts.TestFilesRoot, "filters", "appledouble", "dave", "resource.frk", sidecar = Path.Combine(Consts.TestFilesRoot, "filters", "appledouble", "dave", "resource.frk",
"DOS_720.dmg"); "DOS_720.dmg");
} }
[Test] [Test]
public void CheckCorrectFile() public void CheckCorrectFile()
{ {
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.File(location, out _);
string result = ctx.File(location, out _);
Assert.AreEqual(EXPECTED_FILE, result); Assert.AreEqual(EXPECTED_FILE, result);
ctx = new Md5Context(); ctx = new Md5Context();
ctx.Init();
result = ctx.File(sidecar, out _); result = ctx.File(sidecar, out _);
Assert.AreEqual(EXPECTED_SIDECAR, result); Assert.AreEqual(EXPECTED_SIDECAR, result);
} }
@@ -76,7 +74,7 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new AppleDouble(); IFilter filter = new AppleDouble();
filter.Open(location); filter.Open(location);
Assert.AreEqual(true, filter.IsOpened()); Assert.AreEqual(true, filter.IsOpened());
Assert.AreEqual(737280, filter.GetDataForkLength()); Assert.AreEqual(737280, filter.GetDataForkLength());
Assert.AreNotEqual(null, filter.GetDataForkStream()); Assert.AreNotEqual(null, filter.GetDataForkStream());
Assert.AreEqual(286, filter.GetResourceForkLength()); Assert.AreEqual(286, filter.GetResourceForkLength());
@@ -90,15 +88,14 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new AppleDouble(); IFilter filter = new AppleDouble();
filter.Open(location); filter.Open(location);
Stream str = filter.GetDataForkStream(); Stream str = filter.GetDataForkStream();
byte[] data = new byte[737280]; byte[] data = new byte[737280];
str.Read(data, 0, 737280); str.Read(data, 0, 737280);
str.Close(); str.Close();
str.Dispose(); str.Dispose();
filter.Close(); filter.Close();
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.Data(data, out _);
string result = ctx.Data(data, out _);
Assert.AreEqual(EXPECTED_CONTENTS, result); Assert.AreEqual(EXPECTED_CONTENTS, result);
} }
@@ -107,15 +104,14 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new AppleDouble(); IFilter filter = new AppleDouble();
filter.Open(location); filter.Open(location);
Stream str = filter.GetResourceForkStream(); Stream str = filter.GetResourceForkStream();
byte[] data = new byte[286]; byte[] data = new byte[286];
str.Read(data, 0, 286); str.Read(data, 0, 286);
str.Close(); str.Close();
str.Dispose(); str.Dispose();
filter.Close(); filter.Close();
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.Data(data, out _);
string result = ctx.Data(data, out _);
Assert.AreEqual(EXPECTED_RESOURCE, result); Assert.AreEqual(EXPECTED_RESOURCE, result);
} }
} }

View File

@@ -36,29 +36,27 @@ namespace DiscImageChef.Tests.Filters
[TestFixture] [TestFixture]
public class AppleDoubleDos public class AppleDoubleDos
{ {
const string EXPECTED_FILE = "c2be571406cf6353269faa59a4a8c0a4"; const string EXPECTED_FILE = "c2be571406cf6353269faa59a4a8c0a4";
const string EXPECTED_SIDECAR = "7b0c25bf8cb70f6fb1a15eca31585250"; const string EXPECTED_SIDECAR = "7b0c25bf8cb70f6fb1a15eca31585250";
const string EXPECTED_CONTENTS = "c2be571406cf6353269faa59a4a8c0a4"; const string EXPECTED_CONTENTS = "c2be571406cf6353269faa59a4a8c0a4";
const string EXPECTED_RESOURCE = "a972d27c44193a7587b21416c0953cc3"; const string EXPECTED_RESOURCE = "a972d27c44193a7587b21416c0953cc3";
readonly string location; readonly string location;
readonly string sidecar; readonly string sidecar;
public AppleDoubleDos() public AppleDoubleDos()
{ {
location = Path.Combine(Consts.TestFilesRoot, "filters", "appledouble", "dos", "DOS_720.dmg"); location = Path.Combine(Consts.TestFilesRoot, "filters", "appledouble", "dos", "DOS_720.dmg");
sidecar = Path.Combine(Consts.TestFilesRoot, "filters", "appledouble", "dos", "DOS_720.adf"); sidecar = Path.Combine(Consts.TestFilesRoot, "filters", "appledouble", "dos", "DOS_720.adf");
} }
[Test] [Test]
public void CheckCorrectFile() public void CheckCorrectFile()
{ {
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.File(location, out _);
string result = ctx.File(location, out _);
Assert.AreEqual(EXPECTED_FILE, result); Assert.AreEqual(EXPECTED_FILE, result);
ctx = new Md5Context(); ctx = new Md5Context();
ctx.Init();
result = ctx.File(sidecar, out _); result = ctx.File(sidecar, out _);
Assert.AreEqual(EXPECTED_SIDECAR, result); Assert.AreEqual(EXPECTED_SIDECAR, result);
} }
@@ -75,7 +73,7 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new AppleDouble(); IFilter filter = new AppleDouble();
filter.Open(location); filter.Open(location);
Assert.AreEqual(true, filter.IsOpened()); Assert.AreEqual(true, filter.IsOpened());
Assert.AreEqual(737280, filter.GetDataForkLength()); Assert.AreEqual(737280, filter.GetDataForkLength());
Assert.AreNotEqual(null, filter.GetDataForkStream()); Assert.AreNotEqual(null, filter.GetDataForkStream());
Assert.AreEqual(286, filter.GetResourceForkLength()); Assert.AreEqual(286, filter.GetResourceForkLength());
@@ -89,15 +87,14 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new AppleDouble(); IFilter filter = new AppleDouble();
filter.Open(location); filter.Open(location);
Stream str = filter.GetDataForkStream(); Stream str = filter.GetDataForkStream();
byte[] data = new byte[737280]; byte[] data = new byte[737280];
str.Read(data, 0, 737280); str.Read(data, 0, 737280);
str.Close(); str.Close();
str.Dispose(); str.Dispose();
filter.Close(); filter.Close();
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.Data(data, out _);
string result = ctx.Data(data, out _);
Assert.AreEqual(EXPECTED_CONTENTS, result); Assert.AreEqual(EXPECTED_CONTENTS, result);
} }
@@ -106,15 +103,14 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new AppleDouble(); IFilter filter = new AppleDouble();
filter.Open(location); filter.Open(location);
Stream str = filter.GetResourceForkStream(); Stream str = filter.GetResourceForkStream();
byte[] data = new byte[286]; byte[] data = new byte[286];
str.Read(data, 0, 286); str.Read(data, 0, 286);
str.Close(); str.Close();
str.Dispose(); str.Dispose();
filter.Close(); filter.Close();
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.Data(data, out _);
string result = ctx.Data(data, out _);
Assert.AreEqual(EXPECTED_RESOURCE, result); Assert.AreEqual(EXPECTED_RESOURCE, result);
} }
} }

View File

@@ -36,30 +36,28 @@ namespace DiscImageChef.Tests.Filters
[TestFixture] [TestFixture]
public class AppleDoubleNetatalk public class AppleDoubleNetatalk
{ {
const string EXPECTED_FILE = "c2be571406cf6353269faa59a4a8c0a4"; const string EXPECTED_FILE = "c2be571406cf6353269faa59a4a8c0a4";
const string EXPECTED_SIDECAR = "7b0c25bf8cb70f6fb1a15eca31585250"; const string EXPECTED_SIDECAR = "7b0c25bf8cb70f6fb1a15eca31585250";
const string EXPECTED_CONTENTS = "c2be571406cf6353269faa59a4a8c0a4"; const string EXPECTED_CONTENTS = "c2be571406cf6353269faa59a4a8c0a4";
const string EXPECTED_RESOURCE = "a972d27c44193a7587b21416c0953cc3"; const string EXPECTED_RESOURCE = "a972d27c44193a7587b21416c0953cc3";
readonly string location; readonly string location;
readonly string sidecar; readonly string sidecar;
public AppleDoubleNetatalk() public AppleDoubleNetatalk()
{ {
location = Path.Combine(Consts.TestFilesRoot, "filters", "appledouble", "netatalk", "DOS_720.dmg"); location = Path.Combine(Consts.TestFilesRoot, "filters", "appledouble", "netatalk", "DOS_720.dmg");
sidecar = Path.Combine(Consts.TestFilesRoot, "filters", "appledouble", "netatalk", ".AppleDouble", sidecar = Path.Combine(Consts.TestFilesRoot, "filters", "appledouble", "netatalk", ".AppleDouble",
"DOS_720.dmg"); "DOS_720.dmg");
} }
[Test] [Test]
public void CheckCorrectFile() public void CheckCorrectFile()
{ {
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.File(location, out _);
string result = ctx.File(location, out _);
Assert.AreEqual(EXPECTED_FILE, result); Assert.AreEqual(EXPECTED_FILE, result);
ctx = new Md5Context(); ctx = new Md5Context();
ctx.Init();
result = ctx.File(sidecar, out _); result = ctx.File(sidecar, out _);
Assert.AreEqual(EXPECTED_SIDECAR, result); Assert.AreEqual(EXPECTED_SIDECAR, result);
} }
@@ -76,7 +74,7 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new AppleDouble(); IFilter filter = new AppleDouble();
filter.Open(location); filter.Open(location);
Assert.AreEqual(true, filter.IsOpened()); Assert.AreEqual(true, filter.IsOpened());
Assert.AreEqual(737280, filter.GetDataForkLength()); Assert.AreEqual(737280, filter.GetDataForkLength());
Assert.AreNotEqual(null, filter.GetDataForkStream()); Assert.AreNotEqual(null, filter.GetDataForkStream());
Assert.AreEqual(286, filter.GetResourceForkLength()); Assert.AreEqual(286, filter.GetResourceForkLength());
@@ -90,15 +88,14 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new AppleDouble(); IFilter filter = new AppleDouble();
filter.Open(location); filter.Open(location);
Stream str = filter.GetDataForkStream(); Stream str = filter.GetDataForkStream();
byte[] data = new byte[737280]; byte[] data = new byte[737280];
str.Read(data, 0, 737280); str.Read(data, 0, 737280);
str.Close(); str.Close();
str.Dispose(); str.Dispose();
filter.Close(); filter.Close();
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.Data(data, out _);
string result = ctx.Data(data, out _);
Assert.AreEqual(EXPECTED_CONTENTS, result); Assert.AreEqual(EXPECTED_CONTENTS, result);
} }
@@ -107,15 +104,14 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new AppleDouble(); IFilter filter = new AppleDouble();
filter.Open(location); filter.Open(location);
Stream str = filter.GetResourceForkStream(); Stream str = filter.GetResourceForkStream();
byte[] data = new byte[286]; byte[] data = new byte[286];
str.Read(data, 0, 286); str.Read(data, 0, 286);
str.Close(); str.Close();
str.Dispose(); str.Dispose();
filter.Close(); filter.Close();
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.Data(data, out _);
string result = ctx.Data(data, out _);
Assert.AreEqual(EXPECTED_RESOURCE, result); Assert.AreEqual(EXPECTED_RESOURCE, result);
} }
} }

View File

@@ -36,29 +36,27 @@ namespace DiscImageChef.Tests.Filters
[TestFixture] [TestFixture]
public class AppleDoubleOsX public class AppleDoubleOsX
{ {
const string EXPECTED_FILE = "c2be571406cf6353269faa59a4a8c0a4"; const string EXPECTED_FILE = "c2be571406cf6353269faa59a4a8c0a4";
const string EXPECTED_SIDECAR = "7b0c25bf8cb70f6fb1a15eca31585250"; const string EXPECTED_SIDECAR = "7b0c25bf8cb70f6fb1a15eca31585250";
const string EXPECTED_CONTENTS = "c2be571406cf6353269faa59a4a8c0a4"; const string EXPECTED_CONTENTS = "c2be571406cf6353269faa59a4a8c0a4";
const string EXPECTED_RESOURCE = "a972d27c44193a7587b21416c0953cc3"; const string EXPECTED_RESOURCE = "a972d27c44193a7587b21416c0953cc3";
readonly string location; readonly string location;
readonly string sidecar; readonly string sidecar;
public AppleDoubleOsX() public AppleDoubleOsX()
{ {
location = Path.Combine(Consts.TestFilesRoot, "filters", "appledouble", "osx", "DOS_720.dmg"); location = Path.Combine(Consts.TestFilesRoot, "filters", "appledouble", "osx", "DOS_720.dmg");
sidecar = Path.Combine(Consts.TestFilesRoot, "filters", "appledouble", "osx", "._DOS_720.dmg"); sidecar = Path.Combine(Consts.TestFilesRoot, "filters", "appledouble", "osx", "._DOS_720.dmg");
} }
[Test] [Test]
public void CheckCorrectFile() public void CheckCorrectFile()
{ {
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.File(location, out _);
string result = ctx.File(location, out _);
Assert.AreEqual(EXPECTED_FILE, result); Assert.AreEqual(EXPECTED_FILE, result);
ctx = new Md5Context(); ctx = new Md5Context();
ctx.Init();
result = ctx.File(sidecar, out _); result = ctx.File(sidecar, out _);
Assert.AreEqual(EXPECTED_SIDECAR, result); Assert.AreEqual(EXPECTED_SIDECAR, result);
} }
@@ -75,7 +73,7 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new AppleDouble(); IFilter filter = new AppleDouble();
filter.Open(location); filter.Open(location);
Assert.AreEqual(true, filter.IsOpened()); Assert.AreEqual(true, filter.IsOpened());
Assert.AreEqual(737280, filter.GetDataForkLength()); Assert.AreEqual(737280, filter.GetDataForkLength());
Assert.AreNotEqual(null, filter.GetDataForkStream()); Assert.AreNotEqual(null, filter.GetDataForkStream());
Assert.AreEqual(286, filter.GetResourceForkLength()); Assert.AreEqual(286, filter.GetResourceForkLength());
@@ -89,15 +87,14 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new AppleDouble(); IFilter filter = new AppleDouble();
filter.Open(location); filter.Open(location);
Stream str = filter.GetDataForkStream(); Stream str = filter.GetDataForkStream();
byte[] data = new byte[737280]; byte[] data = new byte[737280];
str.Read(data, 0, 737280); str.Read(data, 0, 737280);
str.Close(); str.Close();
str.Dispose(); str.Dispose();
filter.Close(); filter.Close();
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.Data(data, out _);
string result = ctx.Data(data, out _);
Assert.AreEqual(EXPECTED_CONTENTS, result); Assert.AreEqual(EXPECTED_CONTENTS, result);
} }
@@ -106,15 +103,14 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new AppleDouble(); IFilter filter = new AppleDouble();
filter.Open(location); filter.Open(location);
Stream str = filter.GetResourceForkStream(); Stream str = filter.GetResourceForkStream();
byte[] data = new byte[286]; byte[] data = new byte[286];
str.Read(data, 0, 286); str.Read(data, 0, 286);
str.Close(); str.Close();
str.Dispose(); str.Dispose();
filter.Close(); filter.Close();
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.Data(data, out _);
string result = ctx.Data(data, out _);
Assert.AreEqual(EXPECTED_RESOURCE, result); Assert.AreEqual(EXPECTED_RESOURCE, result);
} }
} }

View File

@@ -36,29 +36,27 @@ namespace DiscImageChef.Tests.Filters
[TestFixture] [TestFixture]
public class AppleDoubleProDos public class AppleDoubleProDos
{ {
const string EXPECTED_FILE = "c2be571406cf6353269faa59a4a8c0a4"; const string EXPECTED_FILE = "c2be571406cf6353269faa59a4a8c0a4";
const string EXPECTED_SIDECAR = "7b0c25bf8cb70f6fb1a15eca31585250"; const string EXPECTED_SIDECAR = "7b0c25bf8cb70f6fb1a15eca31585250";
const string EXPECTED_CONTENTS = "c2be571406cf6353269faa59a4a8c0a4"; const string EXPECTED_CONTENTS = "c2be571406cf6353269faa59a4a8c0a4";
const string EXPECTED_RESOURCE = "a972d27c44193a7587b21416c0953cc3"; const string EXPECTED_RESOURCE = "a972d27c44193a7587b21416c0953cc3";
readonly string location; readonly string location;
readonly string sidecar; readonly string sidecar;
public AppleDoubleProDos() public AppleDoubleProDos()
{ {
location = Path.Combine(Consts.TestFilesRoot, "filters", "appledouble", "prodos", "DOS_720.dmg"); location = Path.Combine(Consts.TestFilesRoot, "filters", "appledouble", "prodos", "DOS_720.dmg");
sidecar = Path.Combine(Consts.TestFilesRoot, "filters", "appledouble", "prodos", "R.DOS_720.dmg"); sidecar = Path.Combine(Consts.TestFilesRoot, "filters", "appledouble", "prodos", "R.DOS_720.dmg");
} }
[Test] [Test]
public void CheckCorrectFile() public void CheckCorrectFile()
{ {
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.File(location, out _);
string result = ctx.File(location, out _);
Assert.AreEqual(EXPECTED_FILE, result); Assert.AreEqual(EXPECTED_FILE, result);
ctx = new Md5Context(); ctx = new Md5Context();
ctx.Init();
result = ctx.File(sidecar, out _); result = ctx.File(sidecar, out _);
Assert.AreEqual(EXPECTED_SIDECAR, result); Assert.AreEqual(EXPECTED_SIDECAR, result);
} }
@@ -75,7 +73,7 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new AppleDouble(); IFilter filter = new AppleDouble();
filter.Open(location); filter.Open(location);
Assert.AreEqual(true, filter.IsOpened()); Assert.AreEqual(true, filter.IsOpened());
Assert.AreEqual(737280, filter.GetDataForkLength()); Assert.AreEqual(737280, filter.GetDataForkLength());
Assert.AreNotEqual(null, filter.GetDataForkStream()); Assert.AreNotEqual(null, filter.GetDataForkStream());
Assert.AreEqual(286, filter.GetResourceForkLength()); Assert.AreEqual(286, filter.GetResourceForkLength());
@@ -89,15 +87,14 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new AppleDouble(); IFilter filter = new AppleDouble();
filter.Open(location); filter.Open(location);
Stream str = filter.GetDataForkStream(); Stream str = filter.GetDataForkStream();
byte[] data = new byte[737280]; byte[] data = new byte[737280];
str.Read(data, 0, 737280); str.Read(data, 0, 737280);
str.Close(); str.Close();
str.Dispose(); str.Dispose();
filter.Close(); filter.Close();
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.Data(data, out _);
string result = ctx.Data(data, out _);
Assert.AreEqual(EXPECTED_CONTENTS, result); Assert.AreEqual(EXPECTED_CONTENTS, result);
} }
@@ -106,15 +103,14 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new AppleDouble(); IFilter filter = new AppleDouble();
filter.Open(location); filter.Open(location);
Stream str = filter.GetResourceForkStream(); Stream str = filter.GetResourceForkStream();
byte[] data = new byte[286]; byte[] data = new byte[286];
str.Read(data, 0, 286); str.Read(data, 0, 286);
str.Close(); str.Close();
str.Dispose(); str.Dispose();
filter.Close(); filter.Close();
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.Data(data, out _);
string result = ctx.Data(data, out _);
Assert.AreEqual(EXPECTED_RESOURCE, result); Assert.AreEqual(EXPECTED_RESOURCE, result);
} }
} }

View File

@@ -36,29 +36,27 @@ namespace DiscImageChef.Tests.Filters
[TestFixture] [TestFixture]
public class AppleDoubleUnAr public class AppleDoubleUnAr
{ {
const string EXPECTED_FILE = "c2be571406cf6353269faa59a4a8c0a4"; const string EXPECTED_FILE = "c2be571406cf6353269faa59a4a8c0a4";
const string EXPECTED_SIDECAR = "7b0c25bf8cb70f6fb1a15eca31585250"; const string EXPECTED_SIDECAR = "7b0c25bf8cb70f6fb1a15eca31585250";
const string EXPECTED_CONTENTS = "c2be571406cf6353269faa59a4a8c0a4"; const string EXPECTED_CONTENTS = "c2be571406cf6353269faa59a4a8c0a4";
const string EXPECTED_RESOURCE = "a972d27c44193a7587b21416c0953cc3"; const string EXPECTED_RESOURCE = "a972d27c44193a7587b21416c0953cc3";
readonly string location; readonly string location;
readonly string sidecar; readonly string sidecar;
public AppleDoubleUnAr() public AppleDoubleUnAr()
{ {
location = Path.Combine(Consts.TestFilesRoot, "filters", "appledouble", "unar", "DOS_720.dmg"); location = Path.Combine(Consts.TestFilesRoot, "filters", "appledouble", "unar", "DOS_720.dmg");
sidecar = Path.Combine(Consts.TestFilesRoot, "filters", "appledouble", "unar", "DOS_720.dmg.rsrc"); sidecar = Path.Combine(Consts.TestFilesRoot, "filters", "appledouble", "unar", "DOS_720.dmg.rsrc");
} }
[Test] [Test]
public void CheckCorrectFile() public void CheckCorrectFile()
{ {
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.File(location, out _);
string result = ctx.File(location, out _);
Assert.AreEqual(EXPECTED_FILE, result); Assert.AreEqual(EXPECTED_FILE, result);
ctx = new Md5Context(); ctx = new Md5Context();
ctx.Init();
result = ctx.File(sidecar, out _); result = ctx.File(sidecar, out _);
Assert.AreEqual(EXPECTED_SIDECAR, result); Assert.AreEqual(EXPECTED_SIDECAR, result);
} }
@@ -75,7 +73,7 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new AppleDouble(); IFilter filter = new AppleDouble();
filter.Open(location); filter.Open(location);
Assert.AreEqual(true, filter.IsOpened()); Assert.AreEqual(true, filter.IsOpened());
Assert.AreEqual(737280, filter.GetDataForkLength()); Assert.AreEqual(737280, filter.GetDataForkLength());
Assert.AreNotEqual(null, filter.GetDataForkStream()); Assert.AreNotEqual(null, filter.GetDataForkStream());
Assert.AreEqual(286, filter.GetResourceForkLength()); Assert.AreEqual(286, filter.GetResourceForkLength());
@@ -89,15 +87,14 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new AppleDouble(); IFilter filter = new AppleDouble();
filter.Open(location); filter.Open(location);
Stream str = filter.GetDataForkStream(); Stream str = filter.GetDataForkStream();
byte[] data = new byte[737280]; byte[] data = new byte[737280];
str.Read(data, 0, 737280); str.Read(data, 0, 737280);
str.Close(); str.Close();
str.Dispose(); str.Dispose();
filter.Close(); filter.Close();
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.Data(data, out _);
string result = ctx.Data(data, out _);
Assert.AreEqual(EXPECTED_CONTENTS, result); Assert.AreEqual(EXPECTED_CONTENTS, result);
} }
@@ -106,15 +103,14 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new AppleDouble(); IFilter filter = new AppleDouble();
filter.Open(location); filter.Open(location);
Stream str = filter.GetResourceForkStream(); Stream str = filter.GetResourceForkStream();
byte[] data = new byte[286]; byte[] data = new byte[286];
str.Read(data, 0, 286); str.Read(data, 0, 286);
str.Close(); str.Close();
str.Dispose(); str.Dispose();
filter.Close(); filter.Close();
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.Data(data, out _);
string result = ctx.Data(data, out _);
Assert.AreEqual(EXPECTED_RESOURCE, result); Assert.AreEqual(EXPECTED_RESOURCE, result);
} }
} }

View File

@@ -36,29 +36,27 @@ namespace DiscImageChef.Tests.Filters
[TestFixture] [TestFixture]
public class AppleDoubleUnix public class AppleDoubleUnix
{ {
const string EXPECTED_FILE = "c2be571406cf6353269faa59a4a8c0a4"; const string EXPECTED_FILE = "c2be571406cf6353269faa59a4a8c0a4";
const string EXPECTED_SIDECAR = "7b0c25bf8cb70f6fb1a15eca31585250"; const string EXPECTED_SIDECAR = "7b0c25bf8cb70f6fb1a15eca31585250";
const string EXPECTED_CONTENTS = "c2be571406cf6353269faa59a4a8c0a4"; const string EXPECTED_CONTENTS = "c2be571406cf6353269faa59a4a8c0a4";
const string EXPECTED_RESOURCE = "a972d27c44193a7587b21416c0953cc3"; const string EXPECTED_RESOURCE = "a972d27c44193a7587b21416c0953cc3";
readonly string location; readonly string location;
readonly string sidecar; readonly string sidecar;
public AppleDoubleUnix() public AppleDoubleUnix()
{ {
location = Path.Combine(Consts.TestFilesRoot, "filters", "appledouble", "unix", "DOS_720.dmg"); location = Path.Combine(Consts.TestFilesRoot, "filters", "appledouble", "unix", "DOS_720.dmg");
sidecar = Path.Combine(Consts.TestFilesRoot, "filters", "appledouble", "unix", "%DOS_720.dmg"); sidecar = Path.Combine(Consts.TestFilesRoot, "filters", "appledouble", "unix", "%DOS_720.dmg");
} }
[Test] [Test]
public void CheckCorrectFile() public void CheckCorrectFile()
{ {
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.File(location, out _);
string result = ctx.File(location, out _);
Assert.AreEqual(EXPECTED_FILE, result); Assert.AreEqual(EXPECTED_FILE, result);
ctx = new Md5Context(); ctx = new Md5Context();
ctx.Init();
result = ctx.File(sidecar, out _); result = ctx.File(sidecar, out _);
Assert.AreEqual(EXPECTED_SIDECAR, result); Assert.AreEqual(EXPECTED_SIDECAR, result);
} }
@@ -75,7 +73,7 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new AppleDouble(); IFilter filter = new AppleDouble();
filter.Open(location); filter.Open(location);
Assert.AreEqual(true, filter.IsOpened()); Assert.AreEqual(true, filter.IsOpened());
Assert.AreEqual(737280, filter.GetDataForkLength()); Assert.AreEqual(737280, filter.GetDataForkLength());
Assert.AreNotEqual(null, filter.GetDataForkStream()); Assert.AreNotEqual(null, filter.GetDataForkStream());
Assert.AreEqual(286, filter.GetResourceForkLength()); Assert.AreEqual(286, filter.GetResourceForkLength());
@@ -89,15 +87,14 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new AppleDouble(); IFilter filter = new AppleDouble();
filter.Open(location); filter.Open(location);
Stream str = filter.GetDataForkStream(); Stream str = filter.GetDataForkStream();
byte[] data = new byte[737280]; byte[] data = new byte[737280];
str.Read(data, 0, 737280); str.Read(data, 0, 737280);
str.Close(); str.Close();
str.Dispose(); str.Dispose();
filter.Close(); filter.Close();
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.Data(data, out _);
string result = ctx.Data(data, out _);
Assert.AreEqual(EXPECTED_CONTENTS, result); Assert.AreEqual(EXPECTED_CONTENTS, result);
} }
@@ -106,15 +103,14 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new AppleDouble(); IFilter filter = new AppleDouble();
filter.Open(location); filter.Open(location);
Stream str = filter.GetResourceForkStream(); Stream str = filter.GetResourceForkStream();
byte[] data = new byte[286]; byte[] data = new byte[286];
str.Read(data, 0, 286); str.Read(data, 0, 286);
str.Close(); str.Close();
str.Dispose(); str.Dispose();
filter.Close(); filter.Close();
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.Data(data, out _);
string result = ctx.Data(data, out _);
Assert.AreEqual(EXPECTED_RESOURCE, result); Assert.AreEqual(EXPECTED_RESOURCE, result);
} }
} }

View File

@@ -36,9 +36,9 @@ namespace DiscImageChef.Tests.Filters
[TestFixture] [TestFixture]
public class AppleSingle public class AppleSingle
{ {
const string EXPECTED_FILE = "7497a3b156dcd0c1046a1ab12e188ab7"; const string EXPECTED_FILE = "7497a3b156dcd0c1046a1ab12e188ab7";
const string EXPECTED_CONTENTS = "c2be571406cf6353269faa59a4a8c0a4"; const string EXPECTED_CONTENTS = "c2be571406cf6353269faa59a4a8c0a4";
const string EXPECTED_RESOURCE = "a972d27c44193a7587b21416c0953cc3"; const string EXPECTED_RESOURCE = "a972d27c44193a7587b21416c0953cc3";
readonly string location; readonly string location;
public AppleSingle() public AppleSingle()
@@ -49,9 +49,8 @@ namespace DiscImageChef.Tests.Filters
[Test] [Test]
public void CheckCorrectFile() public void CheckCorrectFile()
{ {
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.File(location, out _);
string result = ctx.File(location, out _);
Assert.AreEqual(EXPECTED_FILE, result); Assert.AreEqual(EXPECTED_FILE, result);
} }
@@ -67,7 +66,7 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new DiscImageChef.Filters.AppleSingle(); IFilter filter = new DiscImageChef.Filters.AppleSingle();
filter.Open(location); filter.Open(location);
Assert.AreEqual(true, filter.IsOpened()); Assert.AreEqual(true, filter.IsOpened());
Assert.AreEqual(737280, filter.GetDataForkLength()); Assert.AreEqual(737280, filter.GetDataForkLength());
Assert.AreNotEqual(null, filter.GetDataForkStream()); Assert.AreNotEqual(null, filter.GetDataForkStream());
Assert.AreEqual(286, filter.GetResourceForkLength()); Assert.AreEqual(286, filter.GetResourceForkLength());
@@ -81,15 +80,14 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new DiscImageChef.Filters.AppleSingle(); IFilter filter = new DiscImageChef.Filters.AppleSingle();
filter.Open(location); filter.Open(location);
Stream str = filter.GetDataForkStream(); Stream str = filter.GetDataForkStream();
byte[] data = new byte[737280]; byte[] data = new byte[737280];
str.Read(data, 0, 737280); str.Read(data, 0, 737280);
str.Close(); str.Close();
str.Dispose(); str.Dispose();
filter.Close(); filter.Close();
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.Data(data, out _);
string result = ctx.Data(data, out _);
Assert.AreEqual(EXPECTED_CONTENTS, result); Assert.AreEqual(EXPECTED_CONTENTS, result);
} }
@@ -98,15 +96,14 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new DiscImageChef.Filters.AppleSingle(); IFilter filter = new DiscImageChef.Filters.AppleSingle();
filter.Open(location); filter.Open(location);
Stream str = filter.GetResourceForkStream(); Stream str = filter.GetResourceForkStream();
byte[] data = new byte[286]; byte[] data = new byte[286];
str.Read(data, 0, 286); str.Read(data, 0, 286);
str.Close(); str.Close();
str.Dispose(); str.Dispose();
filter.Close(); filter.Close();
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.Data(data, out _);
string result = ctx.Data(data, out _);
Assert.AreEqual(EXPECTED_RESOURCE, result); Assert.AreEqual(EXPECTED_RESOURCE, result);
} }
} }

View File

@@ -50,9 +50,8 @@ namespace DiscImageChef.Tests.Filters
[Test] [Test]
public void CheckCorrectFile() public void CheckCorrectFile()
{ {
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); byte[] result = ctx.File(location);
byte[] result = ctx.File(location);
Assert.AreEqual(ExpectedFile, result); Assert.AreEqual(ExpectedFile, result);
} }
@@ -68,11 +67,11 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new DiscImageChef.Filters.BZip2(); IFilter filter = new DiscImageChef.Filters.BZip2();
filter.Open(location); filter.Open(location);
Assert.AreEqual(true, filter.IsOpened()); Assert.AreEqual(true, filter.IsOpened());
Assert.AreEqual(1048576, filter.GetDataForkLength()); Assert.AreEqual(1048576, filter.GetDataForkLength());
Assert.AreNotEqual(null, filter.GetDataForkStream()); Assert.AreNotEqual(null, filter.GetDataForkStream());
Assert.AreEqual(0, filter.GetResourceForkLength()); Assert.AreEqual(0, filter.GetResourceForkLength());
Assert.AreEqual(null, filter.GetResourceForkStream()); Assert.AreEqual(null, filter.GetResourceForkStream());
Assert.AreEqual(false, filter.HasResourceFork()); Assert.AreEqual(false, filter.HasResourceFork());
filter.Close(); filter.Close();
} }
@@ -82,14 +81,13 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new DiscImageChef.Filters.BZip2(); IFilter filter = new DiscImageChef.Filters.BZip2();
filter.Open(location); filter.Open(location);
Stream str = filter.GetDataForkStream(); Stream str = filter.GetDataForkStream();
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
str.Read(data, 0, 1048576); str.Read(data, 0, 1048576);
str.Close(); str.Close();
str.Dispose(); str.Dispose();
filter.Close(); filter.Close();
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init();
ctx.Data(data, out byte[] result); ctx.Data(data, out byte[] result);
Assert.AreEqual(ExpectedContents, result); Assert.AreEqual(ExpectedContents, result);
} }

View File

@@ -50,9 +50,8 @@ namespace DiscImageChef.Tests.Filters
[Test] [Test]
public void CheckCorrectFile() public void CheckCorrectFile()
{ {
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); byte[] result = ctx.File(location);
byte[] result = ctx.File(location);
Assert.AreEqual(ExpectedFile, result); Assert.AreEqual(ExpectedFile, result);
} }
@@ -68,11 +67,11 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new DiscImageChef.Filters.GZip(); IFilter filter = new DiscImageChef.Filters.GZip();
filter.Open(location); filter.Open(location);
Assert.AreEqual(true, filter.IsOpened()); Assert.AreEqual(true, filter.IsOpened());
Assert.AreEqual(1048576, filter.GetDataForkLength()); Assert.AreEqual(1048576, filter.GetDataForkLength());
Assert.AreNotEqual(null, filter.GetDataForkStream()); Assert.AreNotEqual(null, filter.GetDataForkStream());
Assert.AreEqual(0, filter.GetResourceForkLength()); Assert.AreEqual(0, filter.GetResourceForkLength());
Assert.AreEqual(null, filter.GetResourceForkStream()); Assert.AreEqual(null, filter.GetResourceForkStream());
Assert.AreEqual(false, filter.HasResourceFork()); Assert.AreEqual(false, filter.HasResourceFork());
filter.Close(); filter.Close();
} }
@@ -82,14 +81,13 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new DiscImageChef.Filters.GZip(); IFilter filter = new DiscImageChef.Filters.GZip();
filter.Open(location); filter.Open(location);
Stream str = filter.GetDataForkStream(); Stream str = filter.GetDataForkStream();
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
str.Read(data, 0, 1048576); str.Read(data, 0, 1048576);
str.Close(); str.Close();
str.Dispose(); str.Dispose();
filter.Close(); filter.Close();
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init();
ctx.Data(data, out byte[] result); ctx.Data(data, out byte[] result);
Assert.AreEqual(ExpectedContents, result); Assert.AreEqual(ExpectedContents, result);
} }

View File

@@ -50,9 +50,8 @@ namespace DiscImageChef.Tests.Filters
[Test] [Test]
public void CheckCorrectFile() public void CheckCorrectFile()
{ {
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); byte[] result = ctx.File(location);
byte[] result = ctx.File(location);
Assert.AreEqual(ExpectedFile, result); Assert.AreEqual(ExpectedFile, result);
} }
@@ -68,11 +67,11 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new DiscImageChef.Filters.LZip(); IFilter filter = new DiscImageChef.Filters.LZip();
filter.Open(location); filter.Open(location);
Assert.AreEqual(true, filter.IsOpened()); Assert.AreEqual(true, filter.IsOpened());
Assert.AreEqual(1048576, filter.GetDataForkLength()); Assert.AreEqual(1048576, filter.GetDataForkLength());
Assert.AreNotEqual(null, filter.GetDataForkStream()); Assert.AreNotEqual(null, filter.GetDataForkStream());
Assert.AreEqual(0, filter.GetResourceForkLength()); Assert.AreEqual(0, filter.GetResourceForkLength());
Assert.AreEqual(null, filter.GetResourceForkStream()); Assert.AreEqual(null, filter.GetResourceForkStream());
Assert.AreEqual(false, filter.HasResourceFork()); Assert.AreEqual(false, filter.HasResourceFork());
filter.Close(); filter.Close();
} }
@@ -82,14 +81,13 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new DiscImageChef.Filters.LZip(); IFilter filter = new DiscImageChef.Filters.LZip();
filter.Open(location); filter.Open(location);
Stream str = filter.GetDataForkStream(); Stream str = filter.GetDataForkStream();
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
str.Read(data, 0, 1048576); str.Read(data, 0, 1048576);
str.Close(); str.Close();
str.Dispose(); str.Dispose();
filter.Close(); filter.Close();
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init();
ctx.Data(data, out byte[] result); ctx.Data(data, out byte[] result);
Assert.AreEqual(ExpectedContents, result); Assert.AreEqual(ExpectedContents, result);
} }

View File

@@ -36,9 +36,9 @@ namespace DiscImageChef.Tests.Filters
[TestFixture] [TestFixture]
public class MacBinary1 public class MacBinary1
{ {
const string EXPECTED_FILE = "596c38555bc7ba284648d1ce57700884"; const string EXPECTED_FILE = "596c38555bc7ba284648d1ce57700884";
const string EXPECTED_CONTENTS = "c2be571406cf6353269faa59a4a8c0a4"; const string EXPECTED_CONTENTS = "c2be571406cf6353269faa59a4a8c0a4";
const string EXPECTED_RESOURCE = "a972d27c44193a7587b21416c0953cc3"; const string EXPECTED_RESOURCE = "a972d27c44193a7587b21416c0953cc3";
readonly string location; readonly string location;
public MacBinary1() public MacBinary1()
@@ -49,9 +49,8 @@ namespace DiscImageChef.Tests.Filters
[Test] [Test]
public void CheckCorrectFile() public void CheckCorrectFile()
{ {
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.File(location, out _);
string result = ctx.File(location, out _);
Assert.AreEqual(EXPECTED_FILE, result); Assert.AreEqual(EXPECTED_FILE, result);
} }
@@ -67,7 +66,7 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new DiscImageChef.Filters.AppleSingle(); IFilter filter = new DiscImageChef.Filters.AppleSingle();
filter.Open(location); filter.Open(location);
Assert.AreEqual(true, filter.IsOpened()); Assert.AreEqual(true, filter.IsOpened());
Assert.AreEqual(737280, filter.GetDataForkLength()); Assert.AreEqual(737280, filter.GetDataForkLength());
Assert.AreNotEqual(null, filter.GetDataForkStream()); Assert.AreNotEqual(null, filter.GetDataForkStream());
Assert.AreEqual(286, filter.GetResourceForkLength()); Assert.AreEqual(286, filter.GetResourceForkLength());
@@ -81,15 +80,14 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new DiscImageChef.Filters.AppleSingle(); IFilter filter = new DiscImageChef.Filters.AppleSingle();
filter.Open(location); filter.Open(location);
Stream str = filter.GetDataForkStream(); Stream str = filter.GetDataForkStream();
byte[] data = new byte[737280]; byte[] data = new byte[737280];
str.Read(data, 0, 737280); str.Read(data, 0, 737280);
str.Close(); str.Close();
str.Dispose(); str.Dispose();
filter.Close(); filter.Close();
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.Data(data, out _);
string result = ctx.Data(data, out _);
Assert.AreEqual(EXPECTED_CONTENTS, result); Assert.AreEqual(EXPECTED_CONTENTS, result);
} }
@@ -98,15 +96,14 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new DiscImageChef.Filters.AppleSingle(); IFilter filter = new DiscImageChef.Filters.AppleSingle();
filter.Open(location); filter.Open(location);
Stream str = filter.GetResourceForkStream(); Stream str = filter.GetResourceForkStream();
byte[] data = new byte[286]; byte[] data = new byte[286];
str.Read(data, 0, 286); str.Read(data, 0, 286);
str.Close(); str.Close();
str.Dispose(); str.Dispose();
filter.Close(); filter.Close();
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.Data(data, out _);
string result = ctx.Data(data, out _);
Assert.AreEqual(EXPECTED_RESOURCE, result); Assert.AreEqual(EXPECTED_RESOURCE, result);
} }
} }

View File

@@ -36,9 +36,9 @@ namespace DiscImageChef.Tests.Filters
[TestFixture] [TestFixture]
public class MacBinary2 public class MacBinary2
{ {
const string EXPECTED_FILE = "a8daa55a65432353e95dc4c61d42660f"; const string EXPECTED_FILE = "a8daa55a65432353e95dc4c61d42660f";
const string EXPECTED_CONTENTS = "c2be571406cf6353269faa59a4a8c0a4"; const string EXPECTED_CONTENTS = "c2be571406cf6353269faa59a4a8c0a4";
const string EXPECTED_RESOURCE = "a972d27c44193a7587b21416c0953cc3"; const string EXPECTED_RESOURCE = "a972d27c44193a7587b21416c0953cc3";
readonly string location; readonly string location;
public MacBinary2() public MacBinary2()
@@ -49,9 +49,8 @@ namespace DiscImageChef.Tests.Filters
[Test] [Test]
public void CheckCorrectFile() public void CheckCorrectFile()
{ {
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.File(location, out _);
string result = ctx.File(location, out _);
Assert.AreEqual(EXPECTED_FILE, result); Assert.AreEqual(EXPECTED_FILE, result);
} }
@@ -67,7 +66,7 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new MacBinary(); IFilter filter = new MacBinary();
filter.Open(location); filter.Open(location);
Assert.AreEqual(true, filter.IsOpened()); Assert.AreEqual(true, filter.IsOpened());
Assert.AreEqual(737280, filter.GetDataForkLength()); Assert.AreEqual(737280, filter.GetDataForkLength());
Assert.AreNotEqual(null, filter.GetDataForkStream()); Assert.AreNotEqual(null, filter.GetDataForkStream());
Assert.AreEqual(286, filter.GetResourceForkLength()); Assert.AreEqual(286, filter.GetResourceForkLength());
@@ -81,15 +80,14 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new MacBinary(); IFilter filter = new MacBinary();
filter.Open(location); filter.Open(location);
Stream str = filter.GetDataForkStream(); Stream str = filter.GetDataForkStream();
byte[] data = new byte[737280]; byte[] data = new byte[737280];
str.Read(data, 0, 737280); str.Read(data, 0, 737280);
str.Close(); str.Close();
str.Dispose(); str.Dispose();
filter.Close(); filter.Close();
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.Data(data, out _);
string result = ctx.Data(data, out _);
Assert.AreEqual(EXPECTED_CONTENTS, result); Assert.AreEqual(EXPECTED_CONTENTS, result);
} }
@@ -98,15 +96,14 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new MacBinary(); IFilter filter = new MacBinary();
filter.Open(location); filter.Open(location);
Stream str = filter.GetResourceForkStream(); Stream str = filter.GetResourceForkStream();
byte[] data = new byte[286]; byte[] data = new byte[286];
str.Read(data, 0, 286); str.Read(data, 0, 286);
str.Close(); str.Close();
str.Dispose(); str.Dispose();
filter.Close(); filter.Close();
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.Data(data, out _);
string result = ctx.Data(data, out _);
Assert.AreEqual(EXPECTED_RESOURCE, result); Assert.AreEqual(EXPECTED_RESOURCE, result);
} }
} }

View File

@@ -36,9 +36,9 @@ namespace DiscImageChef.Tests.Filters
[TestFixture] [TestFixture]
public class MacBinary3 public class MacBinary3
{ {
const string EXPECTED_FILE = "3a7363a6109fb52a264b0b45dfa16694"; const string EXPECTED_FILE = "3a7363a6109fb52a264b0b45dfa16694";
const string EXPECTED_CONTENTS = "c2be571406cf6353269faa59a4a8c0a4"; const string EXPECTED_CONTENTS = "c2be571406cf6353269faa59a4a8c0a4";
const string EXPECTED_RESOURCE = "a972d27c44193a7587b21416c0953cc3"; const string EXPECTED_RESOURCE = "a972d27c44193a7587b21416c0953cc3";
readonly string location; readonly string location;
public MacBinary3() public MacBinary3()
@@ -49,9 +49,8 @@ namespace DiscImageChef.Tests.Filters
[Test] [Test]
public void CheckCorrectFile() public void CheckCorrectFile()
{ {
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.File(location, out _);
string result = ctx.File(location, out _);
Assert.AreEqual(EXPECTED_FILE, result); Assert.AreEqual(EXPECTED_FILE, result);
} }
@@ -67,7 +66,7 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new MacBinary(); IFilter filter = new MacBinary();
filter.Open(location); filter.Open(location);
Assert.AreEqual(true, filter.IsOpened()); Assert.AreEqual(true, filter.IsOpened());
Assert.AreEqual(737280, filter.GetDataForkLength()); Assert.AreEqual(737280, filter.GetDataForkLength());
Assert.AreNotEqual(null, filter.GetDataForkStream()); Assert.AreNotEqual(null, filter.GetDataForkStream());
Assert.AreEqual(286, filter.GetResourceForkLength()); Assert.AreEqual(286, filter.GetResourceForkLength());
@@ -81,15 +80,14 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new MacBinary(); IFilter filter = new MacBinary();
filter.Open(location); filter.Open(location);
Stream str = filter.GetDataForkStream(); Stream str = filter.GetDataForkStream();
byte[] data = new byte[737280]; byte[] data = new byte[737280];
str.Read(data, 0, 737280); str.Read(data, 0, 737280);
str.Close(); str.Close();
str.Dispose(); str.Dispose();
filter.Close(); filter.Close();
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.Data(data, out _);
string result = ctx.Data(data, out _);
Assert.AreEqual(EXPECTED_CONTENTS, result); Assert.AreEqual(EXPECTED_CONTENTS, result);
} }
@@ -98,15 +96,14 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new MacBinary(); IFilter filter = new MacBinary();
filter.Open(location); filter.Open(location);
Stream str = filter.GetResourceForkStream(); Stream str = filter.GetResourceForkStream();
byte[] data = new byte[286]; byte[] data = new byte[286];
str.Read(data, 0, 286); str.Read(data, 0, 286);
str.Close(); str.Close();
str.Dispose(); str.Dispose();
filter.Close(); filter.Close();
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.Data(data, out _);
string result = ctx.Data(data, out _);
Assert.AreEqual(EXPECTED_RESOURCE, result); Assert.AreEqual(EXPECTED_RESOURCE, result);
} }
} }

View File

@@ -36,9 +36,9 @@ namespace DiscImageChef.Tests.Filters
[TestFixture] [TestFixture]
public class PcExchange public class PcExchange
{ {
const string EXPECTED_FILE = "348825a08fa84766d20b91ed917012b9"; const string EXPECTED_FILE = "348825a08fa84766d20b91ed917012b9";
const string EXPECTED_CONTENTS = "c2be571406cf6353269faa59a4a8c0a4"; const string EXPECTED_CONTENTS = "c2be571406cf6353269faa59a4a8c0a4";
const string EXPECTED_RESOURCE = "5cb168d60ce8b2b1b3133c2faaf47165"; const string EXPECTED_RESOURCE = "5cb168d60ce8b2b1b3133c2faaf47165";
readonly string location; readonly string location;
public PcExchange() public PcExchange()
@@ -49,9 +49,9 @@ namespace DiscImageChef.Tests.Filters
[Test] [Test]
public void CheckCorrectFile() public void CheckCorrectFile()
{ {
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.File(Path.Combine(Consts.TestFilesRoot, "filters", "pcexchange", "FINDER.DAT"),
string result = ctx.File(Path.Combine(Consts.TestFilesRoot, "filters", "pcexchange", "FINDER.DAT"), out _); out _);
Assert.AreEqual(EXPECTED_FILE, result); Assert.AreEqual(EXPECTED_FILE, result);
} }
@@ -67,7 +67,7 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new PCExchange(); IFilter filter = new PCExchange();
filter.Open(location); filter.Open(location);
Assert.AreEqual(true, filter.IsOpened()); Assert.AreEqual(true, filter.IsOpened());
Assert.AreEqual(737280, filter.GetDataForkLength()); Assert.AreEqual(737280, filter.GetDataForkLength());
Assert.AreNotEqual(null, filter.GetDataForkStream()); Assert.AreNotEqual(null, filter.GetDataForkStream());
Assert.AreEqual(546, filter.GetResourceForkLength()); Assert.AreEqual(546, filter.GetResourceForkLength());
@@ -81,15 +81,14 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new PCExchange(); IFilter filter = new PCExchange();
filter.Open(location); filter.Open(location);
Stream str = filter.GetDataForkStream(); Stream str = filter.GetDataForkStream();
byte[] data = new byte[737280]; byte[] data = new byte[737280];
str.Read(data, 0, 737280); str.Read(data, 0, 737280);
str.Close(); str.Close();
str.Dispose(); str.Dispose();
filter.Close(); filter.Close();
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.Data(data, out _);
string result = ctx.Data(data, out _);
Assert.AreEqual(EXPECTED_CONTENTS, result); Assert.AreEqual(EXPECTED_CONTENTS, result);
} }
@@ -98,15 +97,14 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new PCExchange(); IFilter filter = new PCExchange();
filter.Open(location); filter.Open(location);
Stream str = filter.GetResourceForkStream(); Stream str = filter.GetResourceForkStream();
byte[] data = new byte[546]; byte[] data = new byte[546];
str.Read(data, 0, 546); str.Read(data, 0, 546);
str.Close(); str.Close();
str.Dispose(); str.Dispose();
filter.Close(); filter.Close();
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); string result = ctx.Data(data, out _);
string result = ctx.Data(data, out _);
Assert.AreEqual(EXPECTED_RESOURCE, result); Assert.AreEqual(EXPECTED_RESOURCE, result);
} }
} }

View File

@@ -50,9 +50,8 @@ namespace DiscImageChef.Tests.Filters
[Test] [Test]
public void CheckCorrectFile() public void CheckCorrectFile()
{ {
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init(); byte[] result = ctx.File(location);
byte[] result = ctx.File(location);
Assert.AreEqual(ExpectedFile, result); Assert.AreEqual(ExpectedFile, result);
} }
@@ -68,11 +67,11 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new XZ(); IFilter filter = new XZ();
filter.Open(location); filter.Open(location);
Assert.AreEqual(true, filter.IsOpened()); Assert.AreEqual(true, filter.IsOpened());
Assert.AreEqual(1048576, filter.GetDataForkLength()); Assert.AreEqual(1048576, filter.GetDataForkLength());
Assert.AreNotEqual(null, filter.GetDataForkStream()); Assert.AreNotEqual(null, filter.GetDataForkStream());
Assert.AreEqual(0, filter.GetResourceForkLength()); Assert.AreEqual(0, filter.GetResourceForkLength());
Assert.AreEqual(null, filter.GetResourceForkStream()); Assert.AreEqual(null, filter.GetResourceForkStream());
Assert.AreEqual(false, filter.HasResourceFork()); Assert.AreEqual(false, filter.HasResourceFork());
filter.Close(); filter.Close();
} }
@@ -82,14 +81,13 @@ namespace DiscImageChef.Tests.Filters
{ {
IFilter filter = new XZ(); IFilter filter = new XZ();
filter.Open(location); filter.Open(location);
Stream str = filter.GetDataForkStream(); Stream str = filter.GetDataForkStream();
byte[] data = new byte[1048576]; byte[] data = new byte[1048576];
str.Read(data, 0, 1048576); str.Read(data, 0, 1048576);
str.Close(); str.Close();
str.Dispose(); str.Dispose();
filter.Close(); filter.Close();
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init();
ctx.Data(data, out byte[] result); ctx.Data(data, out byte[] result);
Assert.AreEqual(ExpectedContents, result); Assert.AreEqual(ExpectedContents, result);
} }

View File

@@ -65,21 +65,20 @@ namespace DiscImageChef.Tests.Images
{ {
for(int i = 0; i < testfiles.Length; i++) for(int i = 0; i < testfiles.Length; i++)
{ {
string location = Path.Combine(Consts.TestFilesRoot, "images", "2mg", testfiles[i]); string location = Path.Combine(Consts.TestFilesRoot, "images", "2mg", testfiles[i]);
IFilter filter = new LZip(); IFilter filter = new LZip();
filter.Open(location); filter.Open(location);
IMediaImage image = new DiscImages.Apple2Mg(); IMediaImage image = new DiscImages.Apple2Mg();
Assert.AreEqual(true, image.Open(filter), testfiles[i]); Assert.AreEqual(true, image.Open(filter), testfiles[i]);
Assert.AreEqual(sectors[i], image.Info.Sectors, testfiles[i]); Assert.AreEqual(sectors[i], image.Info.Sectors, testfiles[i]);
Assert.AreEqual(sectorsize[i], image.Info.SectorSize, testfiles[i]); Assert.AreEqual(sectorsize[i], image.Info.SectorSize, testfiles[i]);
Assert.AreEqual(mediatypes[i], image.Info.MediaType, testfiles[i]); Assert.AreEqual(mediatypes[i], image.Info.MediaType, testfiles[i]);
// How many sectors to read at once // How many sectors to read at once
const uint SECTORS_TO_READ = 256; const uint SECTORS_TO_READ = 256;
ulong doneSectors = 0; ulong doneSectors = 0;
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init();
while(doneSectors < image.Info.Sectors) while(doneSectors < image.Info.Sectors)
{ {
@@ -87,13 +86,13 @@ namespace DiscImageChef.Tests.Images
if(image.Info.Sectors - doneSectors >= SECTORS_TO_READ) if(image.Info.Sectors - doneSectors >= SECTORS_TO_READ)
{ {
sector = image.ReadSectors(doneSectors, SECTORS_TO_READ); sector = image.ReadSectors(doneSectors, SECTORS_TO_READ);
doneSectors += SECTORS_TO_READ; doneSectors += SECTORS_TO_READ;
} }
else else
{ {
sector = image.ReadSectors(doneSectors, (uint)(image.Info.Sectors - doneSectors)); sector = image.ReadSectors(doneSectors, (uint)(image.Info.Sectors - doneSectors));
doneSectors += image.Info.Sectors - doneSectors; doneSectors += image.Info.Sectors - doneSectors;
} }
ctx.Update(sector); ctx.Update(sector);

View File

@@ -69,21 +69,20 @@ namespace DiscImageChef.Tests.Images
{ {
for(int i = 0; i < testfiles.Length; i++) for(int i = 0; i < testfiles.Length; i++)
{ {
string location = Path.Combine(Consts.TestFilesRoot, "images", "anex86", testfiles[i]); string location = Path.Combine(Consts.TestFilesRoot, "images", "anex86", testfiles[i]);
IFilter filter = new LZip(); IFilter filter = new LZip();
filter.Open(location); filter.Open(location);
IMediaImage image = new DiscImages.Anex86(); IMediaImage image = new DiscImages.Anex86();
Assert.AreEqual(true, image.Open(filter), testfiles[i]); Assert.AreEqual(true, image.Open(filter), testfiles[i]);
Assert.AreEqual(sectors[i], image.Info.Sectors, testfiles[i]); Assert.AreEqual(sectors[i], image.Info.Sectors, testfiles[i]);
Assert.AreEqual(sectorsize[i], image.Info.SectorSize, testfiles[i]); Assert.AreEqual(sectorsize[i], image.Info.SectorSize, testfiles[i]);
Assert.AreEqual(mediatypes[i], image.Info.MediaType, testfiles[i]); Assert.AreEqual(mediatypes[i], image.Info.MediaType, testfiles[i]);
// How many sectors to read at once // How many sectors to read at once
const uint SECTORS_TO_READ = 256; const uint SECTORS_TO_READ = 256;
ulong doneSectors = 0; ulong doneSectors = 0;
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init();
while(doneSectors < image.Info.Sectors) while(doneSectors < image.Info.Sectors)
{ {
@@ -91,13 +90,13 @@ namespace DiscImageChef.Tests.Images
if(image.Info.Sectors - doneSectors >= SECTORS_TO_READ) if(image.Info.Sectors - doneSectors >= SECTORS_TO_READ)
{ {
sector = image.ReadSectors(doneSectors, SECTORS_TO_READ); sector = image.ReadSectors(doneSectors, SECTORS_TO_READ);
doneSectors += SECTORS_TO_READ; doneSectors += SECTORS_TO_READ;
} }
else else
{ {
sector = image.ReadSectors(doneSectors, (uint)(image.Info.Sectors - doneSectors)); sector = image.ReadSectors(doneSectors, (uint)(image.Info.Sectors - doneSectors));
doneSectors += image.Info.Sectors - doneSectors; doneSectors += image.Info.Sectors - doneSectors;
} }
ctx.Update(sector); ctx.Update(sector);

View File

@@ -83,21 +83,20 @@ namespace DiscImageChef.Tests.Images
{ {
for(int i = 0; i < testfiles.Length; i++) for(int i = 0; i < testfiles.Length; i++)
{ {
string location = Path.Combine(Consts.TestFilesRoot, "images", "ciscopy", testfiles[i]); string location = Path.Combine(Consts.TestFilesRoot, "images", "ciscopy", testfiles[i]);
IFilter filter = new LZip(); IFilter filter = new LZip();
filter.Open(location); filter.Open(location);
IMediaImage image = new DiscImages.CisCopy(); IMediaImage image = new DiscImages.CisCopy();
Assert.AreEqual(true, image.Open(filter), testfiles[i]); Assert.AreEqual(true, image.Open(filter), testfiles[i]);
Assert.AreEqual(sectors[i], image.Info.Sectors, testfiles[i]); Assert.AreEqual(sectors[i], image.Info.Sectors, testfiles[i]);
Assert.AreEqual(sectorsize[i], image.Info.SectorSize, testfiles[i]); Assert.AreEqual(sectorsize[i], image.Info.SectorSize, testfiles[i]);
Assert.AreEqual(mediatypes[i], image.Info.MediaType, testfiles[i]); Assert.AreEqual(mediatypes[i], image.Info.MediaType, testfiles[i]);
// How many sectors to read at once // How many sectors to read at once
const uint SECTORS_TO_READ = 256; const uint SECTORS_TO_READ = 256;
ulong doneSectors = 0; ulong doneSectors = 0;
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init();
while(doneSectors < image.Info.Sectors) while(doneSectors < image.Info.Sectors)
{ {
@@ -105,13 +104,13 @@ namespace DiscImageChef.Tests.Images
if(image.Info.Sectors - doneSectors >= SECTORS_TO_READ) if(image.Info.Sectors - doneSectors >= SECTORS_TO_READ)
{ {
sector = image.ReadSectors(doneSectors, SECTORS_TO_READ); sector = image.ReadSectors(doneSectors, SECTORS_TO_READ);
doneSectors += SECTORS_TO_READ; doneSectors += SECTORS_TO_READ;
} }
else else
{ {
sector = image.ReadSectors(doneSectors, (uint)(image.Info.Sectors - doneSectors)); sector = image.ReadSectors(doneSectors, (uint)(image.Info.Sectors - doneSectors));
doneSectors += image.Info.Sectors - doneSectors; doneSectors += image.Info.Sectors - doneSectors;
} }
ctx.Update(sector); ctx.Update(sector);

View File

@@ -71,17 +71,16 @@ namespace DiscImageChef.Tests.Images
IFilter filter = new LZip(); IFilter filter = new LZip();
filter.Open(location); filter.Open(location);
IMediaImage image = new DiscImages.CopyQm(); IMediaImage image = new DiscImages.CopyQm();
Assert.AreEqual(true, image.Open(filter), testfiles[i]); Assert.AreEqual(true, image.Open(filter), testfiles[i]);
Assert.AreEqual(sectors[i], image.Info.Sectors, testfiles[i]); Assert.AreEqual(sectors[i], image.Info.Sectors, testfiles[i]);
Assert.AreEqual(sectorsize[i], image.Info.SectorSize, testfiles[i]); Assert.AreEqual(sectorsize[i], image.Info.SectorSize, testfiles[i]);
Assert.AreEqual(mediatypes[i], image.Info.MediaType, testfiles[i]); Assert.AreEqual(mediatypes[i], image.Info.MediaType, testfiles[i]);
// How many sectors to read at once // How many sectors to read at once
const uint SECTORS_TO_READ = 256; const uint SECTORS_TO_READ = 256;
ulong doneSectors = 0; ulong doneSectors = 0;
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init();
while(doneSectors < image.Info.Sectors) while(doneSectors < image.Info.Sectors)
{ {

View File

@@ -85,21 +85,20 @@ namespace DiscImageChef.Tests.Images
{ {
for(int i = 0; i < testfiles.Length; i++) for(int i = 0; i < testfiles.Length; i++)
{ {
string location = Path.Combine(Consts.TestFilesRoot, "images", "d88", testfiles[i]); string location = Path.Combine(Consts.TestFilesRoot, "images", "d88", testfiles[i]);
IFilter filter = new LZip(); IFilter filter = new LZip();
filter.Open(location); filter.Open(location);
IMediaImage image = new DiscImages.D88(); IMediaImage image = new DiscImages.D88();
Assert.AreEqual(true, image.Open(filter), testfiles[i]); Assert.AreEqual(true, image.Open(filter), testfiles[i]);
Assert.AreEqual(sectors[i], image.Info.Sectors, testfiles[i]); Assert.AreEqual(sectors[i], image.Info.Sectors, testfiles[i]);
Assert.AreEqual(sectorsize[i], image.Info.SectorSize, testfiles[i]); Assert.AreEqual(sectorsize[i], image.Info.SectorSize, testfiles[i]);
Assert.AreEqual(mediatypes[i], image.Info.MediaType, testfiles[i]); Assert.AreEqual(mediatypes[i], image.Info.MediaType, testfiles[i]);
// How many sectors to read at once // How many sectors to read at once
const uint SECTORS_TO_READ = 256; const uint SECTORS_TO_READ = 256;
ulong doneSectors = 0; ulong doneSectors = 0;
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init();
while(doneSectors < image.Info.Sectors) while(doneSectors < image.Info.Sectors)
{ {
@@ -107,13 +106,13 @@ namespace DiscImageChef.Tests.Images
if(image.Info.Sectors - doneSectors >= SECTORS_TO_READ) if(image.Info.Sectors - doneSectors >= SECTORS_TO_READ)
{ {
sector = image.ReadSectors(doneSectors, SECTORS_TO_READ); sector = image.ReadSectors(doneSectors, SECTORS_TO_READ);
doneSectors += SECTORS_TO_READ; doneSectors += SECTORS_TO_READ;
} }
else else
{ {
sector = image.ReadSectors(doneSectors, (uint)(image.Info.Sectors - doneSectors)); sector = image.ReadSectors(doneSectors, (uint)(image.Info.Sectors - doneSectors));
doneSectors += image.Info.Sectors - doneSectors; doneSectors += image.Info.Sectors - doneSectors;
} }
ctx.Update(sector); ctx.Update(sector);

View File

@@ -66,21 +66,20 @@ namespace DiscImageChef.Tests.Images
{ {
for(int i = 0; i < testfiles.Length; i++) for(int i = 0; i < testfiles.Length; i++)
{ {
string location = Path.Combine(Consts.TestFilesRoot, "images", "dart", testfiles[i]); string location = Path.Combine(Consts.TestFilesRoot, "images", "dart", testfiles[i]);
IFilter filter = new LZip(); IFilter filter = new LZip();
filter.Open(location); filter.Open(location);
IMediaImage image = new DiscImages.D88(); IMediaImage image = new DiscImages.D88();
Assert.AreEqual(true, image.Open(filter), testfiles[i]); Assert.AreEqual(true, image.Open(filter), testfiles[i]);
Assert.AreEqual(sectors[i], image.Info.Sectors, testfiles[i]); Assert.AreEqual(sectors[i], image.Info.Sectors, testfiles[i]);
Assert.AreEqual(sectorsize[i], image.Info.SectorSize, testfiles[i]); Assert.AreEqual(sectorsize[i], image.Info.SectorSize, testfiles[i]);
Assert.AreEqual(mediatypes[i], image.Info.MediaType, testfiles[i]); Assert.AreEqual(mediatypes[i], image.Info.MediaType, testfiles[i]);
// How many sectors to read at once // How many sectors to read at once
const uint SECTORS_TO_READ = 256; const uint SECTORS_TO_READ = 256;
ulong doneSectors = 0; ulong doneSectors = 0;
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init();
while(doneSectors < image.Info.Sectors) while(doneSectors < image.Info.Sectors)
{ {
@@ -88,13 +87,13 @@ namespace DiscImageChef.Tests.Images
if(image.Info.Sectors - doneSectors >= SECTORS_TO_READ) if(image.Info.Sectors - doneSectors >= SECTORS_TO_READ)
{ {
sector = image.ReadSectors(doneSectors, SECTORS_TO_READ); sector = image.ReadSectors(doneSectors, SECTORS_TO_READ);
doneSectors += SECTORS_TO_READ; doneSectors += SECTORS_TO_READ;
} }
else else
{ {
sector = image.ReadSectors(doneSectors, (uint)(image.Info.Sectors - doneSectors)); sector = image.ReadSectors(doneSectors, (uint)(image.Info.Sectors - doneSectors));
doneSectors += image.Info.Sectors - doneSectors; doneSectors += image.Info.Sectors - doneSectors;
} }
ctx.Update(sector); ctx.Update(sector);

View File

@@ -86,21 +86,20 @@ namespace DiscImageChef.Tests.Images
{ {
for(int i = 0; i < testfiles.Length; i++) for(int i = 0; i < testfiles.Length; i++)
{ {
string location = Path.Combine(Consts.TestFilesRoot, "images", "", testfiles[i]); string location = Path.Combine(Consts.TestFilesRoot, "images", "", testfiles[i]);
IFilter filter = new LZip(); IFilter filter = new LZip();
filter.Open(location); filter.Open(location);
IMediaImage image = new DiscImages.DiskCopy42(); IMediaImage image = new DiscImages.DiskCopy42();
Assert.AreEqual(true, image.Open(filter), testfiles[i]); Assert.AreEqual(true, image.Open(filter), testfiles[i]);
Assert.AreEqual(sectors[i], image.Info.Sectors, testfiles[i]); Assert.AreEqual(sectors[i], image.Info.Sectors, testfiles[i]);
Assert.AreEqual(sectorsize[i], image.Info.SectorSize, testfiles[i]); Assert.AreEqual(sectorsize[i], image.Info.SectorSize, testfiles[i]);
Assert.AreEqual(mediatypes[i], image.Info.MediaType, testfiles[i]); Assert.AreEqual(mediatypes[i], image.Info.MediaType, testfiles[i]);
// How many sectors to read at once // How many sectors to read at once
const uint SECTORS_TO_READ = 256; const uint SECTORS_TO_READ = 256;
ulong doneSectors = 0; ulong doneSectors = 0;
Md5Context ctx = new Md5Context(); Md5Context ctx = new Md5Context();
ctx.Init();
while(doneSectors < image.Info.Sectors) while(doneSectors < image.Info.Sectors)
{ {
@@ -108,13 +107,13 @@ namespace DiscImageChef.Tests.Images
if(image.Info.Sectors - doneSectors >= SECTORS_TO_READ) if(image.Info.Sectors - doneSectors >= SECTORS_TO_READ)
{ {
sector = image.ReadSectors(doneSectors, SECTORS_TO_READ); sector = image.ReadSectors(doneSectors, SECTORS_TO_READ);
doneSectors += SECTORS_TO_READ; doneSectors += SECTORS_TO_READ;
} }
else else
{ {
sector = image.ReadSectors(doneSectors, (uint)(image.Info.Sectors - doneSectors)); sector = image.ReadSectors(doneSectors, (uint)(image.Info.Sectors - doneSectors));
doneSectors += image.Info.Sectors - doneSectors; doneSectors += image.Info.Sectors - doneSectors;
} }
ctx.Update(sector); ctx.Update(sector);

View File

@@ -45,15 +45,15 @@ namespace DiscImageChef.Commands
{ {
internal static void DoEntropy(EntropyOptions options) internal static void DoEntropy(EntropyOptions options)
{ {
DicConsole.DebugWriteLine("Entropy command", "--debug={0}", options.Debug); DicConsole.DebugWriteLine("Entropy command", "--debug={0}", options.Debug);
DicConsole.DebugWriteLine("Entropy command", "--verbose={0}", options.Verbose); DicConsole.DebugWriteLine("Entropy command", "--verbose={0}", options.Verbose);
DicConsole.DebugWriteLine("Entropy command", "--separated-tracks={0}", options.SeparatedTracks); DicConsole.DebugWriteLine("Entropy command", "--separated-tracks={0}", options.SeparatedTracks);
DicConsole.DebugWriteLine("Entropy command", "--whole-disc={0}", options.WholeDisc); DicConsole.DebugWriteLine("Entropy command", "--whole-disc={0}", options.WholeDisc);
DicConsole.DebugWriteLine("Entropy command", "--input={0}", options.InputFile); DicConsole.DebugWriteLine("Entropy command", "--input={0}", options.InputFile);
DicConsole.DebugWriteLine("Entropy command", "--duplicated-sectors={0}", options.DuplicatedSectors); DicConsole.DebugWriteLine("Entropy command", "--duplicated-sectors={0}", options.DuplicatedSectors);
FiltersList filtersList = new FiltersList(); FiltersList filtersList = new FiltersList();
IFilter inputFilter = filtersList.GetFilter(options.InputFile); IFilter inputFilter = filtersList.GetFilter(options.InputFile);
if(inputFilter == null) if(inputFilter == null)
{ {
@@ -73,9 +73,9 @@ namespace DiscImageChef.Commands
Core.Statistics.AddMediaFormat(inputFormat.Format); Core.Statistics.AddMediaFormat(inputFormat.Format);
Core.Statistics.AddMedia(inputFormat.Info.MediaType, false); Core.Statistics.AddMedia(inputFormat.Info.MediaType, false);
Core.Statistics.AddFilter(inputFilter.Name); Core.Statistics.AddFilter(inputFilter.Name);
double entropy = 0; double entropy = 0;
ulong[] entTable; ulong[] entTable;
ulong sectors; ulong sectors;
if(options.SeparatedTracks) if(options.SeparatedTracks)
try try
@@ -84,9 +84,9 @@ namespace DiscImageChef.Commands
foreach(Track currentTrack in inputTracks) foreach(Track currentTrack in inputTracks)
{ {
Sha1Context sha1CtxTrack = new Sha1Context(); Sha1Context sha1CtxTrack = new Sha1Context();
entTable = new ulong[256]; entTable = new ulong[256];
ulong trackSize = 0; ulong trackSize = 0;
List<string> uniqueSectorsPerTrack = new List<string>(); List<string> uniqueSectorsPerTrack = new List<string>();
sectors = currentTrack.TrackEndSector - currentTrack.TrackStartSector + 1; sectors = currentTrack.TrackEndSector - currentTrack.TrackStartSector + 1;
@@ -108,7 +108,7 @@ namespace DiscImageChef.Commands
trackSize += (ulong)sector.LongLength; trackSize += (ulong)sector.LongLength;
} }
entropy += entTable.Select(l => (double)l / (double)trackSize) entropy += entTable.Select(l => (double)l / (double)trackSize)
.Select(frequency => -(frequency * Math.Log(frequency, 2))).Sum(); .Select(frequency => -(frequency * Math.Log(frequency, 2))).Sum();
DicConsole.WriteLine("Entropy for track {0} is {1:F4}.", currentTrack.TrackSequence, entropy); DicConsole.WriteLine("Entropy for track {0} is {1:F4}.", currentTrack.TrackSequence, entropy);
@@ -129,16 +129,14 @@ namespace DiscImageChef.Commands
if(!options.WholeDisc) return; if(!options.WholeDisc) return;
Sha1Context sha1Ctx = new Sha1Context(); Sha1Context sha1Ctx = new Sha1Context();
entTable = new ulong[256]; entTable = new ulong[256];
ulong diskSize = 0; ulong diskSize = 0;
List<string> uniqueSectors = new List<string>(); List<string> uniqueSectors = new List<string>();
sectors = inputFormat.Info.Sectors; sectors = inputFormat.Info.Sectors;
DicConsole.WriteLine("Sectors {0}", sectors); DicConsole.WriteLine("Sectors {0}", sectors);
sha1Ctx.Init();
for(ulong i = 0; i < sectors; i++) for(ulong i = 0; i < sectors; i++)
{ {
DicConsole.Write("\rEntropying sector {0}", i + 1); DicConsole.Write("\rEntropying sector {0}", i + 1);
@@ -155,7 +153,7 @@ namespace DiscImageChef.Commands
diskSize += (ulong)sector.LongLength; diskSize += (ulong)sector.LongLength;
} }
entropy += entTable.Select(l => (double)l / (double)diskSize) entropy += entTable.Select(l => (double)l / (double)diskSize)
.Select(frequency => -(frequency * Math.Log(frequency, 2))).Sum(); .Select(frequency => -(frequency * Math.Log(frequency, 2))).Sum();
DicConsole.WriteLine(); DicConsole.WriteLine();