mirror of
https://github.com/aaru-dps/Aaru.Checksums.git
synced 2025-12-16 19:24:29 +00:00
General refactor.
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using DiscImageChef.Console;
|
||||
|
||||
@@ -292,8 +293,6 @@ namespace DiscImageChef.Checksums
|
||||
channel[0x00C], channel[0x00D], channel[0x00E], calculatedEdc, storedEdc);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static uint ComputeEdc(uint edc, byte[] src, int size)
|
||||
static uint ComputeEdc(uint edc, IReadOnlyList<byte> src, int size)
|
||||
{
|
||||
int pos = 0;
|
||||
for(; size > 0; size--) edc = (edc >> 8) ^ edcTable[(edc ^ src[pos++]) & 0xFF];
|
||||
@@ -309,7 +308,7 @@ namespace DiscImageChef.Checksums
|
||||
return edc;
|
||||
}
|
||||
|
||||
static bool? CheckCdSectorSubChannel(byte[] subchannel)
|
||||
static bool? CheckCdSectorSubChannel(IReadOnlyList<byte> subchannel)
|
||||
{
|
||||
bool? status = true;
|
||||
byte[] qSubChannel = new byte[12];
|
||||
|
||||
@@ -231,9 +231,9 @@ namespace DiscImageChef.Checksums
|
||||
*/
|
||||
void generate_gf()
|
||||
{
|
||||
int i, mask;
|
||||
int i;
|
||||
|
||||
mask = 1;
|
||||
int mask = 1;
|
||||
alpha_to[mm] = 0;
|
||||
for(i = 0; i < mm; i++)
|
||||
{
|
||||
@@ -372,8 +372,7 @@ namespace DiscImageChef.Checksums
|
||||
if(!initialized) throw new UnauthorizedAccessException("Trying to calculate RS without initializing!");
|
||||
|
||||
erasPos = new int[nn - kk];
|
||||
int degLambda, el, degOmega;
|
||||
int i, j, r;
|
||||
int i, j;
|
||||
int q, tmp;
|
||||
int[] recd = new int[nn];
|
||||
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[] reg = new int[nn - kk + 1];
|
||||
int[] loc = new int[nn - kk];
|
||||
int synError, count;
|
||||
int count;
|
||||
|
||||
/* data[] is in polynomial form, copy and convert to index form */
|
||||
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)
|
||||
* namely @**(B0+i), i = 0, ... ,(NN-KK-1)
|
||||
*/
|
||||
synError = 0;
|
||||
int synError = 0;
|
||||
for(i = 1; i <= nn - kk; i++)
|
||||
{
|
||||
tmp = 0;
|
||||
@@ -471,8 +470,8 @@ namespace DiscImageChef.Checksums
|
||||
* Begin Berlekamp-Massey algorithm to determine error+erasure
|
||||
* locator polynomial
|
||||
*/
|
||||
r = noEras;
|
||||
el = noEras;
|
||||
int r = noEras;
|
||||
int el = noEras;
|
||||
while(++r <= nn - kk)
|
||||
{
|
||||
/* r is the step number */
|
||||
@@ -518,7 +517,7 @@ namespace DiscImageChef.Checksums
|
||||
}
|
||||
|
||||
/* Convert lambda to index form and compute deg(lambda(x)) */
|
||||
degLambda = 0;
|
||||
int degLambda = 0;
|
||||
for(i = 0; i < nn - kk + 1; 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
|
||||
* x**(NN-KK)). in index form. Also find deg(omega).
|
||||
*/
|
||||
degOmega = 0;
|
||||
int degOmega = 0;
|
||||
for(i = 0; i < nn - kk; i++)
|
||||
{
|
||||
tmp = 0;
|
||||
|
||||
@@ -177,15 +177,13 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
void fuzzy_try_fork_blockhash()
|
||||
{
|
||||
uint obh, nbh;
|
||||
|
||||
if(self.Bhend >= NUM_BLOCKHASHES) return;
|
||||
|
||||
if(self.Bhend == 0) // assert
|
||||
throw new Exception("Assertion failed");
|
||||
|
||||
obh = self.Bhend - 1;
|
||||
nbh = self.Bhend;
|
||||
uint obh = self.Bhend - 1;
|
||||
uint nbh = self.Bhend;
|
||||
self.Bh[nbh].H = self.Bh[obh].H;
|
||||
self.Bh[nbh].Halfh = self.Bh[obh].Halfh;
|
||||
self.Bh[nbh].Digest[0] = 0;
|
||||
@@ -213,13 +211,12 @@ namespace DiscImageChef.Checksums
|
||||
|
||||
void fuzzy_engine_step(byte c)
|
||||
{
|
||||
ulong h;
|
||||
uint i;
|
||||
/* 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
|
||||
* as a element of the signature and reset the normal hash. */
|
||||
roll_hash(c);
|
||||
h = roll_sum();
|
||||
ulong h = roll_sum();
|
||||
|
||||
for(i = self.Bhstart; i < self.Bhend; ++i)
|
||||
{
|
||||
@@ -266,14 +263,13 @@ namespace DiscImageChef.Checksums
|
||||
StringBuilder sb = new StringBuilder();
|
||||
uint bi = self.Bhstart;
|
||||
uint h = roll_sum();
|
||||
int i, resultOff;
|
||||
int remain = (int)(FUZZY_MAX_RESULT - 1); /* Exclude terminating '\0'. */
|
||||
result = new byte[FUZZY_MAX_RESULT];
|
||||
/* Verify that our elimination was not overeager. */
|
||||
if(!(bi == 0 || (ulong)SSDEEP_BS(bi) / 2 * SPAMSUM_LENGTH < self.TotalSize))
|
||||
throw new Exception("Assertion failed");
|
||||
|
||||
resultOff = 0;
|
||||
int resultOff = 0;
|
||||
|
||||
/* Initial blocksize guess. */
|
||||
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");
|
||||
|
||||
sb.AppendFormat("{0}:", SSDEEP_BS(bi));
|
||||
i = Encoding.ASCII.GetBytes(sb.ToString()).Length;
|
||||
int 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");
|
||||
|
||||
Reference in New Issue
Block a user