mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
REFACTOR: Reformat code.
This commit is contained in:
@@ -138,10 +138,7 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
StringBuilder adlerOutput = new StringBuilder();
|
||||
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
adlerOutput.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
for(int i = 0; i < hash.Length; i++) { adlerOutput.Append(hash[i].ToString("x2")); }
|
||||
|
||||
fileStream.Close();
|
||||
|
||||
@@ -175,10 +172,7 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
StringBuilder adlerOutput = new StringBuilder();
|
||||
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
adlerOutput.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
for(int i = 0; i < hash.Length; i++) { adlerOutput.Append(hash[i].ToString("x2")); }
|
||||
|
||||
return adlerOutput.ToString();
|
||||
}
|
||||
@@ -193,5 +187,4 @@ namespace DiscImageChef.Checksums
|
||||
return Data(data, (uint)data.Length, out hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -48,34 +48,27 @@ namespace DiscImageChef.Checksums
|
||||
switch(buffer.Length)
|
||||
{
|
||||
case 2448:
|
||||
{
|
||||
byte[] subchannel = new byte[96];
|
||||
byte[] channel = new byte[2352];
|
||||
{
|
||||
byte[] subchannel = new byte[96];
|
||||
byte[] channel = new byte[2352];
|
||||
|
||||
Array.Copy(buffer, 0, channel, 0, 2352);
|
||||
Array.Copy(buffer, 2352, subchannel, 0, 96);
|
||||
Array.Copy(buffer, 0, channel, 0, 2352);
|
||||
Array.Copy(buffer, 2352, subchannel, 0, 96);
|
||||
|
||||
bool? channelStatus = CheckCDSectorChannel(channel);
|
||||
bool? subchannelStatus = CheckCDSectorSubChannel(subchannel);
|
||||
bool? status = null;
|
||||
bool? channelStatus = CheckCDSectorChannel(channel);
|
||||
bool? subchannelStatus = CheckCDSectorSubChannel(subchannel);
|
||||
bool? status = null;
|
||||
|
||||
if(channelStatus == null && subchannelStatus == null)
|
||||
status = null;
|
||||
if(channelStatus == false || subchannelStatus == false)
|
||||
status = false;
|
||||
if(channelStatus == null && subchannelStatus == true)
|
||||
status = true;
|
||||
if(channelStatus == true && subchannelStatus == null)
|
||||
status = true;
|
||||
if(channelStatus == true && subchannelStatus == true)
|
||||
status = true;
|
||||
if(channelStatus == null && subchannelStatus == null) status = null;
|
||||
if(channelStatus == false || subchannelStatus == false) status = false;
|
||||
if(channelStatus == null && subchannelStatus == true) status = true;
|
||||
if(channelStatus == true && subchannelStatus == null) status = true;
|
||||
if(channelStatus == true && subchannelStatus == true) status = true;
|
||||
|
||||
return status;
|
||||
}
|
||||
case 2352:
|
||||
return CheckCDSectorChannel(buffer);
|
||||
default:
|
||||
return null;
|
||||
return status;
|
||||
}
|
||||
case 2352: return CheckCDSectorChannel(buffer);
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,15 +85,8 @@ namespace DiscImageChef.Checksums
|
||||
}
|
||||
}
|
||||
|
||||
static bool CheckECC(
|
||||
byte[] address,
|
||||
byte[] data,
|
||||
uint major_count,
|
||||
uint minor_count,
|
||||
uint major_mult,
|
||||
uint minor_inc,
|
||||
byte[] ecc
|
||||
)
|
||||
static bool CheckECC(byte[] address, byte[] data, uint major_count, uint minor_count, uint major_mult,
|
||||
uint minor_inc, byte[] ecc)
|
||||
{
|
||||
uint size = major_count * minor_count;
|
||||
uint major;
|
||||
@@ -113,31 +99,19 @@ namespace DiscImageChef.Checksums
|
||||
for(minor = 0; minor < minor_count; minor++)
|
||||
{
|
||||
byte temp;
|
||||
if(index < 4)
|
||||
{
|
||||
temp = address[index];
|
||||
}
|
||||
else
|
||||
{
|
||||
temp = data[index - 4];
|
||||
}
|
||||
if(index < 4) { temp = address[index]; }
|
||||
else { temp = data[index - 4]; }
|
||||
index += minor_inc;
|
||||
if(index >= size)
|
||||
{
|
||||
index -= size;
|
||||
}
|
||||
if(index >= size) { index -= size; }
|
||||
ecc_a ^= temp;
|
||||
ecc_b ^= temp;
|
||||
ecc_a = ECC_F_Table[ecc_a];
|
||||
}
|
||||
|
||||
ecc_a = ECC_B_Table[ECC_F_Table[ecc_a] ^ ecc_b];
|
||||
if(
|
||||
ecc[major] != (ecc_a) ||
|
||||
ecc[major + major_count] != (ecc_a ^ ecc_b))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(ecc[major] != (ecc_a) || ecc[major + major_count] != (ecc_a ^ ecc_b)) { return false; }
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -145,49 +119,44 @@ namespace DiscImageChef.Checksums
|
||||
{
|
||||
ECCInit();
|
||||
|
||||
if(
|
||||
channel[0x000] == 0x00 && // sync (12 bytes)
|
||||
channel[0x001] == 0xFF &&
|
||||
channel[0x002] == 0xFF &&
|
||||
channel[0x003] == 0xFF &&
|
||||
channel[0x004] == 0xFF &&
|
||||
channel[0x005] == 0xFF &&
|
||||
channel[0x006] == 0xFF &&
|
||||
channel[0x007] == 0xFF &&
|
||||
channel[0x008] == 0xFF &&
|
||||
channel[0x009] == 0xFF &&
|
||||
channel[0x00A] == 0xFF &&
|
||||
channel[0x00B] == 0x00)
|
||||
if(channel[0x000] == 0x00 && // sync (12 bytes)
|
||||
channel[0x001] == 0xFF && channel[0x002] == 0xFF && channel[0x003] == 0xFF && channel[0x004] == 0xFF &&
|
||||
channel[0x005] == 0xFF && channel[0x006] == 0xFF && channel[0x007] == 0xFF && channel[0x008] == 0xFF &&
|
||||
channel[0x009] == 0xFF && channel[0x00A] == 0xFF && channel[0x00B] == 0x00)
|
||||
{
|
||||
DicConsole.DebugWriteLine("CD checksums", "Data sector, address {0:X2}:{1:X2}:{2:X2}", channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
DicConsole.DebugWriteLine("CD checksums", "Data sector, address {0:X2}:{1:X2}:{2:X2}", channel[0x00C],
|
||||
channel[0x00D], channel[0x00E]);
|
||||
|
||||
if(channel[0x00F] == 0x00) // mode (1 byte)
|
||||
{
|
||||
DicConsole.DebugWriteLine("CD checksums", "Mode 0 sector at address {0:X2}:{1:X2}:{2:X2}", channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
DicConsole.DebugWriteLine("CD checksums", "Mode 0 sector at address {0:X2}:{1:X2}:{2:X2}",
|
||||
channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
for(int i = 0x010; i < 0x930; i++)
|
||||
{
|
||||
if(channel[i] != 0x00)
|
||||
{
|
||||
DicConsole.DebugWriteLine("CD checksums", "Mode 0 sector with error at address: {0:X2}:{1:X2}:{2:X2}", channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
DicConsole.DebugWriteLine("CD checksums",
|
||||
"Mode 0 sector with error at address: {0:X2}:{1:X2}:{2:X2}",
|
||||
channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else if(channel[0x00F] == 0x01) // mode (1 byte)
|
||||
{
|
||||
DicConsole.DebugWriteLine("CD checksums", "Mode 1 sector at address {0:X2}:{1:X2}:{2:X2}", channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
DicConsole.DebugWriteLine("CD checksums", "Mode 1 sector at address {0:X2}:{1:X2}:{2:X2}",
|
||||
channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
|
||||
if(channel[0x814] != 0x00 || // reserved (8 bytes)
|
||||
channel[0x815] != 0x00 ||
|
||||
channel[0x816] != 0x00 ||
|
||||
channel[0x817] != 0x00 ||
|
||||
channel[0x818] != 0x00 ||
|
||||
channel[0x819] != 0x00 ||
|
||||
channel[0x81A] != 0x00 ||
|
||||
channel[0x81B] != 0x00)
|
||||
channel[0x815] != 0x00 || channel[0x816] != 0x00 || channel[0x817] != 0x00 ||
|
||||
channel[0x818] != 0x00 || channel[0x819] != 0x00 || channel[0x81A] != 0x00 ||
|
||||
channel[0x81B] != 0x00)
|
||||
{
|
||||
DicConsole.DebugWriteLine("CD checksums", "Mode 1 sector with data in reserved bytes at address: {0:X2}:{1:X2}:{2:X2}", channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
DicConsole.DebugWriteLine("CD checksums",
|
||||
"Mode 1 sector with data in reserved bytes at address: {0:X2}:{1:X2}:{2:X2}",
|
||||
channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -207,12 +176,15 @@ namespace DiscImageChef.Checksums
|
||||
bool FailedECC_Q = CheckECC(address, data2, 52, 43, 86, 88, ecc_q);
|
||||
|
||||
if(FailedECC_P)
|
||||
DicConsole.DebugWriteLine("CD checksums", "Mode 1 sector at address: {0:X2}:{1:X2}:{2:X2}, fails ECC P check", channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
DicConsole.DebugWriteLine("CD checksums",
|
||||
"Mode 1 sector at address: {0:X2}:{1:X2}:{2:X2}, fails ECC P check",
|
||||
channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
if(FailedECC_Q)
|
||||
DicConsole.DebugWriteLine("CD checksums", "Mode 1 sector at address: {0:X2}:{1:X2}:{2:X2}, fails ECC Q check", channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
DicConsole.DebugWriteLine("CD checksums",
|
||||
"Mode 1 sector at address: {0:X2}:{1:X2}:{2:X2}, fails ECC Q check",
|
||||
channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
|
||||
if(FailedECC_P || FailedECC_Q)
|
||||
return false;
|
||||
if(FailedECC_P || FailedECC_Q) return false;
|
||||
|
||||
/* TODO: This is not working
|
||||
byte[] SectorForCheck = new byte[0x810];
|
||||
@@ -232,13 +204,17 @@ namespace DiscImageChef.Checksums
|
||||
}
|
||||
else if(channel[0x00F] == 0x02) // mode (1 byte)
|
||||
{
|
||||
DicConsole.DebugWriteLine("CD checksums", "Mode 2 sector at address {0:X2}:{1:X2}:{2:X2}", channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
DicConsole.DebugWriteLine("CD checksums", "Mode 2 sector at address {0:X2}:{1:X2}:{2:X2}",
|
||||
channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
|
||||
if((channel[0x012] & 0x20) == 0x20) // mode 2 form 2
|
||||
{
|
||||
if(channel[0x010] != channel[0x014] || channel[0x011] != channel[0x015] || channel[0x012] != channel[0x016] || channel[0x013] != channel[0x017])
|
||||
if(channel[0x010] != channel[0x014] || channel[0x011] != channel[0x015] ||
|
||||
channel[0x012] != channel[0x016] || channel[0x013] != channel[0x017])
|
||||
{
|
||||
DicConsole.DebugWriteLine("CD checksums", "Subheader copies differ in mode 2 form 2 sector at address: {0:X2}:{1:X2}:{2:X2}", channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
DicConsole.DebugWriteLine("CD checksums",
|
||||
"Subheader copies differ in mode 2 form 2 sector at address: {0:X2}:{1:X2}:{2:X2}",
|
||||
channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
}
|
||||
|
||||
/* TODO: This is not working
|
||||
@@ -257,9 +233,12 @@ namespace DiscImageChef.Checksums
|
||||
}
|
||||
else
|
||||
{
|
||||
if(channel[0x010] != channel[0x014] || channel[0x011] != channel[0x015] || channel[0x012] != channel[0x016] || channel[0x013] != channel[0x017])
|
||||
if(channel[0x010] != channel[0x014] || channel[0x011] != channel[0x015] ||
|
||||
channel[0x012] != channel[0x016] || channel[0x013] != channel[0x017])
|
||||
{
|
||||
DicConsole.DebugWriteLine("CD checksums", "Subheader copies differ in mode 2 form 1 sector at address: {0:X2}:{1:X2}:{2:X2}", channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
DicConsole.DebugWriteLine("CD checksums",
|
||||
"Subheader copies differ in mode 2 form 1 sector at address: {0:X2}:{1:X2}:{2:X2}",
|
||||
channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
}
|
||||
|
||||
byte[] address = new byte[4];
|
||||
@@ -281,12 +260,15 @@ namespace DiscImageChef.Checksums
|
||||
bool FailedECC_Q = CheckECC(address, data2, 52, 43, 86, 88, ecc_q);
|
||||
|
||||
if(FailedECC_P)
|
||||
DicConsole.DebugWriteLine("CD checksums", "Mode 2 form 1 sector at address: {0:X2}:{1:X2}:{2:X2}, fails ECC P check", channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
DicConsole.DebugWriteLine("CD checksums",
|
||||
"Mode 2 form 1 sector at address: {0:X2}:{1:X2}:{2:X2}, fails ECC P check",
|
||||
channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
if(FailedECC_Q)
|
||||
DicConsole.DebugWriteLine("CD checksums", "Mode 2 form 1 sector at address: {0:X2}:{1:X2}:{2:X2}, fails ECC Q check", channel[0x00F], channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
DicConsole.DebugWriteLine("CD checksums",
|
||||
"Mode 2 form 1 sector at address: {0:X2}:{1:X2}:{2:X2}, fails ECC Q check",
|
||||
channel[0x00F], channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
|
||||
if(FailedECC_P || FailedECC_Q)
|
||||
return false;
|
||||
if(FailedECC_P || FailedECC_Q) return false;
|
||||
|
||||
/* TODO: This is not working
|
||||
byte[] SectorForCheck = new byte[0x808];
|
||||
@@ -307,10 +289,13 @@ namespace DiscImageChef.Checksums
|
||||
}
|
||||
else
|
||||
{
|
||||
DicConsole.DebugWriteLine("CD checksums", "Unknown mode {0} sector at address: {1:X2}:{2:X2}:{3:X2}", channel[0x00F], channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
DicConsole.DebugWriteLine("CD checksums",
|
||||
"Unknown mode {0} sector at address: {1:X2}:{2:X2}:{3:X2}",
|
||||
channel[0x00F], channel[0x00C], channel[0x00D], channel[0x00E]);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -328,8 +313,7 @@ namespace DiscImageChef.Checksums
|
||||
byte[] CDSubRWPack4 = new byte[24];
|
||||
|
||||
int i = 0;
|
||||
for(int j = 0; j < 12; j++)
|
||||
QSubChannel[j] = 0;
|
||||
for(int j = 0; j < 12; j++) QSubChannel[j] = 0;
|
||||
for(int j = 0; j < 18; j++)
|
||||
{
|
||||
CDTextPack1[j] = 0;
|
||||
@@ -360,82 +344,46 @@ namespace DiscImageChef.Checksums
|
||||
i = 0;
|
||||
for(int j = 0; j < 18; j++)
|
||||
{
|
||||
if(j < 18)
|
||||
CDTextPack1[j] = (byte)(CDTextPack1[j] | ((subchannel[i++] & 0x3F) << 2));
|
||||
if(j < 18)
|
||||
CDTextPack1[j] = (byte)(CDTextPack1[j++] | ((subchannel[i] & 0xC0) >> 4));
|
||||
if(j < 18)
|
||||
CDTextPack1[j] = (byte)(CDTextPack1[j] | ((subchannel[i++] & 0x0F) << 4));
|
||||
if(j < 18)
|
||||
CDTextPack1[j] = (byte)(CDTextPack1[j++] | ((subchannel[i] & 0x3C) >> 2));
|
||||
if(j < 18)
|
||||
CDTextPack1[j] = (byte)(CDTextPack1[j] | ((subchannel[i++] & 0x03) << 6));
|
||||
if(j < 18)
|
||||
CDTextPack1[j] = (byte)(CDTextPack1[j] | (subchannel[i++] & 0x3F));
|
||||
if(j < 18) CDTextPack1[j] = (byte)(CDTextPack1[j] | ((subchannel[i++] & 0x3F) << 2));
|
||||
if(j < 18) CDTextPack1[j] = (byte)(CDTextPack1[j++] | ((subchannel[i] & 0xC0) >> 4));
|
||||
if(j < 18) CDTextPack1[j] = (byte)(CDTextPack1[j] | ((subchannel[i++] & 0x0F) << 4));
|
||||
if(j < 18) CDTextPack1[j] = (byte)(CDTextPack1[j++] | ((subchannel[i] & 0x3C) >> 2));
|
||||
if(j < 18) CDTextPack1[j] = (byte)(CDTextPack1[j] | ((subchannel[i++] & 0x03) << 6));
|
||||
if(j < 18) CDTextPack1[j] = (byte)(CDTextPack1[j] | (subchannel[i++] & 0x3F));
|
||||
}
|
||||
for(int j = 0; j < 18; j++)
|
||||
{
|
||||
if(j < 18)
|
||||
CDTextPack2[j] = (byte)(CDTextPack2[j] | ((subchannel[i++] & 0x3F) << 2));
|
||||
if(j < 18)
|
||||
CDTextPack2[j] = (byte)(CDTextPack2[j++] | ((subchannel[i] & 0xC0) >> 4));
|
||||
if(j < 18)
|
||||
CDTextPack2[j] = (byte)(CDTextPack2[j] | ((subchannel[i++] & 0x0F) << 4));
|
||||
if(j < 18)
|
||||
CDTextPack2[j] = (byte)(CDTextPack2[j++] | ((subchannel[i] & 0x3C) >> 2));
|
||||
if(j < 18)
|
||||
CDTextPack2[j] = (byte)(CDTextPack2[j] | ((subchannel[i++] & 0x03) << 6));
|
||||
if(j < 18)
|
||||
CDTextPack2[j] = (byte)(CDTextPack2[j] | (subchannel[i++] & 0x3F));
|
||||
if(j < 18) CDTextPack2[j] = (byte)(CDTextPack2[j] | ((subchannel[i++] & 0x3F) << 2));
|
||||
if(j < 18) CDTextPack2[j] = (byte)(CDTextPack2[j++] | ((subchannel[i] & 0xC0) >> 4));
|
||||
if(j < 18) CDTextPack2[j] = (byte)(CDTextPack2[j] | ((subchannel[i++] & 0x0F) << 4));
|
||||
if(j < 18) CDTextPack2[j] = (byte)(CDTextPack2[j++] | ((subchannel[i] & 0x3C) >> 2));
|
||||
if(j < 18) CDTextPack2[j] = (byte)(CDTextPack2[j] | ((subchannel[i++] & 0x03) << 6));
|
||||
if(j < 18) CDTextPack2[j] = (byte)(CDTextPack2[j] | (subchannel[i++] & 0x3F));
|
||||
}
|
||||
for(int j = 0; j < 18; j++)
|
||||
{
|
||||
if(j < 18)
|
||||
CDTextPack3[j] = (byte)(CDTextPack3[j] | ((subchannel[i++] & 0x3F) << 2));
|
||||
if(j < 18)
|
||||
CDTextPack3[j] = (byte)(CDTextPack3[j++] | ((subchannel[i] & 0xC0) >> 4));
|
||||
if(j < 18)
|
||||
CDTextPack3[j] = (byte)(CDTextPack3[j] | ((subchannel[i++] & 0x0F) << 4));
|
||||
if(j < 18)
|
||||
CDTextPack3[j] = (byte)(CDTextPack3[j++] | ((subchannel[i] & 0x3C) >> 2));
|
||||
if(j < 18)
|
||||
CDTextPack3[j] = (byte)(CDTextPack3[j] | ((subchannel[i++] & 0x03) << 6));
|
||||
if(j < 18)
|
||||
CDTextPack3[j] = (byte)(CDTextPack3[j] | (subchannel[i++] & 0x3F));
|
||||
if(j < 18) CDTextPack3[j] = (byte)(CDTextPack3[j] | ((subchannel[i++] & 0x3F) << 2));
|
||||
if(j < 18) CDTextPack3[j] = (byte)(CDTextPack3[j++] | ((subchannel[i] & 0xC0) >> 4));
|
||||
if(j < 18) CDTextPack3[j] = (byte)(CDTextPack3[j] | ((subchannel[i++] & 0x0F) << 4));
|
||||
if(j < 18) CDTextPack3[j] = (byte)(CDTextPack3[j++] | ((subchannel[i] & 0x3C) >> 2));
|
||||
if(j < 18) CDTextPack3[j] = (byte)(CDTextPack3[j] | ((subchannel[i++] & 0x03) << 6));
|
||||
if(j < 18) CDTextPack3[j] = (byte)(CDTextPack3[j] | (subchannel[i++] & 0x3F));
|
||||
}
|
||||
for(int j = 0; j < 18; j++)
|
||||
{
|
||||
if(j < 18)
|
||||
CDTextPack4[j] = (byte)(CDTextPack4[j] | ((subchannel[i++] & 0x3F) << 2));
|
||||
if(j < 18)
|
||||
CDTextPack4[j] = (byte)(CDTextPack4[j++] | ((subchannel[i] & 0xC0) >> 4));
|
||||
if(j < 18)
|
||||
CDTextPack4[j] = (byte)(CDTextPack4[j] | ((subchannel[i++] & 0x0F) << 4));
|
||||
if(j < 18)
|
||||
CDTextPack4[j] = (byte)(CDTextPack4[j++] | ((subchannel[i] & 0x3C) >> 2));
|
||||
if(j < 18)
|
||||
CDTextPack4[j] = (byte)(CDTextPack4[j] | ((subchannel[i++] & 0x03) << 6));
|
||||
if(j < 18)
|
||||
CDTextPack4[j] = (byte)(CDTextPack4[j] | (subchannel[i++] & 0x3F));
|
||||
if(j < 18) CDTextPack4[j] = (byte)(CDTextPack4[j] | ((subchannel[i++] & 0x3F) << 2));
|
||||
if(j < 18) CDTextPack4[j] = (byte)(CDTextPack4[j++] | ((subchannel[i] & 0xC0) >> 4));
|
||||
if(j < 18) CDTextPack4[j] = (byte)(CDTextPack4[j] | ((subchannel[i++] & 0x0F) << 4));
|
||||
if(j < 18) CDTextPack4[j] = (byte)(CDTextPack4[j++] | ((subchannel[i] & 0x3C) >> 2));
|
||||
if(j < 18) CDTextPack4[j] = (byte)(CDTextPack4[j] | ((subchannel[i++] & 0x03) << 6));
|
||||
if(j < 18) CDTextPack4[j] = (byte)(CDTextPack4[j] | (subchannel[i++] & 0x3F));
|
||||
}
|
||||
|
||||
i = 0;
|
||||
for(int j = 0; j < 24; j++)
|
||||
{
|
||||
CDSubRWPack1[j] = (byte)(subchannel[i++] & 0x3F);
|
||||
}
|
||||
for(int j = 0; j < 24; j++)
|
||||
{
|
||||
CDSubRWPack2[j] = (byte)(subchannel[i++] & 0x3F);
|
||||
}
|
||||
for(int j = 0; j < 24; j++)
|
||||
{
|
||||
CDSubRWPack3[j] = (byte)(subchannel[i++] & 0x3F);
|
||||
}
|
||||
for(int j = 0; j < 24; j++)
|
||||
{
|
||||
CDSubRWPack4[j] = (byte)(subchannel[i++] & 0x3F);
|
||||
}
|
||||
for(int j = 0; j < 24; j++) { CDSubRWPack1[j] = (byte)(subchannel[i++] & 0x3F); }
|
||||
for(int j = 0; j < 24; j++) { CDSubRWPack2[j] = (byte)(subchannel[i++] & 0x3F); }
|
||||
for(int j = 0; j < 24; j++) { CDSubRWPack3[j] = (byte)(subchannel[i++] & 0x3F); }
|
||||
for(int j = 0; j < 24; j++) { CDSubRWPack4[j] = (byte)(subchannel[i++] & 0x3F); }
|
||||
|
||||
switch(CDSubRWPack1[0])
|
||||
{
|
||||
@@ -461,7 +409,10 @@ namespace DiscImageChef.Checksums
|
||||
DicConsole.DebugWriteLine("CD checksums", "Detected User Pack in subchannel");
|
||||
break;
|
||||
default:
|
||||
DicConsole.DebugWriteLine("CD checksums", "Detected unknown Pack type in subchannel: mode {0}, item {1}", Convert.ToString(CDSubRWPack1[0] & 0x38, 2), Convert.ToString(CDSubRWPack1[0] & 0x07, 2));
|
||||
DicConsole.DebugWriteLine("CD checksums",
|
||||
"Detected unknown Pack type in subchannel: mode {0}, item {1}",
|
||||
Convert.ToString(CDSubRWPack1[0] & 0x38, 2),
|
||||
Convert.ToString(CDSubRWPack1[0] & 0x07, 2));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -474,7 +425,8 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
if(QSubChannelCRC != CalculatedQCRC)
|
||||
{
|
||||
DicConsole.DebugWriteLine("CD checksums", "Q subchannel CRC 0x{0:X4}, expected 0x{1:X4}", CalculatedQCRC, QSubChannelCRC);
|
||||
DicConsole.DebugWriteLine("CD checksums", "Q subchannel CRC 0x{0:X4}, expected 0x{1:X4}",
|
||||
CalculatedQCRC, QSubChannelCRC);
|
||||
status = false;
|
||||
}
|
||||
|
||||
@@ -487,7 +439,8 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
if(CDTextPack1CRC != CalculatedCDTP1CRC && CDTextPack1CRC != 0)
|
||||
{
|
||||
DicConsole.DebugWriteLine("CD checksums", "CD-Text Pack 1 CRC 0x{0:X4}, expected 0x{1:X4}", CDTextPack1CRC, CalculatedCDTP1CRC);
|
||||
DicConsole.DebugWriteLine("CD checksums", "CD-Text Pack 1 CRC 0x{0:X4}, expected 0x{1:X4}",
|
||||
CDTextPack1CRC, CalculatedCDTP1CRC);
|
||||
status = false;
|
||||
}
|
||||
}
|
||||
@@ -498,11 +451,13 @@ namespace DiscImageChef.Checksums
|
||||
byte[] CDTextPack2ForCRC = new byte[16];
|
||||
Array.Copy(CDTextPack2, 0, CDTextPack2ForCRC, 0, 16);
|
||||
ushort CalculatedCDTP2CRC = CalculateCCITT_CRC16(CDTextPack2ForCRC);
|
||||
DicConsole.DebugWriteLine("CD checksums", "Cyclic CDTP2 0x{0:X4}, Calc CDTP2 0x{1:X4}", CDTextPack2CRC, CalculatedCDTP2CRC);
|
||||
DicConsole.DebugWriteLine("CD checksums", "Cyclic CDTP2 0x{0:X4}, Calc CDTP2 0x{1:X4}", CDTextPack2CRC,
|
||||
CalculatedCDTP2CRC);
|
||||
|
||||
if(CDTextPack2CRC != CalculatedCDTP2CRC && CDTextPack2CRC != 0)
|
||||
{
|
||||
DicConsole.DebugWriteLine("CD checksums", "CD-Text Pack 2 CRC 0x{0:X4}, expected 0x{1:X4}", CDTextPack2CRC, CalculatedCDTP2CRC);
|
||||
DicConsole.DebugWriteLine("CD checksums", "CD-Text Pack 2 CRC 0x{0:X4}, expected 0x{1:X4}",
|
||||
CDTextPack2CRC, CalculatedCDTP2CRC);
|
||||
status = false;
|
||||
}
|
||||
}
|
||||
@@ -513,11 +468,13 @@ namespace DiscImageChef.Checksums
|
||||
byte[] CDTextPack3ForCRC = new byte[16];
|
||||
Array.Copy(CDTextPack3, 0, CDTextPack3ForCRC, 0, 16);
|
||||
ushort CalculatedCDTP3CRC = CalculateCCITT_CRC16(CDTextPack3ForCRC);
|
||||
DicConsole.DebugWriteLine("CD checksums", "Cyclic CDTP3 0x{0:X4}, Calc CDTP3 0x{1:X4}", CDTextPack3CRC, CalculatedCDTP3CRC);
|
||||
DicConsole.DebugWriteLine("CD checksums", "Cyclic CDTP3 0x{0:X4}, Calc CDTP3 0x{1:X4}", CDTextPack3CRC,
|
||||
CalculatedCDTP3CRC);
|
||||
|
||||
if(CDTextPack3CRC != CalculatedCDTP3CRC && CDTextPack3CRC != 0)
|
||||
{
|
||||
DicConsole.DebugWriteLine("CD checksums", "CD-Text Pack 3 CRC 0x{0:X4}, expected 0x{1:X4}", CDTextPack3CRC, CalculatedCDTP3CRC);
|
||||
DicConsole.DebugWriteLine("CD checksums", "CD-Text Pack 3 CRC 0x{0:X4}, expected 0x{1:X4}",
|
||||
CDTextPack3CRC, CalculatedCDTP3CRC);
|
||||
status = false;
|
||||
}
|
||||
}
|
||||
@@ -528,11 +485,13 @@ namespace DiscImageChef.Checksums
|
||||
byte[] CDTextPack4ForCRC = new byte[16];
|
||||
Array.Copy(CDTextPack4, 0, CDTextPack4ForCRC, 0, 16);
|
||||
ushort CalculatedCDTP4CRC = CalculateCCITT_CRC16(CDTextPack4ForCRC);
|
||||
DicConsole.DebugWriteLine("CD checksums", "Cyclic CDTP4 0x{0:X4}, Calc CDTP4 0x{1:X4}", CDTextPack4CRC, CalculatedCDTP4CRC);
|
||||
DicConsole.DebugWriteLine("CD checksums", "Cyclic CDTP4 0x{0:X4}, Calc CDTP4 0x{1:X4}", CDTextPack4CRC,
|
||||
CalculatedCDTP4CRC);
|
||||
|
||||
if(CDTextPack4CRC != CalculatedCDTP4CRC && CDTextPack4CRC != 0)
|
||||
{
|
||||
DicConsole.DebugWriteLine("CD checksums", "CD-Text Pack 4 CRC 0x{0:X4}, expected 0x{1:X4}", CDTextPack4CRC, CalculatedCDTP4CRC);
|
||||
DicConsole.DebugWriteLine("CD checksums", "CD-Text Pack 4 CRC 0x{0:X4}, expected 0x{1:X4}",
|
||||
CDTextPack4CRC, CalculatedCDTP4CRC);
|
||||
status = false;
|
||||
}
|
||||
}
|
||||
@@ -542,38 +501,26 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
static readonly ushort[] CCITT_CRC16Table =
|
||||
{
|
||||
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
|
||||
0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
|
||||
0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
|
||||
0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
|
||||
0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
|
||||
0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
|
||||
0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
|
||||
0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
|
||||
0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
|
||||
0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
|
||||
0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
|
||||
0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
|
||||
0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
|
||||
0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
|
||||
0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
|
||||
0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
|
||||
0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
|
||||
0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
|
||||
0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
|
||||
0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
|
||||
0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
|
||||
0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
|
||||
0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
|
||||
0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
|
||||
0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
|
||||
0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
|
||||
0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
|
||||
0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
|
||||
0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
|
||||
0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
|
||||
0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
|
||||
0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
|
||||
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c,
|
||||
0xd1ad, 0xe1ce, 0xf1ef, 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, 0x9339, 0x8318,
|
||||
0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4,
|
||||
0x5485, 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, 0x3653, 0x2672, 0x1611, 0x0630,
|
||||
0x76d7, 0x66f6, 0x5695, 0x46b4, 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, 0x48c4,
|
||||
0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969,
|
||||
0xa90a, 0xb92b, 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, 0xdbfd, 0xcbdc, 0xfbbf,
|
||||
0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
|
||||
0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13,
|
||||
0x2e32, 0x1e51, 0x0e70, 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, 0x9188, 0x81a9,
|
||||
0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046,
|
||||
0x6067, 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, 0x02b1, 0x1290, 0x22f3, 0x32d2,
|
||||
0x4235, 0x5214, 0x6277, 0x7256, 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, 0x34e2,
|
||||
0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e,
|
||||
0xc71d, 0xd73c, 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, 0xd94c, 0xc96d, 0xf90e,
|
||||
0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
|
||||
0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1,
|
||||
0x1ad0, 0x2ab3, 0x3a92, 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, 0x7c26, 0x6c07,
|
||||
0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9,
|
||||
0x9ff8, 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
|
||||
};
|
||||
|
||||
static ushort CalculateCCITT_CRC16(byte[] buffer)
|
||||
@@ -583,10 +530,10 @@ namespace DiscImageChef.Checksums
|
||||
{
|
||||
CRC16 = (ushort)(CCITT_CRC16Table[(CRC16 >> 8) ^ buffer[i]] ^ (CRC16 << 8));
|
||||
}
|
||||
|
||||
CRC16 = (ushort)~CRC16;
|
||||
|
||||
return CRC16;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -59,10 +59,9 @@ namespace DiscImageChef.Checksums
|
||||
{
|
||||
ushort entry = (ushort)i;
|
||||
for(int j = 0; j < 8; j++)
|
||||
if((entry & 1) == 1)
|
||||
entry = (ushort)((entry >> 1) ^ crc16Poly);
|
||||
else
|
||||
entry = (ushort)(entry >> 1);
|
||||
if((entry & 1) == 1) entry = (ushort)((entry >> 1) ^ crc16Poly);
|
||||
else entry = (ushort)(entry >> 1);
|
||||
|
||||
table[i] = entry;
|
||||
}
|
||||
}
|
||||
@@ -74,8 +73,7 @@ namespace DiscImageChef.Checksums
|
||||
/// <param name="len">Length of buffer to hash.</param>
|
||||
public void Update(byte[] data, uint len)
|
||||
{
|
||||
for(int i = 0; i < len; i++)
|
||||
hashInt = (ushort)((hashInt >> 8) ^ table[data[i] ^ (hashInt & 0xFF)]);
|
||||
for(int i = 0; i < len; i++) hashInt = (ushort)((hashInt >> 8) ^ table[data[i] ^ (hashInt & 0xFF)]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -143,10 +141,9 @@ namespace DiscImageChef.Checksums
|
||||
{
|
||||
ushort entry = (ushort)i;
|
||||
for(int j = 0; j < 8; j++)
|
||||
if((entry & 1) == 1)
|
||||
entry = (ushort)((entry >> 1) ^ crc16Poly);
|
||||
else
|
||||
entry = (ushort)(entry >> 1);
|
||||
if((entry & 1) == 1) entry = (ushort)((entry >> 1) ^ crc16Poly);
|
||||
else entry = (ushort)(entry >> 1);
|
||||
|
||||
localTable[i] = entry;
|
||||
}
|
||||
|
||||
@@ -158,10 +155,7 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
StringBuilder crc16Output = new StringBuilder();
|
||||
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
crc16Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
for(int i = 0; i < hash.Length; i++) { crc16Output.Append(hash[i].ToString("x2")); }
|
||||
|
||||
fileStream.Close();
|
||||
|
||||
@@ -199,10 +193,9 @@ namespace DiscImageChef.Checksums
|
||||
{
|
||||
ushort entry = (ushort)i;
|
||||
for(int j = 0; j < 8; j++)
|
||||
if((entry & 1) == 1)
|
||||
entry = (ushort)((entry >> 1) ^ polynomial);
|
||||
else
|
||||
entry = (ushort)(entry >> 1);
|
||||
if((entry & 1) == 1) entry = (ushort)((entry >> 1) ^ polynomial);
|
||||
else entry = (ushort)(entry >> 1);
|
||||
|
||||
localTable[i] = entry;
|
||||
}
|
||||
|
||||
@@ -214,10 +207,7 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
StringBuilder crc16Output = new StringBuilder();
|
||||
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
crc16Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
for(int i = 0; i < hash.Length; i++) { crc16Output.Append(hash[i].ToString("x2")); }
|
||||
|
||||
return crc16Output.ToString();
|
||||
}
|
||||
@@ -232,5 +222,4 @@ namespace DiscImageChef.Checksums
|
||||
return Data(data, (uint)data.Length, out hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -59,10 +59,9 @@ namespace DiscImageChef.Checksums
|
||||
{
|
||||
uint entry = (uint)i;
|
||||
for(int j = 0; j < 8; j++)
|
||||
if((entry & 1) == 1)
|
||||
entry = (entry >> 1) ^ crc32Poly;
|
||||
else
|
||||
entry = entry >> 1;
|
||||
if((entry & 1) == 1) entry = (entry >> 1) ^ crc32Poly;
|
||||
else entry = entry >> 1;
|
||||
|
||||
table[i] = entry;
|
||||
}
|
||||
}
|
||||
@@ -74,8 +73,7 @@ namespace DiscImageChef.Checksums
|
||||
/// <param name="len">Length of buffer to hash.</param>
|
||||
public void Update(byte[] data, uint len)
|
||||
{
|
||||
for(int i = 0; i < len; i++)
|
||||
hashInt = (hashInt >> 8) ^ table[data[i] ^ hashInt & 0xff];
|
||||
for(int i = 0; i < len; i++) hashInt = (hashInt >> 8) ^ table[data[i] ^ hashInt & 0xff];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -143,10 +141,9 @@ namespace DiscImageChef.Checksums
|
||||
{
|
||||
uint entry = (uint)i;
|
||||
for(int j = 0; j < 8; j++)
|
||||
if((entry & 1) == 1)
|
||||
entry = (entry >> 1) ^ crc32Poly;
|
||||
else
|
||||
entry = entry >> 1;
|
||||
if((entry & 1) == 1) entry = (entry >> 1) ^ crc32Poly;
|
||||
else entry = entry >> 1;
|
||||
|
||||
localTable[i] = entry;
|
||||
}
|
||||
|
||||
@@ -159,10 +156,7 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
StringBuilder crc32Output = new StringBuilder();
|
||||
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
crc32Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
for(int i = 0; i < hash.Length; i++) { crc32Output.Append(hash[i].ToString("x2")); }
|
||||
|
||||
fileStream.Close();
|
||||
|
||||
@@ -200,15 +194,13 @@ namespace DiscImageChef.Checksums
|
||||
{
|
||||
uint entry = (uint)i;
|
||||
for(int j = 0; j < 8; j++)
|
||||
if((entry & 1) == 1)
|
||||
entry = (entry >> 1) ^ polynomial;
|
||||
else
|
||||
entry = entry >> 1;
|
||||
if((entry & 1) == 1) entry = (entry >> 1) ^ polynomial;
|
||||
else entry = entry >> 1;
|
||||
|
||||
localTable[i] = entry;
|
||||
}
|
||||
|
||||
for(int i = 0; i < len; i++)
|
||||
localhashInt = (localhashInt >> 8) ^ localTable[data[i] ^ localhashInt & 0xff];
|
||||
for(int i = 0; i < len; i++) localhashInt = (localhashInt >> 8) ^ localTable[data[i] ^ localhashInt & 0xff];
|
||||
|
||||
localhashInt ^= crc32Seed;
|
||||
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
|
||||
@@ -216,10 +208,7 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
StringBuilder crc32Output = new StringBuilder();
|
||||
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
crc32Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
for(int i = 0; i < hash.Length; i++) { crc32Output.Append(hash[i].ToString("x2")); }
|
||||
|
||||
return crc32Output.ToString();
|
||||
}
|
||||
@@ -234,6 +223,4 @@ namespace DiscImageChef.Checksums
|
||||
return Data(data, (uint)data.Length, out hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -58,10 +58,9 @@ namespace DiscImageChef.Checksums
|
||||
{
|
||||
ulong entry = (ulong)i;
|
||||
for(int j = 0; j < 8; j++)
|
||||
if((entry & 1) == 1)
|
||||
entry = (entry >> 1) ^ crc64Poly;
|
||||
else
|
||||
entry = entry >> 1;
|
||||
if((entry & 1) == 1) entry = (entry >> 1) ^ crc64Poly;
|
||||
else entry = entry >> 1;
|
||||
|
||||
table[i] = entry;
|
||||
}
|
||||
}
|
||||
@@ -73,8 +72,7 @@ namespace DiscImageChef.Checksums
|
||||
/// <param name="len">Length of buffer to hash.</param>
|
||||
public void Update(byte[] data, uint len)
|
||||
{
|
||||
for(int i = 0; i < len; i++)
|
||||
hashInt = (hashInt >> 8) ^ table[data[i] ^ hashInt & 0xff];
|
||||
for(int i = 0; i < len; i++) hashInt = (hashInt >> 8) ^ table[data[i] ^ hashInt & 0xff];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -142,10 +140,9 @@ namespace DiscImageChef.Checksums
|
||||
{
|
||||
ulong entry = (ulong)i;
|
||||
for(int j = 0; j < 8; j++)
|
||||
if((entry & 1) == 1)
|
||||
entry = (entry >> 1) ^ crc64Poly;
|
||||
else
|
||||
entry = entry >> 1;
|
||||
if((entry & 1) == 1) entry = (entry >> 1) ^ crc64Poly;
|
||||
else entry = entry >> 1;
|
||||
|
||||
localTable[i] = entry;
|
||||
}
|
||||
|
||||
@@ -158,10 +155,7 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
StringBuilder crc64Output = new StringBuilder();
|
||||
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
crc64Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
for(int i = 0; i < hash.Length; i++) { crc64Output.Append(hash[i].ToString("x2")); }
|
||||
|
||||
fileStream.Close();
|
||||
|
||||
@@ -199,15 +193,13 @@ namespace DiscImageChef.Checksums
|
||||
{
|
||||
ulong entry = (ulong)i;
|
||||
for(int j = 0; j < 8; j++)
|
||||
if((entry & 1) == 1)
|
||||
entry = (entry >> 1) ^ polynomial;
|
||||
else
|
||||
entry = entry >> 1;
|
||||
if((entry & 1) == 1) entry = (entry >> 1) ^ polynomial;
|
||||
else entry = entry >> 1;
|
||||
|
||||
localTable[i] = entry;
|
||||
}
|
||||
|
||||
for(int i = 0; i < len; i++)
|
||||
localhashInt = (localhashInt >> 8) ^ localTable[data[i] ^ localhashInt & 0xff];
|
||||
for(int i = 0; i < len; i++) localhashInt = (localhashInt >> 8) ^ localTable[data[i] ^ localhashInt & 0xff];
|
||||
|
||||
localhashInt ^= crc64Seed;
|
||||
BigEndianBitConverter.IsLittleEndian = BigEndianBitConverter.IsLittleEndian;
|
||||
@@ -215,10 +207,7 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
StringBuilder crc64Output = new StringBuilder();
|
||||
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
crc64Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
for(int i = 0; i < hash.Length; i++) { crc64Output.Append(hash[i].ToString("x2")); }
|
||||
|
||||
return crc64Output.ToString();
|
||||
}
|
||||
@@ -233,6 +222,4 @@ namespace DiscImageChef.Checksums
|
||||
return Data(data, (uint)data.Length, out hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -453,3 +453,4 @@ namespace DiscImageChef.Checksums
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
@@ -87,10 +87,7 @@ namespace DiscImageChef.Checksums
|
||||
_md5Provider.TransformFinalBlock(new byte[0], 0, 0);
|
||||
StringBuilder md5Output = new StringBuilder();
|
||||
|
||||
for(int i = 0; i < _md5Provider.Hash.Length; i++)
|
||||
{
|
||||
md5Output.Append(_md5Provider.Hash[i].ToString("x2"));
|
||||
}
|
||||
for(int i = 0; i < _md5Provider.Hash.Length; i++) { md5Output.Append(_md5Provider.Hash[i].ToString("x2")); }
|
||||
|
||||
return md5Output.ToString();
|
||||
}
|
||||
@@ -118,10 +115,7 @@ namespace DiscImageChef.Checksums
|
||||
hash = _md5Provider.ComputeHash(fileStream);
|
||||
StringBuilder md5Output = new StringBuilder();
|
||||
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
md5Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
for(int i = 0; i < hash.Length; i++) { md5Output.Append(hash[i].ToString("x2")); }
|
||||
|
||||
fileStream.Close();
|
||||
|
||||
@@ -139,10 +133,7 @@ namespace DiscImageChef.Checksums
|
||||
hash = _md5Provider.ComputeHash(data, 0, (int)len);
|
||||
StringBuilder md5Output = new StringBuilder();
|
||||
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
md5Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
for(int i = 0; i < hash.Length; i++) { md5Output.Append(hash[i].ToString("x2")); }
|
||||
|
||||
return md5Output.ToString();
|
||||
}
|
||||
@@ -157,5 +148,4 @@ namespace DiscImageChef.Checksums
|
||||
return Data(data, (uint)data.Length, out hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -54,5 +54,4 @@ using System.Reflection;
|
||||
// if desired. See the Mono documentation for more information about signing.
|
||||
|
||||
//[assembly: AssemblyDelaySign(false)]
|
||||
//[assembly: AssemblyKeyFile("")]
|
||||
|
||||
//[assembly: AssemblyKeyFile("")]
|
||||
@@ -118,10 +118,7 @@ namespace DiscImageChef.Checksums
|
||||
hash = _ripemd160Provider.ComputeHash(fileStream);
|
||||
StringBuilder ripemd160Output = new StringBuilder();
|
||||
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
ripemd160Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
for(int i = 0; i < hash.Length; i++) { ripemd160Output.Append(hash[i].ToString("x2")); }
|
||||
|
||||
fileStream.Close();
|
||||
|
||||
@@ -139,10 +136,7 @@ namespace DiscImageChef.Checksums
|
||||
hash = _ripemd160Provider.ComputeHash(data, 0, (int)len);
|
||||
StringBuilder ripemd160Output = new StringBuilder();
|
||||
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
ripemd160Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
for(int i = 0; i < hash.Length; i++) { ripemd160Output.Append(hash[i].ToString("x2")); }
|
||||
|
||||
return ripemd160Output.ToString();
|
||||
}
|
||||
@@ -157,5 +151,4 @@ namespace DiscImageChef.Checksums
|
||||
return Data(data, (uint)data.Length, out hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -94,52 +94,51 @@ namespace DiscImageChef.Checksums
|
||||
switch(m)
|
||||
{
|
||||
case 2:
|
||||
Pp = new[] { 1, 1, 1 };
|
||||
Pp = new[] {1, 1, 1};
|
||||
break;
|
||||
case 3:
|
||||
Pp = new[] { 1, 1, 0, 1 };
|
||||
Pp = new[] {1, 1, 0, 1};
|
||||
break;
|
||||
case 4:
|
||||
Pp = new[] { 1, 1, 0, 0, 1 };
|
||||
Pp = new[] {1, 1, 0, 0, 1};
|
||||
break;
|
||||
case 5:
|
||||
Pp = new[] { 1, 0, 1, 0, 0, 1 };
|
||||
Pp = new[] {1, 0, 1, 0, 0, 1};
|
||||
break;
|
||||
case 6:
|
||||
Pp = new[] { 1, 1, 0, 0, 0, 0, 1 };
|
||||
Pp = new[] {1, 1, 0, 0, 0, 0, 1};
|
||||
break;
|
||||
case 7:
|
||||
Pp = new[] { 1, 0, 0, 1, 0, 0, 0, 1 };
|
||||
Pp = new[] {1, 0, 0, 1, 0, 0, 0, 1};
|
||||
break;
|
||||
case 8:
|
||||
Pp = new[] { 1, 0, 1, 1, 1, 0, 0, 0, 1 };
|
||||
Pp = new[] {1, 0, 1, 1, 1, 0, 0, 0, 1};
|
||||
break;
|
||||
case 9:
|
||||
Pp = new[] { 1, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
|
||||
Pp = new[] {1, 0, 0, 0, 1, 0, 0, 0, 0, 1};
|
||||
break;
|
||||
case 10:
|
||||
Pp = new[] { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1 };
|
||||
Pp = new[] {1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1};
|
||||
break;
|
||||
case 11:
|
||||
Pp = new[] { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
|
||||
Pp = new[] {1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1};
|
||||
break;
|
||||
case 12:
|
||||
Pp = new[] { 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1 };
|
||||
Pp = new[] {1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1};
|
||||
break;
|
||||
case 13:
|
||||
Pp = new[] { 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
|
||||
Pp = new[] {1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1};
|
||||
break;
|
||||
case 14:
|
||||
Pp = new[] { 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1 };
|
||||
Pp = new[] {1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1};
|
||||
break;
|
||||
case 15:
|
||||
Pp = new[] { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
|
||||
Pp = new[] {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
|
||||
break;
|
||||
case 16:
|
||||
Pp = new[] { 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1 };
|
||||
Pp = new[] {1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1};
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(m), "m must be between 2 and 16 inclusive");
|
||||
default: throw new ArgumentOutOfRangeException(nameof(m), "m must be between 2 and 16 inclusive");
|
||||
}
|
||||
|
||||
MM = m;
|
||||
@@ -149,7 +148,6 @@ namespace DiscImageChef.Checksums
|
||||
Alpha_to = new int[n + 1];
|
||||
Index_of = new int[n + 1];
|
||||
|
||||
|
||||
Gg = new int[NN - KK + 1];
|
||||
|
||||
generate_gf();
|
||||
@@ -165,6 +163,7 @@ namespace DiscImageChef.Checksums
|
||||
x -= NN;
|
||||
x = (x >> MM) + (x & NN);
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
@@ -176,22 +175,19 @@ namespace DiscImageChef.Checksums
|
||||
static void CLEAR(ref int[] a, int n)
|
||||
{
|
||||
int ci;
|
||||
for(ci = (n) - 1; ci >= 0; ci--)
|
||||
(a)[ci] = 0;
|
||||
for(ci = (n) - 1; ci >= 0; ci--) (a)[ci] = 0;
|
||||
}
|
||||
|
||||
static void COPY(ref int[] a, ref int[] b, int n)
|
||||
{
|
||||
int ci;
|
||||
for(ci = (n) - 1; ci >= 0; ci--)
|
||||
(a)[ci] = (b)[ci];
|
||||
for(ci = (n) - 1; ci >= 0; ci--) (a)[ci] = (b)[ci];
|
||||
}
|
||||
|
||||
static void COPYDOWN(ref int[] a, ref int[] b, int n)
|
||||
{
|
||||
int ci;
|
||||
for(ci = (n) - 1; ci >= 0; ci--)
|
||||
(a)[ci] = (b)[ci];
|
||||
for(ci = (n) - 1; ci >= 0; ci--) (a)[ci] = (b)[ci];
|
||||
}
|
||||
|
||||
/* generate GF(2**m) from the irreducible polynomial p(X) in p[0]..p[m]
|
||||
@@ -235,10 +231,10 @@ namespace DiscImageChef.Checksums
|
||||
Alpha_to[i] = mask;
|
||||
Index_of[Alpha_to[i]] = i;
|
||||
/* If Pp[i] == 1 then, term @^i occurs in poly-repr of @^MM */
|
||||
if(Pp[i] != 0)
|
||||
Alpha_to[MM] ^= mask; /* Bit-wise EXOR operation */
|
||||
if(Pp[i] != 0) Alpha_to[MM] ^= mask; /* Bit-wise EXOR operation */
|
||||
mask <<= 1; /* single left-shift */
|
||||
}
|
||||
|
||||
Index_of[Alpha_to[MM]] = MM;
|
||||
/*
|
||||
* Have obtained poly-repr of @^MM. Poly-repr of @^(i+1) is given by
|
||||
@@ -248,12 +244,11 @@ namespace DiscImageChef.Checksums
|
||||
mask >>= 1;
|
||||
for(i = MM + 1; i < NN; i++)
|
||||
{
|
||||
if(Alpha_to[i - 1] >= mask)
|
||||
Alpha_to[i] = Alpha_to[MM] ^ ((Alpha_to[i - 1] ^ mask) << 1);
|
||||
else
|
||||
Alpha_to[i] = Alpha_to[i - 1] << 1;
|
||||
if(Alpha_to[i - 1] >= mask) Alpha_to[i] = Alpha_to[MM] ^ ((Alpha_to[i - 1] ^ mask) << 1);
|
||||
else Alpha_to[i] = Alpha_to[i - 1] << 1;
|
||||
Index_of[Alpha_to[i]] = i;
|
||||
}
|
||||
|
||||
Index_of[0] = A0;
|
||||
Alpha_to[NN] = 0;
|
||||
}
|
||||
@@ -276,7 +271,7 @@ namespace DiscImageChef.Checksums
|
||||
int i, j;
|
||||
|
||||
Gg[0] = Alpha_to[B0];
|
||||
Gg[1] = 1; /* g(x) = (X+@**B0) initially */
|
||||
Gg[1] = 1; /* g(x) = (X+@**B0) initially */
|
||||
for(i = 2; i <= NN - KK; i++)
|
||||
{
|
||||
Gg[i] = 1;
|
||||
@@ -285,16 +280,13 @@ namespace DiscImageChef.Checksums
|
||||
* (@**(B0+i-1) + x)
|
||||
*/
|
||||
for(j = i - 1; j > 0; j--)
|
||||
if(Gg[j] != 0)
|
||||
Gg[j] = Gg[j - 1] ^ Alpha_to[modnn((Index_of[Gg[j]]) + B0 + i - 1)];
|
||||
else
|
||||
Gg[j] = Gg[j - 1];
|
||||
if(Gg[j] != 0) Gg[j] = Gg[j - 1] ^ Alpha_to[modnn((Index_of[Gg[j]]) + B0 + i - 1)];
|
||||
else Gg[j] = Gg[j - 1];
|
||||
/* Gg[0] can never be zero */
|
||||
Gg[0] = Alpha_to[modnn((Index_of[Gg[0]]) + B0 + i - 1)];
|
||||
}
|
||||
/* convert Gg[] to index form for quicker encoding */
|
||||
for(i = 0; i <= NN - KK; i++)
|
||||
Gg[i] = Index_of[Gg[i]];
|
||||
for(i = 0; i <= NN - KK; i++) Gg[i] = Index_of[Gg[i]];
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -322,31 +314,31 @@ namespace DiscImageChef.Checksums
|
||||
CLEAR(ref bb, NN - KK);
|
||||
for(i = KK - 1; i >= 0; i--)
|
||||
{
|
||||
if(MM != 8)
|
||||
{
|
||||
if(data[i] > NN)
|
||||
return -1; /* Illegal symbol */
|
||||
}
|
||||
if(MM != 8) { if(data[i] > NN) return -1; /* Illegal symbol */ }
|
||||
|
||||
feedback = Index_of[data[i] ^ bb[NN - KK - 1]];
|
||||
if(feedback != A0)
|
||||
{ /* feedback term is non-zero */
|
||||
{
|
||||
/* feedback term is non-zero */
|
||||
for(j = NN - KK - 1; j > 0; j--)
|
||||
if(Gg[j] != A0)
|
||||
bb[j] = bb[j - 1] ^ Alpha_to[modnn(Gg[j] + feedback)];
|
||||
else
|
||||
bb[j] = bb[j - 1];
|
||||
if(Gg[j] != A0) bb[j] = bb[j - 1] ^ Alpha_to[modnn(Gg[j] + feedback)];
|
||||
else bb[j] = bb[j - 1];
|
||||
|
||||
bb[0] = Alpha_to[modnn(Gg[0] + feedback)];
|
||||
}
|
||||
else
|
||||
{ /* feedback term is zero. encoder becomes a
|
||||
* single-byte shifter */
|
||||
for(j = NN - KK - 1; j > 0; j--)
|
||||
bb[j] = bb[j - 1];
|
||||
{
|
||||
/* feedback term is zero. encoder becomes a
|
||||
* single-byte shifter */
|
||||
for(j = NN - KK - 1; j > 0; j--) bb[j] = bb[j - 1];
|
||||
|
||||
bb[0] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
throw new UnauthorizedAccessException("Trying to calculate RS without initializing!");
|
||||
}
|
||||
|
||||
@@ -392,11 +384,8 @@ namespace DiscImageChef.Checksums
|
||||
/* data[] is in polynomial form, copy and convert to index form */
|
||||
for(i = NN - 1; i >= 0; i--)
|
||||
{
|
||||
if(MM != 8)
|
||||
{
|
||||
if(data[i] > NN)
|
||||
return -1; /* Illegal symbol */
|
||||
}
|
||||
if(MM != 8) { if(data[i] > NN) return -1; /* Illegal symbol */ }
|
||||
|
||||
recd[i] = Index_of[data[i]];
|
||||
}
|
||||
/* first form the syndromes; i.e., evaluate recd(x) at roots of g(x)
|
||||
@@ -407,13 +396,15 @@ namespace DiscImageChef.Checksums
|
||||
{
|
||||
tmp = 0;
|
||||
for(j = 0; j < NN; j++)
|
||||
if(recd[j] != A0) /* recd[j] in index form */
|
||||
if(recd[j] != A0) /* recd[j] in index form */
|
||||
tmp ^= Alpha_to[modnn(recd[j] + (B0 + i - 1) * j)];
|
||||
syn_error |= tmp; /* set flag if non-zero syndrome =>
|
||||
|
||||
syn_error |= tmp; /* set flag if non-zero syndrome =>
|
||||
* error */
|
||||
/* store syndrome in index form */
|
||||
s[i] = Index_of[tmp];
|
||||
}
|
||||
|
||||
if(syn_error == 0)
|
||||
{
|
||||
/*
|
||||
@@ -422,6 +413,7 @@ namespace DiscImageChef.Checksums
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
CLEAR(ref lambda, NN - KK);
|
||||
lambda[0] = 1;
|
||||
if(no_eras > 0)
|
||||
@@ -434,15 +426,14 @@ namespace DiscImageChef.Checksums
|
||||
for(j = i + 1; j > 0; j--)
|
||||
{
|
||||
tmp = Index_of[lambda[j - 1]];
|
||||
if(tmp != A0)
|
||||
lambda[j] ^= Alpha_to[modnn(u + tmp)];
|
||||
if(tmp != A0) lambda[j] ^= Alpha_to[modnn(u + tmp)];
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
/* find roots of the erasure location polynomial */
|
||||
for(i = 1; i <= no_eras; i++)
|
||||
reg[i] = Index_of[lambda[i]];
|
||||
for(i = 1; i <= no_eras; i++) reg[i] = Index_of[lambda[i]];
|
||||
|
||||
count = 0;
|
||||
for(i = 1; i <= NN; i++)
|
||||
{
|
||||
@@ -453,6 +444,7 @@ namespace DiscImageChef.Checksums
|
||||
reg[j] = modnn(reg[j] + j);
|
||||
q ^= Alpha_to[reg[j]];
|
||||
}
|
||||
|
||||
if(q == 0)
|
||||
{
|
||||
/* store root and error location
|
||||
@@ -463,20 +455,22 @@ namespace DiscImageChef.Checksums
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
if(count != no_eras)
|
||||
{
|
||||
DicConsole.DebugWriteLine("Reed Solomon", "\n lambda(x) is WRONG\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
DicConsole.DebugWriteLine("Reed Solomon", "\n Erasure positions as determined by roots of Eras Loc Poly:\n");
|
||||
for(i = 0; i < count; i++)
|
||||
DicConsole.DebugWriteLine("Reed Solomon", "{0} ", loc[i]);
|
||||
DicConsole.DebugWriteLine("Reed Solomon",
|
||||
"\n Erasure positions as determined by roots of Eras Loc Poly:\n");
|
||||
for(i = 0; i < count; i++) DicConsole.DebugWriteLine("Reed Solomon", "{0} ", loc[i]);
|
||||
|
||||
DicConsole.DebugWriteLine("Reed Solomon", "\n");
|
||||
#endif
|
||||
}
|
||||
for(i = 0; i < NN - KK + 1; i++)
|
||||
b[i] = Index_of[lambda[i]];
|
||||
|
||||
for(i = 0; i < NN - KK + 1; i++) b[i] = Index_of[lambda[i]];
|
||||
|
||||
/*
|
||||
* Begin Berlekamp-Massey algorithm to determine error+erasure
|
||||
@@ -485,7 +479,8 @@ namespace DiscImageChef.Checksums
|
||||
r = no_eras;
|
||||
el = no_eras;
|
||||
while(++r <= NN - KK)
|
||||
{ /* r is the step number */
|
||||
{
|
||||
/* r is the step number */
|
||||
/* Compute discrepancy at the r-th step in poly-form */
|
||||
discr_r = 0;
|
||||
for(i = 0; i < r; i++)
|
||||
@@ -495,7 +490,8 @@ namespace DiscImageChef.Checksums
|
||||
discr_r ^= Alpha_to[modnn(Index_of[lambda[i]] + s[r - i])];
|
||||
}
|
||||
}
|
||||
discr_r = Index_of[discr_r]; /* Index form */
|
||||
|
||||
discr_r = Index_of[discr_r]; /* Index form */
|
||||
if(discr_r == A0)
|
||||
{
|
||||
/* 2 lines below: B(x) <-- x*B(x) */
|
||||
@@ -508,11 +504,10 @@ namespace DiscImageChef.Checksums
|
||||
t[0] = lambda[0];
|
||||
for(i = 0; i < NN - KK; i++)
|
||||
{
|
||||
if(b[i] != A0)
|
||||
t[i + 1] = lambda[i + 1] ^ Alpha_to[modnn(discr_r + b[i])];
|
||||
else
|
||||
t[i + 1] = lambda[i + 1];
|
||||
if(b[i] != A0) t[i + 1] = lambda[i + 1] ^ Alpha_to[modnn(discr_r + b[i])];
|
||||
else t[i + 1] = lambda[i + 1];
|
||||
}
|
||||
|
||||
if(2 * el <= r + no_eras - 1)
|
||||
{
|
||||
el = r + no_eras - el;
|
||||
@@ -529,6 +524,7 @@ namespace DiscImageChef.Checksums
|
||||
COPYDOWN(ref b, ref b, NN - KK);
|
||||
b[0] = A0;
|
||||
}
|
||||
|
||||
COPY(ref lambda, ref t, NN - KK + 1);
|
||||
}
|
||||
}
|
||||
@@ -538,8 +534,7 @@ namespace DiscImageChef.Checksums
|
||||
for(i = 0; i < NN - KK + 1; i++)
|
||||
{
|
||||
lambda[i] = Index_of[lambda[i]];
|
||||
if(lambda[i] != A0)
|
||||
deg_lambda = i;
|
||||
if(lambda[i] != A0) deg_lambda = i;
|
||||
}
|
||||
/*
|
||||
* Find roots of the error+erasure locator polynomial. By Chien
|
||||
@@ -548,7 +543,7 @@ namespace DiscImageChef.Checksums
|
||||
int temp = reg[0];
|
||||
COPY(ref reg, ref lambda, NN - KK);
|
||||
reg[0] = temp;
|
||||
count = 0; /* Number of roots of lambda(x) */
|
||||
count = 0; /* Number of roots of lambda(x) */
|
||||
for(i = 1; i <= NN; i++)
|
||||
{
|
||||
q = 1;
|
||||
@@ -558,6 +553,7 @@ namespace DiscImageChef.Checksums
|
||||
reg[j] = modnn(reg[j] + j);
|
||||
q ^= Alpha_to[reg[j]];
|
||||
}
|
||||
|
||||
if(q == 0)
|
||||
{
|
||||
/* store root (index-form) and error location number */
|
||||
@@ -569,8 +565,8 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
#if DEBUG
|
||||
DicConsole.DebugWriteLine("Reed Solomon", "\n Final error positions:\t");
|
||||
for(i = 0; i < count; i++)
|
||||
DicConsole.DebugWriteLine("Reed Solomon", "{0} ", loc[i]);
|
||||
for(i = 0; i < count; i++) DicConsole.DebugWriteLine("Reed Solomon", "{0} ", loc[i]);
|
||||
|
||||
DicConsole.DebugWriteLine("Reed Solomon", "\n");
|
||||
#endif
|
||||
|
||||
@@ -593,13 +589,13 @@ namespace DiscImageChef.Checksums
|
||||
j = (deg_lambda < i) ? deg_lambda : i;
|
||||
for(; j >= 0; j--)
|
||||
{
|
||||
if((s[i + 1 - j] != A0) && (lambda[j] != A0))
|
||||
tmp ^= Alpha_to[modnn(s[i + 1 - j] + lambda[j])];
|
||||
if((s[i + 1 - j] != A0) && (lambda[j] != A0)) tmp ^= Alpha_to[modnn(s[i + 1 - j] + lambda[j])];
|
||||
}
|
||||
if(tmp != 0)
|
||||
deg_omega = i;
|
||||
|
||||
if(tmp != 0) deg_omega = i;
|
||||
omega[i] = Index_of[tmp];
|
||||
}
|
||||
|
||||
omega[NN - KK] = A0;
|
||||
|
||||
/*
|
||||
@@ -611,18 +607,18 @@ namespace DiscImageChef.Checksums
|
||||
num1 = 0;
|
||||
for(i = deg_omega; i >= 0; i--)
|
||||
{
|
||||
if(omega[i] != A0)
|
||||
num1 ^= Alpha_to[modnn(omega[i] + i * root[j])];
|
||||
if(omega[i] != A0) num1 ^= Alpha_to[modnn(omega[i] + i * root[j])];
|
||||
}
|
||||
|
||||
num2 = Alpha_to[modnn(root[j] * (B0 - 1) + NN)];
|
||||
den = 0;
|
||||
|
||||
/* lambda[i+1] for i even is the formal derivative lambda_pr of lambda[i] */
|
||||
for(i = min(deg_lambda, NN - KK - 1) & ~1; i >= 0; i -= 2)
|
||||
{
|
||||
if(lambda[i + 1] != A0)
|
||||
den ^= Alpha_to[modnn(lambda[i + 1] + i * root[j])];
|
||||
if(lambda[i + 1] != A0) den ^= Alpha_to[modnn(lambda[i + 1] + i * root[j])];
|
||||
}
|
||||
|
||||
if(den == 0)
|
||||
{
|
||||
DicConsole.DebugWriteLine("Reed Solomon", "\n ERROR: denominator = 0\n");
|
||||
@@ -634,9 +630,11 @@ namespace DiscImageChef.Checksums
|
||||
data[loc[j]] ^= Alpha_to[modnn(Index_of[num1] + Index_of[num2] + NN - Index_of[den])];
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
throw new UnauthorizedAccessException("Trying to calculate RS without initializing!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,10 +118,7 @@ namespace DiscImageChef.Checksums
|
||||
hash = _sha1Provider.ComputeHash(fileStream);
|
||||
StringBuilder sha1Output = new StringBuilder();
|
||||
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
sha1Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
for(int i = 0; i < hash.Length; i++) { sha1Output.Append(hash[i].ToString("x2")); }
|
||||
|
||||
fileStream.Close();
|
||||
|
||||
@@ -139,10 +136,7 @@ namespace DiscImageChef.Checksums
|
||||
hash = _sha1Provider.ComputeHash(data, 0, (int)len);
|
||||
StringBuilder sha1Output = new StringBuilder();
|
||||
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
sha1Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
for(int i = 0; i < hash.Length; i++) { sha1Output.Append(hash[i].ToString("x2")); }
|
||||
|
||||
return sha1Output.ToString();
|
||||
}
|
||||
@@ -157,5 +151,4 @@ namespace DiscImageChef.Checksums
|
||||
return Data(data, (uint)data.Length, out hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -118,10 +118,7 @@ namespace DiscImageChef.Checksums
|
||||
hash = _sha256Provider.ComputeHash(fileStream);
|
||||
StringBuilder sha256Output = new StringBuilder();
|
||||
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
sha256Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
for(int i = 0; i < hash.Length; i++) { sha256Output.Append(hash[i].ToString("x2")); }
|
||||
|
||||
fileStream.Close();
|
||||
|
||||
@@ -139,10 +136,7 @@ namespace DiscImageChef.Checksums
|
||||
hash = _sha256Provider.ComputeHash(data, 0, (int)len);
|
||||
StringBuilder sha256Output = new StringBuilder();
|
||||
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
sha256Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
for(int i = 0; i < hash.Length; i++) { sha256Output.Append(hash[i].ToString("x2")); }
|
||||
|
||||
return sha256Output.ToString();
|
||||
}
|
||||
@@ -157,5 +151,4 @@ namespace DiscImageChef.Checksums
|
||||
return Data(data, (uint)data.Length, out hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -118,10 +118,7 @@ namespace DiscImageChef.Checksums
|
||||
hash = _sha384Provider.ComputeHash(fileStream);
|
||||
StringBuilder sha384Output = new StringBuilder();
|
||||
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
sha384Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
for(int i = 0; i < hash.Length; i++) { sha384Output.Append(hash[i].ToString("x2")); }
|
||||
|
||||
fileStream.Close();
|
||||
|
||||
@@ -139,10 +136,7 @@ namespace DiscImageChef.Checksums
|
||||
hash = _sha384Provider.ComputeHash(data, 0, (int)len);
|
||||
StringBuilder sha384Output = new StringBuilder();
|
||||
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
sha384Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
for(int i = 0; i < hash.Length; i++) { sha384Output.Append(hash[i].ToString("x2")); }
|
||||
|
||||
return sha384Output.ToString();
|
||||
}
|
||||
@@ -157,5 +151,4 @@ namespace DiscImageChef.Checksums
|
||||
return Data(data, (uint)data.Length, out hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -118,10 +118,7 @@ namespace DiscImageChef.Checksums
|
||||
hash = _sha512Provider.ComputeHash(fileStream);
|
||||
StringBuilder sha512Output = new StringBuilder();
|
||||
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
sha512Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
for(int i = 0; i < hash.Length; i++) { sha512Output.Append(hash[i].ToString("x2")); }
|
||||
|
||||
fileStream.Close();
|
||||
|
||||
@@ -139,10 +136,7 @@ namespace DiscImageChef.Checksums
|
||||
hash = _sha512Provider.ComputeHash(data, 0, (int)len);
|
||||
StringBuilder sha512Output = new StringBuilder();
|
||||
|
||||
for(int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
sha512Output.Append(hash[i].ToString("x2"));
|
||||
}
|
||||
for(int i = 0; i < hash.Length; i++) { sha512Output.Append(hash[i].ToString("x2")); }
|
||||
|
||||
return sha512Output.ToString();
|
||||
}
|
||||
@@ -157,5 +151,4 @@ namespace DiscImageChef.Checksums
|
||||
return Data(data, (uint)data.Length, out hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -58,14 +58,11 @@ namespace DiscImageChef.Checksums
|
||||
const uint FUZZY_MAX_RESULT = (2 * SPAMSUM_LENGTH + 20);
|
||||
//"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
readonly byte[] b64 =
|
||||
{0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
|
||||
0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50,
|
||||
0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
|
||||
0x59, 0x5A, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
|
||||
0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E,
|
||||
0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76,
|
||||
0x77, 0x78, 0x79, 0x7A, 0x30, 0x31, 0x32, 0x33,
|
||||
0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2B, 0x2F
|
||||
{
|
||||
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52,
|
||||
0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A,
|
||||
0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x30, 0x31,
|
||||
0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2B, 0x2F
|
||||
};
|
||||
|
||||
struct roll_state
|
||||
@@ -118,8 +115,7 @@ namespace DiscImageChef.Checksums
|
||||
{
|
||||
self = new fuzzy_state();
|
||||
self.bh = new blockhash_context[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.bhend = 1;
|
||||
@@ -180,8 +176,7 @@ namespace DiscImageChef.Checksums
|
||||
{
|
||||
uint obh, nbh;
|
||||
|
||||
if(self.bhend >= NUM_BLOCKHASHES)
|
||||
return;
|
||||
if(self.bhend >= NUM_BLOCKHASHES) return;
|
||||
|
||||
if(self.bhend == 0) // assert
|
||||
throw new Exception("Assertion failed");
|
||||
@@ -198,20 +193,15 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
void fuzzy_try_reduce_blockhash()
|
||||
{
|
||||
if(self.bhstart >= self.bhend)
|
||||
throw new Exception("Assertion failed");
|
||||
if(self.bhstart >= self.bhend) throw new Exception("Assertion failed");
|
||||
|
||||
if(self.bhend - self.bhstart < 2)
|
||||
/* Need at least two working hashes. */
|
||||
return;
|
||||
if((ulong)SSDEEP_BS(self.bhstart) * SPAMSUM_LENGTH >=
|
||||
self.total_size)
|
||||
/* Need at least two working hashes. */ return;
|
||||
if((ulong)SSDEEP_BS(self.bhstart) * SPAMSUM_LENGTH >= self.total_size)
|
||||
/* Initial blocksize estimate would select this or a smaller
|
||||
* blocksize. */
|
||||
return;
|
||||
* blocksize. */ return;
|
||||
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
|
||||
* start_blocksize. Get rid of it. */
|
||||
++self.bhstart;
|
||||
@@ -239,8 +229,7 @@ namespace DiscImageChef.Checksums
|
||||
if(h % SSDEEP_BS(i) != SSDEEP_BS(i) - 1)
|
||||
/* Once this condition is false for one bs, it is
|
||||
* 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
|
||||
* based on all characters in the piece of the message between
|
||||
* the last reset point and this one */
|
||||
@@ -268,8 +257,7 @@ namespace DiscImageChef.Checksums
|
||||
self.bh[i].halfdigest = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
fuzzy_try_reduce_blockhash();
|
||||
else fuzzy_try_reduce_blockhash();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,8 +269,7 @@ namespace DiscImageChef.Checksums
|
||||
public void Update(byte[] data, uint len)
|
||||
{
|
||||
self.total_size += len;
|
||||
for(int i = 0; i < len; i++)
|
||||
fuzzy_engine_step(data[i]);
|
||||
for(int i = 0; i < len; i++) fuzzy_engine_step(data[i]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -313,26 +300,20 @@ namespace DiscImageChef.Checksums
|
||||
while((ulong)SSDEEP_BS(bi) * SPAMSUM_LENGTH < self.total_size)
|
||||
{
|
||||
++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. */
|
||||
while(bi >= self.bhend)
|
||||
--bi;
|
||||
while(bi > self.bhstart && self.bh[bi].dlen < SPAMSUM_LENGTH / 2)
|
||||
--bi;
|
||||
if((bi > 0 && self.bh[bi].dlen < SPAMSUM_LENGTH / 2))
|
||||
throw new Exception("Assertion failed");
|
||||
while(bi >= self.bhend) --bi;
|
||||
while(bi > self.bhstart && self.bh[bi].dlen < SPAMSUM_LENGTH / 2) --bi;
|
||||
|
||||
if((bi > 0 && self.bh[bi].dlen < SPAMSUM_LENGTH / 2)) throw new Exception("Assertion failed");
|
||||
|
||||
sb.AppendFormat("{0}:", SSDEEP_BS(bi));
|
||||
i = Encoding.ASCII.GetBytes(sb.ToString()).Length;
|
||||
if(i <= 0)
|
||||
/* Maybe snprintf has set errno here? */
|
||||
throw new OverflowException("The input exceeds data types.");
|
||||
if(i >= remain)
|
||||
throw new Exception("Assertion failed");
|
||||
/* Maybe snprintf has set errno here? */ throw new OverflowException("The input exceeds data types.");
|
||||
if(i >= remain) throw new Exception("Assertion failed");
|
||||
|
||||
remain -= i;
|
||||
|
||||
Array.Copy(Encoding.ASCII.GetBytes(sb.ToString()), 0, result, 0, i);
|
||||
@@ -340,21 +321,18 @@ namespace DiscImageChef.Checksums
|
||||
result_off += i;
|
||||
|
||||
i = (int)self.bh[bi].dlen;
|
||||
if(i > remain)
|
||||
throw new Exception("Assertion failed");
|
||||
if(i > remain) throw new Exception("Assertion failed");
|
||||
|
||||
Array.Copy(self.bh[bi].digest, 0, result, result_off, i);
|
||||
result_off += i;
|
||||
remain -= i;
|
||||
if(h != 0)
|
||||
{
|
||||
if(remain <= 0)
|
||||
throw new Exception("Assertion failed");
|
||||
if(remain <= 0) throw new Exception("Assertion failed");
|
||||
|
||||
result[result_off] = b64[self.bh[bi].h % 64];
|
||||
if(i < 3 ||
|
||||
result[result_off] != result[result_off - 1] ||
|
||||
result[result_off] != result[result_off - 2] ||
|
||||
result[result_off] != result[result_off - 3])
|
||||
if(i < 3 || result[result_off] != result[result_off - 1] ||
|
||||
result[result_off] != result[result_off - 2] || result[result_off] != result[result_off - 3])
|
||||
{
|
||||
++result_off;
|
||||
--remain;
|
||||
@@ -362,42 +340,39 @@ namespace DiscImageChef.Checksums
|
||||
}
|
||||
else if(self.bh[bi].digest[i] != 0)
|
||||
{
|
||||
if(remain <= 0)
|
||||
throw new Exception("Assertion failed");
|
||||
if(remain <= 0) throw new Exception("Assertion failed");
|
||||
|
||||
result[result_off] = self.bh[bi].digest[i];
|
||||
if(i < 3 ||
|
||||
result[result_off] != result[result_off - 1] ||
|
||||
result[result_off] != result[result_off - 2] ||
|
||||
result[result_off] != result[result_off - 3])
|
||||
if(i < 3 || result[result_off] != result[result_off - 1] ||
|
||||
result[result_off] != result[result_off - 2] || result[result_off] != result[result_off - 3])
|
||||
{
|
||||
++result_off;
|
||||
--remain;
|
||||
}
|
||||
}
|
||||
if(remain <= 0)
|
||||
throw new Exception("Assertion failed");
|
||||
|
||||
if(remain <= 0) throw new Exception("Assertion failed");
|
||||
|
||||
result[result_off++] = 0x3A; // ':'
|
||||
--remain;
|
||||
if(bi < self.bhend - 1)
|
||||
{
|
||||
++bi;
|
||||
i = (int)self.bh[bi].dlen;
|
||||
if(i > remain)
|
||||
throw new Exception("Assertion failed");
|
||||
if(i > remain) throw new Exception("Assertion failed");
|
||||
|
||||
Array.Copy(self.bh[bi].digest, 0, result, result_off, i);
|
||||
result_off += i;
|
||||
remain -= i;
|
||||
|
||||
if(h != 0)
|
||||
{
|
||||
if(remain <= 0)
|
||||
throw new Exception("Assertion failed");
|
||||
if(remain <= 0) throw new Exception("Assertion failed");
|
||||
|
||||
h = self.bh[bi].halfh;
|
||||
result[result_off] = b64[h % 64];
|
||||
if(i < 3 ||
|
||||
result[result_off] != result[result_off - 1] ||
|
||||
result[result_off] != result[result_off - 2] ||
|
||||
result[result_off] != result[result_off - 3])
|
||||
if(i < 3 || result[result_off] != result[result_off - 1] ||
|
||||
result[result_off] != result[result_off - 2] || result[result_off] != result[result_off - 3])
|
||||
{
|
||||
++result_off;
|
||||
--remain;
|
||||
@@ -408,13 +383,11 @@ namespace DiscImageChef.Checksums
|
||||
i = self.bh[bi].halfdigest;
|
||||
if(i != 0)
|
||||
{
|
||||
if(remain <= 0)
|
||||
throw new Exception("Assertion failed");
|
||||
if(remain <= 0) throw new Exception("Assertion failed");
|
||||
|
||||
result[result_off] = (byte)i;
|
||||
if(i < 3 ||
|
||||
result[result_off] != result[result_off - 1] ||
|
||||
result[result_off] != result[result_off - 2] ||
|
||||
result[result_off] != result[result_off - 3])
|
||||
if(i < 3 || result[result_off] != result[result_off - 1] ||
|
||||
result[result_off] != result[result_off - 2] || result[result_off] != result[result_off - 3])
|
||||
{
|
||||
++result_off;
|
||||
--remain;
|
||||
@@ -424,15 +397,15 @@ namespace DiscImageChef.Checksums
|
||||
}
|
||||
else if(h != 0)
|
||||
{
|
||||
if(self.bh[bi].dlen != 0)
|
||||
throw new Exception("Assertion failed");
|
||||
if(remain <= 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");
|
||||
|
||||
result[result_off++] = b64[self.bh[bi].h % 64];
|
||||
/* No need to bother with FUZZY_FLAG_ELIMSEQ, because this
|
||||
* digest has length 1. */
|
||||
--remain;
|
||||
}
|
||||
|
||||
result[result_off] = 0;
|
||||
return 0;
|
||||
}
|
||||
@@ -515,8 +488,7 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
for(int i = 0; i < CString.Length; i++)
|
||||
{
|
||||
if(CString[i] == 0)
|
||||
break;
|
||||
if(CString[i] == 0) break;
|
||||
|
||||
sb.Append(Encoding.ASCII.GetString(CString, i, 1));
|
||||
}
|
||||
@@ -524,5 +496,4 @@ namespace DiscImageChef.Checksums
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user