|
|
@ -269,7 +269,7 @@ var RD = { //rep decode
|
|
|
|
var rBuffer;
|
|
|
|
var rBuffer;
|
|
|
|
|
|
|
|
|
|
|
|
// read in Huffman tables for RAR
|
|
|
|
// read in Huffman tables for RAR
|
|
|
|
function RarReadTables(bstream) {
|
|
|
|
function rarReadTables(bstream) {
|
|
|
|
var BitLength = new Array(rBC),
|
|
|
|
var BitLength = new Array(rBC),
|
|
|
|
Table = new Array(rHuffTableSize);
|
|
|
|
Table = new Array(rHuffTableSize);
|
|
|
|
var i;
|
|
|
|
var i;
|
|
|
@ -480,7 +480,7 @@ function Unpack20(bstream) { //, Solid) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (num < 270) {
|
|
|
|
if (num < 270) {
|
|
|
|
var Distance = rSDDecode[num -= 261] + 1;
|
|
|
|
Distance = rSDDecode[num -= 261] + 1;
|
|
|
|
if ((Bits = rSDBits[num]) > 0) {
|
|
|
|
if ((Bits = rSDBits[num]) > 0) {
|
|
|
|
Distance += bstream.readBits(Bits);
|
|
|
|
Distance += bstream.readBits(Bits);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -513,9 +513,9 @@ function rarReadTables20(bstream) {
|
|
|
|
var BitLength = new Array(rBC20);
|
|
|
|
var BitLength = new Array(rBC20);
|
|
|
|
var Table = new Array(rMC20 * 4);
|
|
|
|
var Table = new Array(rMC20 * 4);
|
|
|
|
var TableSize, N, I;
|
|
|
|
var TableSize, N, I;
|
|
|
|
|
|
|
|
var i;
|
|
|
|
bstream.readBits(1);
|
|
|
|
bstream.readBits(1);
|
|
|
|
if (!bstream.readBits(1)) {
|
|
|
|
if (!bstream.readBits(1)) {
|
|
|
|
var i;
|
|
|
|
|
|
|
|
for (i = UnpOldTable20.length; i--;) UnpOldTable20[i] = 0;
|
|
|
|
for (i = UnpOldTable20.length; i--;) UnpOldTable20[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TableSize = rNC20 + rDC20 + rRC20;
|
|
|
|
TableSize = rNC20 + rDC20 + rRC20;
|
|
|
@ -553,12 +553,13 @@ function rarReadTables20(bstream) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Unpack29(bstream, Solid) {
|
|
|
|
function Unpack29(bstream) {
|
|
|
|
// lazy initialize rDDecode and rDBits
|
|
|
|
// lazy initialize rDDecode and rDBits
|
|
|
|
|
|
|
|
|
|
|
|
var DDecode = new Array(rDC);
|
|
|
|
var DDecode = new Array(rDC);
|
|
|
|
var DBits = new Array(rDC);
|
|
|
|
var DBits = new Array(rDC);
|
|
|
|
|
|
|
|
var Distance = 0;
|
|
|
|
|
|
|
|
var Length = 0;
|
|
|
|
var Dist = 0, BitLength = 0, Slot = 0;
|
|
|
|
var Dist = 0, BitLength = 0, Slot = 0;
|
|
|
|
var I;
|
|
|
|
var I;
|
|
|
|
for (I = 0; I < rDBitLengthCounts.length; I++, BitLength++) {
|
|
|
|
for (I = 0; I < rDBitLengthCounts.length; I++, BitLength++) {
|
|
|
@ -571,7 +572,7 @@ function Unpack29(bstream, Solid) {
|
|
|
|
var Bits;
|
|
|
|
var Bits;
|
|
|
|
//tablesRead = false;
|
|
|
|
//tablesRead = false;
|
|
|
|
|
|
|
|
|
|
|
|
rOldDist = [0, 0, 0, 0]
|
|
|
|
rOldDist = [0, 0, 0, 0];
|
|
|
|
|
|
|
|
|
|
|
|
lastDist = 0;
|
|
|
|
lastDist = 0;
|
|
|
|
lastLength = 0;
|
|
|
|
lastLength = 0;
|
|
|
@ -579,7 +580,7 @@ function Unpack29(bstream, Solid) {
|
|
|
|
for (i = UnpOldTable.length; i--;) UnpOldTable[i] = 0;
|
|
|
|
for (i = UnpOldTable.length; i--;) UnpOldTable[i] = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// read in Huffman tables
|
|
|
|
// read in Huffman tables
|
|
|
|
RarReadTables(bstream);
|
|
|
|
rarReadTables(bstream);
|
|
|
|
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
while (true) {
|
|
|
|
var num = rarDecodeNumber(bstream, LD);
|
|
|
|
var num = rarDecodeNumber(bstream, LD);
|
|
|
@ -589,12 +590,12 @@ function Unpack29(bstream, Solid) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (num >= 271) {
|
|
|
|
if (num >= 271) {
|
|
|
|
var Length = rLDecode[num -= 271] + 3;
|
|
|
|
Length = rLDecode[num -= 271] + 3;
|
|
|
|
if ((Bits = rLBits[num]) > 0) {
|
|
|
|
if ((Bits = rLBits[num]) > 0) {
|
|
|
|
Length += bstream.readBits(Bits);
|
|
|
|
Length += bstream.readBits(Bits);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var DistNumber = rarDecodeNumber(bstream, DD);
|
|
|
|
var DistNumber = rarDecodeNumber(bstream, DD);
|
|
|
|
var Distance = DDecode[DistNumber]+1;
|
|
|
|
Distance = DDecode[DistNumber] + 1;
|
|
|
|
if ((Bits = DBits[DistNumber]) > 0) {
|
|
|
|
if ((Bits = DBits[DistNumber]) > 0) {
|
|
|
|
if (DistNumber > 9) {
|
|
|
|
if (DistNumber > 9) {
|
|
|
|
if (Bits > 4) {
|
|
|
|
if (Bits > 4) {
|
|
|
@ -625,18 +626,18 @@ function Unpack29(bstream, Solid) {
|
|
|
|
Length++;
|
|
|
|
Length++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RarInsertOldDist(Distance);
|
|
|
|
rarInsertOldDist(Distance);
|
|
|
|
RarInsertLastMatch(Length, Distance);
|
|
|
|
rarInsertLastMatch(Length, Distance);
|
|
|
|
rarCopyString(Length, Distance);
|
|
|
|
rarCopyString(Length, Distance);
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (num === 256) {
|
|
|
|
if (num === 256) {
|
|
|
|
if (!RarReadEndOfBlock(bstream)) break;
|
|
|
|
if (!rarReadEndOfBlock(bstream)) break;
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (num === 257) {
|
|
|
|
if (num === 257) {
|
|
|
|
//console.log("READVMCODE");
|
|
|
|
//console.log("READVMCODE");
|
|
|
|
if (!RarReadVMCode(bstream)) break;
|
|
|
|
if (!rarReadVMCode(bstream)) break;
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (num === 258) {
|
|
|
|
if (num === 258) {
|
|
|
@ -647,7 +648,7 @@ function Unpack29(bstream, Solid) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (num < 263) {
|
|
|
|
if (num < 263) {
|
|
|
|
var DistNum = num - 259;
|
|
|
|
var DistNum = num - 259;
|
|
|
|
var Distance = rOldDist[DistNum];
|
|
|
|
Distance = rOldDist[DistNum];
|
|
|
|
|
|
|
|
|
|
|
|
for (var I = DistNum; I > 0; I--) {
|
|
|
|
for (var I = DistNum; I > 0; I--) {
|
|
|
|
rOldDist[I] = rOldDist[I - 1];
|
|
|
|
rOldDist[I] = rOldDist[I - 1];
|
|
|
@ -655,21 +656,21 @@ function Unpack29(bstream, Solid) {
|
|
|
|
rOldDist[0] = Distance;
|
|
|
|
rOldDist[0] = Distance;
|
|
|
|
|
|
|
|
|
|
|
|
var LengthNumber = rarDecodeNumber(bstream, RD);
|
|
|
|
var LengthNumber = rarDecodeNumber(bstream, RD);
|
|
|
|
var Length = rLDecode[LengthNumber] + 2;
|
|
|
|
Length = rLDecode[LengthNumber] + 2;
|
|
|
|
if ((Bits = rLBits[LengthNumber]) > 0) {
|
|
|
|
if ((Bits = rLBits[LengthNumber]) > 0) {
|
|
|
|
Length += bstream.readBits(Bits);
|
|
|
|
Length += bstream.readBits(Bits);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RarInsertLastMatch(Length, Distance);
|
|
|
|
rarInsertLastMatch(Length, Distance);
|
|
|
|
rarCopyString(Length, Distance);
|
|
|
|
rarCopyString(Length, Distance);
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (num < 272) {
|
|
|
|
if (num < 272) {
|
|
|
|
var Distance = rSDDecode[num -= 263] + 1;
|
|
|
|
Distance = rSDDecode[num -= 263] + 1;
|
|
|
|
if ((Bits = rSDBits[num]) > 0) {
|
|
|
|
if ((Bits = rSDBits[num]) > 0) {
|
|
|
|
Distance += bstream.readBits(Bits);
|
|
|
|
Distance += bstream.readBits(Bits);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RarInsertOldDist(Distance);
|
|
|
|
rarInsertOldDist(Distance);
|
|
|
|
RarInsertLastMatch(2, Distance);
|
|
|
|
rarInsertLastMatch(2, Distance);
|
|
|
|
rarCopyString(2, Distance);
|
|
|
|
rarCopyString(2, Distance);
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -677,9 +678,9 @@ function Unpack29(bstream, Solid) {
|
|
|
|
rarUpdateProgress()
|
|
|
|
rarUpdateProgress()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function RarReadEndOfBlock(bstream) {
|
|
|
|
function rarReadEndOfBlock(bstream) {
|
|
|
|
|
|
|
|
|
|
|
|
rarUpdateProgress()
|
|
|
|
rarUpdateProgress();
|
|
|
|
|
|
|
|
|
|
|
|
var NewTable = false, NewFile = false;
|
|
|
|
var NewTable = false, NewFile = false;
|
|
|
|
if (bstream.readBits(1)) {
|
|
|
|
if (bstream.readBits(1)) {
|
|
|
@ -689,11 +690,11 @@ function RarReadEndOfBlock(bstream) {
|
|
|
|
NewTable = !!bstream.readBits(1);
|
|
|
|
NewTable = !!bstream.readBits(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//tablesRead = !NewTable;
|
|
|
|
//tablesRead = !NewTable;
|
|
|
|
return !(NewFile || NewTable && !RarReadTables(bstream));
|
|
|
|
return !(NewFile || NewTable && !rarReadTables(bstream));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function RarReadVMCode(bstream) {
|
|
|
|
function rarReadVMCode(bstream) {
|
|
|
|
var FirstByte = bstream.readBits(8);
|
|
|
|
var FirstByte = bstream.readBits(8);
|
|
|
|
var Length = (FirstByte & 7) + 1;
|
|
|
|
var Length = (FirstByte & 7) + 1;
|
|
|
|
if (Length === 7) {
|
|
|
|
if (Length === 7) {
|
|
|
@ -717,12 +718,12 @@ function RarAddVMCode(firstByte, vmCode, length) {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function RarInsertLastMatch(length, distance) {
|
|
|
|
function rarInsertLastMatch(length, distance) {
|
|
|
|
lastDist = distance;
|
|
|
|
lastDist = distance;
|
|
|
|
lastLength = length;
|
|
|
|
lastLength = length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function RarInsertOldDist(distance) {
|
|
|
|
function rarInsertOldDist(distance) {
|
|
|
|
rOldDist.splice(3,1);
|
|
|
|
rOldDist.splice(3,1);
|
|
|
|
rOldDist.splice(0,0,distance);
|
|
|
|
rOldDist.splice(0,0,distance);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -768,7 +769,7 @@ function unpack(v) {
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 29: // rar 3.x compression
|
|
|
|
case 29: // rar 3.x compression
|
|
|
|
case 36: // alternative hash
|
|
|
|
case 36: // alternative hash
|
|
|
|
Unpack29(bstream, Solid);
|
|
|
|
Unpack29(bstream);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
} // switch(method)
|
|
|
|
} // switch(method)
|
|
|
|
|
|
|
|
|
|
|
|