|
|
@ -41,10 +41,10 @@ var postProgress = function() {
|
|
|
|
// shows a byte value as its hex representation
|
|
|
|
// shows a byte value as its hex representation
|
|
|
|
var nibble = "0123456789ABCDEF";
|
|
|
|
var nibble = "0123456789ABCDEF";
|
|
|
|
var byteValueToHexString = function(num) {
|
|
|
|
var byteValueToHexString = function(num) {
|
|
|
|
return nibble[num>>4] + nibble[num&0xF];
|
|
|
|
return nibble[num >> 4] + nibble[num & 0xF];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
var twoByteValueToHexString = function(num) {
|
|
|
|
var twoByteValueToHexString = function(num) {
|
|
|
|
return nibble[(num>>12)&0xF] + nibble[(num>>8)&0xF] + nibble[(num>>4)&0xF] + nibble[num&0xF];
|
|
|
|
return nibble[(num >> 12) & 0xF] + nibble[(num >> 8) & 0xF] + nibble[(num >> 4) & 0xF] + nibble[num & 0xF];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -69,7 +69,7 @@ var MARK_HEAD = 0x72,
|
|
|
|
var RarVolumeHeader = function(bstream) {
|
|
|
|
var RarVolumeHeader = function(bstream) {
|
|
|
|
var headPos = bstream.bytePtr;
|
|
|
|
var headPos = bstream.bytePtr;
|
|
|
|
// byte 1,2
|
|
|
|
// byte 1,2
|
|
|
|
info("Rar Volume Header @"+bstream.bytePtr);
|
|
|
|
info("Rar Volume Header @" + bstream.bytePtr);
|
|
|
|
|
|
|
|
|
|
|
|
this.crc = bstream.readBits(16);
|
|
|
|
this.crc = bstream.readBits(16);
|
|
|
|
info(" crc=" + this.crc);
|
|
|
|
info(" crc=" + this.crc);
|
|
|
@ -180,13 +180,13 @@ var RarVolumeHeader = function(bstream) {
|
|
|
|
|
|
|
|
|
|
|
|
// this is adapted straight out of arcread.cpp, Archive::ReadHeader()
|
|
|
|
// this is adapted straight out of arcread.cpp, Archive::ReadHeader()
|
|
|
|
for (var I = 0; I < 4; ++I) {
|
|
|
|
for (var I = 0; I < 4; ++I) {
|
|
|
|
var rmode = extTimeFlags >> ((3-I)*4);
|
|
|
|
var rmode = extTimeFlags >> ((3 - I) * 4);
|
|
|
|
if ((rmode & 8)==0) {
|
|
|
|
if ((rmode & 8) == 0) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (I!=0)
|
|
|
|
if (I != 0)
|
|
|
|
bstream.readBits(16);
|
|
|
|
bstream.readBits(16);
|
|
|
|
var count = (rmode&3);
|
|
|
|
var count = (rmode & 3);
|
|
|
|
for (var J = 0; J < count; ++J) {
|
|
|
|
for (var J = 0; J < count; ++J) {
|
|
|
|
bstream.readBits(8);
|
|
|
|
bstream.readBits(8);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -208,7 +208,7 @@ var RarVolumeHeader = function(bstream) {
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
info("Found a header of type 0x" + byteValueToHexString(this.headType));
|
|
|
|
info("Found a header of type 0x" + byteValueToHexString(this.headType));
|
|
|
|
// skip the rest of the header bytes (for now)
|
|
|
|
// skip the rest of the header bytes (for now)
|
|
|
|
bstream.readBytes( this.headSize - 7 );
|
|
|
|
bstream.readBytes(this.headSize - 7);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -216,21 +216,23 @@ var RarVolumeHeader = function(bstream) {
|
|
|
|
var BLOCK_LZ = 0,
|
|
|
|
var BLOCK_LZ = 0,
|
|
|
|
BLOCK_PPM = 1;
|
|
|
|
BLOCK_PPM = 1;
|
|
|
|
|
|
|
|
|
|
|
|
var rLDecode = [0,1,2,3,4,5,6,7,8,10,12,14,16,20,24,28,32,40,48,56,64,80,96,112,128,160,192,224],
|
|
|
|
var rLDecode = [0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224],
|
|
|
|
rLBits = [0,0,0,0,0,0,0,0,1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5],
|
|
|
|
rLBits = [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5],
|
|
|
|
rDBitLengthCounts = [4,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,14,0,12],
|
|
|
|
rDBitLengthCounts = [4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 14, 0, 12],
|
|
|
|
rSDDecode = [0,4,8,16,32,64,128,192],
|
|
|
|
rSDDecode = [0, 4, 8, 16, 32, 64, 128, 192],
|
|
|
|
rSDBits = [2,2,3, 4, 5, 6, 6, 6];
|
|
|
|
rSDBits = [2, 2, 3, 4, 5, 6, 6, 6];
|
|
|
|
|
|
|
|
|
|
|
|
var rDDecode = [0, 1, 2, 3, 4, 6, 8, 12, 16, 24, 32,
|
|
|
|
var rDDecode = [0, 1, 2, 3, 4, 6, 8, 12, 16, 24, 32,
|
|
|
|
48, 64, 96, 128, 192, 256, 384, 512, 768, 1024, 1536, 2048, 3072,
|
|
|
|
48, 64, 96, 128, 192, 256, 384, 512, 768, 1024, 1536, 2048, 3072,
|
|
|
|
4096, 6144, 8192, 12288, 16384, 24576, 32768, 49152, 65536, 98304,
|
|
|
|
4096, 6144, 8192, 12288, 16384, 24576, 32768, 49152, 65536, 98304,
|
|
|
|
131072, 196608, 262144, 327680, 393216, 458752, 524288, 589824,
|
|
|
|
131072, 196608, 262144, 327680, 393216, 458752, 524288, 589824,
|
|
|
|
655360, 720896, 786432, 851968, 917504, 983040];
|
|
|
|
655360, 720896, 786432, 851968, 917504, 983040
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
var rDBits = [0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5,
|
|
|
|
var rDBits = [0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5,
|
|
|
|
5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14,
|
|
|
|
5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14,
|
|
|
|
15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16];
|
|
|
|
15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
var rLOW_DIST_REP_COUNT = 16;
|
|
|
|
var rLOW_DIST_REP_COUNT = 16;
|
|
|
|
|
|
|
|
|
|
|
@ -239,7 +241,7 @@ var rNC = 299,
|
|
|
|
rLDC = 17,
|
|
|
|
rLDC = 17,
|
|
|
|
rRC = 28,
|
|
|
|
rRC = 28,
|
|
|
|
rBC = 20,
|
|
|
|
rBC = 20,
|
|
|
|
rHUFF_TABLE_SIZE = (rNC+rDC+rRC+rLDC);
|
|
|
|
rHUFF_TABLE_SIZE = (rNC + rDC + rRC + rLDC);
|
|
|
|
|
|
|
|
|
|
|
|
var UnpBlockType = BLOCK_LZ;
|
|
|
|
var UnpBlockType = BLOCK_LZ;
|
|
|
|
var UnpOldTable = new Array(rHUFF_TABLE_SIZE);
|
|
|
|
var UnpOldTable = new Array(rHUFF_TABLE_SIZE);
|
|
|
@ -308,7 +310,7 @@ function RarReadTables(bstream) {
|
|
|
|
var Table = new Array(rHUFF_TABLE_SIZE);
|
|
|
|
var Table = new Array(rHUFF_TABLE_SIZE);
|
|
|
|
|
|
|
|
|
|
|
|
// before we start anything we need to get byte-aligned
|
|
|
|
// before we start anything we need to get byte-aligned
|
|
|
|
bstream.readBits( (8 - bstream.bitPtr) & 0x7 );
|
|
|
|
bstream.readBits((8 - bstream.bitPtr) & 0x7);
|
|
|
|
|
|
|
|
|
|
|
|
if (bstream.readBits(1)) {
|
|
|
|
if (bstream.readBits(1)) {
|
|
|
|
info("Error! PPM not implemented yet");
|
|
|
|
info("Error! PPM not implemented yet");
|
|
|
@ -328,15 +330,13 @@ function RarReadTables(bstream) {
|
|
|
|
var ZeroCount = bstream.readBits(4);
|
|
|
|
var ZeroCount = bstream.readBits(4);
|
|
|
|
if (ZeroCount == 0) {
|
|
|
|
if (ZeroCount == 0) {
|
|
|
|
BitLength[I] = 15;
|
|
|
|
BitLength[I] = 15;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
else {
|
|
|
|
|
|
|
|
ZeroCount += 2;
|
|
|
|
ZeroCount += 2;
|
|
|
|
while (ZeroCount-- > 0 && I < rBC)
|
|
|
|
while (ZeroCount-- > 0 && I < rBC)
|
|
|
|
BitLength[I++] = 0;
|
|
|
|
BitLength[I++] = 0;
|
|
|
|
--I;
|
|
|
|
--I;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
else {
|
|
|
|
|
|
|
|
BitLength[I] = Length;
|
|
|
|
BitLength[I] = Length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -381,26 +381,28 @@ function RarReadTables(bstream) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function RarDecodeNumber(bstream, dec) {
|
|
|
|
function RarDecodeNumber(bstream, dec) {
|
|
|
|
var DecodeLen = dec.DecodeLen, DecodePos = dec.DecodePos, DecodeNum = dec.DecodeNum;
|
|
|
|
var DecodeLen = dec.DecodeLen,
|
|
|
|
|
|
|
|
DecodePos = dec.DecodePos,
|
|
|
|
|
|
|
|
DecodeNum = dec.DecodeNum;
|
|
|
|
var bitField = bstream.getBits() & 0xfffe;
|
|
|
|
var bitField = bstream.getBits() & 0xfffe;
|
|
|
|
//some sort of rolled out binary search
|
|
|
|
//some sort of rolled out binary search
|
|
|
|
var bits = ((bitField < DecodeLen[8])?
|
|
|
|
var bits = ((bitField < DecodeLen[8]) ?
|
|
|
|
((bitField < DecodeLen[4])?
|
|
|
|
((bitField < DecodeLen[4]) ?
|
|
|
|
((bitField < DecodeLen[2])?
|
|
|
|
((bitField < DecodeLen[2]) ?
|
|
|
|
((bitField < DecodeLen[1])?1:2)
|
|
|
|
((bitField < DecodeLen[1]) ? 1 : 2) :
|
|
|
|
:((bitField < DecodeLen[3])?3:4))
|
|
|
|
((bitField < DecodeLen[3]) ? 3 : 4)) :
|
|
|
|
:(bitField < DecodeLen[6])?
|
|
|
|
(bitField < DecodeLen[6]) ?
|
|
|
|
((bitField < DecodeLen[5])?5:6)
|
|
|
|
((bitField < DecodeLen[5]) ? 5 : 6) :
|
|
|
|
:((bitField < DecodeLen[7])?7:8))
|
|
|
|
((bitField < DecodeLen[7]) ? 7 : 8)) :
|
|
|
|
:((bitField < DecodeLen[12])?
|
|
|
|
((bitField < DecodeLen[12]) ?
|
|
|
|
((bitField < DecodeLen[10])?
|
|
|
|
((bitField < DecodeLen[10]) ?
|
|
|
|
((bitField < DecodeLen[9])?9:10)
|
|
|
|
((bitField < DecodeLen[9]) ? 9 : 10) :
|
|
|
|
:((bitField < DecodeLen[11])?11:12))
|
|
|
|
((bitField < DecodeLen[11]) ? 11 : 12)) :
|
|
|
|
:(bitField < DecodeLen[14])?
|
|
|
|
(bitField < DecodeLen[14]) ?
|
|
|
|
((bitField < DecodeLen[13])?13:14)
|
|
|
|
((bitField < DecodeLen[13]) ? 13 : 14) :
|
|
|
|
:15));
|
|
|
|
15));
|
|
|
|
bstream.readBits(bits);
|
|
|
|
bstream.readBits(bits);
|
|
|
|
var N = DecodePos[bits] + ((bitField - DecodeLen[bits -1]) >>> (16 - bits));
|
|
|
|
var N = DecodePos[bits] + ((bitField - DecodeLen[bits - 1]) >>> (16 - bits));
|
|
|
|
|
|
|
|
|
|
|
|
return DecodeNum[N];
|
|
|
|
return DecodeNum[N];
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -410,8 +412,8 @@ function RarMakeDecodeTables(BitLength, offset, dec, size) {
|
|
|
|
var DecodeLen = dec.DecodeLen;
|
|
|
|
var DecodeLen = dec.DecodeLen;
|
|
|
|
var DecodePos = dec.DecodePos;
|
|
|
|
var DecodePos = dec.DecodePos;
|
|
|
|
var DecodeNum = dec.DecodeNum;
|
|
|
|
var DecodeNum = dec.DecodeNum;
|
|
|
|
var LenCount = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
|
|
|
|
var LenCount = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
|
|
var TmpPos = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
|
|
|
|
var TmpPos = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
|
|
var N = 0;
|
|
|
|
var N = 0;
|
|
|
|
var M = 0;
|
|
|
|
var M = 0;
|
|
|
|
|
|
|
|
|
|
|
@ -427,18 +429,18 @@ function RarMakeDecodeTables(BitLength, offset, dec, size) {
|
|
|
|
DecodeLen[0] = 0;
|
|
|
|
DecodeLen[0] = 0;
|
|
|
|
|
|
|
|
|
|
|
|
for (var I = 1; I < 16; ++I) {
|
|
|
|
for (var I = 1; I < 16; ++I) {
|
|
|
|
N = 2 * (N+LenCount[I]);
|
|
|
|
N = 2 * (N + LenCount[I]);
|
|
|
|
M = (N << (15-I));
|
|
|
|
M = (N << (15 - I));
|
|
|
|
if (M > 0xFFFF) {
|
|
|
|
if (M > 0xFFFF) {
|
|
|
|
M = 0xFFFF;
|
|
|
|
M = 0xFFFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DecodeLen[I] = M;
|
|
|
|
DecodeLen[I] = M;
|
|
|
|
DecodePos[I] = DecodePos[I-1] + LenCount[I-1];
|
|
|
|
DecodePos[I] = DecodePos[I - 1] + LenCount[I - 1];
|
|
|
|
TmpPos[I] = DecodePos[I];
|
|
|
|
TmpPos[I] = DecodePos[I];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (I = 0; I < size; ++I) {
|
|
|
|
for (I = 0; I < size; ++I) {
|
|
|
|
if (BitLength[I + offset] != 0) {
|
|
|
|
if (BitLength[I + offset] != 0) {
|
|
|
|
DecodeNum[ TmpPos[ BitLength[offset + I] & 0xF ]++] = I;
|
|
|
|
DecodeNum[TmpPos[BitLength[offset + I] & 0xF]++] = I;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -503,7 +505,7 @@ function Unpack20(bstream, Solid) {
|
|
|
|
if (num < 261) {
|
|
|
|
if (num < 261) {
|
|
|
|
var Distance = rOldDist[(oldDistPtr - (num - 256)) & 3];
|
|
|
|
var Distance = rOldDist[(oldDistPtr - (num - 256)) & 3];
|
|
|
|
var LengthNumber = RarDecodeNumber(bstream, RD);
|
|
|
|
var LengthNumber = RarDecodeNumber(bstream, RD);
|
|
|
|
var Length = rLDecode[LengthNumber] +2;
|
|
|
|
var Length = rLDecode[LengthNumber] + 2;
|
|
|
|
if ((Bits = rLBits[LengthNumber]) > 0) {
|
|
|
|
if ((Bits = rLBits[LengthNumber]) > 0) {
|
|
|
|
Length += bstream.readBits(Bits);
|
|
|
|
Length += bstream.readBits(Bits);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -600,7 +602,7 @@ function RarReadTables20(bstream) {
|
|
|
|
var lowDistRepCount = 0;
|
|
|
|
var lowDistRepCount = 0;
|
|
|
|
var prevLowDist = 0;
|
|
|
|
var prevLowDist = 0;
|
|
|
|
|
|
|
|
|
|
|
|
var rOldDist = [0,0,0,0];
|
|
|
|
var rOldDist = [0, 0, 0, 0];
|
|
|
|
var lastDist;
|
|
|
|
var lastDist;
|
|
|
|
var lastLength;
|
|
|
|
var lastLength;
|
|
|
|
|
|
|
|
|
|
|
@ -644,7 +646,7 @@ function InitFilters() {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function RarAddVMCode(firstByte, vmCode) {
|
|
|
|
function RarAddVMCode(firstByte, vmCode) {
|
|
|
|
VM.init();
|
|
|
|
VM.init();
|
|
|
|
var bstream = new bitjs.io.BitStream(vmCode.buffer, true /* rtl */);
|
|
|
|
var bstream = new bitjs.io.BitStream(vmCode.buffer, true /* rtl */ );
|
|
|
|
|
|
|
|
|
|
|
|
var filtPos;
|
|
|
|
var filtPos;
|
|
|
|
if (firstByte & 0x80) {
|
|
|
|
if (firstByte & 0x80) {
|
|
|
@ -716,9 +718,9 @@ function RarAddVMCode(firstByte, vmCode) {
|
|
|
|
if (firstByte & 0x20) {
|
|
|
|
if (firstByte & 0x20) {
|
|
|
|
stackFilter.BlockLength = RarVM.readData(bstream);
|
|
|
|
stackFilter.BlockLength = RarVM.readData(bstream);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
stackFilter.BlockLength = filtPos < OldFilterLengths.length
|
|
|
|
stackFilter.BlockLength = filtPos < OldFilterLengths.length ?
|
|
|
|
? OldFilterLengths[filtPos]
|
|
|
|
OldFilterLengths[filtPos] :
|
|
|
|
: 0;
|
|
|
|
0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stackFilter.NextWindow = (wBuffer.ptr != rBuffer.ptr) &&
|
|
|
|
stackFilter.NextWindow = (wBuffer.ptr != rBuffer.ptr) &&
|
|
|
|
(((wBuffer.ptr - rBuffer.ptr) & MAXWINMASK) <= blockStart);
|
|
|
|
(((wBuffer.ptr - rBuffer.ptr) & MAXWINMASK) <= blockStart);
|
|
|
@ -788,7 +790,7 @@ function RarAddVMCode(firstByte, vmCode) {
|
|
|
|
// return(false);
|
|
|
|
// return(false);
|
|
|
|
var dataSize = RarVM.readData(bstream);
|
|
|
|
var dataSize = RarVM.readData(bstream);
|
|
|
|
if (dataSize > (VM_GLOBALMEMSIZE - VM_FIXEDGLOBALSIZE)) {
|
|
|
|
if (dataSize > (VM_GLOBALMEMSIZE - VM_FIXEDGLOBALSIZE)) {
|
|
|
|
return(false);
|
|
|
|
return (false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var curSize = stackFilter.Prg.GlobalData.length;
|
|
|
|
var curSize = stackFilter.Prg.GlobalData.length;
|
|
|
@ -849,17 +851,17 @@ function Unpack29(bstream, Solid) {
|
|
|
|
var BitLength = 0;
|
|
|
|
var BitLength = 0;
|
|
|
|
var Slot = 0;
|
|
|
|
var Slot = 0;
|
|
|
|
|
|
|
|
|
|
|
|
for (var I = 0; I < rDBitLengthCounts.length; I++,BitLength++) {
|
|
|
|
for (var I = 0; I < rDBitLengthCounts.length; I++, BitLength++) {
|
|
|
|
for (var J = 0; J < rDBitLengthCounts[I]; J++,Slot++,Dist+=(1<<BitLength)) {
|
|
|
|
for (var J = 0; J < rDBitLengthCounts[I]; J++, Slot++, Dist += (1 << BitLength)) {
|
|
|
|
DDecode[Slot]=Dist;
|
|
|
|
DDecode[Slot] = Dist;
|
|
|
|
DBits[Slot]=BitLength;
|
|
|
|
DBits[Slot] = BitLength;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
@ -943,7 +945,7 @@ function Unpack29(bstream, Solid) {
|
|
|
|
var Distance = rOldDist[DistNum];
|
|
|
|
var 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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rOldDist[0] = Distance;
|
|
|
|
rOldDist[0] = Distance;
|
|
|
|
|
|
|
|
|
|
|
@ -1109,8 +1111,8 @@ function RarWriteBuf() {
|
|
|
|
function RarWriteArea(startPtr, endPtr) {
|
|
|
|
function RarWriteArea(startPtr, endPtr) {
|
|
|
|
if (endPtr < startPtr) {
|
|
|
|
if (endPtr < startPtr) {
|
|
|
|
console.error('endPtr < startPtr, endPtr=' + endPtr + ', startPtr=' + startPtr);
|
|
|
|
console.error('endPtr < startPtr, endPtr=' + endPtr + ', startPtr=' + startPtr);
|
|
|
|
// RarWriteData(startPtr, -(int)StartPtr & MAXWINMASK);
|
|
|
|
// RarWriteData(startPtr, -(int)StartPtr & MAXWINMASK);
|
|
|
|
// RarWriteData(0, endPtr);
|
|
|
|
// RarWriteData(0, endPtr);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
} else if (startPtr < endPtr) {
|
|
|
|
} else if (startPtr < endPtr) {
|
|
|
|
RarWriteData(startPtr, endPtr - startPtr);
|
|
|
|
RarWriteData(startPtr, endPtr - startPtr);
|
|
|
@ -1138,8 +1140,7 @@ function RarWriteData(offset, numBytes) {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @param {VM_PreparedProgram} prg
|
|
|
|
* @param {VM_PreparedProgram} prg
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function RarExecuteCode(prg)
|
|
|
|
function RarExecuteCode(prg) {
|
|
|
|
{
|
|
|
|
|
|
|
|
if (prg.GlobalData.length > 0) {
|
|
|
|
if (prg.GlobalData.length > 0) {
|
|
|
|
var writtenFileSize = wBuffer.ptr;
|
|
|
|
var writtenFileSize = wBuffer.ptr;
|
|
|
|
prg.InitR[6] = writtenFileSize;
|
|
|
|
prg.InitR[6] = writtenFileSize;
|
|
|
@ -1152,7 +1153,8 @@ function RarExecuteCode(prg)
|
|
|
|
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)) {
|
|
|
|
NewTable = true;
|
|
|
|
NewTable = true;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -1169,8 +1171,8 @@ function RarInsertLastMatch(length, distance) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function RarInsertOldDist(distance) {
|
|
|
|
function RarInsertOldDist(distance) {
|
|
|
|
rOldDist.splice(3,1);
|
|
|
|
rOldDist.splice(3, 1);
|
|
|
|
rOldDist.splice(0,0,distance);
|
|
|
|
rOldDist.splice(0, 0, distance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -1208,7 +1210,7 @@ function unpack(v) {
|
|
|
|
// TODO: implement what happens when unpVer is < 15
|
|
|
|
// TODO: implement what happens when unpVer is < 15
|
|
|
|
var Ver = v.header.unpVer <= 15 ? 15 : v.header.unpVer;
|
|
|
|
var Ver = v.header.unpVer <= 15 ? 15 : v.header.unpVer;
|
|
|
|
var Solid = v.header.LHD_SOLID;
|
|
|
|
var Solid = v.header.LHD_SOLID;
|
|
|
|
var bstream = new bitjs.io.BitStream(v.fileData.buffer, true /* rtl */, v.fileData.byteOffset, v.fileData.byteLength );
|
|
|
|
var bstream = new bitjs.io.BitStream(v.fileData.buffer, true /* rtl */ , v.fileData.byteOffset, v.fileData.byteLength);
|
|
|
|
|
|
|
|
|
|
|
|
rBuffer = new bitjs.io.ByteBuffer(v.header.unpackedSize);
|
|
|
|
rBuffer = new bitjs.io.ByteBuffer(v.header.unpackedSize);
|
|
|
|
|
|
|
|
|
|
|
@ -1242,8 +1244,7 @@ var RarLocalFile = function(bstream) {
|
|
|
|
if (this.header.headType != FILE_HEAD && this.header.headType != ENDARC_HEAD) {
|
|
|
|
if (this.header.headType != FILE_HEAD && this.header.headType != ENDARC_HEAD) {
|
|
|
|
this.isValid = false;
|
|
|
|
this.isValid = false;
|
|
|
|
info("Error! RAR Volume did not include a FILE_HEAD header ");
|
|
|
|
info("Error! RAR Volume did not include a FILE_HEAD header ");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
else {
|
|
|
|
|
|
|
|
// read in the compressed data
|
|
|
|
// read in the compressed data
|
|
|
|
this.fileData = null;
|
|
|
|
this.fileData = null;
|
|
|
|
if (this.header.packSize > 0) {
|
|
|
|
if (this.header.packSize > 0) {
|
|
|
@ -1257,7 +1258,7 @@ RarLocalFile.prototype.unrar = function() {
|
|
|
|
if (!this.header.flags.LHD_SPLIT_BEFORE) {
|
|
|
|
if (!this.header.flags.LHD_SPLIT_BEFORE) {
|
|
|
|
// unstore file
|
|
|
|
// unstore file
|
|
|
|
if (this.header.method == 0x30) {
|
|
|
|
if (this.header.method == 0x30) {
|
|
|
|
info("Unstore "+this.filename);
|
|
|
|
info("Unstore " + this.filename);
|
|
|
|
this.isValid = true;
|
|
|
|
this.isValid = true;
|
|
|
|
|
|
|
|
|
|
|
|
currentBytesUnarchivedInFile += this.fileData.length;
|
|
|
|
currentBytesUnarchivedInFile += this.fileData.length;
|
|
|
@ -1284,7 +1285,7 @@ var unrar = function(arrayBuffer) {
|
|
|
|
totalFilesInArchive = 0;
|
|
|
|
totalFilesInArchive = 0;
|
|
|
|
|
|
|
|
|
|
|
|
postMessage(new bitjs.archive.UnarchiveStartEvent());
|
|
|
|
postMessage(new bitjs.archive.UnarchiveStartEvent());
|
|
|
|
var bstream = new bitjs.io.BitStream(arrayBuffer, false /* rtl */);
|
|
|
|
var bstream = new bitjs.io.BitStream(arrayBuffer, false /* rtl */ );
|
|
|
|
|
|
|
|
|
|
|
|
var header = new RarVolumeHeader(bstream);
|
|
|
|
var header = new RarVolumeHeader(bstream);
|
|
|
|
if (header.crc == 0x6152 &&
|
|
|
|
if (header.crc == 0x6152 &&
|
|
|
@ -1296,8 +1297,7 @@ var unrar = function(arrayBuffer) {
|
|
|
|
var mhead = new RarVolumeHeader(bstream);
|
|
|
|
var mhead = new RarVolumeHeader(bstream);
|
|
|
|
if (mhead.headType != MAIN_HEAD) {
|
|
|
|
if (mhead.headType != MAIN_HEAD) {
|
|
|
|
info("Error! RAR did not include a MAIN_HEAD header");
|
|
|
|
info("Error! RAR did not include a MAIN_HEAD header");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
else {
|
|
|
|
|
|
|
|
var localFiles = [],
|
|
|
|
var localFiles = [],
|
|
|
|
localFile = null;
|
|
|
|
localFile = null;
|
|
|
|
do {
|
|
|
|
do {
|
|
|
@ -1310,7 +1310,7 @@ var unrar = function(arrayBuffer) {
|
|
|
|
} else if (localFile.header.packSize == 0 && localFile.header.unpackedSize == 0) {
|
|
|
|
} else if (localFile.header.packSize == 0 && localFile.header.unpackedSize == 0) {
|
|
|
|
localFile.isValid = true;
|
|
|
|
localFile.isValid = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch(err) {
|
|
|
|
} catch (err) {
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//info("bstream" + bstream.bytePtr+"/"+bstream.bytes.length);
|
|
|
|
//info("bstream" + bstream.bytePtr+"/"+bstream.bytes.length);
|
|
|
@ -1319,13 +1319,15 @@ var unrar = function(arrayBuffer) {
|
|
|
|
|
|
|
|
|
|
|
|
// now we have all information but things are unpacked
|
|
|
|
// now we have all information but things are unpacked
|
|
|
|
// TODO: unpack
|
|
|
|
// TODO: unpack
|
|
|
|
localFiles = localFiles.sort(function(a,b) {
|
|
|
|
localFiles = localFiles.sort(function(a, b) {
|
|
|
|
var aname = a.filename.toLowerCase();
|
|
|
|
var aname = a.filename.toLowerCase();
|
|
|
|
var bname = b.filename.toLowerCase();
|
|
|
|
var bname = b.filename.toLowerCase();
|
|
|
|
return aname > bname ? 1 : -1;
|
|
|
|
return aname > bname ? 1 : -1;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
info(localFiles.map(function(a){return a.filename}).join(', '));
|
|
|
|
info(localFiles.map(function(a) {
|
|
|
|
|
|
|
|
return a.filename
|
|
|
|
|
|
|
|
}).join(', '));
|
|
|
|
for (var i = 0; i < localFiles.length; ++i) {
|
|
|
|
for (var i = 0; i < localFiles.length; ++i) {
|
|
|
|
var localfile = localFiles[i];
|
|
|
|
var localfile = localFiles[i];
|
|
|
|
|
|
|
|
|
|
|
@ -1344,8 +1346,7 @@ var unrar = function(arrayBuffer) {
|
|
|
|
|
|
|
|
|
|
|
|
postProgress();
|
|
|
|
postProgress();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
else {
|
|
|
|
|
|
|
|
err("Invalid RAR file");
|
|
|
|
err("Invalid RAR file");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
postMessage(new bitjs.archive.UnarchiveFinishEvent());
|
|
|
|
postMessage(new bitjs.archive.UnarchiveFinishEvent());
|
|
|
|