mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-17 08:11:49 -06:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e24f7fba53 | ||
|
|
7c8a265a15 | ||
|
|
a663a6deb7 | ||
|
|
6543c28020 | ||
|
|
f6444c3256 | ||
|
|
cba375916f |
@@ -1,5 +1,5 @@
|
||||
/* 7zAlloc.c -- Allocation functions
|
||||
2015-02-21 : Igor Pavlov : Public domain */
|
||||
2015-11-09 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
@@ -26,7 +26,7 @@ void *SzAlloc(void *p, size_t size)
|
||||
if (size == 0)
|
||||
return 0;
|
||||
#ifdef _SZ_ALLOC_DEBUG
|
||||
fprintf(stderr, "\nAlloc %10d bytes; count = %10d", size, g_allocCount);
|
||||
fprintf(stderr, "\nAlloc %10u bytes; count = %10d", (unsigned)size, g_allocCount);
|
||||
g_allocCount++;
|
||||
#endif
|
||||
return malloc(size);
|
||||
@@ -51,7 +51,7 @@ void *SzAllocTemp(void *p, size_t size)
|
||||
if (size == 0)
|
||||
return 0;
|
||||
#ifdef _SZ_ALLOC_DEBUG
|
||||
fprintf(stderr, "\nAlloc_temp %10d bytes; count = %10d", size, g_allocCountTemp);
|
||||
fprintf(stderr, "\nAlloc_temp %10u bytes; count = %10d", (unsigned)size, g_allocCountTemp);
|
||||
g_allocCountTemp++;
|
||||
#ifdef _WIN32
|
||||
return HeapAlloc(GetProcessHeap(), 0, size);
|
||||
|
||||
65
C/7zArcIn.c
65
C/7zArcIn.c
@@ -1,5 +1,5 @@
|
||||
/* 7zArcIn.c -- 7z Input functions
|
||||
2015-05-16 : Igor Pavlov : Public domain */
|
||||
2015-11-13 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
@@ -942,7 +942,6 @@ typedef struct
|
||||
static SRes ReadSubStreamsInfo(CSzAr *p, CSzData *sd, CSubStreamInfo *ssi)
|
||||
{
|
||||
UInt64 type = 0;
|
||||
UInt32 i;
|
||||
UInt32 numSubDigests = 0;
|
||||
UInt32 numFolders = p->NumFolders;
|
||||
UInt32 numUnpackStreams = numFolders;
|
||||
@@ -953,6 +952,7 @@ static SRes ReadSubStreamsInfo(CSzAr *p, CSzData *sd, CSubStreamInfo *ssi)
|
||||
RINOK(ReadID(sd, &type));
|
||||
if (type == k7zIdNumUnpackStream)
|
||||
{
|
||||
UInt32 i;
|
||||
ssi->sdNumSubStreams.Data = sd->Data;
|
||||
numUnpackStreams = 0;
|
||||
numSubDigests = 0;
|
||||
@@ -1215,7 +1215,6 @@ static SRes SzReadHeader2(
|
||||
UInt64 type;
|
||||
UInt32 numFiles = 0;
|
||||
UInt32 numEmptyStreams = 0;
|
||||
UInt32 i;
|
||||
CSubStreamInfo ssi;
|
||||
const Byte *emptyStreams = 0;
|
||||
const Byte *emptyFiles = 0;
|
||||
@@ -1295,7 +1294,7 @@ static SRes SzReadHeader2(
|
||||
{
|
||||
SKIP_DATA(sd, size);
|
||||
}
|
||||
else switch((unsigned)type)
|
||||
else switch ((unsigned)type)
|
||||
{
|
||||
case k7zIdName:
|
||||
{
|
||||
@@ -1397,22 +1396,22 @@ static SRes SzReadHeader2(
|
||||
}
|
||||
|
||||
{
|
||||
UInt32 i;
|
||||
UInt32 emptyFileIndex = 0;
|
||||
|
||||
UInt32 folderIndex = 0;
|
||||
UInt32 indexInFolder = 0;
|
||||
UInt32 remSubStreams = 0;
|
||||
UInt32 numSubStreams = 0;
|
||||
UInt64 unpackPos = 0;
|
||||
const Byte *digestsDefs = 0;
|
||||
const Byte *digestsVals = 0;
|
||||
UInt32 digestsValsIndex = 0;
|
||||
UInt32 digestIndex;
|
||||
Byte allDigestsDefined = 0;
|
||||
UInt32 curNumSubStreams = (UInt32)(Int32)-1;
|
||||
Byte isDirMask = 0;
|
||||
Byte crcMask = 0;
|
||||
Byte mask = 0x80;
|
||||
// size_t unpSizesOffset = 0;
|
||||
CSzData sdCodersUnpSizes;
|
||||
|
||||
sdCodersUnpSizes.Data = p->db.UnpackSizesData;
|
||||
sdCodersUnpSizes.Size = p->db.UnpackSizesDataSize;
|
||||
|
||||
@@ -1437,6 +1436,7 @@ static SRes SzReadHeader2(
|
||||
}
|
||||
|
||||
digestIndex = 0;
|
||||
|
||||
for (i = 0; i < numFiles; i++, mask >>= 1)
|
||||
{
|
||||
if (mask == 0)
|
||||
@@ -1451,49 +1451,45 @@ static SRes SzReadHeader2(
|
||||
|
||||
p->UnpackPositions[i] = unpackPos;
|
||||
p->CRCs.Vals[i] = 0;
|
||||
// p->CRCs.Defs[i] = 0;
|
||||
if (emptyStreams && SzBitArray_Check(emptyStreams , i))
|
||||
|
||||
if (emptyStreams && SzBitArray_Check(emptyStreams, i))
|
||||
{
|
||||
if (!emptyFiles || !SzBitArray_Check(emptyFiles, emptyFileIndex))
|
||||
isDirMask |= mask;
|
||||
emptyFileIndex++;
|
||||
if (indexInFolder == 0)
|
||||
if (remSubStreams == 0)
|
||||
{
|
||||
p->FileIndexToFolderIndexMap[i] = (UInt32)-1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (indexInFolder == 0)
|
||||
|
||||
if (remSubStreams == 0)
|
||||
{
|
||||
/*
|
||||
v3.13 incorrectly worked with empty folders
|
||||
v4.07: Loop for skipping empty folders
|
||||
*/
|
||||
for (;;)
|
||||
{
|
||||
if (folderIndex >= p->db.NumFolders)
|
||||
return SZ_ERROR_ARCHIVE;
|
||||
p->FolderStartFileIndex[folderIndex] = i;
|
||||
if (curNumSubStreams == (UInt32)(Int32)-1);
|
||||
numSubStreams = 1;
|
||||
if (ssi.sdNumSubStreams.Data)
|
||||
{
|
||||
curNumSubStreams = 1;
|
||||
if (ssi.sdNumSubStreams.Data != 0)
|
||||
{
|
||||
RINOK(SzReadNumber32(&ssi.sdNumSubStreams, &curNumSubStreams));
|
||||
}
|
||||
RINOK(SzReadNumber32(&ssi.sdNumSubStreams, &numSubStreams));
|
||||
}
|
||||
if (curNumSubStreams != 0)
|
||||
remSubStreams = numSubStreams;
|
||||
if (numSubStreams != 0)
|
||||
break;
|
||||
curNumSubStreams = (UInt32)(Int32)-1;
|
||||
folderIndex++; // check it
|
||||
p->db.FoSizesOffsets[folderIndex] = sdCodersUnpSizes.Data - p->db.UnpackSizesData;
|
||||
folderIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
p->FileIndexToFolderIndexMap[i] = folderIndex;
|
||||
if (emptyStreams && SzBitArray_Check(emptyStreams , i))
|
||||
|
||||
if (emptyStreams && SzBitArray_Check(emptyStreams, i))
|
||||
continue;
|
||||
|
||||
indexInFolder++;
|
||||
if (indexInFolder >= curNumSubStreams)
|
||||
if (--remSubStreams == 0)
|
||||
{
|
||||
UInt64 folderUnpackSize = 0;
|
||||
UInt64 startFolderUnpackPos;
|
||||
@@ -1523,7 +1519,7 @@ static SRes SzReadHeader2(
|
||||
return SZ_ERROR_ARCHIVE;
|
||||
unpackPos = startFolderUnpackPos + folderUnpackSize;
|
||||
|
||||
if (curNumSubStreams == 1 && SzBitWithVals_Check(&p->db.FolderCRCs, i))
|
||||
if (numSubStreams == 1 && SzBitWithVals_Check(&p->db.FolderCRCs, i))
|
||||
{
|
||||
p->CRCs.Vals[i] = p->db.FolderCRCs.Vals[folderIndex];
|
||||
crcMask |= mask;
|
||||
@@ -1534,14 +1530,16 @@ static SRes SzReadHeader2(
|
||||
digestsValsIndex++;
|
||||
crcMask |= mask;
|
||||
}
|
||||
|
||||
folderIndex++;
|
||||
indexInFolder = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
UInt64 v;
|
||||
RINOK(ReadNumber(&ssi.sdSizes, &v));
|
||||
unpackPos += v;
|
||||
if (unpackPos < v)
|
||||
return SZ_ERROR_ARCHIVE;
|
||||
if (allDigestsDefined || (digestsDefs && SzBitArray_Check(digestsDefs, digestIndex)))
|
||||
{
|
||||
p->CRCs.Vals[i] = GetUi32(digestsVals + (size_t)digestsValsIndex * 4);
|
||||
@@ -1550,12 +1548,14 @@ static SRes SzReadHeader2(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mask != 0x80)
|
||||
{
|
||||
UInt32 byteIndex = (i - 1) >> 3;
|
||||
p->IsDirs[byteIndex] = isDirMask;
|
||||
p->CRCs.Defs[byteIndex] = crcMask;
|
||||
}
|
||||
|
||||
p->UnpackPositions[i] = unpackPos;
|
||||
p->FolderStartFileIndex[folderIndex] = i;
|
||||
p->db.FoSizesOffsets[folderIndex] = sdCodersUnpSizes.Data - p->db.UnpackSizesData;
|
||||
@@ -1567,9 +1567,8 @@ static SRes SzReadHeader(
|
||||
CSzArEx *p,
|
||||
CSzData *sd,
|
||||
ILookInStream *inStream,
|
||||
ISzAlloc *allocMain
|
||||
,ISzAlloc *allocTemp
|
||||
)
|
||||
ISzAlloc *allocMain,
|
||||
ISzAlloc *allocTemp)
|
||||
{
|
||||
// Byte *emptyStreamVector = 0;
|
||||
// Byte *emptyFileVector = 0;
|
||||
|
||||
14
C/7zDec.c
14
C/7zDec.c
@@ -1,5 +1,5 @@
|
||||
/* 7zDec.c -- Decoding from 7z folder
|
||||
2015-06-13 : Igor Pavlov : Public domain */
|
||||
2015-08-01 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
@@ -144,11 +144,11 @@ static SRes SzDecodeLzma(const Byte *props, unsigned propsSize, UInt64 inSize, I
|
||||
|
||||
for (;;)
|
||||
{
|
||||
Byte *inBuf = NULL;
|
||||
const void *inBuf = NULL;
|
||||
size_t lookahead = (1 << 18);
|
||||
if (lookahead > inSize)
|
||||
lookahead = (size_t)inSize;
|
||||
res = inStream->Look((void *)inStream, (const void **)&inBuf, &lookahead);
|
||||
res = inStream->Look(inStream, &inBuf, &lookahead);
|
||||
if (res != SZ_OK)
|
||||
break;
|
||||
|
||||
@@ -197,11 +197,11 @@ static SRes SzDecodeLzma2(const Byte *props, unsigned propsSize, UInt64 inSize,
|
||||
|
||||
for (;;)
|
||||
{
|
||||
Byte *inBuf = NULL;
|
||||
const void *inBuf = NULL;
|
||||
size_t lookahead = (1 << 18);
|
||||
if (lookahead > inSize)
|
||||
lookahead = (size_t)inSize;
|
||||
res = inStream->Look((void *)inStream, (const void **)&inBuf, &lookahead);
|
||||
res = inStream->Look(inStream, &inBuf, &lookahead);
|
||||
if (res != SZ_OK)
|
||||
break;
|
||||
|
||||
@@ -237,11 +237,11 @@ static SRes SzDecodeCopy(UInt64 inSize, ILookInStream *inStream, Byte *outBuffer
|
||||
{
|
||||
while (inSize > 0)
|
||||
{
|
||||
void *inBuf;
|
||||
const void *inBuf;
|
||||
size_t curSize = (1 << 18);
|
||||
if (curSize > inSize)
|
||||
curSize = (size_t)inSize;
|
||||
RINOK(inStream->Look((void *)inStream, (const void **)&inBuf, &curSize));
|
||||
RINOK(inStream->Look(inStream, &inBuf, &curSize));
|
||||
if (curSize == 0)
|
||||
return SZ_ERROR_INPUT_EOF;
|
||||
memcpy(outBuffer, inBuf, curSize);
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
#define MY_VER_MAJOR 15
|
||||
#define MY_VER_MINOR 05
|
||||
#define MY_VER_BUILD 00
|
||||
#define MY_VERSION "15.05 beta"
|
||||
#define MY_DATE "2015-06-14"
|
||||
#define MY_VER_MINOR 11
|
||||
#define MY_VER_BUILD 0
|
||||
#define MY_VERSION_NUMBERS "15.11"
|
||||
#define MY_VERSION "15.11 beta"
|
||||
#define MY_DATE "2015-11-14"
|
||||
#undef MY_COPYRIGHT
|
||||
#undef MY_VERSION_COPYRIGHT_DATE
|
||||
#define MY_AUTHOR_NAME "Igor Pavlov"
|
||||
#define MY_COPYRIGHT_PD "Igor Pavlov : Public domain"
|
||||
#define MY_COPYRIGHT_CR "Copyright (c) 1999-2015 Igor Pavlov"
|
||||
|
||||
|
||||
6
C/Bcj2.c
6
C/Bcj2.c
@@ -1,5 +1,5 @@
|
||||
/* Bcj2.c -- BCJ2 Decoder (Converter for x86 code)
|
||||
2014-11-09 : Igor Pavlov : Public domain */
|
||||
2015-08-01 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
@@ -178,8 +178,8 @@ SRes Bcj2Dec_Decode(CBcj2Dec *p)
|
||||
p->state =
|
||||
p->bufs[BCJ2_STREAM_MAIN] ==
|
||||
p->lims[BCJ2_STREAM_MAIN] ?
|
||||
BCJ2_STREAM_MAIN :
|
||||
BCJ2_DEC_STATE_ORIG;
|
||||
(unsigned)BCJ2_STREAM_MAIN :
|
||||
(unsigned)BCJ2_DEC_STATE_ORIG;
|
||||
return SZ_OK;
|
||||
}
|
||||
|
||||
|
||||
48
C/Blake2.h
Normal file
48
C/Blake2.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/* Blake2.h -- BLAKE2 Hash
|
||||
2015-06-30 : Igor Pavlov : Public domain
|
||||
2015 : Samuel Neves : Public domain */
|
||||
|
||||
#ifndef __BLAKE2_H
|
||||
#define __BLAKE2_H
|
||||
|
||||
#include "7zTypes.h"
|
||||
|
||||
EXTERN_C_BEGIN
|
||||
|
||||
#define BLAKE2S_BLOCK_SIZE 64
|
||||
#define BLAKE2S_DIGEST_SIZE 32
|
||||
#define BLAKE2SP_PARALLEL_DEGREE 8
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UInt32 h[8];
|
||||
UInt32 t[2];
|
||||
UInt32 f[2];
|
||||
Byte buf[BLAKE2S_BLOCK_SIZE];
|
||||
UInt32 bufPos;
|
||||
UInt32 lastNode_f1;
|
||||
UInt32 dummy[2]; /* for sizeof(CBlake2s) alignment */
|
||||
} CBlake2s;
|
||||
|
||||
/* You need to xor CBlake2s::h[i] with input parameter block after Blake2s_Init0() */
|
||||
/*
|
||||
void Blake2s_Init0(CBlake2s *p);
|
||||
void Blake2s_Update(CBlake2s *p, const Byte *data, size_t size);
|
||||
void Blake2s_Final(CBlake2s *p, Byte *digest);
|
||||
*/
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
CBlake2s S[BLAKE2SP_PARALLEL_DEGREE];
|
||||
unsigned bufPos;
|
||||
} CBlake2sp;
|
||||
|
||||
|
||||
void Blake2sp_Init(CBlake2sp *p);
|
||||
void Blake2sp_Update(CBlake2sp *p, const Byte *data, size_t size);
|
||||
void Blake2sp_Final(CBlake2sp *p, Byte *digest);
|
||||
|
||||
EXTERN_C_END
|
||||
|
||||
#endif
|
||||
244
C/Blake2s.c
Normal file
244
C/Blake2s.c
Normal file
@@ -0,0 +1,244 @@
|
||||
/* Blake2s.c -- BLAKE2s and BLAKE2sp Hash
|
||||
2015-06-30 : Igor Pavlov : Public domain
|
||||
2015 : Samuel Neves : Public domain */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "Blake2.h"
|
||||
#include "CpuArch.h"
|
||||
#include "RotateDefs.h"
|
||||
|
||||
#define rotr32 rotrFixed
|
||||
|
||||
#define BLAKE2S_NUM_ROUNDS 10
|
||||
#define BLAKE2S_FINAL_FLAG (~(UInt32)0)
|
||||
|
||||
static const UInt32 k_Blake2s_IV[8] =
|
||||
{
|
||||
0x6A09E667UL, 0xBB67AE85UL, 0x3C6EF372UL, 0xA54FF53AUL,
|
||||
0x510E527FUL, 0x9B05688CUL, 0x1F83D9ABUL, 0x5BE0CD19UL
|
||||
};
|
||||
|
||||
static const Byte k_Blake2s_Sigma[BLAKE2S_NUM_ROUNDS][16] =
|
||||
{
|
||||
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } ,
|
||||
{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 } ,
|
||||
{ 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 } ,
|
||||
{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 } ,
|
||||
{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 } ,
|
||||
{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 } ,
|
||||
{ 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 } ,
|
||||
{ 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 } ,
|
||||
{ 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 } ,
|
||||
{ 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 } ,
|
||||
};
|
||||
|
||||
|
||||
void Blake2s_Init0(CBlake2s *p)
|
||||
{
|
||||
unsigned i;
|
||||
for (i = 0; i < 8; i++)
|
||||
p->h[i] = k_Blake2s_IV[i];
|
||||
p->t[0] = 0;
|
||||
p->t[1] = 0;
|
||||
p->f[0] = 0;
|
||||
p->f[1] = 0;
|
||||
p->bufPos = 0;
|
||||
p->lastNode_f1 = 0;
|
||||
}
|
||||
|
||||
|
||||
static void Blake2s_Compress(CBlake2s *p)
|
||||
{
|
||||
UInt32 m[16];
|
||||
UInt32 v[16];
|
||||
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < 16; i++)
|
||||
m[i] = GetUi32(p->buf + i * sizeof(m[i]));
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
v[i] = p->h[i];
|
||||
}
|
||||
|
||||
v[ 8] = k_Blake2s_IV[0];
|
||||
v[ 9] = k_Blake2s_IV[1];
|
||||
v[10] = k_Blake2s_IV[2];
|
||||
v[11] = k_Blake2s_IV[3];
|
||||
|
||||
v[12] = p->t[0] ^ k_Blake2s_IV[4];
|
||||
v[13] = p->t[1] ^ k_Blake2s_IV[5];
|
||||
v[14] = p->f[0] ^ k_Blake2s_IV[6];
|
||||
v[15] = p->f[1] ^ k_Blake2s_IV[7];
|
||||
|
||||
#define G(r,i,a,b,c,d) \
|
||||
a += b + m[sigma[2*i+0]]; d ^= a; d = rotr32(d, 16); c += d; b ^= c; b = rotr32(b, 12); \
|
||||
a += b + m[sigma[2*i+1]]; d ^= a; d = rotr32(d, 8); c += d; b ^= c; b = rotr32(b, 7); \
|
||||
|
||||
#define R(r) \
|
||||
G(r,0,v[ 0],v[ 4],v[ 8],v[12]); \
|
||||
G(r,1,v[ 1],v[ 5],v[ 9],v[13]); \
|
||||
G(r,2,v[ 2],v[ 6],v[10],v[14]); \
|
||||
G(r,3,v[ 3],v[ 7],v[11],v[15]); \
|
||||
G(r,4,v[ 0],v[ 5],v[10],v[15]); \
|
||||
G(r,5,v[ 1],v[ 6],v[11],v[12]); \
|
||||
G(r,6,v[ 2],v[ 7],v[ 8],v[13]); \
|
||||
G(r,7,v[ 3],v[ 4],v[ 9],v[14]); \
|
||||
|
||||
{
|
||||
unsigned r;
|
||||
for (r = 0; r < BLAKE2S_NUM_ROUNDS; r++)
|
||||
{
|
||||
const Byte *sigma = k_Blake2s_Sigma[r];
|
||||
R(r);
|
||||
}
|
||||
/* R(0); R(1); R(2); R(3); R(4); R(5); R(6); R(7); R(8); R(9); */
|
||||
}
|
||||
|
||||
#undef G
|
||||
#undef R
|
||||
|
||||
{
|
||||
unsigned i;
|
||||
for (i = 0; i < 8; i++)
|
||||
p->h[i] ^= v[i] ^ v[i + 8];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define Blake2s_Increment_Counter(S, inc) \
|
||||
{ p->t[0] += (inc); p->t[1] += (p->t[0] < (inc)); }
|
||||
|
||||
#define Blake2s_Set_LastBlock(p) \
|
||||
{ p->f[0] = BLAKE2S_FINAL_FLAG; p->f[1] = p->lastNode_f1; }
|
||||
|
||||
|
||||
static void Blake2s_Update(CBlake2s *p, const Byte *data, size_t size)
|
||||
{
|
||||
while (size != 0)
|
||||
{
|
||||
unsigned pos = (unsigned)p->bufPos;
|
||||
unsigned rem = BLAKE2S_BLOCK_SIZE - pos;
|
||||
|
||||
if (size <= rem)
|
||||
{
|
||||
memcpy(p->buf + pos, data, size);
|
||||
p->bufPos += (UInt32)size;
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(p->buf + pos, data, rem);
|
||||
Blake2s_Increment_Counter(S, BLAKE2S_BLOCK_SIZE);
|
||||
Blake2s_Compress(p);
|
||||
p->bufPos = 0;
|
||||
data += rem;
|
||||
size -= rem;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void Blake2s_Final(CBlake2s *p, Byte *digest)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
Blake2s_Increment_Counter(S, (UInt32)p->bufPos);
|
||||
Blake2s_Set_LastBlock(p);
|
||||
memset(p->buf + p->bufPos, 0, BLAKE2S_BLOCK_SIZE - p->bufPos);
|
||||
Blake2s_Compress(p);
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
SetUi32(digest + sizeof(p->h[i]) * i, p->h[i]);
|
||||
}
|
||||
|
||||
|
||||
/* ---------- BLAKE2s ---------- */
|
||||
|
||||
/* we need to xor CBlake2s::h[i] with input parameter block after Blake2s_Init0() */
|
||||
/*
|
||||
typedef struct
|
||||
{
|
||||
Byte digest_length;
|
||||
Byte key_length;
|
||||
Byte fanout;
|
||||
Byte depth;
|
||||
UInt32 leaf_length;
|
||||
Byte node_offset[6];
|
||||
Byte node_depth;
|
||||
Byte inner_length;
|
||||
Byte salt[BLAKE2S_SALTBYTES];
|
||||
Byte personal[BLAKE2S_PERSONALBYTES];
|
||||
} CBlake2sParam;
|
||||
*/
|
||||
|
||||
|
||||
static void Blake2sp_Init_Spec(CBlake2s *p, unsigned node_offset, unsigned node_depth)
|
||||
{
|
||||
Blake2s_Init0(p);
|
||||
|
||||
p->h[0] ^= (BLAKE2S_DIGEST_SIZE | ((UInt32)BLAKE2SP_PARALLEL_DEGREE << 16) | ((UInt32)2 << 24));
|
||||
p->h[2] ^= ((UInt32)node_offset);
|
||||
p->h[3] ^= ((UInt32)node_depth << 16) | ((UInt32)BLAKE2S_DIGEST_SIZE << 24);
|
||||
/*
|
||||
P->digest_length = BLAKE2S_DIGEST_SIZE;
|
||||
P->key_length = 0;
|
||||
P->fanout = BLAKE2SP_PARALLEL_DEGREE;
|
||||
P->depth = 2;
|
||||
P->leaf_length = 0;
|
||||
store48(P->node_offset, node_offset);
|
||||
P->node_depth = node_depth;
|
||||
P->inner_length = BLAKE2S_DIGEST_SIZE;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
void Blake2sp_Init(CBlake2sp *p)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
p->bufPos = 0;
|
||||
|
||||
for (i = 0; i < BLAKE2SP_PARALLEL_DEGREE; i++)
|
||||
Blake2sp_Init_Spec(&p->S[i], i, 0);
|
||||
|
||||
p->S[BLAKE2SP_PARALLEL_DEGREE - 1].lastNode_f1 = BLAKE2S_FINAL_FLAG;
|
||||
}
|
||||
|
||||
|
||||
void Blake2sp_Update(CBlake2sp *p, const Byte *data, size_t size)
|
||||
{
|
||||
unsigned pos = p->bufPos;
|
||||
while (size != 0)
|
||||
{
|
||||
unsigned index = pos / BLAKE2S_BLOCK_SIZE;
|
||||
unsigned rem = BLAKE2S_BLOCK_SIZE - (pos & (BLAKE2S_BLOCK_SIZE - 1));
|
||||
if (rem > size)
|
||||
rem = (unsigned)size;
|
||||
Blake2s_Update(&p->S[index], data, rem);
|
||||
size -= rem;
|
||||
data += rem;
|
||||
pos += rem;
|
||||
pos &= (BLAKE2S_BLOCK_SIZE * BLAKE2SP_PARALLEL_DEGREE - 1);
|
||||
}
|
||||
p->bufPos = pos;
|
||||
}
|
||||
|
||||
|
||||
void Blake2sp_Final(CBlake2sp *p, Byte *digest)
|
||||
{
|
||||
CBlake2s R;
|
||||
unsigned i;
|
||||
|
||||
Blake2sp_Init_Spec(&R, 0, 1);
|
||||
R.lastNode_f1 = BLAKE2S_FINAL_FLAG;
|
||||
|
||||
for (i = 0; i < BLAKE2SP_PARALLEL_DEGREE; i++)
|
||||
{
|
||||
Byte hash[BLAKE2S_DIGEST_SIZE];
|
||||
Blake2s_Final(&p->S[i], hash);
|
||||
Blake2s_Update(&R, hash, BLAKE2S_DIGEST_SIZE);
|
||||
}
|
||||
|
||||
Blake2s_Final(&R, digest);
|
||||
}
|
||||
@@ -513,4 +513,3 @@ UInt32 BlockSort(UInt32 *Indices, const Byte *data, UInt32 blockSize)
|
||||
#endif
|
||||
return Groups[0];
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* Compiler.h
|
||||
2015-03-25 : Igor Pavlov : Public domain */
|
||||
2015-08-02 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __7Z_COMPILER_H
|
||||
#define __7Z_COMPILER_H
|
||||
@@ -18,6 +18,7 @@
|
||||
#else
|
||||
#pragma warning(disable : 4511) // copy constructor could not be generated
|
||||
#pragma warning(disable : 4512) // assignment operator could not be generated
|
||||
#pragma warning(disable : 4514) // unreferenced inline function has been removed
|
||||
#pragma warning(disable : 4702) // unreachable code
|
||||
#pragma warning(disable : 4710) // not inlined
|
||||
#pragma warning(disable : 4786) // identifier was truncated to '255' characters in the debug information
|
||||
|
||||
49
C/CpuArch.h
49
C/CpuArch.h
@@ -1,5 +1,5 @@
|
||||
/* CpuArch.h -- CPU specific code
|
||||
2015-03-25: Igor Pavlov : Public domain */
|
||||
2015-10-31: Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __CPU_ARCH_H
|
||||
#define __CPU_ARCH_H
|
||||
@@ -10,14 +10,18 @@ EXTERN_C_BEGIN
|
||||
|
||||
/*
|
||||
MY_CPU_LE means that CPU is LITTLE ENDIAN.
|
||||
If MY_CPU_LE is not defined, we don't know about that property of platform (it can be LITTLE ENDIAN).
|
||||
MY_CPU_BE means that CPU is BIG ENDIAN.
|
||||
If MY_CPU_LE and MY_CPU_BE are not defined, we don't know about ENDIANNESS of platform.
|
||||
|
||||
MY_CPU_LE_UNALIGN means that CPU is LITTLE ENDIAN and CPU supports unaligned memory accesses.
|
||||
If MY_CPU_LE_UNALIGN is not defined, we don't know about these properties of platform.
|
||||
*/
|
||||
|
||||
#if defined(_M_X64) || defined(_M_AMD64) || defined(__x86_64__)
|
||||
#define MY_CPU_AMD64
|
||||
#if defined(_M_X64) \
|
||||
|| defined(_M_AMD64) \
|
||||
|| defined(__x86_64__) \
|
||||
|| defined(__AMD64__) \
|
||||
|| defined(__amd64__)
|
||||
#define MY_CPU_AMD64
|
||||
#endif
|
||||
|
||||
#if defined(MY_CPU_AMD64) \
|
||||
@@ -52,10 +56,6 @@ If MY_CPU_LE_UNALIGN is not defined, we don't know about these properties of pla
|
||||
#define MY_CPU_IA64_LE
|
||||
#endif
|
||||
|
||||
#if defined(MY_CPU_X86_OR_AMD64)
|
||||
#define MY_CPU_LE_UNALIGN
|
||||
#endif
|
||||
|
||||
#if defined(MY_CPU_X86_OR_AMD64) \
|
||||
|| defined(MY_CPU_ARM_LE) \
|
||||
|| defined(MY_CPU_IA64_LE) \
|
||||
@@ -65,7 +65,8 @@ If MY_CPU_LE_UNALIGN is not defined, we don't know about these properties of pla
|
||||
|| defined(__AARCH64EL__) \
|
||||
|| defined(__MIPSEL__) \
|
||||
|| defined(__MIPSEL) \
|
||||
|| defined(_MIPSEL)
|
||||
|| defined(_MIPSEL) \
|
||||
|| (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
|
||||
#define MY_CPU_LE
|
||||
#endif
|
||||
|
||||
@@ -76,7 +77,9 @@ If MY_CPU_LE_UNALIGN is not defined, we don't know about these properties of pla
|
||||
|| defined(__MIPSEB__) \
|
||||
|| defined(__MIPSEB) \
|
||||
|| defined(_MIPSEB) \
|
||||
|| defined(__m68k__)
|
||||
|| defined(__m68k__) \
|
||||
|| defined(__s390x__) \
|
||||
|| (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))
|
||||
#define MY_CPU_BE
|
||||
#endif
|
||||
|
||||
@@ -85,14 +88,23 @@ Stop_Compiling_Bad_Endian
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef MY_CPU_LE
|
||||
#if defined(MY_CPU_X86_OR_AMD64) \
|
||||
/* || defined(__AARCH64EL__) */
|
||||
#define MY_CPU_LE_UNALIGN
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef MY_CPU_LE_UNALIGN
|
||||
|
||||
#define GetUi16(p) (*(const UInt16 *)(const void *)(p))
|
||||
#define GetUi32(p) (*(const UInt32 *)(const void *)(p))
|
||||
#define GetUi64(p) (*(const UInt64 *)(const void *)(p))
|
||||
#define SetUi16(p, v) *(UInt16 *)(p) = (v);
|
||||
#define SetUi32(p, v) *(UInt32 *)(p) = (v);
|
||||
#define SetUi64(p, v) *(UInt64 *)(p) = (v);
|
||||
|
||||
#define SetUi16(p, v) { *(UInt16 *)(p) = (v); }
|
||||
#define SetUi32(p, v) { *(UInt32 *)(p) = (v); }
|
||||
#define SetUi64(p, v) { *(UInt64 *)(p) = (v); }
|
||||
|
||||
#else
|
||||
|
||||
@@ -127,6 +139,8 @@ Stop_Compiling_Bad_Endian
|
||||
|
||||
#if defined(MY_CPU_LE_UNALIGN) && /* defined(_WIN64) && */ (_MSC_VER >= 1300)
|
||||
|
||||
/* Note: we use bswap instruction, that is unsupported in 386 cpu */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#pragma intrinsic(_byteswap_ulong)
|
||||
@@ -136,6 +150,13 @@ Stop_Compiling_Bad_Endian
|
||||
|
||||
#define SetBe32(p, v) (*(UInt32 *)(void *)(p)) = _byteswap_ulong(v)
|
||||
|
||||
#elif defined(MY_CPU_LE_UNALIGN) && defined (__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
|
||||
|
||||
#define GetBe32(p) __builtin_bswap32(*(const UInt32 *)(const Byte *)(p))
|
||||
#define GetBe64(p) __builtin_bswap64(*(const UInt64 *)(const Byte *)(p))
|
||||
|
||||
#define SetBe32(p, v) (*(UInt32 *)(void *)(p)) = __builtin_bswap32(v)
|
||||
|
||||
#else
|
||||
|
||||
#define GetBe32(p) ( \
|
||||
|
||||
22
C/LzFind.c
22
C/LzFind.c
@@ -1,5 +1,5 @@
|
||||
/* LzFind.c -- Match finder for LZ algorithms
|
||||
2015-05-15 : Igor Pavlov : Public domain */
|
||||
2015-10-15 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#define kEmptyHashValue 0
|
||||
#define kMaxValForNormalize ((UInt32)0xFFFFFFFF)
|
||||
#define kNormalizeStepMin (1 << 10) /* it must be power of 2 */
|
||||
#define kNormalizeMask (~(kNormalizeStepMin - 1))
|
||||
#define kNormalizeMask (~(UInt32)(kNormalizeStepMin - 1))
|
||||
#define kMaxHistorySize ((UInt32)7 << 29)
|
||||
|
||||
#define kStartMaxLen 3
|
||||
@@ -60,9 +60,11 @@ static void MatchFinder_ReadBlock(CMatchFinder *p)
|
||||
if (p->streamEndWasReached || p->result != SZ_OK)
|
||||
return;
|
||||
|
||||
/* We use (p->streamPos - p->pos) value. (p->streamPos < p->pos) is allowed. */
|
||||
|
||||
if (p->directInput)
|
||||
{
|
||||
UInt32 curSize = 0xFFFFFFFF - p->streamPos;
|
||||
UInt32 curSize = 0xFFFFFFFF - (p->streamPos - p->pos);
|
||||
if (curSize > p->directInputRem)
|
||||
curSize = (UInt32)p->directInputRem;
|
||||
p->directInputRem -= curSize;
|
||||
@@ -97,7 +99,7 @@ void MatchFinder_MoveBlock(CMatchFinder *p)
|
||||
{
|
||||
memmove(p->bufferBase,
|
||||
p->buffer - p->keepSizeBefore,
|
||||
(size_t)(p->streamPos - p->pos + p->keepSizeBefore));
|
||||
(size_t)(p->streamPos - p->pos) + p->keepSizeBefore);
|
||||
p->buffer = p->bufferBase + p->keepSizeBefore;
|
||||
}
|
||||
|
||||
@@ -290,7 +292,7 @@ static void MatchFinder_SetLimits(CMatchFinder *p)
|
||||
p->posLimit = p->pos + limit;
|
||||
}
|
||||
|
||||
void MatchFinder_Init(CMatchFinder *p)
|
||||
void MatchFinder_Init_2(CMatchFinder *p, int readData)
|
||||
{
|
||||
UInt32 i;
|
||||
UInt32 *hash = p->hash;
|
||||
@@ -303,10 +305,18 @@ void MatchFinder_Init(CMatchFinder *p)
|
||||
p->pos = p->streamPos = p->cyclicBufferSize;
|
||||
p->result = SZ_OK;
|
||||
p->streamEndWasReached = 0;
|
||||
MatchFinder_ReadBlock(p);
|
||||
|
||||
if (readData)
|
||||
MatchFinder_ReadBlock(p);
|
||||
|
||||
MatchFinder_SetLimits(p);
|
||||
}
|
||||
|
||||
void MatchFinder_Init(CMatchFinder *p)
|
||||
{
|
||||
MatchFinder_Init_2(p, True);
|
||||
}
|
||||
|
||||
static UInt32 MatchFinder_GetSubValue(CMatchFinder *p)
|
||||
{
|
||||
return (p->pos - p->historySize - 1) & kNormalizeMask;
|
||||
|
||||
10
C/LzFind.h
10
C/LzFind.h
@@ -1,5 +1,5 @@
|
||||
/* LzFind.h -- Match finder for LZ algorithms
|
||||
2015-05-01 : Igor Pavlov : Public domain */
|
||||
2015-10-15 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __LZ_FIND_H
|
||||
#define __LZ_FIND_H
|
||||
@@ -53,6 +53,11 @@ typedef struct _CMatchFinder
|
||||
|
||||
#define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)
|
||||
|
||||
#define Inline_MatchFinder_IsFinishedOK(p) \
|
||||
((p)->streamEndWasReached \
|
||||
&& (p)->streamPos == (p)->pos \
|
||||
&& (!(p)->directInput || (p)->directInputRem == 0))
|
||||
|
||||
int MatchFinder_NeedMove(CMatchFinder *p);
|
||||
Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);
|
||||
void MatchFinder_MoveBlock(CMatchFinder *p);
|
||||
@@ -98,9 +103,12 @@ typedef struct _IMatchFinder
|
||||
|
||||
void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);
|
||||
|
||||
void MatchFinder_Init_2(CMatchFinder *p, int readData);
|
||||
void MatchFinder_Init(CMatchFinder *p);
|
||||
|
||||
UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
|
||||
UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
|
||||
|
||||
void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
|
||||
void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
|
||||
|
||||
|
||||
19
C/LzFindMt.c
19
C/LzFindMt.c
@@ -1,5 +1,5 @@
|
||||
/* LzFindMt.c -- multithreaded Match finder for LZ algorithms
|
||||
2015-05-03 : Igor Pavlov : Public domain */
|
||||
2015-10-15 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
@@ -173,12 +173,12 @@ static void HashThreadFunc(CMatchFinderMt *mt)
|
||||
CriticalSection_Enter(&mt->btSync.cs);
|
||||
CriticalSection_Enter(&mt->hashSync.cs);
|
||||
{
|
||||
const Byte *beforePtr = MatchFinder_GetPointerToCurrentPos(mf);
|
||||
const Byte *afterPtr;
|
||||
const Byte *beforePtr = Inline_MatchFinder_GetPointerToCurrentPos(mf);
|
||||
ptrdiff_t offset;
|
||||
MatchFinder_MoveBlock(mf);
|
||||
afterPtr = MatchFinder_GetPointerToCurrentPos(mf);
|
||||
mt->pointerToCurPos -= beforePtr - afterPtr;
|
||||
mt->buffer -= beforePtr - afterPtr;
|
||||
offset = beforePtr - Inline_MatchFinder_GetPointerToCurrentPos(mf);
|
||||
mt->pointerToCurPos -= offset;
|
||||
mt->buffer -= offset;
|
||||
}
|
||||
CriticalSection_Leave(&mt->btSync.cs);
|
||||
CriticalSection_Leave(&mt->hashSync.cs);
|
||||
@@ -501,8 +501,11 @@ void MatchFinderMt_Init(CMatchFinderMt *p)
|
||||
CMatchFinder *mf = p->MatchFinder;
|
||||
p->btBufPos = p->btBufPosLimit = 0;
|
||||
p->hashBufPos = p->hashBufPosLimit = 0;
|
||||
MatchFinder_Init(mf);
|
||||
p->pointerToCurPos = MatchFinder_GetPointerToCurrentPos(mf);
|
||||
|
||||
/* Init without data reading. We don't want to read data in this thread */
|
||||
MatchFinder_Init_2(mf, False);
|
||||
|
||||
p->pointerToCurPos = Inline_MatchFinder_GetPointerToCurrentPos(mf);
|
||||
p->btNumAvailBytes = 0;
|
||||
p->lzPos = p->historySize + 1;
|
||||
|
||||
|
||||
10
C/Lzma2Dec.c
10
C/Lzma2Dec.c
@@ -1,5 +1,5 @@
|
||||
/* Lzma2Dec.c -- LZMA2 Decoder
|
||||
2014-10-29 : Igor Pavlov : Public domain */
|
||||
2015-11-09 : Igor Pavlov : Public domain */
|
||||
|
||||
/* #define SHOW_DEBUG_INFO */
|
||||
|
||||
@@ -103,8 +103,8 @@ static ELzma2State Lzma2Dec_UpdateState(CLzma2Dec *p, Byte b)
|
||||
{
|
||||
case LZMA2_STATE_CONTROL:
|
||||
p->control = b;
|
||||
PRF(printf("\n %4X ", p->decoder.dicPos));
|
||||
PRF(printf(" %2X", b));
|
||||
PRF(printf("\n %4X ", (unsigned)p->decoder.dicPos));
|
||||
PRF(printf(" %2X", (unsigned)b));
|
||||
if (p->control == 0)
|
||||
return LZMA2_STATE_FINISHED;
|
||||
if (LZMA2_IS_UNCOMPRESSED_STATE(p))
|
||||
@@ -124,7 +124,7 @@ static ELzma2State Lzma2Dec_UpdateState(CLzma2Dec *p, Byte b)
|
||||
case LZMA2_STATE_UNPACK1:
|
||||
p->unpackSize |= (UInt32)b;
|
||||
p->unpackSize++;
|
||||
PRF(printf(" %8d", p->unpackSize));
|
||||
PRF(printf(" %8u", (unsigned)p->unpackSize));
|
||||
return (LZMA2_IS_UNCOMPRESSED_STATE(p)) ? LZMA2_STATE_DATA : LZMA2_STATE_PACK0;
|
||||
|
||||
case LZMA2_STATE_PACK0:
|
||||
@@ -134,7 +134,7 @@ static ELzma2State Lzma2Dec_UpdateState(CLzma2Dec *p, Byte b)
|
||||
case LZMA2_STATE_PACK1:
|
||||
p->packSize |= (UInt32)b;
|
||||
p->packSize++;
|
||||
PRF(printf(" %8d", p->packSize));
|
||||
PRF(printf(" %8u", (unsigned)p->packSize));
|
||||
return LZMA2_IS_THERE_PROP(LZMA2_GET_LZMA_MODE(p)) ? LZMA2_STATE_PROP:
|
||||
(p->needInitProp ? LZMA2_STATE_ERROR : LZMA2_STATE_DATA);
|
||||
|
||||
|
||||
55
C/Lzma2Enc.c
55
C/Lzma2Enc.c
@@ -1,5 +1,5 @@
|
||||
/* Lzma2Enc.c -- LZMA2 Encoder
|
||||
2012-06-19 : Igor Pavlov : Public domain */
|
||||
2015-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
@@ -109,6 +109,7 @@ static SRes Lzma2EncInt_EncodeSubblock(CLzma2EncInt *p, Byte *outBuf,
|
||||
{
|
||||
size_t destPos = 0;
|
||||
PRF(printf("################# COPY "));
|
||||
|
||||
while (unpackSize > 0)
|
||||
{
|
||||
UInt32 u = (unpackSize < LZMA2_COPY_CHUNK_SIZE) ? unpackSize : LZMA2_COPY_CHUNK_SIZE;
|
||||
@@ -121,6 +122,7 @@ static SRes Lzma2EncInt_EncodeSubblock(CLzma2EncInt *p, Byte *outBuf,
|
||||
unpackSize -= u;
|
||||
destPos += u;
|
||||
p->srcPos += u;
|
||||
|
||||
if (outStream)
|
||||
{
|
||||
*packSizeRes += destPos;
|
||||
@@ -132,9 +134,11 @@ static SRes Lzma2EncInt_EncodeSubblock(CLzma2EncInt *p, Byte *outBuf,
|
||||
*packSizeRes = destPos;
|
||||
/* needInitState = True; */
|
||||
}
|
||||
|
||||
LzmaEnc_RestoreState(p->enc);
|
||||
return SZ_OK;
|
||||
}
|
||||
|
||||
{
|
||||
size_t destPos = 0;
|
||||
UInt32 u = unpackSize - 1;
|
||||
@@ -160,11 +164,13 @@ static SRes Lzma2EncInt_EncodeSubblock(CLzma2EncInt *p, Byte *outBuf,
|
||||
if (outStream)
|
||||
if (outStream->Write(outStream, outBuf, destPos) != destPos)
|
||||
return SZ_ERROR_WRITE;
|
||||
|
||||
*packSizeRes = destPos;
|
||||
return SZ_OK;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ---------- Lzma2 Props ---------- */
|
||||
|
||||
void Lzma2EncProps_Init(CLzma2EncProps *p)
|
||||
@@ -221,6 +227,8 @@ void Lzma2EncProps_Normalize(CLzma2EncProps *p)
|
||||
|
||||
LzmaEncProps_Normalize(&p->lzmaProps);
|
||||
|
||||
t1 = p->lzmaProps.numThreads;
|
||||
|
||||
if (p->blockSize == 0)
|
||||
{
|
||||
UInt32 dictSize = p->lzmaProps.dictSize;
|
||||
@@ -232,7 +240,8 @@ void Lzma2EncProps_Normalize(CLzma2EncProps *p)
|
||||
if (blockSize < dictSize) blockSize = dictSize;
|
||||
p->blockSize = (size_t)blockSize;
|
||||
}
|
||||
if (t2 > 1)
|
||||
|
||||
if (t2 > 1 && p->lzmaProps.reduceSize != (UInt64)(Int64)-1)
|
||||
{
|
||||
UInt64 temp = p->lzmaProps.reduceSize + p->blockSize - 1;
|
||||
if (temp > p->lzmaProps.reduceSize)
|
||||
@@ -241,19 +250,24 @@ void Lzma2EncProps_Normalize(CLzma2EncProps *p)
|
||||
if (numBlocks < (unsigned)t2)
|
||||
{
|
||||
t2 = (unsigned)numBlocks;
|
||||
if (t2 == 0)
|
||||
t2 = 1;
|
||||
t3 = t1 * t2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
p->numBlockThreads = t2;
|
||||
p->numTotalThreads = t3;
|
||||
}
|
||||
|
||||
|
||||
static SRes Progress(ICompressProgress *p, UInt64 inSize, UInt64 outSize)
|
||||
{
|
||||
return (p && p->Progress(p, inSize, outSize) != SZ_OK) ? SZ_ERROR_PROGRESS : SZ_OK;
|
||||
}
|
||||
|
||||
|
||||
/* ---------- Lzma2 ---------- */
|
||||
|
||||
typedef struct
|
||||
@@ -283,15 +297,17 @@ static SRes Lzma2Enc_EncodeMt1(CLzma2EncInt *p, CLzma2Enc *mainEncoder,
|
||||
UInt64 packTotal = 0;
|
||||
SRes res = SZ_OK;
|
||||
|
||||
if (mainEncoder->outBuf == 0)
|
||||
if (!mainEncoder->outBuf)
|
||||
{
|
||||
mainEncoder->outBuf = (Byte *)IAlloc_Alloc(mainEncoder->alloc, LZMA2_CHUNK_SIZE_COMPRESSED_MAX);
|
||||
if (mainEncoder->outBuf == 0)
|
||||
if (!mainEncoder->outBuf)
|
||||
return SZ_ERROR_MEM;
|
||||
}
|
||||
|
||||
RINOK(Lzma2EncInt_Init(p, &mainEncoder->props));
|
||||
RINOK(LzmaEnc_PrepareForLzma2(p->enc, inStream, LZMA2_KEEP_WINDOW_SIZE,
|
||||
mainEncoder->alloc, mainEncoder->allocBig));
|
||||
|
||||
for (;;)
|
||||
{
|
||||
size_t packSize = LZMA2_CHUNK_SIZE_COMPRESSED_MAX;
|
||||
@@ -305,16 +321,20 @@ static SRes Lzma2Enc_EncodeMt1(CLzma2EncInt *p, CLzma2Enc *mainEncoder,
|
||||
if (packSize == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
LzmaEnc_Finish(p->enc);
|
||||
|
||||
if (res == SZ_OK)
|
||||
{
|
||||
Byte b = 0;
|
||||
if (outStream->Write(outStream, &b, 1) != 1)
|
||||
return SZ_ERROR_WRITE;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
#ifndef _7ZIP_ST
|
||||
|
||||
typedef struct
|
||||
@@ -362,10 +382,12 @@ static SRes MtCallbackImp_Code(void *pp, unsigned index, Byte *dest, size_t *des
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
LzmaEnc_Finish(p->enc);
|
||||
if (res != SZ_OK)
|
||||
return res;
|
||||
}
|
||||
|
||||
if (finished)
|
||||
{
|
||||
if (*destSize == destLim)
|
||||
@@ -378,12 +400,13 @@ static SRes MtCallbackImp_Code(void *pp, unsigned index, Byte *dest, size_t *des
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* ---------- Lzma2Enc ---------- */
|
||||
|
||||
CLzma2EncHandle Lzma2Enc_Create(ISzAlloc *alloc, ISzAlloc *allocBig)
|
||||
{
|
||||
CLzma2Enc *p = (CLzma2Enc *)alloc->Alloc(alloc, sizeof(CLzma2Enc));
|
||||
if (p == 0)
|
||||
if (!p)
|
||||
return NULL;
|
||||
Lzma2EncProps_Init(&p->props);
|
||||
Lzma2EncProps_Normalize(&p->props);
|
||||
@@ -395,6 +418,7 @@ CLzma2EncHandle Lzma2Enc_Create(ISzAlloc *alloc, ISzAlloc *allocBig)
|
||||
for (i = 0; i < NUM_MT_CODER_THREADS_MAX; i++)
|
||||
p->coders[i].enc = 0;
|
||||
}
|
||||
|
||||
#ifndef _7ZIP_ST
|
||||
MtCoder_Construct(&p->mtCoder);
|
||||
#endif
|
||||
@@ -455,22 +479,17 @@ SRes Lzma2Enc_Encode(CLzma2EncHandle pp,
|
||||
|
||||
for (i = 0; i < p->props.numBlockThreads; i++)
|
||||
{
|
||||
CLzma2EncInt *t = &p->coders[i];
|
||||
if (t->enc == NULL)
|
||||
CLzma2EncInt *t = &p->coders[(unsigned)i];
|
||||
if (!t->enc)
|
||||
{
|
||||
t->enc = LzmaEnc_Create(p->alloc);
|
||||
if (t->enc == NULL)
|
||||
if (!t->enc)
|
||||
return SZ_ERROR_MEM;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef _7ZIP_ST
|
||||
if (p->props.numBlockThreads <= 1)
|
||||
#endif
|
||||
return Lzma2Enc_EncodeMt1(&p->coders[0], p, outStream, inStream, progress);
|
||||
|
||||
#ifndef _7ZIP_ST
|
||||
|
||||
if (p->props.numBlockThreads > 1)
|
||||
{
|
||||
CMtCallbackImp mtCallback;
|
||||
|
||||
@@ -485,9 +504,17 @@ SRes Lzma2Enc_Encode(CLzma2EncHandle pp,
|
||||
|
||||
p->mtCoder.blockSize = p->props.blockSize;
|
||||
p->mtCoder.destBlockSize = p->props.blockSize + (p->props.blockSize >> 10) + 16;
|
||||
if (p->mtCoder.destBlockSize < p->props.blockSize)
|
||||
{
|
||||
p->mtCoder.destBlockSize = (size_t)0 - 1;
|
||||
if (p->mtCoder.destBlockSize < p->props.blockSize)
|
||||
return SZ_ERROR_FAIL;
|
||||
}
|
||||
p->mtCoder.numThreads = p->props.numBlockThreads;
|
||||
|
||||
return MtCoder_Code(&p->mtCoder);
|
||||
}
|
||||
#endif
|
||||
|
||||
return Lzma2Enc_EncodeMt1(&p->coders[0], p, outStream, inStream, progress);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
/* Lzma86Dec.c -- LZMA + x86 (BCJ) Filter Decoder
|
||||
2009-08-14 : Igor Pavlov : Public domain */
|
||||
2015-11-08 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
#include "Lzma86.h"
|
||||
|
||||
@@ -7,8 +9,8 @@
|
||||
#include "Bra.h"
|
||||
#include "LzmaDec.h"
|
||||
|
||||
static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }
|
||||
static void SzFree(void *p, void *address) { p = p; MyFree(address); }
|
||||
static void *SzAlloc(void *p, size_t size) { UNUSED_VAR(p); return MyAlloc(size); }
|
||||
static void SzFree(void *p, void *address) { UNUSED_VAR(p); MyFree(address); }
|
||||
|
||||
SRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
/* Lzma86Enc.c -- LZMA + x86 (BCJ) Filter Encoder
|
||||
2009-08-14 : Igor Pavlov : Public domain */
|
||||
2015-11-08 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@@ -11,8 +13,8 @@
|
||||
|
||||
#define SZE_OUT_OVERFLOW SZE_DATA_ERROR
|
||||
|
||||
static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }
|
||||
static void SzFree(void *p, void *address) { p = p; MyFree(address); }
|
||||
static void *SzAlloc(void *p, size_t size) { UNUSED_VAR(p); return MyAlloc(size); }
|
||||
static void SzFree(void *p, void *address) { UNUSED_VAR(p); MyFree(address); }
|
||||
|
||||
int Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen,
|
||||
int level, UInt32 dictSize, int filterMode)
|
||||
|
||||
11
C/LzmaDec.c
11
C/LzmaDec.c
@@ -1,5 +1,5 @@
|
||||
/* LzmaDec.c -- LZMA Decoder
|
||||
2015-05-14 : Igor Pavlov : Public domain */
|
||||
2015-06-23 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
@@ -438,10 +438,16 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
|
||||
if (checkDicSize == 0)
|
||||
{
|
||||
if (distance >= processedPos)
|
||||
{
|
||||
p->dicPos = dicPos;
|
||||
return SZ_ERROR_DATA;
|
||||
}
|
||||
}
|
||||
else if (distance >= checkDicSize)
|
||||
{
|
||||
p->dicPos = dicPos;
|
||||
return SZ_ERROR_DATA;
|
||||
}
|
||||
state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3;
|
||||
}
|
||||
|
||||
@@ -453,7 +459,10 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
|
||||
SizeT pos;
|
||||
|
||||
if ((rem = limit - dicPos) == 0)
|
||||
{
|
||||
p->dicPos = dicPos;
|
||||
return SZ_ERROR_DATA;
|
||||
}
|
||||
|
||||
curLen = ((rem < len) ? (unsigned)rem : len);
|
||||
pos = dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0);
|
||||
|
||||
71
C/LzmaEnc.c
71
C/LzmaEnc.c
@@ -1,5 +1,5 @@
|
||||
/* LzmaEnc.c -- LZMA Encoder
|
||||
2015-05-15 Igor Pavlov : Public domain */
|
||||
2015-11-08 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
@@ -505,8 +505,8 @@ static const int kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11,
|
||||
|
||||
static void RangeEnc_Construct(CRangeEnc *p)
|
||||
{
|
||||
p->outStream = 0;
|
||||
p->bufBase = 0;
|
||||
p->outStream = NULL;
|
||||
p->bufBase = NULL;
|
||||
}
|
||||
|
||||
#define RangeEnc_GetProcessed(p) ((p)->processed + ((p)->buf - (p)->bufBase) + (p)->cacheSize)
|
||||
@@ -514,10 +514,10 @@ static void RangeEnc_Construct(CRangeEnc *p)
|
||||
#define RC_BUF_SIZE (1 << 16)
|
||||
static int RangeEnc_Alloc(CRangeEnc *p, ISzAlloc *alloc)
|
||||
{
|
||||
if (p->bufBase == 0)
|
||||
if (!p->bufBase)
|
||||
{
|
||||
p->bufBase = (Byte *)alloc->Alloc(alloc, RC_BUF_SIZE);
|
||||
if (p->bufBase == 0)
|
||||
if (!p->bufBase)
|
||||
return 0;
|
||||
p->bufLim = p->bufBase + RC_BUF_SIZE;
|
||||
}
|
||||
@@ -854,7 +854,7 @@ static void MovePos(CLzmaEnc *p, UInt32 num)
|
||||
{
|
||||
#ifdef SHOW_STAT
|
||||
g_STAT_OFFSET += num;
|
||||
printf("\n MovePos %d", num);
|
||||
printf("\n MovePos %u", num);
|
||||
#endif
|
||||
|
||||
if (num != 0)
|
||||
@@ -871,12 +871,12 @@ static UInt32 ReadMatchDistances(CLzmaEnc *p, UInt32 *numDistancePairsRes)
|
||||
numPairs = p->matchFinder.GetMatches(p->matchFinderObj, p->matches);
|
||||
|
||||
#ifdef SHOW_STAT
|
||||
printf("\n i = %d numPairs = %d ", g_STAT_OFFSET, numPairs / 2);
|
||||
printf("\n i = %u numPairs = %u ", g_STAT_OFFSET, numPairs / 2);
|
||||
g_STAT_OFFSET++;
|
||||
{
|
||||
UInt32 i;
|
||||
for (i = 0; i < numPairs; i += 2)
|
||||
printf("%2d %6d | ", p->matches[i], p->matches[i + 1]);
|
||||
printf("%2u %6u | ", p->matches[i], p->matches[i + 1]);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1167,12 +1167,12 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
|
||||
cur = 0;
|
||||
|
||||
#ifdef SHOW_STAT2
|
||||
if (position >= 0)
|
||||
/* if (position >= 0) */
|
||||
{
|
||||
unsigned i;
|
||||
printf("\n pos = %4X", position);
|
||||
for (i = cur; i <= lenEnd; i++)
|
||||
printf("\nprice[%4X] = %d", position - cur + i, p->opt[i].price);
|
||||
printf("\nprice[%4X] = %u", position - cur + i, p->opt[i].price);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1397,13 +1397,13 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
|
||||
{
|
||||
UInt32 lenTest2 = lenTest + 1;
|
||||
UInt32 limit = lenTest2 + p->numFastBytes;
|
||||
UInt32 nextRepMatchPrice;
|
||||
if (limit > numAvailFull)
|
||||
limit = numAvailFull;
|
||||
for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);
|
||||
lenTest2 -= lenTest + 1;
|
||||
if (lenTest2 >= 2)
|
||||
{
|
||||
UInt32 nextRepMatchPrice;
|
||||
UInt32 state2 = kRepNextStates[state];
|
||||
UInt32 posStateNext = (position + lenTest) & p->pbMask;
|
||||
UInt32 curAndLenCharPrice =
|
||||
@@ -1487,13 +1487,13 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
|
||||
const Byte *data2 = data - curBack - 1;
|
||||
UInt32 lenTest2 = lenTest + 1;
|
||||
UInt32 limit = lenTest2 + p->numFastBytes;
|
||||
UInt32 nextRepMatchPrice;
|
||||
if (limit > numAvailFull)
|
||||
limit = numAvailFull;
|
||||
for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);
|
||||
lenTest2 -= lenTest + 1;
|
||||
if (lenTest2 >= 2)
|
||||
{
|
||||
UInt32 nextRepMatchPrice;
|
||||
UInt32 state2 = kMatchNextStates[state];
|
||||
UInt32 posStateNext = (position + lenTest) & p->pbMask;
|
||||
UInt32 curAndLenCharPrice = curAndLenPrice +
|
||||
@@ -1749,15 +1749,15 @@ void LzmaEnc_Construct(CLzmaEnc *p)
|
||||
#endif
|
||||
|
||||
LzmaEnc_InitPriceTables(p->ProbPrices);
|
||||
p->litProbs = 0;
|
||||
p->saveState.litProbs = 0;
|
||||
p->litProbs = NULL;
|
||||
p->saveState.litProbs = NULL;
|
||||
}
|
||||
|
||||
CLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc)
|
||||
{
|
||||
void *p;
|
||||
p = alloc->Alloc(alloc, sizeof(CLzmaEnc));
|
||||
if (p != 0)
|
||||
if (p)
|
||||
LzmaEnc_Construct((CLzmaEnc *)p);
|
||||
return p;
|
||||
}
|
||||
@@ -1766,8 +1766,8 @@ void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc)
|
||||
{
|
||||
alloc->Free(alloc, p->litProbs);
|
||||
alloc->Free(alloc, p->saveState.litProbs);
|
||||
p->litProbs = 0;
|
||||
p->saveState.litProbs = 0;
|
||||
p->litProbs = NULL;
|
||||
p->saveState.litProbs = NULL;
|
||||
}
|
||||
|
||||
void LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig)
|
||||
@@ -1829,7 +1829,7 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize
|
||||
len = GetOptimum(p, nowPos32, &pos);
|
||||
|
||||
#ifdef SHOW_STAT2
|
||||
printf("\n pos = %4X, len = %d pos = %d", nowPos32, len, pos);
|
||||
printf("\n pos = %4X, len = %u pos = %u", nowPos32, len, pos);
|
||||
#endif
|
||||
|
||||
posState = nowPos32 & p->pbMask;
|
||||
@@ -1963,12 +1963,12 @@ static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, I
|
||||
|
||||
{
|
||||
unsigned lclp = p->lc + p->lp;
|
||||
if (p->litProbs == 0 || p->saveState.litProbs == 0 || p->lclp != lclp)
|
||||
if (!p->litProbs || !p->saveState.litProbs || p->lclp != lclp)
|
||||
{
|
||||
LzmaEnc_FreeLits(p, alloc);
|
||||
p->litProbs = (CLzmaProb *)alloc->Alloc(alloc, ((UInt32)0x300 << lclp) * sizeof(CLzmaProb));
|
||||
p->saveState.litProbs = (CLzmaProb *)alloc->Alloc(alloc, ((UInt32)0x300 << lclp) * sizeof(CLzmaProb));
|
||||
if (p->litProbs == 0 || p->saveState.litProbs == 0)
|
||||
if (!p->litProbs || !p->saveState.litProbs)
|
||||
{
|
||||
LzmaEnc_FreeLits(p, alloc);
|
||||
return SZ_ERROR_MEM;
|
||||
@@ -2140,6 +2140,7 @@ void LzmaEnc_Finish(CLzmaEncHandle pp)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ISeqOutStream funcTable;
|
||||
@@ -2169,12 +2170,14 @@ UInt32 LzmaEnc_GetNumAvailableBytes(CLzmaEncHandle pp)
|
||||
return p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);
|
||||
}
|
||||
|
||||
|
||||
const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp)
|
||||
{
|
||||
const CLzmaEnc *p = (CLzmaEnc *)pp;
|
||||
return p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;
|
||||
}
|
||||
|
||||
|
||||
SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,
|
||||
Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize)
|
||||
{
|
||||
@@ -2209,6 +2212,7 @@ SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static SRes LzmaEnc_Encode2(CLzmaEnc *p, ICompressProgress *progress)
|
||||
{
|
||||
SRes res = SZ_OK;
|
||||
@@ -2222,9 +2226,9 @@ static SRes LzmaEnc_Encode2(CLzmaEnc *p, ICompressProgress *progress)
|
||||
for (;;)
|
||||
{
|
||||
res = LzmaEnc_CodeOneBlock(p, False, 0, 0);
|
||||
if (res != SZ_OK || p->finished != 0)
|
||||
if (res != SZ_OK || p->finished)
|
||||
break;
|
||||
if (progress != 0)
|
||||
if (progress)
|
||||
{
|
||||
res = progress->Progress(progress, p->nowPos64, RangeEnc_GetProcessed(&p->rc));
|
||||
if (res != SZ_OK)
|
||||
@@ -2234,10 +2238,19 @@ static SRes LzmaEnc_Encode2(CLzmaEnc *p, ICompressProgress *progress)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LzmaEnc_Finish(p);
|
||||
|
||||
/*
|
||||
if (res == S_OK && !Inline_MatchFinder_IsFinishedOK(&p->matchFinderBase))
|
||||
res = SZ_ERROR_FAIL;
|
||||
}
|
||||
*/
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
SRes LzmaEnc_Encode(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress,
|
||||
ISzAlloc *alloc, ISzAlloc *allocBig)
|
||||
{
|
||||
@@ -2245,6 +2258,7 @@ SRes LzmaEnc_Encode(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *i
|
||||
return LzmaEnc_Encode2((CLzmaEnc *)pp, progress);
|
||||
}
|
||||
|
||||
|
||||
SRes LzmaEnc_WriteProperties(CLzmaEncHandle pp, Byte *props, SizeT *size)
|
||||
{
|
||||
CLzmaEnc *p = (CLzmaEnc *)pp;
|
||||
@@ -2272,6 +2286,7 @@ SRes LzmaEnc_WriteProperties(CLzmaEncHandle pp, Byte *props, SizeT *size)
|
||||
return SZ_OK;
|
||||
}
|
||||
|
||||
|
||||
SRes LzmaEnc_MemEncode(CLzmaEncHandle pp, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
|
||||
int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)
|
||||
{
|
||||
@@ -2280,19 +2295,22 @@ SRes LzmaEnc_MemEncode(CLzmaEncHandle pp, Byte *dest, SizeT *destLen, const Byte
|
||||
|
||||
CSeqOutStreamBuf outStream;
|
||||
|
||||
LzmaEnc_SetInputBuf(p, src, srcLen);
|
||||
|
||||
outStream.funcTable.Write = MyWrite;
|
||||
outStream.data = dest;
|
||||
outStream.rem = *destLen;
|
||||
outStream.overflow = False;
|
||||
|
||||
p->writeEndMark = writeEndMark;
|
||||
|
||||
p->rc.outStream = &outStream.funcTable;
|
||||
|
||||
res = LzmaEnc_MemPrepare(pp, src, srcLen, 0, alloc, allocBig);
|
||||
|
||||
if (res == SZ_OK)
|
||||
{
|
||||
res = LzmaEnc_Encode2(p, progress);
|
||||
if (res == SZ_OK && p->nowPos64 != srcLen)
|
||||
res = SZ_ERROR_FAIL;
|
||||
}
|
||||
|
||||
*destLen -= outStream.rem;
|
||||
if (outStream.overflow)
|
||||
@@ -2300,13 +2318,14 @@ SRes LzmaEnc_MemEncode(CLzmaEncHandle pp, Byte *dest, SizeT *destLen, const Byte
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
|
||||
const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
|
||||
ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)
|
||||
{
|
||||
CLzmaEnc *p = (CLzmaEnc *)LzmaEnc_Create(alloc);
|
||||
SRes res;
|
||||
if (p == 0)
|
||||
if (!p)
|
||||
return SZ_ERROR_MEM;
|
||||
|
||||
res = LzmaEnc_SetProps(p, props);
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
/* MtCoder.c -- Multi-thread Coder
|
||||
2010-09-24 : Igor Pavlov : Public domain */
|
||||
2015-10-13 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "MtCoder.h"
|
||||
|
||||
void LoopThread_Construct(CLoopThread *p)
|
||||
@@ -120,7 +118,7 @@ void CMtThread_Construct(CMtThread *p, CMtCoder *mtCoder)
|
||||
LoopThread_Construct(&p->thread);
|
||||
}
|
||||
|
||||
#define RINOK_THREAD(x) { if((x) != 0) return SZ_ERROR_THREAD; }
|
||||
#define RINOK_THREAD(x) { if ((x) != 0) return SZ_ERROR_THREAD; }
|
||||
|
||||
static void CMtThread_CloseEvents(CMtThread *p)
|
||||
{
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
/* Ppmd7.c -- PPMdH codec
|
||||
2010-03-12 : Igor Pavlov : Public domain
|
||||
2015-09-28 : Igor Pavlov : Public domain
|
||||
This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
#include <memory.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "Ppmd7.h"
|
||||
|
||||
@@ -66,7 +66,7 @@ void Ppmd7_Construct(CPpmd7 *p)
|
||||
for (i = 0, k = 0; i < PPMD_NUM_INDEXES; i++)
|
||||
{
|
||||
unsigned step = (i >= 12 ? 4 : (i >> 2) + 1);
|
||||
do { p->Units2Indx[k++] = (Byte)i; } while(--step);
|
||||
do { p->Units2Indx[k++] = (Byte)i; } while (--step);
|
||||
p->Indx2Units[i] = (Byte)k;
|
||||
}
|
||||
|
||||
@@ -257,7 +257,7 @@ static void *AllocUnits(CPpmd7 *p, unsigned indx)
|
||||
|
||||
#define MyMem12Cpy(dest, src, num) \
|
||||
{ UInt32 *d = (UInt32 *)dest; const UInt32 *s = (const UInt32 *)src; UInt32 n = num; \
|
||||
do { d[0] = s[0]; d[1] = s[1]; d[2] = s[2]; s += 3; d += 3; } while(--n); }
|
||||
do { d[0] = s[0]; d[1] = s[1]; d[2] = s[2]; s += 3; d += 3; } while (--n); }
|
||||
|
||||
static void *ShrinkUnits(CPpmd7 *p, void *oldPtr, unsigned oldNU, unsigned newNU)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* Ppmd7Enc.c -- PPMdH Encoder
|
||||
2010-03-12 : Igor Pavlov : Public domain
|
||||
2015-09-28 : Igor Pavlov : Public domain
|
||||
This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
@@ -26,7 +26,7 @@ static void RangeEnc_ShiftLow(CPpmd7z_RangeEnc *p)
|
||||
p->Stream->Write(p->Stream, (Byte)(temp + (Byte)(p->Low >> 32)));
|
||||
temp = 0xFF;
|
||||
}
|
||||
while(--p->CacheSize != 0);
|
||||
while (--p->CacheSize != 0);
|
||||
p->Cache = (Byte)((UInt32)p->Low >> 24);
|
||||
}
|
||||
p->CacheSize++;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
/* Ppmd8.c -- PPMdI codec
|
||||
2013-11-12 : Igor Pavlov : Public domain
|
||||
2015-09-28 : Igor Pavlov : Public domain
|
||||
This code is based on PPMd var.I (2002): Dmitry Shkarin : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
#include <memory.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "Ppmd8.h"
|
||||
|
||||
@@ -67,7 +67,7 @@ void Ppmd8_Construct(CPpmd8 *p)
|
||||
for (i = 0, k = 0; i < PPMD_NUM_INDEXES; i++)
|
||||
{
|
||||
unsigned step = (i >= 12 ? 4 : (i >> 2) + 1);
|
||||
do { p->Units2Indx[k++] = (Byte)i; } while(--step);
|
||||
do { p->Units2Indx[k++] = (Byte)i; } while (--step);
|
||||
p->Indx2Units[i] = (Byte)k;
|
||||
}
|
||||
|
||||
@@ -241,7 +241,7 @@ static void *AllocUnits(CPpmd8 *p, unsigned indx)
|
||||
|
||||
#define MyMem12Cpy(dest, src, num) \
|
||||
{ UInt32 *d = (UInt32 *)dest; const UInt32 *s = (const UInt32 *)src; UInt32 n = num; \
|
||||
do { d[0] = s[0]; d[1] = s[1]; d[2] = s[2]; s += 3; d += 3; } while(--n); }
|
||||
do { d[0] = s[0]; d[1] = s[1]; d[2] = s[2]; s += 3; d += 3; } while (--n); }
|
||||
|
||||
static void *ShrinkUnits(CPpmd8 *p, void *oldPtr, unsigned oldNU, unsigned newNU)
|
||||
{
|
||||
|
||||
37
C/Sha256.c
37
C/Sha256.c
@@ -1,5 +1,5 @@
|
||||
/* Crypto/Sha256.c -- SHA-256 Hash
|
||||
2015-03-02 : Igor Pavlov : Public domain
|
||||
2015-11-14 : Igor Pavlov : Public domain
|
||||
This code is based on public domain code from Wei Dai's Crypto++ library. */
|
||||
|
||||
#include "Precomp.h"
|
||||
@@ -113,10 +113,26 @@ static void Sha256_WriteByteBlock(CSha256 *p)
|
||||
{
|
||||
UInt32 W[16];
|
||||
unsigned j;
|
||||
UInt32 *state = p->state;
|
||||
UInt32 *state;
|
||||
|
||||
#ifdef _SHA256_UNROLL2
|
||||
UInt32 a,b,c,d,e,f,g,h;
|
||||
#else
|
||||
UInt32 T[8];
|
||||
#endif
|
||||
|
||||
for (j = 0; j < 16; j += 4)
|
||||
{
|
||||
const Byte *ccc = p->buffer + j * 4;
|
||||
W[j ] = GetBe32(ccc);
|
||||
W[j + 1] = GetBe32(ccc + 4);
|
||||
W[j + 2] = GetBe32(ccc + 8);
|
||||
W[j + 3] = GetBe32(ccc + 12);
|
||||
}
|
||||
|
||||
state = p->state;
|
||||
|
||||
#ifdef _SHA256_UNROLL2
|
||||
a = state[0];
|
||||
b = state[1];
|
||||
c = state[2];
|
||||
@@ -126,17 +142,10 @@ static void Sha256_WriteByteBlock(CSha256 *p)
|
||||
g = state[6];
|
||||
h = state[7];
|
||||
#else
|
||||
UInt32 T[8];
|
||||
for (j = 0; j < 8; j++)
|
||||
T[j] = state[j];
|
||||
#endif
|
||||
|
||||
for (j = 0; j < 16; j += 2)
|
||||
{
|
||||
W[j ] = GetBe32(p->buffer + j * 4);
|
||||
W[j + 1] = GetBe32(p->buffer + j * 4 + 4);
|
||||
}
|
||||
|
||||
for (j = 0; j < 64; j += 16)
|
||||
{
|
||||
RX_16
|
||||
@@ -226,11 +235,13 @@ void Sha256_Final(CSha256 *p, Byte *digest)
|
||||
|
||||
Sha256_WriteByteBlock(p);
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
for (i = 0; i < 8; i += 2)
|
||||
{
|
||||
UInt32 v = p->state[i];
|
||||
SetBe32(digest, v);
|
||||
digest += 4;
|
||||
UInt32 v0 = p->state[i];
|
||||
UInt32 v1 = p->state[i + 1];
|
||||
SetBe32(digest , v0);
|
||||
SetBe32(digest + 4, v1);
|
||||
digest += 8;
|
||||
}
|
||||
|
||||
Sha256_Init(p);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* 7zMain.c - Test application for 7z Decoder
|
||||
2015-05-11 : Igor Pavlov : Public domain */
|
||||
2015-08-02 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
@@ -328,22 +328,20 @@ void PrintError(char *sz)
|
||||
printf("\nERROR: %s\n", sz);
|
||||
}
|
||||
|
||||
#ifdef USE_WINDOWS_FILE
|
||||
static void GetAttribString(UInt32 wa, Bool isDir, char *s)
|
||||
{
|
||||
#ifdef USE_WINDOWS_FILE
|
||||
s[0] = (char)(((wa & FILE_ATTRIBUTE_DIRECTORY) != 0 || isDir) ? 'D' : '.');
|
||||
s[1] = (char)(((wa & FILE_ATTRIBUTE_READONLY ) != 0) ? 'R': '.');
|
||||
s[2] = (char)(((wa & FILE_ATTRIBUTE_HIDDEN ) != 0) ? 'H': '.');
|
||||
s[3] = (char)(((wa & FILE_ATTRIBUTE_SYSTEM ) != 0) ? 'S': '.');
|
||||
s[4] = (char)(((wa & FILE_ATTRIBUTE_ARCHIVE ) != 0) ? 'A': '.');
|
||||
s[5] = '\0';
|
||||
s[5] = 0;
|
||||
#else
|
||||
s[0] = (char)(((wa & (1 << 4)) != 0 || isDir) ? 'D' : '.');
|
||||
s[1] = 0;
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
static void GetAttribString(UInt32, Bool, char *s)
|
||||
{
|
||||
s[0] = '\0';
|
||||
}
|
||||
#endif
|
||||
|
||||
// #define NUM_PARENTS_MAX 128
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
PROG = 7zDec
|
||||
CXX = g++
|
||||
CXX = gcc
|
||||
LIB =
|
||||
RM = rm -f
|
||||
CFLAGS = -c -O2 -Wall
|
||||
|
||||
OBJS = 7zMain.o 7zAlloc.o 7zArcIn.o 7zBuf.o 7zBuf2.o 7zCrc.o 7zCrcOpt.o 7zDec.o CpuArch.o LzmaDec.o Lzma2Dec.o Bra.o Bra86.o Bcj2.o Ppmd7.o Ppmd7Dec.o 7zFile.o 7zStream.o
|
||||
OBJS = 7zMain.o 7zAlloc.o 7zArcIn.o 7zBuf.o 7zBuf2.o 7zCrc.o 7zCrcOpt.o 7zDec.o CpuArch.o Delta.o LzmaDec.o Lzma2Dec.o Bra.o Bra86.o BraIA64.o Bcj2.o Ppmd7.o Ppmd7Dec.o 7zFile.o 7zStream.o
|
||||
|
||||
all: $(PROG)
|
||||
|
||||
@@ -38,6 +38,9 @@ $(PROG): $(OBJS)
|
||||
CpuArch.o: ../../CpuArch.c
|
||||
$(CXX) $(CFLAGS) ../../CpuArch.c
|
||||
|
||||
Delta.o: ../../Delta.c
|
||||
$(CXX) $(CFLAGS) ../../Delta.c
|
||||
|
||||
LzmaDec.o: ../../LzmaDec.c
|
||||
$(CXX) $(CFLAGS) ../../LzmaDec.c
|
||||
|
||||
@@ -50,6 +53,9 @@ Bra.o: ../../Bra.c
|
||||
Bra86.o: ../../Bra86.c
|
||||
$(CXX) $(CFLAGS) ../../Bra86.c
|
||||
|
||||
BraIA64.o: ../../BraIA64.c
|
||||
$(CXX) $(CFLAGS) ../../BraIA64.c
|
||||
|
||||
Bcj2.o: ../../Bcj2.c
|
||||
$(CXX) $(CFLAGS) ../../Bcj2.c
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* 7zipInnstall.c - 7-Zip Installer
|
||||
2015-06-13 : Igor Pavlov : Public domain */
|
||||
/* 7zipInstall.c - 7-Zip Installer
|
||||
2015-11-08 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
@@ -37,7 +37,7 @@ static const WCHAR *k_Reg_Software_7zip = L"Software\\7-Zip";
|
||||
#define k_7zip_with_Ver_base L"7-Zip " LLL(MY_VERSION)
|
||||
|
||||
#ifdef _64BIT_INSTALLER
|
||||
#define k_7zip_with_Ver k_7zip_with_Ver_base L" x64"
|
||||
#define k_7zip_with_Ver k_7zip_with_Ver_base L" (x64)"
|
||||
#else
|
||||
#define k_7zip_with_Ver k_7zip_with_Ver_base
|
||||
#endif
|
||||
@@ -84,6 +84,8 @@ static HWND g_Path_HWND;
|
||||
static HWND g_InfoLine_HWND;
|
||||
static HWND g_Progress_HWND;
|
||||
|
||||
static DWORD g_TotalSize;
|
||||
|
||||
static WCHAR path[MAX_PATH * 2 + 40];
|
||||
|
||||
|
||||
@@ -143,7 +145,7 @@ static WRes CreateComplexDir()
|
||||
|
||||
if (IS_DRIVE_PATH(s))
|
||||
prefixSize = 3;
|
||||
else if (IS_SEPAR(s[1]) && IS_SEPAR(s[1]))
|
||||
else if (IS_SEPAR(s[0]) && IS_SEPAR(s[1]))
|
||||
prefixSize = 2;
|
||||
else
|
||||
return ERROR_INVALID_NAME;
|
||||
@@ -259,7 +261,7 @@ static LONG MyRegistry_CreateKeyAndVal(HKEY parentKey, LPCWSTR keyName, LPCWSTR
|
||||
if (res == ERROR_SUCCESS)
|
||||
{
|
||||
res = MyRegistry_SetString(destKey, valName, val);
|
||||
res = RegCloseKey(destKey);
|
||||
/* res = */ RegCloseKey(destKey);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -282,7 +284,7 @@ static LONG MyRegistry_CreateKeyAndVal_32(HKEY parentKey, LPCWSTR keyName, LPCWS
|
||||
if (res == ERROR_SUCCESS)
|
||||
{
|
||||
res = MyRegistry_SetString(destKey, valName, val);
|
||||
res = RegCloseKey(destKey);
|
||||
/* res = */ RegCloseKey(destKey);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -320,7 +322,7 @@ static Bool FindSignature(CSzFile *stream, UInt64 *resPos)
|
||||
processed -= k7zStartHeaderSize;
|
||||
for (pos = 0; pos <= processed; pos++)
|
||||
{
|
||||
for (; buf[pos] != '7' && pos <= processed; pos++);
|
||||
for (; pos <= processed && buf[pos] != '7'; pos++);
|
||||
if (pos > processed)
|
||||
break;
|
||||
if (memcmp(buf + pos, k7zSignature, k7zSignatureSize) == 0)
|
||||
@@ -596,8 +598,8 @@ static LONG SetRegKey_Path2(HKEY parentKey)
|
||||
if (res == ERROR_SUCCESS)
|
||||
{
|
||||
res = MyRegistry_SetString(destKey, k_Reg_Path32, path);
|
||||
res = MyRegistry_SetString(destKey, k_Reg_Path, path);
|
||||
res = RegCloseKey(destKey);
|
||||
/* res = */ MyRegistry_SetString(destKey, k_Reg_Path, path);
|
||||
/* res = */ RegCloseKey(destKey);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -716,10 +718,10 @@ static void WriteCLSID()
|
||||
WCHAR destPath[MAX_PATH + 10];
|
||||
wcscpy(destPath, path);
|
||||
wcscat(destPath, L"7-zip32.dll");
|
||||
res = MyRegistry_SetString(destKey, NULL, destPath);
|
||||
res = MyRegistry_SetString(destKey, L"ThreadingModel", L"Apartment");
|
||||
/* res = */ MyRegistry_SetString(destKey, NULL, destPath);
|
||||
/* res = */ MyRegistry_SetString(destKey, L"ThreadingModel", L"Apartment");
|
||||
// DeleteRegValue(destKey, L"InprocServer32");
|
||||
res = RegCloseKey(destKey);
|
||||
/* res = */ RegCloseKey(destKey);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -735,10 +737,10 @@ static void WriteCLSID()
|
||||
WCHAR destPath[MAX_PATH + 10];
|
||||
wcscpy(destPath, path);
|
||||
wcscat(destPath, L"7-zip.dll");
|
||||
res = MyRegistry_SetString(destKey, NULL, destPath);
|
||||
res = MyRegistry_SetString(destKey, L"ThreadingModel", L"Apartment");
|
||||
/* res = */ MyRegistry_SetString(destKey, NULL, destPath);
|
||||
/* res = */ MyRegistry_SetString(destKey, L"ThreadingModel", L"Apartment");
|
||||
// DeleteRegValue(destKey, L"InprocServer32");
|
||||
res = RegCloseKey(destKey);
|
||||
/* res = */ RegCloseKey(destKey);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -796,16 +798,30 @@ static void WriteShellEx()
|
||||
// wcscpy(destPath, path);
|
||||
// wcscat(destPath, L"7zFM.exe");
|
||||
MyRegistry_SetString(destKey, L"DisplayName", k_7zip_with_Ver_str);
|
||||
MyRegistry_SetString(destKey, L"DisplayVersion", LLL(MY_VERSION_NUMBERS));
|
||||
|
||||
MyRegistry_SetString(destKey, L"DisplayIcon", destPath);
|
||||
|
||||
wcscpy(destPath, path);
|
||||
// MyRegistry_SetString(destKey, L"InstallLocation", destPath);
|
||||
MyRegistry_SetString(destKey, L"InstallLocation", destPath);
|
||||
wcscat(destPath, L"Uninstall.exe");
|
||||
// wcscat(destPath, L"\"");
|
||||
MyRegistry_SetString(destKey, L"UninstallString", destPath);
|
||||
|
||||
MyRegistry_SetDWORD(destKey, L"NoModify", 1);
|
||||
MyRegistry_SetDWORD(destKey, L"NoRepair", 1);
|
||||
|
||||
MyRegistry_SetDWORD(destKey, L"EstimatedSize", g_TotalSize >> 10);
|
||||
|
||||
MyRegistry_SetDWORD(destKey, L"VersionMajor", MY_VER_MAJOR);
|
||||
MyRegistry_SetDWORD(destKey, L"VersionMinor", MY_VER_MINOR);
|
||||
|
||||
MyRegistry_SetString(destKey, L"Publisher", LLL(MY_AUTHOR_NAME));
|
||||
|
||||
// MyRegistry_SetString(destKey, L"HelpLink", L"http://www.7-zip.org/support.html");
|
||||
// MyRegistry_SetString(destKey, L"URLInfoAbout", L"http://www.7-zip.org/");
|
||||
// MyRegistry_SetString(destKey, L"URLUpdateInfo", L"http://www.7-zip.org/");
|
||||
|
||||
RegCloseKey(destKey);
|
||||
}
|
||||
}
|
||||
@@ -1067,7 +1083,6 @@ static int Install()
|
||||
WCHAR sfxPath[MAX_PATH + 2];
|
||||
|
||||
Bool needReboot = False;
|
||||
size_t pathLen;
|
||||
|
||||
allocImp.Alloc = SzAlloc;
|
||||
allocImp.Free = SzFree;
|
||||
@@ -1100,6 +1115,7 @@ static int Install()
|
||||
|
||||
if (res == SZ_OK)
|
||||
{
|
||||
size_t pathLen;
|
||||
if (!g_SilentMode)
|
||||
{
|
||||
GetDlgItemTextW(g_HWND, IDE_EXTRACT_PATH, path, MAX_PATH);
|
||||
@@ -1108,6 +1124,23 @@ if (res == SZ_OK)
|
||||
FileInStream_CreateVTable(&archiveStream);
|
||||
LookToRead_CreateVTable(&lookStream, False);
|
||||
|
||||
{
|
||||
// Remove post spaces
|
||||
unsigned endPos = 0;
|
||||
unsigned i = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
wchar_t c = path[i++];
|
||||
if (c == 0)
|
||||
break;
|
||||
if (c != ' ')
|
||||
endPos = i;
|
||||
}
|
||||
|
||||
path[endPos] = 0;
|
||||
}
|
||||
|
||||
NormalizePrefix(path);
|
||||
winRes = CreateComplexDir();
|
||||
|
||||
@@ -1128,9 +1161,11 @@ if (res == SZ_OK)
|
||||
if (res == SZ_OK)
|
||||
{
|
||||
UInt32 i;
|
||||
UInt32 blockIndex = 0xFFFFFFFF; /* it can have any value before first call, if(!outBuf) */
|
||||
UInt32 blockIndex = 0xFFFFFFFF; /* it can have any value before first call, if (!outBuf) */
|
||||
Byte *outBuf = NULL; /* it must be NULL before first call for each new archive. */
|
||||
size_t outBufSize = 0; /* it can have any value before first call, if(!outBuf) */
|
||||
size_t outBufSize = 0; /* it can have any value before first call, if (!outBuf) */
|
||||
|
||||
g_TotalSize = 0;
|
||||
|
||||
if (!g_SilentMode)
|
||||
{
|
||||
@@ -1309,6 +1344,8 @@ if (res == SZ_OK)
|
||||
res = SZ_ERROR_FAIL;
|
||||
}
|
||||
|
||||
g_TotalSize += (DWORD)outSizeProcessed;
|
||||
|
||||
#ifdef USE_WINDOWS_FILE
|
||||
if (SzBitWithVals_Check(&db.MTime, i))
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#define IDD_INSTALL 100
|
||||
#define IDD_INSTALL 100
|
||||
|
||||
#define IDT_EXTRACT_EXTRACT_TO 110
|
||||
#define IDT_EXTRACT_EXTRACT_TO 110
|
||||
#define IDE_EXTRACT_PATH 111
|
||||
#define IDB_EXTRACT_SET_PATH 112
|
||||
#define IDT_CUR_FILE 113
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* 7zipUninstall.c - 7-Zip Uninstaller
|
||||
2015-06-13 : Igor Pavlov : Public domain */
|
||||
2015-11-08 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#define k_7zip_with_Ver_base L"7-Zip " LLL(MY_VERSION)
|
||||
|
||||
#ifdef _64BIT_INSTALLER
|
||||
#define k_7zip_with_Ver k_7zip_with_Ver_base L" x64"
|
||||
#define k_7zip_with_Ver k_7zip_with_Ver_base L" (x64)"
|
||||
#else
|
||||
#define k_7zip_with_Ver k_7zip_with_Ver_base
|
||||
#endif
|
||||
@@ -384,7 +384,7 @@ static void WriteCLSID()
|
||||
if (res == ERROR_SUCCESS)
|
||||
{
|
||||
RegDeleteValueW(destKey, k_7zip_CLSID);
|
||||
res = RegCloseKey(destKey);
|
||||
/* res = */ RegCloseKey(destKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -419,7 +419,7 @@ static void WriteCLSID()
|
||||
if (res == ERROR_SUCCESS)
|
||||
{
|
||||
RegDeleteValueW(destKey, k_7zip_CLSID);
|
||||
res = RegCloseKey(destKey);
|
||||
/* res = */ RegCloseKey(destKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#define IDD_INSTALL 100
|
||||
#define IDD_INSTALL 100
|
||||
|
||||
#define IDT_EXTRACT_EXTRACT_TO 110
|
||||
#define IDT_EXTRACT_EXTRACT_TO 110
|
||||
#define IDE_EXTRACT_PATH 111
|
||||
|
||||
#define IDT_CUR_FILE 113
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* LzmaUtil.c -- Test application for LZMA compression
|
||||
2015-06-13 : Igor Pavlov : Public domain */
|
||||
2015-11-08 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "../../Precomp.h"
|
||||
|
||||
@@ -133,7 +133,7 @@ static SRes Encode(ISeqOutStream *outStream, ISeqInStream *inStream, UInt64 file
|
||||
SRes res;
|
||||
CLzmaEncProps props;
|
||||
|
||||
rs = rs;
|
||||
UNUSED_VAR(rs);
|
||||
|
||||
enc = LzmaEnc_Create(&g_Alloc);
|
||||
if (enc == 0)
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
/* LzmaLibExports.c -- LZMA library DLL Entry point
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
2015-11-08 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "../../Precomp.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
|
||||
{
|
||||
hInstance = hInstance;
|
||||
dwReason = dwReason;
|
||||
lpReserved = lpReserved;
|
||||
UNUSED_VAR(hInstance);
|
||||
UNUSED_VAR(dwReason);
|
||||
UNUSED_VAR(lpReserved);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* SfxSetup.c - 7z SFX Setup
|
||||
2015-03-25 : Igor Pavlov : Public domain */
|
||||
2015-11-08 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
@@ -88,7 +88,7 @@ static unsigned FindItem(const char * const *items, unsigned num, const wchar_t
|
||||
#ifdef _CONSOLE
|
||||
static BOOL WINAPI HandlerRoutine(DWORD ctrlType)
|
||||
{
|
||||
ctrlType = ctrlType;
|
||||
UNUSED_VAR(ctrlType);
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
@@ -144,7 +144,7 @@ static Bool FindSignature(CSzFile *stream, UInt64 *resPos)
|
||||
processed -= k7zStartHeaderSize;
|
||||
for (pos = 0; pos <= processed; pos++)
|
||||
{
|
||||
for (; buf[pos] != '7' && pos <= processed; pos++);
|
||||
for (; pos <= processed && buf[pos] != '7'; pos++);
|
||||
if (pos > processed)
|
||||
break;
|
||||
if (memcmp(buf + pos, k7zSignature, k7zSignatureSize) == 0)
|
||||
@@ -257,10 +257,10 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
||||
#ifdef _CONSOLE
|
||||
SetConsoleCtrlHandler(HandlerRoutine, TRUE);
|
||||
#else
|
||||
hInstance = hInstance;
|
||||
hPrevInstance = hPrevInstance;
|
||||
lpCmdLine = lpCmdLine;
|
||||
nCmdShow = nCmdShow;
|
||||
UNUSED_VAR(hInstance);
|
||||
UNUSED_VAR(hPrevInstance);
|
||||
UNUSED_VAR(lpCmdLine);
|
||||
UNUSED_VAR(nCmdShow);
|
||||
#endif
|
||||
|
||||
CrcGenerateTable();
|
||||
|
||||
16
C/XzDec.c
16
C/XzDec.c
@@ -1,5 +1,5 @@
|
||||
/* XzDec.c -- Xz Decode
|
||||
2015-05-01 : Igor Pavlov : Public domain */
|
||||
2015-11-09 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
@@ -74,7 +74,7 @@ static void BraState_Free(void *pp, ISzAlloc *alloc)
|
||||
static SRes BraState_SetProps(void *pp, const Byte *props, size_t propSize, ISzAlloc *alloc)
|
||||
{
|
||||
CBraState *p = ((CBraState *)pp);
|
||||
alloc = alloc;
|
||||
UNUSED_VAR(alloc);
|
||||
p->ip = 0;
|
||||
if (p->methodId == XZ_ID_Delta)
|
||||
{
|
||||
@@ -129,9 +129,9 @@ static SRes BraState_Code(void *pp, Byte *dest, SizeT *destLen, const Byte *src,
|
||||
CBraState *p = ((CBraState *)pp);
|
||||
SizeT destLenOrig = *destLen;
|
||||
SizeT srcLenOrig = *srcLen;
|
||||
UNUSED_VAR(finishMode);
|
||||
*destLen = 0;
|
||||
*srcLen = 0;
|
||||
finishMode = finishMode;
|
||||
*wasFinished = 0;
|
||||
while (destLenOrig > 0)
|
||||
{
|
||||
@@ -236,8 +236,8 @@ static void SbState_Free(void *pp, ISzAlloc *alloc)
|
||||
static SRes SbState_SetProps(void *pp, const Byte *props, size_t propSize, ISzAlloc *alloc)
|
||||
{
|
||||
UNUSED_VAR(pp);
|
||||
props = props;
|
||||
alloc = alloc;
|
||||
UNUSED_VAR(props);
|
||||
UNUSED_VAR(alloc);
|
||||
return (propSize == 0) ? SZ_OK : SZ_ERROR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
@@ -251,7 +251,7 @@ static SRes SbState_Code(void *pp, Byte *dest, SizeT *destLen, const Byte *src,
|
||||
{
|
||||
CSbDec *p = (CSbDec *)pp;
|
||||
SRes res;
|
||||
srcWasFinished = srcWasFinished;
|
||||
UNUSED_VAR(srcWasFinished);
|
||||
p->dest = dest;
|
||||
p->destLen = *destLen;
|
||||
p->src = src;
|
||||
@@ -308,7 +308,7 @@ static SRes Lzma2State_Code(void *pp, Byte *dest, SizeT *destLen, const Byte *sr
|
||||
ELzmaStatus status;
|
||||
/* ELzmaFinishMode fm = (finishMode == LZMA_FINISH_ANY) ? LZMA_FINISH_ANY : LZMA_FINISH_END; */
|
||||
SRes res = Lzma2Dec_DecodeToBuf((CLzma2Dec *)pp, dest, destLen, src, srcLen, (ELzmaFinishMode)finishMode, &status);
|
||||
srcWasFinished = srcWasFinished;
|
||||
UNUSED_VAR(srcWasFinished);
|
||||
*wasFinished = (status == LZMA_STATUS_FINISHED_WITH_MARK);
|
||||
return res;
|
||||
}
|
||||
@@ -555,7 +555,7 @@ SRes XzBlock_Parse(CXzBlock *p, const Byte *header)
|
||||
pos += (unsigned)size;
|
||||
|
||||
#ifdef XZ_DUMP
|
||||
printf("\nf[%d] = %2X: ", i, filter->id);
|
||||
printf("\nf[%u] = %2X: ", i, (unsigned)filter->id);
|
||||
{
|
||||
unsigned i;
|
||||
for (i = 0; i < size; i++)
|
||||
|
||||
65
C/XzEnc.c
65
C/XzEnc.c
@@ -1,5 +1,5 @@
|
||||
/* XzEnc.c -- Xz Encode
|
||||
2015-05-01 : Igor Pavlov : Public domain */
|
||||
2015-09-16 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "Alloc.h"
|
||||
#include "Bra.h"
|
||||
#include "CpuArch.h"
|
||||
|
||||
#ifdef USE_SUBBLOCK
|
||||
#include "Bcj3Enc.c"
|
||||
#include "SbFind.c"
|
||||
@@ -34,7 +35,7 @@ static SRes WriteBytesAndCrc(ISeqOutStream *s, const void *buf, UInt32 size, UIn
|
||||
return WriteBytes(s, buf, size);
|
||||
}
|
||||
|
||||
SRes Xz_WriteHeader(CXzStreamFlags f, ISeqOutStream *s)
|
||||
static SRes Xz_WriteHeader(CXzStreamFlags f, ISeqOutStream *s)
|
||||
{
|
||||
UInt32 crc;
|
||||
Byte header[XZ_STREAM_HEADER_SIZE];
|
||||
@@ -46,7 +47,8 @@ SRes Xz_WriteHeader(CXzStreamFlags f, ISeqOutStream *s)
|
||||
return WriteBytes(s, header, XZ_STREAM_HEADER_SIZE);
|
||||
}
|
||||
|
||||
SRes XzBlock_WriteHeader(const CXzBlock *p, ISeqOutStream *s)
|
||||
|
||||
static SRes XzBlock_WriteHeader(const CXzBlock *p, ISeqOutStream *s)
|
||||
{
|
||||
Byte header[XZ_BLOCK_HEADER_SIZE_MAX];
|
||||
|
||||
@@ -75,7 +77,8 @@ SRes XzBlock_WriteHeader(const CXzBlock *p, ISeqOutStream *s)
|
||||
return WriteBytes(s, header, pos + 4);
|
||||
}
|
||||
|
||||
SRes Xz_WriteFooter(CXzStream *p, ISeqOutStream *s)
|
||||
|
||||
static SRes Xz_WriteFooter(CXzStream *p, ISeqOutStream *s)
|
||||
{
|
||||
Byte buf[32];
|
||||
UInt64 globalPos;
|
||||
@@ -87,6 +90,7 @@ SRes Xz_WriteFooter(CXzStream *p, ISeqOutStream *s)
|
||||
globalPos = pos;
|
||||
buf[0] = 0;
|
||||
RINOK(WriteBytesAndCrc(s, buf, pos, &crc));
|
||||
|
||||
for (i = 0; i < p->numBlocks; i++)
|
||||
{
|
||||
const CXzBlockSizes *block = &p->blocks[i];
|
||||
@@ -95,7 +99,9 @@ SRes Xz_WriteFooter(CXzStream *p, ISeqOutStream *s)
|
||||
globalPos += pos;
|
||||
RINOK(WriteBytesAndCrc(s, buf, pos, &crc));
|
||||
}
|
||||
|
||||
pos = ((unsigned)globalPos & 3);
|
||||
|
||||
if (pos != 0)
|
||||
{
|
||||
buf[0] = buf[1] = buf[2] = 0;
|
||||
@@ -120,34 +126,36 @@ SRes Xz_WriteFooter(CXzStream *p, ISeqOutStream *s)
|
||||
}
|
||||
}
|
||||
|
||||
SRes Xz_AddIndexRecord(CXzStream *p, UInt64 unpackSize, UInt64 totalSize, ISzAlloc *alloc)
|
||||
|
||||
static SRes Xz_AddIndexRecord(CXzStream *p, UInt64 unpackSize, UInt64 totalSize, ISzAlloc *alloc)
|
||||
{
|
||||
if (p->blocks == 0 || p->numBlocksAllocated == p->numBlocks)
|
||||
if (!p->blocks || p->numBlocksAllocated == p->numBlocks)
|
||||
{
|
||||
size_t num = (p->numBlocks + 1) * 2;
|
||||
size_t num = p->numBlocks * 2 + 1;
|
||||
size_t newSize = sizeof(CXzBlockSizes) * num;
|
||||
CXzBlockSizes *blocks;
|
||||
if (newSize / sizeof(CXzBlockSizes) != num)
|
||||
return SZ_ERROR_MEM;
|
||||
blocks = (CXzBlockSizes *)alloc->Alloc(alloc, newSize);
|
||||
if (blocks == 0)
|
||||
if (!blocks)
|
||||
return SZ_ERROR_MEM;
|
||||
if (p->numBlocks != 0)
|
||||
{
|
||||
memcpy(blocks, p->blocks, p->numBlocks * sizeof(CXzBlockSizes));
|
||||
Xz_Free(p, alloc);
|
||||
alloc->Free(alloc, p->blocks);
|
||||
}
|
||||
p->blocks = blocks;
|
||||
p->numBlocksAllocated = num;
|
||||
}
|
||||
{
|
||||
CXzBlockSizes *block = &p->blocks[p->numBlocks++];
|
||||
block->totalSize = totalSize;
|
||||
block->unpackSize = unpackSize;
|
||||
block->totalSize = totalSize;
|
||||
}
|
||||
return SZ_OK;
|
||||
}
|
||||
|
||||
|
||||
/* ---------- CSeqCheckInStream ---------- */
|
||||
|
||||
typedef struct
|
||||
@@ -178,6 +186,7 @@ static SRes SeqCheckInStream_Read(void *pp, void *data, size_t *size)
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
/* ---------- CSeqSizeOutStream ---------- */
|
||||
|
||||
typedef struct
|
||||
@@ -195,6 +204,7 @@ static size_t MyWrite(void *pp, const void *data, size_t size)
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
/* ---------- CSeqInFilter ---------- */
|
||||
|
||||
#define FILTER_BUF_SIZE (1 << 20)
|
||||
@@ -217,6 +227,7 @@ static SRes SeqInFilter_Read(void *pp, void *data, size_t *size)
|
||||
if (sizeOriginal == 0)
|
||||
return SZ_OK;
|
||||
*size = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (!p->srcWasFinished && p->curPos == p->endPos)
|
||||
@@ -274,6 +285,7 @@ static SRes SeqInFilter_Init(CSeqInFilter *p, const CXzFilter *props)
|
||||
return SZ_OK;
|
||||
}
|
||||
|
||||
|
||||
/* ---------- CSbEncInStream ---------- */
|
||||
|
||||
#ifdef USE_SUBBLOCK
|
||||
@@ -291,6 +303,7 @@ static SRes SbEncInStream_Read(void *pp, void *data, size_t *size)
|
||||
size_t sizeOriginal = *size;
|
||||
if (sizeOriginal == 0)
|
||||
return S_OK;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (p->enc.needRead && !p->enc.readWasFinished)
|
||||
@@ -305,6 +318,7 @@ static SRes SbEncInStream_Read(void *pp, void *data, size_t *size)
|
||||
}
|
||||
p->enc.needRead = False;
|
||||
}
|
||||
|
||||
*size = sizeOriginal;
|
||||
RINOK(SbEnc_Read(&p->enc, data, size));
|
||||
if (*size != 0 || !p->enc.needRead)
|
||||
@@ -357,7 +371,7 @@ static void Lzma2WithFilters_Construct(CLzma2WithFilters *p, ISzAlloc *alloc, IS
|
||||
static SRes Lzma2WithFilters_Create(CLzma2WithFilters *p)
|
||||
{
|
||||
p->lzma2 = Lzma2Enc_Create(p->alloc, p->bigAlloc);
|
||||
if (p->lzma2 == 0)
|
||||
if (!p->lzma2)
|
||||
return SZ_ERROR_MEM;
|
||||
return SZ_OK;
|
||||
}
|
||||
@@ -375,10 +389,11 @@ static void Lzma2WithFilters_Free(CLzma2WithFilters *p)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void XzProps_Init(CXzProps *p)
|
||||
{
|
||||
p->lzma2Props = 0;
|
||||
p->filterProps = 0;
|
||||
p->lzma2Props = NULL;
|
||||
p->filterProps = NULL;
|
||||
p->checkId = XZ_CHECK_CRC32;
|
||||
}
|
||||
|
||||
@@ -386,10 +401,11 @@ void XzFilterProps_Init(CXzFilterProps *p)
|
||||
{
|
||||
p->id = 0;
|
||||
p->delta = 0;
|
||||
p->ip= 0;
|
||||
p->ip = 0;
|
||||
p->ipDefined = False;
|
||||
}
|
||||
|
||||
|
||||
static SRes Xz_Compress(CXzStream *xz, CLzma2WithFilters *lzmaf,
|
||||
ISeqOutStream *outStream, ISeqInStream *inStream,
|
||||
const CXzProps *props, ICompressProgress *progress)
|
||||
@@ -415,6 +431,7 @@ static SRes Xz_Compress(CXzStream *xz, CLzma2WithFilters *lzmaf,
|
||||
filter = &block.filters[filterIndex++];
|
||||
filter->id = fp->id;
|
||||
filter->propsSize = 0;
|
||||
|
||||
if (fp->id == XZ_ID_Delta)
|
||||
{
|
||||
filter->props[0] = (Byte)(fp->delta - 1);
|
||||
@@ -462,14 +479,16 @@ static SRes Xz_Compress(CXzStream *xz, CLzma2WithFilters *lzmaf,
|
||||
|
||||
{
|
||||
UInt64 packPos = seqSizeOutStream.processed;
|
||||
|
||||
SRes res = Lzma2Enc_Encode(lzmaf->lzma2, &seqSizeOutStream.p,
|
||||
fp ?
|
||||
#ifdef USE_SUBBLOCK
|
||||
(fp->id == XZ_ID_Subblock) ? &lzmaf->sb.p:
|
||||
#endif
|
||||
&lzmaf->filter.p:
|
||||
&checkInStream.p,
|
||||
progress);
|
||||
fp ?
|
||||
#ifdef USE_SUBBLOCK
|
||||
(fp->id == XZ_ID_Subblock) ? &lzmaf->sb.p:
|
||||
#endif
|
||||
&lzmaf->filter.p:
|
||||
&checkInStream.p,
|
||||
progress);
|
||||
|
||||
RINOK(res);
|
||||
block.unpackSize = checkInStream.processed;
|
||||
block.packSize = seqSizeOutStream.processed - packPos;
|
||||
@@ -478,7 +497,7 @@ static SRes Xz_Compress(CXzStream *xz, CLzma2WithFilters *lzmaf,
|
||||
{
|
||||
unsigned padSize = 0;
|
||||
Byte buf[128];
|
||||
while((((unsigned)block.packSize + padSize) & 3) != 0)
|
||||
while ((((unsigned)block.packSize + padSize) & 3) != 0)
|
||||
buf[padSize++] = 0;
|
||||
SeqCheckInStream_GetDigest(&checkInStream, buf + padSize);
|
||||
RINOK(WriteBytes(&seqSizeOutStream.p, buf, padSize + XzFlags_GetCheckSize(xz->flags)));
|
||||
@@ -488,6 +507,7 @@ static SRes Xz_Compress(CXzStream *xz, CLzma2WithFilters *lzmaf,
|
||||
return Xz_WriteFooter(xz, outStream);
|
||||
}
|
||||
|
||||
|
||||
SRes Xz_Encode(ISeqOutStream *outStream, ISeqInStream *inStream,
|
||||
const CXzProps *props, ICompressProgress *progress)
|
||||
{
|
||||
@@ -504,6 +524,7 @@ SRes Xz_Encode(ISeqOutStream *outStream, ISeqInStream *inStream,
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
SRes Xz_EncodeEmpty(ISeqOutStream *outStream)
|
||||
{
|
||||
SRes res;
|
||||
|
||||
5
C/XzIn.c
5
C/XzIn.c
@@ -1,5 +1,5 @@
|
||||
/* XzIn.c - Xz input
|
||||
2015-04-21 : Igor Pavlov : Public domain */
|
||||
2015-11-08 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
@@ -72,7 +72,7 @@ SRes XzBlock_ReadFooter(CXzBlock *p, CXzStreamFlags f, ISeqInStream *inStream)
|
||||
|
||||
static SRes Xz_ReadIndex2(CXzStream *p, const Byte *buf, size_t size, ISzAlloc *alloc)
|
||||
{
|
||||
size_t i, numBlocks, pos = 1;
|
||||
size_t numBlocks, pos = 1;
|
||||
UInt32 crc;
|
||||
|
||||
if (size < 5 || buf[0] != 0)
|
||||
@@ -94,6 +94,7 @@ static SRes Xz_ReadIndex2(CXzStream *p, const Byte *buf, size_t size, ISzAlloc *
|
||||
Xz_Free(p, alloc);
|
||||
if (numBlocks != 0)
|
||||
{
|
||||
size_t i;
|
||||
p->numBlocks = numBlocks;
|
||||
p->numBlocksAllocated = numBlocks;
|
||||
p->blocks = alloc->Alloc(alloc, sizeof(CXzBlockSizes) * numBlocks);
|
||||
|
||||
@@ -158,14 +158,6 @@ SOURCE=.\7zFolderInStream.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\7zFolderOutStream.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\7zFolderOutStream.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\7zHandler.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@@ -350,14 +342,6 @@ SOURCE=..\Common\CoderMixer2.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Common\CrossThreadProgress.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Common\CrossThreadProgress.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Common\HandlerOut.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
@@ -301,6 +301,12 @@ HRESULT CDecoder::Decode(
|
||||
{
|
||||
const CCoderInfo &coderInfo = folderInfo.Coders[i];
|
||||
|
||||
#ifndef _SFX
|
||||
// we don't support RAR codecs here
|
||||
if ((coderInfo.MethodID >> 8) == 0x403)
|
||||
return E_NOTIMPL;
|
||||
#endif
|
||||
|
||||
CCreatedCoder cod;
|
||||
RINOK(CreateCoder(
|
||||
EXTERNAL_CODECS_LOC_VARS
|
||||
|
||||
@@ -254,8 +254,16 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
lps->Init(extractCallback, false);
|
||||
|
||||
CDecoder decoder(
|
||||
#ifndef USE_MIXER_ST
|
||||
#if !defined(USE_MIXER_MT)
|
||||
false
|
||||
#elif !defined(USE_MIXER_ST)
|
||||
true
|
||||
#elif !defined(__7Z_SET_PROPERTIES)
|
||||
#ifdef _7ZIP_ST
|
||||
false
|
||||
#else
|
||||
true
|
||||
#endif
|
||||
#else
|
||||
_useMultiThreadMixer
|
||||
#endif
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
// 7zFolderOutStream.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
@@ -1,6 +0,0 @@
|
||||
// 7zFolderOutStream.h
|
||||
|
||||
#ifndef __7Z_FOLDER_OUT_STREAM_H
|
||||
#define __7Z_FOLDER_OUT_STREAM_H
|
||||
|
||||
#endif
|
||||
@@ -36,10 +36,14 @@ CHandler::CHandler()
|
||||
#endif
|
||||
|
||||
#ifdef EXTRACT_ONLY
|
||||
|
||||
_crcSize = 4;
|
||||
|
||||
#ifdef __7Z_SET_PROPERTIES
|
||||
_numThreads = NSystem::GetNumberOfProcessors();
|
||||
_useMultiThreadMixer = true;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -722,10 +726,14 @@ STDMETHODIMP CHandler::SetProperties(const wchar_t * const *names, const PROPVAR
|
||||
return E_INVALIDARG;
|
||||
const PROPVARIANT &value = values[i];
|
||||
UInt32 number;
|
||||
int index = ParseStringToUInt32(name, number);
|
||||
unsigned index = ParseStringToUInt32(name, number);
|
||||
if (index == 0)
|
||||
{
|
||||
if (name.IsEqualTo("mtf")) return PROPVARIANT_to_bool(value, _useMultiThreadMixer);
|
||||
if (name.IsEqualTo("mtf"))
|
||||
{
|
||||
RINOK(PROPVARIANT_to_bool(value, _useMultiThreadMixer));
|
||||
continue;
|
||||
}
|
||||
if (name.IsPrefixedBy_Ascii_NoCase("mt"))
|
||||
{
|
||||
RINOK(ParseMtProp(name.Ptr(2), value, numProcessors, _numThreads));
|
||||
|
||||
@@ -21,11 +21,11 @@ namespace N7z {
|
||||
#ifndef __7Z_SET_PROPERTIES
|
||||
|
||||
#ifdef EXTRACT_ONLY
|
||||
#if !defined(_7ZIP_ST) && !defined(_SFX)
|
||||
#define __7Z_SET_PROPERTIES
|
||||
#endif
|
||||
#if !defined(_7ZIP_ST) && !defined(_SFX)
|
||||
#define __7Z_SET_PROPERTIES
|
||||
#endif
|
||||
#else
|
||||
#define __7Z_SET_PROPERTIES
|
||||
#define __7Z_SET_PROPERTIES
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -44,6 +44,7 @@ public:
|
||||
UInt64 _numSolidBytes;
|
||||
bool _numSolidBytesDefined;
|
||||
bool _solidExtension;
|
||||
bool _useTypeSorting;
|
||||
|
||||
bool _compressHeaders;
|
||||
bool _encryptHeadersSpecified;
|
||||
|
||||
@@ -282,7 +282,8 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
|
||||
bool need_CTime = (Write_CTime.Def && Write_CTime.Val);
|
||||
bool need_ATime = (Write_ATime.Def && Write_ATime.Val);
|
||||
bool need_MTime = (Write_MTime.Def && Write_MTime.Val || !Write_MTime.Def);
|
||||
if (db)
|
||||
|
||||
if (db && !db->Files.IsEmpty())
|
||||
{
|
||||
if (!Write_CTime.Def) need_CTime = !db->CTime.Defs.IsEmpty();
|
||||
if (!Write_ATime.Def) need_ATime = !db->ATime.Defs.IsEmpty();
|
||||
@@ -508,14 +509,19 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
|
||||
|
||||
if (ui.NewData)
|
||||
{
|
||||
NCOM::CPropVariant prop;
|
||||
RINOK(updateCallback->GetProperty(i, kpidSize, &prop));
|
||||
if (prop.vt != VT_UI8)
|
||||
return E_INVALIDARG;
|
||||
ui.Size = (UInt64)prop.uhVal.QuadPart;
|
||||
if (ui.Size != 0 && ui.IsAnti)
|
||||
return E_INVALIDARG;
|
||||
ui.Size = 0;
|
||||
if (!ui.IsDir)
|
||||
{
|
||||
NCOM::CPropVariant prop;
|
||||
RINOK(updateCallback->GetProperty(i, kpidSize, &prop));
|
||||
if (prop.vt != VT_UI8)
|
||||
return E_INVALIDARG;
|
||||
ui.Size = (UInt64)prop.uhVal.QuadPart;
|
||||
if (ui.Size != 0 && ui.IsAnti)
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
}
|
||||
|
||||
updateItems.Add(ui);
|
||||
}
|
||||
|
||||
@@ -613,6 +619,8 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
|
||||
options.NumSolidFiles = _numSolidFiles;
|
||||
options.NumSolidBytes = _numSolidBytes;
|
||||
options.SolidExtension = _solidExtension;
|
||||
options.UseTypeSorting = _useTypeSorting;
|
||||
|
||||
options.RemoveSfxBlock = _removeSfxBlock;
|
||||
// options.VolumeMode = _volumeMode;
|
||||
|
||||
@@ -701,6 +709,7 @@ void COutHandler::InitProps()
|
||||
// _volumeMode = false;
|
||||
|
||||
InitSolid();
|
||||
_useTypeSorting = false;
|
||||
}
|
||||
|
||||
HRESULT COutHandler::SetSolidFromString(const UString &s)
|
||||
@@ -821,6 +830,8 @@ HRESULT COutHandler::SetProperty(const wchar_t *nameSpec, const PROPVARIANT &val
|
||||
|
||||
if (name.IsEqualTo("mtf")) return PROPVARIANT_to_bool(value, _useMultiThreadMixer);
|
||||
|
||||
if (name.IsEqualTo("qs")) return PROPVARIANT_to_bool(value, _useTypeSorting);
|
||||
|
||||
// if (name.IsEqualTo("v")) return PROPVARIANT_to_bool(value, _volumeMode);
|
||||
}
|
||||
return CMultiMethodProps::SetProperty(name, value);
|
||||
|
||||
@@ -1180,7 +1180,7 @@ HRESULT CInArchive::ReadHeader(
|
||||
bool isKnownType = true;
|
||||
if (type > ((UInt32)1 << 30))
|
||||
isKnownType = false;
|
||||
else switch((UInt32)type)
|
||||
else switch ((UInt32)type)
|
||||
{
|
||||
case NID::kName:
|
||||
{
|
||||
@@ -1338,7 +1338,7 @@ HRESULT CInArchive::ReadHeader(
|
||||
db.UnsupportedFeatureWarning = true;
|
||||
_inByteBack->SkipRem();
|
||||
}
|
||||
// SkipData worked incorrectly in some versions before v4.59 (7zVer <= 00.02)
|
||||
// SkipData worked incorrectly in some versions before v4.59 (7zVer <= 0.02)
|
||||
if (_inByteBack->GetRem() != 0)
|
||||
ThrowIncorrect();
|
||||
}
|
||||
|
||||
@@ -87,6 +87,8 @@ struct CFolders
|
||||
return PackPositions[index + 1] - PackPositions[index];
|
||||
}
|
||||
|
||||
CFolders(): NumPackStreams(0), NumFolders(0) {}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
NumPackStreams = 0;
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace N7z {
|
||||
struct CPropMap
|
||||
{
|
||||
UInt32 FilePropID;
|
||||
STATPROPSTG StatPROPSTG;
|
||||
CStatProp StatProp;
|
||||
};
|
||||
|
||||
static const CPropMap kPropMap[] =
|
||||
@@ -24,11 +24,11 @@ static const CPropMap kPropMap[] =
|
||||
{ NID::kPackInfo, { NULL, kpidPackSize, VT_UI8 } },
|
||||
|
||||
#ifdef _MULTI_PACK
|
||||
{ 100, { L"Pack0", kpidPackedSize0, VT_UI8 } },
|
||||
{ 101, { L"Pack1", kpidPackedSize1, VT_UI8 } },
|
||||
{ 102, { L"Pack2", kpidPackedSize2, VT_UI8 } },
|
||||
{ 103, { L"Pack3", kpidPackedSize3, VT_UI8 } },
|
||||
{ 104, { L"Pack4", kpidPackedSize4, VT_UI8 } },
|
||||
{ 100, { "Pack0", kpidPackedSize0, VT_UI8 } },
|
||||
{ 101, { "Pack1", kpidPackedSize1, VT_UI8 } },
|
||||
{ 102, { "Pack2", kpidPackedSize2, VT_UI8 } },
|
||||
{ 103, { "Pack3", kpidPackedSize3, VT_UI8 } },
|
||||
{ 104, { "Pack4", kpidPackedSize4, VT_UI8 } },
|
||||
#endif
|
||||
|
||||
{ NID::kCTime, { NULL, kpidCTime, VT_FILETIME } },
|
||||
@@ -90,7 +90,7 @@ void CHandler::FillPopIDs()
|
||||
_fileInfoPopIDs.Clear();
|
||||
|
||||
#ifdef _7Z_VOL
|
||||
if(_volumes.Size() < 1)
|
||||
if (_volumes.Size() < 1)
|
||||
return;
|
||||
const CVolume &volume = _volumes.Front();
|
||||
const CArchiveDatabaseEx &_db = volume.Database;
|
||||
@@ -156,8 +156,8 @@ STDMETHODIMP CHandler::GetPropertyInfo(UInt32 index, BSTR *name, PROPID *propID,
|
||||
const CPropMap &pr = kPropMap[i];
|
||||
if (pr.FilePropID == id)
|
||||
{
|
||||
const STATPROPSTG &st = pr.StatPROPSTG;
|
||||
*propID = st.propid;
|
||||
const CStatProp &st = pr.StatProp;
|
||||
*propID = st.PropID;
|
||||
*varType = st.vt;
|
||||
/*
|
||||
if (st.lpwstrName)
|
||||
|
||||
@@ -118,11 +118,11 @@ static int Parse_EXE(const Byte *buf, size_t size, CFilterMode *filterMode)
|
||||
|
||||
#define ELF_SIG 0x464C457F
|
||||
|
||||
#define ELF_CLASS_32 1
|
||||
#define ELF_CLASS_64 2
|
||||
#define ELF_CLASS_32 1
|
||||
#define ELF_CLASS_64 2
|
||||
|
||||
#define ELF_DATA_2LSB 1
|
||||
#define ELF_DATA_2MSB 2
|
||||
#define ELF_DATA_2LSB 1
|
||||
#define ELF_DATA_2MSB 2
|
||||
|
||||
static UInt16 Get16(const Byte *p, Bool be) { if (be) return (UInt16)GetBe16(p); return (UInt16)GetUi16(p); }
|
||||
static UInt32 Get32(const Byte *p, Bool be) { if (be) return GetBe32(p); return GetUi32(p); }
|
||||
@@ -554,11 +554,11 @@ static int CompareEmptyItems(const unsigned *p1, const unsigned *p2, void *param
|
||||
}
|
||||
|
||||
static const char *g_Exts =
|
||||
" lzma 7z ace arc arj bz bz2 deb lzo lzx gz pak rpm sit tgz tbz tbz2 tgz cab ha lha lzh rar zoo"
|
||||
" 7z xz lzma ace arc arj bz tbz bz2 tbz2 cab deb gz tgz ha lha lzh lzo lzx pak rar rpm sit zoo"
|
||||
" zip jar ear war msi"
|
||||
" 3gp avi mov mpeg mpg mpe wmv"
|
||||
" aac ape fla flac la mp3 m4a mp4 ofr ogg pac ra rm rka shn swa tta wv wma wav"
|
||||
" swf "
|
||||
" swf"
|
||||
" chm hxi hxs"
|
||||
" gif jpeg jpg jp2 png tiff bmp ico psd psp"
|
||||
" awg ps eps cgm dxf svg vrml wmf emf ai md"
|
||||
@@ -569,9 +569,9 @@ static const char *g_Exts =
|
||||
" vmdk dsk nvram vmem vmsd vmsn vmss vmtm"
|
||||
" inl inc idl acf asa h hpp hxx c cpp cxx rc java cs pas bas vb cls ctl frm dlg def"
|
||||
" f77 f f90 f95"
|
||||
" asm sql manifest dep "
|
||||
" mak clw csproj vcproj sln dsp dsw "
|
||||
" class "
|
||||
" asm sql manifest dep"
|
||||
" mak clw csproj vcproj sln dsp dsw"
|
||||
" class"
|
||||
" bat cmd"
|
||||
" xml xsd xsl xslt hxk hxc htm html xhtml xht mht mhtml htw asp aspx css cgi jsp shtml"
|
||||
" awk sed hta js php php3 php4 php5 phptml pl pm py pyo rb sh tcl vbs"
|
||||
@@ -580,7 +580,7 @@ static const char *g_Exts =
|
||||
" abw afp cwk lwp wpd wps wpt wrf wri"
|
||||
" abf afm bdf fon mgf otf pcf pfa snf ttf"
|
||||
" dbf mdb nsf ntf wdb db fdb gdb"
|
||||
" exe dll ocx vbx sfx sys tlb awx com obj lib out o so "
|
||||
" exe dll ocx vbx sfx sys tlb awx com obj lib out o so"
|
||||
" pdb pch idb ncb opt";
|
||||
|
||||
static unsigned GetExtIndex(const char *ext)
|
||||
@@ -2251,7 +2251,7 @@ HRESULT Update(
|
||||
continue;
|
||||
CRecordVector<CRefItem> refItems;
|
||||
refItems.ClearAndSetSize(numFiles);
|
||||
bool sortByType = (numSolidFiles > 1);
|
||||
bool sortByType = (options.UseTypeSorting && numSolidFiles > 1);
|
||||
for (i = 0; i < numFiles; i++)
|
||||
refItems[i] = CRefItem(group.Indices[i], updateItems[group.Indices[i]], sortByType);
|
||||
CSortParam sortParam;
|
||||
|
||||
@@ -97,6 +97,9 @@ struct CUpdateOptions
|
||||
UInt64 NumSolidFiles;
|
||||
UInt64 NumSolidBytes;
|
||||
bool SolidExtension;
|
||||
|
||||
bool UseTypeSorting;
|
||||
|
||||
bool RemoveSfxBlock;
|
||||
bool MultiThreadMixer;
|
||||
|
||||
@@ -109,6 +112,7 @@ struct CUpdateOptions
|
||||
NumSolidFiles((UInt64)(Int64)(-1)),
|
||||
NumSolidBytes((UInt64)(Int64)(-1)),
|
||||
SolidExtension(false),
|
||||
UseTypeSorting(true),
|
||||
RemoveSfxBlock(false),
|
||||
MultiThreadMixer(true)
|
||||
{}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
PROG = 7z.dll
|
||||
DEF_FILE = ../../Archive/Archive2.def
|
||||
DEF_FILE = ../Archive.def
|
||||
CFLAGS = $(CFLAGS) \
|
||||
-DEXTERNAL_CODECS \
|
||||
|
||||
@@ -13,7 +13,6 @@ AR_OBJS = \
|
||||
$O\7zEncode.obj \
|
||||
$O\7zExtract.obj \
|
||||
$O\7zFolderInStream.obj \
|
||||
$O\7zFolderOutStream.obj \
|
||||
$O\7zHandler.obj \
|
||||
$O\7zHandlerOut.obj \
|
||||
$O\7zHeader.obj \
|
||||
@@ -60,10 +59,11 @@ WIN_OBJS = \
|
||||
$O\StreamUtils.obj \
|
||||
$O\VirtThread.obj \
|
||||
|
||||
COMPRESS_OBJS = \
|
||||
$O\CopyCoder.obj \
|
||||
|
||||
AR_COMMON_OBJS = \
|
||||
$O\CoderMixer2.obj \
|
||||
$O\CoderMixer2MT.obj \
|
||||
$O\CrossThreadProgress.obj \
|
||||
$O\HandlerOut.obj \
|
||||
$O\InStreamWithCRC.obj \
|
||||
$O\ItemNameUtils.obj \
|
||||
@@ -76,4 +76,6 @@ C_OBJS = \
|
||||
$O\CpuArch.obj \
|
||||
$O\Threads.obj \
|
||||
|
||||
!include "../../Crc.mak"
|
||||
|
||||
!include "../../7zip.mak"
|
||||
|
||||
@@ -7,16 +7,13 @@
|
||||
#include "../../Common/ComTry.h"
|
||||
#include "../../Common/Defs.h"
|
||||
#include "../../Common/IntToString.h"
|
||||
#include "../../Common/MyString.h"
|
||||
|
||||
#include "../../Windows/PropVariant.h"
|
||||
|
||||
#include "../Common/LimitedStreams.h"
|
||||
#include "../Common/ProgressUtils.h"
|
||||
#include "../Common/RegisterArc.h"
|
||||
#include "../Common/StreamUtils.h"
|
||||
|
||||
#include "../Compress/CopyCoder.h"
|
||||
#include "HandlerCont.h"
|
||||
|
||||
#define Get16(p) GetBe16(p)
|
||||
#define Get32(p) GetBe32(p)
|
||||
@@ -75,13 +72,9 @@ struct CItem
|
||||
}
|
||||
};
|
||||
|
||||
class CHandler:
|
||||
public IInArchive,
|
||||
public IInArchiveGetStream,
|
||||
public CMyUnknownImp
|
||||
class CHandler: public CHandlerCont
|
||||
{
|
||||
CRecordVector<CItem> _items;
|
||||
CMyComPtr<IInStream> _stream;
|
||||
unsigned _blockSizeLog;
|
||||
UInt32 _numBlocks;
|
||||
UInt64 _phySize;
|
||||
@@ -89,11 +82,17 @@ class CHandler:
|
||||
|
||||
HRESULT ReadTables(IInStream *stream);
|
||||
UInt64 BlocksToBytes(UInt32 i) const { return (UInt64)i << _blockSizeLog; }
|
||||
UInt64 GetItemSize(const CItem &item) const { return BlocksToBytes(item.NumBlocks); }
|
||||
|
||||
virtual int GetItem_ExtractInfo(UInt32 index, UInt64 &pos, UInt64 &size) const
|
||||
{
|
||||
const CItem &item = _items[index];
|
||||
pos = BlocksToBytes(item.StartBlock);
|
||||
size = BlocksToBytes(item.NumBlocks);
|
||||
return NExtract::NOperationResult::kOK;
|
||||
}
|
||||
|
||||
public:
|
||||
MY_UNKNOWN_IMP2(IInArchive, IInArchiveGetStream)
|
||||
INTERFACE_IInArchive(;)
|
||||
STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);
|
||||
INTERFACE_IInArchive_Cont(;)
|
||||
};
|
||||
|
||||
static const UInt32 kSectorSize = 512;
|
||||
@@ -300,7 +299,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
}
|
||||
case kpidSize:
|
||||
case kpidPackSize:
|
||||
prop = GetItemSize(item);
|
||||
prop = BlocksToBytes(item.NumBlocks);
|
||||
break;
|
||||
case kpidOffset: prop = BlocksToBytes(item.StartBlock); break;
|
||||
}
|
||||
@@ -309,73 +308,6 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
Int32 testMode, IArchiveExtractCallback *extractCallback)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
bool allFilesMode = (numItems == (UInt32)(Int32)-1);
|
||||
if (allFilesMode)
|
||||
numItems = _items.Size();
|
||||
if (numItems == 0)
|
||||
return S_OK;
|
||||
UInt64 totalSize = 0;
|
||||
UInt32 i;
|
||||
for (i = 0; i < numItems; i++)
|
||||
totalSize += GetItemSize(_items[allFilesMode ? i : indices[i]]);
|
||||
extractCallback->SetTotal(totalSize);
|
||||
|
||||
totalSize = 0;
|
||||
|
||||
NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder();
|
||||
CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
|
||||
|
||||
CLocalProgress *lps = new CLocalProgress;
|
||||
CMyComPtr<ICompressProgressInfo> progress = lps;
|
||||
lps->Init(extractCallback, false);
|
||||
|
||||
CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
|
||||
CMyComPtr<ISequentialInStream> inStream(streamSpec);
|
||||
streamSpec->SetStream(_stream);
|
||||
|
||||
for (i = 0; i < numItems; i++)
|
||||
{
|
||||
lps->InSize = totalSize;
|
||||
lps->OutSize = totalSize;
|
||||
RINOK(lps->SetCur());
|
||||
CMyComPtr<ISequentialOutStream> outStream;
|
||||
Int32 askMode = testMode ?
|
||||
NExtract::NAskMode::kTest :
|
||||
NExtract::NAskMode::kExtract;
|
||||
Int32 index = allFilesMode ? i : indices[i];
|
||||
const CItem &item = _items[index];
|
||||
|
||||
RINOK(extractCallback->GetStream(index, &outStream, askMode));
|
||||
UInt64 size = GetItemSize(item);
|
||||
totalSize += size;
|
||||
if (!testMode && !outStream)
|
||||
continue;
|
||||
RINOK(extractCallback->PrepareOperation(askMode));
|
||||
|
||||
RINOK(_stream->Seek(BlocksToBytes(item.StartBlock), STREAM_SEEK_SET, NULL));
|
||||
streamSpec->Init(size);
|
||||
RINOK(copyCoder->Code(inStream, outStream, NULL, NULL, progress));
|
||||
outStream.Release();
|
||||
RINOK(extractCallback->SetOperationResult(copyCoderSpec->TotalSize == size ?
|
||||
NExtract::NOperationResult::kOK:
|
||||
NExtract::NOperationResult::kDataError));
|
||||
}
|
||||
return S_OK;
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
const CItem &item = _items[index];
|
||||
return CreateLimitedInStream(_stream, BlocksToBytes(item.StartBlock), GetItemSize(item), stream);
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
static const Byte k_Signature[] = { kSig0, kSig1 };
|
||||
|
||||
REGISTER_ARC_I(
|
||||
|
||||
@@ -29,15 +29,24 @@ CCabBlockInStream::~CCabBlockInStream()
|
||||
static UInt32 CheckSum(const Byte *p, UInt32 size)
|
||||
{
|
||||
UInt32 sum = 0;
|
||||
for (UInt32 i = size >> 2; i != 0; i--)
|
||||
|
||||
for (; size >= 8; size -= 8)
|
||||
{
|
||||
sum ^= GetUi32(p) ^ GetUi32(p + 4);
|
||||
p += 8;
|
||||
}
|
||||
|
||||
if (size >= 4)
|
||||
{
|
||||
sum ^= GetUi32(p);
|
||||
p += 4;
|
||||
}
|
||||
|
||||
size &= 3;
|
||||
if (size > 2) sum ^= (UInt32)(*p++) << 16;
|
||||
if (size > 1) sum ^= (UInt32)(*p++) << 8;
|
||||
if (size > 0) sum ^= (UInt32)(*p++);
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,10 +25,16 @@ public:
|
||||
|
||||
CCabBlockInStream(): _buf(0), ReservedSize(0), MsZip(false) {}
|
||||
~CCabBlockInStream();
|
||||
|
||||
bool Create();
|
||||
|
||||
void InitForNewBlock() { _size = 0; _pos = 0; }
|
||||
|
||||
HRESULT PreRead(ISequentialInStream *stream, UInt32 &packSize, UInt32 &unpackSize);
|
||||
|
||||
UInt32 GetPackSizeAvail() const { return _size - _pos; }
|
||||
const Byte *GetData() const { return _buf + _pos; }
|
||||
|
||||
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
|
||||
};
|
||||
|
||||
|
||||
@@ -569,13 +569,14 @@ public:
|
||||
UInt64 folderSize,
|
||||
IArchiveExtractCallback *extractCallback,
|
||||
bool testMode);
|
||||
HRESULT FlushCorrupted();
|
||||
HRESULT FlushCorrupted(unsigned folderIndex);
|
||||
HRESULT Unsupported();
|
||||
|
||||
UInt64 GetRemain() const { return m_FolderSize - m_PosInFolder; }
|
||||
UInt64 GetPosInFolder() const { return m_PosInFolder; }
|
||||
};
|
||||
|
||||
|
||||
void CFolderOutStream::Init(
|
||||
const CMvDatabaseEx *database,
|
||||
const CRecordVector<bool> *extractStatuses,
|
||||
@@ -600,6 +601,7 @@ void CFolderOutStream::Init(
|
||||
NumIdenticalFiles = 0;
|
||||
}
|
||||
|
||||
|
||||
HRESULT CFolderOutStream::CloseFileWithResOp(Int32 resOp)
|
||||
{
|
||||
m_RealOutStream.Release();
|
||||
@@ -608,6 +610,7 @@ HRESULT CFolderOutStream::CloseFileWithResOp(Int32 resOp)
|
||||
return m_ExtractCallback->SetOperationResult(resOp);
|
||||
}
|
||||
|
||||
|
||||
HRESULT CFolderOutStream::CloseFile()
|
||||
{
|
||||
return CloseFileWithResOp(m_IsOk ?
|
||||
@@ -615,6 +618,7 @@ HRESULT CFolderOutStream::CloseFile()
|
||||
NExtract::NOperationResult::kDataError);
|
||||
}
|
||||
|
||||
|
||||
HRESULT CFolderOutStream::OpenFile()
|
||||
{
|
||||
if (NumIdenticalFiles == 0)
|
||||
@@ -680,6 +684,7 @@ HRESULT CFolderOutStream::OpenFile()
|
||||
return m_ExtractCallback->PrepareOperation(askMode);
|
||||
}
|
||||
|
||||
|
||||
HRESULT CFolderOutStream::WriteEmptyFiles()
|
||||
{
|
||||
if (m_FileIsOpen)
|
||||
@@ -699,13 +704,15 @@ HRESULT CFolderOutStream::WriteEmptyFiles()
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// This is Write function
|
||||
|
||||
HRESULT CFolderOutStream::Write2(const void *data, UInt32 size, UInt32 *processedSize, bool isOK)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
|
||||
UInt32 realProcessed = 0;
|
||||
if (processedSize)
|
||||
*processedSize = 0;
|
||||
|
||||
while (size != 0)
|
||||
{
|
||||
if (m_FileIsOpen)
|
||||
@@ -732,8 +739,10 @@ HRESULT CFolderOutStream::Write2(const void *data, UInt32 size, UInt32 *processe
|
||||
size -= numBytesToWrite;
|
||||
m_RemainFileSize -= numBytesToWrite;
|
||||
m_PosInFolder += numBytesToWrite;
|
||||
|
||||
if (res != S_OK)
|
||||
return res;
|
||||
|
||||
if (m_RemainFileSize == 0)
|
||||
{
|
||||
RINOK(CloseFile());
|
||||
@@ -754,17 +763,27 @@ HRESULT CFolderOutStream::Write2(const void *data, UInt32 size, UInt32 *processe
|
||||
{
|
||||
RINOK(CloseFile());
|
||||
}
|
||||
|
||||
RINOK(result);
|
||||
}
|
||||
|
||||
TempBufMode = false;
|
||||
}
|
||||
|
||||
if (realProcessed > 0)
|
||||
break; // with this break this function works as Write-Part
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_CurrentIndex >= m_ExtractStatuses->Size())
|
||||
return E_FAIL;
|
||||
{
|
||||
// we ignore extra data;
|
||||
realProcessed += size;
|
||||
if (processedSize)
|
||||
*processedSize = realProcessed;
|
||||
return S_OK;
|
||||
// return E_FAIL;
|
||||
}
|
||||
|
||||
const CMvItem &mvItem = m_Database->Items[m_StartIndex + m_CurrentIndex];
|
||||
const CItem &item = m_Database->Volumes[mvItem.VolumeIndex].Items[mvItem.ItemIndex];
|
||||
@@ -772,8 +791,10 @@ HRESULT CFolderOutStream::Write2(const void *data, UInt32 size, UInt32 *processe
|
||||
m_RemainFileSize = item.Size;
|
||||
|
||||
UInt32 fileOffset = item.Offset;
|
||||
|
||||
if (fileOffset < m_PosInFolder)
|
||||
return E_FAIL;
|
||||
|
||||
if (fileOffset > m_PosInFolder)
|
||||
{
|
||||
UInt32 numBytesToWrite = MyMin(fileOffset - (UInt32)m_PosInFolder, size);
|
||||
@@ -784,6 +805,7 @@ HRESULT CFolderOutStream::Write2(const void *data, UInt32 size, UInt32 *processe
|
||||
size -= numBytesToWrite;
|
||||
m_PosInFolder += numBytesToWrite;
|
||||
}
|
||||
|
||||
if (fileOffset == m_PosInFolder)
|
||||
{
|
||||
RINOK(OpenFile());
|
||||
@@ -793,21 +815,39 @@ HRESULT CFolderOutStream::Write2(const void *data, UInt32 size, UInt32 *processe
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return WriteEmptyFiles();
|
||||
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
|
||||
STDMETHODIMP CFolderOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
return Write2(data, size, processedSize, true);
|
||||
}
|
||||
|
||||
HRESULT CFolderOutStream::FlushCorrupted()
|
||||
|
||||
HRESULT CFolderOutStream::FlushCorrupted(unsigned folderIndex)
|
||||
{
|
||||
UInt64 remain = GetRemain();
|
||||
|
||||
if (remain == 0)
|
||||
{
|
||||
CMyComPtr<IArchiveExtractCallbackMessage> callbackMessage;
|
||||
m_ExtractCallback.QueryInterface(IID_IArchiveExtractCallbackMessage, &callbackMessage);
|
||||
if (callbackMessage)
|
||||
{
|
||||
RINOK(callbackMessage->ReportExtractResult(NEventIndexType::kBlockIndex, folderIndex, NExtract::NOperationResult::kDataError));
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
const unsigned kBufSize = (1 << 10);
|
||||
Byte buf[kBufSize];
|
||||
for (unsigned i = 0; i < kBufSize; i++)
|
||||
buf[i] = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
UInt64 remain = GetRemain();
|
||||
@@ -819,6 +859,7 @@ HRESULT CFolderOutStream::FlushCorrupted()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
HRESULT CFolderOutStream::Unsupported()
|
||||
{
|
||||
while (m_CurrentIndex < m_ExtractStatuses->Size())
|
||||
@@ -838,6 +879,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
Int32 testModeSpec, IArchiveExtractCallback *extractCallback)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
|
||||
bool allFilesMode = (numItems == (UInt32)(Int32)-1);
|
||||
if (allFilesMode)
|
||||
numItems = m_Database.Items.Size();
|
||||
@@ -883,10 +925,10 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
CMyComPtr<ICompressCoder> deflateDecoder;
|
||||
|
||||
NCompress::NLzx::CDecoder *lzxDecoderSpec = NULL;
|
||||
CMyComPtr<ICompressCoder> lzxDecoder;
|
||||
CMyComPtr<IUnknown> lzxDecoder;
|
||||
|
||||
NCompress::NQuantum::CDecoder *quantumDecoderSpec = NULL;
|
||||
CMyComPtr<ICompressCoder> quantumDecoder;
|
||||
CMyComPtr<IUnknown> quantumDecoder;
|
||||
|
||||
CCabBlockInStream *cabBlockInStreamSpec = new CCabBlockInStream();
|
||||
CMyComPtr<ISequentialInStream> cabBlockInStream = cabBlockInStreamSpec;
|
||||
@@ -968,7 +1010,8 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
CFolderOutStream *cabFolderOutStream = new CFolderOutStream;
|
||||
CMyComPtr<ISequentialOutStream> outStream(cabFolderOutStream);
|
||||
|
||||
const CFolder &folder = db.Folders[item.GetFolderIndex(db.Folders.Size())];
|
||||
unsigned folderIndex2 = item.GetFolderIndex(db.Folders.Size());
|
||||
const CFolder &folder = db.Folders[folderIndex2];
|
||||
|
||||
cabFolderOutStream->Init(&m_Database, &extractStatuses, startIndex2,
|
||||
curUnpack, extractCallback, testMode);
|
||||
@@ -980,6 +1023,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
{
|
||||
case NHeader::NMethod::kNone:
|
||||
break;
|
||||
|
||||
case NHeader::NMethod::kMSZip:
|
||||
if (!deflateDecoder)
|
||||
{
|
||||
@@ -988,14 +1032,16 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
}
|
||||
cabBlockInStreamSpec->MsZip = true;
|
||||
break;
|
||||
|
||||
case NHeader::NMethod::kLZX:
|
||||
if (!lzxDecoder)
|
||||
{
|
||||
lzxDecoderSpec = new NCompress::NLzx::CDecoder;
|
||||
lzxDecoder = lzxDecoderSpec;
|
||||
}
|
||||
res = lzxDecoderSpec->SetParams(folder.MethodMinor);
|
||||
res = lzxDecoderSpec->SetParams_and_Alloc(folder.MethodMinor);
|
||||
break;
|
||||
|
||||
case NHeader::NMethod::kQuantum:
|
||||
if (!quantumDecoder)
|
||||
{
|
||||
@@ -1004,6 +1050,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
}
|
||||
res = quantumDecoderSpec->SetParams(folder.MethodMinor);
|
||||
break;
|
||||
|
||||
default:
|
||||
res = E_INVALIDARG;
|
||||
break;
|
||||
@@ -1022,6 +1069,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
int locFolderIndex = item.GetFolderIndex(db.Folders.Size());
|
||||
bool keepHistory = false;
|
||||
bool keepInputBuffer = false;
|
||||
bool thereWasNotAlignedChunk = false;
|
||||
|
||||
for (UInt32 bl = 0; cabFolderOutStream->GetRemain() != 0;)
|
||||
{
|
||||
@@ -1058,6 +1106,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
bl++;
|
||||
|
||||
if (!keepInputBuffer)
|
||||
@@ -1079,19 +1128,39 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
lps->InSize = totalPacked;
|
||||
RINOK(lps->SetCur());
|
||||
|
||||
UInt64 unpackRemain = cabFolderOutStream->GetRemain();
|
||||
|
||||
const UInt32 kBlockSizeMax = (1 << 15);
|
||||
if (unpackRemain > kBlockSizeMax)
|
||||
unpackRemain = kBlockSizeMax;
|
||||
if (unpackRemain > unpackSize)
|
||||
unpackRemain = unpackSize;
|
||||
|
||||
/* We don't try to reduce last block.
|
||||
Note that LZX converts data with x86 filter.
|
||||
and filter needs larger input data than reduced size.
|
||||
It's simpler to decompress full chunk here.
|
||||
also we need full block for quantum for more integrity checks */
|
||||
|
||||
if (unpackSize > kBlockSizeMax)
|
||||
{
|
||||
res = S_FALSE;
|
||||
break;
|
||||
}
|
||||
|
||||
if (unpackSize != kBlockSizeMax)
|
||||
{
|
||||
if (thereWasNotAlignedChunk)
|
||||
{
|
||||
res = S_FALSE;
|
||||
break;
|
||||
}
|
||||
thereWasNotAlignedChunk = true;
|
||||
}
|
||||
|
||||
UInt64 unpackSize64 = unpackSize;
|
||||
UInt32 packSizeChunk = cabBlockInStreamSpec->GetPackSizeAvail();
|
||||
|
||||
switch (folder.GetMethod())
|
||||
{
|
||||
case NHeader::NMethod::kNone:
|
||||
res = copyCoder->Code(cabBlockInStream, outStream, NULL, &unpackRemain, NULL);
|
||||
res = copyCoder->Code(cabBlockInStream, outStream, NULL, &unpackSize64, NULL);
|
||||
break;
|
||||
|
||||
case NHeader::NMethod::kMSZip:
|
||||
deflateDecoderSpec->Set_KeepHistory(keepHistory);
|
||||
/* v9.31: now we follow MSZIP specification that requires to finish deflate stream at the end of each block.
|
||||
@@ -1100,7 +1169,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
Maybe we also should ignore that error?
|
||||
Or we should extract full file and show the warning? */
|
||||
deflateDecoderSpec->Set_NeedFinishInput(true);
|
||||
res = deflateDecoder->Code(cabBlockInStream, outStream, NULL, &unpackRemain, NULL);
|
||||
res = deflateDecoder->Code(cabBlockInStream, outStream, NULL, &unpackSize64, NULL);
|
||||
if (res == S_OK)
|
||||
{
|
||||
if (!deflateDecoderSpec->IsFinished())
|
||||
@@ -1108,16 +1177,24 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
if (!deflateDecoderSpec->IsFinalBlock())
|
||||
res = S_FALSE;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case NHeader::NMethod::kLZX:
|
||||
lzxDecoderSpec->SetKeepHistory(keepHistory);
|
||||
res = lzxDecoder->Code(cabBlockInStream, outStream, NULL, &unpackRemain, NULL);
|
||||
lzxDecoderSpec->KeepHistoryForNext = true;
|
||||
|
||||
res = lzxDecoderSpec->Code(cabBlockInStreamSpec->GetData(), packSizeChunk, unpackSize);
|
||||
|
||||
if (res == S_OK)
|
||||
res = WriteStream(outStream,
|
||||
lzxDecoderSpec->GetUnpackData(),
|
||||
lzxDecoderSpec->GetUnpackSize());
|
||||
break;
|
||||
|
||||
case NHeader::NMethod::kQuantum:
|
||||
quantumDecoderSpec->SetKeepHistory(keepHistory);
|
||||
res = quantumDecoder->Code(cabBlockInStream, outStream, NULL, &unpackRemain, NULL);
|
||||
break;
|
||||
res = quantumDecoderSpec->Code(cabBlockInStreamSpec->GetData(),
|
||||
packSizeChunk, outStream, unpackSize, keepHistory);
|
||||
break;
|
||||
}
|
||||
|
||||
if (res != S_OK)
|
||||
@@ -1135,17 +1212,21 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
RINOK(cabFolderOutStream->WriteEmptyFiles());
|
||||
}
|
||||
}
|
||||
|
||||
if (res != S_OK || cabFolderOutStream->GetRemain() != 0)
|
||||
{
|
||||
RINOK(cabFolderOutStream->FlushCorrupted());
|
||||
RINOK(cabFolderOutStream->FlushCorrupted(folderIndex2));
|
||||
}
|
||||
|
||||
totalUnPacked += curUnpack;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
|
||||
STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
|
||||
{
|
||||
*numItems = m_Database.Items.Size();
|
||||
|
||||
@@ -101,9 +101,10 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
NCOM::CPropVariant prop;
|
||||
|
||||
if (m_Database.NewFormat)
|
||||
{
|
||||
switch(propID)
|
||||
switch (propID)
|
||||
{
|
||||
case kpidSize:
|
||||
prop = (UInt64)m_Database.NewFormatString.Len();
|
||||
@@ -112,12 +113,15 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
prop.Detach(value);
|
||||
return S_OK;
|
||||
}
|
||||
int entryIndex;
|
||||
|
||||
unsigned entryIndex;
|
||||
if (m_Database.LowLevel)
|
||||
entryIndex = index;
|
||||
else
|
||||
entryIndex = m_Database.Indices[index];
|
||||
|
||||
const CItem &item = m_Database.Items[entryIndex];
|
||||
|
||||
switch (propID)
|
||||
{
|
||||
case kpidPath:
|
||||
@@ -144,7 +148,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
if (item.Section == 0)
|
||||
prop = "Copy";
|
||||
else if (item.Section < m_Database.Sections.Size())
|
||||
prop = m_Database.Sections[(int)item.Section].GetMethodName();
|
||||
prop = m_Database.Sections[(unsigned)item.Section].GetMethodName();
|
||||
break;
|
||||
}
|
||||
case kpidBlock:
|
||||
@@ -161,6 +165,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
prop.Detach(value);
|
||||
return S_OK;
|
||||
COM_TRY_END
|
||||
@@ -244,9 +249,9 @@ public:
|
||||
UInt64 m_PosInFolder;
|
||||
UInt64 m_PosInSection;
|
||||
const CRecordVector<bool> *m_ExtractStatuses;
|
||||
int m_StartIndex;
|
||||
int m_CurrentIndex;
|
||||
int m_NumFiles;
|
||||
unsigned m_StartIndex;
|
||||
unsigned m_CurrentIndex;
|
||||
unsigned m_NumFiles;
|
||||
|
||||
private:
|
||||
const CFilesDatabase *m_Database;
|
||||
@@ -298,7 +303,7 @@ HRESULT CChmFolderOutStream::WriteEmptyFiles()
|
||||
{
|
||||
if (m_FileIsOpen)
|
||||
return S_OK;
|
||||
for (;m_CurrentIndex < m_NumFiles; m_CurrentIndex++)
|
||||
for (; m_CurrentIndex < m_NumFiles; m_CurrentIndex++)
|
||||
{
|
||||
UInt64 fileSize = m_Database->GetFileSize(m_StartIndex + m_CurrentIndex);
|
||||
if (fileSize != 0)
|
||||
@@ -315,9 +320,10 @@ HRESULT CChmFolderOutStream::WriteEmptyFiles()
|
||||
HRESULT CChmFolderOutStream::Write2(const void *data, UInt32 size, UInt32 *processedSize, bool isOK)
|
||||
{
|
||||
UInt32 realProcessed = 0;
|
||||
if (processedSize != NULL)
|
||||
if (processedSize)
|
||||
*processedSize = 0;
|
||||
while(size != 0)
|
||||
|
||||
while (size != 0)
|
||||
{
|
||||
if (m_FileIsOpen)
|
||||
{
|
||||
@@ -335,7 +341,7 @@ HRESULT CChmFolderOutStream::Write2(const void *data, UInt32 size, UInt32 *proce
|
||||
}
|
||||
}
|
||||
realProcessed += numBytesToWrite;
|
||||
if (processedSize != NULL)
|
||||
if (processedSize)
|
||||
*processedSize = realProcessed;
|
||||
data = (const void *)((const Byte *)data + numBytesToWrite);
|
||||
size -= numBytesToWrite;
|
||||
@@ -359,23 +365,32 @@ HRESULT CChmFolderOutStream::Write2(const void *data, UInt32 size, UInt32 *proce
|
||||
else
|
||||
{
|
||||
if (m_CurrentIndex >= m_NumFiles)
|
||||
return E_FAIL;
|
||||
int fullIndex = m_StartIndex + m_CurrentIndex;
|
||||
{
|
||||
realProcessed += size;
|
||||
if (processedSize)
|
||||
*processedSize = realProcessed;
|
||||
return S_OK;
|
||||
// return E_FAIL;
|
||||
}
|
||||
|
||||
unsigned fullIndex = m_StartIndex + m_CurrentIndex;
|
||||
m_RemainFileSize = m_Database->GetFileSize(fullIndex);
|
||||
UInt64 fileOffset = m_Database->GetFileOffset(fullIndex);
|
||||
if (fileOffset < m_PosInSection)
|
||||
return E_FAIL;
|
||||
|
||||
if (fileOffset > m_PosInSection)
|
||||
{
|
||||
UInt32 numBytesToWrite = (UInt32)MyMin(fileOffset - m_PosInSection, UInt64(size));
|
||||
realProcessed += numBytesToWrite;
|
||||
if (processedSize != NULL)
|
||||
if (processedSize)
|
||||
*processedSize = realProcessed;
|
||||
data = (const void *)((const Byte *)data + numBytesToWrite);
|
||||
size -= numBytesToWrite;
|
||||
m_PosInSection += numBytesToWrite;
|
||||
m_PosInFolder += numBytesToWrite;
|
||||
}
|
||||
|
||||
if (fileOffset == m_PosInSection)
|
||||
{
|
||||
RINOK(OpenFile());
|
||||
@@ -385,6 +400,7 @@ HRESULT CChmFolderOutStream::Write2(const void *data, UInt32 size, UInt32 *proce
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return WriteEmptyFiles();
|
||||
}
|
||||
|
||||
@@ -397,7 +413,7 @@ HRESULT CChmFolderOutStream::FlushCorrupted(UInt64 maxSize)
|
||||
{
|
||||
const UInt32 kBufferSize = (1 << 10);
|
||||
Byte buffer[kBufferSize];
|
||||
for (int i = 0; i < kBufferSize; i++)
|
||||
for (unsigned i = 0; i < kBufferSize; i++)
|
||||
buffer[i] = 0;
|
||||
if (maxSize > m_FolderSize)
|
||||
maxSize = m_FolderSize;
|
||||
@@ -430,7 +446,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
|
||||
UInt64 currentTotalSize = 0;
|
||||
|
||||
NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder();
|
||||
NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder;
|
||||
CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
|
||||
UInt32 i;
|
||||
|
||||
@@ -446,11 +462,13 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
{
|
||||
UInt64 currentItemSize = 0;
|
||||
UInt64 totalSize = 0;
|
||||
|
||||
if (m_Database.NewFormat)
|
||||
totalSize = m_Database.NewFormatString.Len();
|
||||
else
|
||||
for (i = 0; i < numItems; i++)
|
||||
totalSize += m_Database.Items[allFilesMode ? i : indices[i]].Size;
|
||||
|
||||
extractCallback->SetTotal(totalSize);
|
||||
|
||||
for (i = 0; i < numItems; i++, currentTotalSize += currentItemSize)
|
||||
@@ -481,6 +499,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
|
||||
continue;
|
||||
}
|
||||
|
||||
const CItem &item = m_Database.Items[index];
|
||||
|
||||
currentItemSize = item.Size;
|
||||
@@ -513,12 +532,12 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
}
|
||||
|
||||
UInt64 lastFolderIndex = ((UInt64)0 - 1);
|
||||
|
||||
for (i = 0; i < numItems; i++)
|
||||
{
|
||||
UInt32 index = allFilesMode ? i : indices[i];
|
||||
int entryIndex = m_Database.Indices[index];
|
||||
const CItem &item = m_Database.Items[entryIndex];
|
||||
UInt64 sectionIndex = item.Section;
|
||||
const CItem &item = m_Database.Items[m_Database.Indices[index]];
|
||||
const UInt64 sectionIndex = item.Section;
|
||||
if (item.IsDir() || item.Size == 0)
|
||||
continue;
|
||||
if (sectionIndex == 0)
|
||||
@@ -526,7 +545,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
currentTotalSize += item.Size;
|
||||
continue;
|
||||
}
|
||||
const CSectionInfo §ion = m_Database.Sections[(int)item.Section];
|
||||
const CSectionInfo §ion = m_Database.Sections[(unsigned)item.Section];
|
||||
if (section.IsLzx())
|
||||
{
|
||||
const CLzxInfo &lzxInfo = section.Methods[0].LzxInfo;
|
||||
@@ -541,25 +560,32 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
|
||||
RINOK(extractCallback->SetTotal(currentTotalSize));
|
||||
|
||||
NCompress::NLzx::CDecoder *lzxDecoderSpec = 0;
|
||||
CMyComPtr<ICompressCoder> lzxDecoder;
|
||||
NCompress::NLzx::CDecoder *lzxDecoderSpec = NULL;
|
||||
CMyComPtr<IUnknown> lzxDecoder;
|
||||
CChmFolderOutStream *chmFolderOutStream = 0;
|
||||
CMyComPtr<ISequentialOutStream> outStream;
|
||||
|
||||
currentTotalSize = 0;
|
||||
|
||||
CRecordVector<bool> extractStatuses;
|
||||
for (i = 0; i < numItems;)
|
||||
|
||||
CByteBuffer packBuf;
|
||||
|
||||
for (i = 0;;)
|
||||
{
|
||||
RINOK(extractCallback->SetCompleted(¤tTotalSize));
|
||||
|
||||
if (i >= numItems)
|
||||
break;
|
||||
|
||||
UInt32 index = allFilesMode ? i : indices[i];
|
||||
i++;
|
||||
int entryIndex = m_Database.Indices[index];
|
||||
const CItem &item = m_Database.Items[entryIndex];
|
||||
UInt64 sectionIndex = item.Section;
|
||||
const CItem &item = m_Database.Items[m_Database.Indices[index]];
|
||||
const UInt64 sectionIndex = item.Section;
|
||||
Int32 askMode= testMode ?
|
||||
NExtract::NAskMode::kTest :
|
||||
NExtract::NAskMode::kExtract;
|
||||
|
||||
if (item.IsDir())
|
||||
{
|
||||
CMyComPtr<ISequentialOutStream> realOutStream;
|
||||
@@ -595,7 +621,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
continue;
|
||||
}
|
||||
|
||||
const CSectionInfo §ion = m_Database.Sections[(int)sectionIndex];
|
||||
const CSectionInfo §ion = m_Database.Sections[(unsigned)sectionIndex];
|
||||
|
||||
if (!section.IsLzx())
|
||||
{
|
||||
@@ -610,7 +636,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
|
||||
const CLzxInfo &lzxInfo = section.Methods[0].LzxInfo;
|
||||
|
||||
if (chmFolderOutStream == 0)
|
||||
if (!chmFolderOutStream)
|
||||
{
|
||||
chmFolderOutStream = new CChmFolderOutStream;
|
||||
outStream = chmFolderOutStream;
|
||||
@@ -618,7 +644,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
|
||||
chmFolderOutStream->Init(&m_Database, extractCallback, testMode);
|
||||
|
||||
if (lzxDecoderSpec == NULL)
|
||||
if (!lzxDecoderSpec)
|
||||
{
|
||||
lzxDecoderSpec = new NCompress::NLzx::CDecoder;
|
||||
lzxDecoder = lzxDecoderSpec;
|
||||
@@ -626,9 +652,8 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
|
||||
UInt64 folderIndex = m_Database.GetFolder(index);
|
||||
|
||||
UInt64 compressedPos = m_Database.ContentOffset + section.Offset;
|
||||
UInt32 numDictBits = lzxInfo.GetNumDictBits();
|
||||
RINOK(lzxDecoderSpec->SetParams(numDictBits));
|
||||
const UInt64 compressedPos = m_Database.ContentOffset + section.Offset;
|
||||
RINOK(lzxDecoderSpec->SetParams_and_Alloc(lzxInfo.GetNumDictBits()));
|
||||
|
||||
const CItem *lastItem = &item;
|
||||
extractStatuses.Clear();
|
||||
@@ -645,17 +670,18 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
lastFolderIndex = m_Database.GetLastFolder(index);
|
||||
UInt64 folderSize = lzxInfo.GetFolderSize();
|
||||
UInt64 unPackSize = folderSize;
|
||||
|
||||
if (extractStatuses.IsEmpty())
|
||||
chmFolderOutStream->m_StartIndex = index + 1;
|
||||
else
|
||||
chmFolderOutStream->m_StartIndex = index;
|
||||
|
||||
if (limitFolderIndex == folderIndex)
|
||||
{
|
||||
for (; i < numItems; i++)
|
||||
{
|
||||
UInt32 nextIndex = allFilesMode ? i : indices[i];
|
||||
int entryIndex = m_Database.Indices[nextIndex];
|
||||
const CItem &nextItem = m_Database.Items[entryIndex];
|
||||
const UInt32 nextIndex = allFilesMode ? i : indices[i];
|
||||
const CItem &nextItem = m_Database.Items[m_Database.Indices[nextIndex]];
|
||||
if (nextItem.Section != sectionIndex)
|
||||
break;
|
||||
UInt64 nextFolderIndex = m_Database.GetFolder(nextIndex);
|
||||
@@ -671,6 +697,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
lastFolderIndex = m_Database.GetLastFolder(index);
|
||||
}
|
||||
}
|
||||
|
||||
unPackSize = MyMin(finishPos - startPos, unPackSize);
|
||||
|
||||
chmFolderOutStream->m_FolderSize = folderSize;
|
||||
@@ -679,11 +706,13 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
chmFolderOutStream->m_ExtractStatuses = &extractStatuses;
|
||||
chmFolderOutStream->m_NumFiles = extractStatuses.Size();
|
||||
chmFolderOutStream->m_CurrentIndex = 0;
|
||||
|
||||
try
|
||||
{
|
||||
UInt64 startBlock = lzxInfo.GetBlockIndexFromFolderIndex(folderIndex);
|
||||
const CResetTable &rt = lzxInfo.ResetTable;
|
||||
UInt32 numBlocks = (UInt32)rt.GetNumBlocks(unPackSize);
|
||||
|
||||
for (UInt32 b = 0; b < numBlocks; b++)
|
||||
{
|
||||
UInt64 completedSize = currentTotalSize + chmFolderOutStream->m_PosInSection - startPos;
|
||||
@@ -691,17 +720,35 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
UInt64 bCur = startBlock + b;
|
||||
if (bCur >= rt.ResetOffsets.Size())
|
||||
return E_FAIL;
|
||||
UInt64 offset = rt.ResetOffsets[(int)bCur];
|
||||
UInt64 offset = rt.ResetOffsets[(unsigned)bCur];
|
||||
UInt64 compressedSize;
|
||||
rt.GetCompressedSizeOfBlock(bCur, compressedSize);
|
||||
UInt64 rem = finishPos - chmFolderOutStream->m_PosInSection;
|
||||
if (rem > rt.BlockSize)
|
||||
rem = rt.BlockSize;
|
||||
|
||||
// chm writes full blocks. So we don't need to use reduced size for last block
|
||||
|
||||
RINOK(m_Stream->Seek(compressedPos + offset, STREAM_SEEK_SET, NULL));
|
||||
streamSpec->SetStream(m_Stream);
|
||||
streamSpec->Init(compressedSize);
|
||||
|
||||
lzxDecoderSpec->SetKeepHistory(b > 0);
|
||||
HRESULT res = lzxDecoder->Code(inStream, outStream, NULL, &rem, NULL);
|
||||
|
||||
size_t compressedSizeT = (size_t)compressedSize;
|
||||
if (compressedSizeT != compressedSize)
|
||||
throw 2;
|
||||
packBuf.AllocAtLeast(compressedSizeT);
|
||||
|
||||
HRESULT res = ReadStream_FALSE(inStream, packBuf, compressedSizeT);
|
||||
|
||||
if (res == S_OK)
|
||||
{
|
||||
lzxDecoderSpec->KeepHistoryForNext = true;
|
||||
res = lzxDecoderSpec->Code(packBuf, compressedSizeT, kBlockSize); // rt.BlockSize;
|
||||
if (res == S_OK)
|
||||
res = WriteStream(chmFolderOutStream,
|
||||
lzxDecoderSpec->GetUnpackData(),
|
||||
lzxDecoderSpec->GetUnpackSize());
|
||||
}
|
||||
|
||||
if (res != S_OK)
|
||||
{
|
||||
if (res != S_FALSE)
|
||||
@@ -714,6 +761,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
{
|
||||
RINOK(chmFolderOutStream->FlushCorrupted(unPackSize));
|
||||
}
|
||||
|
||||
currentTotalSize += folderSize;
|
||||
if (folderIndex == lastFolderIndex)
|
||||
break;
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
// #include <stdio.h>
|
||||
|
||||
#include "../../../../C/CpuArch.h"
|
||||
|
||||
#include "../../../Common/IntToString.h"
|
||||
#include "../../../Common/UTFConvert.h"
|
||||
|
||||
@@ -11,6 +13,10 @@
|
||||
|
||||
#include "ChmIn.h"
|
||||
|
||||
#define Get16(p) GetUi16(p)
|
||||
#define Get32(p) GetUi32(p)
|
||||
#define Get64(p) GetUi64(p)
|
||||
|
||||
namespace NArchive {
|
||||
namespace NChm {
|
||||
|
||||
@@ -168,38 +174,36 @@ Byte CInArchive::ReadByte()
|
||||
|
||||
void CInArchive::Skip(size_t size)
|
||||
{
|
||||
while (size-- != 0)
|
||||
ReadByte();
|
||||
if (_inBuffer.Skip(size) != size)
|
||||
throw CEnexpectedEndException();
|
||||
}
|
||||
|
||||
void CInArchive::ReadBytes(Byte *data, UInt32 size)
|
||||
{
|
||||
for (UInt32 i = 0; i < size; i++)
|
||||
data[i] = ReadByte();
|
||||
if (_inBuffer.ReadBytes(data, size) != size)
|
||||
throw CEnexpectedEndException();
|
||||
}
|
||||
|
||||
UInt16 CInArchive::ReadUInt16()
|
||||
{
|
||||
UInt16 val = 0;
|
||||
for (int i = 0; i < 2; i++)
|
||||
val |= ((UInt16)(ReadByte()) << (8 * i));
|
||||
return val;
|
||||
Byte b0, b1;
|
||||
if (!_inBuffer.ReadByte(b0)) throw CEnexpectedEndException();
|
||||
if (!_inBuffer.ReadByte(b1)) throw CEnexpectedEndException();
|
||||
return (UInt16)(((UInt16)b1 << 8) | b0);
|
||||
}
|
||||
|
||||
UInt32 CInArchive::ReadUInt32()
|
||||
{
|
||||
UInt32 val = 0;
|
||||
for (int i = 0; i < 4; i++)
|
||||
val |= ((UInt32)(ReadByte()) << (8 * i));
|
||||
return val;
|
||||
Byte p[4];
|
||||
ReadBytes(p, 4);
|
||||
return Get32(p);
|
||||
}
|
||||
|
||||
UInt64 CInArchive::ReadUInt64()
|
||||
{
|
||||
UInt64 val = 0;
|
||||
for (int i = 0; i < 8; i++)
|
||||
val |= ((UInt64)(ReadByte()) << (8 * i));
|
||||
return val;
|
||||
Byte p[8];
|
||||
ReadBytes(p, 8);
|
||||
return Get64(p);
|
||||
}
|
||||
|
||||
UInt64 CInArchive::ReadEncInt()
|
||||
@@ -227,15 +231,10 @@ void CInArchive::ReadGUID(GUID &g)
|
||||
void CInArchive::ReadString(unsigned size, AString &s)
|
||||
{
|
||||
s.Empty();
|
||||
while (size-- != 0)
|
||||
if (size != 0)
|
||||
{
|
||||
char c = (char)ReadByte();
|
||||
if (c == 0)
|
||||
{
|
||||
Skip(size);
|
||||
return;
|
||||
}
|
||||
s += c;
|
||||
ReadBytes((Byte *)s.GetBuf(size), size);
|
||||
s.ReleaseBuf_CalcLen(size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -380,6 +379,7 @@ HRESULT CInArchive::OpenChm(IInStream *inStream, CDatabase &database)
|
||||
ReadUInt32(); // Chunk number of next listing chunk when reading
|
||||
// directory in sequence (-1 if this is the last listing chunk)
|
||||
unsigned numItems = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
UInt64 offset = _inBuffer.GetProcessedSize() - chunkPos;
|
||||
@@ -391,9 +391,16 @@ HRESULT CInArchive::OpenChm(IInStream *inStream, CDatabase &database)
|
||||
RINOK(ReadDirEntry(database));
|
||||
numItems++;
|
||||
}
|
||||
|
||||
Skip(quickrefLength - 2);
|
||||
if (ReadUInt16() != numItems)
|
||||
return S_FALSE;
|
||||
|
||||
unsigned rrr = ReadUInt16();
|
||||
if (rrr != numItems)
|
||||
{
|
||||
// Lazarus 9-26-2 chm contains 0 here.
|
||||
if (rrr != 0)
|
||||
return S_FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
Skip(dirChunkSize - 4);
|
||||
@@ -649,7 +656,7 @@ static AString GetSectionPrefix(const AString &name)
|
||||
|
||||
#define RINOZ(x) { int __tt = (x); if (__tt != 0) return __tt; }
|
||||
|
||||
static int CompareFiles(const int *p1, const int *p2, void *param)
|
||||
static int CompareFiles(const unsigned *p1, const unsigned *p2, void *param)
|
||||
{
|
||||
const CObjectVector<CItem> &items = *(const CObjectVector<CItem> *)param;
|
||||
const CItem &item1 = items[*p1];
|
||||
@@ -709,6 +716,14 @@ bool CFilesDatabase::Check()
|
||||
return true;
|
||||
}
|
||||
|
||||
static int inline GetLog(UInt32 num)
|
||||
{
|
||||
for (int i = 0; i < 32; i++)
|
||||
if (((UInt32)1 << i) == num)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
HRESULT CInArchive::OpenHighLevel(IInStream *inStream, CFilesDatabase &database)
|
||||
{
|
||||
{
|
||||
@@ -716,7 +731,7 @@ HRESULT CInArchive::OpenHighLevel(IInStream *inStream, CFilesDatabase &database)
|
||||
RINOK(DecompressStream(inStream, database, kNameList));
|
||||
/* UInt16 length = */ ReadUInt16();
|
||||
UInt16 numSections = ReadUInt16();
|
||||
for (int i = 0; i < numSections; i++)
|
||||
for (unsigned i = 0; i < numSections; i++)
|
||||
{
|
||||
CSectionInfo section;
|
||||
UInt16 nameLen = ReadUInt16();
|
||||
@@ -751,10 +766,10 @@ HRESULT CInArchive::OpenHighLevel(IInStream *inStream, CFilesDatabase &database)
|
||||
RINOK(DecompressStream(inStream, database, transformPrefix + kTransformList));
|
||||
if ((_chunkSize & 0xF) != 0)
|
||||
return S_FALSE;
|
||||
int numGuids = (int)(_chunkSize / 0x10);
|
||||
unsigned numGuids = (unsigned)(_chunkSize / 0x10);
|
||||
if (numGuids < 1)
|
||||
return S_FALSE;
|
||||
for (int i = 0; i < numGuids; i++)
|
||||
for (unsigned i = 0; i < numGuids; i++)
|
||||
{
|
||||
CMethodInfo method;
|
||||
ReadGUID(method.Guid);
|
||||
@@ -771,6 +786,7 @@ HRESULT CInArchive::OpenHighLevel(IInStream *inStream, CFilesDatabase &database)
|
||||
{
|
||||
// Control Data
|
||||
RINOK(DecompressStream(inStream, database, sectionPrefix + kControlData));
|
||||
|
||||
FOR_VECTOR (mi, section.Methods)
|
||||
{
|
||||
CMethodInfo &method = section.Methods[mi];
|
||||
@@ -785,27 +801,25 @@ HRESULT CInArchive::OpenHighLevel(IInStream *inStream, CFilesDatabase &database)
|
||||
li.Version = ReadUInt32();
|
||||
if (li.Version != 2 && li.Version != 3)
|
||||
return S_FALSE;
|
||||
li.ResetInterval = ReadUInt32();
|
||||
li.WindowSize = ReadUInt32();
|
||||
|
||||
{
|
||||
// There is bug in VC6, if we use function call as parameter for inline function
|
||||
UInt32 val32 = ReadUInt32();
|
||||
int n = GetLog(val32);
|
||||
if (n < 0 || n > 16)
|
||||
return S_FALSE;
|
||||
li.ResetIntervalBits = n;
|
||||
}
|
||||
|
||||
{
|
||||
UInt32 val32 = ReadUInt32();
|
||||
int n = GetLog(val32);
|
||||
if (n < 0 || n > 16)
|
||||
return S_FALSE;
|
||||
li.WindowSizeBits = n;
|
||||
}
|
||||
|
||||
li.CacheSize = ReadUInt32();
|
||||
if (
|
||||
li.ResetInterval != 1 &&
|
||||
li.ResetInterval != 2 &&
|
||||
li.ResetInterval != 4 &&
|
||||
li.ResetInterval != 8 &&
|
||||
li.ResetInterval != 16 &&
|
||||
li.ResetInterval != 32 &&
|
||||
li.ResetInterval != 64)
|
||||
return S_FALSE;
|
||||
if (
|
||||
li.WindowSize != 1 &&
|
||||
li.WindowSize != 2 &&
|
||||
li.WindowSize != 4 &&
|
||||
li.WindowSize != 8 &&
|
||||
li.WindowSize != 16 &&
|
||||
li.WindowSize != 32 &&
|
||||
li.WindowSize != 64)
|
||||
return S_FALSE;
|
||||
numDWORDS -= 5;
|
||||
while (numDWORDS-- != 0)
|
||||
ReadUInt32();
|
||||
@@ -835,6 +849,7 @@ HRESULT CInArchive::OpenHighLevel(IInStream *inStream, CFilesDatabase &database)
|
||||
RINOK(DecompressStream(inStream, database, transformPrefix +
|
||||
method.GetGuidString() + kResetTable));
|
||||
CResetTable &rt = method.LzxInfo.ResetTable;
|
||||
|
||||
if (_chunkSize < 4)
|
||||
{
|
||||
if (_chunkSize != 0)
|
||||
@@ -844,7 +859,7 @@ HRESULT CInArchive::OpenHighLevel(IInStream *inStream, CFilesDatabase &database)
|
||||
return S_FALSE;
|
||||
rt.UncompressedSize = 0;
|
||||
rt.CompressedSize = 0;
|
||||
rt.BlockSize = 0;
|
||||
// rt.BlockSize = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -852,18 +867,45 @@ HRESULT CInArchive::OpenHighLevel(IInStream *inStream, CFilesDatabase &database)
|
||||
if (ver != 2 && ver != 3)
|
||||
return S_FALSE;
|
||||
UInt32 numEntries = ReadUInt32();
|
||||
if (ReadUInt32() != 8) // Size of table entry (bytes)
|
||||
const unsigned kEntrySize = 8;
|
||||
if (ReadUInt32() != kEntrySize)
|
||||
return S_FALSE;
|
||||
if (ReadUInt32() != 0x28) // Len of table header
|
||||
const unsigned kRtHeaderSize = 4 * 4 + 8 * 3;
|
||||
if (ReadUInt32() != kRtHeaderSize)
|
||||
return S_FALSE;
|
||||
if (kRtHeaderSize + kEntrySize * (UInt64)numEntries != _chunkSize)
|
||||
return S_FALSE;
|
||||
|
||||
rt.UncompressedSize = ReadUInt64();
|
||||
rt.CompressedSize = ReadUInt64();
|
||||
rt.BlockSize = ReadUInt64(); // 0x8000 block size for locations below
|
||||
if (rt.BlockSize != 0x8000)
|
||||
UInt64 blockSize = ReadUInt64();
|
||||
if (blockSize != kBlockSize)
|
||||
return S_FALSE;
|
||||
UInt64 numBlocks = (rt.UncompressedSize + kBlockSize + 1) / kBlockSize;
|
||||
if (numEntries != numBlocks &&
|
||||
numEntries != numBlocks + 1)
|
||||
return S_FALSE;
|
||||
|
||||
rt.ResetOffsets.ClearAndReserve(numEntries);
|
||||
|
||||
for (UInt32 i = 0; i < numEntries; i++)
|
||||
rt.ResetOffsets.AddInReserved(ReadUInt64());
|
||||
{
|
||||
UInt64 v = ReadUInt64();
|
||||
if (i != 0 && v < rt.ResetOffsets[i - 1])
|
||||
return S_FALSE;
|
||||
rt.ResetOffsets.AddInReserved(v);
|
||||
}
|
||||
|
||||
if (numEntries != 0)
|
||||
if (rt.ResetOffsets[0] != 0)
|
||||
return S_FALSE;
|
||||
|
||||
if (numEntries == numBlocks + 1)
|
||||
{
|
||||
// Lazarus 9-26-2 chm contains additional entty
|
||||
if (rt.ResetOffsets.Back() != rt.CompressedSize)
|
||||
return S_FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -896,14 +938,16 @@ HRESULT CInArchive::Open2(IInStream *inStream,
|
||||
|
||||
if (_help2)
|
||||
{
|
||||
const int kSignatureSize = 8;
|
||||
UInt64 signature = ((UInt64)kSignature_ITLS << 32)| kSignature_ITOL;
|
||||
const unsigned kSignatureSize = 8;
|
||||
const UInt64 signature = ((UInt64)kSignature_ITLS << 32) | kSignature_ITOL;
|
||||
UInt64 limit = 1 << 18;
|
||||
|
||||
if (searchHeaderSizeLimit)
|
||||
if (limit > *searchHeaderSizeLimit)
|
||||
limit = *searchHeaderSizeLimit;
|
||||
|
||||
UInt64 val = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
Byte b;
|
||||
@@ -919,6 +963,7 @@ HRESULT CInArchive::Open2(IInStream *inStream,
|
||||
return S_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
database.StartPosition += _inBuffer.GetProcessedSize() - kSignatureSize;
|
||||
RINOK(OpenHelp2(inStream, database));
|
||||
if (database.NewFormat)
|
||||
|
||||
@@ -36,12 +36,13 @@ struct CItem
|
||||
|
||||
bool IsDir() const
|
||||
{
|
||||
if (Name.Len() == 0)
|
||||
if (Name.IsEmpty())
|
||||
return false;
|
||||
return (Name.Back() == '/');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct CDatabase
|
||||
{
|
||||
UInt64 StartPosition;
|
||||
@@ -73,11 +74,14 @@ struct CDatabase
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const UInt32 kBlockSize = 1 << 15;
|
||||
|
||||
struct CResetTable
|
||||
{
|
||||
UInt64 UncompressedSize;
|
||||
UInt64 CompressedSize;
|
||||
UInt64 BlockSize;
|
||||
// unsigned BlockSizeBits;
|
||||
CRecordVector<UInt64> ResetOffsets;
|
||||
|
||||
bool GetCompressedSizeOfBlocks(UInt64 blockIndex, UInt32 numBlocks, UInt64 &size) const
|
||||
@@ -91,39 +95,41 @@ struct CResetTable
|
||||
size = ResetOffsets[(unsigned)(blockIndex + numBlocks)] - startPos;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GetCompressedSizeOfBlock(UInt64 blockIndex, UInt64 &size) const
|
||||
{
|
||||
return GetCompressedSizeOfBlocks(blockIndex, 1, size);
|
||||
}
|
||||
|
||||
UInt64 GetNumBlocks(UInt64 size) const
|
||||
{
|
||||
return (size + BlockSize - 1) / BlockSize;
|
||||
return (size + kBlockSize - 1) / kBlockSize;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct CLzxInfo
|
||||
{
|
||||
UInt32 Version;
|
||||
UInt32 ResetInterval;
|
||||
UInt32 WindowSize;
|
||||
|
||||
unsigned ResetIntervalBits;
|
||||
unsigned WindowSizeBits;
|
||||
UInt32 CacheSize;
|
||||
|
||||
CResetTable ResetTable;
|
||||
|
||||
UInt32 GetNumDictBits() const
|
||||
unsigned GetNumDictBits() const
|
||||
{
|
||||
if (Version == 2 || Version == 3)
|
||||
{
|
||||
for (unsigned i = 0; i <= 31; i++)
|
||||
if (((UInt32)1 << i) >= WindowSize)
|
||||
return 15 + i;
|
||||
}
|
||||
return 15 + WindowSizeBits;
|
||||
return 0;
|
||||
}
|
||||
|
||||
UInt64 GetFolderSize() const { return ResetTable.BlockSize * ResetInterval; }
|
||||
UInt64 GetFolderSize() const { return kBlockSize << ResetIntervalBits; }
|
||||
UInt64 GetFolder(UInt64 offset) const { return offset / GetFolderSize(); }
|
||||
UInt64 GetFolderPos(UInt64 folderIndex) const { return folderIndex * GetFolderSize(); }
|
||||
UInt64 GetBlockIndexFromFolderIndex(UInt64 folderIndex) const { return folderIndex * ResetInterval; }
|
||||
UInt64 GetBlockIndexFromFolderIndex(UInt64 folderIndex) const { return folderIndex << ResetIntervalBits; }
|
||||
|
||||
bool GetOffsetOfFolder(UInt64 folderIndex, UInt64 &offset) const
|
||||
{
|
||||
UInt64 blockIndex = GetBlockIndexFromFolderIndex(folderIndex);
|
||||
@@ -132,24 +138,28 @@ struct CLzxInfo
|
||||
offset = ResetTable.ResetOffsets[(unsigned)blockIndex];
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GetCompressedSizeOfFolder(UInt64 folderIndex, UInt64 &size) const
|
||||
{
|
||||
UInt64 blockIndex = GetBlockIndexFromFolderIndex(folderIndex);
|
||||
return ResetTable.GetCompressedSizeOfBlocks(blockIndex, ResetInterval, size);
|
||||
return ResetTable.GetCompressedSizeOfBlocks(blockIndex, (UInt32)1 << ResetIntervalBits, size);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct CMethodInfo
|
||||
{
|
||||
GUID Guid;
|
||||
CByteBuffer ControlData;
|
||||
CLzxInfo LzxInfo;
|
||||
|
||||
bool IsLzx() const;
|
||||
bool IsDes() const;
|
||||
AString GetGuidString() const;
|
||||
UString GetName() const;
|
||||
};
|
||||
|
||||
|
||||
struct CSectionInfo
|
||||
{
|
||||
UInt64 Offset;
|
||||
@@ -167,25 +177,25 @@ class CFilesDatabase: public CDatabase
|
||||
{
|
||||
public:
|
||||
bool LowLevel;
|
||||
CRecordVector<int> Indices;
|
||||
CUIntVector Indices;
|
||||
CObjectVector<CSectionInfo> Sections;
|
||||
|
||||
UInt64 GetFileSize(int fileIndex) const { return Items[Indices[fileIndex]].Size; }
|
||||
UInt64 GetFileOffset(int fileIndex) const { return Items[Indices[fileIndex]].Offset; }
|
||||
UInt64 GetFileSize(unsigned fileIndex) const { return Items[Indices[fileIndex]].Size; }
|
||||
UInt64 GetFileOffset(unsigned fileIndex) const { return Items[Indices[fileIndex]].Offset; }
|
||||
|
||||
UInt64 GetFolder(int fileIndex) const
|
||||
UInt64 GetFolder(unsigned fileIndex) const
|
||||
{
|
||||
const CItem &item = Items[Indices[fileIndex]];
|
||||
const CSectionInfo §ion = Sections[(int)item.Section];
|
||||
const CSectionInfo §ion = Sections[(unsigned)item.Section];
|
||||
if (section.IsLzx())
|
||||
return section.Methods[0].LzxInfo.GetFolder(item.Offset);
|
||||
return 0;
|
||||
}
|
||||
|
||||
UInt64 GetLastFolder(int fileIndex) const
|
||||
UInt64 GetLastFolder(unsigned fileIndex) const
|
||||
{
|
||||
const CItem &item = Items[Indices[fileIndex]];
|
||||
const CSectionInfo §ion = Sections[(int)item.Section];
|
||||
const CSectionInfo §ion = Sections[(unsigned)item.Section];
|
||||
if (section.IsLzx())
|
||||
return section.Methods[0].LzxInfo.GetFolder(item.Offset + item.Size - 1);
|
||||
return 0;
|
||||
@@ -203,19 +213,12 @@ public:
|
||||
CDatabase::Clear();
|
||||
HighLevelClear();
|
||||
}
|
||||
|
||||
void SetIndices();
|
||||
void Sort();
|
||||
bool Check();
|
||||
};
|
||||
|
||||
/*
|
||||
class CProgressVirt
|
||||
{
|
||||
public:
|
||||
STDMETHOD(SetTotal)(const UInt64 *numFiles) PURE;
|
||||
STDMETHOD(SetCompleted)(const UInt64 *numFiles) PURE;
|
||||
};
|
||||
*/
|
||||
|
||||
class CInArchive
|
||||
{
|
||||
|
||||
@@ -433,9 +433,9 @@ HRESULT CDatabase::Open(IInStream *inStream)
|
||||
SectorSizeBits = sectorSizeBits;
|
||||
MiniSectorSizeBits = miniSectorSizeBits;
|
||||
|
||||
if (sectorSizeBits > 28 ||
|
||||
if (sectorSizeBits > 24 ||
|
||||
sectorSizeBits < 7 ||
|
||||
miniSectorSizeBits > 28 ||
|
||||
miniSectorSizeBits > 24 ||
|
||||
miniSectorSizeBits < 2 ||
|
||||
miniSectorSizeBits > sectorSizeBits)
|
||||
return S_FALSE;
|
||||
@@ -592,13 +592,13 @@ HRESULT CDatabase::Open(IInStream *inStream)
|
||||
MainSubfile = -1;
|
||||
|
||||
{
|
||||
FOR_VECTOR(t, Items)
|
||||
FOR_VECTOR (t, Items)
|
||||
{
|
||||
Update_PhySize_WithItem(t);
|
||||
}
|
||||
}
|
||||
{
|
||||
FOR_VECTOR(t, Items)
|
||||
FOR_VECTOR (t, Items)
|
||||
{
|
||||
const CItem &item = Items[t];
|
||||
|
||||
@@ -739,7 +739,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
return S_OK;
|
||||
UInt32 i;
|
||||
UInt64 totalSize = 0;
|
||||
for(i = 0; i < numItems; i++)
|
||||
for (i = 0; i < numItems; i++)
|
||||
{
|
||||
const CItem &item = _db.Items[_db.Refs[allFilesMode ? i : indices[i]].Did];
|
||||
if (!item.IsDir())
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
// CoderMixer.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "CoderMixer.h"
|
||||
|
||||
namespace NCoderMixer {
|
||||
|
||||
void CCoderInfo::SetCoderInfo(const UInt64 *inSize, const UInt64 *outSize)
|
||||
{
|
||||
InSizeAssigned = (inSize != 0);
|
||||
if (InSizeAssigned)
|
||||
InSizeValue = *inSize;
|
||||
OutSizeAssigned = (outSize != 0);
|
||||
if (OutSizeAssigned)
|
||||
OutSizeValue = *outSize;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
// CoderMixer.h
|
||||
|
||||
#ifndef __CODER_MIXER_H
|
||||
#define __CODER_MIXER_H
|
||||
|
||||
#include "../../../Common/MyCom.h"
|
||||
#include "../../ICoder.h"
|
||||
|
||||
namespace NCoderMixer {
|
||||
|
||||
struct CCoderInfo
|
||||
{
|
||||
CMyComPtr<ICompressCoder> Coder;
|
||||
CMyComPtr<ISequentialInStream> InStream;
|
||||
CMyComPtr<ISequentialOutStream> OutStream;
|
||||
CMyComPtr<ICompressProgressInfo> Progress;
|
||||
|
||||
UInt64 InSizeValue;
|
||||
UInt64 OutSizeValue;
|
||||
bool InSizeAssigned;
|
||||
bool OutSizeAssigned;
|
||||
|
||||
void ReInit()
|
||||
{
|
||||
InSizeAssigned = OutSizeAssigned = false;
|
||||
}
|
||||
|
||||
void SetCoderInfo(const UInt64 *inSize, const UInt64 *outSize);
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -1,254 +0,0 @@
|
||||
// CoderMixer2MT.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "CoderMixer2MT.h"
|
||||
|
||||
namespace NCoderMixer2 {
|
||||
|
||||
void CCoderMT::Execute() { Code(NULL); }
|
||||
|
||||
void CCoderMT::Code(ICompressProgressInfo *progress)
|
||||
{
|
||||
unsigned numInStreams = EncodeMode ? 1 : NumStreams;
|
||||
unsigned numOutStreams = EncodeMode ? NumStreams : 1;
|
||||
|
||||
InStreamPointers.ClearAndReserve(numInStreams);
|
||||
OutStreamPointers.ClearAndReserve(numOutStreams);
|
||||
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < numInStreams; i++)
|
||||
InStreamPointers.AddInReserved((ISequentialInStream *)InStreams[i]);
|
||||
|
||||
for (i = 0; i < numOutStreams; i++)
|
||||
OutStreamPointers.AddInReserved((ISequentialOutStream *)OutStreams[i]);
|
||||
|
||||
// we suppose that UnpackSizePointer and PackSizePointers contain correct pointers.
|
||||
/*
|
||||
if (UnpackSizePointer)
|
||||
UnpackSizePointer = &UnpackSize;
|
||||
for (i = 0; i < NumStreams; i++)
|
||||
if (PackSizePointers[i])
|
||||
PackSizePointers[i] = &PackSizes[i];
|
||||
*/
|
||||
|
||||
if (Coder)
|
||||
Result = Coder->Code(InStreamPointers[0], OutStreamPointers[0],
|
||||
EncodeMode ? UnpackSizePointer : PackSizePointers[0],
|
||||
EncodeMode ? PackSizePointers[0] : UnpackSizePointer,
|
||||
progress);
|
||||
else
|
||||
Result = Coder2->Code(
|
||||
&InStreamPointers.Front(), EncodeMode ? &UnpackSizePointer : &PackSizePointers.Front(), numInStreams,
|
||||
&OutStreamPointers.Front(), EncodeMode ? &PackSizePointers.Front(): &UnpackSizePointer, numOutStreams,
|
||||
progress);
|
||||
|
||||
InStreamPointers.Clear();
|
||||
OutStreamPointers.Clear();
|
||||
|
||||
for (i = 0; i < InStreams.Size(); i++)
|
||||
InStreams[i].Release();
|
||||
for (i = 0; i < OutStreams.Size(); i++)
|
||||
OutStreams[i].Release();
|
||||
}
|
||||
|
||||
HRESULT CMixerMT::SetBindInfo(const CBindInfo &bindInfo)
|
||||
{
|
||||
CMixer::SetBindInfo(bindInfo);
|
||||
|
||||
_streamBinders.Clear();
|
||||
FOR_VECTOR (i, _bi.Bonds)
|
||||
{
|
||||
RINOK(_streamBinders.AddNew().CreateEvents());
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void CMixerMT::AddCoder(ICompressCoder *coder, ICompressCoder2 *coder2, bool isFilter)
|
||||
{
|
||||
const CCoderStreamsInfo &c = _bi.Coders[_coders.Size()];
|
||||
CCoderMT &c2 = _coders.AddNew();
|
||||
c2.NumStreams = c.NumStreams;
|
||||
c2.EncodeMode = EncodeMode;
|
||||
c2.Coder = coder;
|
||||
c2.Coder2 = coder2;
|
||||
IsFilter_Vector.Add(isFilter);
|
||||
}
|
||||
|
||||
CCoder &CMixerMT::GetCoder(unsigned index)
|
||||
{
|
||||
return _coders[index];
|
||||
}
|
||||
|
||||
void CMixerMT::ReInit()
|
||||
{
|
||||
FOR_VECTOR (i, _streamBinders)
|
||||
_streamBinders[i].ReInit();
|
||||
}
|
||||
|
||||
void CMixerMT::SelectMainCoder(bool useFirst)
|
||||
{
|
||||
unsigned ci = _bi.UnpackCoder;
|
||||
|
||||
if (!useFirst)
|
||||
for (;;)
|
||||
{
|
||||
if (_coders[ci].NumStreams != 1)
|
||||
break;
|
||||
if (!IsFilter_Vector[ci])
|
||||
break;
|
||||
|
||||
UInt32 st = _bi.Coder_to_Stream[ci];
|
||||
if (_bi.IsStream_in_PackStreams(st))
|
||||
break;
|
||||
int bond = _bi.FindBond_for_PackStream(st);
|
||||
if (bond < 0)
|
||||
throw 20150213;
|
||||
ci = _bi.Bonds[bond].UnpackIndex;
|
||||
}
|
||||
|
||||
MainCoderIndex = ci;
|
||||
}
|
||||
|
||||
HRESULT CMixerMT::Init(ISequentialInStream * const *inStreams, ISequentialOutStream * const *outStreams)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < _coders.Size(); i++)
|
||||
{
|
||||
CCoderMT &coderInfo = _coders[i];
|
||||
const CCoderStreamsInfo &csi = _bi.Coders[i];
|
||||
|
||||
UInt32 j;
|
||||
|
||||
unsigned numInStreams = EncodeMode ? 1 : csi.NumStreams;
|
||||
unsigned numOutStreams = EncodeMode ? csi.NumStreams : 1;
|
||||
|
||||
coderInfo.InStreams.Clear();
|
||||
for (j = 0; j < numInStreams; j++)
|
||||
coderInfo.InStreams.AddNew();
|
||||
|
||||
coderInfo.OutStreams.Clear();
|
||||
for (j = 0; j < numOutStreams; j++)
|
||||
coderInfo.OutStreams.AddNew();
|
||||
}
|
||||
|
||||
for (i = 0; i < _bi.Bonds.Size(); i++)
|
||||
{
|
||||
const CBond &bond = _bi.Bonds[i];
|
||||
|
||||
UInt32 inCoderIndex, inCoderStreamIndex;
|
||||
UInt32 outCoderIndex, outCoderStreamIndex;
|
||||
|
||||
{
|
||||
UInt32 coderIndex, coderStreamIndex;
|
||||
_bi.GetCoder_for_Stream(bond.PackIndex, coderIndex, coderStreamIndex);
|
||||
|
||||
inCoderIndex = EncodeMode ? bond.UnpackIndex : coderIndex;
|
||||
outCoderIndex = EncodeMode ? coderIndex : bond.UnpackIndex;
|
||||
|
||||
inCoderStreamIndex = EncodeMode ? 0 : coderStreamIndex;
|
||||
outCoderStreamIndex = EncodeMode ? coderStreamIndex : 0;
|
||||
}
|
||||
|
||||
_streamBinders[i].CreateStreams(
|
||||
&_coders[inCoderIndex].InStreams[inCoderStreamIndex],
|
||||
&_coders[outCoderIndex].OutStreams[outCoderStreamIndex]);
|
||||
|
||||
CMyComPtr<ICompressSetBufSize> inSetSize, outSetSize;
|
||||
_coders[inCoderIndex].QueryInterface(IID_ICompressSetBufSize, (void **)&inSetSize);
|
||||
_coders[outCoderIndex].QueryInterface(IID_ICompressSetBufSize, (void **)&outSetSize);
|
||||
if (inSetSize && outSetSize)
|
||||
{
|
||||
const UInt32 kBufSize = 1 << 19;
|
||||
inSetSize->SetInBufSize(inCoderStreamIndex, kBufSize);
|
||||
outSetSize->SetOutBufSize(outCoderStreamIndex, kBufSize);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
CCoderMT &cod = _coders[_bi.UnpackCoder];
|
||||
if (EncodeMode)
|
||||
cod.InStreams[0] = inStreams[0];
|
||||
else
|
||||
cod.OutStreams[0] = outStreams[0];
|
||||
}
|
||||
|
||||
for (i = 0; i < _bi.PackStreams.Size(); i++)
|
||||
{
|
||||
UInt32 coderIndex, coderStreamIndex;
|
||||
_bi.GetCoder_for_Stream(_bi.PackStreams[i], coderIndex, coderStreamIndex);
|
||||
CCoderMT &cod = _coders[coderIndex];
|
||||
if (EncodeMode)
|
||||
cod.OutStreams[coderStreamIndex] = outStreams[i];
|
||||
else
|
||||
cod.InStreams[coderStreamIndex] = inStreams[i];
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CMixerMT::ReturnIfError(HRESULT code)
|
||||
{
|
||||
FOR_VECTOR (i, _coders)
|
||||
if (_coders[i].Result == code)
|
||||
return code;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CMixerMT::Code(
|
||||
ISequentialInStream * const *inStreams,
|
||||
ISequentialOutStream * const *outStreams,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
Init(inStreams, outStreams);
|
||||
|
||||
unsigned i;
|
||||
for (i = 0; i < _coders.Size(); i++)
|
||||
if (i != MainCoderIndex)
|
||||
{
|
||||
RINOK(_coders[i].Create());
|
||||
}
|
||||
|
||||
for (i = 0; i < _coders.Size(); i++)
|
||||
if (i != MainCoderIndex)
|
||||
_coders[i].Start();
|
||||
|
||||
_coders[MainCoderIndex].Code(progress);
|
||||
|
||||
for (i = 0; i < _coders.Size(); i++)
|
||||
if (i != MainCoderIndex)
|
||||
_coders[i].WaitExecuteFinish();
|
||||
|
||||
RINOK(ReturnIfError(E_ABORT));
|
||||
RINOK(ReturnIfError(E_OUTOFMEMORY));
|
||||
|
||||
for (i = 0; i < _coders.Size(); i++)
|
||||
{
|
||||
HRESULT result = _coders[i].Result;
|
||||
if (result != S_OK
|
||||
&& result != k_My_HRESULT_WritingWasCut
|
||||
&& result != S_FALSE
|
||||
&& result != E_FAIL)
|
||||
return result;
|
||||
}
|
||||
|
||||
RINOK(ReturnIfError(S_FALSE));
|
||||
|
||||
for (i = 0; i < _coders.Size(); i++)
|
||||
{
|
||||
HRESULT result = _coders[i].Result;
|
||||
if (result != S_OK && result != k_My_HRESULT_WritingWasCut)
|
||||
return result;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
UInt64 CMixerMT::GetBondStreamSize(unsigned bondIndex) const
|
||||
{
|
||||
return _streamBinders[bondIndex].ProcessedSize;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
// CoderMixer2MT.h
|
||||
|
||||
#ifndef __CODER_MIXER2_MT_H
|
||||
#define __CODER_MIXER2_MT_H
|
||||
|
||||
#include "../../../Common/MyCom.h"
|
||||
|
||||
#include "../../Common/StreamBinder.h"
|
||||
#include "../../Common/VirtThread.h"
|
||||
|
||||
#include "CoderMixer2.h"
|
||||
|
||||
namespace NCoderMixer2 {
|
||||
|
||||
class CCoderMT: public CCoder, public CVirtThread
|
||||
{
|
||||
CLASS_NO_COPY(CCoderMT)
|
||||
CRecordVector<ISequentialInStream*> InStreamPointers;
|
||||
CRecordVector<ISequentialOutStream*> OutStreamPointers;
|
||||
|
||||
private:
|
||||
void Execute();
|
||||
public:
|
||||
bool EncodeMode;
|
||||
HRESULT Result;
|
||||
CObjectVector< CMyComPtr<ISequentialInStream> > InStreams;
|
||||
CObjectVector< CMyComPtr<ISequentialOutStream> > OutStreams;
|
||||
|
||||
CCoderMT(): EncodeMode(false) {}
|
||||
~CCoderMT() { CVirtThread::WaitThreadFinish(); }
|
||||
|
||||
void Code(ICompressProgressInfo *progress);
|
||||
};
|
||||
|
||||
|
||||
|
||||
class CMixerMT:
|
||||
public IUnknown,
|
||||
public CMixer,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
CObjectVector<CStreamBinder> _streamBinders;
|
||||
|
||||
HRESULT Init(ISequentialInStream * const *inStreams, ISequentialOutStream * const *outStreams);
|
||||
HRESULT ReturnIfError(HRESULT code);
|
||||
|
||||
public:
|
||||
CObjectVector<CCoderMT> _coders;
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
virtual HRESULT SetBindInfo(const CBindInfo &bindInfo);
|
||||
|
||||
virtual void AddCoder(ICompressCoder *coder, ICompressCoder2 *coder2, bool isFilter);
|
||||
|
||||
virtual CCoder &GetCoder(unsigned index);
|
||||
|
||||
virtual void SelectMainCoder(bool useFirst);
|
||||
|
||||
virtual void ReInit();
|
||||
|
||||
virtual void SetCoderInfo(unsigned coderIndex, const UInt64 *unpackSize, const UInt64 * const *packSizes)
|
||||
{ _coders[coderIndex].SetCoderInfo(unpackSize, packSizes); }
|
||||
|
||||
virtual HRESULT Code(
|
||||
ISequentialInStream * const *inStreams,
|
||||
ISequentialOutStream * const *outStreams,
|
||||
ICompressProgressInfo *progress);
|
||||
|
||||
virtual UInt64 GetBondStreamSize(unsigned bondIndex) const;
|
||||
|
||||
CMixerMT(bool encodeMode): CMixer(encodeMode) {}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,562 +0,0 @@
|
||||
// CoderMixer2ST.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "CoderMixer2ST.h"
|
||||
|
||||
STDMETHODIMP CSequentialInStreamCalcSize::Read(void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
UInt32 realProcessed = 0;
|
||||
HRESULT result = S_OK;
|
||||
if (_stream)
|
||||
result = _stream->Read(data, size, &realProcessed);
|
||||
_size += realProcessed;
|
||||
if (size != 0 && realProcessed == 0)
|
||||
_wasFinished = true;
|
||||
if (processedSize)
|
||||
*processedSize = realProcessed;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
STDMETHODIMP COutStreamCalcSize::Write(const void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
HRESULT result = S_OK;
|
||||
if (_stream)
|
||||
result = _stream->Write(data, size, &size);
|
||||
_size += size;
|
||||
if (processedSize)
|
||||
*processedSize = size;
|
||||
return result;
|
||||
}
|
||||
|
||||
STDMETHODIMP COutStreamCalcSize::Flush()
|
||||
{
|
||||
HRESULT result = S_OK;
|
||||
if (_stream)
|
||||
{
|
||||
CMyComPtr<IOutStreamFlush> outStreamFlush;
|
||||
_stream.QueryInterface(IID_IOutStreamFlush, &outStreamFlush);
|
||||
if (outStreamFlush)
|
||||
result = outStreamFlush->Flush();;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
namespace NCoderMixer2 {
|
||||
|
||||
CMixerST::CMixerST(bool encodeMode):
|
||||
CMixer(encodeMode)
|
||||
{}
|
||||
|
||||
CMixerST::~CMixerST() {}
|
||||
|
||||
void CMixerST::AddCoder(ICompressCoder *coder, ICompressCoder2 *coder2, bool isFilter)
|
||||
{
|
||||
IsFilter_Vector.Add(isFilter);
|
||||
const CCoderStreamsInfo &c = _bi.Coders[_coders.Size()];
|
||||
CCoderST &c2 = _coders.AddNew();
|
||||
c2.NumStreams = c.NumStreams;
|
||||
c2.Coder = coder;
|
||||
c2.Coder2 = coder2;
|
||||
|
||||
/*
|
||||
if (isFilter)
|
||||
{
|
||||
c2.CanRead = true;
|
||||
c2.CanWrite = true;
|
||||
}
|
||||
else
|
||||
*/
|
||||
{
|
||||
IUnknown *unk = (coder ? (IUnknown *)coder : (IUnknown *)coder2);
|
||||
{
|
||||
CMyComPtr<ISequentialInStream> s;
|
||||
unk->QueryInterface(IID_ISequentialInStream, (void**)&s);
|
||||
c2.CanRead = (s != NULL);
|
||||
}
|
||||
{
|
||||
CMyComPtr<ISequentialOutStream> s;
|
||||
unk->QueryInterface(IID_ISequentialOutStream, (void**)&s);
|
||||
c2.CanWrite = (s != NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CCoder &CMixerST::GetCoder(unsigned index)
|
||||
{
|
||||
return _coders[index];
|
||||
}
|
||||
|
||||
void CMixerST::ReInit() {}
|
||||
|
||||
HRESULT CMixerST::GetInStream2(
|
||||
ISequentialInStream * const *inStreams, /* const UInt64 * const *inSizes, */
|
||||
UInt32 outStreamIndex, ISequentialInStream **inStreamRes)
|
||||
{
|
||||
UInt32 coderIndex = outStreamIndex, coderStreamIndex = 0;
|
||||
|
||||
if (EncodeMode)
|
||||
{
|
||||
_bi.GetCoder_for_Stream(outStreamIndex, coderIndex, coderStreamIndex);
|
||||
if (coderStreamIndex != 0)
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
const CCoder &coder = _coders[coderIndex];
|
||||
|
||||
CMyComPtr<ISequentialInStream> seqInStream;
|
||||
coder.QueryInterface(IID_ISequentialInStream, (void **)&seqInStream);
|
||||
if (!seqInStream)
|
||||
return E_NOTIMPL;
|
||||
|
||||
UInt32 numInStreams = EncodeMode ? 1 : coder.NumStreams;
|
||||
UInt32 startIndex = EncodeMode ? coderIndex : _bi.Coder_to_Stream[coderIndex];
|
||||
|
||||
bool isSet = false;
|
||||
|
||||
if (numInStreams == 1)
|
||||
{
|
||||
CMyComPtr<ICompressSetInStream> setStream;
|
||||
coder.QueryInterface(IID_ICompressSetInStream, (void **)&setStream);
|
||||
if (setStream)
|
||||
{
|
||||
CMyComPtr<ISequentialInStream> seqInStream2;
|
||||
RINOK(GetInStream(inStreams, /* inSizes, */ startIndex + 0, &seqInStream2));
|
||||
RINOK(setStream->SetInStream(seqInStream2));
|
||||
isSet = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isSet && numInStreams != 0)
|
||||
{
|
||||
CMyComPtr<ICompressSetInStream2> setStream2;
|
||||
coder.QueryInterface(IID_ICompressSetInStream2, (void **)&setStream2);
|
||||
if (!setStream2)
|
||||
return E_NOTIMPL;
|
||||
|
||||
for (UInt32 i = 0; i < numInStreams; i++)
|
||||
{
|
||||
CMyComPtr<ISequentialInStream> seqInStream2;
|
||||
RINOK(GetInStream(inStreams, /* inSizes, */ startIndex + i, &seqInStream2));
|
||||
RINOK(setStream2->SetInStream2(i, seqInStream2));
|
||||
}
|
||||
}
|
||||
|
||||
*inStreamRes = seqInStream.Detach();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
HRESULT CMixerST::GetInStream(
|
||||
ISequentialInStream * const *inStreams, /* const UInt64 * const *inSizes, */
|
||||
UInt32 inStreamIndex, ISequentialInStream **inStreamRes)
|
||||
{
|
||||
CMyComPtr<ISequentialInStream> seqInStream;
|
||||
|
||||
{
|
||||
int index = -1;
|
||||
if (EncodeMode)
|
||||
{
|
||||
if (_bi.UnpackCoder == inStreamIndex)
|
||||
index = 0;
|
||||
}
|
||||
else
|
||||
index = _bi.FindStream_in_PackStreams(inStreamIndex);
|
||||
|
||||
if (index >= 0)
|
||||
{
|
||||
seqInStream = inStreams[index];
|
||||
*inStreamRes = seqInStream.Detach();
|
||||
return S_OK;
|
||||
}
|
||||
}
|
||||
|
||||
int bond = FindBond_for_Stream(
|
||||
true, // forInputStream
|
||||
inStreamIndex);
|
||||
if (bond < 0)
|
||||
return E_INVALIDARG;
|
||||
|
||||
RINOK(GetInStream2(inStreams, /* inSizes, */
|
||||
_bi.Bonds[bond].Get_OutIndex(EncodeMode), &seqInStream));
|
||||
|
||||
while (_binderStreams.Size() <= (unsigned)bond)
|
||||
_binderStreams.AddNew();
|
||||
CStBinderStream &bs = _binderStreams[bond];
|
||||
|
||||
if (bs.StreamRef || bs.InStreamSpec)
|
||||
return E_NOTIMPL;
|
||||
|
||||
CSequentialInStreamCalcSize *spec = new CSequentialInStreamCalcSize;
|
||||
bs.StreamRef = spec;
|
||||
bs.InStreamSpec = spec;
|
||||
|
||||
spec->SetStream(seqInStream);
|
||||
spec->Init();
|
||||
|
||||
seqInStream = bs.InStreamSpec;
|
||||
|
||||
*inStreamRes = seqInStream.Detach();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
HRESULT CMixerST::GetOutStream(
|
||||
ISequentialOutStream * const *outStreams, /* const UInt64 * const *outSizes, */
|
||||
UInt32 outStreamIndex, ISequentialOutStream **outStreamRes)
|
||||
{
|
||||
CMyComPtr<ISequentialOutStream> seqOutStream;
|
||||
|
||||
{
|
||||
int index = -1;
|
||||
if (!EncodeMode)
|
||||
{
|
||||
if (_bi.UnpackCoder == outStreamIndex)
|
||||
index = 0;
|
||||
}
|
||||
else
|
||||
index = _bi.FindStream_in_PackStreams(outStreamIndex);
|
||||
|
||||
if (index >= 0)
|
||||
{
|
||||
seqOutStream = outStreams[index];
|
||||
*outStreamRes = seqOutStream.Detach();
|
||||
return S_OK;
|
||||
}
|
||||
}
|
||||
|
||||
int bond = FindBond_for_Stream(
|
||||
false, // forInputStream
|
||||
outStreamIndex);
|
||||
if (bond < 0)
|
||||
return E_INVALIDARG;
|
||||
|
||||
UInt32 inStreamIndex = _bi.Bonds[bond].Get_InIndex(EncodeMode);
|
||||
|
||||
UInt32 coderIndex = inStreamIndex;
|
||||
UInt32 coderStreamIndex = 0;
|
||||
|
||||
if (!EncodeMode)
|
||||
_bi.GetCoder_for_Stream(inStreamIndex, coderIndex, coderStreamIndex);
|
||||
|
||||
CCoder &coder = _coders[coderIndex];
|
||||
|
||||
/*
|
||||
if (!coder.Coder)
|
||||
return E_NOTIMPL;
|
||||
*/
|
||||
|
||||
coder.QueryInterface(IID_ISequentialOutStream, (void **)&seqOutStream);
|
||||
if (!seqOutStream)
|
||||
return E_NOTIMPL;
|
||||
|
||||
UInt32 numOutStreams = EncodeMode ? coder.NumStreams : 1;
|
||||
UInt32 startIndex = EncodeMode ? _bi.Coder_to_Stream[coderIndex]: coderIndex;
|
||||
|
||||
bool isSet = false;
|
||||
|
||||
if (numOutStreams == 1)
|
||||
{
|
||||
CMyComPtr<ICompressSetOutStream> setOutStream;
|
||||
coder.Coder.QueryInterface(IID_ICompressSetOutStream, &setOutStream);
|
||||
if (setOutStream)
|
||||
{
|
||||
CMyComPtr<ISequentialOutStream> seqOutStream2;
|
||||
RINOK(GetOutStream(outStreams, /* outSizes, */ startIndex + 0, &seqOutStream2));
|
||||
RINOK(setOutStream->SetOutStream(seqOutStream2));
|
||||
isSet = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isSet && numOutStreams != 0)
|
||||
{
|
||||
// return E_NOTIMPL;
|
||||
// /*
|
||||
CMyComPtr<ICompressSetOutStream2> setStream2;
|
||||
coder.QueryInterface(IID_ICompressSetOutStream2, (void **)&setStream2);
|
||||
if (!setStream2)
|
||||
return E_NOTIMPL;
|
||||
for (UInt32 i = 0; i < numOutStreams; i++)
|
||||
{
|
||||
CMyComPtr<ISequentialOutStream> seqOutStream2;
|
||||
RINOK(GetOutStream(outStreams, startIndex + i, &seqOutStream2));
|
||||
RINOK(setStream2->SetOutStream2(i, seqOutStream2));
|
||||
}
|
||||
// */
|
||||
}
|
||||
|
||||
while (_binderStreams.Size() <= (unsigned)bond)
|
||||
_binderStreams.AddNew();
|
||||
CStBinderStream &bs = _binderStreams[bond];
|
||||
|
||||
if (bs.StreamRef || bs.OutStreamSpec)
|
||||
return E_NOTIMPL;
|
||||
|
||||
COutStreamCalcSize *spec = new COutStreamCalcSize;
|
||||
bs.StreamRef = (ISequentialOutStream *)spec;
|
||||
bs.OutStreamSpec = spec;
|
||||
|
||||
spec->SetStream(seqOutStream);
|
||||
spec->Init();
|
||||
|
||||
seqOutStream = bs.OutStreamSpec;
|
||||
|
||||
*outStreamRes = seqOutStream.Detach();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
static HRESULT GetError(HRESULT res, HRESULT res2)
|
||||
{
|
||||
if (res == res2)
|
||||
return res;
|
||||
if (res == S_OK)
|
||||
return res2;
|
||||
if (res == k_My_HRESULT_WritingWasCut)
|
||||
{
|
||||
if (res2 != S_OK)
|
||||
return res2;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
HRESULT CMixerST::FlushStream(UInt32 streamIndex)
|
||||
{
|
||||
{
|
||||
int index = -1;
|
||||
if (!EncodeMode)
|
||||
{
|
||||
if (_bi.UnpackCoder == streamIndex)
|
||||
index = 0;
|
||||
}
|
||||
else
|
||||
index = _bi.FindStream_in_PackStreams(streamIndex);
|
||||
|
||||
if (index >= 0)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
int bond = FindBond_for_Stream(
|
||||
false, // forInputStream
|
||||
streamIndex);
|
||||
if (bond < 0)
|
||||
return E_INVALIDARG;
|
||||
|
||||
UInt32 inStreamIndex = _bi.Bonds[bond].Get_InIndex(EncodeMode);
|
||||
|
||||
UInt32 coderIndex = inStreamIndex;
|
||||
UInt32 coderStreamIndex = 0;
|
||||
if (!EncodeMode)
|
||||
_bi.GetCoder_for_Stream(inStreamIndex, coderIndex, coderStreamIndex);
|
||||
|
||||
CCoder &coder = _coders[coderIndex];
|
||||
CMyComPtr<IOutStreamFlush> flush;
|
||||
coder.QueryInterface(IID_IOutStreamFlush, (void **)&flush);
|
||||
HRESULT res = S_OK;
|
||||
if (flush)
|
||||
{
|
||||
res = flush->Flush();
|
||||
}
|
||||
return GetError(res, FlushCoder(coderIndex));
|
||||
}
|
||||
|
||||
|
||||
HRESULT CMixerST::FlushCoder(UInt32 coderIndex)
|
||||
{
|
||||
CCoder &coder = _coders[coderIndex];
|
||||
|
||||
UInt32 numOutStreams = EncodeMode ? coder.NumStreams : 1;
|
||||
UInt32 startIndex = EncodeMode ? _bi.Coder_to_Stream[coderIndex]: coderIndex;
|
||||
|
||||
HRESULT res = S_OK;
|
||||
for (unsigned i = 0; i < numOutStreams; i++)
|
||||
res = GetError(res, FlushStream(startIndex + i));
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
void CMixerST::SelectMainCoder(bool useFirst)
|
||||
{
|
||||
unsigned ci = _bi.UnpackCoder;
|
||||
|
||||
int firstNonFilter = -1;
|
||||
int firstAllowed = ci;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
const CCoderST &coder = _coders[ci];
|
||||
// break;
|
||||
|
||||
if (ci != _bi.UnpackCoder)
|
||||
if (EncodeMode ? !coder.CanWrite : !coder.CanRead)
|
||||
{
|
||||
firstAllowed = ci;
|
||||
firstNonFilter = -2;
|
||||
}
|
||||
|
||||
if (coder.NumStreams != 1)
|
||||
break;
|
||||
|
||||
UInt32 st = _bi.Coder_to_Stream[ci];
|
||||
if (_bi.IsStream_in_PackStreams(st))
|
||||
break;
|
||||
int bond = _bi.FindBond_for_PackStream(st);
|
||||
if (bond < 0)
|
||||
throw 20150213;
|
||||
|
||||
if (EncodeMode ? !coder.CanRead : !coder.CanWrite)
|
||||
break;
|
||||
|
||||
if (firstNonFilter == -1 && !IsFilter_Vector[ci])
|
||||
firstNonFilter = ci;
|
||||
|
||||
ci = _bi.Bonds[bond].UnpackIndex;
|
||||
}
|
||||
|
||||
ci = firstNonFilter;
|
||||
if (firstNonFilter < 0 || useFirst)
|
||||
ci = firstAllowed;
|
||||
MainCoderIndex = ci;
|
||||
}
|
||||
|
||||
|
||||
HRESULT CMixerST::Code(
|
||||
ISequentialInStream * const *inStreams,
|
||||
ISequentialOutStream * const *outStreams,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
_binderStreams.Clear();
|
||||
unsigned ci = MainCoderIndex;
|
||||
|
||||
const CCoder &mainCoder = _coders[MainCoderIndex];
|
||||
|
||||
CObjectVector< CMyComPtr<ISequentialInStream> > seqInStreams;
|
||||
CObjectVector< CMyComPtr<ISequentialOutStream> > seqOutStreams;
|
||||
|
||||
UInt32 numInStreams = EncodeMode ? 1 : mainCoder.NumStreams;
|
||||
UInt32 numOutStreams = !EncodeMode ? 1 : mainCoder.NumStreams;
|
||||
|
||||
UInt32 startInIndex = EncodeMode ? ci : _bi.Coder_to_Stream[ci];
|
||||
UInt32 startOutIndex = !EncodeMode ? ci : _bi.Coder_to_Stream[ci];
|
||||
|
||||
UInt32 i;
|
||||
|
||||
for (i = 0; i < numInStreams; i++)
|
||||
{
|
||||
CMyComPtr<ISequentialInStream> seqInStream;
|
||||
RINOK(GetInStream(inStreams, /* inSizes, */ startInIndex + i, &seqInStream));
|
||||
seqInStreams.Add(seqInStream);
|
||||
}
|
||||
|
||||
for (i = 0; i < numOutStreams; i++)
|
||||
{
|
||||
CMyComPtr<ISequentialOutStream> seqOutStream;
|
||||
RINOK(GetOutStream(outStreams, /* outSizes, */ startOutIndex + i, &seqOutStream));
|
||||
seqOutStreams.Add(seqOutStream);
|
||||
}
|
||||
|
||||
CRecordVector< ISequentialInStream * > seqInStreamsSpec;
|
||||
CRecordVector< ISequentialOutStream * > seqOutStreamsSpec;
|
||||
|
||||
for (i = 0; i < numInStreams; i++)
|
||||
seqInStreamsSpec.Add(seqInStreams[i]);
|
||||
for (i = 0; i < numOutStreams; i++)
|
||||
seqOutStreamsSpec.Add(seqOutStreams[i]);
|
||||
|
||||
for (i = 0; i < _coders.Size(); i++)
|
||||
{
|
||||
if (i == ci)
|
||||
continue;
|
||||
|
||||
CCoder &coder = _coders[i];
|
||||
|
||||
CMyComPtr<ICompressSetOutStreamSize> setOutStreamSize;
|
||||
coder.QueryInterface(IID_ICompressSetOutStreamSize, (void **)&setOutStreamSize);
|
||||
if (setOutStreamSize)
|
||||
{
|
||||
RINOK(setOutStreamSize->SetOutStreamSize(
|
||||
EncodeMode ? coder.PackSizePointers[0] : coder.UnpackSizePointer));
|
||||
}
|
||||
}
|
||||
|
||||
const UInt64 * const *isSizes2 = EncodeMode ? &mainCoder.UnpackSizePointer : &mainCoder.PackSizePointers.Front();
|
||||
const UInt64 * const *outSizes2 = EncodeMode ? &mainCoder.PackSizePointers.Front() : &mainCoder.UnpackSizePointer;
|
||||
|
||||
HRESULT res;
|
||||
if (mainCoder.Coder)
|
||||
{
|
||||
res = mainCoder.Coder->Code(
|
||||
seqInStreamsSpec[0], seqOutStreamsSpec[0],
|
||||
isSizes2[0], outSizes2[0],
|
||||
progress);
|
||||
}
|
||||
else
|
||||
{
|
||||
res = mainCoder.Coder2->Code(
|
||||
&seqInStreamsSpec.Front(), isSizes2, numInStreams,
|
||||
&seqOutStreamsSpec.Front(), outSizes2, numOutStreams,
|
||||
progress);
|
||||
}
|
||||
|
||||
if (res == k_My_HRESULT_WritingWasCut)
|
||||
res = S_OK;
|
||||
|
||||
if (res == S_OK || res == S_FALSE)
|
||||
{
|
||||
res = GetError(res, FlushCoder(ci));
|
||||
}
|
||||
|
||||
for (i = 0; i < _binderStreams.Size(); i++)
|
||||
{
|
||||
const CStBinderStream &bs = _binderStreams[i];
|
||||
if (bs.InStreamSpec)
|
||||
bs.InStreamSpec->ReleaseStream();
|
||||
else
|
||||
bs.OutStreamSpec->ReleaseStream();
|
||||
}
|
||||
|
||||
if (res == k_My_HRESULT_WritingWasCut)
|
||||
res = S_OK;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
HRESULT CMixerST::GetMainUnpackStream(
|
||||
ISequentialInStream * const *inStreams,
|
||||
ISequentialInStream **inStreamRes)
|
||||
{
|
||||
CMyComPtr<ISequentialInStream> seqInStream;
|
||||
|
||||
RINOK(GetInStream2(inStreams, /* inSizes, */
|
||||
_bi.UnpackCoder, &seqInStream))
|
||||
|
||||
FOR_VECTOR (i, _coders)
|
||||
{
|
||||
CCoder &coder = _coders[i];
|
||||
CMyComPtr<ICompressSetOutStreamSize> setOutStreamSize;
|
||||
coder.QueryInterface(IID_ICompressSetOutStreamSize, (void **)&setOutStreamSize);
|
||||
if (setOutStreamSize)
|
||||
{
|
||||
RINOK(setOutStreamSize->SetOutStreamSize(coder.UnpackSizePointer));
|
||||
}
|
||||
}
|
||||
|
||||
*inStreamRes = seqInStream.Detach();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
UInt64 CMixerST::GetBondStreamSize(unsigned bondIndex) const
|
||||
{
|
||||
const CStBinderStream &bs = _binderStreams[bondIndex];
|
||||
if (bs.InStreamSpec)
|
||||
return bs.InStreamSpec->GetSize();
|
||||
return bs.OutStreamSpec->GetSize();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
// CoderMixer2ST.h
|
||||
|
||||
#ifndef __CODER_MIXER2_ST_H
|
||||
#define __CODER_MIXER2_ST_H
|
||||
|
||||
#include "../../../Common/MyCom.h"
|
||||
|
||||
#include "../../ICoder.h"
|
||||
|
||||
#include "CoderMixer2.h"
|
||||
|
||||
class CSequentialInStreamCalcSize:
|
||||
public ISequentialInStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
public:
|
||||
MY_UNKNOWN_IMP1(ISequentialInStream)
|
||||
|
||||
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
|
||||
private:
|
||||
CMyComPtr<ISequentialInStream> _stream;
|
||||
UInt64 _size;
|
||||
bool _wasFinished;
|
||||
public:
|
||||
void SetStream(ISequentialInStream *stream) { _stream = stream; }
|
||||
void Init()
|
||||
{
|
||||
_size = 0;
|
||||
_wasFinished = false;
|
||||
}
|
||||
void ReleaseStream() { _stream.Release(); }
|
||||
UInt64 GetSize() const { return _size; }
|
||||
bool WasFinished() const { return _wasFinished; }
|
||||
};
|
||||
|
||||
|
||||
class COutStreamCalcSize:
|
||||
public ISequentialOutStream,
|
||||
public IOutStreamFlush,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
CMyComPtr<ISequentialOutStream> _stream;
|
||||
UInt64 _size;
|
||||
public:
|
||||
MY_UNKNOWN_IMP2(ISequentialOutStream, IOutStreamFlush)
|
||||
|
||||
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
|
||||
STDMETHOD(Flush)();
|
||||
|
||||
void SetStream(ISequentialOutStream *stream) { _stream = stream; }
|
||||
void ReleaseStream() { _stream.Release(); }
|
||||
void Init() { _size = 0; }
|
||||
UInt64 GetSize() const { return _size; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
namespace NCoderMixer2 {
|
||||
|
||||
struct CCoderST: public CCoder
|
||||
{
|
||||
bool CanRead;
|
||||
bool CanWrite;
|
||||
|
||||
CCoderST(): CanRead(false), CanWrite(false) {}
|
||||
};
|
||||
|
||||
|
||||
struct CStBinderStream
|
||||
{
|
||||
CSequentialInStreamCalcSize *InStreamSpec;
|
||||
COutStreamCalcSize *OutStreamSpec;
|
||||
CMyComPtr<IUnknown> StreamRef;
|
||||
|
||||
CStBinderStream(): InStreamSpec(NULL), OutStreamSpec(NULL) {}
|
||||
};
|
||||
|
||||
|
||||
class CMixerST:
|
||||
public IUnknown,
|
||||
public CMixer,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
HRESULT GetInStream2(ISequentialInStream * const *inStreams, /* const UInt64 * const *inSizes, */
|
||||
UInt32 outStreamIndex, ISequentialInStream **inStreamRes);
|
||||
HRESULT GetInStream(ISequentialInStream * const *inStreams, /* const UInt64 * const *inSizes, */
|
||||
UInt32 inStreamIndex, ISequentialInStream **inStreamRes);
|
||||
HRESULT GetOutStream(ISequentialOutStream * const *outStreams, /* const UInt64 * const *outSizes, */
|
||||
UInt32 outStreamIndex, ISequentialOutStream **outStreamRes);
|
||||
|
||||
HRESULT FlushStream(UInt32 streamIndex);
|
||||
HRESULT FlushCoder(UInt32 coderIndex);
|
||||
|
||||
public:
|
||||
CObjectVector<CCoderST> _coders;
|
||||
|
||||
CObjectVector<CStBinderStream> _binderStreams;
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
CMixerST(bool encodeMode);
|
||||
~CMixerST();
|
||||
|
||||
virtual void AddCoder(ICompressCoder *coder, ICompressCoder2 *coder2, bool isFilter);
|
||||
|
||||
virtual CCoder &GetCoder(unsigned index);
|
||||
|
||||
virtual void SelectMainCoder(bool useFirst);
|
||||
|
||||
virtual void ReInit();
|
||||
|
||||
virtual void SetCoderInfo(unsigned coderIndex, const UInt64 *unpackSize, const UInt64 * const *packSizes)
|
||||
{ _coders[coderIndex].SetCoderInfo(unpackSize, packSizes); }
|
||||
|
||||
virtual HRESULT Code(
|
||||
ISequentialInStream * const *inStreams,
|
||||
ISequentialOutStream * const *outStreams,
|
||||
ICompressProgressInfo *progress);
|
||||
|
||||
virtual UInt64 GetBondStreamSize(unsigned bondIndex) const;
|
||||
|
||||
HRESULT GetMainUnpackStream(
|
||||
ISequentialInStream * const *inStreams,
|
||||
ISequentialInStream **inStreamRes);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,99 +0,0 @@
|
||||
// CoderMixerMT.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "CoderMixerMT.h"
|
||||
|
||||
namespace NCoderMixer {
|
||||
|
||||
void CCoder::Execute() { Code(NULL); }
|
||||
|
||||
void CCoder::Code(ICompressProgressInfo *progress)
|
||||
{
|
||||
Result = Coder->Code(InStream, OutStream,
|
||||
InSizeAssigned ? &InSizeValue : NULL,
|
||||
OutSizeAssigned ? &OutSizeValue : NULL,
|
||||
progress);
|
||||
InStream.Release();
|
||||
OutStream.Release();
|
||||
}
|
||||
|
||||
void CCoderMixerMT::AddCoder(ICompressCoder *coder)
|
||||
{
|
||||
_coders.Add(CCoder());
|
||||
_coders.Back().Coder = coder;
|
||||
}
|
||||
|
||||
void CCoderMixerMT::ReInit()
|
||||
{
|
||||
for(int i = 0; i < _coders.Size(); i++)
|
||||
_coders[i].ReInit();
|
||||
}
|
||||
|
||||
HRESULT CCoderMixerMT::ReturnIfError(HRESULT code)
|
||||
{
|
||||
for (int i = 0; i < _coders.Size(); i++)
|
||||
if (_coders[i].Result == code)
|
||||
return code;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CCoderMixerMT::Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream,
|
||||
const UInt64 * /* inSize */, const UInt64 * /* outSize */,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
_coders.Front().InStream = inStream;
|
||||
int i;
|
||||
_coders.Back().OutStream = outStream;
|
||||
|
||||
for (i = 0; i < _coders.Size(); i++)
|
||||
if (i != _progressCoderIndex)
|
||||
{
|
||||
RINOK(_coders[i].Create());
|
||||
}
|
||||
|
||||
_streamBinders.Clear();
|
||||
for (i = 0; i + 1 < _coders.Size(); i++)
|
||||
{
|
||||
_streamBinders.Add(CStreamBinder());
|
||||
CStreamBinder &sb = _streamBinders[i];
|
||||
RINOK(sb.CreateEvents());
|
||||
sb.CreateStreams(&_coders[i + 1].InStream, &_coders[i].OutStream);
|
||||
}
|
||||
|
||||
for(i = 0; i < _streamBinders.Size(); i++)
|
||||
_streamBinders[i].ReInit();
|
||||
|
||||
for (i = 0; i < _coders.Size(); i++)
|
||||
if (i != _progressCoderIndex)
|
||||
_coders[i].Start();
|
||||
|
||||
_coders[_progressCoderIndex].Code(progress);
|
||||
|
||||
for (i = 0; i < _coders.Size(); i++)
|
||||
if (i != _progressCoderIndex)
|
||||
_coders[i].WaitExecuteFinish();
|
||||
|
||||
RINOK(ReturnIfError(E_ABORT));
|
||||
RINOK(ReturnIfError(E_OUTOFMEMORY));
|
||||
|
||||
for (i = 0; i < _coders.Size(); i++)
|
||||
{
|
||||
HRESULT result = _coders[i].Result;
|
||||
if (result != S_OK && result != E_FAIL && result != S_FALSE)
|
||||
return result;
|
||||
}
|
||||
|
||||
RINOK(ReturnIfError(S_FALSE));
|
||||
|
||||
for (i = 0; i < _coders.Size(); i++)
|
||||
{
|
||||
HRESULT result = _coders[i].Result;
|
||||
if (result != S_OK)
|
||||
return result;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
// CoderMixerMT.h
|
||||
|
||||
#ifndef __CODER_MIXER_MT_H
|
||||
#define __CODER_MIXER_MT_H
|
||||
|
||||
#include "../../../Common/MyVector.h"
|
||||
#include "../../../Common/MyCom.h"
|
||||
#include "../../ICoder.h"
|
||||
#include "../../Common/StreamBinder.h"
|
||||
#include "../../Common/VirtThread.h"
|
||||
#include "CoderMixer.h"
|
||||
|
||||
namespace NCoderMixer {
|
||||
|
||||
struct CCoder: public CCoderInfo, public CVirtThread
|
||||
{
|
||||
HRESULT Result;
|
||||
|
||||
virtual void Execute();
|
||||
void Code(ICompressProgressInfo *progress);
|
||||
virtual ~CCoder() { CVirtThread::WaitThreadFinish(); }
|
||||
};
|
||||
|
||||
/*
|
||||
for each coder
|
||||
AddCoder()
|
||||
SetProgressIndex(UInt32 coderIndex);
|
||||
|
||||
for each file
|
||||
{
|
||||
ReInit()
|
||||
for each coder
|
||||
SetCoderInfo
|
||||
Code
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
class CCoderMixerMT:
|
||||
public ICompressCoder,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
CObjectVector<CStreamBinder> _streamBinders;
|
||||
int _progressCoderIndex;
|
||||
|
||||
HRESULT ReturnIfError(HRESULT code);
|
||||
public:
|
||||
CObjectVector<CCoder> _coders;
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(Code)(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream,
|
||||
const UInt64 *inSize, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
|
||||
void AddCoder(ICompressCoder *coder);
|
||||
void SetProgressCoderIndex(int coderIndex) { _progressCoderIndex = coderIndex; }
|
||||
|
||||
void ReInit();
|
||||
void SetCoderInfo(UInt32 coderIndex, const UInt64 *inSize, const UInt64 *outSize)
|
||||
{ _coders[coderIndex].SetCoderInfo(inSize, outSize); }
|
||||
|
||||
/*
|
||||
UInt64 GetWriteProcessedSize(UInt32 binderIndex) const
|
||||
{ return _streamBinders[binderIndex].ProcessedSize; }
|
||||
*/
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -1,15 +0,0 @@
|
||||
// CrossThreadProgress.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "CrossThreadProgress.h"
|
||||
|
||||
STDMETHODIMP CCrossThreadProgress::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)
|
||||
{
|
||||
InSize = inSize;
|
||||
OutSize = outSize;
|
||||
ProgressEvent.Set();
|
||||
WaitEvent.Lock();
|
||||
return Result;
|
||||
}
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
// CrossThreadProgress.h
|
||||
|
||||
#ifndef __CROSSTHREADPROGRESS_H
|
||||
#define __CROSSTHREADPROGRESS_H
|
||||
|
||||
#include "../../ICoder.h"
|
||||
#include "../../../Windows/Synchronization.h"
|
||||
#include "../../../Common/MyCom.h"
|
||||
|
||||
class CCrossThreadProgress:
|
||||
public ICompressProgressInfo,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
public:
|
||||
const UInt64 *InSize;
|
||||
const UInt64 *OutSize;
|
||||
HRESULT Result;
|
||||
NWindows::NSynchronization::CAutoResetEvent ProgressEvent;
|
||||
NWindows::NSynchronization::CAutoResetEvent WaitEvent;
|
||||
|
||||
HRes Create()
|
||||
{
|
||||
RINOK(ProgressEvent.CreateIfNotCreated());
|
||||
return WaitEvent.CreateIfNotCreated();
|
||||
}
|
||||
void Init()
|
||||
{
|
||||
ProgressEvent.Reset();
|
||||
WaitEvent.Reset();
|
||||
}
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "../../../Common/MyBuffer.h"
|
||||
|
||||
#include "../../Common/StreamUtils.h"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// FindSignature.h
|
||||
|
||||
#ifndef __FINDSIGNATURE_H
|
||||
#define __FINDSIGNATURE_H
|
||||
#ifndef __FIND_SIGNATURE_H
|
||||
#define __FIND_SIGNATURE_H
|
||||
|
||||
#include "../../IStream.h"
|
||||
|
||||
|
||||
@@ -147,7 +147,9 @@ HRESULT CSingleMethodProps::SetProperties(const wchar_t * const *names, const PR
|
||||
#endif
|
||||
}
|
||||
else
|
||||
return ParseMethodFromPROPVARIANT(names[i], value);
|
||||
{
|
||||
RINOK(ParseMethodFromPROPVARIANT(names[i], value));
|
||||
}
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@@ -119,9 +119,9 @@ HRESULT COutVolumeStream::Flush()
|
||||
/*
|
||||
STDMETHODIMP COutMultiStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
if(processedSize != NULL)
|
||||
if (processedSize)
|
||||
*processedSize = 0;
|
||||
while(size > 0)
|
||||
while (size > 0)
|
||||
{
|
||||
if (_streamIndex >= Streams.Size())
|
||||
{
|
||||
@@ -157,7 +157,7 @@ STDMETHODIMP COutMultiStream::Write(const void *data, UInt32 size, UInt32 *proce
|
||||
_absPos += realProcessed;
|
||||
if (_absPos > _length)
|
||||
_length = _absPos;
|
||||
if(processedSize != NULL)
|
||||
if (processedSize)
|
||||
*processedSize += realProcessed;
|
||||
if (subStream.Pos == subStream.Size)
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "../../../C/CpuArch.h"
|
||||
|
||||
#include "../../Common/ComTry.h"
|
||||
#include "../../Common/MyLinux.h"
|
||||
#include "../../Common/StringConvert.h"
|
||||
#include "../../Common/StringToInt.h"
|
||||
#include "../../Common/UTFConvert.h"
|
||||
@@ -121,7 +122,7 @@ struct CItem
|
||||
|
||||
bool IsBin() const { return Type == k_Type_BinLe || Type == k_Type_BinBe; }
|
||||
bool IsCrcFormat() const { return Type == k_Type_HexCrc; }
|
||||
bool IsDir() const { return (Mode & 0170000) == 0040000; }
|
||||
bool IsDir() const { return MY_LIN_S_ISDIR(Mode); }
|
||||
bool IsTrailer() const { return strcmp(Name, kName_TRAILER) == 0; }
|
||||
UInt64 GetDataPosition() const { return HeaderPos + HeaderSize; }
|
||||
};
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "../../../C/LzmaDec.h"
|
||||
|
||||
#include "../../Common/ComTry.h"
|
||||
#include "../../Common/MyLinux.h"
|
||||
#include "../../Common/StringConvert.h"
|
||||
|
||||
#include "../../Windows/PropVariantUtils.h"
|
||||
@@ -98,7 +99,7 @@ struct CNode
|
||||
#define Get32(p) (be ? GetBe32(p) : GetUi32(p))
|
||||
|
||||
static UInt32 GetMode(const Byte *p, bool be) { return be ? GetBe16(p) : GetUi16(p); }
|
||||
static bool IsDir(const Byte *p, bool be) { return (GetMode(p, be) & 0xF000) == 0x4000; }
|
||||
static bool IsDir(const Byte *p, bool be) { return MY_LIN_S_ISDIR(GetMode(p, be)); }
|
||||
|
||||
static UInt32 GetSize(const Byte *p, bool be)
|
||||
{
|
||||
@@ -146,7 +147,7 @@ struct CHeader
|
||||
{
|
||||
if (memcmp(p + 16, kSignature, ARRAY_SIZE(kSignature)) != 0)
|
||||
return false;
|
||||
switch(GetUi32(p))
|
||||
switch (GetUi32(p))
|
||||
{
|
||||
case 0x28CD3D45: be = false; break;
|
||||
case 0x453DCD28: be = true; break;
|
||||
@@ -354,7 +355,7 @@ HRESULT CHandler::Open2(IInStream *inStream)
|
||||
|
||||
if (!_h.IsVer2())
|
||||
{
|
||||
FOR_VECTOR(i, _items)
|
||||
FOR_VECTOR (i, _items)
|
||||
{
|
||||
const CItem &item = _items[i];
|
||||
const Byte *p = _data + item.Offset;
|
||||
@@ -530,7 +531,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
const Byte *p = _data + item.Offset;
|
||||
bool be = _h.be;
|
||||
bool isDir = IsDir(p, be);
|
||||
switch(propID)
|
||||
switch (propID)
|
||||
{
|
||||
case kpidPath: prop = MultiByteToUnicodeString(GetPath(index), CP_OEMCP); break;
|
||||
case kpidIsDir: prop = isDir; break;
|
||||
@@ -660,10 +661,6 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
CMyComPtr<ICompressProgressInfo> progress = lps;
|
||||
lps->Init(extractCallback, false);
|
||||
|
||||
CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
|
||||
CMyComPtr<ISequentialInStream> inStream(streamSpec);
|
||||
streamSpec->SetStream(_stream);
|
||||
|
||||
for (i = 0; i < numItems; i++)
|
||||
{
|
||||
lps->InSize = totalPackSize;
|
||||
@@ -701,20 +698,16 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
int res = NExtract::NOperationResult::kDataError;
|
||||
{
|
||||
CMyComPtr<ISequentialInStream> inSeqStream;
|
||||
CMyComPtr<IInStream> inStream;
|
||||
HRESULT hres = GetStream(index, &inSeqStream);
|
||||
if (inSeqStream)
|
||||
inSeqStream.QueryInterface(IID_IInStream, &inStream);
|
||||
if (hres == E_OUTOFMEMORY)
|
||||
return E_OUTOFMEMORY;
|
||||
if (hres == S_FALSE || !inStream)
|
||||
if (hres == S_FALSE || !inSeqStream)
|
||||
res = NExtract::NOperationResult::kUnsupportedMethod;
|
||||
else
|
||||
{
|
||||
RINOK(hres);
|
||||
if (inStream)
|
||||
{
|
||||
HRESULT hres = copyCoder->Code(inStream, outStream, NULL, NULL, progress);
|
||||
HRESULT hres = copyCoder->Code(inSeqStream, outStream, NULL, NULL, progress);
|
||||
if (hres == S_OK)
|
||||
{
|
||||
if (copyCoderSpec->TotalSize == curSize)
|
||||
@@ -729,6 +722,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
}
|
||||
RINOK(extractCallback->SetOperationResult(res));
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "../../Common/MyWindows.h"
|
||||
|
||||
#include "../../Common/MyInitGuid.h"
|
||||
|
||||
#if defined(_7ZIP_LARGE_PAGES)
|
||||
@@ -24,6 +26,7 @@ HINSTANCE g_hInstance;
|
||||
|
||||
#define NT_CHECK_FAIL_ACTION return FALSE;
|
||||
|
||||
#ifdef _WIN32
|
||||
extern "C"
|
||||
BOOL WINAPI DllMain(
|
||||
#ifdef UNDER_CE
|
||||
@@ -47,6 +50,7 @@ BOOL WINAPI DllMain(
|
||||
*/
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
DEFINE_GUID(CLSID_CArchiveHandler,
|
||||
k_7zip_GUID_Data1,
|
||||
|
||||
@@ -545,8 +545,8 @@ HRESULT CHandler::Open2(IInStream *stream)
|
||||
CChecksum masterChecksum;
|
||||
masterChecksum.Parse(buf + 0x160);
|
||||
|
||||
// UInt32 imageVariant = Get32(buf + 0x1E8);
|
||||
// UInt64 numSectors = Get64(buf + 0x1EC);
|
||||
// UInt32 imageVariant = Get32(buf + 0x1E8);
|
||||
// UInt64 numSectors = Get64(buf + 0x1EC);
|
||||
// Byte reserved[0x12]
|
||||
|
||||
const UInt32 RSRC_HEAD_SIZE = 0x100;
|
||||
|
||||
@@ -226,25 +226,25 @@ void CSegment::Parse(const Byte *p, bool mode64, bool be)
|
||||
|
||||
// Section types
|
||||
|
||||
#define SHT_NULL 0
|
||||
#define SHT_PROGBITS 1
|
||||
#define SHT_SYMTAB 2
|
||||
#define SHT_STRTAB 3
|
||||
#define SHT_RELA 4
|
||||
#define SHT_HASH 5
|
||||
#define SHT_DYNAMIC 6
|
||||
#define SHT_NOTE 7
|
||||
#define SHT_NOBITS 8
|
||||
#define SHT_REL 9
|
||||
#define SHT_SHLIB 10
|
||||
#define SHT_DYNSYM 11
|
||||
#define SHT_UNKNOWN12 12
|
||||
#define SHT_UNKNOWN13 13
|
||||
#define SHT_INIT_ARRAY 14
|
||||
#define SHT_FINI_ARRAY 15
|
||||
#define SHT_PREINIT_ARRAY 16
|
||||
#define SHT_GROUP 17
|
||||
#define SHT_SYMTAB_SHNDX 18
|
||||
#define SHT_NULL 0
|
||||
#define SHT_PROGBITS 1
|
||||
#define SHT_SYMTAB 2
|
||||
#define SHT_STRTAB 3
|
||||
#define SHT_RELA 4
|
||||
#define SHT_HASH 5
|
||||
#define SHT_DYNAMIC 6
|
||||
#define SHT_NOTE 7
|
||||
#define SHT_NOBITS 8
|
||||
#define SHT_REL 9
|
||||
#define SHT_SHLIB 10
|
||||
#define SHT_DYNSYM 11
|
||||
#define SHT_UNKNOWN12 12
|
||||
#define SHT_UNKNOWN13 13
|
||||
#define SHT_INIT_ARRAY 14
|
||||
#define SHT_FINI_ARRAY 15
|
||||
#define SHT_PREINIT_ARRAY 16
|
||||
#define SHT_GROUP 17
|
||||
#define SHT_SYMTAB_SHNDX 18
|
||||
|
||||
|
||||
static const CUInt32PCharPair g_SectTypes[] =
|
||||
@@ -554,11 +554,11 @@ static const CUInt32PCharPair g_OS[] =
|
||||
{ 255, "Standalone" }
|
||||
};
|
||||
|
||||
#define ET_NONE 0
|
||||
#define ET_REL 1
|
||||
#define ET_EXEC 2
|
||||
#define ET_DYN 3
|
||||
#define ET_CORE 4
|
||||
#define ET_NONE 0
|
||||
#define ET_REL 1
|
||||
#define ET_EXEC 2
|
||||
#define ET_DYN 3
|
||||
#define ET_CORE 4
|
||||
|
||||
static const char *g_Types[] =
|
||||
{
|
||||
@@ -632,7 +632,7 @@ enum
|
||||
kpidInfoSection
|
||||
};
|
||||
|
||||
static const STATPROPSTG kProps[] =
|
||||
static const CStatProp kProps[] =
|
||||
{
|
||||
{ NULL, kpidPath, VT_BSTR },
|
||||
{ NULL, kpidSize, VT_UI8 },
|
||||
@@ -641,8 +641,8 @@ static const STATPROPSTG kProps[] =
|
||||
{ NULL, kpidVa, VT_UI8 },
|
||||
{ NULL, kpidType, VT_BSTR },
|
||||
{ NULL, kpidCharacts, VT_BSTR }
|
||||
, { (LPOLESTR)L"Link Section", kpidLinkSection, VT_BSTR}
|
||||
, { (LPOLESTR)L"Info Section", kpidInfoSection, VT_BSTR}
|
||||
, { "Link Section", kpidLinkSection, VT_BSTR}
|
||||
, { "Info Section", kpidInfoSection, VT_BSTR}
|
||||
};
|
||||
|
||||
IMP_IInArchive_Props_WITH_NAME
|
||||
|
||||
2856
CPP/7zip/Archive/ExtHandler.cpp
Normal file
2856
CPP/7zip/Archive/ExtHandler.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -133,15 +133,23 @@ bool CHeader::Parse(const Byte *p)
|
||||
default: return false;
|
||||
}
|
||||
{
|
||||
int s = GetLog(Get16(p + 11));
|
||||
if (s < 9 || s > 12)
|
||||
return false;
|
||||
SectorSizeLog = (Byte)s;
|
||||
s = GetLog(p[13]);
|
||||
if (s < 0)
|
||||
return false;
|
||||
SectorsPerClusterLog = (Byte)s;
|
||||
{
|
||||
UInt32 val32 = Get16(p + 11);
|
||||
int s = GetLog(val32);
|
||||
if (s < 9 || s > 12)
|
||||
return false;
|
||||
SectorSizeLog = (Byte)s;
|
||||
}
|
||||
{
|
||||
UInt32 val32 = p[13];
|
||||
int s = GetLog(val32);
|
||||
if (s < 0)
|
||||
return false;
|
||||
SectorsPerClusterLog = (Byte)s;
|
||||
}
|
||||
ClusterSizeLog = (Byte)(SectorSizeLog + SectorsPerClusterLog);
|
||||
if (ClusterSizeLog > 24)
|
||||
return false;
|
||||
}
|
||||
|
||||
NumReservedSectors = Get16(p + 14);
|
||||
@@ -805,7 +813,7 @@ enum
|
||||
// kpidFileSysType
|
||||
};
|
||||
|
||||
static const STATPROPSTG kArcProps[] =
|
||||
static const CStatProp kArcProps[] =
|
||||
{
|
||||
{ NULL, kpidFileSystem, VT_BSTR},
|
||||
{ NULL, kpidClusterSize, VT_UI4},
|
||||
@@ -814,12 +822,12 @@ static const STATPROPSTG kArcProps[] =
|
||||
{ NULL, kpidMTime, VT_FILETIME},
|
||||
{ NULL, kpidVolumeName, VT_BSTR},
|
||||
|
||||
{ (LPOLESTR)L"FATs", kpidNumFats, VT_UI4},
|
||||
{ "FATs", kpidNumFats, VT_UI4},
|
||||
{ NULL, kpidSectorSize, VT_UI4},
|
||||
{ NULL, kpidId, VT_UI4},
|
||||
// { (LPOLESTR)L"OEM Name", kpidOemName, VT_BSTR},
|
||||
// { (LPOLESTR)L"Volume Name", kpidVolName, VT_BSTR},
|
||||
// { (LPOLESTR)L"File System Type", kpidFileSysType, VT_BSTR}
|
||||
// { "OEM Name", kpidOemName, VT_BSTR},
|
||||
// { "Volume Name", kpidVolName, VT_BSTR},
|
||||
// { "File System Type", kpidFileSysType, VT_BSTR}
|
||||
// { NULL, kpidSectorsPerTrack, VT_UI4},
|
||||
// { NULL, kpidNumHeads, VT_UI4},
|
||||
// { NULL, kpidHiddenSectors, VT_UI4}
|
||||
@@ -858,7 +866,7 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
NWindows::NCOM::CPropVariant prop;
|
||||
switch(propID)
|
||||
switch (propID)
|
||||
{
|
||||
case kpidFileSystem:
|
||||
{
|
||||
@@ -897,7 +905,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
COM_TRY_BEGIN
|
||||
NWindows::NCOM::CPropVariant prop;
|
||||
const CItem &item = Items[index];
|
||||
switch(propID)
|
||||
switch (propID)
|
||||
{
|
||||
case kpidPath: prop = GetItemPath(index); break;
|
||||
case kpidShortName: prop = item.GetShortName(); break;
|
||||
|
||||
@@ -145,7 +145,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
{
|
||||
NWindows::NCOM::CPropVariant prop;
|
||||
const CItem2 &item = _items2[index];
|
||||
switch(propID)
|
||||
switch (propID)
|
||||
{
|
||||
case kpidExtension:
|
||||
prop = _isRaw ?
|
||||
@@ -209,7 +209,7 @@ AString CHandler::GetComment()
|
||||
Byte type = *p++;
|
||||
size--;
|
||||
bool ok = false;
|
||||
switch(type)
|
||||
switch (type)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
@@ -256,7 +256,7 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
|
||||
{
|
||||
// COM_TRY_BEGIN
|
||||
NWindows::NCOM::CPropVariant prop;
|
||||
switch(propID)
|
||||
switch (propID)
|
||||
{
|
||||
// case kpidComment: prop = GetComment(); break;
|
||||
case kpidPhySize: prop = (UInt64)_phySize; break;
|
||||
|
||||
393
CPP/7zip/Archive/GptHandler.cpp
Normal file
393
CPP/7zip/Archive/GptHandler.cpp
Normal file
@@ -0,0 +1,393 @@
|
||||
// GptHandler.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "../../../C/7zCrc.h"
|
||||
#include "../../../C/CpuArch.h"
|
||||
|
||||
#include "../../Common/ComTry.h"
|
||||
#include "../../Common/IntToString.h"
|
||||
#include "../../Common/MyBuffer.h"
|
||||
|
||||
#include "../../Windows/PropVariantUtils.h"
|
||||
|
||||
#include "../Common/RegisterArc.h"
|
||||
#include "../Common/StreamUtils.h"
|
||||
|
||||
#include "HandlerCont.h"
|
||||
|
||||
#define Get16(p) GetUi16(p)
|
||||
#define Get32(p) GetUi32(p)
|
||||
#define Get64(p) GetUi64(p)
|
||||
|
||||
using namespace NWindows;
|
||||
|
||||
namespace NArchive {
|
||||
namespace NGpt {
|
||||
|
||||
#define SIGNATURE { 'E', 'F', 'I', ' ', 'P', 'A', 'R', 'T', 0, 0, 1, 0 }
|
||||
|
||||
static const unsigned k_SignatureSize = 12;
|
||||
static const Byte k_Signature[k_SignatureSize] = SIGNATURE;
|
||||
|
||||
static const UInt32 kSectorSize = 512;
|
||||
|
||||
static const CUInt32PCharPair g_PartitionFlags[] =
|
||||
{
|
||||
{ 0, "Sys" },
|
||||
{ 1, "Ignore" },
|
||||
{ 2, "Legacy" },
|
||||
{ 60, "Win-Read-only" },
|
||||
{ 62, "Win-Hidden" },
|
||||
{ 63, "Win-Not-Automount" }
|
||||
};
|
||||
|
||||
static const unsigned kNameLen = 36;
|
||||
|
||||
struct CPartition
|
||||
{
|
||||
Byte Type[16];
|
||||
Byte Id[16];
|
||||
UInt64 FirstLba;
|
||||
UInt64 LastLba;
|
||||
UInt64 Flags;
|
||||
Byte Name[kNameLen * 2];
|
||||
|
||||
bool IsUnused() const
|
||||
{
|
||||
for (unsigned i = 0; i < 16; i++)
|
||||
if (Type[i] != 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
UInt64 GetSize() const { return (LastLba - FirstLba + 1) * kSectorSize; }
|
||||
UInt64 GetPos() const { return FirstLba * kSectorSize; }
|
||||
UInt64 GetEnd() const { return (LastLba + 1) * kSectorSize; }
|
||||
|
||||
void Parse(const Byte *p)
|
||||
{
|
||||
memcpy(Type, p, 16);
|
||||
memcpy(Id, p + 16, 16);
|
||||
FirstLba = Get64(p + 32);
|
||||
LastLba = Get64(p + 40);
|
||||
Flags = Get64(p + 48);
|
||||
memcpy(Name, p + 56, kNameLen * 2);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct CPartType
|
||||
{
|
||||
UInt32 Id;
|
||||
const char *Ext;
|
||||
const char *Type;
|
||||
};
|
||||
|
||||
static const CPartType kPartTypes[] =
|
||||
{
|
||||
// { 0x0, 0, "Unused" },
|
||||
{ 0xC12A7328, 0, "EFI System" },
|
||||
{ 0x024DEE41, 0, "MBR" },
|
||||
|
||||
{ 0xE3C9E316, 0, "Windows MSR" },
|
||||
{ 0xEBD0A0A2, 0, "Windows BDP" },
|
||||
{ 0x5808C8AA, 0, "Windows LDM Metadata" },
|
||||
{ 0xAF9B60A0, 0, "Windows LDM Data" },
|
||||
{ 0xDE94BBA4, 0, "Windows Recovery" },
|
||||
// { 0x37AFFC90, 0, "IBM GPFS" },
|
||||
// { 0xE75CAF8F, 0, "Windows Storage Spaces" },
|
||||
|
||||
{ 0x83BD6B9D, 0, "FreeBSD Boot" },
|
||||
{ 0x516E7CB4, 0, "FreeBSD Data" },
|
||||
{ 0x516E7CB5, 0, "FreeBSD Swap" },
|
||||
{ 0x516E7CB6, "ufs", "FreeBSD UFS" },
|
||||
{ 0x516E7CB8, 0, "FreeBSD Vinum" },
|
||||
{ 0x516E7CB8, "zfs", "FreeBSD ZFS" },
|
||||
|
||||
{ 0x48465300, "hfsx", "HFS+" },
|
||||
};
|
||||
|
||||
static int FindPartType(const Byte *guid)
|
||||
{
|
||||
UInt32 val = Get32(guid);
|
||||
for (unsigned i = 0; i < ARRAY_SIZE(kPartTypes); i++)
|
||||
if (kPartTypes[i].Id == val)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static inline char GetHex(unsigned t) { return (char)(((t < 10) ? ('0' + t) : ('A' + (t - 10)))); }
|
||||
|
||||
static void PrintHex(unsigned v, char *s)
|
||||
{
|
||||
s[0] = GetHex((v >> 4) & 0xF);
|
||||
s[1] = GetHex(v & 0xF);
|
||||
}
|
||||
|
||||
static void ConvertUInt16ToHex4Digits(UInt32 val, char *s) throw()
|
||||
{
|
||||
PrintHex(val >> 8, s);
|
||||
PrintHex(val & 0xFF, s + 2);
|
||||
}
|
||||
|
||||
static void GuidToString(const Byte *g, char *s)
|
||||
{
|
||||
ConvertUInt32ToHex8Digits(Get32(g ), s); s += 8; *s++ = '-';
|
||||
ConvertUInt16ToHex4Digits(Get16(g + 4), s); s += 4; *s++ = '-';
|
||||
ConvertUInt16ToHex4Digits(Get16(g + 6), s); s += 4; *s++ = '-';
|
||||
for (unsigned i = 0; i < 8; i++)
|
||||
{
|
||||
if (i == 2)
|
||||
*s++ = '-';
|
||||
PrintHex(g[8 + i], s);
|
||||
s += 2;
|
||||
}
|
||||
*s = 0;
|
||||
}
|
||||
|
||||
|
||||
class CHandler: public CHandlerCont
|
||||
{
|
||||
CRecordVector<CPartition> _items;
|
||||
UInt64 _totalSize;
|
||||
Byte Guid[16];
|
||||
|
||||
CByteBuffer _buffer;
|
||||
|
||||
HRESULT Open2(IInStream *stream);
|
||||
|
||||
virtual int GetItem_ExtractInfo(UInt32 index, UInt64 &pos, UInt64 &size) const
|
||||
{
|
||||
const CPartition &item = _items[index];
|
||||
pos = item.GetPos();
|
||||
size = item.GetSize();
|
||||
return NExtract::NOperationResult::kOK;
|
||||
}
|
||||
|
||||
public:
|
||||
INTERFACE_IInArchive_Cont(;)
|
||||
};
|
||||
|
||||
|
||||
HRESULT CHandler::Open2(IInStream *stream)
|
||||
{
|
||||
_buffer.Alloc(kSectorSize * 2);
|
||||
RINOK(ReadStream_FALSE(stream, _buffer, kSectorSize * 2));
|
||||
|
||||
const Byte *buf = _buffer;
|
||||
if (buf[0x1FE] != 0x55 || buf[0x1FF] != 0xAA)
|
||||
return S_FALSE;
|
||||
|
||||
buf += kSectorSize;
|
||||
if (memcmp(buf, k_Signature, k_SignatureSize) != 0)
|
||||
return S_FALSE;
|
||||
{
|
||||
// if (Get32(buf + 8) != 0x10000) return S_FALSE; // revision
|
||||
UInt32 headerSize = Get32(buf + 12); // = 0x5C usually
|
||||
if (headerSize > kSectorSize)
|
||||
return S_FALSE;
|
||||
UInt32 crc = Get32(buf + 0x10);
|
||||
SetUi32(_buffer + kSectorSize + 0x10, 0);
|
||||
if (CrcCalc(_buffer + kSectorSize, headerSize) != crc)
|
||||
return S_FALSE;
|
||||
}
|
||||
// UInt32 reserved = Get32(buf + 0x14);
|
||||
UInt64 curLba = Get64(buf + 0x18);
|
||||
if (curLba != 1)
|
||||
return S_FALSE;
|
||||
UInt64 backupLba = Get64(buf + 0x20);
|
||||
// UInt64 firstUsableLba = Get64(buf + 0x28);
|
||||
// UInt64 lastUsableLba = Get64(buf + 0x30);
|
||||
memcpy(Guid, buf + 0x38, 16);
|
||||
UInt64 tableLba = Get64(buf + 0x48);
|
||||
if (tableLba < 2)
|
||||
return S_FALSE;
|
||||
UInt32 numEntries = Get32(buf + 0x50);
|
||||
UInt32 entrySize = Get32(buf + 0x54); // = 128 usually
|
||||
UInt32 entriesCrc = Get32(buf + 0x58);
|
||||
|
||||
if (entrySize < 128
|
||||
|| entrySize > (1 << 12)
|
||||
|| numEntries > (1 << 16)
|
||||
|| tableLba < 2
|
||||
|| tableLba >= ((UInt64)1 << (64 - 10)))
|
||||
return S_FALSE;
|
||||
|
||||
UInt32 tableSize = entrySize * numEntries;
|
||||
UInt32 tableSizeAligned = (tableSize + kSectorSize - 1) & ~(kSectorSize - 1);
|
||||
_buffer.Alloc(tableSizeAligned);
|
||||
UInt64 tableOffset = tableLba * kSectorSize;
|
||||
RINOK(stream->Seek(tableOffset, STREAM_SEEK_SET, NULL));
|
||||
RINOK(ReadStream_FALSE(stream, _buffer, tableSizeAligned));
|
||||
|
||||
if (CrcCalc(_buffer, tableSize) != entriesCrc)
|
||||
return S_FALSE;
|
||||
|
||||
_totalSize = tableOffset + tableSizeAligned;
|
||||
|
||||
for (UInt32 i = 0; i < numEntries; i++)
|
||||
{
|
||||
CPartition item;
|
||||
item.Parse(_buffer + i * entrySize);
|
||||
if (item.IsUnused())
|
||||
continue;
|
||||
UInt64 endPos = item.GetEnd();
|
||||
if (_totalSize < endPos)
|
||||
_totalSize = endPos;
|
||||
_items.Add(item);
|
||||
}
|
||||
|
||||
UInt64 end = (backupLba + 1) * kSectorSize;
|
||||
if (_totalSize < end)
|
||||
_totalSize = end;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CHandler::Open(IInStream *stream,
|
||||
const UInt64 * /* maxCheckStartPosition */,
|
||||
IArchiveOpenCallback * /* openArchiveCallback */)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
Close();
|
||||
RINOK(Open2(stream));
|
||||
_stream = stream;
|
||||
return S_OK;
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
STDMETHODIMP CHandler::Close()
|
||||
{
|
||||
_totalSize = 0;
|
||||
memset(Guid, 0, sizeof(Guid));
|
||||
_items.Clear();
|
||||
_stream.Release();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static const Byte kProps[] =
|
||||
{
|
||||
kpidPath,
|
||||
kpidSize,
|
||||
kpidFileSystem,
|
||||
kpidCharacts,
|
||||
kpidOffset,
|
||||
kpidId
|
||||
};
|
||||
|
||||
static const Byte kArcProps[] =
|
||||
{
|
||||
kpidId
|
||||
};
|
||||
|
||||
IMP_IInArchive_Props
|
||||
IMP_IInArchive_ArcProps
|
||||
|
||||
STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
NCOM::CPropVariant prop;
|
||||
switch (propID)
|
||||
{
|
||||
case kpidMainSubfile:
|
||||
{
|
||||
if (_items.Size() == 1)
|
||||
prop = (UInt32)0;
|
||||
break;
|
||||
}
|
||||
case kpidPhySize: prop = _totalSize; break;
|
||||
case kpidId:
|
||||
{
|
||||
char s[48];
|
||||
GuidToString(Guid, s);
|
||||
prop = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
prop.Detach(value);
|
||||
return S_OK;
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
|
||||
{
|
||||
*numItems = _items.Size();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
NCOM::CPropVariant prop;
|
||||
|
||||
const CPartition &item = _items[index];
|
||||
|
||||
switch (propID)
|
||||
{
|
||||
case kpidPath:
|
||||
{
|
||||
UString s;
|
||||
for (unsigned i = 0; i < kNameLen; i++)
|
||||
{
|
||||
wchar_t c = (wchar_t)Get16(item.Name + i * 2);
|
||||
if (c == 0)
|
||||
break;
|
||||
s += c;
|
||||
}
|
||||
{
|
||||
int typeIndex = FindPartType(item.Type);
|
||||
s += L'.';
|
||||
const char *ext = "img";
|
||||
if (typeIndex >= 0 && kPartTypes[(unsigned)typeIndex].Ext)
|
||||
ext = kPartTypes[(unsigned)typeIndex].Ext;
|
||||
s.AddAscii(ext);
|
||||
}
|
||||
prop = s;
|
||||
break;
|
||||
}
|
||||
|
||||
case kpidSize:
|
||||
case kpidPackSize: prop = item.GetSize(); break;
|
||||
case kpidOffset: prop = item.GetPos(); break;
|
||||
|
||||
case kpidFileSystem:
|
||||
{
|
||||
char s[48];
|
||||
const char *res;
|
||||
int typeIndex = FindPartType(item.Type);
|
||||
if (typeIndex >= 0 && kPartTypes[(unsigned)typeIndex].Type)
|
||||
res = kPartTypes[(unsigned)typeIndex].Type;
|
||||
else
|
||||
{
|
||||
GuidToString(item.Type, s);
|
||||
res = s;
|
||||
}
|
||||
prop = res;
|
||||
break;
|
||||
}
|
||||
|
||||
case kpidId:
|
||||
{
|
||||
char s[48];
|
||||
GuidToString(item.Id, s);
|
||||
prop = s;
|
||||
break;
|
||||
}
|
||||
|
||||
case kpidCharacts: FLAGS64_TO_PROP(g_PartitionFlags, item.Flags, prop); break;
|
||||
}
|
||||
|
||||
prop.Detach(value);
|
||||
return S_OK;
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
REGISTER_ARC_I(
|
||||
"GPT", "gpt mbr", NULL, 0xCB,
|
||||
k_Signature,
|
||||
kSectorSize,
|
||||
0,
|
||||
NULL)
|
||||
|
||||
}}
|
||||
288
CPP/7zip/Archive/HandlerCont.cpp
Normal file
288
CPP/7zip/Archive/HandlerCont.cpp
Normal file
@@ -0,0 +1,288 @@
|
||||
// HandlerCont.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "../../Common/ComTry.h"
|
||||
|
||||
#include "../Common/LimitedStreams.h"
|
||||
#include "../Common/ProgressUtils.h"
|
||||
#include "../Common/StreamUtils.h"
|
||||
|
||||
#include "../Compress/CopyCoder.h"
|
||||
|
||||
#include "HandlerCont.h"
|
||||
|
||||
namespace NArchive {
|
||||
|
||||
STDMETHODIMP CHandlerCont::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
Int32 testMode, IArchiveExtractCallback *extractCallback)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
bool allFilesMode = (numItems == (UInt32)(Int32)-1);
|
||||
if (allFilesMode)
|
||||
{
|
||||
RINOK(GetNumberOfItems(&numItems));
|
||||
}
|
||||
if (numItems == 0)
|
||||
return S_OK;
|
||||
UInt64 totalSize = 0;
|
||||
UInt32 i;
|
||||
for (i = 0; i < numItems; i++)
|
||||
{
|
||||
UInt64 pos, size;
|
||||
GetItem_ExtractInfo(allFilesMode ? i : indices[i], pos, size);
|
||||
totalSize += size;
|
||||
}
|
||||
extractCallback->SetTotal(totalSize);
|
||||
|
||||
totalSize = 0;
|
||||
|
||||
NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder();
|
||||
CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
|
||||
|
||||
CLocalProgress *lps = new CLocalProgress;
|
||||
CMyComPtr<ICompressProgressInfo> progress = lps;
|
||||
lps->Init(extractCallback, false);
|
||||
|
||||
CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
|
||||
CMyComPtr<ISequentialInStream> inStream(streamSpec);
|
||||
streamSpec->SetStream(_stream);
|
||||
|
||||
for (i = 0; i < numItems; i++)
|
||||
{
|
||||
lps->InSize = totalSize;
|
||||
lps->OutSize = totalSize;
|
||||
RINOK(lps->SetCur());
|
||||
CMyComPtr<ISequentialOutStream> outStream;
|
||||
Int32 askMode = testMode ?
|
||||
NExtract::NAskMode::kTest :
|
||||
NExtract::NAskMode::kExtract;
|
||||
Int32 index = allFilesMode ? i : indices[i];
|
||||
|
||||
RINOK(extractCallback->GetStream(index, &outStream, askMode));
|
||||
|
||||
UInt64 pos, size;
|
||||
int opRes = GetItem_ExtractInfo(index, pos, size);
|
||||
totalSize += size;
|
||||
if (!testMode && !outStream)
|
||||
continue;
|
||||
|
||||
RINOK(extractCallback->PrepareOperation(askMode));
|
||||
|
||||
if (opRes == NExtract::NOperationResult::kOK)
|
||||
{
|
||||
RINOK(_stream->Seek(pos, STREAM_SEEK_SET, NULL));
|
||||
streamSpec->Init(size);
|
||||
|
||||
RINOK(copyCoder->Code(inStream, outStream, NULL, NULL, progress));
|
||||
|
||||
opRes = NExtract::NOperationResult::kDataError;
|
||||
|
||||
if (copyCoderSpec->TotalSize == size)
|
||||
opRes = NExtract::NOperationResult::kOK;
|
||||
else if (copyCoderSpec->TotalSize < size)
|
||||
opRes = NExtract::NOperationResult::kUnexpectedEnd;
|
||||
}
|
||||
|
||||
outStream.Release();
|
||||
RINOK(extractCallback->SetOperationResult(opRes));
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
STDMETHODIMP CHandlerCont::GetStream(UInt32 index, ISequentialInStream **stream)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
*stream = NULL;
|
||||
UInt64 pos, size;
|
||||
if (GetItem_ExtractInfo(index, pos, size) != NExtract::NOperationResult::kOK)
|
||||
return S_FALSE;
|
||||
return CreateLimitedInStream(_stream, pos, size, stream);
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
|
||||
|
||||
CHandlerImg::CHandlerImg():
|
||||
_imgExt(NULL)
|
||||
{
|
||||
ClearStreamVars();
|
||||
}
|
||||
|
||||
STDMETHODIMP CHandlerImg::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
|
||||
{
|
||||
switch (seekOrigin)
|
||||
{
|
||||
case STREAM_SEEK_SET: break;
|
||||
case STREAM_SEEK_CUR: offset += _virtPos; break;
|
||||
case STREAM_SEEK_END: offset += _size; break;
|
||||
default: return STG_E_INVALIDFUNCTION;
|
||||
}
|
||||
if (offset < 0)
|
||||
return HRESULT_WIN32_ERROR_NEGATIVE_SEEK;
|
||||
_virtPos = offset;
|
||||
if (newPosition)
|
||||
*newPosition = offset;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static const Byte k_GDP_Signature[] = { 'E', 'F', 'I', ' ', 'P', 'A', 'R', 'T' };
|
||||
|
||||
static const char *GetImgExt(ISequentialInStream *stream)
|
||||
{
|
||||
const size_t kHeaderSize = 1 << 10;
|
||||
Byte buf[kHeaderSize];
|
||||
if (ReadStream_FAIL(stream, buf, kHeaderSize) == S_OK)
|
||||
{
|
||||
if (buf[0x1FE] == 0x55 && buf[0x1FF] == 0xAA)
|
||||
{
|
||||
if (memcmp(buf + 512, k_GDP_Signature, sizeof(k_GDP_Signature)) == 0)
|
||||
return "gpt";
|
||||
return "mbr";
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CHandlerImg::CloseAtError()
|
||||
{
|
||||
Stream.Release();
|
||||
}
|
||||
|
||||
STDMETHODIMP CHandlerImg::Open(IInStream *stream,
|
||||
const UInt64 * /* maxCheckStartPosition */,
|
||||
IArchiveOpenCallback * openCallback)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
{
|
||||
Close();
|
||||
HRESULT res;
|
||||
try
|
||||
{
|
||||
res = Open2(stream, openCallback);
|
||||
if (res == S_OK)
|
||||
{
|
||||
CMyComPtr<ISequentialInStream> inStream;
|
||||
HRESULT res2 = GetStream(0, &inStream);
|
||||
if (res2 == S_OK && inStream)
|
||||
_imgExt = GetImgExt(inStream);
|
||||
return S_OK;
|
||||
}
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
CloseAtError();
|
||||
throw;
|
||||
}
|
||||
CloseAtError();
|
||||
return res;
|
||||
}
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
STDMETHODIMP CHandlerImg::GetNumberOfItems(UInt32 *numItems)
|
||||
{
|
||||
*numItems = 1;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CHandlerImg::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
Int32 testMode, IArchiveExtractCallback *extractCallback)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
if (numItems == 0)
|
||||
return S_OK;
|
||||
if (numItems != (UInt32)(Int32)-1 && (numItems != 1 || indices[0] != 0))
|
||||
return E_INVALIDARG;
|
||||
|
||||
RINOK(extractCallback->SetTotal(_size));
|
||||
CMyComPtr<ISequentialOutStream> outStream;
|
||||
Int32 askMode = testMode ?
|
||||
NExtract::NAskMode::kTest :
|
||||
NExtract::NAskMode::kExtract;
|
||||
RINOK(extractCallback->GetStream(0, &outStream, askMode));
|
||||
if (!testMode && !outStream)
|
||||
return S_OK;
|
||||
RINOK(extractCallback->PrepareOperation(askMode));
|
||||
|
||||
CLocalProgress *lps = new CLocalProgress;
|
||||
CMyComPtr<ICompressProgressInfo> progress = lps;
|
||||
lps->Init(extractCallback, false);
|
||||
|
||||
int opRes = NExtract::NOperationResult::kDataError;
|
||||
|
||||
ClearStreamVars();
|
||||
|
||||
CMyComPtr<ISequentialInStream> inStream;
|
||||
HRESULT hres = GetStream(0, &inStream);
|
||||
if (hres == S_FALSE)
|
||||
hres = E_NOTIMPL;
|
||||
|
||||
if (hres == S_OK && inStream)
|
||||
{
|
||||
NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder();
|
||||
CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
|
||||
|
||||
hres = copyCoder->Code(inStream, outStream, NULL, &_size, progress);
|
||||
if (hres == S_OK)
|
||||
{
|
||||
if (copyCoderSpec->TotalSize == _size)
|
||||
opRes = NExtract::NOperationResult::kOK;
|
||||
|
||||
if (_stream_unavailData)
|
||||
opRes = NExtract::NOperationResult::kUnavailable;
|
||||
else if (_stream_unsupportedMethod)
|
||||
opRes = NExtract::NOperationResult::kUnsupportedMethod;
|
||||
else if (_stream_dataError)
|
||||
opRes = NExtract::NOperationResult::kDataError;
|
||||
else if (copyCoderSpec->TotalSize < _size)
|
||||
opRes = NExtract::NOperationResult::kUnexpectedEnd;
|
||||
}
|
||||
}
|
||||
|
||||
inStream.Release();
|
||||
outStream.Release();
|
||||
|
||||
if (hres != S_OK)
|
||||
{
|
||||
if (hres == S_FALSE)
|
||||
opRes = NExtract::NOperationResult::kDataError;
|
||||
else if (hres == E_NOTIMPL)
|
||||
opRes = NExtract::NOperationResult::kUnsupportedMethod;
|
||||
else
|
||||
return hres;
|
||||
}
|
||||
|
||||
return extractCallback->SetOperationResult(opRes);
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
|
||||
HRESULT ReadZeroTail(ISequentialInStream *stream, bool &areThereNonZeros, UInt64 &numZeros, UInt64 maxSize)
|
||||
{
|
||||
areThereNonZeros = false;
|
||||
numZeros = 0;
|
||||
const size_t kBufSize = 1 << 11;
|
||||
Byte buf[kBufSize];
|
||||
for (;;)
|
||||
{
|
||||
UInt32 size = 0;
|
||||
HRESULT(stream->Read(buf, kBufSize, &size));
|
||||
if (size == 0)
|
||||
return S_OK;
|
||||
for (UInt32 i = 0; i < size; i++)
|
||||
if (buf[i] != 0)
|
||||
{
|
||||
areThereNonZeros = true;
|
||||
numZeros += i;
|
||||
return S_OK;
|
||||
}
|
||||
numZeros += size;
|
||||
if (numZeros > maxSize)
|
||||
return S_OK;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
116
CPP/7zip/Archive/HandlerCont.h
Normal file
116
CPP/7zip/Archive/HandlerCont.h
Normal file
@@ -0,0 +1,116 @@
|
||||
// HandlerCont.h
|
||||
|
||||
#ifndef __HANDLER_CONT_H
|
||||
#define __HANDLER_CONT_H
|
||||
|
||||
#include "../../Common/MyCom.h"
|
||||
|
||||
#include "IArchive.h"
|
||||
|
||||
namespace NArchive {
|
||||
|
||||
#define INTERFACE_IInArchive_Cont(x) \
|
||||
STDMETHOD(Open)(IInStream *stream, const UInt64 *maxCheckStartPosition, IArchiveOpenCallback *openCallback) MY_NO_THROW_DECL_ONLY x; \
|
||||
STDMETHOD(Close)() MY_NO_THROW_DECL_ONLY x; \
|
||||
STDMETHOD(GetNumberOfItems)(UInt32 *numItems) MY_NO_THROW_DECL_ONLY x; \
|
||||
STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) MY_NO_THROW_DECL_ONLY x; \
|
||||
/* STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, Int32 testMode, IArchiveExtractCallback *extractCallback) MY_NO_THROW_DECL_ONLY x; */ \
|
||||
STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value) MY_NO_THROW_DECL_ONLY x; \
|
||||
STDMETHOD(GetNumberOfProperties)(UInt32 *numProps) MY_NO_THROW_DECL_ONLY x; \
|
||||
STDMETHOD(GetPropertyInfo)(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) MY_NO_THROW_DECL_ONLY x; \
|
||||
STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProps) MY_NO_THROW_DECL_ONLY x; \
|
||||
STDMETHOD(GetArchivePropertyInfo)(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) MY_NO_THROW_DECL_ONLY x; \
|
||||
|
||||
|
||||
class CHandlerCont:
|
||||
public IInArchive,
|
||||
public IInArchiveGetStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
protected:
|
||||
CMyComPtr<IInStream> _stream;
|
||||
|
||||
virtual int GetItem_ExtractInfo(UInt32 index, UInt64 &pos, UInt64 &size) const = 0;
|
||||
|
||||
public:
|
||||
MY_UNKNOWN_IMP2(IInArchive, IInArchiveGetStream)
|
||||
INTERFACE_IInArchive_Cont(PURE)
|
||||
|
||||
STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, Int32 testMode, IArchiveExtractCallback *extractCallback) MY_NO_THROW_DECL_ONLY;
|
||||
|
||||
STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);
|
||||
|
||||
// destructor must be virtual for this class
|
||||
virtual ~CHandlerCont() {}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#define INTERFACE_IInArchive_Img(x) \
|
||||
/* STDMETHOD(Open)(IInStream *stream, const UInt64 *maxCheckStartPosition, IArchiveOpenCallback *openCallback) MY_NO_THROW_DECL_ONLY x; */ \
|
||||
STDMETHOD(Close)() MY_NO_THROW_DECL_ONLY x; \
|
||||
/* STDMETHOD(GetNumberOfItems)(UInt32 *numItems) MY_NO_THROW_DECL_ONLY x; */ \
|
||||
STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) MY_NO_THROW_DECL_ONLY x; \
|
||||
/* STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, Int32 testMode, IArchiveExtractCallback *extractCallback) MY_NO_THROW_DECL_ONLY x; */ \
|
||||
STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value) MY_NO_THROW_DECL_ONLY x; \
|
||||
STDMETHOD(GetNumberOfProperties)(UInt32 *numProps) MY_NO_THROW_DECL_ONLY x; \
|
||||
STDMETHOD(GetPropertyInfo)(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) MY_NO_THROW_DECL_ONLY x; \
|
||||
STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProps) MY_NO_THROW_DECL_ONLY x; \
|
||||
STDMETHOD(GetArchivePropertyInfo)(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) MY_NO_THROW_DECL_ONLY x; \
|
||||
|
||||
|
||||
class CHandlerImg:
|
||||
public IInStream,
|
||||
public IInArchive,
|
||||
public IInArchiveGetStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
protected:
|
||||
UInt64 _virtPos;
|
||||
UInt64 _posInArc;
|
||||
UInt64 _size;
|
||||
CMyComPtr<IInStream> Stream;
|
||||
const char *_imgExt;
|
||||
|
||||
bool _stream_unavailData;
|
||||
bool _stream_unsupportedMethod;
|
||||
bool _stream_dataError;
|
||||
// bool _stream_UsePackSize;
|
||||
// UInt64 _stream_PackSize;
|
||||
|
||||
void ClearStreamVars()
|
||||
{
|
||||
_stream_unavailData = false;
|
||||
_stream_unsupportedMethod = false;
|
||||
_stream_dataError = false;
|
||||
// _stream_UsePackSize = false;
|
||||
// _stream_PackSize = 0;
|
||||
}
|
||||
|
||||
|
||||
virtual HRESULT Open2(IInStream *stream, IArchiveOpenCallback *openCallback) = 0;
|
||||
virtual void CloseAtError();
|
||||
public:
|
||||
MY_UNKNOWN_IMP3(IInArchive, IInArchiveGetStream, IInStream)
|
||||
INTERFACE_IInArchive_Img(PURE)
|
||||
|
||||
STDMETHOD(Open)(IInStream *stream, const UInt64 *maxCheckStartPosition, IArchiveOpenCallback *openCallback);
|
||||
STDMETHOD(GetNumberOfItems)(UInt32 *numItems);
|
||||
STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, Int32 testMode, IArchiveExtractCallback *extractCallback);
|
||||
|
||||
STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream) = 0;
|
||||
|
||||
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize) = 0;
|
||||
STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
|
||||
|
||||
CHandlerImg();
|
||||
// destructor must be virtual for this class
|
||||
virtual ~CHandlerImg() {}
|
||||
};
|
||||
|
||||
|
||||
HRESULT ReadZeroTail(ISequentialInStream *stream, bool &areThereNonZeros, UInt64 &numZeros, UInt64 maxSize);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -293,12 +293,14 @@ namespace NPropDataType
|
||||
const UInt32 kMask_ZeroEnd = 1 << 4;
|
||||
// const UInt32 kMask_BigEndian = 1 << 5;
|
||||
const UInt32 kMask_Utf = 1 << 6;
|
||||
// const UInt32 kMask_Utf8 = kMask_Utf | 0;
|
||||
const UInt32 kMask_Utf8 = kMask_Utf | 0;
|
||||
const UInt32 kMask_Utf16 = kMask_Utf | 1;
|
||||
// const UInt32 kMask_Utf32 = kMask_Utf | 2;
|
||||
|
||||
const UInt32 kNotDefined = 0;
|
||||
const UInt32 kRaw = 1;
|
||||
|
||||
const UInt32 kUtf8z = kMask_Utf8 | kMask_ZeroEnd;
|
||||
const UInt32 kUtf16z = kMask_Utf16 | kMask_ZeroEnd;
|
||||
};
|
||||
|
||||
@@ -512,12 +514,26 @@ ARCHIVE_INTERFACE(IArchiveAllowTail, 0x05)
|
||||
{ if (index >= ARRAY_SIZE(k)) return E_INVALIDARG; \
|
||||
*propID = k[index]; *varType = k7z_PROPID_To_VARTYPE[(unsigned)*propID]; *name = 0; return S_OK; } \
|
||||
|
||||
|
||||
struct CStatProp
|
||||
{
|
||||
const char *Name;
|
||||
UInt32 PropID;
|
||||
VARTYPE vt;
|
||||
};
|
||||
|
||||
namespace NWindows {
|
||||
namespace NCOM {
|
||||
// PropVariant.cpp
|
||||
BSTR AllocBstrFromAscii(const char *s) throw();
|
||||
}}
|
||||
|
||||
#define IMP_IInArchive_GetProp_WITH_NAME(k) \
|
||||
(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) \
|
||||
{ if (index >= ARRAY_SIZE(k)) return E_INVALIDARG; \
|
||||
const STATPROPSTG &srcItem = k[index]; \
|
||||
*propID = srcItem.propid; *varType = srcItem.vt; \
|
||||
if (srcItem.lpwstrName == 0) *name = 0; else *name = ::SysAllocString(srcItem.lpwstrName); return S_OK; } \
|
||||
const CStatProp &prop = k[index]; \
|
||||
*propID = (PROPID)prop.PropID; *varType = prop.vt; \
|
||||
*name = NWindows::NCOM::AllocBstrFromAscii(prop.Name); return S_OK; } \
|
||||
|
||||
#define IMP_IInArchive_Props \
|
||||
STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProps) \
|
||||
|
||||
@@ -323,7 +323,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
{
|
||||
lps->InSize = lps->OutSize = currentTotalSize + offset;
|
||||
const CDir &item2 = ref.Dir->_subItems[ref.Index + e];
|
||||
RINOK(_stream->Seek((UInt64)item2.ExtentLocation * _archive.BlockSize, STREAM_SEEK_SET, NULL));
|
||||
RINOK(_stream->Seek((UInt64)item2.ExtentLocation * kBlockSize, STREAM_SEEK_SET, NULL));
|
||||
streamSpec->Init(item2.Size);
|
||||
RINOK(copyCoder->Code(inStream, realOutStream, NULL, NULL, progress));
|
||||
if (copyCoderSpec->TotalSize != item2.Size)
|
||||
@@ -336,7 +336,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
}
|
||||
else
|
||||
{
|
||||
RINOK(_stream->Seek(blockIndex * _archive.BlockSize, STREAM_SEEK_SET, NULL));
|
||||
RINOK(_stream->Seek((UInt64)blockIndex * kBlockSize, STREAM_SEEK_SET, NULL));
|
||||
streamSpec->Init(currentItemSize);
|
||||
RINOK(copyCoder->Code(inStream, realOutStream, NULL, NULL, progress));
|
||||
if (copyCoderSpec->TotalSize != currentItemSize)
|
||||
@@ -379,7 +379,7 @@ STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
|
||||
if (item.Size == 0)
|
||||
continue;
|
||||
CSeekExtent se;
|
||||
se.Phy = (UInt64)item.ExtentLocation * _archive.BlockSize;
|
||||
se.Phy = (UInt64)item.ExtentLocation * kBlockSize;
|
||||
se.Virt = virtOffset;
|
||||
extentStreamSpec->Extents.Add(se);
|
||||
virtOffset += item.Size;
|
||||
@@ -405,7 +405,7 @@ STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
|
||||
blockIndex = be.LoadRBA;
|
||||
}
|
||||
|
||||
return CreateLimitedInStream(_stream, blockIndex * _archive.BlockSize, currentItemSize, stream);
|
||||
return CreateLimitedInStream(_stream, (UInt64)blockIndex * kBlockSize, currentItemSize, stream);
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
|
||||
#include "../../Common/StreamUtils.h"
|
||||
|
||||
#include "../HandlerCont.h"
|
||||
|
||||
#include "IsoIn.h"
|
||||
|
||||
namespace NArchive {
|
||||
@@ -86,15 +88,15 @@ AString CBootInitialEntry::GetName() const
|
||||
|
||||
Byte CInArchive::ReadByte()
|
||||
{
|
||||
if (m_BufferPos >= BlockSize)
|
||||
if (m_BufferPos >= kBlockSize)
|
||||
m_BufferPos = 0;
|
||||
if (m_BufferPos == 0)
|
||||
{
|
||||
size_t processed = BlockSize;
|
||||
size_t processed = kBlockSize;
|
||||
HRESULT res = ReadStream(_stream, m_Buffer, &processed);
|
||||
if (res != S_OK)
|
||||
throw CSystemException(res);
|
||||
if (processed != BlockSize)
|
||||
if (processed != kBlockSize)
|
||||
throw CUnexpectedEndException();
|
||||
UInt64 end = _position + processed;
|
||||
if (PhySize < end)
|
||||
@@ -292,7 +294,11 @@ void CInArchive::ReadVolumeDescriptor(CVolumeDescriptor &d)
|
||||
d.FileStructureVersion = ReadByte(); // = 1
|
||||
SkipZeros(1);
|
||||
ReadBytes(d.ApplicationUse, sizeof(d.ApplicationUse));
|
||||
SkipZeros(653);
|
||||
|
||||
// Most ISO contains zeros in the following field (reserved for future standardization).
|
||||
// But some ISO programs write some data to that area.
|
||||
// So we disable check for zeros.
|
||||
Skip(653); // SkipZeros(653);
|
||||
}
|
||||
|
||||
static const Byte kSig_CD001[5] = { 'C', 'D', '0', '0', '1' };
|
||||
@@ -509,7 +515,7 @@ HRESULT CInArchive::Open2()
|
||||
|
||||
PhySize = _position;
|
||||
m_BufferPos = 0;
|
||||
BlockSize = kBlockSize;
|
||||
// BlockSize = kBlockSize;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
@@ -596,7 +602,7 @@ HRESULT CInArchive::Open2()
|
||||
ReadBootInfo();
|
||||
|
||||
{
|
||||
FOR_VECTOR(i, Refs)
|
||||
FOR_VECTOR (i, Refs)
|
||||
{
|
||||
const CRef &ref = Refs[i];
|
||||
for (UInt32 j = 0; j < ref.NumExtents; j++)
|
||||
@@ -608,12 +614,28 @@ HRESULT CInArchive::Open2()
|
||||
}
|
||||
}
|
||||
{
|
||||
FOR_VECTOR(i, BootEntries)
|
||||
FOR_VECTOR (i, BootEntries)
|
||||
{
|
||||
const CBootInitialEntry &be = BootEntries[i];
|
||||
UpdatePhySize(be.LoadRBA, GetBootItemSize(i));
|
||||
}
|
||||
}
|
||||
|
||||
if (PhySize < _fileSize)
|
||||
{
|
||||
UInt64 rem = _fileSize - PhySize;
|
||||
const UInt64 kRemMax = 1 << 21;
|
||||
if (rem <= kRemMax)
|
||||
{
|
||||
RINOK(_stream->Seek(PhySize, STREAM_SEEK_SET, NULL));
|
||||
bool areThereNonZeros = false;
|
||||
UInt64 numZeros = 0;
|
||||
RINOK(ReadZeroTail(_stream, areThereNonZeros, numZeros, kRemMax));
|
||||
if (!areThereNonZeros)
|
||||
PhySize += numZeros;
|
||||
}
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -282,7 +282,7 @@ public:
|
||||
CRecordVector<CRef> Refs;
|
||||
CObjectVector<CVolumeDescriptor> VolDescs;
|
||||
int MainVolDescIndex;
|
||||
UInt32 BlockSize;
|
||||
// UInt32 BlockSize;
|
||||
CObjectVector<CBootInitialEntry> BootEntries;
|
||||
|
||||
bool IsArc;
|
||||
@@ -297,8 +297,8 @@ public:
|
||||
|
||||
void UpdatePhySize(UInt32 blockIndex, UInt64 size)
|
||||
{
|
||||
UInt64 alignedSize = (size + BlockSize - 1) & ~((UInt64)BlockSize - 1);
|
||||
UInt64 end = blockIndex * BlockSize + alignedSize;
|
||||
const UInt64 alignedSize = (size + kBlockSize - 1) & ~((UInt64)kBlockSize - 1);
|
||||
const UInt64 end = (UInt64)blockIndex * kBlockSize + alignedSize;
|
||||
if (PhySize < end)
|
||||
PhySize = end;
|
||||
}
|
||||
@@ -315,7 +315,7 @@ public:
|
||||
size = (1440 << 10);
|
||||
else if (be.BootMediaType == NBootMediaType::k2d88Floppy)
|
||||
size = (2880 << 10);
|
||||
UInt64 startPos = (UInt64)be.LoadRBA * BlockSize;
|
||||
UInt64 startPos = (UInt64)be.LoadRBA * kBlockSize;
|
||||
if (startPos < _fileSize)
|
||||
{
|
||||
if (_fileSize - startPos < size)
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace NMacho {
|
||||
|
||||
#define CPU_SUBTYPE_LIB64 (1 << 31)
|
||||
|
||||
#define CPU_SUBTYPE_POWERPC_970 100
|
||||
#define CPU_SUBTYPE_POWERPC_970 100
|
||||
|
||||
static const char * const k_PowerPc_SubTypes[] =
|
||||
{
|
||||
|
||||
@@ -13,16 +13,13 @@
|
||||
#include "../../Common/ComTry.h"
|
||||
#include "../../Common/IntToString.h"
|
||||
#include "../../Common/MyBuffer.h"
|
||||
#include "../../Common/MyString.h"
|
||||
|
||||
#include "../../Windows/PropVariant.h"
|
||||
|
||||
#include "../Common/LimitedStreams.h"
|
||||
#include "../Common/ProgressUtils.h"
|
||||
#include "../Common/RegisterArc.h"
|
||||
#include "../Common/StreamUtils.h"
|
||||
|
||||
#include "../Compress/CopyCoder.h"
|
||||
#include "HandlerCont.h"
|
||||
|
||||
#ifdef SHOW_DEBUG_INFO
|
||||
#define PRF(x) x
|
||||
@@ -56,12 +53,15 @@ struct CChs
|
||||
|
||||
#define RINOZ(x) { int __tt = (x); if (__tt != 0) return __tt; }
|
||||
|
||||
// Chs in some MBRs contains only low bits of "Cyl number". So we disable check.
|
||||
/*
|
||||
static int CompareChs(const CChs &c1, const CChs &c2)
|
||||
{
|
||||
RINOZ(MyCompare(c1.GetCyl(), c2.GetCyl()));
|
||||
RINOZ(MyCompare(c1.Head, c2.Head));
|
||||
return MyCompare(c1.GetSector(), c2.GetSector());
|
||||
}
|
||||
*/
|
||||
|
||||
static void AddUIntToString(UInt32 val, AString &res)
|
||||
{
|
||||
@@ -112,12 +112,11 @@ struct CPartition
|
||||
return true;
|
||||
if (Status != 0 && Status != 0x80)
|
||||
return false;
|
||||
return
|
||||
BeginChs.Check() &&
|
||||
EndChs.Check() &&
|
||||
CompareChs(BeginChs, EndChs) <= 0 &&
|
||||
NumBlocks > 0 &&
|
||||
CheckLbaLimits();
|
||||
return BeginChs.Check()
|
||||
&& EndChs.Check()
|
||||
// && CompareChs(BeginChs, EndChs) <= 0
|
||||
&& NumBlocks > 0
|
||||
&& CheckLbaLimits();
|
||||
}
|
||||
|
||||
#ifdef SHOW_DEBUG_INFO
|
||||
@@ -159,11 +158,13 @@ static const CPartType kPartTypes[] =
|
||||
{ 0x1E, kFat, "FAT16-LBA-WIN95-Hidden" },
|
||||
{ 0x82, 0, "Solaris x86 / Linux swap" },
|
||||
{ 0x83, 0, "Linux" },
|
||||
{ 0x8E, "lvm", "Linux LVM" },
|
||||
{ 0xA5, 0, "BSD slice" },
|
||||
{ 0xBE, 0, "Solaris 8 boot" },
|
||||
{ 0xBF, 0, "New Solaris x86" },
|
||||
{ 0xC2, 0, "Linux-Hidden" },
|
||||
{ 0xC3, 0, "Linux swap-Hidden" },
|
||||
{ 0xEE, 0, "EFI-MBR" },
|
||||
{ 0xEE, 0, "GPT" },
|
||||
{ 0xEE, 0, "EFI" }
|
||||
};
|
||||
|
||||
@@ -183,21 +184,23 @@ struct CItem
|
||||
CPartition Part;
|
||||
};
|
||||
|
||||
class CHandler:
|
||||
public IInArchive,
|
||||
public IInArchiveGetStream,
|
||||
public CMyUnknownImp
|
||||
class CHandler: public CHandlerCont
|
||||
{
|
||||
CMyComPtr<IInStream> _stream;
|
||||
CObjectVector<CItem> _items;
|
||||
UInt64 _totalSize;
|
||||
CByteBuffer _buffer;
|
||||
|
||||
virtual int GetItem_ExtractInfo(UInt32 index, UInt64 &pos, UInt64 &size) const
|
||||
{
|
||||
const CItem &item = _items[index];
|
||||
pos = item.Part.GetPos();
|
||||
size = item.Size;
|
||||
return NExtract::NOperationResult::kOK;
|
||||
}
|
||||
|
||||
HRESULT ReadTables(IInStream *stream, UInt32 baseLba, UInt32 lba, unsigned level);
|
||||
public:
|
||||
MY_UNKNOWN_IMP2(IInArchive, IInArchiveGetStream)
|
||||
INTERFACE_IInArchive(;)
|
||||
STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);
|
||||
INTERFACE_IInArchive_Cont(;)
|
||||
};
|
||||
|
||||
HRESULT CHandler::ReadTables(IInStream *stream, UInt32 baseLba, UInt32 lba, unsigned level)
|
||||
@@ -336,15 +339,15 @@ enum
|
||||
kpidEndChs
|
||||
};
|
||||
|
||||
static const STATPROPSTG kProps[] =
|
||||
static const CStatProp kProps[] =
|
||||
{
|
||||
{ NULL, kpidPath, VT_BSTR},
|
||||
{ NULL, kpidSize, VT_UI8},
|
||||
{ NULL, kpidFileSystem, VT_BSTR},
|
||||
{ NULL, kpidOffset, VT_UI8},
|
||||
{ (LPOLESTR)L"Primary", kpidPrimary, VT_BOOL},
|
||||
{ (LPOLESTR)L"Begin CHS", kpidBegChs, VT_BSTR},
|
||||
{ (LPOLESTR)L"End CHS", kpidEndChs, VT_BSTR}
|
||||
{ "Primary", kpidPrimary, VT_BOOL},
|
||||
{ "Begin CHS", kpidBegChs, VT_BSTR},
|
||||
{ "End CHS", kpidEndChs, VT_BSTR}
|
||||
};
|
||||
|
||||
IMP_IInArchive_Props_WITH_NAME
|
||||
@@ -391,7 +394,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
|
||||
const CItem &item = _items[index];
|
||||
const CPartition &part = item.Part;
|
||||
switch(propID)
|
||||
switch (propID)
|
||||
{
|
||||
case kpidPath:
|
||||
{
|
||||
@@ -421,7 +424,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
prop = res;
|
||||
}
|
||||
break;
|
||||
case kpidSize: prop = item.Size; break;;
|
||||
case kpidSize:
|
||||
case kpidPackSize: prop = item.Size; break;
|
||||
case kpidOffset: prop = part.GetPos(); break;
|
||||
case kpidPrimary: if (item.IsReal) prop = item.IsPrim; break;
|
||||
@@ -433,72 +436,6 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
Int32 testMode, IArchiveExtractCallback *extractCallback)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
bool allFilesMode = (numItems == (UInt32)(Int32)-1);
|
||||
if (allFilesMode)
|
||||
numItems = _items.Size();
|
||||
if (numItems == 0)
|
||||
return S_OK;
|
||||
UInt64 totalSize = 0;
|
||||
UInt32 i;
|
||||
for (i = 0; i < numItems; i++)
|
||||
totalSize += _items[allFilesMode ? i : indices[i]].Size;
|
||||
extractCallback->SetTotal(totalSize);
|
||||
|
||||
totalSize = 0;
|
||||
|
||||
NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder();
|
||||
CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
|
||||
|
||||
CLocalProgress *lps = new CLocalProgress;
|
||||
CMyComPtr<ICompressProgressInfo> progress = lps;
|
||||
lps->Init(extractCallback, false);
|
||||
|
||||
CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
|
||||
CMyComPtr<ISequentialInStream> inStream(streamSpec);
|
||||
streamSpec->SetStream(_stream);
|
||||
|
||||
for (i = 0; i < numItems; i++)
|
||||
{
|
||||
lps->InSize = totalSize;
|
||||
lps->OutSize = totalSize;
|
||||
RINOK(lps->SetCur());
|
||||
CMyComPtr<ISequentialOutStream> outStream;
|
||||
Int32 askMode = testMode ?
|
||||
NExtract::NAskMode::kTest :
|
||||
NExtract::NAskMode::kExtract;
|
||||
Int32 index = allFilesMode ? i : indices[i];
|
||||
const CItem &item = _items[index];
|
||||
const CPartition &part = item.Part;
|
||||
RINOK(extractCallback->GetStream(index, &outStream, askMode));
|
||||
totalSize += item.Size;
|
||||
if (!testMode && !outStream)
|
||||
continue;
|
||||
RINOK(extractCallback->PrepareOperation(askMode));
|
||||
|
||||
RINOK(_stream->Seek(part.GetPos(), STREAM_SEEK_SET, NULL));
|
||||
streamSpec->Init(item.Size);
|
||||
RINOK(copyCoder->Code(inStream, outStream, NULL, NULL, progress));
|
||||
outStream.Release();
|
||||
RINOK(extractCallback->SetOperationResult(copyCoderSpec->TotalSize == item.Size ?
|
||||
NExtract::NOperationResult::kOK:
|
||||
NExtract::NOperationResult::kDataError));
|
||||
}
|
||||
return S_OK;
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
const CItem &item = _items[index];
|
||||
return CreateLimitedInStream(_stream, item.Part.GetPos(), item.Size, stream);
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
|
||||
// 3, { 1, 1, 0 },
|
||||
// 2, { 0x55, 0x1FF },
|
||||
|
||||
@@ -10,12 +10,10 @@
|
||||
|
||||
#include "../../Windows/PropVariant.h"
|
||||
|
||||
#include "../Common/LimitedStreams.h"
|
||||
#include "../Common/ProgressUtils.h"
|
||||
#include "../Common/RegisterArc.h"
|
||||
#include "../Common/StreamUtils.h"
|
||||
|
||||
#include "../Compress/CopyCoder.h"
|
||||
#include "HandlerCont.h"
|
||||
|
||||
static UInt32 Get32(const Byte *p, bool be) { if (be) return GetBe32(p); return GetUi32(p); }
|
||||
|
||||
@@ -36,7 +34,7 @@ namespace NMub {
|
||||
|
||||
#define MACH_CPU_SUBTYPE_LIB64 (1 << 31)
|
||||
|
||||
#define MACH_CPU_SUBTYPE_I386_ALL 3
|
||||
#define MACH_CPU_SUBTYPE_I386_ALL 3
|
||||
|
||||
struct CItem
|
||||
{
|
||||
@@ -49,12 +47,8 @@ struct CItem
|
||||
|
||||
static const UInt32 kNumFilesMax = 10;
|
||||
|
||||
class CHandler:
|
||||
public IInArchive,
|
||||
public IInArchiveGetStream,
|
||||
public CMyUnknownImp
|
||||
class CHandler: public CHandlerCont
|
||||
{
|
||||
CMyComPtr<IInStream> _stream;
|
||||
// UInt64 _startPos;
|
||||
UInt64 _phySize;
|
||||
UInt32 _numItems;
|
||||
@@ -62,10 +56,17 @@ class CHandler:
|
||||
CItem _items[kNumFilesMax];
|
||||
|
||||
HRESULT Open2(IInStream *stream);
|
||||
|
||||
virtual int GetItem_ExtractInfo(UInt32 index, UInt64 &pos, UInt64 &size) const
|
||||
{
|
||||
const CItem &item = _items[index];
|
||||
pos = item.Offset;
|
||||
size = item.Size;
|
||||
return NExtract::NOperationResult::kOK;
|
||||
}
|
||||
|
||||
public:
|
||||
MY_UNKNOWN_IMP2(IInArchive, IInArchiveGetStream)
|
||||
INTERFACE_IInArchive(;)
|
||||
STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);
|
||||
INTERFACE_IInArchive_Cont(;)
|
||||
};
|
||||
|
||||
static const Byte kArcProps[] =
|
||||
@@ -223,75 +224,6 @@ STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
Int32 testMode, IArchiveExtractCallback *extractCallback)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
bool allFilesMode = (numItems == (UInt32)(Int32)-1);
|
||||
if (allFilesMode)
|
||||
numItems = _numItems;
|
||||
if (numItems == 0)
|
||||
return S_OK;
|
||||
UInt64 totalSize = 0;
|
||||
UInt32 i;
|
||||
for (i = 0; i < numItems; i++)
|
||||
totalSize += _items[allFilesMode ? i : indices[i]].Size;
|
||||
extractCallback->SetTotal(totalSize);
|
||||
|
||||
UInt64 currentTotalSize = 0;
|
||||
|
||||
NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder();
|
||||
CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
|
||||
|
||||
CLocalProgress *lps = new CLocalProgress;
|
||||
CMyComPtr<ICompressProgressInfo> progress = lps;
|
||||
lps->Init(extractCallback, false);
|
||||
|
||||
CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
|
||||
CMyComPtr<ISequentialInStream> inStream(streamSpec);
|
||||
streamSpec->SetStream(_stream);
|
||||
|
||||
for (i = 0; i < numItems; i++)
|
||||
{
|
||||
lps->InSize = lps->OutSize = currentTotalSize;
|
||||
RINOK(lps->SetCur());
|
||||
CMyComPtr<ISequentialOutStream> realOutStream;
|
||||
Int32 askMode = testMode ?
|
||||
NExtract::NAskMode::kTest :
|
||||
NExtract::NAskMode::kExtract;
|
||||
UInt32 index = allFilesMode ? i : indices[i];
|
||||
const CItem &item = _items[index];
|
||||
RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
|
||||
currentTotalSize += item.Size;
|
||||
|
||||
if (!testMode && !realOutStream)
|
||||
continue;
|
||||
RINOK(extractCallback->PrepareOperation(askMode));
|
||||
if (testMode)
|
||||
{
|
||||
RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
|
||||
continue;
|
||||
}
|
||||
RINOK(_stream->Seek(/* _startPos + */ item.Offset, STREAM_SEEK_SET, NULL));
|
||||
streamSpec->Init(item.Size);
|
||||
RINOK(copyCoder->Code(inStream, realOutStream, NULL, NULL, progress));
|
||||
realOutStream.Release();
|
||||
RINOK(extractCallback->SetOperationResult((copyCoderSpec->TotalSize == item.Size) ?
|
||||
NExtract::NOperationResult::kOK:
|
||||
NExtract::NOperationResult::kDataError));
|
||||
}
|
||||
return S_OK;
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
const CItem &item = _items[index];
|
||||
return CreateLimitedInStream(_stream, /* _startPos + */ item.Offset, item.Size, stream);
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
namespace NBe {
|
||||
|
||||
static const Byte k_Signature[] = {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
/* If NSIS_SCRIPT is defined, it will decompile NSIS script to [NSIS].nsi file.
|
||||
The code is much larger in that case. */
|
||||
|
||||
#define NSIS_SCRIPT
|
||||
// #define NSIS_SCRIPT
|
||||
|
||||
namespace NArchive {
|
||||
namespace NNsis {
|
||||
|
||||
@@ -519,7 +519,7 @@ bool CAttr::ParseExtents(CRecordVector<CExtent> &extents, UInt64 numClustersMax,
|
||||
UInt64 vSize = 0;
|
||||
{
|
||||
unsigned i = num;
|
||||
do vSize = (vSize << 8) | p[--i]; while(i);
|
||||
do vSize = (vSize << 8) | p[--i]; while (i);
|
||||
}
|
||||
if (vSize == 0)
|
||||
return false;
|
||||
@@ -576,20 +576,20 @@ class CInStream:
|
||||
UInt64 _physPos;
|
||||
UInt64 _curRem;
|
||||
bool _sparseMode;
|
||||
size_t _compressedPos;
|
||||
|
||||
UInt64 _tags[kNumCacheChunks];
|
||||
|
||||
unsigned _chunkSizeLog;
|
||||
UInt64 _tags[kNumCacheChunks];
|
||||
CByteBuffer _inBuf;
|
||||
CByteBuffer _outBuf;
|
||||
public:
|
||||
CMyComPtr<IInStream> Stream;
|
||||
UInt64 Size;
|
||||
UInt64 InitializedSize;
|
||||
unsigned BlockSizeLog;
|
||||
unsigned CompressionUnit;
|
||||
bool InUse;
|
||||
CRecordVector<CExtent> Extents;
|
||||
bool InUse;
|
||||
CMyComPtr<IInStream> Stream;
|
||||
|
||||
HRESULT SeekToPhys() { return Stream->Seek(_physPos, STREAM_SEEK_SET, NULL); }
|
||||
|
||||
@@ -597,11 +597,11 @@ public:
|
||||
HRESULT InitAndSeek(unsigned compressionUnit)
|
||||
{
|
||||
CompressionUnit = compressionUnit;
|
||||
_chunkSizeLog = BlockSizeLog + CompressionUnit;
|
||||
if (compressionUnit != 0)
|
||||
{
|
||||
UInt32 cuSize = GetCuSize();
|
||||
_inBuf.Alloc(cuSize);
|
||||
_chunkSizeLog = BlockSizeLog + CompressionUnit;
|
||||
_outBuf.Alloc(kNumCacheChunks << _chunkSizeLog);
|
||||
}
|
||||
for (size_t i = 0; i < kNumCacheChunks; i++)
|
||||
@@ -1835,7 +1835,7 @@ HRESULT CDatabase::Open()
|
||||
int indexOfUnnamedStream = -1;
|
||||
if (!rec.IsDir())
|
||||
{
|
||||
FOR_VECTOR(di, rec.DataRefs)
|
||||
FOR_VECTOR (di, rec.DataRefs)
|
||||
if (rec.DataAttrs[rec.DataRefs[di].Start].Name.IsEmpty())
|
||||
{
|
||||
indexOfUnnamedStream = di;
|
||||
@@ -1849,7 +1849,7 @@ HRESULT CDatabase::Open()
|
||||
if (i < kNumSysRecs)
|
||||
{
|
||||
needShow = false;
|
||||
FOR_VECTOR(di, rec.DataRefs)
|
||||
FOR_VECTOR (di, rec.DataRefs)
|
||||
if (rec.GetSize(di) != 0)
|
||||
{
|
||||
needShow = true;
|
||||
@@ -1905,7 +1905,7 @@ HRESULT CDatabase::Open()
|
||||
|
||||
unsigned numAltStreams = 0;
|
||||
|
||||
FOR_VECTOR(di, rec.DataRefs)
|
||||
FOR_VECTOR (di, rec.DataRefs)
|
||||
{
|
||||
if (!rec.IsDir() && (int)di == indexOfUnnamedStream)
|
||||
continue;
|
||||
@@ -2173,7 +2173,7 @@ enum
|
||||
kpidATime2
|
||||
};
|
||||
|
||||
static const STATPROPSTG kProps[] =
|
||||
static const CStatProp kProps[] =
|
||||
{
|
||||
{ NULL, kpidPath, VT_BSTR},
|
||||
{ NULL, kpidSize, VT_UI8},
|
||||
@@ -2181,20 +2181,20 @@ static const STATPROPSTG kProps[] =
|
||||
|
||||
// { NULL, kpidLink, VT_BSTR},
|
||||
|
||||
// { (LPOLESTR)L"Link 2", kpidLink2, VT_BSTR},
|
||||
// { (LPOLESTR)L"Link Type", kpidLinkType, VT_UI2},
|
||||
// { "Link 2", kpidLink2, VT_BSTR},
|
||||
// { "Link Type", kpidLinkType, VT_UI2},
|
||||
{ NULL, kpidINode, VT_UI8},
|
||||
|
||||
{ NULL, kpidMTime, VT_FILETIME},
|
||||
{ NULL, kpidCTime, VT_FILETIME},
|
||||
{ NULL, kpidATime, VT_FILETIME},
|
||||
|
||||
// { (LPOLESTR)L"Record Modified", kpidRecMTime, VT_FILETIME},
|
||||
// { "Record Modified", kpidRecMTime, VT_FILETIME},
|
||||
|
||||
// { (LPOLESTR)L"Modified 2", kpidMTime2, VT_FILETIME},
|
||||
// { (LPOLESTR)L"Created 2", kpidCTime2, VT_FILETIME},
|
||||
// { (LPOLESTR)L"Accessed 2", kpidATime2, VT_FILETIME},
|
||||
// { (LPOLESTR)L"Record Modified 2", kpidRecMTime2, VT_FILETIME},
|
||||
// { "Modified 2", kpidMTime2, VT_FILETIME},
|
||||
// { "Created 2", kpidCTime2, VT_FILETIME},
|
||||
// { "Accessed 2", kpidATime2, VT_FILETIME},
|
||||
// { "Record Modified 2", kpidRecMTime2, VT_FILETIME},
|
||||
|
||||
{ NULL, kpidAttrib, VT_UI4},
|
||||
{ NULL, kpidNumBlocks, VT_UI4},
|
||||
@@ -2226,13 +2226,13 @@ enum
|
||||
kpidRecordSize = kpidUserDefined
|
||||
};
|
||||
|
||||
static const STATPROPSTG kArcProps[] =
|
||||
static const CStatProp kArcProps[] =
|
||||
{
|
||||
{ NULL, kpidVolumeName, VT_BSTR},
|
||||
{ NULL, kpidFileSystem, VT_BSTR},
|
||||
{ NULL, kpidClusterSize, VT_UI4},
|
||||
{ NULL, kpidSectorSize, VT_UI4},
|
||||
{ (LPOLESTR)L"Record Size", kpidRecordSize, VT_UI4},
|
||||
{ "Record Size", kpidRecordSize, VT_UI4},
|
||||
{ NULL, kpidHeadersSize, VT_UI8},
|
||||
{ NULL, kpidCTime, VT_FILETIME},
|
||||
{ NULL, kpidId, VT_UI8},
|
||||
@@ -2514,8 +2514,8 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
attrib |= FILE_ATTRIBUTE_DIRECTORY;
|
||||
|
||||
/* some system entries can contain extra flags (Index View).
|
||||
// 0x10000000 (Directory)
|
||||
// 0x20000000 FILE_ATTR_VIEW_INDEX_PRESENT MFT_RECORD_IS_VIEW_INDEX (Index View)
|
||||
// 0x10000000 (Directory)
|
||||
// 0x20000000 FILE_ATTR_VIEW_INDEX_PRESENT MFT_RECORD_IS_VIEW_INDEX (Index View)
|
||||
But we don't need them */
|
||||
attrib &= 0xFFFF;
|
||||
|
||||
|
||||
@@ -765,7 +765,7 @@ enum
|
||||
// kpidBaseOfData32,
|
||||
};
|
||||
|
||||
static const STATPROPSTG kArcProps[] =
|
||||
static const CStatProp kArcProps[] =
|
||||
{
|
||||
// { NULL, kpidWarning, VT_BSTR},
|
||||
{ NULL, kpidCpu, VT_BSTR},
|
||||
@@ -776,28 +776,28 @@ static const STATPROPSTG kArcProps[] =
|
||||
{ NULL, kpidChecksum, VT_UI4},
|
||||
{ NULL, kpidName, VT_BSTR},
|
||||
|
||||
{ (LPOLESTR)L"Image Size", kpidImageSize, VT_UI4},
|
||||
{ (LPOLESTR)L"Section Alignment", kpidSectAlign, VT_UI4},
|
||||
{ (LPOLESTR)L"File Alignment", kpidFileAlign, VT_UI4},
|
||||
{ (LPOLESTR)L"Code Size", kpidCodeSize, VT_UI4},
|
||||
{ (LPOLESTR)L"Initialized Data Size", kpidInitDataSize, VT_UI4},
|
||||
{ (LPOLESTR)L"Uninitialized Data Size", kpidUnInitDataSize, VT_UI4},
|
||||
{ (LPOLESTR)L"Linker Version", kpidLinkerVer, VT_BSTR},
|
||||
{ (LPOLESTR)L"OS Version", kpidOsVer, VT_BSTR},
|
||||
{ (LPOLESTR)L"Image Version", kpidImageVer, VT_BSTR},
|
||||
{ (LPOLESTR)L"Subsystem Version", kpidSubsysVer, VT_BSTR},
|
||||
{ (LPOLESTR)L"Subsystem", kpidSubSystem, VT_BSTR},
|
||||
{ (LPOLESTR)L"DLL Characteristics", kpidDllCharacts, VT_BSTR},
|
||||
{ (LPOLESTR)L"Stack Reserve", kpidStackReserve, VT_UI8},
|
||||
{ (LPOLESTR)L"Stack Commit", kpidStackCommit, VT_UI8},
|
||||
{ (LPOLESTR)L"Heap Reserve", kpidHeapReserve, VT_UI8},
|
||||
{ (LPOLESTR)L"Heap Commit", kpidHeapCommit, VT_UI8},
|
||||
{ (LPOLESTR)L"Image Base", kpidImageBase, VT_UI8},
|
||||
{ "Image Size", kpidImageSize, VT_UI4},
|
||||
{ "Section Alignment", kpidSectAlign, VT_UI4},
|
||||
{ "File Alignment", kpidFileAlign, VT_UI4},
|
||||
{ "Code Size", kpidCodeSize, VT_UI4},
|
||||
{ "Initialized Data Size", kpidInitDataSize, VT_UI4},
|
||||
{ "Uninitialized Data Size", kpidUnInitDataSize, VT_UI4},
|
||||
{ "Linker Version", kpidLinkerVer, VT_BSTR},
|
||||
{ "OS Version", kpidOsVer, VT_BSTR},
|
||||
{ "Image Version", kpidImageVer, VT_BSTR},
|
||||
{ "Subsystem Version", kpidSubsysVer, VT_BSTR},
|
||||
{ "Subsystem", kpidSubSystem, VT_BSTR},
|
||||
{ "DLL Characteristics", kpidDllCharacts, VT_BSTR},
|
||||
{ "Stack Reserve", kpidStackReserve, VT_UI8},
|
||||
{ "Stack Commit", kpidStackCommit, VT_UI8},
|
||||
{ "Heap Reserve", kpidHeapReserve, VT_UI8},
|
||||
{ "Heap Commit", kpidHeapCommit, VT_UI8},
|
||||
{ "Image Base", kpidImageBase, VT_UI8},
|
||||
{ NULL, kpidComment, VT_BSTR},
|
||||
|
||||
// { (LPOLESTR)L"Address Of Entry Point", kpidAddressOfEntryPoint, VT_UI8},
|
||||
// { (LPOLESTR)L"Base Of Code", kpidBaseOfCode, VT_UI8},
|
||||
// { (LPOLESTR)L"Base Of Data", kpidBaseOfData32, VT_UI8},
|
||||
// { "Address Of Entry Point", kpidAddressOfEntryPoint, VT_UI8},
|
||||
// { "Base Of Code", kpidBaseOfCode, VT_UI8},
|
||||
// { "Base Of Data", kpidBaseOfData32, VT_UI8},
|
||||
};
|
||||
|
||||
static const Byte kProps[] =
|
||||
@@ -2233,7 +2233,7 @@ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
|
||||
sections.Sort();
|
||||
UInt32 limit = (1 << 12);
|
||||
unsigned num = 0;
|
||||
FOR_VECTOR(i, sections)
|
||||
FOR_VECTOR (i, sections)
|
||||
{
|
||||
const CSection &s = sections[i];
|
||||
if (s.Pa > limit)
|
||||
@@ -2798,12 +2798,12 @@ enum
|
||||
// , kpidImageBase
|
||||
};
|
||||
|
||||
static const STATPROPSTG kArcProps[] =
|
||||
static const CStatProp kArcProps[] =
|
||||
{
|
||||
// { NULL, kpidHeadersSize, VT_UI4 },
|
||||
{ NULL, kpidCpu, VT_BSTR},
|
||||
{ (LPOLESTR)L"Subsystem", kpidSubSystem, VT_BSTR },
|
||||
// { (LPOLESTR)L"Image Base", kpidImageBase, VT_UI8 }
|
||||
{ "Subsystem", kpidSubSystem, VT_BSTR },
|
||||
// { "Image Base", kpidImageBase, VT_UI8 }
|
||||
};
|
||||
|
||||
IMP_IInArchive_Props
|
||||
|
||||
611
CPP/7zip/Archive/QcowHandler.cpp
Normal file
611
CPP/7zip/Archive/QcowHandler.cpp
Normal file
@@ -0,0 +1,611 @@
|
||||
// QcowHandler.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
// #include <stdio.h>
|
||||
|
||||
#include "../../../C/CpuArch.h"
|
||||
|
||||
#include "../../Common/ComTry.h"
|
||||
#include "../../Common/IntToString.h"
|
||||
|
||||
#include "../../Windows/PropVariant.h"
|
||||
|
||||
#include "../Common/RegisterArc.h"
|
||||
#include "../Common/StreamObjects.h"
|
||||
#include "../Common/StreamUtils.h"
|
||||
|
||||
#include "../Compress/DeflateDecoder.h"
|
||||
|
||||
#include "HandlerCont.h"
|
||||
|
||||
#define Get32(p) GetBe32(p)
|
||||
#define Get64(p) GetBe64(p)
|
||||
|
||||
using namespace NWindows;
|
||||
|
||||
namespace NArchive {
|
||||
namespace NQcow {
|
||||
|
||||
#define SIGNATURE { 'Q', 'F', 'I', 0xFB, 0, 0, 0 }
|
||||
|
||||
static const Byte k_Signature[] = SIGNATURE;
|
||||
|
||||
class CHandler: public CHandlerImg
|
||||
{
|
||||
unsigned _clusterBits;
|
||||
unsigned _numMidBits;
|
||||
UInt64 _compressedFlag;
|
||||
|
||||
CObjectVector<CByteBuffer> _tables;
|
||||
UInt64 _cacheCluster;
|
||||
CByteBuffer _cache;
|
||||
CByteBuffer _cacheCompressed;
|
||||
|
||||
UInt64 _comprPos;
|
||||
size_t _comprSize;
|
||||
|
||||
UInt64 _phySize;
|
||||
|
||||
CBufInStream *_bufInStreamSpec;
|
||||
CMyComPtr<ISequentialInStream> _bufInStream;
|
||||
|
||||
CBufPtrSeqOutStream *_bufOutStreamSpec;
|
||||
CMyComPtr<ISequentialOutStream> _bufOutStream;
|
||||
|
||||
NCompress::NDeflate::NDecoder::CCOMCoder *_deflateDecoderSpec;
|
||||
CMyComPtr<ICompressCoder> _deflateDecoder;
|
||||
|
||||
bool _needDeflate;
|
||||
bool _isArc;
|
||||
bool _unsupported;
|
||||
|
||||
UInt32 _version;
|
||||
UInt32 _cryptMethod;
|
||||
|
||||
HRESULT Seek(UInt64 offset)
|
||||
{
|
||||
_posInArc = offset;
|
||||
return Stream->Seek(offset, STREAM_SEEK_SET, NULL);
|
||||
}
|
||||
|
||||
HRESULT InitAndSeek()
|
||||
{
|
||||
_virtPos = 0;
|
||||
return Seek(0);
|
||||
}
|
||||
|
||||
HRESULT Open2(IInStream *stream, IArchiveOpenCallback *openCallback);
|
||||
|
||||
public:
|
||||
INTERFACE_IInArchive_Img(;)
|
||||
|
||||
STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);
|
||||
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
|
||||
};
|
||||
|
||||
|
||||
STDMETHODIMP CHandler::Read(void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
if (processedSize)
|
||||
*processedSize = 0;
|
||||
if (_virtPos >= _size)
|
||||
return S_OK;
|
||||
{
|
||||
UInt64 rem = _size - _virtPos;
|
||||
if (size > rem)
|
||||
size = (UInt32)rem;
|
||||
if (size == 0)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
for (;;)
|
||||
{
|
||||
UInt64 cluster = _virtPos >> _clusterBits;
|
||||
size_t clusterSize = (size_t)1 << _clusterBits;
|
||||
size_t lowBits = (size_t)_virtPos & (clusterSize - 1);
|
||||
{
|
||||
size_t rem = clusterSize - lowBits;
|
||||
if (size > rem)
|
||||
size = (UInt32)rem;
|
||||
}
|
||||
|
||||
if (cluster == _cacheCluster)
|
||||
{
|
||||
memcpy(data, _cache + lowBits, size);
|
||||
_virtPos += size;
|
||||
if (processedSize)
|
||||
*processedSize = size;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
UInt64 high = cluster >> _numMidBits;
|
||||
|
||||
if (high < _tables.Size())
|
||||
{
|
||||
const CByteBuffer &buffer = _tables[(unsigned)high];
|
||||
|
||||
if (buffer.Size() != 0)
|
||||
{
|
||||
size_t midBits = (size_t)cluster & (((size_t)1 << _numMidBits) - 1);
|
||||
const Byte *p = (const Byte *)buffer + (midBits << 3);
|
||||
UInt64 v = Get64(p);
|
||||
|
||||
if (v != 0)
|
||||
{
|
||||
if ((v & _compressedFlag) != 0)
|
||||
{
|
||||
if (_version <= 1)
|
||||
return E_FAIL;
|
||||
unsigned numOffsetBits = (62 - (_clusterBits - 8));
|
||||
UInt64 offset = v & (((UInt64)1 << 62) - 1);
|
||||
const size_t dataSize = ((size_t)(offset >> numOffsetBits) + 1) << 9;
|
||||
offset &= ((UInt64)1 << numOffsetBits) - 1;
|
||||
UInt64 sectorOffset = offset >> 9 << 9;
|
||||
UInt64 offset2inCache = sectorOffset - _comprPos;
|
||||
|
||||
if (sectorOffset >= _comprPos && offset2inCache < _comprSize)
|
||||
{
|
||||
if (offset2inCache != 0)
|
||||
{
|
||||
_comprSize -= (size_t)offset2inCache;
|
||||
memmove(_cacheCompressed, _cacheCompressed + offset2inCache, _comprSize);
|
||||
_comprPos = sectorOffset;
|
||||
}
|
||||
sectorOffset += _comprSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
_comprPos = sectorOffset;
|
||||
_comprSize = 0;
|
||||
}
|
||||
|
||||
// printf("\nDeflate");
|
||||
if (sectorOffset != _posInArc)
|
||||
{
|
||||
// printf("\nDeflate %12I64x %12I64x\n", sectorOffset, sectorOffset - _posInArc);
|
||||
RINOK(Seek(sectorOffset));
|
||||
}
|
||||
|
||||
if (_cacheCompressed.Size() < dataSize)
|
||||
return E_FAIL;
|
||||
size_t dataSize3 = dataSize - _comprSize;
|
||||
size_t dataSize2 = dataSize3;
|
||||
RINOK(ReadStream(Stream, _cacheCompressed + _comprSize, &dataSize2));
|
||||
_posInArc += dataSize2;
|
||||
if (dataSize2 != dataSize3)
|
||||
return E_FAIL;
|
||||
_comprSize += dataSize2;
|
||||
|
||||
const size_t kSectorMask = (1 << 9) - 1;
|
||||
size_t offsetInSector = ((size_t)offset & kSectorMask);
|
||||
_bufInStreamSpec->Init(_cacheCompressed + offsetInSector, dataSize - offsetInSector);
|
||||
|
||||
_cacheCluster = (UInt64)(Int64)-1;
|
||||
if (_cache.Size() < clusterSize)
|
||||
return E_FAIL;
|
||||
_bufOutStreamSpec->Init(_cache, clusterSize);
|
||||
|
||||
// Do we need to use smaller block than clusterSize for last cluster?
|
||||
UInt64 blockSize64 = clusterSize;
|
||||
HRESULT res = _deflateDecoderSpec->Code(_bufInStream, _bufOutStream, NULL, &blockSize64, NULL);
|
||||
|
||||
/*
|
||||
if (_bufOutStreamSpec->GetPos() != clusterSize)
|
||||
memset(_cache + _bufOutStreamSpec->GetPos(), 0, clusterSize - _bufOutStreamSpec->GetPos());
|
||||
*/
|
||||
|
||||
if (res == S_OK)
|
||||
if (!_deflateDecoderSpec->IsFinished()
|
||||
|| _bufOutStreamSpec->GetPos() != clusterSize)
|
||||
res = S_FALSE;
|
||||
|
||||
RINOK(res);
|
||||
_cacheCluster = cluster;
|
||||
|
||||
continue;
|
||||
/*
|
||||
memcpy(data, _cache + lowBits, size);
|
||||
_virtPos += size;
|
||||
if (processedSize)
|
||||
*processedSize = size;
|
||||
return S_OK;
|
||||
*/
|
||||
}
|
||||
|
||||
// version 3 support zero clusters
|
||||
if (((UInt32)v & 511) != 1)
|
||||
{
|
||||
v &= (_compressedFlag - 1);
|
||||
v += lowBits;
|
||||
if (v != _posInArc)
|
||||
{
|
||||
// printf("\n%12I64x\n", v - _posInArc);
|
||||
RINOK(Seek(v));
|
||||
}
|
||||
HRESULT res = Stream->Read(data, size, &size);
|
||||
_posInArc += size;
|
||||
_virtPos += size;
|
||||
if (processedSize)
|
||||
*processedSize = size;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
memset(data, 0, size);
|
||||
_virtPos += size;
|
||||
if (processedSize)
|
||||
*processedSize = size;
|
||||
return S_OK;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static const Byte kProps[] =
|
||||
{
|
||||
kpidSize,
|
||||
kpidPackSize
|
||||
};
|
||||
|
||||
static const Byte kArcProps[] =
|
||||
{
|
||||
kpidClusterSize,
|
||||
kpidUnpackVer,
|
||||
kpidMethod
|
||||
};
|
||||
|
||||
IMP_IInArchive_Props
|
||||
IMP_IInArchive_ArcProps
|
||||
|
||||
STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
NCOM::CPropVariant prop;
|
||||
|
||||
switch (propID)
|
||||
{
|
||||
case kpidMainSubfile: prop = (UInt32)0; break;
|
||||
case kpidClusterSize: prop = (UInt32)1 << _clusterBits; break;
|
||||
case kpidPhySize: if (_phySize != 0) prop = _phySize; break;
|
||||
case kpidUnpackVer: prop = _version; break;
|
||||
|
||||
case kpidMethod:
|
||||
{
|
||||
AString s;
|
||||
|
||||
if (_needDeflate)
|
||||
s = "Deflate";
|
||||
|
||||
if (_cryptMethod != 0)
|
||||
{
|
||||
s.Add_Space_if_NotEmpty();
|
||||
if (_cryptMethod == 1)
|
||||
s += "AES";
|
||||
else
|
||||
{
|
||||
char temp[16];
|
||||
ConvertUInt32ToString(_cryptMethod, temp);
|
||||
s += temp;
|
||||
}
|
||||
}
|
||||
|
||||
if (!s.IsEmpty())
|
||||
prop = s;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case kpidErrorFlags:
|
||||
{
|
||||
UInt32 v = 0;
|
||||
if (!_isArc) v |= kpv_ErrorFlags_IsNotArc;;
|
||||
if (_unsupported) v |= kpv_ErrorFlags_UnsupportedMethod;
|
||||
// if (_headerError) v |= kpv_ErrorFlags_HeadersError;
|
||||
if (!Stream && v == 0 && _isArc)
|
||||
v = kpv_ErrorFlags_HeadersError;
|
||||
if (v != 0)
|
||||
prop = v;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
prop.Detach(value);
|
||||
return S_OK;
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
|
||||
STDMETHODIMP CHandler::GetProperty(UInt32 /* index */, PROPID propID, PROPVARIANT *value)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
NCOM::CPropVariant prop;
|
||||
|
||||
switch (propID)
|
||||
{
|
||||
case kpidSize: prop = _size; break;
|
||||
case kpidPackSize: prop = _phySize; break;
|
||||
case kpidExtension: prop = (_imgExt ? _imgExt : "img"); break;
|
||||
}
|
||||
|
||||
prop.Detach(value);
|
||||
return S_OK;
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
|
||||
HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *openCallback)
|
||||
{
|
||||
const unsigned kHeaderSize = 18 * 4;
|
||||
Byte buf[kHeaderSize];
|
||||
RINOK(ReadStream_FALSE(stream, buf, kHeaderSize));
|
||||
|
||||
if (memcmp(buf, k_Signature, 4) != 0)
|
||||
return S_FALSE;
|
||||
|
||||
_version = Get32(buf + 4);
|
||||
if (_version < 1 || _version > 3)
|
||||
return S_FALSE;
|
||||
|
||||
const UInt64 backOffset = Get64(buf + 8);
|
||||
// UInt32 backSize = Get32(buf + 0x10);
|
||||
|
||||
UInt64 l1Offset = 0;
|
||||
UInt32 l1Size = 0;
|
||||
|
||||
if (_version == 1)
|
||||
{
|
||||
// _mTime = Get32(buf + 0x14); // is unused im most images
|
||||
_size = Get64(buf + 0x18);
|
||||
_clusterBits = buf[0x20];
|
||||
_numMidBits = buf[0x21];
|
||||
if (_clusterBits < 9 || _clusterBits > 30)
|
||||
return S_FALSE;
|
||||
if (_numMidBits < 1 || _numMidBits > 28)
|
||||
return S_FALSE;
|
||||
_cryptMethod = Get32(buf + 0x24);
|
||||
l1Offset = Get64(buf + 0x28);
|
||||
if (l1Offset < 0x30)
|
||||
return S_FALSE;
|
||||
unsigned numBits2 = (_clusterBits + _numMidBits);
|
||||
UInt64 l1Size64 = (_size + (((UInt64)1 << numBits2) - 1)) >> numBits2;
|
||||
if (l1Size64 > ((UInt32)1 << 31))
|
||||
return S_FALSE;
|
||||
l1Size = (UInt32)l1Size64;
|
||||
}
|
||||
else
|
||||
{
|
||||
_clusterBits = Get32(buf + 0x14);
|
||||
if (_clusterBits < 9 || _clusterBits > 30)
|
||||
return S_FALSE;
|
||||
_numMidBits = _clusterBits - 3;
|
||||
_size = Get64(buf + 0x18);
|
||||
_cryptMethod = Get32(buf + 0x20);
|
||||
l1Size = Get32(buf + 0x24);
|
||||
l1Offset = Get64(buf + 0x28); // must be aligned for cluster
|
||||
|
||||
UInt64 refOffset = Get64(buf + 0x30); // must be aligned for cluster
|
||||
UInt32 refClusters = Get32(buf + 0x38);
|
||||
|
||||
// UInt32 numSnapshots = Get32(buf + 0x3C);
|
||||
// UInt64 snapshotsOffset = Get64(buf + 0x40); // must be aligned for cluster
|
||||
/*
|
||||
if (numSnapshots != 0)
|
||||
return S_FALSE;
|
||||
*/
|
||||
|
||||
if (refClusters != 0)
|
||||
{
|
||||
size_t numBytes = refClusters << _clusterBits;
|
||||
/*
|
||||
CByteBuffer refs;
|
||||
refs.Alloc(numBytes);
|
||||
RINOK(stream->Seek(refOffset, STREAM_SEEK_SET, NULL));
|
||||
RINOK(ReadStream_FALSE(stream, refs, numBytes));
|
||||
*/
|
||||
UInt64 end = refOffset + numBytes;
|
||||
if (_phySize < end)
|
||||
_phySize = end;
|
||||
/*
|
||||
for (size_t i = 0; i < numBytes; i += 2)
|
||||
{
|
||||
UInt32 v = GetBe16((const Byte *)refs + (size_t)i);
|
||||
if (v == 0)
|
||||
continue;
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
_isArc = true;
|
||||
|
||||
if (backOffset != 0)
|
||||
{
|
||||
_unsupported = true;
|
||||
return S_FALSE;
|
||||
}
|
||||
|
||||
const size_t clusterSize = (size_t)1 << _clusterBits;
|
||||
|
||||
CByteBuffer table;
|
||||
{
|
||||
size_t t1SizeBytes = (size_t)l1Size << 3;
|
||||
if ((t1SizeBytes >> 3) != l1Size)
|
||||
return S_FALSE;
|
||||
table.Alloc(t1SizeBytes);
|
||||
RINOK(stream->Seek(l1Offset, STREAM_SEEK_SET, NULL));
|
||||
RINOK(ReadStream_FALSE(stream, table, t1SizeBytes));
|
||||
|
||||
{
|
||||
UInt64 end = l1Offset + t1SizeBytes;
|
||||
// we need to uses align end for empty qcow files
|
||||
end = (end + clusterSize - 1) >> _clusterBits << _clusterBits;
|
||||
if (_phySize < end)
|
||||
_phySize = end;
|
||||
}
|
||||
}
|
||||
|
||||
if (openCallback)
|
||||
{
|
||||
UInt64 totalBytes = (UInt64)l1Size << (_numMidBits + 3);
|
||||
RINOK(openCallback->SetTotal(NULL, &totalBytes));
|
||||
}
|
||||
|
||||
_compressedFlag = (_version <= 1) ? ((UInt64)1 << 63) : ((UInt64)1 << 62);
|
||||
const UInt64 offsetMask = _compressedFlag - 1;
|
||||
|
||||
for (UInt32 i = 0; i < l1Size; i++)
|
||||
{
|
||||
if (openCallback)
|
||||
{
|
||||
UInt64 numBytes = (UInt64)i << (_numMidBits + 3);
|
||||
RINOK(openCallback->SetCompleted(NULL, &numBytes));
|
||||
}
|
||||
|
||||
UInt64 v = Get64((const Byte *)table + (size_t)i * 8);
|
||||
v &= offsetMask;
|
||||
CByteBuffer &buf = _tables.AddNew();
|
||||
if (v == 0)
|
||||
continue;
|
||||
|
||||
buf.Alloc((size_t)1 << (_numMidBits + 3));
|
||||
RINOK(stream->Seek(v, STREAM_SEEK_SET, NULL));
|
||||
RINOK(ReadStream_FALSE(stream, buf, clusterSize));
|
||||
UInt64 end = v + clusterSize;
|
||||
if (_phySize < end)
|
||||
_phySize = end;
|
||||
|
||||
for (size_t k = 0; k < clusterSize; k += 8)
|
||||
{
|
||||
UInt64 v = Get64((const Byte *)buf + (size_t)k);
|
||||
if (v == 0)
|
||||
continue;
|
||||
UInt64 offset = v & offsetMask;
|
||||
size_t dataSize = clusterSize;
|
||||
|
||||
if ((v & _compressedFlag) != 0)
|
||||
{
|
||||
if (_version <= 1)
|
||||
{
|
||||
unsigned numOffsetBits = (63 - _clusterBits);
|
||||
dataSize = ((size_t)(offset >> numOffsetBits) + 1) << 9;
|
||||
offset &= ((UInt64)1 << numOffsetBits) - 1;
|
||||
dataSize = 0;
|
||||
// offset >>= 9;
|
||||
// offset <<= 9;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned numOffsetBits = (62 - (_clusterBits - 8));
|
||||
dataSize = ((size_t)(offset >> numOffsetBits) + 1) << 9;
|
||||
offset &= ((UInt64)1 << numOffsetBits) - 1;
|
||||
offset >>= 9;
|
||||
offset <<= 9;
|
||||
}
|
||||
_needDeflate = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
UInt32 low = (UInt32)v & 511;
|
||||
if (low != 0)
|
||||
{
|
||||
// version 3 support zero clusters
|
||||
if (_version < 3 || low != 1)
|
||||
{
|
||||
_unsupported = true;
|
||||
return S_FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UInt64 end = offset + dataSize;
|
||||
if (_phySize < end)
|
||||
_phySize = end;
|
||||
}
|
||||
}
|
||||
|
||||
if (_cryptMethod != 0)
|
||||
_unsupported = true;
|
||||
|
||||
if (_needDeflate && _version <= 1) // that case was not implemented
|
||||
_unsupported = true;
|
||||
|
||||
Stream = stream;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
STDMETHODIMP CHandler::Close()
|
||||
{
|
||||
_tables.Clear();
|
||||
_phySize = 0;
|
||||
_size = 0;
|
||||
|
||||
_cacheCluster = (UInt64)(Int64)-1;
|
||||
_comprPos = 0;
|
||||
_comprSize = 0;
|
||||
_needDeflate = false;
|
||||
|
||||
_isArc = false;
|
||||
_unsupported = false;
|
||||
|
||||
_imgExt = NULL;
|
||||
Stream.Release();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
STDMETHODIMP CHandler::GetStream(UInt32 /* index */, ISequentialInStream **stream)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
*stream = NULL;
|
||||
|
||||
if (_unsupported)
|
||||
return S_FALSE;
|
||||
|
||||
if (_needDeflate)
|
||||
{
|
||||
if (_version <= 1)
|
||||
return S_FALSE;
|
||||
|
||||
if (!_bufInStream)
|
||||
{
|
||||
_bufInStreamSpec = new CBufInStream;
|
||||
_bufInStream = _bufInStreamSpec;
|
||||
}
|
||||
|
||||
if (!_bufOutStream)
|
||||
{
|
||||
_bufOutStreamSpec = new CBufPtrSeqOutStream();
|
||||
_bufOutStream = _bufOutStreamSpec;
|
||||
}
|
||||
|
||||
if (!_deflateDecoder)
|
||||
{
|
||||
_deflateDecoderSpec = new NCompress::NDeflate::NDecoder::CCOMCoder();
|
||||
_deflateDecoder = _deflateDecoderSpec;
|
||||
_deflateDecoderSpec->Set_NeedFinishInput(true);
|
||||
}
|
||||
|
||||
size_t clusterSize = (size_t)1 << _clusterBits;
|
||||
_cache.AllocAtLeast(clusterSize);
|
||||
_cacheCompressed.AllocAtLeast(clusterSize * 2);
|
||||
}
|
||||
|
||||
CMyComPtr<ISequentialInStream> streamTemp = this;
|
||||
RINOK(InitAndSeek());
|
||||
*stream = streamTemp.Detach();
|
||||
return S_OK;
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
|
||||
REGISTER_ARC_I(
|
||||
"QCOW", "qcow qcow2 qcow2c", NULL, 0xCA,
|
||||
k_Signature,
|
||||
0,
|
||||
0,
|
||||
NULL)
|
||||
|
||||
}}
|
||||
2706
CPP/7zip/Archive/Rar/Rar5Handler.cpp
Normal file
2706
CPP/7zip/Archive/Rar/Rar5Handler.cpp
Normal file
File diff suppressed because it is too large
Load Diff
411
CPP/7zip/Archive/Rar/Rar5Handler.h
Normal file
411
CPP/7zip/Archive/Rar/Rar5Handler.h
Normal file
@@ -0,0 +1,411 @@
|
||||
// Rar5Handler.h
|
||||
|
||||
#ifndef __RAR5_HANDLER_H
|
||||
#define __RAR5_HANDLER_H
|
||||
|
||||
#include "../../../../C/Blake2.h"
|
||||
|
||||
#include "../../../Common/MyBuffer.h"
|
||||
|
||||
#include "../../../Windows/PropVariant.h"
|
||||
|
||||
#include "../../Common/CreateCoder.h"
|
||||
|
||||
#include "../IArchive.h"
|
||||
|
||||
namespace NArchive {
|
||||
namespace NRar5 {
|
||||
|
||||
namespace NHeaderFlags
|
||||
{
|
||||
const unsigned kExtra = 1 << 0;
|
||||
const unsigned kData = 1 << 1;
|
||||
// const unsigned kUnknown = 1 << 2;
|
||||
const unsigned kPrevVol = 1 << 3;
|
||||
const unsigned kNextVol = 1 << 4;
|
||||
// const unsigned kIsChild = 1 << 5;
|
||||
// const unsigned kPreserveChild = 1 << 6;
|
||||
}
|
||||
|
||||
namespace NHeaderType
|
||||
{
|
||||
enum
|
||||
{
|
||||
kArc = 1,
|
||||
kFile,
|
||||
kService,
|
||||
kArcEncrypt,
|
||||
kEndOfArc
|
||||
};
|
||||
}
|
||||
|
||||
namespace NArcFlags
|
||||
{
|
||||
const unsigned kVol = 1 << 0;
|
||||
const unsigned kVolNumber = 1 << 1;
|
||||
const unsigned kSolid = 1 << 2;
|
||||
// const unsigned kRecovery = 1 << 3;
|
||||
// const unsigned kLocked = 1 << 4;
|
||||
}
|
||||
|
||||
const unsigned kArcExtraRecordType_Locator = 1;
|
||||
|
||||
namespace NLocatorFlags
|
||||
{
|
||||
const unsigned kQuickOpen = 1 << 0;
|
||||
const unsigned kRecovery = 1 << 1;
|
||||
}
|
||||
|
||||
namespace NFileFlags
|
||||
{
|
||||
const unsigned kIsDir = 1 << 0;
|
||||
const unsigned kUnixTime = 1 << 1;
|
||||
const unsigned kCrc32 = 1 << 2;
|
||||
const unsigned kUnknownSize = 1 << 3;
|
||||
}
|
||||
|
||||
namespace NMethodFlags
|
||||
{
|
||||
// const unsigned kVersionMask = 0x3F;
|
||||
const unsigned kSolid = 1 << 6;
|
||||
}
|
||||
|
||||
namespace NArcEndFlags
|
||||
{
|
||||
const unsigned kMoreVols = 1 << 0;
|
||||
}
|
||||
|
||||
enum EHostOS
|
||||
{
|
||||
kHost_Windows = 0,
|
||||
kHost_Unix
|
||||
};
|
||||
|
||||
|
||||
|
||||
// ---------- Extra ----------
|
||||
|
||||
namespace NExtraRecordType
|
||||
{
|
||||
enum
|
||||
{
|
||||
kCrypto = 1,
|
||||
kHash,
|
||||
kTime,
|
||||
kVersion,
|
||||
kLink,
|
||||
kUnixOwner,
|
||||
kSubdata
|
||||
};
|
||||
}
|
||||
|
||||
// const unsigned kCryptoAlgo_AES = 0;
|
||||
|
||||
namespace NCryptoFlags
|
||||
{
|
||||
const unsigned kPswCheck = 1 << 0;
|
||||
const unsigned kUseMAC = 1 << 1;
|
||||
}
|
||||
|
||||
struct CCryptoInfo
|
||||
{
|
||||
UInt64 Algo;
|
||||
UInt64 Flags;
|
||||
Byte Cnt;
|
||||
|
||||
bool UseMAC() const { return (Flags & NCryptoFlags::kUseMAC) != 0; }
|
||||
bool IsThereCheck() const { return (Flags & NCryptoFlags::kPswCheck) != 0; }
|
||||
bool Parse(const Byte *p, size_t size);
|
||||
};
|
||||
|
||||
const unsigned kHashID_Blake2sp = 0;
|
||||
|
||||
namespace NTimeRecord
|
||||
{
|
||||
enum
|
||||
{
|
||||
k_Index_MTime = 0,
|
||||
k_Index_CTime,
|
||||
k_Index_ATime
|
||||
};
|
||||
|
||||
namespace NFlags
|
||||
{
|
||||
const unsigned kUnixTime = 1 << 0;
|
||||
const unsigned kMTime = 1 << 1;
|
||||
// const unsigned kCTime = 1 << 2;
|
||||
// const unsigned kATime = 1 << 3;
|
||||
}
|
||||
}
|
||||
|
||||
namespace NLinkType
|
||||
{
|
||||
enum
|
||||
{
|
||||
kUnixSymLink = 1,
|
||||
kWinSymLink,
|
||||
kWinJunction,
|
||||
kHardLink,
|
||||
kFileCopy
|
||||
};
|
||||
}
|
||||
|
||||
namespace NLinkFlags
|
||||
{
|
||||
const unsigned kTargetIsDir = 1 << 0;
|
||||
}
|
||||
|
||||
|
||||
struct CItem
|
||||
{
|
||||
UInt32 CommonFlags;
|
||||
UInt32 Flags;
|
||||
|
||||
Byte RecordType;
|
||||
bool Version_Defined;
|
||||
|
||||
int ACL;
|
||||
|
||||
AString Name;
|
||||
|
||||
int VolIndex;
|
||||
int NextItem;
|
||||
|
||||
UInt32 UnixMTime;
|
||||
UInt32 CRC;
|
||||
UInt32 Attrib;
|
||||
UInt32 Method;
|
||||
|
||||
CByteBuffer Extra;
|
||||
|
||||
UInt64 Size;
|
||||
UInt64 PackSize;
|
||||
UInt64 HostOS;
|
||||
|
||||
UInt64 DataPos;
|
||||
UInt64 Version;
|
||||
|
||||
CItem() { Clear(); }
|
||||
|
||||
void Clear()
|
||||
{
|
||||
CommonFlags = 0;
|
||||
Flags = 0;
|
||||
|
||||
VolIndex = 0;
|
||||
NextItem = -1;
|
||||
|
||||
Version_Defined = false;
|
||||
Version = 0;
|
||||
|
||||
Name.Empty();
|
||||
Extra.Free();
|
||||
ACL = -1;
|
||||
}
|
||||
|
||||
bool IsSplitBefore() const { return (CommonFlags & NHeaderFlags::kPrevVol) != 0; }
|
||||
bool IsSplitAfter() const { return (CommonFlags & NHeaderFlags::kNextVol) != 0; }
|
||||
bool IsSplit() const { return (CommonFlags & (NHeaderFlags::kPrevVol | NHeaderFlags::kNextVol)) != 0; }
|
||||
|
||||
bool IsDir() const { return (Flags & NFileFlags::kIsDir) != 0; }
|
||||
bool Has_UnixMTime() const { return (Flags & NFileFlags::kUnixTime) != 0; }
|
||||
bool Has_CRC() const { return (Flags & NFileFlags::kCrc32) != 0; }
|
||||
bool Is_UnknownSize() const { return (Flags & NFileFlags::kUnknownSize) != 0; }
|
||||
|
||||
bool IsNextForItem(const CItem &prev) const
|
||||
{
|
||||
return !IsDir() && !prev.IsDir() && IsSplitBefore() && prev.IsSplitAfter() && (Name == prev.Name);
|
||||
// && false;
|
||||
}
|
||||
|
||||
bool IsSolid() const { return ((UInt32)Method & NMethodFlags::kSolid) != 0; }
|
||||
unsigned GetAlgoVersion() const { return (unsigned)Method & 0x3F; }
|
||||
unsigned GetMethod() const { return ((unsigned)Method >> 7) & 0x7; }
|
||||
UInt32 GetDictSize() const { return (((UInt32)Method >> 10) & 0xF); }
|
||||
|
||||
bool IsService() const { return RecordType == NHeaderType::kService; }
|
||||
|
||||
bool Is_STM() const { return IsService() && Name == "STM"; }
|
||||
bool Is_CMT() const { return IsService() && Name == "CMT"; }
|
||||
bool Is_ACL() const { return IsService() && Name == "ACL"; }
|
||||
// bool Is_QO() const { return IsService() && Name == "QO"; }
|
||||
|
||||
int FindExtra(unsigned type, unsigned &recordDataSize) const;
|
||||
|
||||
bool IsEncrypted() const
|
||||
{
|
||||
unsigned size;
|
||||
return FindExtra(NExtraRecordType::kCrypto, size) >= 0;
|
||||
}
|
||||
|
||||
int FindExtra_Blake() const
|
||||
{
|
||||
unsigned size = 0;
|
||||
int offset = FindExtra(NExtraRecordType::kHash, size);
|
||||
if (offset >= 0
|
||||
&& size == BLAKE2S_DIGEST_SIZE + 1
|
||||
&& Extra[(unsigned)offset] == kHashID_Blake2sp)
|
||||
return offset + 1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool FindExtra_Version(UInt64 &version) const;
|
||||
|
||||
struct CLinkInfo
|
||||
{
|
||||
UInt64 Type;
|
||||
UInt64 Flags;
|
||||
unsigned NameOffset;
|
||||
unsigned NameLen;
|
||||
};
|
||||
|
||||
bool FindExtra_Link(CLinkInfo &link) const;
|
||||
void Link_to_Prop(unsigned linkType, NWindows::NCOM::CPropVariant &prop) const;
|
||||
bool Is_CopyLink() const;
|
||||
|
||||
bool NeedUse_as_CopyLink() const { return PackSize == 0 && Is_CopyLink(); }
|
||||
|
||||
bool GetAltStreamName(AString &name) const;
|
||||
|
||||
UInt32 GetWinAttrib() const
|
||||
{
|
||||
UInt32 a;
|
||||
switch (HostOS)
|
||||
{
|
||||
case kHost_Windows: a = Attrib; break;
|
||||
case kHost_Unix: a = (Attrib << 16); break;
|
||||
default: a = 0;
|
||||
}
|
||||
// if (IsDir()) a |= FILE_ATTRIBUTE_DIRECTORY;
|
||||
return a;
|
||||
}
|
||||
|
||||
UInt64 GetDataPosition() const { return DataPos; }
|
||||
};
|
||||
|
||||
|
||||
struct CInArcInfo
|
||||
{
|
||||
UInt64 Flags;
|
||||
UInt64 VolNumber;
|
||||
UInt64 StartPos;
|
||||
UInt64 EndPos;
|
||||
|
||||
UInt64 EndFlags;
|
||||
bool EndOfArchive_was_Read;
|
||||
|
||||
bool IsEncrypted;
|
||||
|
||||
// CByteBuffer Extra;
|
||||
|
||||
/*
|
||||
struct CLocator
|
||||
{
|
||||
UInt64 Flags;
|
||||
UInt64 QuickOpen;
|
||||
UInt64 Recovery;
|
||||
|
||||
bool Is_QuickOpen() const { return (Flags & NLocatorFlags::kQuickOpen) != 0; }
|
||||
bool Is_Recovery() const { return (Flags & NLocatorFlags::kRecovery) != 0; }
|
||||
};
|
||||
|
||||
int FindExtra(unsigned type, unsigned &recordDataSize) const;
|
||||
bool FindExtra_Locator(CLocator &locator) const;
|
||||
*/
|
||||
|
||||
CInArcInfo():
|
||||
Flags(0),
|
||||
VolNumber(0),
|
||||
StartPos(0),
|
||||
EndPos(0),
|
||||
EndFlags(0),
|
||||
EndOfArchive_was_Read(false),
|
||||
IsEncrypted(false)
|
||||
{}
|
||||
|
||||
/*
|
||||
void Clear()
|
||||
{
|
||||
Flags = 0;
|
||||
VolNumber = 0;
|
||||
StartPos = 0;
|
||||
EndPos = 0;
|
||||
EndFlags = 0;
|
||||
EndOfArchive_was_Read = false;
|
||||
Extra.Free();
|
||||
}
|
||||
*/
|
||||
|
||||
UInt64 GetPhySize() const { return EndPos - StartPos; }
|
||||
|
||||
bool AreMoreVolumes() const { return (EndFlags & NArcEndFlags::kMoreVols) != 0; }
|
||||
|
||||
bool IsVolume() const { return (Flags & NArcFlags::kVol) != 0; }
|
||||
bool IsSolid() const { return (Flags & NArcFlags::kSolid) != 0; }
|
||||
bool Is_VolNumber_Defined() const { return (Flags & NArcFlags::kVolNumber) != 0; }
|
||||
|
||||
UInt64 GetVolIndex() const { return Is_VolNumber_Defined() ? VolNumber : 0; }
|
||||
};
|
||||
|
||||
|
||||
struct CRefItem
|
||||
{
|
||||
unsigned Item;
|
||||
unsigned Last;
|
||||
int Parent;
|
||||
int Link;
|
||||
};
|
||||
|
||||
|
||||
struct CArc
|
||||
{
|
||||
CMyComPtr<IInStream> Stream;
|
||||
CInArcInfo Info;
|
||||
};
|
||||
|
||||
|
||||
class CHandler:
|
||||
public IInArchive,
|
||||
public IArchiveGetRawProps,
|
||||
PUBLIC_ISetCompressCodecsInfo
|
||||
public CMyUnknownImp
|
||||
{
|
||||
public:
|
||||
CRecordVector<CRefItem> _refs;
|
||||
CObjectVector<CItem> _items;
|
||||
private:
|
||||
CObjectVector<CArc> _arcs;
|
||||
CObjectVector<CByteBuffer> _acls;
|
||||
|
||||
UInt32 _errorFlags;
|
||||
// UInt32 _warningFlags;
|
||||
bool _isArc;
|
||||
CByteBuffer _comment;
|
||||
UString _missingVolName;
|
||||
|
||||
DECL_EXTERNAL_CODECS_VARS
|
||||
|
||||
UInt64 GetPackSize(unsigned refIndex) const;
|
||||
|
||||
void FillLinks();
|
||||
|
||||
HRESULT Open2(IInStream *stream,
|
||||
const UInt64 *maxCheckStartPosition,
|
||||
IArchiveOpenCallback *openCallback);
|
||||
|
||||
public:
|
||||
MY_QUERYINTERFACE_BEGIN2(IInArchive)
|
||||
MY_QUERYINTERFACE_ENTRY(IArchiveGetRawProps)
|
||||
QUERY_ENTRY_ISetCompressCodecsInfo
|
||||
MY_QUERYINTERFACE_END
|
||||
MY_ADDREF_RELEASE
|
||||
|
||||
INTERFACE_IInArchive(;)
|
||||
INTERFACE_IArchiveGetRawProps(;)
|
||||
|
||||
DECL_ISetCompressCodecsInfo
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
@@ -30,6 +30,9 @@
|
||||
#include "../Common/ItemNameUtils.h"
|
||||
#include "../Common/OutStreamWithCRC.h"
|
||||
|
||||
#include "../HandlerCont.h"
|
||||
|
||||
#include "RarVol.h"
|
||||
#include "RarHandler.h"
|
||||
|
||||
using namespace NWindows;
|
||||
@@ -44,6 +47,8 @@ namespace NRar {
|
||||
|
||||
static const Byte kMarker[NHeader::kMarkerSize] = SIGNATURE;
|
||||
|
||||
const unsigned kPasswordLen_MAX = 127;
|
||||
|
||||
bool CItem::IgnoreItem() const
|
||||
{
|
||||
switch (HostOS)
|
||||
@@ -131,7 +136,7 @@ class CInArchive
|
||||
CByteBuffer _comment;
|
||||
CByteBuffer m_FileHeaderData;
|
||||
NHeader::NBlock::CBlock m_BlockHeader;
|
||||
NCrypto::NRar29::CDecoder *m_RarAESSpec;
|
||||
NCrypto::NRar3::CDecoder *m_RarAESSpec;
|
||||
CMyComPtr<ICompressFilter> m_RarAES;
|
||||
CBuffer<Byte> m_DecryptedData;
|
||||
Byte *m_DecryptedDataAligned;
|
||||
@@ -362,6 +367,7 @@ static int ReadTime(const Byte *p, unsigned size, Byte mask, CRarTime &rarTime)
|
||||
_ttt_ .DosTime = Get32(p); p += 4; size -= 4; \
|
||||
READ_TIME(_mask_, _ttt_); } \
|
||||
|
||||
|
||||
bool CInArchive::ReadHeaderReal(const Byte *p, unsigned size, CItem &item)
|
||||
{
|
||||
const Byte *pStart = p;
|
||||
@@ -500,7 +506,7 @@ HRESULT CInArchive::GetNextItem(CItem &item, ICryptoGetTextPassword *getTextPass
|
||||
}
|
||||
if (!m_RarAES)
|
||||
{
|
||||
m_RarAESSpec = new NCrypto::NRar29::CDecoder;
|
||||
m_RarAESSpec = new NCrypto::NRar3::CDecoder;
|
||||
m_RarAES = m_RarAESSpec;
|
||||
}
|
||||
m_RarAESSpec->SetRar350Mode(ArcInfo.IsEncryptOld());
|
||||
@@ -518,7 +524,10 @@ HRESULT CInArchive::GetNextItem(CItem &item, ICryptoGetTextPassword *getTextPass
|
||||
unsigned len = 0;
|
||||
if (password)
|
||||
len = MyStringLen(password);
|
||||
CByteBuffer buffer(len * 2);
|
||||
if (len > kPasswordLen_MAX)
|
||||
len = kPasswordLen_MAX;
|
||||
|
||||
CByteArr buffer(len * 2);
|
||||
for (unsigned i = 0; i < len; i++)
|
||||
{
|
||||
wchar_t c = password[i];
|
||||
@@ -526,7 +535,7 @@ HRESULT CInArchive::GetNextItem(CItem &item, ICryptoGetTextPassword *getTextPass
|
||||
((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8);
|
||||
}
|
||||
|
||||
RINOK(m_RarAESSpec->CryptoSetPassword((const Byte *)buffer, (UInt32)buffer.Size()));
|
||||
m_RarAESSpec->SetPassword((const Byte *)buffer, len * 2);
|
||||
|
||||
const UInt32 kDecryptedBufferSize = (1 << 12);
|
||||
if (m_DecryptedData.Size() == 0)
|
||||
@@ -631,6 +640,7 @@ HRESULT CInArchive::GetNextItem(CItem &item, ICryptoGetTextPassword *getTextPass
|
||||
{
|
||||
ArcInfo.EndFlags = m_BlockHeader.Flags;
|
||||
UInt32 offset = 7;
|
||||
|
||||
if (m_BlockHeader.Flags & NHeader::NArchive::kEndOfArc_Flags_DataCRC)
|
||||
{
|
||||
if (processed < offset + 4)
|
||||
@@ -639,6 +649,7 @@ HRESULT CInArchive::GetNextItem(CItem &item, ICryptoGetTextPassword *getTextPass
|
||||
ArcInfo.DataCRC = Get32(m_FileHeaderData + offset);
|
||||
offset += 4;
|
||||
}
|
||||
|
||||
if (m_BlockHeader.Flags & NHeader::NArchive::kEndOfArc_Flags_VolNumber)
|
||||
{
|
||||
if (processed < offset + 2)
|
||||
@@ -648,6 +659,7 @@ HRESULT CInArchive::GetNextItem(CItem &item, ICryptoGetTextPassword *getTextPass
|
||||
|
||||
ArcInfo.EndOfArchive_was_Read = true;
|
||||
}
|
||||
|
||||
m_Position += processed;
|
||||
FinishCryptoBlock();
|
||||
ArcInfo.EndPos = m_Position;
|
||||
@@ -690,11 +702,13 @@ HRESULT CInArchive::GetNextItem(CItem &item, ICryptoGetTextPassword *getTextPass
|
||||
continue;
|
||||
*/
|
||||
}
|
||||
|
||||
if (m_CryptoMode && m_BlockHeader.HeadSize > (1 << 10))
|
||||
{
|
||||
error = k_ErrorType_DecryptionError;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
if ((m_BlockHeader.Flags & NHeader::NBlock::kLongBlock) != 0)
|
||||
{
|
||||
if (m_FileHeaderData.Size() < 7 + 4)
|
||||
@@ -846,7 +860,20 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
|
||||
break;
|
||||
}
|
||||
|
||||
// case kpidError: if (!_errorMessage.IsEmpty()) prop = _errorMessage; break;
|
||||
|
||||
case kpidError:
|
||||
{
|
||||
// if (!_errorMessage.IsEmpty()) prop = _errorMessage; break;
|
||||
|
||||
if (/* &_missingVol || */ !_missingVolName.IsEmpty())
|
||||
{
|
||||
UString s;
|
||||
s.SetFromAscii("Missing volume : ");
|
||||
s += _missingVolName;
|
||||
prop = s;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case kpidErrorFlags:
|
||||
{
|
||||
@@ -931,7 +958,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
if (item.BaseFileIndex >= 0)
|
||||
mainItem = &_items[_refItems[item.BaseFileIndex].ItemIndex];
|
||||
*/
|
||||
switch(propID)
|
||||
switch (propID)
|
||||
{
|
||||
case kpidPath:
|
||||
{
|
||||
@@ -990,144 +1017,6 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
static bool IsDigit(wchar_t c)
|
||||
{
|
||||
return c >= L'0' && c <= L'9';
|
||||
}
|
||||
|
||||
class CVolumeName
|
||||
{
|
||||
bool _first;
|
||||
bool _newStyle;
|
||||
UString _unchangedPart;
|
||||
UString _changedPart;
|
||||
UString _afterPart;
|
||||
public:
|
||||
CVolumeName(): _newStyle(true) {};
|
||||
|
||||
bool InitName(const UString &name, bool newStyle)
|
||||
{
|
||||
_first = true;
|
||||
_newStyle = newStyle;
|
||||
int dotPos = name.ReverseFind_Dot();
|
||||
UString basePart = name;
|
||||
|
||||
if (dotPos >= 0)
|
||||
{
|
||||
UString ext = name.Ptr(dotPos + 1);
|
||||
if (ext.IsEqualTo_Ascii_NoCase("rar"))
|
||||
{
|
||||
_afterPart = name.Ptr(dotPos);
|
||||
basePart = name.Left(dotPos);
|
||||
}
|
||||
else if (ext.IsEqualTo_Ascii_NoCase("exe"))
|
||||
{
|
||||
_afterPart.SetFromAscii(".rar");
|
||||
basePart = name.Left(dotPos);
|
||||
}
|
||||
else if (!_newStyle)
|
||||
{
|
||||
if (ext.IsEqualTo_Ascii_NoCase("000") ||
|
||||
ext.IsEqualTo_Ascii_NoCase("001") ||
|
||||
ext.IsEqualTo_Ascii_NoCase("r00") ||
|
||||
ext.IsEqualTo_Ascii_NoCase("r01"))
|
||||
{
|
||||
_afterPart.Empty();
|
||||
_first = false;
|
||||
_changedPart = ext;
|
||||
_unchangedPart = name.Left(dotPos + 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!_newStyle)
|
||||
{
|
||||
_afterPart.Empty();
|
||||
_unchangedPart = basePart;
|
||||
_unchangedPart += L'.';
|
||||
_changedPart.SetFromAscii("r00");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (basePart.IsEmpty())
|
||||
return false;
|
||||
unsigned i = basePart.Len();
|
||||
|
||||
do
|
||||
if (!IsDigit(basePart[i - 1]))
|
||||
break;
|
||||
while (--i);
|
||||
|
||||
_unchangedPart = basePart.Left(i);
|
||||
_changedPart = basePart.Ptr(i);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
void MakeBeforeFirstName()
|
||||
{
|
||||
unsigned len = _changedPart.Len();
|
||||
_changedPart.Empty();
|
||||
for (unsigned i = 0; i < len; i++)
|
||||
_changedPart += L'0';
|
||||
}
|
||||
*/
|
||||
|
||||
UString GetNextName()
|
||||
{
|
||||
if (_newStyle || !_first)
|
||||
{
|
||||
unsigned i = _changedPart.Len();
|
||||
for (;;)
|
||||
{
|
||||
wchar_t c = _changedPart[--i];
|
||||
if (c == L'9')
|
||||
{
|
||||
c = L'0';
|
||||
_changedPart.ReplaceOneCharAtPos(i, c);
|
||||
if (i == 0)
|
||||
{
|
||||
_changedPart.InsertAtFront(L'1');
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
c++;
|
||||
_changedPart.ReplaceOneCharAtPos(i, c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_first = false;
|
||||
return _unchangedPart + _changedPart + _afterPart;
|
||||
}
|
||||
};
|
||||
|
||||
static HRESULT ReadZeroTail(ISequentialInStream *stream, bool &areThereNonZeros, UInt64 &numZeros, UInt64 maxSize)
|
||||
{
|
||||
areThereNonZeros = false;
|
||||
numZeros = 0;
|
||||
const size_t kBufSize = 1 << 9;
|
||||
Byte buf[kBufSize];
|
||||
for (;;)
|
||||
{
|
||||
UInt32 size = 0;
|
||||
HRESULT(stream->Read(buf, kBufSize, &size));
|
||||
if (size == 0)
|
||||
return S_OK;
|
||||
for (UInt32 i = 0; i < size; i++)
|
||||
if (buf[i] != 0)
|
||||
{
|
||||
areThereNonZeros = true;
|
||||
numZeros += i;
|
||||
return S_OK;
|
||||
}
|
||||
numZeros += size;
|
||||
if (numZeros > maxSize)
|
||||
return S_OK;
|
||||
}
|
||||
}
|
||||
|
||||
HRESULT CHandler::Open2(IInStream *stream,
|
||||
const UInt64 *maxCheckStartPosition,
|
||||
@@ -1136,7 +1025,6 @@ HRESULT CHandler::Open2(IInStream *stream,
|
||||
{
|
||||
CMyComPtr<IArchiveOpenVolumeCallback> openVolumeCallback;
|
||||
CMyComPtr<ICryptoGetTextPassword> getTextPassword;
|
||||
CMyComPtr<IArchiveOpenCallback> openArchiveCallbackWrap = openCallback;
|
||||
|
||||
CVolumeName seqName;
|
||||
|
||||
@@ -1145,11 +1033,14 @@ HRESULT CHandler::Open2(IInStream *stream,
|
||||
|
||||
if (openCallback)
|
||||
{
|
||||
openArchiveCallbackWrap.QueryInterface(IID_IArchiveOpenVolumeCallback, &openVolumeCallback);
|
||||
openArchiveCallbackWrap.QueryInterface(IID_ICryptoGetTextPassword, &getTextPassword);
|
||||
openCallback->QueryInterface(IID_IArchiveOpenVolumeCallback, (void **)&openVolumeCallback);
|
||||
openCallback->QueryInterface(IID_ICryptoGetTextPassword, (void **)&getTextPassword);
|
||||
}
|
||||
|
||||
bool nextVol_is_Required = false;
|
||||
|
||||
CInArchive archive;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
CMyComPtr<IInStream> inStream;
|
||||
@@ -1180,14 +1071,19 @@ HRESULT CHandler::Open2(IInStream *stream,
|
||||
*/
|
||||
}
|
||||
|
||||
UString fullName = seqName.GetNextName();
|
||||
HRESULT result = openVolumeCallback->GetStream(fullName, &inStream);
|
||||
if (result == S_FALSE)
|
||||
break;
|
||||
if (result != S_OK)
|
||||
const UString volName = seqName.GetNextName();
|
||||
|
||||
HRESULT result = openVolumeCallback->GetStream(volName, &inStream);
|
||||
|
||||
if (result != S_OK && result != S_FALSE)
|
||||
return result;
|
||||
if (!inStream)
|
||||
|
||||
if (!inStream || result != S_OK)
|
||||
{
|
||||
if (nextVol_is_Required)
|
||||
_missingVolName = volName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
inStream = stream;
|
||||
@@ -1304,6 +1200,18 @@ HRESULT CHandler::Open2(IInStream *stream,
|
||||
arc.PhySize = archive.ArcInfo.GetPhySize();
|
||||
arc.Stream = inStream;
|
||||
}
|
||||
|
||||
nextVol_is_Required = false;
|
||||
|
||||
if (!archive.ArcInfo.IsVolume())
|
||||
break;
|
||||
|
||||
if (archive.ArcInfo.EndOfArchive_was_Read)
|
||||
{
|
||||
if (!archive.ArcInfo.AreMoreVolumes())
|
||||
break;
|
||||
nextVol_is_Required = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1346,6 +1254,7 @@ STDMETHODIMP CHandler::Close()
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
// _errorMessage.Empty();
|
||||
_missingVolName.Empty();
|
||||
_errorFlags = 0;
|
||||
_warningFlags = 0;
|
||||
_isArc = false;
|
||||
@@ -1363,108 +1272,91 @@ struct CMethodItem
|
||||
};
|
||||
|
||||
|
||||
class CFolderInStream:
|
||||
class CVolsInStream:
|
||||
public ISequentialInStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
UInt64 _rem;
|
||||
ISequentialInStream *_stream;
|
||||
const CObjectVector<CArc> *_arcs;
|
||||
const CObjectVector<CItem> *_items;
|
||||
CRefItem _refItem;
|
||||
unsigned _curIndex;
|
||||
UInt32 _crc;
|
||||
bool _calcCrc;
|
||||
|
||||
public:
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
|
||||
|
||||
private:
|
||||
const CObjectVector<CArc> *_archives;
|
||||
const CObjectVector<CItem> *_items;
|
||||
CRefItem _refItem;
|
||||
unsigned _curIndex;
|
||||
UInt32 _crc;
|
||||
bool _fileIsOpen;
|
||||
CMyComPtr<ISequentialInStream> _stream;
|
||||
|
||||
HRESULT OpenStream();
|
||||
HRESULT CloseStream();
|
||||
public:
|
||||
void Init(const CObjectVector<CArc> *archives,
|
||||
void Init(const CObjectVector<CArc> *arcs,
|
||||
const CObjectVector<CItem> *items,
|
||||
const CRefItem &refItem);
|
||||
const CRefItem &refItem)
|
||||
{
|
||||
_arcs = arcs;
|
||||
_items = items;
|
||||
_refItem = refItem;
|
||||
_curIndex = 0;
|
||||
_stream = NULL;
|
||||
CrcIsOK = true;
|
||||
}
|
||||
|
||||
CRecordVector<UInt32> CRCs;
|
||||
bool CrcIsOK;
|
||||
};
|
||||
|
||||
|
||||
ISequentialInStream* CArc::CreateLimitedStream(UInt64 offset, UInt64 size) const
|
||||
{
|
||||
CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
|
||||
CMyComPtr<ISequentialInStream> inStream(streamSpec);
|
||||
Stream->Seek(offset, STREAM_SEEK_SET, NULL);
|
||||
streamSpec->SetStream(Stream);
|
||||
streamSpec->Init(size);
|
||||
return inStream.Detach();
|
||||
}
|
||||
|
||||
void CFolderInStream::Init(
|
||||
const CObjectVector<CArc> *archives,
|
||||
const CObjectVector<CItem> *items,
|
||||
const CRefItem &refItem)
|
||||
{
|
||||
_archives = archives;
|
||||
_items = items;
|
||||
_refItem = refItem;
|
||||
_curIndex = 0;
|
||||
CRCs.Clear();
|
||||
_fileIsOpen = false;
|
||||
}
|
||||
|
||||
HRESULT CFolderInStream::OpenStream()
|
||||
{
|
||||
while (_curIndex < _refItem.NumItems)
|
||||
{
|
||||
const CItem &item = (*_items)[_refItem.ItemIndex + _curIndex];
|
||||
_stream.Attach((*_archives)[_refItem.VolumeIndex + _curIndex].
|
||||
CreateLimitedStream(item.GetDataPosition(), item.PackSize));
|
||||
_curIndex++;
|
||||
_fileIsOpen = true;
|
||||
_crc = CRC_INIT_VAL;
|
||||
return S_OK;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CFolderInStream::CloseStream()
|
||||
{
|
||||
CRCs.Add(CRC_GET_DIGEST(_crc));
|
||||
_stream.Release();
|
||||
_fileIsOpen = false;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CFolderInStream::Read(void *data, UInt32 size, UInt32 *processedSize)
|
||||
STDMETHODIMP CVolsInStream::Read(void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
if (processedSize)
|
||||
*processedSize = 0;
|
||||
UInt32 realProcessedSize = 0;
|
||||
while ((_curIndex < _refItem.NumItems || _fileIsOpen) && size > 0)
|
||||
|
||||
while (size != 0)
|
||||
{
|
||||
if (_fileIsOpen)
|
||||
if (!_stream)
|
||||
{
|
||||
UInt32 localProcessedSize;
|
||||
RINOK(_stream->Read(
|
||||
((Byte *)data) + realProcessedSize, size, &localProcessedSize));
|
||||
_crc = CrcUpdate(_crc, ((Byte *)data) + realProcessedSize, localProcessedSize);
|
||||
if (localProcessedSize == 0)
|
||||
{
|
||||
RINOK(CloseStream());
|
||||
continue;
|
||||
}
|
||||
realProcessedSize += localProcessedSize;
|
||||
size -= localProcessedSize;
|
||||
break;
|
||||
if (_curIndex >= _refItem.NumItems)
|
||||
break;
|
||||
const CItem &item = (*_items)[_refItem.ItemIndex + _curIndex];
|
||||
IInStream *s = (*_arcs)[_refItem.VolumeIndex + _curIndex].Stream;
|
||||
RINOK(s->Seek(item.GetDataPosition(), STREAM_SEEK_SET, NULL));
|
||||
_stream = s;
|
||||
_calcCrc = (CrcIsOK && item.IsSplitAfter());
|
||||
_crc = CRC_INIT_VAL;
|
||||
_rem = item.PackSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
RINOK(OpenStream());
|
||||
UInt32 cur = size;
|
||||
if (cur > _rem)
|
||||
cur = (UInt32)_rem;
|
||||
UInt32 num = cur;
|
||||
HRESULT res = _stream->Read(data, cur, &cur);
|
||||
if (_calcCrc)
|
||||
_crc = CrcUpdate(_crc, data, cur);
|
||||
realProcessedSize += cur;
|
||||
if (processedSize)
|
||||
*processedSize = realProcessedSize;
|
||||
data = (Byte *)data + cur;
|
||||
size -= cur;
|
||||
_rem -= cur;
|
||||
if (_rem == 0)
|
||||
{
|
||||
const CItem &item = (*_items)[_refItem.ItemIndex + _curIndex];
|
||||
_curIndex++;
|
||||
if (_calcCrc && CRC_GET_DIGEST(_crc) != item.FileCRC)
|
||||
CrcIsOK = false;
|
||||
_stream = NULL;
|
||||
}
|
||||
if (res != S_OK)
|
||||
return res;
|
||||
if (realProcessedSize != 0)
|
||||
return S_OK;
|
||||
if (cur == 0 && num != 0)
|
||||
return S_OK;
|
||||
}
|
||||
}
|
||||
if (processedSize != 0)
|
||||
*processedSize = realProcessedSize;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@@ -1526,13 +1418,13 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
CFilterCoder *filterStreamSpec = new CFilterCoder(false);
|
||||
CMyComPtr<ISequentialInStream> filterStream = filterStreamSpec;
|
||||
|
||||
NCrypto::NRar20::CDecoder *rar20CryptoDecoderSpec = NULL;
|
||||
NCrypto::NRar2::CDecoder *rar20CryptoDecoderSpec = NULL;
|
||||
CMyComPtr<ICompressFilter> rar20CryptoDecoder;
|
||||
NCrypto::NRar29::CDecoder *rar29CryptoDecoderSpec = NULL;
|
||||
CMyComPtr<ICompressFilter> rar29CryptoDecoder;
|
||||
NCrypto::NRar3::CDecoder *rar3CryptoDecoderSpec = NULL;
|
||||
CMyComPtr<ICompressFilter> rar3CryptoDecoder;
|
||||
|
||||
CFolderInStream *folderInStreamSpec = NULL;
|
||||
CMyComPtr<ISequentialInStream> folderInStream;
|
||||
CVolsInStream *volsInStreamSpec = NULL;
|
||||
CMyComPtr<ISequentialInStream> volsInStream;
|
||||
|
||||
CLocalProgress *lps = new CLocalProgress;
|
||||
CMyComPtr<ICompressProgressInfo> progress = lps;
|
||||
@@ -1602,26 +1494,13 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
outStreamSpec->Init();
|
||||
realOutStream.Release();
|
||||
|
||||
/*
|
||||
for (unsigned partIndex = 0; partIndex < 1; partIndex++)
|
||||
if (!volsInStream)
|
||||
{
|
||||
CMyComPtr<ISequentialInStream> inStream;
|
||||
|
||||
// item redefinition
|
||||
const CItem &item = _items[refItem.ItemIndex + partIndex];
|
||||
|
||||
CInArchive &archive = _arcs[refItem.VolumeIndex + partIndex];
|
||||
|
||||
inStream.Attach(archive.CreateLimitedStream(item.GetDataPosition(),
|
||||
item.PackSize));
|
||||
*/
|
||||
if (!folderInStream)
|
||||
{
|
||||
folderInStreamSpec = new CFolderInStream;
|
||||
folderInStream = folderInStreamSpec;
|
||||
volsInStreamSpec = new CVolsInStream;
|
||||
volsInStream = volsInStreamSpec;
|
||||
}
|
||||
|
||||
folderInStreamSpec->Init(&_arcs, &_items, refItem);
|
||||
volsInStreamSpec->Init(&_arcs, &_items, refItem);
|
||||
|
||||
UInt64 packSize = currentPackSize;
|
||||
|
||||
@@ -1632,29 +1511,29 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
|
||||
if (item.IsEncrypted())
|
||||
{
|
||||
CMyComPtr<ICryptoSetPassword> cryptoSetPassword;
|
||||
// CMyComPtr<ICryptoSetPassword> cryptoSetPassword;
|
||||
|
||||
if (item.UnPackVersion >= 29)
|
||||
{
|
||||
if (!rar29CryptoDecoder)
|
||||
if (!rar3CryptoDecoder)
|
||||
{
|
||||
rar29CryptoDecoderSpec = new NCrypto::NRar29::CDecoder;
|
||||
rar29CryptoDecoder = rar29CryptoDecoderSpec;
|
||||
rar3CryptoDecoderSpec = new NCrypto::NRar3::CDecoder;
|
||||
rar3CryptoDecoder = rar3CryptoDecoderSpec;
|
||||
}
|
||||
rar29CryptoDecoderSpec->SetRar350Mode(item.UnPackVersion < 36);
|
||||
rar3CryptoDecoderSpec->SetRar350Mode(item.UnPackVersion < 36);
|
||||
/*
|
||||
CMyComPtr<ICompressSetDecoderProperties2> cryptoProperties;
|
||||
RINOK(rar29CryptoDecoder.QueryInterface(IID_ICompressSetDecoderProperties2,
|
||||
RINOK(rar3CryptoDecoder.QueryInterface(IID_ICompressSetDecoderProperties2,
|
||||
&cryptoProperties));
|
||||
*/
|
||||
RINOK(rar29CryptoDecoderSpec->SetDecoderProperties2(item.Salt, item.HasSalt() ? sizeof(item.Salt) : 0));
|
||||
filterStreamSpec->Filter = rar29CryptoDecoder;
|
||||
RINOK(rar3CryptoDecoderSpec->SetDecoderProperties2(item.Salt, item.HasSalt() ? sizeof(item.Salt) : 0));
|
||||
filterStreamSpec->Filter = rar3CryptoDecoder;
|
||||
}
|
||||
else if (item.UnPackVersion >= 20)
|
||||
{
|
||||
if (!rar20CryptoDecoder)
|
||||
{
|
||||
rar20CryptoDecoderSpec = new NCrypto::NRar20::CDecoder;
|
||||
rar20CryptoDecoderSpec = new NCrypto::NRar2::CDecoder;
|
||||
rar20CryptoDecoder = rar20CryptoDecoderSpec;
|
||||
}
|
||||
filterStreamSpec->Filter = rar20CryptoDecoder;
|
||||
@@ -1666,54 +1545,71 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
continue;
|
||||
}
|
||||
|
||||
RINOK(filterStreamSpec->Filter.QueryInterface(IID_ICryptoSetPassword, &cryptoSetPassword));
|
||||
// RINOK(filterStreamSpec->Filter.QueryInterface(IID_ICryptoSetPassword, &cryptoSetPassword));
|
||||
|
||||
if (!getTextPassword)
|
||||
extractCallback->QueryInterface(IID_ICryptoGetTextPassword, (void **)&getTextPassword);
|
||||
if (getTextPassword)
|
||||
|
||||
if (!getTextPassword)
|
||||
{
|
||||
outStream.Release();
|
||||
RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kUnsupportedMethod));
|
||||
continue;
|
||||
}
|
||||
|
||||
// if (getTextPassword)
|
||||
{
|
||||
CMyComBSTR password;
|
||||
RINOK(getTextPassword->CryptoGetTextPassword(&password));
|
||||
|
||||
if (item.UnPackVersion >= 29)
|
||||
{
|
||||
UString unicodePassword;
|
||||
unsigned len = 0;
|
||||
if (password)
|
||||
len = MyStringLen(password);
|
||||
CByteBuffer buffer(len * 2);
|
||||
if (len > kPasswordLen_MAX)
|
||||
len = kPasswordLen_MAX;
|
||||
CByteArr buffer(len * 2);
|
||||
for (unsigned i = 0; i < len; i++)
|
||||
{
|
||||
wchar_t c = password[i];
|
||||
((Byte *)buffer)[i * 2] = (Byte)c;
|
||||
((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8);
|
||||
}
|
||||
RINOK(cryptoSetPassword->CryptoSetPassword((const Byte *)buffer, (UInt32)buffer.Size()));
|
||||
rar3CryptoDecoderSpec->SetPassword((const Byte *)buffer, len * 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
AString oemPassword;
|
||||
if (password)
|
||||
oemPassword = UnicodeStringToMultiByte((const wchar_t *)password, CP_OEMCP);
|
||||
RINOK(cryptoSetPassword->CryptoSetPassword((const Byte *)(const char *)oemPassword, oemPassword.Len()));
|
||||
{
|
||||
UString unicode = (LPCOLESTR)password;
|
||||
if (unicode.Len() > kPasswordLen_MAX)
|
||||
unicode.DeleteFrom(kPasswordLen_MAX);
|
||||
oemPassword = UnicodeStringToMultiByte(unicode, CP_OEMCP);
|
||||
}
|
||||
rar20CryptoDecoderSpec->SetPassword((const Byte *)(const char *)oemPassword, oemPassword.Len());
|
||||
}
|
||||
}
|
||||
/*
|
||||
else
|
||||
{
|
||||
RINOK(cryptoSetPassword->CryptoSetPassword(0, 0));
|
||||
RINOK(cryptoSetPassword->CryptoSetPassword(NULL, 0));
|
||||
}
|
||||
*/
|
||||
|
||||
filterStreamSpec->SetInStream(folderInStream);
|
||||
filterStreamSpec->SetInStream(volsInStream);
|
||||
filterStreamSpec->SetOutStreamSize(NULL);
|
||||
inStream = filterStream;
|
||||
}
|
||||
else
|
||||
{
|
||||
inStream = folderInStream;
|
||||
inStream = volsInStream;
|
||||
}
|
||||
|
||||
CMyComPtr<ICompressCoder> commonCoder;
|
||||
|
||||
switch(item.Method)
|
||||
switch (item.Method)
|
||||
{
|
||||
case '0':
|
||||
{
|
||||
@@ -1766,7 +1662,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
Byte isSolid = (Byte)((IsSolid(index) || item.IsSplitBefore()) ? 1: 0);
|
||||
if (solidStart)
|
||||
{
|
||||
isSolid = false;
|
||||
isSolid = 0;
|
||||
solidStart = false;
|
||||
}
|
||||
|
||||
@@ -1786,46 +1682,25 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
|
||||
if (item.IsEncrypted())
|
||||
filterStreamSpec->ReleaseInStream();
|
||||
if (result == S_FALSE)
|
||||
{
|
||||
outStream.Release();
|
||||
RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kDataError));
|
||||
continue;
|
||||
}
|
||||
if (result != S_OK)
|
||||
return result;
|
||||
|
||||
/*
|
||||
if (refItem.NumItems == 1 &&
|
||||
!item.IsSplitBefore() && !item.IsSplitAfter())
|
||||
*/
|
||||
const CItem &lastItem = _items[refItem.ItemIndex + refItem.NumItems - 1];
|
||||
int opRes = (volsInStreamSpec->CrcIsOK && outStreamSpec->GetCRC() == lastItem.FileCRC) ?
|
||||
NExtract::NOperationResult::kOK:
|
||||
NExtract::NOperationResult::kCRCError;
|
||||
outStream.Release();
|
||||
|
||||
if (result != S_OK)
|
||||
{
|
||||
const CItem &lastItem = _items[refItem.ItemIndex + refItem.NumItems - 1];
|
||||
bool crcOK = outStreamSpec->GetCRC() == lastItem.FileCRC;
|
||||
outStream.Release();
|
||||
RINOK(extractCallback->SetOperationResult(crcOK ?
|
||||
NExtract::NOperationResult::kOK:
|
||||
NExtract::NOperationResult::kCRCError));
|
||||
if (result == S_FALSE)
|
||||
opRes = NExtract::NOperationResult::kDataError;
|
||||
else if (result == E_NOTIMPL)
|
||||
opRes = NExtract::NOperationResult::kUnsupportedMethod;
|
||||
else
|
||||
return result;
|
||||
}
|
||||
/*
|
||||
else
|
||||
{
|
||||
bool crcOK = true;
|
||||
for (unsigned partIndex = 0; partIndex < refItem.NumItems; partIndex++)
|
||||
{
|
||||
const CItem &item = _items[refItem.ItemIndex + partIndex];
|
||||
if (item.FileCRC != folderInStreamSpec->CRCs[partIndex])
|
||||
{
|
||||
crcOK = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
RINOK(extractCallback->SetOperationResult(crcOK ?
|
||||
NExtract::NOperationResult::kOK:
|
||||
NExtract::NOperationResult::kCRCError));
|
||||
}
|
||||
*/
|
||||
RINOK(extractCallback->SetOperationResult(opRes));
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ struct CInArcInfo
|
||||
|
||||
bool IsEncryptOld() const { return (!IsThereEncryptVer() || EncryptVersion < 36); }
|
||||
|
||||
bool AreMoreVolumes() const { return (EndFlags & NHeader::NArchive::kEndOfArc_Flags_NextVol) != 0; }
|
||||
bool Is_VolNumber_Defined() const { return (EndFlags & NHeader::NArchive::kEndOfArc_Flags_VolNumber) != 0; }
|
||||
bool Is_DataCRC_Defined() const { return (EndFlags & NHeader::NArchive::kEndOfArc_Flags_DataCRC) != 0; }
|
||||
};
|
||||
@@ -79,6 +80,7 @@ class CHandler:
|
||||
UInt32 _errorFlags;
|
||||
UInt32 _warningFlags;
|
||||
bool _isArc;
|
||||
UString _missingVolName;
|
||||
|
||||
DECL_EXTERNAL_CODECS_VARS
|
||||
|
||||
|
||||
129
CPP/7zip/Archive/Rar/RarVol.h
Normal file
129
CPP/7zip/Archive/Rar/RarVol.h
Normal file
@@ -0,0 +1,129 @@
|
||||
// RarVol.h
|
||||
|
||||
#ifndef __ARCHIVE_RAR_VOL_H
|
||||
#define __ARCHIVE_RAR_VOL_H
|
||||
|
||||
#include "../../../Common/StringConvert.h"
|
||||
|
||||
#include "RarHeader.h"
|
||||
|
||||
namespace NArchive {
|
||||
namespace NRar {
|
||||
|
||||
inline bool IsDigit(wchar_t c)
|
||||
{
|
||||
return c >= L'0' && c <= L'9';
|
||||
}
|
||||
|
||||
class CVolumeName
|
||||
{
|
||||
bool _needChangeForNext;
|
||||
UString _before;
|
||||
UString _changed;
|
||||
UString _after;
|
||||
public:
|
||||
CVolumeName(): _needChangeForNext(true) {};
|
||||
|
||||
bool InitName(const UString &name, bool newStyle = true)
|
||||
{
|
||||
_needChangeForNext = true;
|
||||
_after.Empty();
|
||||
UString base = name;
|
||||
int dotPos = name.ReverseFind_Dot();
|
||||
|
||||
if (dotPos >= 0)
|
||||
{
|
||||
const UString ext = name.Ptr(dotPos + 1);
|
||||
if (ext.IsEqualTo_Ascii_NoCase("rar"))
|
||||
{
|
||||
_after = name.Ptr(dotPos);
|
||||
base.DeleteFrom(dotPos);
|
||||
}
|
||||
else if (ext.IsEqualTo_Ascii_NoCase("exe"))
|
||||
{
|
||||
_after.SetFromAscii(".rar");
|
||||
base.DeleteFrom(dotPos);
|
||||
}
|
||||
else if (!newStyle)
|
||||
{
|
||||
if (ext.IsEqualTo_Ascii_NoCase("000") ||
|
||||
ext.IsEqualTo_Ascii_NoCase("001") ||
|
||||
ext.IsEqualTo_Ascii_NoCase("r00") ||
|
||||
ext.IsEqualTo_Ascii_NoCase("r01"))
|
||||
{
|
||||
_changed = ext;
|
||||
_before = name.Left(dotPos + 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (newStyle)
|
||||
{
|
||||
unsigned i = base.Len();
|
||||
|
||||
for (; i != 0; i--)
|
||||
if (!IsDigit(base[i - 1]))
|
||||
break;
|
||||
|
||||
if (i != base.Len())
|
||||
{
|
||||
_before = base.Left(i);
|
||||
_changed = base.Ptr(i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
_after.Empty();
|
||||
_before = base;
|
||||
_before += L'.';
|
||||
_changed.SetFromAscii("r00");
|
||||
_needChangeForNext = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
void MakeBeforeFirstName()
|
||||
{
|
||||
unsigned len = _changed.Len();
|
||||
_changed.Empty();
|
||||
for (unsigned i = 0; i < len; i++)
|
||||
_changed += L'0';
|
||||
}
|
||||
*/
|
||||
|
||||
UString GetNextName()
|
||||
{
|
||||
if (_needChangeForNext)
|
||||
{
|
||||
unsigned i = _changed.Len();
|
||||
if (i == 0)
|
||||
return UString();
|
||||
for (;;)
|
||||
{
|
||||
wchar_t c = _changed[--i];
|
||||
if (c == L'9')
|
||||
{
|
||||
c = L'0';
|
||||
_changed.ReplaceOneCharAtPos(i, c);
|
||||
if (i == 0)
|
||||
{
|
||||
_changed.InsertAtFront(L'1');
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
c++;
|
||||
_changed.ReplaceOneCharAtPos(i, c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_needChangeForNext = true;
|
||||
return _before + _changed + _after;
|
||||
}
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
@@ -4,21 +4,19 @@
|
||||
|
||||
#include "../../../C/CpuArch.h"
|
||||
|
||||
#include "../../Common/MyBuffer.h"
|
||||
#include "../../Common/ComTry.h"
|
||||
#include "../../Common/IntToString.h"
|
||||
#include "../../Common/MyString.h"
|
||||
#include "../../Common/StringConvert.h"
|
||||
#include "../../Common/UTFConvert.h"
|
||||
|
||||
#include "../../Windows/PropVariant.h"
|
||||
#include "../../Windows/TimeUtils.h"
|
||||
|
||||
#include "../Common/LimitedStreams.h"
|
||||
#include "../Common/ProgressUtils.h"
|
||||
#include "../Common/RegisterArc.h"
|
||||
#include "../Common/StreamUtils.h"
|
||||
|
||||
#include "../Compress/CopyCoder.h"
|
||||
#include "HandlerCont.h"
|
||||
|
||||
// #define _SHOW_RPM_METADATA
|
||||
|
||||
@@ -169,13 +167,8 @@ struct CEntry
|
||||
}
|
||||
};
|
||||
|
||||
class CHandler:
|
||||
public IInArchive,
|
||||
public IInArchiveGetStream,
|
||||
public CMyUnknownImp
|
||||
class CHandler: public CHandlerCont
|
||||
{
|
||||
CMyComPtr<IInStream> _stream;
|
||||
|
||||
UInt64 _headersSize; // is equal to start offset of payload data
|
||||
UInt64 _payloadSize;
|
||||
UInt64 _size;
|
||||
@@ -232,10 +225,16 @@ class CHandler:
|
||||
|
||||
HRESULT ReadHeader(ISequentialInStream *stream, bool isMainHeader);
|
||||
HRESULT Open2(ISequentialInStream *stream);
|
||||
|
||||
virtual int GetItem_ExtractInfo(UInt32 /* index */, UInt64 &pos, UInt64 &size) const
|
||||
{
|
||||
pos = _headersSize;
|
||||
size = _size;
|
||||
return NExtract::NOperationResult::kOK;
|
||||
}
|
||||
|
||||
public:
|
||||
MY_UNKNOWN_IMP2(IInArchive, IInArchiveGetStream)
|
||||
INTERFACE_IInArchive(;)
|
||||
STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);
|
||||
INTERFACE_IInArchive_Cont(;)
|
||||
};
|
||||
|
||||
static const Byte kArcProps[] =
|
||||
@@ -728,50 +727,6 @@ STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
Int32 testMode, IArchiveExtractCallback *extractCallback)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
if (numItems == 0)
|
||||
return S_OK;
|
||||
if (numItems != (UInt32)(Int32)-1 && (numItems != 1 || indices[0] != 0))
|
||||
return E_INVALIDARG;
|
||||
|
||||
RINOK(extractCallback->SetTotal(_size));
|
||||
|
||||
CMyComPtr<ISequentialOutStream> outStream;
|
||||
Int32 askMode = testMode ?
|
||||
NExtract::NAskMode::kTest :
|
||||
NExtract::NAskMode::kExtract;
|
||||
RINOK(extractCallback->GetStream(0, &outStream, askMode));
|
||||
if (!testMode && !outStream)
|
||||
return S_OK;
|
||||
RINOK(extractCallback->PrepareOperation(askMode));
|
||||
|
||||
NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder;
|
||||
CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
|
||||
|
||||
CLocalProgress *lps = new CLocalProgress;
|
||||
CMyComPtr<ICompressProgressInfo> progress = lps;
|
||||
lps->Init(extractCallback, false);
|
||||
|
||||
RINOK(_stream->Seek(_headersSize, STREAM_SEEK_SET, NULL));
|
||||
RINOK(copyCoder->Code(_stream, outStream, NULL, &_size, progress));
|
||||
outStream.Release();
|
||||
Int32 opRes = NExtract::NOperationResult::kOK;
|
||||
if (copyCoderSpec->TotalSize < _size)
|
||||
opRes = NExtract::NOperationResult::kUnexpectedEnd;
|
||||
return extractCallback->SetOperationResult(opRes);
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
STDMETHODIMP CHandler::GetStream(UInt32 /* index */, ISequentialInStream **stream)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
return CreateLimitedInStream(_stream, _headersSize, _size, stream);
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
static const Byte k_Signature[] = { 0xED, 0xAB, 0xEE, 0xDB};
|
||||
|
||||
REGISTER_ARC_I(
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user