init commit
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
namespace Org.BouncyCastle.Apache.Bzip2;
|
||||
|
||||
public class BZip2Constants
|
||||
{
|
||||
public const int baseBlockSize = 100000;
|
||||
|
||||
public const int MAX_ALPHA_SIZE = 258;
|
||||
|
||||
public const int MAX_CODE_LEN = 23;
|
||||
|
||||
public const int RUNA = 0;
|
||||
|
||||
public const int RUNB = 1;
|
||||
|
||||
public const int N_GROUPS = 6;
|
||||
|
||||
public const int G_SIZE = 50;
|
||||
|
||||
public const int N_ITERS = 4;
|
||||
|
||||
public const int MAX_SELECTORS = 18002;
|
||||
|
||||
public const int NUM_OVERSHOOT_BYTES = 20;
|
||||
|
||||
public static readonly int[] rNums = new int[512]
|
||||
{
|
||||
619, 720, 127, 481, 931, 816, 813, 233, 566, 247,
|
||||
985, 724, 205, 454, 863, 491, 741, 242, 949, 214,
|
||||
733, 859, 335, 708, 621, 574, 73, 654, 730, 472,
|
||||
419, 436, 278, 496, 867, 210, 399, 680, 480, 51,
|
||||
878, 465, 811, 169, 869, 675, 611, 697, 867, 561,
|
||||
862, 687, 507, 283, 482, 129, 807, 591, 733, 623,
|
||||
150, 238, 59, 379, 684, 877, 625, 169, 643, 105,
|
||||
170, 607, 520, 932, 727, 476, 693, 425, 174, 647,
|
||||
73, 122, 335, 530, 442, 853, 695, 249, 445, 515,
|
||||
909, 545, 703, 919, 874, 474, 882, 500, 594, 612,
|
||||
641, 801, 220, 162, 819, 984, 589, 513, 495, 799,
|
||||
161, 604, 958, 533, 221, 400, 386, 867, 600, 782,
|
||||
382, 596, 414, 171, 516, 375, 682, 485, 911, 276,
|
||||
98, 553, 163, 354, 666, 933, 424, 341, 533, 870,
|
||||
227, 730, 475, 186, 263, 647, 537, 686, 600, 224,
|
||||
469, 68, 770, 919, 190, 373, 294, 822, 808, 206,
|
||||
184, 943, 795, 384, 383, 461, 404, 758, 839, 887,
|
||||
715, 67, 618, 276, 204, 918, 873, 777, 604, 560,
|
||||
951, 160, 578, 722, 79, 804, 96, 409, 713, 940,
|
||||
652, 934, 970, 447, 318, 353, 859, 672, 112, 785,
|
||||
645, 863, 803, 350, 139, 93, 354, 99, 820, 908,
|
||||
609, 772, 154, 274, 580, 184, 79, 626, 630, 742,
|
||||
653, 282, 762, 623, 680, 81, 927, 626, 789, 125,
|
||||
411, 521, 938, 300, 821, 78, 343, 175, 128, 250,
|
||||
170, 774, 972, 275, 999, 639, 495, 78, 352, 126,
|
||||
857, 956, 358, 619, 580, 124, 737, 594, 701, 612,
|
||||
669, 112, 134, 694, 363, 992, 809, 743, 168, 974,
|
||||
944, 375, 748, 52, 600, 747, 642, 182, 862, 81,
|
||||
344, 805, 988, 739, 511, 655, 814, 334, 249, 515,
|
||||
897, 955, 664, 981, 649, 113, 974, 459, 893, 228,
|
||||
433, 837, 553, 268, 926, 240, 102, 654, 459, 51,
|
||||
686, 754, 806, 760, 493, 403, 415, 394, 687, 700,
|
||||
946, 670, 656, 610, 738, 392, 760, 799, 887, 653,
|
||||
978, 321, 576, 617, 626, 502, 894, 679, 243, 440,
|
||||
680, 879, 194, 572, 640, 724, 926, 56, 204, 700,
|
||||
707, 151, 457, 449, 797, 195, 791, 558, 945, 679,
|
||||
297, 59, 87, 824, 713, 663, 412, 693, 342, 606,
|
||||
134, 108, 571, 364, 631, 212, 174, 643, 304, 329,
|
||||
343, 97, 430, 751, 497, 314, 983, 374, 822, 928,
|
||||
140, 206, 73, 263, 980, 736, 876, 478, 430, 305,
|
||||
170, 514, 364, 692, 829, 82, 855, 953, 676, 246,
|
||||
369, 970, 294, 750, 807, 827, 150, 790, 288, 923,
|
||||
804, 378, 215, 828, 592, 281, 565, 555, 710, 82,
|
||||
896, 831, 547, 261, 524, 462, 293, 465, 502, 56,
|
||||
661, 821, 976, 991, 658, 869, 905, 758, 745, 193,
|
||||
768, 550, 608, 933, 378, 286, 215, 979, 792, 961,
|
||||
61, 688, 793, 644, 986, 403, 106, 366, 905, 644,
|
||||
372, 567, 466, 434, 645, 210, 389, 550, 919, 135,
|
||||
780, 773, 635, 389, 707, 100, 626, 958, 165, 504,
|
||||
920, 176, 193, 713, 857, 265, 203, 50, 668, 108,
|
||||
645, 990, 626, 197, 510, 357, 358, 850, 858, 364,
|
||||
936, 638
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,930 @@
|
||||
using System.IO;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Apache.Bzip2;
|
||||
|
||||
public class CBZip2InputStream : Stream
|
||||
{
|
||||
private const int START_BLOCK_STATE = 1;
|
||||
|
||||
private const int RAND_PART_A_STATE = 2;
|
||||
|
||||
private const int RAND_PART_B_STATE = 3;
|
||||
|
||||
private const int RAND_PART_C_STATE = 4;
|
||||
|
||||
private const int NO_RAND_PART_A_STATE = 5;
|
||||
|
||||
private const int NO_RAND_PART_B_STATE = 6;
|
||||
|
||||
private const int NO_RAND_PART_C_STATE = 7;
|
||||
|
||||
private int last;
|
||||
|
||||
private int origPtr;
|
||||
|
||||
private int blockSize100k;
|
||||
|
||||
private bool blockRandomised;
|
||||
|
||||
private int bsBuff;
|
||||
|
||||
private int bsLive;
|
||||
|
||||
private CRC mCrc = new CRC();
|
||||
|
||||
private bool[] inUse = new bool[256];
|
||||
|
||||
private int nInUse;
|
||||
|
||||
private char[] seqToUnseq = new char[256];
|
||||
|
||||
private char[] unseqToSeq = new char[256];
|
||||
|
||||
private char[] selector = new char[18002];
|
||||
|
||||
private char[] selectorMtf = new char[18002];
|
||||
|
||||
private int[] tt;
|
||||
|
||||
private char[] ll8;
|
||||
|
||||
private int[] unzftab = new int[256];
|
||||
|
||||
private int[][] limit = InitIntArray(6, 258);
|
||||
|
||||
private int[][] basev = InitIntArray(6, 258);
|
||||
|
||||
private int[][] perm = InitIntArray(6, 258);
|
||||
|
||||
private int[] minLens = new int[6];
|
||||
|
||||
private Stream bsStream;
|
||||
|
||||
private bool streamEnd = false;
|
||||
|
||||
private int currentChar = -1;
|
||||
|
||||
private int currentState = 1;
|
||||
|
||||
private int storedBlockCRC;
|
||||
|
||||
private int storedCombinedCRC;
|
||||
|
||||
private int computedBlockCRC;
|
||||
|
||||
private int computedCombinedCRC;
|
||||
|
||||
private int i2;
|
||||
|
||||
private int count;
|
||||
|
||||
private int chPrev;
|
||||
|
||||
private int ch2;
|
||||
|
||||
private int i;
|
||||
|
||||
private int tPos;
|
||||
|
||||
private int rNToGo = 0;
|
||||
|
||||
private int rTPos = 0;
|
||||
|
||||
private int j2;
|
||||
|
||||
private char z;
|
||||
|
||||
public override bool CanRead => true;
|
||||
|
||||
public override bool CanSeek => false;
|
||||
|
||||
public override bool CanWrite => false;
|
||||
|
||||
public override long Length => 0L;
|
||||
|
||||
public override long Position
|
||||
{
|
||||
get
|
||||
{
|
||||
return 0L;
|
||||
}
|
||||
set
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private static void Cadvise()
|
||||
{
|
||||
}
|
||||
|
||||
private static void CompressedStreamEOF()
|
||||
{
|
||||
Cadvise();
|
||||
}
|
||||
|
||||
private void MakeMaps()
|
||||
{
|
||||
nInUse = 0;
|
||||
for (int i = 0; i < 256; i++)
|
||||
{
|
||||
if (inUse[i])
|
||||
{
|
||||
seqToUnseq[nInUse] = (char)i;
|
||||
unseqToSeq[i] = (char)nInUse;
|
||||
nInUse++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public CBZip2InputStream(Stream zStream)
|
||||
{
|
||||
ll8 = null;
|
||||
tt = null;
|
||||
BsSetStream(zStream);
|
||||
Initialize();
|
||||
InitBlock();
|
||||
SetupBlock();
|
||||
}
|
||||
|
||||
internal static int[][] InitIntArray(int n1, int n2)
|
||||
{
|
||||
int[][] array = new int[n1][];
|
||||
for (int i = 0; i < n1; i++)
|
||||
{
|
||||
array[i] = new int[n2];
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
internal static char[][] InitCharArray(int n1, int n2)
|
||||
{
|
||||
char[][] array = new char[n1][];
|
||||
for (int i = 0; i < n1; i++)
|
||||
{
|
||||
array[i] = new char[n2];
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public override int ReadByte()
|
||||
{
|
||||
if (streamEnd)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
int result = currentChar;
|
||||
switch (currentState)
|
||||
{
|
||||
case 3:
|
||||
SetupRandPartB();
|
||||
break;
|
||||
case 4:
|
||||
SetupRandPartC();
|
||||
break;
|
||||
case 6:
|
||||
SetupNoRandPartB();
|
||||
break;
|
||||
case 7:
|
||||
SetupNoRandPartC();
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
char c = BsGetUChar();
|
||||
char c2 = BsGetUChar();
|
||||
if (c != 'B' && c2 != 'Z')
|
||||
{
|
||||
throw new IOException("Not a BZIP2 marked stream");
|
||||
}
|
||||
c = BsGetUChar();
|
||||
c2 = BsGetUChar();
|
||||
if (c != 'h' || c2 < '1' || c2 > '9')
|
||||
{
|
||||
BsFinishedWithStream();
|
||||
streamEnd = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
SetDecompressStructureSizes(c2 - 48);
|
||||
computedCombinedCRC = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void InitBlock()
|
||||
{
|
||||
char c = BsGetUChar();
|
||||
char c2 = BsGetUChar();
|
||||
char c3 = BsGetUChar();
|
||||
char c4 = BsGetUChar();
|
||||
char c5 = BsGetUChar();
|
||||
char c6 = BsGetUChar();
|
||||
if (c == '\u0017' && c2 == 'r' && c3 == 'E' && c4 == '8' && c5 == 'P' && c6 == '\u0090')
|
||||
{
|
||||
Complete();
|
||||
return;
|
||||
}
|
||||
if (c != '1' || c2 != 'A' || c3 != 'Y' || c4 != '&' || c5 != 'S' || c6 != 'Y')
|
||||
{
|
||||
BadBlockHeader();
|
||||
streamEnd = true;
|
||||
return;
|
||||
}
|
||||
storedBlockCRC = BsGetInt32();
|
||||
if (BsR(1) == 1)
|
||||
{
|
||||
blockRandomised = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
blockRandomised = false;
|
||||
}
|
||||
GetAndMoveToFrontDecode();
|
||||
mCrc.InitialiseCRC();
|
||||
currentState = 1;
|
||||
}
|
||||
|
||||
private void EndBlock()
|
||||
{
|
||||
computedBlockCRC = mCrc.GetFinalCRC();
|
||||
if (storedBlockCRC != computedBlockCRC)
|
||||
{
|
||||
CrcError();
|
||||
}
|
||||
computedCombinedCRC = (computedCombinedCRC << 1) | (computedCombinedCRC >>> 31);
|
||||
computedCombinedCRC ^= computedBlockCRC;
|
||||
}
|
||||
|
||||
private void Complete()
|
||||
{
|
||||
storedCombinedCRC = BsGetInt32();
|
||||
if (storedCombinedCRC != computedCombinedCRC)
|
||||
{
|
||||
CrcError();
|
||||
}
|
||||
BsFinishedWithStream();
|
||||
streamEnd = true;
|
||||
}
|
||||
|
||||
private static void BlockOverrun()
|
||||
{
|
||||
Cadvise();
|
||||
}
|
||||
|
||||
private static void BadBlockHeader()
|
||||
{
|
||||
Cadvise();
|
||||
}
|
||||
|
||||
private static void CrcError()
|
||||
{
|
||||
Cadvise();
|
||||
}
|
||||
|
||||
private void BsFinishedWithStream()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (bsStream != null)
|
||||
{
|
||||
Platform.Dispose(bsStream);
|
||||
bsStream = null;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private void BsSetStream(Stream f)
|
||||
{
|
||||
bsStream = f;
|
||||
bsLive = 0;
|
||||
bsBuff = 0;
|
||||
}
|
||||
|
||||
private int BsR(int n)
|
||||
{
|
||||
while (bsLive < n)
|
||||
{
|
||||
char c = '\0';
|
||||
try
|
||||
{
|
||||
c = (char)bsStream.ReadByte();
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
CompressedStreamEOF();
|
||||
}
|
||||
if (c == '\uffff')
|
||||
{
|
||||
CompressedStreamEOF();
|
||||
}
|
||||
int num = c;
|
||||
bsBuff = (bsBuff << 8) | (num & 0xFF);
|
||||
bsLive += 8;
|
||||
}
|
||||
int result = (bsBuff >> bsLive - n) & ((1 << n) - 1);
|
||||
bsLive -= n;
|
||||
return result;
|
||||
}
|
||||
|
||||
private char BsGetUChar()
|
||||
{
|
||||
return (char)BsR(8);
|
||||
}
|
||||
|
||||
private int BsGetint()
|
||||
{
|
||||
int num = 0;
|
||||
num = (num << 8) | BsR(8);
|
||||
num = (num << 8) | BsR(8);
|
||||
num = (num << 8) | BsR(8);
|
||||
return (num << 8) | BsR(8);
|
||||
}
|
||||
|
||||
private int BsGetIntVS(int numBits)
|
||||
{
|
||||
return BsR(numBits);
|
||||
}
|
||||
|
||||
private int BsGetInt32()
|
||||
{
|
||||
return BsGetint();
|
||||
}
|
||||
|
||||
private void HbCreateDecodeTables(int[] limit, int[] basev, int[] perm, char[] length, int minLen, int maxLen, int alphaSize)
|
||||
{
|
||||
int num = 0;
|
||||
for (int i = minLen; i <= maxLen; i++)
|
||||
{
|
||||
for (int j = 0; j < alphaSize; j++)
|
||||
{
|
||||
if (length[j] == i)
|
||||
{
|
||||
perm[num] = j;
|
||||
num++;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 23; i++)
|
||||
{
|
||||
basev[i] = 0;
|
||||
}
|
||||
for (int i = 0; i < alphaSize; i++)
|
||||
{
|
||||
int[] array2;
|
||||
int[] array = (array2 = basev);
|
||||
int num2 = length[i] + 1;
|
||||
nint num3 = num2;
|
||||
array[num2] = array2[num3] + 1;
|
||||
}
|
||||
for (int i = 1; i < 23; i++)
|
||||
{
|
||||
int[] array2;
|
||||
int[] array3 = (array2 = basev);
|
||||
int num4 = i;
|
||||
nint num3 = num4;
|
||||
array3[num4] = array2[num3] + basev[i - 1];
|
||||
}
|
||||
for (int i = 0; i < 23; i++)
|
||||
{
|
||||
limit[i] = 0;
|
||||
}
|
||||
int num5 = 0;
|
||||
for (int i = minLen; i <= maxLen; i++)
|
||||
{
|
||||
num5 += basev[i + 1] - basev[i];
|
||||
limit[i] = num5 - 1;
|
||||
num5 <<= 1;
|
||||
}
|
||||
for (int i = minLen + 1; i <= maxLen; i++)
|
||||
{
|
||||
basev[i] = (limit[i - 1] + 1 << 1) - basev[i];
|
||||
}
|
||||
}
|
||||
|
||||
private void RecvDecodingTables()
|
||||
{
|
||||
char[][] array = InitCharArray(6, 258);
|
||||
bool[] array2 = new bool[16];
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
if (BsR(1) == 1)
|
||||
{
|
||||
array2[i] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
array2[i] = false;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 256; i++)
|
||||
{
|
||||
inUse[i] = false;
|
||||
}
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
if (!array2[i])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
for (int j = 0; j < 16; j++)
|
||||
{
|
||||
if (BsR(1) == 1)
|
||||
{
|
||||
inUse[i * 16 + j] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
MakeMaps();
|
||||
int num = nInUse + 2;
|
||||
int num2 = BsR(3);
|
||||
int num3 = BsR(15);
|
||||
for (int i = 0; i < num3; i++)
|
||||
{
|
||||
int j = 0;
|
||||
while (BsR(1) == 1)
|
||||
{
|
||||
j++;
|
||||
}
|
||||
selectorMtf[i] = (char)j;
|
||||
}
|
||||
char[] array3 = new char[6];
|
||||
for (char c = '\0'; c < num2; c = (char)(c + 1))
|
||||
{
|
||||
array3[(uint)c] = c;
|
||||
}
|
||||
for (int i = 0; i < num3; i++)
|
||||
{
|
||||
char c = selectorMtf[i];
|
||||
char c2 = array3[(uint)c];
|
||||
while (c > '\0')
|
||||
{
|
||||
array3[(uint)c] = array3[c - 1];
|
||||
c = (char)(c - 1);
|
||||
}
|
||||
array3[0] = c2;
|
||||
selector[i] = c2;
|
||||
}
|
||||
for (int k = 0; k < num2; k++)
|
||||
{
|
||||
int num4 = BsR(5);
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
while (BsR(1) == 1)
|
||||
{
|
||||
num4 = ((BsR(1) != 0) ? (num4 - 1) : (num4 + 1));
|
||||
}
|
||||
array[k][i] = (char)num4;
|
||||
}
|
||||
}
|
||||
for (int k = 0; k < num2; k++)
|
||||
{
|
||||
int num5 = 32;
|
||||
int num6 = 0;
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
if (array[k][i] > num6)
|
||||
{
|
||||
num6 = array[k][i];
|
||||
}
|
||||
if (array[k][i] < num5)
|
||||
{
|
||||
num5 = array[k][i];
|
||||
}
|
||||
}
|
||||
HbCreateDecodeTables(limit[k], basev[k], perm[k], array[k], num5, num6, num);
|
||||
minLens[k] = num5;
|
||||
}
|
||||
}
|
||||
|
||||
private void GetAndMoveToFrontDecode()
|
||||
{
|
||||
char[] array = new char[256];
|
||||
int num = 100000 * blockSize100k;
|
||||
origPtr = BsGetIntVS(24);
|
||||
RecvDecodingTables();
|
||||
int num2 = nInUse + 1;
|
||||
int num3 = -1;
|
||||
int num4 = 0;
|
||||
for (int i = 0; i <= 255; i++)
|
||||
{
|
||||
unzftab[i] = 0;
|
||||
}
|
||||
for (int i = 0; i <= 255; i++)
|
||||
{
|
||||
array[i] = (char)i;
|
||||
}
|
||||
last = -1;
|
||||
if (num4 == 0)
|
||||
{
|
||||
num3++;
|
||||
num4 = 50;
|
||||
}
|
||||
num4--;
|
||||
int num5 = selector[num3];
|
||||
int num6 = minLens[num5];
|
||||
int num7 = BsR(num6);
|
||||
while (num7 > limit[num5][num6])
|
||||
{
|
||||
num6++;
|
||||
while (bsLive < 1)
|
||||
{
|
||||
char c = '\0';
|
||||
try
|
||||
{
|
||||
c = (char)bsStream.ReadByte();
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
CompressedStreamEOF();
|
||||
}
|
||||
if (c == '\uffff')
|
||||
{
|
||||
CompressedStreamEOF();
|
||||
}
|
||||
int num8 = c;
|
||||
bsBuff = (bsBuff << 8) | (num8 & 0xFF);
|
||||
bsLive += 8;
|
||||
}
|
||||
int num9 = (bsBuff >> bsLive - 1) & 1;
|
||||
bsLive--;
|
||||
num7 = (num7 << 1) | num9;
|
||||
}
|
||||
int num10 = perm[num5][num7 - basev[num5][num6]];
|
||||
while (num10 != num2)
|
||||
{
|
||||
int[] array3;
|
||||
nint num18;
|
||||
if (num10 == 0 || num10 == 1)
|
||||
{
|
||||
int num11 = -1;
|
||||
int num12 = 1;
|
||||
do
|
||||
{
|
||||
switch (num10)
|
||||
{
|
||||
case 0:
|
||||
num11 += num12;
|
||||
break;
|
||||
case 1:
|
||||
num11 += 2 * num12;
|
||||
break;
|
||||
}
|
||||
num12 *= 2;
|
||||
if (num4 == 0)
|
||||
{
|
||||
num3++;
|
||||
num4 = 50;
|
||||
}
|
||||
num4--;
|
||||
int num13 = selector[num3];
|
||||
int num14 = minLens[num13];
|
||||
int num15 = BsR(num14);
|
||||
while (num15 > limit[num13][num14])
|
||||
{
|
||||
num14++;
|
||||
while (bsLive < 1)
|
||||
{
|
||||
char c2 = '\0';
|
||||
try
|
||||
{
|
||||
c2 = (char)bsStream.ReadByte();
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
CompressedStreamEOF();
|
||||
}
|
||||
if (c2 == '\uffff')
|
||||
{
|
||||
CompressedStreamEOF();
|
||||
}
|
||||
int num16 = c2;
|
||||
bsBuff = (bsBuff << 8) | (num16 & 0xFF);
|
||||
bsLive += 8;
|
||||
}
|
||||
int num17 = (bsBuff >> bsLive - 1) & 1;
|
||||
bsLive--;
|
||||
num15 = (num15 << 1) | num17;
|
||||
}
|
||||
num10 = perm[num13][num15 - basev[num13][num14]];
|
||||
}
|
||||
while (num10 == 0 || num10 == 1);
|
||||
num11++;
|
||||
char c3 = seqToUnseq[(uint)array[0]];
|
||||
int[] array2 = (array3 = unzftab);
|
||||
num18 = (int)c3;
|
||||
array2[(uint)c3] = array3[num18] + num11;
|
||||
while (num11 > 0)
|
||||
{
|
||||
last++;
|
||||
ll8[last] = c3;
|
||||
num11--;
|
||||
}
|
||||
if (last >= num)
|
||||
{
|
||||
BlockOverrun();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
last++;
|
||||
if (last >= num)
|
||||
{
|
||||
BlockOverrun();
|
||||
}
|
||||
char c4 = array[num10 - 1];
|
||||
int[] array4 = (array3 = unzftab);
|
||||
char num19 = seqToUnseq[(uint)c4];
|
||||
num18 = (int)num19;
|
||||
array4[(uint)num19] = array3[num18] + 1;
|
||||
ll8[last] = seqToUnseq[(uint)c4];
|
||||
int num20;
|
||||
for (num20 = num10 - 1; num20 > 3; num20 -= 4)
|
||||
{
|
||||
array[num20] = array[num20 - 1];
|
||||
array[num20 - 1] = array[num20 - 2];
|
||||
array[num20 - 2] = array[num20 - 3];
|
||||
array[num20 - 3] = array[num20 - 4];
|
||||
}
|
||||
while (num20 > 0)
|
||||
{
|
||||
array[num20] = array[num20 - 1];
|
||||
num20--;
|
||||
}
|
||||
array[0] = c4;
|
||||
if (num4 == 0)
|
||||
{
|
||||
num3++;
|
||||
num4 = 50;
|
||||
}
|
||||
num4--;
|
||||
int num21 = selector[num3];
|
||||
int num22 = minLens[num21];
|
||||
int num23 = BsR(num22);
|
||||
while (num23 > limit[num21][num22])
|
||||
{
|
||||
num22++;
|
||||
while (bsLive < 1)
|
||||
{
|
||||
char c5 = '\0';
|
||||
try
|
||||
{
|
||||
c5 = (char)bsStream.ReadByte();
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
CompressedStreamEOF();
|
||||
}
|
||||
int num24 = c5;
|
||||
bsBuff = (bsBuff << 8) | (num24 & 0xFF);
|
||||
bsLive += 8;
|
||||
}
|
||||
int num25 = (bsBuff >> bsLive - 1) & 1;
|
||||
bsLive--;
|
||||
num23 = (num23 << 1) | num25;
|
||||
}
|
||||
num10 = perm[num21][num23 - basev[num21][num22]];
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupBlock()
|
||||
{
|
||||
int[] array = new int[257];
|
||||
array[0] = 0;
|
||||
for (i = 1; i <= 256; i++)
|
||||
{
|
||||
array[i] = unzftab[i - 1];
|
||||
}
|
||||
for (i = 1; i <= 256; i++)
|
||||
{
|
||||
int[] array3;
|
||||
int[] array2 = (array3 = array);
|
||||
int num = i;
|
||||
nint num2 = num;
|
||||
array2[num] = array3[num2] + array[i - 1];
|
||||
}
|
||||
for (i = 0; i <= last; i++)
|
||||
{
|
||||
char c = ll8[i];
|
||||
tt[array[(uint)c]] = i;
|
||||
int[] array3;
|
||||
int[] array4 = (array3 = array);
|
||||
nint num2 = (int)c;
|
||||
array4[(uint)c] = array3[num2] + 1;
|
||||
}
|
||||
array = null;
|
||||
tPos = tt[origPtr];
|
||||
count = 0;
|
||||
i2 = 0;
|
||||
ch2 = 256;
|
||||
if (blockRandomised)
|
||||
{
|
||||
rNToGo = 0;
|
||||
rTPos = 0;
|
||||
SetupRandPartA();
|
||||
}
|
||||
else
|
||||
{
|
||||
SetupNoRandPartA();
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupRandPartA()
|
||||
{
|
||||
if (i2 <= last)
|
||||
{
|
||||
chPrev = ch2;
|
||||
ch2 = ll8[tPos];
|
||||
tPos = tt[tPos];
|
||||
if (rNToGo == 0)
|
||||
{
|
||||
rNToGo = BZip2Constants.rNums[rTPos];
|
||||
rTPos++;
|
||||
if (rTPos == 512)
|
||||
{
|
||||
rTPos = 0;
|
||||
}
|
||||
}
|
||||
rNToGo--;
|
||||
ch2 ^= ((rNToGo == 1) ? 1 : 0);
|
||||
i2++;
|
||||
currentChar = ch2;
|
||||
currentState = 3;
|
||||
mCrc.UpdateCRC(ch2);
|
||||
}
|
||||
else
|
||||
{
|
||||
EndBlock();
|
||||
InitBlock();
|
||||
SetupBlock();
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupNoRandPartA()
|
||||
{
|
||||
if (i2 <= last)
|
||||
{
|
||||
chPrev = ch2;
|
||||
ch2 = ll8[tPos];
|
||||
tPos = tt[tPos];
|
||||
i2++;
|
||||
currentChar = ch2;
|
||||
currentState = 6;
|
||||
mCrc.UpdateCRC(ch2);
|
||||
}
|
||||
else
|
||||
{
|
||||
EndBlock();
|
||||
InitBlock();
|
||||
SetupBlock();
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupRandPartB()
|
||||
{
|
||||
if (ch2 != chPrev)
|
||||
{
|
||||
currentState = 2;
|
||||
count = 1;
|
||||
SetupRandPartA();
|
||||
return;
|
||||
}
|
||||
count++;
|
||||
if (count >= 4)
|
||||
{
|
||||
z = ll8[tPos];
|
||||
tPos = tt[tPos];
|
||||
if (rNToGo == 0)
|
||||
{
|
||||
rNToGo = BZip2Constants.rNums[rTPos];
|
||||
rTPos++;
|
||||
if (rTPos == 512)
|
||||
{
|
||||
rTPos = 0;
|
||||
}
|
||||
}
|
||||
rNToGo--;
|
||||
z ^= ((rNToGo == 1) ? '\u0001' : '\0');
|
||||
j2 = 0;
|
||||
currentState = 4;
|
||||
SetupRandPartC();
|
||||
}
|
||||
else
|
||||
{
|
||||
currentState = 2;
|
||||
SetupRandPartA();
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupRandPartC()
|
||||
{
|
||||
if (j2 < z)
|
||||
{
|
||||
currentChar = ch2;
|
||||
mCrc.UpdateCRC(ch2);
|
||||
j2++;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentState = 2;
|
||||
i2++;
|
||||
count = 0;
|
||||
SetupRandPartA();
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupNoRandPartB()
|
||||
{
|
||||
if (ch2 != chPrev)
|
||||
{
|
||||
currentState = 5;
|
||||
count = 1;
|
||||
SetupNoRandPartA();
|
||||
return;
|
||||
}
|
||||
count++;
|
||||
if (count >= 4)
|
||||
{
|
||||
z = ll8[tPos];
|
||||
tPos = tt[tPos];
|
||||
currentState = 7;
|
||||
j2 = 0;
|
||||
SetupNoRandPartC();
|
||||
}
|
||||
else
|
||||
{
|
||||
currentState = 5;
|
||||
SetupNoRandPartA();
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupNoRandPartC()
|
||||
{
|
||||
if (j2 < z)
|
||||
{
|
||||
currentChar = ch2;
|
||||
mCrc.UpdateCRC(ch2);
|
||||
j2++;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentState = 5;
|
||||
i2++;
|
||||
count = 0;
|
||||
SetupNoRandPartA();
|
||||
}
|
||||
}
|
||||
|
||||
private void SetDecompressStructureSizes(int newSize100k)
|
||||
{
|
||||
if (0 <= newSize100k && newSize100k <= 9 && 0 <= blockSize100k)
|
||||
{
|
||||
_ = blockSize100k;
|
||||
_ = 9;
|
||||
}
|
||||
blockSize100k = newSize100k;
|
||||
if (newSize100k != 0)
|
||||
{
|
||||
int num = 100000 * newSize100k;
|
||||
ll8 = new char[num];
|
||||
tt = new int[num];
|
||||
}
|
||||
}
|
||||
|
||||
public override void Flush()
|
||||
{
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
int num = -1;
|
||||
int i;
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
num = ReadByte();
|
||||
if (num == -1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
buffer[i + offset] = (byte)num;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
public override long Seek(long offset, SeekOrigin origin)
|
||||
{
|
||||
return 0L;
|
||||
}
|
||||
|
||||
public override void SetLength(long value)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Write(byte[] buffer, int offset, int count)
|
||||
{
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,71 @@
|
||||
namespace Org.BouncyCastle.Apache.Bzip2;
|
||||
|
||||
internal class CRC
|
||||
{
|
||||
public static readonly int[] crc32Table = new int[256]
|
||||
{
|
||||
0, 79764919, 159529838, 222504665, 319059676, 398814059, 445009330, 507990021, 638119352, 583659535,
|
||||
797628118, 726387553, 890018660, 835552979, 1015980042, 944750013, 1276238704, 1221641927, 1167319070, 1095957929,
|
||||
1595256236, 1540665371, 1452775106, 1381403509, 1780037320, 1859660671, 1671105958, 1733955601, 2031960084, 2111593891,
|
||||
1889500026, 1952343757, -1742489888, -1662866601, -1851683442, -1788833735, -1960329156, -1880695413, -2103051438, -2040207643,
|
||||
-1104454824, -1159051537, -1213636554, -1284997759, -1389417084, -1444007885, -1532160278, -1603531939, -734892656, -789352409,
|
||||
-575645954, -646886583, -952755380, -1007220997, -827056094, -898286187, -231047128, -151282273, -71779514, -8804623,
|
||||
-515967244, -436212925, -390279782, -327299027, 881225847, 809987520, 1023691545, 969234094, 662832811, 591600412,
|
||||
771767749, 717299826, 311336399, 374308984, 453813921, 533576470, 25881363, 88864420, 134795389, 214552010,
|
||||
2023205639, 2086057648, 1897238633, 1976864222, 1804852699, 1867694188, 1645340341, 1724971778, 1587496639, 1516133128,
|
||||
1461550545, 1406951526, 1302016099, 1230646740, 1142491917, 1087903418, -1398421865, -1469785312, -1524105735, -1578704818,
|
||||
-1079922613, -1151291908, -1239184603, -1293773166, -1968362705, -1905510760, -2094067647, -2014441994, -1716953613, -1654112188,
|
||||
-1876203875, -1796572374, -525066777, -462094256, -382327159, -302564546, -206542021, -143559028, -97365931, -17609246,
|
||||
-960696225, -1031934488, -817968335, -872425850, -709327229, -780559564, -600130067, -654598054, 1762451694, 1842216281,
|
||||
1619975040, 1682949687, 2047383090, 2127137669, 1938468188, 2001449195, 1325665622, 1271206113, 1183200824, 1111960463,
|
||||
1543535498, 1489069629, 1434599652, 1363369299, 622672798, 568075817, 748617968, 677256519, 907627842, 853037301,
|
||||
1067152940, 995781531, 51762726, 131386257, 177728840, 240578815, 269590778, 349224269, 429104020, 491947555,
|
||||
-248556018, -168932423, -122852000, -60002089, -500490030, -420856475, -341238852, -278395381, -685261898, -739858943,
|
||||
-559578920, -630940305, -1004286614, -1058877219, -845023740, -916395085, -1119974018, -1174433591, -1262701040, -1333941337,
|
||||
-1371866206, -1426332139, -1481064244, -1552294533, -1690935098, -1611170447, -1833673816, -1770699233, -2009983462, -1930228819,
|
||||
-2119160460, -2056179517, 1569362073, 1498123566, 1409854455, 1355396672, 1317987909, 1246755826, 1192025387, 1137557660,
|
||||
2072149281, 2135122070, 1912620623, 1992383480, 1753615357, 1816598090, 1627664531, 1707420964, 295390185, 358241886,
|
||||
404320391, 483945776, 43990325, 106832002, 186451547, 266083308, 932423249, 861060070, 1041341759, 986742920,
|
||||
613929101, 542559546, 756411363, 701822548, -978770311, -1050133554, -869589737, -924188512, -693284699, -764654318,
|
||||
-550540341, -605129092, -475935807, -413084042, -366743377, -287118056, -257573603, -194731862, -114850189, -35218492,
|
||||
-1984365303, -1921392450, -2143631769, -2063868976, -1698919467, -1635936670, -1824608069, -1744851700, -1347415887, -1418654458,
|
||||
-1506661409, -1561119128, -1129027987, -1200260134, -1254728445, -1309196108
|
||||
};
|
||||
|
||||
internal int globalCrc;
|
||||
|
||||
public CRC()
|
||||
{
|
||||
InitialiseCRC();
|
||||
}
|
||||
|
||||
internal void InitialiseCRC()
|
||||
{
|
||||
globalCrc = -1;
|
||||
}
|
||||
|
||||
internal int GetFinalCRC()
|
||||
{
|
||||
return ~globalCrc;
|
||||
}
|
||||
|
||||
internal int GetGlobalCRC()
|
||||
{
|
||||
return globalCrc;
|
||||
}
|
||||
|
||||
internal void SetGlobalCRC(int newCrc)
|
||||
{
|
||||
globalCrc = newCrc;
|
||||
}
|
||||
|
||||
internal void UpdateCRC(int inCh)
|
||||
{
|
||||
int num = (globalCrc >> 24) ^ inCh;
|
||||
if (num < 0)
|
||||
{
|
||||
num = 256 + num;
|
||||
}
|
||||
globalCrc = (globalCrc << 8) ^ crc32Table[num];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user