General refactor.

This commit is contained in:
2018-06-20 22:22:21 +01:00
parent 8d16b350b0
commit d3f24ddefd
3 changed files with 17 additions and 23 deletions

View File

@@ -32,6 +32,7 @@
// ****************************************************************************/ // ****************************************************************************/
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using DiscImageChef.Console; using DiscImageChef.Console;
@@ -292,8 +293,6 @@ namespace DiscImageChef.Checksums
channel[0x00C], channel[0x00D], channel[0x00E], calculatedEdc, storedEdc); channel[0x00C], channel[0x00D], channel[0x00E], calculatedEdc, storedEdc);
return false; return false;
} }
return true;
} }
DicConsole.DebugWriteLine("CD checksums", "Unknown mode {0} sector at address: {1:X2}:{2:X2}:{3:X2}", DicConsole.DebugWriteLine("CD checksums", "Unknown mode {0} sector at address: {1:X2}:{2:X2}:{3:X2}",
@@ -301,7 +300,7 @@ namespace DiscImageChef.Checksums
return null; return null;
} }
static uint ComputeEdc(uint edc, byte[] src, int size) static uint ComputeEdc(uint edc, IReadOnlyList<byte> src, int size)
{ {
int pos = 0; int pos = 0;
for(; size > 0; size--) edc = (edc >> 8) ^ edcTable[(edc ^ src[pos++]) & 0xFF]; for(; size > 0; size--) edc = (edc >> 8) ^ edcTable[(edc ^ src[pos++]) & 0xFF];
@@ -309,7 +308,7 @@ namespace DiscImageChef.Checksums
return edc; return edc;
} }
static bool? CheckCdSectorSubChannel(byte[] subchannel) static bool? CheckCdSectorSubChannel(IReadOnlyList<byte> subchannel)
{ {
bool? status = true; bool? status = true;
byte[] qSubChannel = new byte[12]; byte[] qSubChannel = new byte[12];

View File

@@ -231,9 +231,9 @@ namespace DiscImageChef.Checksums
*/ */
void generate_gf() void generate_gf()
{ {
int i, mask; int i;
mask = 1; int mask = 1;
alpha_to[mm] = 0; alpha_to[mm] = 0;
for(i = 0; i < mm; i++) for(i = 0; i < mm; i++)
{ {
@@ -372,8 +372,7 @@ namespace DiscImageChef.Checksums
if(!initialized) throw new UnauthorizedAccessException("Trying to calculate RS without initializing!"); if(!initialized) throw new UnauthorizedAccessException("Trying to calculate RS without initializing!");
erasPos = new int[nn - kk]; erasPos = new int[nn - kk];
int degLambda, el, degOmega; int i, j;
int i, j, r;
int q, tmp; int q, tmp;
int[] recd = new int[nn]; int[] recd = new int[nn];
int[] lambda = new int[nn - kk + 1]; /* Err+Eras Locator poly */ int[] lambda = new int[nn - kk + 1]; /* Err+Eras Locator poly */
@@ -384,7 +383,7 @@ namespace DiscImageChef.Checksums
int[] root = new int[nn - kk]; int[] root = new int[nn - kk];
int[] reg = new int[nn - kk + 1]; int[] reg = new int[nn - kk + 1];
int[] loc = new int[nn - kk]; int[] loc = new int[nn - kk];
int synError, count; int count;
/* data[] is in polynomial form, copy and convert to index form */ /* data[] is in polynomial form, copy and convert to index form */
for(i = nn - 1; i >= 0; i--) for(i = nn - 1; i >= 0; i--)
@@ -396,7 +395,7 @@ namespace DiscImageChef.Checksums
/* first form the syndromes; i.e., evaluate recd(x) at roots of g(x) /* first form the syndromes; i.e., evaluate recd(x) at roots of g(x)
* namely @**(B0+i), i = 0, ... ,(NN-KK-1) * namely @**(B0+i), i = 0, ... ,(NN-KK-1)
*/ */
synError = 0; int synError = 0;
for(i = 1; i <= nn - kk; i++) for(i = 1; i <= nn - kk; i++)
{ {
tmp = 0; tmp = 0;
@@ -471,8 +470,8 @@ namespace DiscImageChef.Checksums
* Begin Berlekamp-Massey algorithm to determine error+erasure * Begin Berlekamp-Massey algorithm to determine error+erasure
* locator polynomial * locator polynomial
*/ */
r = noEras; int r = noEras;
el = noEras; int el = noEras;
while(++r <= nn - kk) while(++r <= nn - kk)
{ {
/* r is the step number */ /* r is the step number */
@@ -518,7 +517,7 @@ namespace DiscImageChef.Checksums
} }
/* Convert lambda to index form and compute deg(lambda(x)) */ /* Convert lambda to index form and compute deg(lambda(x)) */
degLambda = 0; int degLambda = 0;
for(i = 0; i < nn - kk + 1; i++) for(i = 0; i < nn - kk + 1; i++)
{ {
lambda[i] = index_of[lambda[i]]; lambda[i] = index_of[lambda[i]];
@@ -561,7 +560,7 @@ namespace DiscImageChef.Checksums
* Compute err+eras evaluator poly omega(x) = s(x)*lambda(x) (modulo * Compute err+eras evaluator poly omega(x) = s(x)*lambda(x) (modulo
* x**(NN-KK)). in index form. Also find deg(omega). * x**(NN-KK)). in index form. Also find deg(omega).
*/ */
degOmega = 0; int degOmega = 0;
for(i = 0; i < nn - kk; i++) for(i = 0; i < nn - kk; i++)
{ {
tmp = 0; tmp = 0;

View File

@@ -177,15 +177,13 @@ namespace DiscImageChef.Checksums
void fuzzy_try_fork_blockhash() void fuzzy_try_fork_blockhash()
{ {
uint obh, nbh;
if(self.Bhend >= NUM_BLOCKHASHES) return; if(self.Bhend >= NUM_BLOCKHASHES) return;
if(self.Bhend == 0) // assert if(self.Bhend == 0) // assert
throw new Exception("Assertion failed"); throw new Exception("Assertion failed");
obh = self.Bhend - 1; uint obh = self.Bhend - 1;
nbh = self.Bhend; uint 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;
@@ -213,13 +211,12 @@ namespace DiscImageChef.Checksums
void fuzzy_engine_step(byte c) void fuzzy_engine_step(byte c)
{ {
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. */
roll_hash(c); roll_hash(c);
h = roll_sum(); ulong h = roll_sum();
for(i = self.Bhstart; i < self.Bhend; ++i) for(i = self.Bhstart; i < self.Bhend; ++i)
{ {
@@ -266,14 +263,13 @@ namespace DiscImageChef.Checksums
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 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");
resultOff = 0; int resultOff = 0;
/* Initial blocksize guess. */ /* Initial blocksize guess. */
while((ulong)SSDEEP_BS(bi) * SPAMSUM_LENGTH < self.TotalSize) while((ulong)SSDEEP_BS(bi) * SPAMSUM_LENGTH < self.TotalSize)
@@ -289,7 +285,7 @@ namespace DiscImageChef.Checksums
if(bi > 0 && self.Bh[bi].Dlen < SPAMSUM_LENGTH / 2) throw new Exception("Assertion failed"); if(bi > 0 && self.Bh[bi].Dlen < SPAMSUM_LENGTH / 2) throw new Exception("Assertion failed");
sb.AppendFormat("{0}:", SSDEEP_BS(bi)); sb.AppendFormat("{0}:", SSDEEP_BS(bi));
i = Encoding.ASCII.GetBytes(sb.ToString()).Length; int i = Encoding.ASCII.GetBytes(sb.ToString()).Length;
if(i <= 0) if(i <= 0)
/* Maybe snprintf has set errno here? */ throw new OverflowException("The input exceeds data types."); /* Maybe snprintf has set errno here? */ throw new OverflowException("The input exceeds data types.");
if(i >= remain) throw new Exception("Assertion failed"); if(i >= remain) throw new Exception("Assertion failed");