mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-17 02:11:49 -06:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bec3b479dc | ||
|
|
66ac98bb02 | ||
|
|
c20d013055 | ||
|
|
9608215ad8 | ||
|
|
5de23c1deb | ||
|
|
e24f7fba53 | ||
|
|
7c8a265a15 |
82
C/7z.h
82
C/7z.h
@@ -1,5 +1,5 @@
|
||||
/* 7z.h -- 7z interface
|
||||
2014-02-08 : Igor Pavlov : Public domain */
|
||||
2015-11-18 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __7Z_H
|
||||
#define __7Z_H
|
||||
@@ -48,21 +48,10 @@ typedef struct
|
||||
UInt32 PackStreams[SZ_NUM_PACK_STREAMS_IN_FOLDER_MAX];
|
||||
CSzBond Bonds[SZ_NUM_BONDS_IN_FOLDER_MAX];
|
||||
CSzCoderInfo Coders[SZ_NUM_CODERS_IN_FOLDER_MAX];
|
||||
UInt64 CodersUnpackSizes[SZ_NUM_CODERS_IN_FOLDER_MAX];
|
||||
} CSzFolder;
|
||||
|
||||
/*
|
||||
typedef struct
|
||||
{
|
||||
size_t CodersDataOffset;
|
||||
size_t UnpackSizeDataOffset;
|
||||
// UInt32 StartCoderUnpackSizesIndex;
|
||||
UInt32 StartPackStreamIndex;
|
||||
// UInt32 IndexOfMainOutStream;
|
||||
} CSzFolder2;
|
||||
*/
|
||||
|
||||
SRes SzGetNextFolderItem(CSzFolder *f, CSzData *sd, CSzData *sdSizes);
|
||||
SRes SzGetNextFolderItem(CSzFolder *f, CSzData *sd);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -92,47 +81,25 @@ typedef struct
|
||||
UInt32 NumPackStreams;
|
||||
UInt32 NumFolders;
|
||||
|
||||
UInt64 *PackPositions; // NumPackStreams + 1
|
||||
CSzBitUi32s FolderCRCs;
|
||||
UInt64 *PackPositions; // NumPackStreams + 1
|
||||
CSzBitUi32s FolderCRCs; // NumFolders
|
||||
|
||||
size_t *FoCodersOffsets;
|
||||
size_t *FoSizesOffsets;
|
||||
// UInt32 StartCoderUnpackSizesIndex;
|
||||
UInt32 *FoStartPackStreamIndex;
|
||||
size_t *FoCodersOffsets; // NumFolders + 1
|
||||
UInt32 *FoStartPackStreamIndex; // NumFolders + 1
|
||||
UInt32 *FoToCoderUnpackSizes; // NumFolders + 1
|
||||
Byte *FoToMainUnpackSizeIndex; // NumFolders
|
||||
UInt64 *CoderUnpackSizes; // for all coders in all folders
|
||||
|
||||
// CSzFolder2 *Folders; // +1 item for sum values
|
||||
Byte *CodersData;
|
||||
Byte *UnpackSizesData;
|
||||
size_t UnpackSizesDataSize;
|
||||
// UInt64 *CoderUnpackSizes;
|
||||
} CSzAr;
|
||||
|
||||
UInt64 SzAr_GetFolderUnpackSize(const CSzAr *p, UInt32 folderIndex);
|
||||
|
||||
SRes SzAr_DecodeFolder(const CSzAr *p, UInt32 folderIndex,
|
||||
ILookInStream *stream, UInt64 startPos,
|
||||
Byte *outBuffer, size_t outSize,
|
||||
ISzAlloc *allocMain);
|
||||
|
||||
/*
|
||||
SzExtract extracts file from archive
|
||||
|
||||
*outBuffer must be 0 before first call for each new archive.
|
||||
|
||||
Extracting cache:
|
||||
If you need to decompress more than one file, you can send
|
||||
these values from previous call:
|
||||
*blockIndex,
|
||||
*outBuffer,
|
||||
*outBufferSize
|
||||
You can consider "*outBuffer" as cache of solid block. If your archive is solid,
|
||||
it will increase decompression speed.
|
||||
|
||||
If you use external function, you can declare these 3 cache variables
|
||||
(blockIndex, outBuffer, outBufferSize) as static in that external function.
|
||||
|
||||
Free *outBuffer and set *outBuffer to 0, if you want to flush cache.
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
CSzAr db;
|
||||
@@ -142,7 +109,7 @@ typedef struct
|
||||
|
||||
UInt32 NumFiles;
|
||||
|
||||
UInt64 *UnpackPositions;
|
||||
UInt64 *UnpackPositions; // NumFiles + 1
|
||||
// Byte *IsEmptyFiles;
|
||||
Byte *IsDirs;
|
||||
CSzBitUi32s CRCs;
|
||||
@@ -152,9 +119,8 @@ typedef struct
|
||||
CSzBitUi64s MTime;
|
||||
CSzBitUi64s CTime;
|
||||
|
||||
// UInt32 *FolderStartPackStreamIndex;
|
||||
UInt32 *FolderStartFileIndex; // + 1
|
||||
UInt32 *FileIndexToFolderIndexMap;
|
||||
UInt32 *FolderToFile; // NumFolders + 1
|
||||
UInt32 *FileToFolder; // NumFiles
|
||||
|
||||
size_t *FileNameOffsets; /* in 2-byte steps */
|
||||
Byte *FileNames; /* UTF-16-LE */
|
||||
@@ -182,6 +148,28 @@ size_t SzArEx_GetFullNameLen(const CSzArEx *p, size_t fileIndex);
|
||||
UInt16 *SzArEx_GetFullNameUtf16_Back(const CSzArEx *p, size_t fileIndex, UInt16 *dest);
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
SzArEx_Extract extracts file from archive
|
||||
|
||||
*outBuffer must be 0 before first call for each new archive.
|
||||
|
||||
Extracting cache:
|
||||
If you need to decompress more than one file, you can send
|
||||
these values from previous call:
|
||||
*blockIndex,
|
||||
*outBuffer,
|
||||
*outBufferSize
|
||||
You can consider "*outBuffer" as cache of solid block. If your archive is solid,
|
||||
it will increase decompression speed.
|
||||
|
||||
If you use external function, you can declare these 3 cache variables
|
||||
(blockIndex, outBuffer, outBufferSize) as static in that external function.
|
||||
|
||||
Free *outBuffer and set *outBuffer to 0, if you want to flush cache.
|
||||
*/
|
||||
|
||||
SRes SzArEx_Extract(
|
||||
const CSzArEx *db,
|
||||
ILookInStream *inStream,
|
||||
|
||||
@@ -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);
|
||||
|
||||
564
C/7zArcIn.c
564
C/7zArcIn.c
File diff suppressed because it is too large
Load Diff
56
C/7zDec.c
56
C/7zDec.c
@@ -1,5 +1,5 @@
|
||||
/* 7zDec.c -- Decoding from 7z folder
|
||||
2015-08-01 : Igor Pavlov : Public domain */
|
||||
2015-11-18 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
/* #define _7ZIP_PPMD_SUPPPORT */
|
||||
|
||||
#include "7z.h"
|
||||
#include "7zCrc.h"
|
||||
|
||||
#include "Bcj2.h"
|
||||
#include "Bra.h"
|
||||
@@ -160,14 +161,23 @@ static SRes SzDecodeLzma(const Byte *props, unsigned propsSize, UInt64 inSize, I
|
||||
inSize -= inProcessed;
|
||||
if (res != SZ_OK)
|
||||
break;
|
||||
if (state.dicPos == state.dicBufSize || (inProcessed == 0 && dicPos == state.dicPos))
|
||||
|
||||
if (status == LZMA_STATUS_FINISHED_WITH_MARK)
|
||||
{
|
||||
if (state.dicBufSize != outSize || lookahead != 0 ||
|
||||
(status != LZMA_STATUS_FINISHED_WITH_MARK &&
|
||||
status != LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK))
|
||||
if (outSize != state.dicPos || inSize != 0)
|
||||
res = SZ_ERROR_DATA;
|
||||
break;
|
||||
}
|
||||
|
||||
if (outSize == state.dicPos && inSize == 0 && status == LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK)
|
||||
break;
|
||||
|
||||
if (inProcessed == 0 && dicPos == state.dicPos)
|
||||
{
|
||||
res = SZ_ERROR_DATA;
|
||||
break;
|
||||
}
|
||||
|
||||
res = inStream->Skip((void *)inStream, inProcessed);
|
||||
if (res != SZ_OK)
|
||||
break;
|
||||
@@ -213,13 +223,20 @@ static SRes SzDecodeLzma2(const Byte *props, unsigned propsSize, UInt64 inSize,
|
||||
inSize -= inProcessed;
|
||||
if (res != SZ_OK)
|
||||
break;
|
||||
if (state.decoder.dicPos == state.decoder.dicBufSize || (inProcessed == 0 && dicPos == state.decoder.dicPos))
|
||||
|
||||
if (status == LZMA_STATUS_FINISHED_WITH_MARK)
|
||||
{
|
||||
if (state.decoder.dicBufSize != outSize || lookahead != 0 ||
|
||||
(status != LZMA_STATUS_FINISHED_WITH_MARK))
|
||||
if (outSize != state.decoder.dicPos || inSize != 0)
|
||||
res = SZ_ERROR_DATA;
|
||||
break;
|
||||
}
|
||||
|
||||
if (inProcessed == 0 && dicPos == state.decoder.dicPos)
|
||||
{
|
||||
res = SZ_ERROR_DATA;
|
||||
break;
|
||||
}
|
||||
|
||||
res = inStream->Skip((void *)inStream, inProcessed);
|
||||
if (res != SZ_OK)
|
||||
break;
|
||||
@@ -537,33 +554,38 @@ SRes SzAr_DecodeFolder(const CSzAr *p, UInt32 folderIndex,
|
||||
SRes res;
|
||||
CSzFolder folder;
|
||||
CSzData sd;
|
||||
CSzData sdSizes;
|
||||
|
||||
const Byte *data = p->CodersData + p->FoCodersOffsets[folderIndex];
|
||||
sd.Data = data;
|
||||
sd.Size = p->FoCodersOffsets[folderIndex + 1] - p->FoCodersOffsets[folderIndex];
|
||||
|
||||
sdSizes.Data = p->UnpackSizesData + p->FoSizesOffsets[folderIndex];
|
||||
sdSizes.Size =
|
||||
p->FoSizesOffsets[folderIndex + 1] -
|
||||
p->FoSizesOffsets[folderIndex];
|
||||
|
||||
res = SzGetNextFolderItem(&folder, &sd, &sdSizes);
|
||||
res = SzGetNextFolderItem(&folder, &sd);
|
||||
|
||||
if (res != SZ_OK)
|
||||
return res;
|
||||
|
||||
if (sd.Size != 0 || outSize != folder.CodersUnpackSizes[folder.UnpackStream])
|
||||
if (sd.Size != 0
|
||||
|| folder.UnpackStream != p->FoToMainUnpackSizeIndex[folderIndex]
|
||||
|| outSize != SzAr_GetFolderUnpackSize(p, folderIndex))
|
||||
return SZ_ERROR_FAIL;
|
||||
{
|
||||
unsigned i;
|
||||
Byte *tempBuf[3] = { 0, 0, 0};
|
||||
res = SzFolder_Decode2(&folder, data, folder.CodersUnpackSizes,
|
||||
|
||||
res = SzFolder_Decode2(&folder, data,
|
||||
&p->CoderUnpackSizes[p->FoToCoderUnpackSizes[folderIndex]],
|
||||
p->PackPositions + p->FoStartPackStreamIndex[folderIndex],
|
||||
inStream, startPos,
|
||||
outBuffer, (SizeT)outSize, allocMain, tempBuf);
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
IAlloc_Free(allocMain, tempBuf[i]);
|
||||
|
||||
if (res == SZ_OK)
|
||||
if (SzBitWithVals_Check(&p->FolderCRCs, folderIndex))
|
||||
if (CrcCalc(outBuffer, outSize) != p->FolderCRCs.Vals[folderIndex])
|
||||
res = SZ_ERROR_CRC;
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#define MY_VER_MAJOR 15
|
||||
#define MY_VER_MINOR 9
|
||||
#define MY_VER_MAJOR 16
|
||||
#define MY_VER_MINOR 01
|
||||
#define MY_VER_BUILD 0
|
||||
#define MY_VERSION_NUMBERS "15.09"
|
||||
#define MY_VERSION "15.09 beta"
|
||||
#define MY_DATE "2015-10-16"
|
||||
#define MY_VERSION_NUMBERS "16.01"
|
||||
#define MY_VERSION "16.01"
|
||||
#define MY_DATE "2016-05-19"
|
||||
#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"
|
||||
#define MY_COPYRIGHT_CR "Copyright (c) 1999-2016 Igor Pavlov"
|
||||
|
||||
#ifdef USE_COPYRIGHT_CR
|
||||
#define MY_COPYRIGHT MY_COPYRIGHT_CR
|
||||
|
||||
@@ -513,4 +513,3 @@ UInt32 BlockSort(UInt32 *Indices, const Byte *data, UInt32 blockSize)
|
||||
#endif
|
||||
return Groups[0];
|
||||
}
|
||||
|
||||
|
||||
13
C/CpuArch.c
13
C/CpuArch.c
@@ -1,5 +1,5 @@
|
||||
/* CpuArch.c -- CPU specific code
|
||||
2015-03-25: Igor Pavlov : Public domain */
|
||||
2016-02-25: Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
@@ -45,7 +45,8 @@ static UInt32 CheckFlag(UInt32 flag)
|
||||
"push %%EDX\n\t"
|
||||
"popf\n\t"
|
||||
"andl %%EAX, %0\n\t":
|
||||
"=c" (flag) : "c" (flag));
|
||||
"=c" (flag) : "c" (flag) :
|
||||
"%eax", "%edx");
|
||||
#endif
|
||||
return flag;
|
||||
}
|
||||
@@ -79,7 +80,13 @@ void MyCPUID(UInt32 function, UInt32 *a, UInt32 *b, UInt32 *c, UInt32 *d)
|
||||
#else
|
||||
|
||||
__asm__ __volatile__ (
|
||||
#if defined(MY_CPU_X86) && defined(__PIC__)
|
||||
#if defined(MY_CPU_AMD64) && defined(__PIC__)
|
||||
"mov %%rbx, %%rdi;"
|
||||
"cpuid;"
|
||||
"xchg %%rbx, %%rdi;"
|
||||
: "=a" (*a) ,
|
||||
"=D" (*b) ,
|
||||
#elif defined(MY_CPU_X86) && defined(__PIC__)
|
||||
"mov %%ebx, %%edi;"
|
||||
"cpuid;"
|
||||
"xchgl %%ebx, %%edi;"
|
||||
|
||||
44
C/CpuArch.h
44
C/CpuArch.h
@@ -1,5 +1,5 @@
|
||||
/* CpuArch.h -- CPU specific code
|
||||
2015-08-02: Igor Pavlov : Public domain */
|
||||
2015-12-01: 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,11 @@ 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(__s390__) \
|
||||
|| defined(__s390x__) \
|
||||
|| defined(__zarch__) \
|
||||
|| (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))
|
||||
#define MY_CPU_BE
|
||||
#endif
|
||||
|
||||
@@ -85,6 +90,14 @@ 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))
|
||||
@@ -128,6 +141,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)
|
||||
@@ -137,6 +152,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) ( \
|
||||
|
||||
12
C/HuffEnc.c
12
C/HuffEnc.c
@@ -1,5 +1,5 @@
|
||||
/* HuffEnc.c -- functions for Huffman encoding
|
||||
2009-09-02 : Igor Pavlov : Public domain */
|
||||
2016-05-16 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
@@ -121,8 +121,8 @@ void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 numSymb
|
||||
i = 0;
|
||||
for (len = maxLen; len != 0; len--)
|
||||
{
|
||||
UInt32 num;
|
||||
for (num = lenCounters[len]; num != 0; num--)
|
||||
UInt32 k;
|
||||
for (k = lenCounters[len]; k != 0; k--)
|
||||
lens[p[i++] & MASK] = (Byte)len;
|
||||
}
|
||||
}
|
||||
@@ -138,9 +138,9 @@ void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 numSymb
|
||||
/* if (code + lenCounters[kMaxLen] - 1 != (1 << kMaxLen) - 1) throw 1; */
|
||||
|
||||
{
|
||||
UInt32 i;
|
||||
for (i = 0; i < numSymbols; i++)
|
||||
p[i] = nextCodes[lens[i]]++;
|
||||
UInt32 k;
|
||||
for (k = 0; k < numSymbols; k++)
|
||||
p[k] = nextCodes[lens[k]]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
/* Lzma86Dec.c -- LZMA + x86 (BCJ) Filter Decoder
|
||||
2009-08-14 : Igor Pavlov : Public domain */
|
||||
2016-05-16 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
#include "Lzma86.h"
|
||||
|
||||
@@ -7,9 +9,6 @@
|
||||
#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); }
|
||||
|
||||
SRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize)
|
||||
{
|
||||
unsigned i;
|
||||
@@ -23,7 +22,6 @@ SRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize)
|
||||
|
||||
SRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen)
|
||||
{
|
||||
ISzAlloc g_Alloc = { SzAlloc, SzFree };
|
||||
SRes res;
|
||||
int useFilter;
|
||||
SizeT inSizePure;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
/* Lzma86Enc.c -- LZMA + x86 (BCJ) Filter Encoder
|
||||
2009-08-14 : Igor Pavlov : Public domain */
|
||||
2016-05-16 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@@ -11,13 +13,9 @@
|
||||
|
||||
#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); }
|
||||
|
||||
int Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen,
|
||||
int level, UInt32 dictSize, int filterMode)
|
||||
{
|
||||
ISzAlloc g_Alloc = { SzAlloc, SzFree };
|
||||
size_t outSize2 = *destLen;
|
||||
Byte *filteredStream;
|
||||
Bool useFilter;
|
||||
|
||||
12
C/LzmaDec.c
12
C/LzmaDec.c
@@ -1,5 +1,5 @@
|
||||
/* LzmaDec.c -- LZMA Decoder
|
||||
2015-06-23 : Igor Pavlov : Public domain */
|
||||
2016-05-16 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
@@ -294,14 +294,14 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
|
||||
|
||||
#ifdef _LZMA_SIZE_OPT
|
||||
{
|
||||
unsigned limit, offset;
|
||||
unsigned lim, offset;
|
||||
CLzmaProb *probLen = prob + LenChoice;
|
||||
IF_BIT_0(probLen)
|
||||
{
|
||||
UPDATE_0(probLen);
|
||||
probLen = prob + LenLow + (posState << kLenNumLowBits);
|
||||
offset = 0;
|
||||
limit = (1 << kLenNumLowBits);
|
||||
lim = (1 << kLenNumLowBits);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -312,17 +312,17 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
|
||||
UPDATE_0(probLen);
|
||||
probLen = prob + LenMid + (posState << kLenNumMidBits);
|
||||
offset = kLenNumLowSymbols;
|
||||
limit = (1 << kLenNumMidBits);
|
||||
lim = (1 << kLenNumMidBits);
|
||||
}
|
||||
else
|
||||
{
|
||||
UPDATE_1(probLen);
|
||||
probLen = prob + LenHigh;
|
||||
offset = kLenNumLowSymbols + kLenNumMidSymbols;
|
||||
limit = (1 << kLenNumHighBits);
|
||||
lim = (1 << kLenNumHighBits);
|
||||
}
|
||||
}
|
||||
TREE_DECODE(probLen, limit, len);
|
||||
TREE_DECODE(probLen, lim, len);
|
||||
len += offset;
|
||||
}
|
||||
#else
|
||||
|
||||
55
C/LzmaEnc.c
55
C/LzmaEnc.c
@@ -1,5 +1,5 @@
|
||||
/* LzmaEnc.c -- LZMA Encoder
|
||||
2015-10-15 Igor Pavlov : Public domain */
|
||||
2016-05-16 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
@@ -108,7 +108,7 @@ UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)
|
||||
|
||||
#define kDicLogSizeMaxCompress 32
|
||||
|
||||
#define BSR2_RET(pos, res) { unsigned long i; _BitScanReverse(&i, (pos)); res = (i + i) + ((pos >> (i - 1)) & 1); }
|
||||
#define BSR2_RET(pos, res) { unsigned long zz; _BitScanReverse(&zz, (pos)); res = (zz + zz) + ((pos >> (zz - 1)) & 1); }
|
||||
|
||||
static UInt32 GetPosSlot1(UInt32 pos)
|
||||
{
|
||||
@@ -145,19 +145,19 @@ static void LzmaEnc_FastPosInit(Byte *g_FastPos)
|
||||
|
||||
/* we can use ((limit - pos) >> 31) only if (pos < ((UInt32)1 << 31)) */
|
||||
/*
|
||||
#define BSR2_RET(pos, res) { UInt32 i = 6 + ((kNumLogBits - 1) & \
|
||||
#define BSR2_RET(pos, res) { UInt32 zz = 6 + ((kNumLogBits - 1) & \
|
||||
(0 - (((((UInt32)1 << (kNumLogBits + 6)) - 1) - pos) >> 31))); \
|
||||
res = p->g_FastPos[pos >> i] + (i * 2); }
|
||||
res = p->g_FastPos[pos >> zz] + (zz * 2); }
|
||||
*/
|
||||
|
||||
/*
|
||||
#define BSR2_RET(pos, res) { UInt32 i = 6 + ((kNumLogBits - 1) & \
|
||||
#define BSR2_RET(pos, res) { UInt32 zz = 6 + ((kNumLogBits - 1) & \
|
||||
(0 - (((((UInt32)1 << (kNumLogBits)) - 1) - (pos >> 6)) >> 31))); \
|
||||
res = p->g_FastPos[pos >> i] + (i * 2); }
|
||||
res = p->g_FastPos[pos >> zz] + (zz * 2); }
|
||||
*/
|
||||
|
||||
#define BSR2_RET(pos, res) { UInt32 i = (pos < (1 << (kNumLogBits + 6))) ? 6 : 6 + kNumLogBits - 1; \
|
||||
res = p->g_FastPos[pos >> i] + (i * 2); }
|
||||
#define BSR2_RET(pos, res) { UInt32 zz = (pos < (1 << (kNumLogBits + 6))) ? 6 : 6 + kNumLogBits - 1; \
|
||||
res = p->g_FastPos[pos >> zz] + (zz * 2); }
|
||||
|
||||
/*
|
||||
#define BSR2_RET(pos, res) { res = (pos < (1 << (kNumLogBits + 6))) ? \
|
||||
@@ -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
|
||||
|
||||
@@ -983,12 +983,17 @@ static UInt32 Backward(CLzmaEnc *p, UInt32 *backRes, UInt32 cur)
|
||||
|
||||
static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
|
||||
{
|
||||
UInt32 numAvail, mainLen, numPairs, repMaxIndex, i, posState, lenEnd, len, cur;
|
||||
UInt32 matchPrice, repMatchPrice, normalMatchPrice;
|
||||
UInt32 lenEnd, cur;
|
||||
UInt32 reps[LZMA_NUM_REPS], repLens[LZMA_NUM_REPS];
|
||||
UInt32 *matches;
|
||||
|
||||
{
|
||||
|
||||
UInt32 numAvail, mainLen, numPairs, repMaxIndex, i, posState, len;
|
||||
UInt32 matchPrice, repMatchPrice, normalMatchPrice;
|
||||
const Byte *data;
|
||||
Byte curByte, matchByte;
|
||||
|
||||
if (p->optimumEndIndex != p->optimumCurrentIndex)
|
||||
{
|
||||
const COptimal *opt = &p->opt[p->optimumCurrentIndex];
|
||||
@@ -1167,17 +1172,20 @@ 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
|
||||
|
||||
}
|
||||
|
||||
for (;;)
|
||||
{
|
||||
UInt32 numAvail;
|
||||
UInt32 numAvailFull, newLen, numPairs, posPrev, state, posState, startLen;
|
||||
UInt32 curPrice, curAnd1Price, matchPrice, repMatchPrice;
|
||||
Bool nextIsChar;
|
||||
@@ -1397,13 +1405,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 =
|
||||
@@ -1465,6 +1473,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
|
||||
for (lenTest = /*2*/ startLen; ; lenTest++)
|
||||
{
|
||||
UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][lenTest - LZMA_MATCH_LEN_MIN];
|
||||
{
|
||||
UInt32 lenToPosState = GetLenToPosState(lenTest);
|
||||
COptimal *opt;
|
||||
if (curBack < kNumFullDistances)
|
||||
@@ -1480,6 +1489,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
|
||||
opt->backPrev = curBack + LZMA_NUM_REPS;
|
||||
opt->prev1IsChar = False;
|
||||
}
|
||||
}
|
||||
|
||||
if (/*_maxMode && */lenTest == matches[offs])
|
||||
{
|
||||
@@ -1487,13 +1497,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 +
|
||||
@@ -1509,15 +1519,15 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
|
||||
/* for (; lenTest2 >= 2; lenTest2--) */
|
||||
{
|
||||
UInt32 offset = cur + lenTest + 1 + lenTest2;
|
||||
UInt32 curAndLenPrice;
|
||||
UInt32 curAndLenPrice2;
|
||||
COptimal *opt;
|
||||
while (lenEnd < offset)
|
||||
p->opt[++lenEnd].price = kInfinityPrice;
|
||||
curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);
|
||||
curAndLenPrice2 = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);
|
||||
opt = &p->opt[offset];
|
||||
if (curAndLenPrice < opt->price)
|
||||
if (curAndLenPrice2 < opt->price)
|
||||
{
|
||||
opt->price = curAndLenPrice;
|
||||
opt->price = curAndLenPrice2;
|
||||
opt->posPrev = cur + lenTest + 1;
|
||||
opt->backPrev = 0;
|
||||
opt->prev1IsChar = True;
|
||||
@@ -1718,7 +1728,6 @@ static void FillDistancesPrices(CLzmaEnc *p)
|
||||
|
||||
{
|
||||
UInt32 *distancesPrices = p->distancesPrices[lenToPosState];
|
||||
UInt32 i;
|
||||
for (i = 0; i < kStartPosModelIndex; i++)
|
||||
distancesPrices[i] = posSlotPrices[i];
|
||||
for (; i < kNumFullDistances; i++)
|
||||
@@ -1829,7 +1838,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;
|
||||
|
||||
6
C/Ppmd.h
6
C/Ppmd.h
@@ -1,5 +1,5 @@
|
||||
/* Ppmd.h -- PPMD codec common code
|
||||
2013-01-18 : Igor Pavlov : Public domain
|
||||
2016-05-16 : Igor Pavlov : Public domain
|
||||
This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
|
||||
|
||||
#ifndef __PPMD_H
|
||||
@@ -77,8 +77,8 @@ typedef
|
||||
CPpmd_Byte_Ref;
|
||||
|
||||
#define PPMD_SetAllBitsIn256Bytes(p) \
|
||||
{ unsigned i; for (i = 0; i < 256 / sizeof(p[0]); i += 8) { \
|
||||
p[i+7] = p[i+6] = p[i+5] = p[i+4] = p[i+3] = p[i+2] = p[i+1] = p[i+0] = ~(size_t)0; }}
|
||||
{ unsigned z; for (z = 0; z < 256 / sizeof(p[0]); z += 8) { \
|
||||
p[z+7] = p[z+6] = p[z+5] = p[z+4] = p[z+3] = p[z+2] = p[z+1] = p[z+0] = ~(size_t)0; }}
|
||||
|
||||
EXTERN_C_END
|
||||
|
||||
|
||||
34
C/Ppmd8.c
34
C/Ppmd8.c
@@ -1,5 +1,5 @@
|
||||
/* Ppmd8.c -- PPMdI codec
|
||||
2015-09-28 : Igor Pavlov : Public domain
|
||||
2016-05-16 : Igor Pavlov : Public domain
|
||||
This code is based on PPMd var.I (2002): Dmitry Shkarin : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
@@ -240,8 +240,8 @@ 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); }
|
||||
{ UInt32 *d = (UInt32 *)dest; const UInt32 *z = (const UInt32 *)src; UInt32 n = num; \
|
||||
do { d[0] = z[0]; d[1] = z[1]; d[2] = z[2]; z += 3; d += 3; } while (--n); }
|
||||
|
||||
static void *ShrinkUnits(CPpmd8 *p, void *oldPtr, unsigned oldNU, unsigned newNU)
|
||||
{
|
||||
@@ -772,7 +772,7 @@ static CTX_PTR ReduceOrder(CPpmd8 *p, CPpmd_State *s1, CTX_PTR c)
|
||||
if (SUCCESSOR(s) <= upBranch)
|
||||
{
|
||||
CTX_PTR successor;
|
||||
CPpmd_State *s1 = p->FoundState;
|
||||
CPpmd_State *s2 = p->FoundState;
|
||||
p->FoundState = s;
|
||||
|
||||
successor = CreateSuccessors(p, False, NULL, c);
|
||||
@@ -780,7 +780,7 @@ static CTX_PTR ReduceOrder(CPpmd8 *p, CPpmd_State *s1, CTX_PTR c)
|
||||
SetSuccessor(s, 0);
|
||||
else
|
||||
SetSuccessor(s, REF(successor));
|
||||
p->FoundState = s1;
|
||||
p->FoundState = s2;
|
||||
}
|
||||
|
||||
if (p->OrderFall == 1 && c1 == p->MaxContext)
|
||||
@@ -924,19 +924,19 @@ static void UpdateModel(CPpmd8 *p)
|
||||
}
|
||||
else
|
||||
{
|
||||
CPpmd_State *s = (CPpmd_State*)AllocUnits(p, 0);
|
||||
if (!s)
|
||||
CPpmd_State *s2 = (CPpmd_State*)AllocUnits(p, 0);
|
||||
if (!s2)
|
||||
{
|
||||
RESTORE_MODEL(c, CTX(fSuccessor));
|
||||
return;
|
||||
}
|
||||
*s = *ONE_STATE(c);
|
||||
c->Stats = REF(s);
|
||||
if (s->Freq < MAX_FREQ / 4 - 1)
|
||||
s->Freq <<= 1;
|
||||
*s2 = *ONE_STATE(c);
|
||||
c->Stats = REF(s2);
|
||||
if (s2->Freq < MAX_FREQ / 4 - 1)
|
||||
s2->Freq <<= 1;
|
||||
else
|
||||
s->Freq = MAX_FREQ - 4;
|
||||
c->SummFreq = (UInt16)(s->Freq + p->InitEsc + (ns > 2));
|
||||
s2->Freq = MAX_FREQ - 4;
|
||||
c->SummFreq = (UInt16)(s2->Freq + p->InitEsc + (ns > 2));
|
||||
}
|
||||
cf = 2 * fFreq * (c->SummFreq + 6);
|
||||
sf = (UInt32)s0 + c->SummFreq;
|
||||
@@ -951,10 +951,10 @@ static void UpdateModel(CPpmd8 *p)
|
||||
c->SummFreq = (UInt16)(c->SummFreq + cf);
|
||||
}
|
||||
{
|
||||
CPpmd_State *s = STATS(c) + ns1 + 1;
|
||||
SetSuccessor(s, successor);
|
||||
s->Symbol = fSymbol;
|
||||
s->Freq = (Byte)cf;
|
||||
CPpmd_State *s2 = STATS(c) + ns1 + 1;
|
||||
SetSuccessor(s2, successor);
|
||||
s2->Symbol = fSymbol;
|
||||
s2->Freq = (Byte)cf;
|
||||
c->Flags |= flag;
|
||||
c->NumStats = (Byte)(ns1 + 1);
|
||||
}
|
||||
|
||||
23
C/Sha1.c
23
C/Sha1.c
@@ -1,5 +1,5 @@
|
||||
/* Sha1.c -- SHA-1 Hash
|
||||
2015-05-10 : Igor Pavlov : Public domain
|
||||
2016-02-09 : Igor Pavlov : Public domain
|
||||
This code is based on public domain code of Steve Reid from Wei Dai's Crypto++ library. */
|
||||
|
||||
#include "Precomp.h"
|
||||
@@ -151,18 +151,23 @@ void Sha1_Update(CSha1 *p, const Byte *data, size_t size)
|
||||
|
||||
if (pos2 != 0)
|
||||
{
|
||||
UInt32 w = ((UInt32)data[0]) << 24;
|
||||
if (--size && pos2 < 3)
|
||||
UInt32 w;
|
||||
pos2 = (3 - pos2) * 8;
|
||||
w = ((UInt32)*data++) << pos2;
|
||||
if (--size && pos2)
|
||||
{
|
||||
w |= ((UInt32)data[1]) << 16;
|
||||
if (--size && pos2 < 2)
|
||||
pos2 -= 8;
|
||||
w |= ((UInt32)*data++) << pos2;
|
||||
if (--size && pos2)
|
||||
{
|
||||
w |= ((UInt32)data[2]) << 8;
|
||||
--size;
|
||||
pos2 -= 8;
|
||||
w |= ((UInt32)*data++) << pos2;
|
||||
size--;
|
||||
}
|
||||
}
|
||||
data += 4 - pos2;
|
||||
p->buffer[pos++] |= (w >> (8 * pos2));
|
||||
p->buffer[pos] |= w;
|
||||
if (pos2 == 0)
|
||||
pos++;
|
||||
}
|
||||
|
||||
for (;;)
|
||||
|
||||
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-08-02 : Igor Pavlov : Public domain */
|
||||
2016-05-16 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
@@ -310,10 +310,10 @@ static void ConvertFileTimeToString(const CNtfsFileTime *nt, char *s)
|
||||
ms[1] = 29;
|
||||
for (mon = 0;; mon++)
|
||||
{
|
||||
unsigned s = ms[mon];
|
||||
if (v < s)
|
||||
unsigned d = ms[mon];
|
||||
if (v < d)
|
||||
break;
|
||||
v -= s;
|
||||
v -= d;
|
||||
}
|
||||
s = UIntToStr(s, year, 4); *s++ = '-';
|
||||
UIntToStr_2(s, mon + 1); s[2] = '-'; s += 3;
|
||||
|
||||
@@ -73,4 +73,3 @@ Ppmd7Dec.o: ../../Ppmd7Dec.c
|
||||
|
||||
clean:
|
||||
-$(RM) $(PROG) $(OBJS)
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* 7zipInstall.c - 7-Zip Installer
|
||||
2015-09-28 : Igor Pavlov : Public domain */
|
||||
2015-12-09 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
@@ -261,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;
|
||||
}
|
||||
@@ -284,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;
|
||||
}
|
||||
@@ -322,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)
|
||||
@@ -571,6 +571,8 @@ static INT_PTR CALLBACK MyDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
default: return FALSE;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -598,8 +600,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;
|
||||
}
|
||||
@@ -718,10 +720,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
|
||||
@@ -737,10 +739,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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1011,7 +1013,8 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
||||
BOOL bRet;
|
||||
MSG msg;
|
||||
|
||||
while ((bRet = GetMessage(&msg, g_HWND, 0, 0)) != 0)
|
||||
// we need messages for all thread windows (including EDITTEXT window in dialog)
|
||||
while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0)
|
||||
{
|
||||
if (bRet == -1)
|
||||
return retCode;
|
||||
@@ -1083,7 +1086,6 @@ static int Install()
|
||||
WCHAR sfxPath[MAX_PATH + 2];
|
||||
|
||||
Bool needReboot = False;
|
||||
size_t pathLen;
|
||||
|
||||
allocImp.Alloc = SzAlloc;
|
||||
allocImp.Free = SzFree;
|
||||
@@ -1116,6 +1118,7 @@ static int Install()
|
||||
|
||||
if (res == SZ_OK)
|
||||
{
|
||||
size_t pathLen;
|
||||
if (!g_SilentMode)
|
||||
{
|
||||
GetDlgItemTextW(g_HWND, IDE_EXTRACT_PATH, path, MAX_PATH);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* 7zipUninstall.c - 7-Zip Uninstaller
|
||||
2015-08-09 : Igor Pavlov : Public domain */
|
||||
2016-05-16 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
@@ -362,9 +362,11 @@ static void WriteCLSID()
|
||||
{
|
||||
if (AreEqual_Path_PrefixName(s, path, L"7-zip.dll"))
|
||||
{
|
||||
LONG res = MyRegistry_DeleteKey(HKEY_CLASSES_ROOT, k_Reg_CLSID_7zip_Inproc);
|
||||
if (res == ERROR_SUCCESS)
|
||||
MyRegistry_DeleteKey(HKEY_CLASSES_ROOT, k_Reg_CLSID_7zip);
|
||||
{
|
||||
LONG res = MyRegistry_DeleteKey(HKEY_CLASSES_ROOT, k_Reg_CLSID_7zip_Inproc);
|
||||
if (res == ERROR_SUCCESS)
|
||||
MyRegistry_DeleteKey(HKEY_CLASSES_ROOT, k_Reg_CLSID_7zip);
|
||||
}
|
||||
|
||||
{
|
||||
unsigned i;
|
||||
@@ -384,7 +386,7 @@ static void WriteCLSID()
|
||||
if (res == ERROR_SUCCESS)
|
||||
{
|
||||
RegDeleteValueW(destKey, k_7zip_CLSID);
|
||||
res = RegCloseKey(destKey);
|
||||
/* res = */ RegCloseKey(destKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -397,9 +399,11 @@ static void WriteCLSID()
|
||||
{
|
||||
if (AreEqual_Path_PrefixName(s, path, L"7-zip32.dll"))
|
||||
{
|
||||
LONG res = MyRegistry_DeleteKey_32(HKEY_CLASSES_ROOT, k_Reg_CLSID_7zip_Inproc);
|
||||
if (res == ERROR_SUCCESS)
|
||||
MyRegistry_DeleteKey_32(HKEY_CLASSES_ROOT, k_Reg_CLSID_7zip);
|
||||
{
|
||||
LONG res = MyRegistry_DeleteKey_32(HKEY_CLASSES_ROOT, k_Reg_CLSID_7zip_Inproc);
|
||||
if (res == ERROR_SUCCESS)
|
||||
MyRegistry_DeleteKey_32(HKEY_CLASSES_ROOT, k_Reg_CLSID_7zip);
|
||||
}
|
||||
|
||||
{
|
||||
unsigned i;
|
||||
@@ -419,7 +423,7 @@ static void WriteCLSID()
|
||||
if (res == ERROR_SUCCESS)
|
||||
{
|
||||
RegDeleteValueW(destKey, k_7zip_CLSID);
|
||||
res = RegCloseKey(destKey);
|
||||
/* res = */ RegCloseKey(destKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -542,7 +546,7 @@ static BOOL RemoveDir()
|
||||
#define k_Lang L"Lang"
|
||||
|
||||
// NUM_LANG_TXT_FILES files are placed before en.ttt
|
||||
#define NUM_LANG_TXT_FILES 86
|
||||
#define NUM_LANG_TXT_FILES 87
|
||||
|
||||
#ifdef _64BIT_INSTALLER
|
||||
#define NUM_EXTRA_FILES_64BIT 1
|
||||
@@ -556,7 +560,7 @@ static const char *k_Names =
|
||||
"af an ar ast az ba be bg bn br ca co cs cy da de el eo es et eu ext"
|
||||
" fa fi fr fur fy ga gl gu he hi hr hu hy id io is it ja ka kaa kk ko ku ku-ckb ky"
|
||||
" lij lt lv mk mn mng mng2 mr ms nb ne nl nn pa-in pl ps pt pt-br ro ru"
|
||||
" sa si sk sl sq sr-spc sr-spl sv ta th tr tt ug uk uz va vi zh-cn zh-tw"
|
||||
" sa si sk sl sq sr-spc sr-spl sv ta th tr tt ug uk uz va vi yo zh-cn zh-tw"
|
||||
" en.ttt"
|
||||
" descript.ion"
|
||||
" History.txt"
|
||||
@@ -771,6 +775,8 @@ static INT_PTR CALLBACK MyDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM
|
||||
OnClose();
|
||||
break;
|
||||
}
|
||||
|
||||
default: return FALSE;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1033,7 +1039,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
||||
BOOL bRet;
|
||||
MSG msg;
|
||||
|
||||
while ((bRet = GetMessage(&msg, g_HWND, 0, 0)) != 0)
|
||||
while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0)
|
||||
{
|
||||
if (bRet == -1)
|
||||
return retCode;
|
||||
|
||||
@@ -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 */
|
||||
2016-05-16 : 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();
|
||||
@@ -396,11 +396,9 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
||||
{
|
||||
size_t offset = 0;
|
||||
size_t outSizeProcessed = 0;
|
||||
size_t len;
|
||||
WCHAR *temp;
|
||||
len = SzArEx_GetFileNameUtf16(&db, i, NULL);
|
||||
|
||||
if (len >= MAX_PATH)
|
||||
|
||||
if (SzArEx_GetFileNameUtf16(&db, i, NULL) >= MAX_PATH)
|
||||
{
|
||||
res = SZ_ERROR_FAIL;
|
||||
break;
|
||||
|
||||
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++)
|
||||
|
||||
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
|
||||
|
||||
@@ -404,11 +404,11 @@ HRESULT CDecoder::Decode(
|
||||
len = password.Len();
|
||||
}
|
||||
CByteBuffer buffer(len * 2);
|
||||
for (size_t i = 0; i < len; i++)
|
||||
for (size_t k = 0; k < len; k++)
|
||||
{
|
||||
wchar_t c = passwordBSTR[i];
|
||||
((Byte *)buffer)[i * 2] = (Byte)c;
|
||||
((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8);
|
||||
wchar_t c = passwordBSTR[k];
|
||||
((Byte *)buffer)[k * 2] = (Byte)c;
|
||||
((Byte *)buffer)[k * 2 + 1] = (Byte)(c >> 8);
|
||||
}
|
||||
RINOK(cryptoSetPassword->CryptoSetPassword((const Byte *)buffer, (UInt32)buffer.Size()));
|
||||
}
|
||||
|
||||
@@ -148,9 +148,9 @@ HRESULT CEncoder::CreateMixerCoder(
|
||||
|
||||
RINOK(_mixer->SetBindInfo(_bindInfo));
|
||||
|
||||
FOR_VECTOR (i, _options.Methods)
|
||||
FOR_VECTOR (m, _options.Methods)
|
||||
{
|
||||
const CMethodFull &methodFull = _options.Methods[i];
|
||||
const CMethodFull &methodFull = _options.Methods[m];
|
||||
|
||||
CCreatedCoder cod;
|
||||
|
||||
@@ -410,9 +410,9 @@ HRESULT CEncoder::Encode(
|
||||
mtOutStreamNotifySpec->_stream = outStream;
|
||||
mtOutStreamNotifySpec->_mtProgresSpec = mtProgressSpec;
|
||||
|
||||
FOR_VECTOR(i, tempBufferSpecs)
|
||||
FOR_VECTOR(t, tempBufferSpecs)
|
||||
{
|
||||
tempBufferSpecs[i]->_mtProgresSpec = mtProgressSpec;
|
||||
tempBufferSpecs[t]->_mtProgresSpec = mtProgressSpec;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -591,9 +591,9 @@ HRESULT CEncoder::EncoderConstr()
|
||||
continue;
|
||||
}
|
||||
|
||||
int i = _bindInfo.FindStream_in_PackStreams(outIndex);
|
||||
if (i >= 0)
|
||||
_bindInfo.PackStreams.MoveToFront(i);
|
||||
int si = _bindInfo.FindStream_in_PackStreams(outIndex);
|
||||
if (si >= 0)
|
||||
_bindInfo.PackStreams.MoveToFront(si);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -311,13 +319,15 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
curUnpacked += _db.Files[k].Size;
|
||||
}
|
||||
|
||||
HRESULT result = folderOutStream->Init(fileIndex,
|
||||
allFilesMode ? NULL : indices + i,
|
||||
numSolidFiles);
|
||||
{
|
||||
HRESULT result = folderOutStream->Init(fileIndex,
|
||||
allFilesMode ? NULL : indices + i,
|
||||
numSolidFiles);
|
||||
|
||||
i += numSolidFiles;
|
||||
i += numSolidFiles;
|
||||
|
||||
RINOK(result);
|
||||
RINOK(result);
|
||||
}
|
||||
|
||||
// to test solid block with zero unpacked size we disable that code
|
||||
if (folderOutStream->WasWritingFinished())
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -425,11 +429,11 @@ HRESULT CHandler::SetMethodToProp(CNum folderIndex, PROPVARIANT *prop) const
|
||||
name = "LZMA2";
|
||||
if (propsSize == 1)
|
||||
{
|
||||
Byte p = props[0];
|
||||
if ((p & 1) == 0)
|
||||
ConvertUInt32ToString((UInt32)((p >> 1) + 12), s);
|
||||
Byte d = props[0];
|
||||
if ((d & 1) == 0)
|
||||
ConvertUInt32ToString((UInt32)((d >> 1) + 12), s);
|
||||
else
|
||||
GetStringForSizeValue(s, 3 << ((p >> 1) + 11));
|
||||
GetStringForSizeValue(s, 3 << ((d >> 1) + 11));
|
||||
}
|
||||
}
|
||||
else if (id == k_PPMD)
|
||||
@@ -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
|
||||
|
||||
@@ -675,14 +675,16 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
|
||||
static HRESULT ParseBond(UString &srcString, UInt32 &coder, UInt32 &stream)
|
||||
{
|
||||
stream = 0;
|
||||
int index = ParseStringToUInt32(srcString, coder);
|
||||
if (index == 0)
|
||||
return E_INVALIDARG;
|
||||
srcString.DeleteFrontal(index);
|
||||
{
|
||||
unsigned index = ParseStringToUInt32(srcString, coder);
|
||||
if (index == 0)
|
||||
return E_INVALIDARG;
|
||||
srcString.DeleteFrontal(index);
|
||||
}
|
||||
if (srcString[0] == 's')
|
||||
{
|
||||
srcString.Delete(0);
|
||||
int index = ParseStringToUInt32(srcString, stream);
|
||||
unsigned index = ParseStringToUInt32(srcString, stream);
|
||||
if (index == 0)
|
||||
return E_INVALIDARG;
|
||||
srcString.DeleteFrontal(index);
|
||||
|
||||
@@ -93,6 +93,8 @@ void CStreamSwitch::Set(CInArchive *archive, const CObjectVector<CByteBuffer> *d
|
||||
Byte external = archive->ReadByte();
|
||||
if (external != 0)
|
||||
{
|
||||
if (!dataVector)
|
||||
ThrowIncorrect();
|
||||
CNum dataIndex = archive->ReadNum();
|
||||
if (dataIndex >= dataVector->Size())
|
||||
ThrowIncorrect();
|
||||
@@ -761,6 +763,8 @@ void CInArchive::ReadUnpackInfo(
|
||||
folders.FoToCoderUnpackSizes[fo] = numCodersOutStreams;
|
||||
numCodersOutStreams += numCoders;
|
||||
folders.FoStartPackStreamIndex[fo] = packStreamIndex;
|
||||
if (numPackStreams > folders.NumPackStreams - packStreamIndex)
|
||||
ThrowIncorrect();
|
||||
packStreamIndex += numPackStreams;
|
||||
folders.FoToMainUnpackSizeIndex[fo] = (Byte)indexOfMainStream;
|
||||
}
|
||||
@@ -770,6 +774,8 @@ void CInArchive::ReadUnpackInfo(
|
||||
folders.FoStartPackStreamIndex[fo] = packStreamIndex;
|
||||
folders.FoCodersDataOffset[fo] = _inByteBack->GetPtr() - startBufPtr;
|
||||
folders.CodersData.CopyFrom(startBufPtr, dataSize);
|
||||
|
||||
// if (folders.NumPackStreams != packStreamIndex) ThrowUnsupported();
|
||||
}
|
||||
|
||||
WaitId(NID::kCodersUnpackSize);
|
||||
@@ -1144,9 +1150,8 @@ HRESULT CInArchive::ReadHeader(
|
||||
if (type == NID::kFilesInfo)
|
||||
{
|
||||
|
||||
CNum numFiles = ReadNum();
|
||||
const CNum numFiles = ReadNum();
|
||||
db.Files.ClearAndSetSize(numFiles);
|
||||
CNum i;
|
||||
/*
|
||||
db.Files.Reserve(numFiles);
|
||||
CNum i;
|
||||
@@ -1168,8 +1173,8 @@ HRESULT CInArchive::ReadHeader(
|
||||
|
||||
for (;;)
|
||||
{
|
||||
UInt64 type = ReadID();
|
||||
if (type == NID::kEnd)
|
||||
const UInt64 type2 = ReadID();
|
||||
if (type2 == NID::kEnd)
|
||||
break;
|
||||
UInt64 size = ReadNumber();
|
||||
if (size > _inByteBack->GetRem())
|
||||
@@ -1178,9 +1183,9 @@ HRESULT CInArchive::ReadHeader(
|
||||
switchProp.Set(this, _inByteBack->GetPtr(), (size_t)size, true);
|
||||
bool addPropIdToList = true;
|
||||
bool isKnownType = true;
|
||||
if (type > ((UInt32)1 << 30))
|
||||
if (type2 > ((UInt32)1 << 30))
|
||||
isKnownType = false;
|
||||
else switch ((UInt32)type)
|
||||
else switch ((UInt32)type2)
|
||||
{
|
||||
case NID::kName:
|
||||
{
|
||||
@@ -1214,7 +1219,7 @@ HRESULT CInArchive::ReadHeader(
|
||||
ReadBoolVector2(db.Files.Size(), boolVector);
|
||||
CStreamSwitch streamSwitch;
|
||||
streamSwitch.Set(this, &dataVector);
|
||||
for (i = 0; i < numFiles; i++)
|
||||
for (CNum i = 0; i < numFiles; i++)
|
||||
{
|
||||
CFileItem &file = db.Files[i];
|
||||
file.AttribDefined = boolVector[i];
|
||||
@@ -1257,7 +1262,7 @@ HRESULT CInArchive::ReadHeader(
|
||||
{
|
||||
ReadBoolVector(numFiles, emptyStreamVector);
|
||||
numEmptyStreams = 0;
|
||||
for (i = 0; i < (CNum)emptyStreamVector.Size(); i++)
|
||||
for (CNum i = 0; i < (CNum)emptyStreamVector.Size(); i++)
|
||||
if (emptyStreamVector[i])
|
||||
numEmptyStreams++;
|
||||
|
||||
@@ -1331,7 +1336,7 @@ HRESULT CInArchive::ReadHeader(
|
||||
if (isKnownType)
|
||||
{
|
||||
if (addPropIdToList)
|
||||
db.ArcInfo.FileInfoPopIDs.Add(type);
|
||||
db.ArcInfo.FileInfoPopIDs.Add(type2);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1352,6 +1357,9 @@ HRESULT CInArchive::ReadHeader(
|
||||
CNum sizeIndex = 0;
|
||||
|
||||
CNum numAntiItems = 0;
|
||||
|
||||
CNum i;
|
||||
|
||||
for (i = 0; i < numEmptyStreams; i++)
|
||||
if (antiFileVector[i])
|
||||
numAntiItems++;
|
||||
|
||||
@@ -87,6 +87,8 @@ struct CFolders
|
||||
return PackPositions[index + 1] - PackPositions[index];
|
||||
}
|
||||
|
||||
CFolders(): NumPackStreams(0), NumFolders(0) {}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
NumPackStreams = 0;
|
||||
|
||||
@@ -540,13 +540,13 @@ void COutArchive::WriteHeader(
|
||||
*/
|
||||
_useAlign = true;
|
||||
|
||||
unsigned i;
|
||||
|
||||
UInt64 packedSize = 0;
|
||||
for (i = 0; i < db.PackSizes.Size(); i++)
|
||||
packedSize += db.PackSizes[i];
|
||||
{
|
||||
UInt64 packSize = 0;
|
||||
FOR_VECTOR (i, db.PackSizes)
|
||||
packSize += db.PackSizes[i];
|
||||
headerOffset = packSize;
|
||||
}
|
||||
|
||||
headerOffset = packedSize;
|
||||
|
||||
WriteByte(NID::kHeader);
|
||||
|
||||
@@ -560,7 +560,7 @@ void COutArchive::WriteHeader(
|
||||
|
||||
CRecordVector<UInt64> unpackSizes;
|
||||
CUInt32DefVector digests;
|
||||
for (i = 0; i < db.Files.Size(); i++)
|
||||
FOR_VECTOR (i, db.Files)
|
||||
{
|
||||
const CFileItem &file = db.Files[i];
|
||||
if (!file.HasStream)
|
||||
@@ -588,14 +588,17 @@ void COutArchive::WriteHeader(
|
||||
CBoolVector emptyStreamVector;
|
||||
emptyStreamVector.ClearAndSetSize(db.Files.Size());
|
||||
unsigned numEmptyStreams = 0;
|
||||
for (i = 0; i < db.Files.Size(); i++)
|
||||
if (db.Files[i].HasStream)
|
||||
emptyStreamVector[i] = false;
|
||||
else
|
||||
{
|
||||
emptyStreamVector[i] = true;
|
||||
numEmptyStreams++;
|
||||
}
|
||||
{
|
||||
FOR_VECTOR (i, db.Files)
|
||||
if (db.Files[i].HasStream)
|
||||
emptyStreamVector[i] = false;
|
||||
else
|
||||
{
|
||||
emptyStreamVector[i] = true;
|
||||
numEmptyStreams++;
|
||||
}
|
||||
}
|
||||
|
||||
if (numEmptyStreams != 0)
|
||||
{
|
||||
WritePropBoolVector(NID::kEmptyStream, emptyStreamVector);
|
||||
@@ -605,7 +608,8 @@ void COutArchive::WriteHeader(
|
||||
antiVector.ClearAndSetSize(numEmptyStreams);
|
||||
bool thereAreEmptyFiles = false, thereAreAntiItems = false;
|
||||
unsigned cur = 0;
|
||||
for (i = 0; i < db.Files.Size(); i++)
|
||||
|
||||
FOR_VECTOR (i, db.Files)
|
||||
{
|
||||
const CFileItem &file = db.Files[i];
|
||||
if (file.HasStream)
|
||||
@@ -672,17 +676,21 @@ void COutArchive::WriteHeader(
|
||||
CBoolVector boolVector;
|
||||
boolVector.ClearAndSetSize(db.Files.Size());
|
||||
unsigned numDefined = 0;
|
||||
for (i = 0; i < db.Files.Size(); i++)
|
||||
|
||||
{
|
||||
bool defined = db.Files[i].AttribDefined;
|
||||
boolVector[i] = defined;
|
||||
if (defined)
|
||||
numDefined++;
|
||||
FOR_VECTOR (i, db.Files)
|
||||
{
|
||||
bool defined = db.Files[i].AttribDefined;
|
||||
boolVector[i] = defined;
|
||||
if (defined)
|
||||
numDefined++;
|
||||
}
|
||||
}
|
||||
|
||||
if (numDefined != 0)
|
||||
{
|
||||
WriteAlignedBoolHeader(boolVector, numDefined, NID::kWinAttrib, 4);
|
||||
for (i = 0; i < db.Files.Size(); i++)
|
||||
FOR_VECTOR (i, db.Files)
|
||||
{
|
||||
const CFileItem &file = db.Files[i];
|
||||
if (file.AttribDefined)
|
||||
|
||||
@@ -380,29 +380,33 @@ static inline bool IsExeFilter(CMethodId m)
|
||||
return false;
|
||||
}
|
||||
|
||||
static unsigned Get_FilterGroup_for_Folder(CRecordVector<CFilterMode2> &filters, const CFolderEx &f)
|
||||
static unsigned Get_FilterGroup_for_Folder(
|
||||
CRecordVector<CFilterMode2> &filters, const CFolderEx &f, bool extractFilter)
|
||||
{
|
||||
CFilterMode2 m;
|
||||
m.Id = 0;
|
||||
m.Delta = 0;
|
||||
m.Encrypted = f.IsEncrypted();
|
||||
|
||||
const CCoderInfo &coder = f.Coders[f.UnpackCoder];
|
||||
if (extractFilter)
|
||||
{
|
||||
const CCoderInfo &coder = f.Coders[f.UnpackCoder];
|
||||
|
||||
if (coder.MethodID == k_Delta)
|
||||
{
|
||||
if (coder.Props.Size() == 1)
|
||||
if (coder.MethodID == k_Delta)
|
||||
{
|
||||
m.Delta = (unsigned)coder.Props[0] + 1;
|
||||
m.Id = k_Delta;
|
||||
if (coder.Props.Size() == 1)
|
||||
{
|
||||
m.Delta = (unsigned)coder.Props[0] + 1;
|
||||
m.Id = k_Delta;
|
||||
}
|
||||
}
|
||||
else if (IsExeFilter(coder.MethodID))
|
||||
{
|
||||
m.Id = (UInt32)coder.MethodID;
|
||||
if (m.Id == k_BCJ2)
|
||||
m.Id = k_BCJ;
|
||||
m.SetDelta();
|
||||
}
|
||||
}
|
||||
else if (IsExeFilter(coder.MethodID))
|
||||
{
|
||||
m.Id = (UInt32)coder.MethodID;
|
||||
if (m.Id == k_BCJ2)
|
||||
m.Id = k_BCJ;
|
||||
m.SetDelta();
|
||||
}
|
||||
|
||||
return GetGroup(filters, m);
|
||||
@@ -567,14 +571,17 @@ static const char *g_Exts =
|
||||
" iso bin nrg mdf img pdi tar cpio xpi"
|
||||
" vfd vhd vud vmc vsv"
|
||||
" 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"
|
||||
" inl inc idl acf asa"
|
||||
" h hpp hxx c cpp cxx m mm go swift"
|
||||
" rc java cs rs pas bas vb cls ctl frm dlg def"
|
||||
" f77 f f90 f95"
|
||||
" asm sql manifest dep"
|
||||
" asm s"
|
||||
" sql manifest dep"
|
||||
" mak clw csproj vcproj sln dsp dsw"
|
||||
" class"
|
||||
" bat cmd"
|
||||
" bat cmd bash sh"
|
||||
" 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"
|
||||
" awk sed hta js json php php3 php4 php5 phptml pl pm py pyo rb tcl ts vbs"
|
||||
" text txt tex ans asc srt reg ini doc docx mcw dot rtf hlp xls xlr xlt xlw ppt pdf"
|
||||
" sxc sxd sxi sxg sxw stc sti stw stm odt ott odg otg odp otp ods ots odf"
|
||||
" abw afp cwk lwp wpd wps wpt wrf wri"
|
||||
@@ -1574,7 +1581,7 @@ HRESULT Update(
|
||||
return E_NOTIMPL;
|
||||
*/
|
||||
|
||||
UInt64 startBlockSize = db != 0 ? db->ArcInfo.StartPosition: 0;
|
||||
UInt64 startBlockSize = db ? db->ArcInfo.StartPosition: 0;
|
||||
if (startBlockSize > 0 && !options.RemoveSfxBlock)
|
||||
{
|
||||
RINOK(WriteRange(inStream, seqOutStream, 0, startBlockSize, NULL));
|
||||
@@ -1588,8 +1595,21 @@ HRESULT Update(
|
||||
CRecordVector<CFilterMode2> filters;
|
||||
CObjectVector<CSolidGroup> groups;
|
||||
bool thereAreRepacks = false;
|
||||
|
||||
bool useFilters = options.UseFilters;
|
||||
if (useFilters)
|
||||
{
|
||||
const CCompressionMethodMode &method = *options.Method;
|
||||
|
||||
FOR_VECTOR (i, method.Methods)
|
||||
if (IsFilterMethod(method.Methods[i].Id))
|
||||
{
|
||||
useFilters = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (db != 0)
|
||||
if (db)
|
||||
{
|
||||
fileIndexToUpdateIndexMap.Alloc(db->Files.Size());
|
||||
unsigned i;
|
||||
@@ -1635,16 +1655,18 @@ HRESULT Update(
|
||||
CFolderEx f;
|
||||
db->ParseFolderEx(i, f);
|
||||
|
||||
bool isEncrypted = f.IsEncrypted();
|
||||
|
||||
unsigned groupIndex = Get_FilterGroup_for_Folder(filters, f);
|
||||
const bool isEncrypted = f.IsEncrypted();
|
||||
const bool needCopy = (numCopyItems == numUnpackStreams);
|
||||
const bool extractFilter = (useFilters || needCopy);
|
||||
|
||||
unsigned groupIndex = Get_FilterGroup_for_Folder(filters, f, extractFilter);
|
||||
|
||||
while (groupIndex >= groups.Size())
|
||||
groups.AddNew();
|
||||
|
||||
groups[groupIndex].folderRefs.Add(rep);
|
||||
|
||||
if (numCopyItems == numUnpackStreams)
|
||||
if (needCopy)
|
||||
complexity += db->GetFolderFullPackSize(i);
|
||||
else
|
||||
{
|
||||
@@ -1659,17 +1681,18 @@ HRESULT Update(
|
||||
}
|
||||
|
||||
UInt64 inSizeForReduce = 0;
|
||||
unsigned i;
|
||||
for (i = 0; i < updateItems.Size(); i++)
|
||||
{
|
||||
const CUpdateItem &ui = updateItems[i];
|
||||
if (ui.NewData)
|
||||
FOR_VECTOR (i, updateItems)
|
||||
{
|
||||
complexity += ui.Size;
|
||||
if (numSolidFiles != 1)
|
||||
inSizeForReduce += ui.Size;
|
||||
else if (inSizeForReduce < ui.Size)
|
||||
inSizeForReduce = ui.Size;
|
||||
const CUpdateItem &ui = updateItems[i];
|
||||
if (ui.NewData)
|
||||
{
|
||||
complexity += ui.Size;
|
||||
if (numSolidFiles != 1)
|
||||
inSizeForReduce += ui.Size;
|
||||
else if (inSizeForReduce < ui.Size)
|
||||
inSizeForReduce = ui.Size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1729,23 +1752,9 @@ HRESULT Update(
|
||||
|
||||
// ---------- Split files to groups ----------
|
||||
|
||||
bool useFilters = options.UseFilters;
|
||||
const CCompressionMethodMode &method = *options.Method;
|
||||
|
||||
if (useFilters)
|
||||
for (i = 0; i < method.Methods.Size(); i++)
|
||||
if (IsFilterMethod(method.Methods[i].Id))
|
||||
{
|
||||
useFilters = false;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
if (!method.Bonds.IsEmpty())
|
||||
useFilters = false;
|
||||
*/
|
||||
|
||||
for (i = 0; i < updateItems.Size(); i++)
|
||||
FOR_VECTOR (i, updateItems)
|
||||
{
|
||||
const CUpdateItem &ui = updateItems[i];
|
||||
if (!ui.NewData || !ui.HasStream())
|
||||
@@ -1849,6 +1858,8 @@ HRESULT Update(
|
||||
/* ---------- Write non-AUX dirs and Empty files ---------- */
|
||||
CUIntVector emptyRefs;
|
||||
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < updateItems.Size(); i++)
|
||||
{
|
||||
const CUpdateItem &ui = updateItems[i];
|
||||
@@ -1911,7 +1922,8 @@ HRESULT Update(
|
||||
const CFilterMode2 &filterMode = filters[groupIndex];
|
||||
|
||||
CCompressionMethodMode method = *options.Method;
|
||||
HRESULT res = MakeExeMethod(method, filterMode,
|
||||
{
|
||||
HRESULT res = MakeExeMethod(method, filterMode,
|
||||
#ifdef _7ZIP_ST
|
||||
false
|
||||
#else
|
||||
@@ -1919,7 +1931,8 @@ HRESULT Update(
|
||||
#endif
|
||||
);
|
||||
|
||||
RINOK(res);
|
||||
RINOK(res);
|
||||
}
|
||||
|
||||
if (filterMode.Encrypted)
|
||||
{
|
||||
@@ -2153,7 +2166,13 @@ HRESULT Update(
|
||||
#ifndef _7ZIP_ST
|
||||
if (options.MultiThreadMixer)
|
||||
{
|
||||
// 16.00: hang was fixed : for case if decoding was not finished.
|
||||
// We close CBinderInStream and it calls CStreamBinder::CloseRead()
|
||||
inStreamSizeCount.Release();
|
||||
sbInStream.Release();
|
||||
|
||||
threadDecoder.WaitExecuteFinish();
|
||||
|
||||
HRESULT decodeRes = threadDecoder.Result;
|
||||
// if (res == k_My_HRESULT_CRC_ERROR)
|
||||
if (decodeRes == S_FALSE)
|
||||
@@ -2252,8 +2271,12 @@ HRESULT Update(
|
||||
CRecordVector<CRefItem> refItems;
|
||||
refItems.ClearAndSetSize(numFiles);
|
||||
bool sortByType = (options.UseTypeSorting && numSolidFiles > 1);
|
||||
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < numFiles; i++)
|
||||
refItems[i] = CRefItem(group.Indices[i], updateItems[group.Indices[i]], sortByType);
|
||||
|
||||
CSortParam sortParam;
|
||||
// sortParam.TreeFolders = &treeFolders;
|
||||
sortParam.SortByType = sortByType;
|
||||
|
||||
@@ -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 \
|
||||
@@ -65,7 +64,6 @@ COMPRESS_OBJS = \
|
||||
|
||||
AR_COMMON_OBJS = \
|
||||
$O\CoderMixer2.obj \
|
||||
$O\CrossThreadProgress.obj \
|
||||
$O\HandlerOut.obj \
|
||||
$O\InStreamWithCRC.obj \
|
||||
$O\ItemNameUtils.obj \
|
||||
|
||||
@@ -343,16 +343,17 @@ HRESULT CHandler::ParseLongNames(IInStream *stream)
|
||||
if (item.Size > ((UInt32)1 << 30))
|
||||
return S_FALSE;
|
||||
RINOK(stream->Seek(item.GetDataPos(), STREAM_SEEK_SET, NULL));
|
||||
size_t size = (size_t)item.Size;
|
||||
const size_t size = (size_t)item.Size;
|
||||
|
||||
CByteArr p(size);
|
||||
RINOK(ReadStream_FALSE(stream, p, size));
|
||||
|
||||
for (i = 0; i < _items.Size(); i++)
|
||||
{
|
||||
CItem &item = _items[i];
|
||||
if (item.Name[0] != '/')
|
||||
CItem &item2 = _items[i];
|
||||
if (item2.Name[0] != '/')
|
||||
continue;
|
||||
const char *ptr = item.Name.Ptr(1);
|
||||
const char *ptr = item2.Name.Ptr(1);
|
||||
const char *end;
|
||||
UInt32 pos = ConvertStringToUInt32(ptr, &end);
|
||||
if (*end != 0 || end == ptr)
|
||||
@@ -369,8 +370,9 @@ HRESULT CHandler::ParseLongNames(IInStream *stream)
|
||||
break;
|
||||
pos++;
|
||||
}
|
||||
item.Name.SetFrom((const char *)(p + start), pos - start);
|
||||
item2.Name.SetFrom((const char *)(p + start), pos - start);
|
||||
}
|
||||
|
||||
_longNames_FileIndex = fileIndex;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@@ -348,15 +348,19 @@ STDMETHODIMP CHandler::Open(IInStream *inStream,
|
||||
|
||||
CMyComPtr<IInStream> nextStream = inStream;
|
||||
bool prevChecked = false;
|
||||
UString startVolName;
|
||||
bool startVolName_was_Requested = false;
|
||||
UInt64 numItems = 0;
|
||||
unsigned numTempVolumes = 0;
|
||||
// try
|
||||
{
|
||||
while (nextStream != NULL)
|
||||
while (nextStream)
|
||||
{
|
||||
CDatabaseEx db;
|
||||
db.Stream = nextStream;
|
||||
|
||||
HRESULT res = archive.Open(db, maxCheckStartPosition);
|
||||
|
||||
_errorInHeaders |= archive.HeaderError;
|
||||
_errorInHeaders |= archive.ErrorInNames;
|
||||
_unexpectedEnd |= archive.UnexpectedEnd;
|
||||
@@ -426,6 +430,7 @@ STDMETHODIMP CHandler::Open(IInStream *inStream,
|
||||
for (;;)
|
||||
{
|
||||
const COtherArc *otherArc = NULL;
|
||||
|
||||
if (!prevChecked)
|
||||
{
|
||||
if (numTempVolumes == 0)
|
||||
@@ -449,18 +454,35 @@ STDMETHODIMP CHandler::Open(IInStream *inStream,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!otherArc)
|
||||
{
|
||||
const CInArcInfo &ai = m_Database.Volumes.Back().ArcInfo;
|
||||
if (ai.IsThereNext())
|
||||
otherArc = &ai.NextArc;
|
||||
}
|
||||
|
||||
if (!otherArc)
|
||||
break;
|
||||
if (!openVolumeCallback)
|
||||
break;
|
||||
// printf("\n%s", otherArc->FileName);
|
||||
const UString fullName = MultiByteToUnicodeString(otherArc->FileName, CP_ACP);
|
||||
|
||||
if (!startVolName_was_Requested)
|
||||
{
|
||||
// some "bad" cab example can contain the link to itself.
|
||||
startVolName_was_Requested = true;
|
||||
{
|
||||
NCOM::CPropVariant prop;
|
||||
RINOK(openVolumeCallback->GetProperty(kpidName, &prop));
|
||||
if (prop.vt == VT_BSTR)
|
||||
startVolName = prop.bstrVal;
|
||||
}
|
||||
if (fullName == startVolName)
|
||||
break;
|
||||
}
|
||||
|
||||
HRESULT result = openVolumeCallback->GetStream(fullName, &nextStream);
|
||||
if (result == S_OK)
|
||||
break;
|
||||
@@ -572,6 +594,7 @@ public:
|
||||
HRESULT FlushCorrupted(unsigned folderIndex);
|
||||
HRESULT Unsupported();
|
||||
|
||||
bool NeedMoreWrite() const { return (m_FolderSize > m_PosInFolder); }
|
||||
UInt64 GetRemain() const { return m_FolderSize - m_PosInFolder; }
|
||||
UInt64 GetPosInFolder() const { return m_PosInFolder; }
|
||||
};
|
||||
@@ -781,6 +804,7 @@ HRESULT CFolderOutStream::Write2(const void *data, UInt32 size, UInt32 *processe
|
||||
realProcessed += size;
|
||||
if (processedSize)
|
||||
*processedSize = realProcessed;
|
||||
m_PosInFolder += size;
|
||||
return S_OK;
|
||||
// return E_FAIL;
|
||||
}
|
||||
@@ -830,9 +854,7 @@ STDMETHODIMP CFolderOutStream::Write(const void *data, UInt32 size, UInt32 *proc
|
||||
|
||||
HRESULT CFolderOutStream::FlushCorrupted(unsigned folderIndex)
|
||||
{
|
||||
UInt64 remain = GetRemain();
|
||||
|
||||
if (remain == 0)
|
||||
if (!NeedMoreWrite())
|
||||
{
|
||||
CMyComPtr<IArchiveExtractCallbackMessage> callbackMessage;
|
||||
m_ExtractCallback.QueryInterface(IID_IArchiveExtractCallbackMessage, &callbackMessage);
|
||||
@@ -843,16 +865,16 @@ HRESULT CFolderOutStream::FlushCorrupted(unsigned folderIndex)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
const unsigned kBufSize = (1 << 10);
|
||||
const unsigned kBufSize = (1 << 12);
|
||||
Byte buf[kBufSize];
|
||||
for (unsigned i = 0; i < kBufSize; i++)
|
||||
buf[i] = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
UInt64 remain = GetRemain();
|
||||
if (remain == 0)
|
||||
if (!NeedMoreWrite())
|
||||
return S_OK;
|
||||
UInt64 remain = GetRemain();
|
||||
UInt32 size = (remain < kBufSize ? (UInt32)remain : (UInt32)kBufSize);
|
||||
UInt32 processedSizeLocal = 0;
|
||||
RINOK(Write2(buf, size, &processedSizeLocal, false));
|
||||
@@ -937,8 +959,15 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
|
||||
CRecordVector<bool> extractStatuses;
|
||||
|
||||
for (i = 0; i < numItems;)
|
||||
for (i = 0;;)
|
||||
{
|
||||
lps->OutSize = totalUnPacked;
|
||||
lps->InSize = totalPacked;
|
||||
RINOK(lps->SetCur());
|
||||
|
||||
if (i >= numItems)
|
||||
break;
|
||||
|
||||
unsigned index = allFilesMode ? i : indices[i];
|
||||
|
||||
const CMvItem &mvItem = m_Database.Items[index];
|
||||
@@ -988,11 +1017,11 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
for (; i < numItems; i++)
|
||||
{
|
||||
unsigned indexNext = allFilesMode ? i : indices[i];
|
||||
const CMvItem &mvItem = m_Database.Items[indexNext];
|
||||
const CItem &item = m_Database.Volumes[mvItem.VolumeIndex].Items[mvItem.ItemIndex];
|
||||
if (item.IsDir())
|
||||
const CMvItem &mvItem2 = m_Database.Items[indexNext];
|
||||
const CItem &item2 = m_Database.Volumes[mvItem2.VolumeIndex].Items[mvItem2.ItemIndex];
|
||||
if (item2.IsDir())
|
||||
continue;
|
||||
int newFolderIndex = m_Database.GetFolderIndex(&mvItem);
|
||||
int newFolderIndex = m_Database.GetFolderIndex(&mvItem2);
|
||||
|
||||
if (newFolderIndex != folderIndex)
|
||||
break;
|
||||
@@ -1000,13 +1029,9 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
extractStatuses.Add(false);
|
||||
extractStatuses.Add(true);
|
||||
startIndex++;
|
||||
curUnpack = item.GetEndOffset();
|
||||
curUnpack = item2.GetEndOffset();
|
||||
}
|
||||
|
||||
lps->OutSize = totalUnPacked;
|
||||
lps->InSize = totalPacked;
|
||||
RINOK(lps->SetCur());
|
||||
|
||||
CFolderOutStream *cabFolderOutStream = new CFolderOutStream;
|
||||
CMyComPtr<ISequentialOutStream> outStream(cabFolderOutStream);
|
||||
|
||||
@@ -1071,7 +1096,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
bool keepInputBuffer = false;
|
||||
bool thereWasNotAlignedChunk = false;
|
||||
|
||||
for (UInt32 bl = 0; cabFolderOutStream->GetRemain() != 0;)
|
||||
for (UInt32 bl = 0; cabFolderOutStream->NeedMoreWrite();)
|
||||
{
|
||||
if (volIndex >= m_Database.Volumes.Size())
|
||||
{
|
||||
@@ -1079,16 +1104,16 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
break;
|
||||
}
|
||||
|
||||
const CDatabaseEx &db = m_Database.Volumes[volIndex];
|
||||
const CFolder &folder = db.Folders[locFolderIndex];
|
||||
const CDatabaseEx &db2 = m_Database.Volumes[volIndex];
|
||||
const CFolder &folder2 = db2.Folders[locFolderIndex];
|
||||
|
||||
if (bl == 0)
|
||||
{
|
||||
cabBlockInStreamSpec->ReservedSize = db.ArcInfo.GetDataBlockReserveSize();
|
||||
RINOK(db.Stream->Seek(db.StartPosition + folder.DataStart, STREAM_SEEK_SET, NULL));
|
||||
cabBlockInStreamSpec->ReservedSize = db2.ArcInfo.GetDataBlockReserveSize();
|
||||
RINOK(db2.Stream->Seek(db2.StartPosition + folder2.DataStart, STREAM_SEEK_SET, NULL));
|
||||
}
|
||||
|
||||
if (bl == folder.NumDataBlocks)
|
||||
if (bl == folder2.NumDataBlocks)
|
||||
{
|
||||
/*
|
||||
CFolder::NumDataBlocks (CFFOLDER::cCFData in CAB specification) is 16-bit.
|
||||
@@ -1113,7 +1138,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
cabBlockInStreamSpec->InitForNewBlock();
|
||||
|
||||
UInt32 packSize, unpackSize;
|
||||
res = cabBlockInStreamSpec->PreRead(db.Stream, packSize, unpackSize);
|
||||
res = cabBlockInStreamSpec->PreRead(db2.Stream, packSize, unpackSize);
|
||||
if (res == S_FALSE)
|
||||
break;
|
||||
RINOK(res);
|
||||
@@ -1155,7 +1180,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
UInt64 unpackSize64 = unpackSize;
|
||||
UInt32 packSizeChunk = cabBlockInStreamSpec->GetPackSizeAvail();
|
||||
|
||||
switch (folder.GetMethod())
|
||||
switch (folder2.GetMethod())
|
||||
{
|
||||
case NHeader::NMethod::kNone:
|
||||
res = copyCoder->Code(cabBlockInStream, outStream, NULL, &unpackSize64, NULL);
|
||||
@@ -1213,7 +1238,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
}
|
||||
}
|
||||
|
||||
if (res != S_OK || cabFolderOutStream->GetRemain() != 0)
|
||||
if (res != S_OK || cabFolderOutStream->NeedMoreWrite())
|
||||
{
|
||||
RINOK(cabFolderOutStream->FlushCorrupted(folderIndex2));
|
||||
}
|
||||
|
||||
@@ -67,6 +67,7 @@ void CInArchive::ReadOtherArc(COtherArc &oa)
|
||||
ReadName(oa.DiskName);
|
||||
}
|
||||
|
||||
|
||||
struct CSignatureFinder
|
||||
{
|
||||
Byte *Buf;
|
||||
@@ -100,6 +101,7 @@ struct CSignatureFinder
|
||||
HRESULT Find();
|
||||
};
|
||||
|
||||
|
||||
HRESULT CSignatureFinder::Find()
|
||||
{
|
||||
for (;;)
|
||||
@@ -156,6 +158,7 @@ HRESULT CSignatureFinder::Find()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool CInArcInfo::Parse(const Byte *p)
|
||||
{
|
||||
if (Get32(p + 0x0C) != 0 ||
|
||||
@@ -177,6 +180,7 @@ bool CInArcInfo::Parse(const Byte *p)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
HRESULT CInArchive::Open2(CDatabaseEx &db, const UInt64 *searchHeaderSizeLimit)
|
||||
{
|
||||
IsArc = false;
|
||||
@@ -286,7 +290,9 @@ HRESULT CInArchive::Open2(CDatabaseEx &db, const UInt64 *searchHeaderSizeLimit)
|
||||
if (ai.IsThereNext()) ReadOtherArc(ai.NextArc);
|
||||
|
||||
UInt32 i;
|
||||
|
||||
db.Folders.ClearAndReserve(ai.NumFolders);
|
||||
|
||||
for (i = 0; i < ai.NumFolders; i++)
|
||||
{
|
||||
Read(p, 8);
|
||||
@@ -311,6 +317,7 @@ HRESULT CInArchive::Open2(CDatabaseEx &db, const UInt64 *searchHeaderSizeLimit)
|
||||
}
|
||||
|
||||
db.Items.ClearAndReserve(ai.NumFiles);
|
||||
|
||||
for (i = 0; i < ai.NumFiles; i++)
|
||||
{
|
||||
Read(p, 16);
|
||||
@@ -324,6 +331,7 @@ HRESULT CInArchive::Open2(CDatabaseEx &db, const UInt64 *searchHeaderSizeLimit)
|
||||
item.Attributes = Get16(p + 14);
|
||||
|
||||
ReadName(item.Name);
|
||||
|
||||
if (item.GetFolderIndex(db.Folders.Size()) >= (int)db.Folders.Size())
|
||||
{
|
||||
HeaderError = true;
|
||||
@@ -336,6 +344,7 @@ HRESULT CInArchive::Open2(CDatabaseEx &db, const UInt64 *searchHeaderSizeLimit)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
HRESULT CInArchive::Open(CDatabaseEx &db, const UInt64 *searchHeaderSizeLimit)
|
||||
{
|
||||
try
|
||||
@@ -370,6 +379,7 @@ static int CompareMvItems(const CMvItem *p1, const CMvItem *p2, void *param)
|
||||
return MyCompare(p1->ItemIndex, p2->ItemIndex);
|
||||
}
|
||||
|
||||
|
||||
bool CMvDatabaseEx::AreItemsEqual(unsigned i1, unsigned i2)
|
||||
{
|
||||
const CMvItem *p1 = &Items[i1];
|
||||
@@ -384,12 +394,15 @@ bool CMvDatabaseEx::AreItemsEqual(unsigned i1, unsigned i2)
|
||||
&& item1.Name == item2.Name;
|
||||
}
|
||||
|
||||
|
||||
void CMvDatabaseEx::FillSortAndShrink()
|
||||
{
|
||||
Items.Clear();
|
||||
StartFolderOfVol.Clear();
|
||||
FolderStartFileIndex.Clear();
|
||||
|
||||
int offset = 0;
|
||||
|
||||
FOR_VECTOR (v, Volumes)
|
||||
{
|
||||
const CDatabaseEx &db = Volumes[v];
|
||||
@@ -422,11 +435,12 @@ void CMvDatabaseEx::FillSortAndShrink()
|
||||
FOR_VECTOR (i, Items)
|
||||
{
|
||||
int folderIndex = GetFolderIndex(&Items[i]);
|
||||
if (folderIndex >= (int)FolderStartFileIndex.Size())
|
||||
while (folderIndex >= (int)FolderStartFileIndex.Size())
|
||||
FolderStartFileIndex.Add(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool CMvDatabaseEx::Check()
|
||||
{
|
||||
for (unsigned v = 1; v < Volumes.Size(); v++)
|
||||
@@ -444,9 +458,11 @@ bool CMvDatabaseEx::Check()
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
UInt32 beginPos = 0;
|
||||
UInt64 endPos = 0;
|
||||
int prevFolder = -2;
|
||||
|
||||
FOR_VECTOR (i, Items)
|
||||
{
|
||||
const CMvItem &mvItem = Items[i];
|
||||
@@ -456,15 +472,19 @@ bool CMvDatabaseEx::Check()
|
||||
const CItem &item = Volumes[mvItem.VolumeIndex].Items[mvItem.ItemIndex];
|
||||
if (item.IsDir())
|
||||
continue;
|
||||
|
||||
int folderIndex = GetFolderIndex(&mvItem);
|
||||
|
||||
if (folderIndex != prevFolder)
|
||||
prevFolder = folderIndex;
|
||||
else if (item.Offset < endPos &&
|
||||
(item.Offset != beginPos || item.GetEndOffset() != endPos))
|
||||
return false;
|
||||
|
||||
beginPos = item.Offset;
|
||||
endPos = item.GetEndOffset();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ struct COtherArc
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct CArchInfo
|
||||
{
|
||||
Byte VersionMinor; // cabinet file format version, minor
|
||||
@@ -65,6 +66,7 @@ struct CArchInfo
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct CInArcInfo: public CArchInfo
|
||||
{
|
||||
UInt32 Size; // size of this cabinet file in bytes
|
||||
@@ -105,17 +107,20 @@ struct CDatabase
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct CDatabaseEx: public CDatabase
|
||||
{
|
||||
CMyComPtr<IInStream> Stream;
|
||||
};
|
||||
|
||||
|
||||
struct CMvItem
|
||||
{
|
||||
unsigned VolumeIndex;
|
||||
unsigned ItemIndex;
|
||||
};
|
||||
|
||||
|
||||
class CMvDatabaseEx
|
||||
{
|
||||
bool AreItemsEqual(unsigned i1, unsigned i2);
|
||||
|
||||
@@ -154,7 +154,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
case kpidBlock:
|
||||
if (m_Database.LowLevel)
|
||||
prop = item.Section;
|
||||
else if (item.Section != 0)
|
||||
else if (item.Section != 0 && item.Section < m_Database.Sections.Size())
|
||||
prop = m_Database.GetFolder(index);
|
||||
break;
|
||||
|
||||
@@ -545,7 +545,11 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
currentTotalSize += item.Size;
|
||||
continue;
|
||||
}
|
||||
const CSectionInfo §ion = m_Database.Sections[(unsigned)item.Section];
|
||||
|
||||
if (sectionIndex >= m_Database.Sections.Size())
|
||||
continue;
|
||||
|
||||
const CSectionInfo §ion = m_Database.Sections[(unsigned)sectionIndex];
|
||||
if (section.IsLzx())
|
||||
{
|
||||
const CLzxInfo &lzxInfo = section.Methods[0].LzxInfo;
|
||||
@@ -621,6 +625,18 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sectionIndex >= m_Database.Sections.Size())
|
||||
{
|
||||
// we must report error here;
|
||||
CMyComPtr<ISequentialOutStream> realOutStream;
|
||||
RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
|
||||
if (!testMode && !realOutStream)
|
||||
continue;
|
||||
RINOK(extractCallback->PrepareOperation(askMode));
|
||||
RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kHeadersError));
|
||||
continue;
|
||||
}
|
||||
|
||||
const CSectionInfo §ion = m_Database.Sections[(unsigned)sectionIndex];
|
||||
|
||||
if (!section.IsLzx())
|
||||
|
||||
@@ -667,13 +667,15 @@ static int CompareFiles(const unsigned *p1, const unsigned *p2, void *param)
|
||||
return -1;
|
||||
if (isDir2)
|
||||
{
|
||||
if (isDir1)
|
||||
return MyCompare(*p1, *p2);
|
||||
return 1;
|
||||
if (!isDir1)
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
RINOZ(MyCompare(item1.Section, item2.Section));
|
||||
RINOZ(MyCompare(item1.Offset, item2.Offset));
|
||||
RINOZ(MyCompare(item1.Size, item2.Size));
|
||||
}
|
||||
RINOZ(MyCompare(item1.Section, item2.Section));
|
||||
RINOZ(MyCompare(item1.Offset, item2.Offset));
|
||||
RINOZ(MyCompare(item1.Size, item2.Size));
|
||||
return MyCompare(*p1, *p2);
|
||||
}
|
||||
|
||||
@@ -716,6 +718,19 @@ bool CFilesDatabase::Check()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CFilesDatabase::CheckSectionRefs()
|
||||
{
|
||||
FOR_VECTOR (i, Indices)
|
||||
{
|
||||
const CItem &item = Items[Indices[i]];
|
||||
if (item.Section == 0 || item.IsDir())
|
||||
continue;
|
||||
if (item.Section >= Sections.Size())
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static int inline GetLog(UInt32 num)
|
||||
{
|
||||
for (int i = 0; i < 32; i++)
|
||||
@@ -745,10 +760,10 @@ HRESULT CInArchive::OpenHighLevel(IInStream *inStream, CFilesDatabase &database)
|
||||
}
|
||||
}
|
||||
|
||||
unsigned i;
|
||||
for (i = 1; i < database.Sections.Size(); i++)
|
||||
unsigned si;
|
||||
for (si = 1; si < database.Sections.Size(); si++)
|
||||
{
|
||||
CSectionInfo §ion = database.Sections[i];
|
||||
CSectionInfo §ion = database.Sections[si];
|
||||
AString sectionPrefix = GetSectionPrefix(section.Name);
|
||||
{
|
||||
// Content
|
||||
@@ -993,6 +1008,8 @@ HRESULT CInArchive::Open2(IInStream *inStream,
|
||||
return S_OK;
|
||||
}
|
||||
RINOK(res);
|
||||
if (!database.CheckSectionRefs())
|
||||
HeadersError = true;
|
||||
database.LowLevel = false;
|
||||
}
|
||||
catch(...)
|
||||
|
||||
@@ -186,18 +186,24 @@ public:
|
||||
UInt64 GetFolder(unsigned fileIndex) const
|
||||
{
|
||||
const CItem &item = Items[Indices[fileIndex]];
|
||||
const CSectionInfo §ion = Sections[(unsigned)item.Section];
|
||||
if (section.IsLzx())
|
||||
return section.Methods[0].LzxInfo.GetFolder(item.Offset);
|
||||
if (item.Section < Sections.Size())
|
||||
{
|
||||
const CSectionInfo §ion = Sections[(unsigned)item.Section];
|
||||
if (section.IsLzx())
|
||||
return section.Methods[0].LzxInfo.GetFolder(item.Offset);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
UInt64 GetLastFolder(unsigned fileIndex) const
|
||||
{
|
||||
const CItem &item = Items[Indices[fileIndex]];
|
||||
const CSectionInfo §ion = Sections[(unsigned)item.Section];
|
||||
if (section.IsLzx())
|
||||
return section.Methods[0].LzxInfo.GetFolder(item.Offset + item.Size - 1);
|
||||
if (item.Section < Sections.Size())
|
||||
{
|
||||
const CSectionInfo §ion = Sections[(unsigned)item.Section];
|
||||
if (section.IsLzx())
|
||||
return section.Methods[0].LzxInfo.GetFolder(item.Offset + item.Size - 1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -217,6 +223,7 @@ public:
|
||||
void SetIndices();
|
||||
void Sort();
|
||||
bool Check();
|
||||
bool CheckSectionRefs();
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -167,7 +167,7 @@ HRESULT CDatabase::ReadSector(IInStream *inStream, Byte *buf, unsigned sectorSiz
|
||||
{
|
||||
UpdatePhySize(((UInt64)sid + 2) << sectorSizeBits);
|
||||
RINOK(inStream->Seek((((UInt64)sid + 1) << sectorSizeBits), STREAM_SEEK_SET, NULL));
|
||||
return ReadStream_FALSE(inStream, buf, (UInt32)1 << sectorSizeBits);
|
||||
return ReadStream_FALSE(inStream, buf, (size_t)1 << sectorSizeBits);
|
||||
}
|
||||
|
||||
HRESULT CDatabase::ReadIDs(IInStream *inStream, Byte *buf, unsigned sectorSizeBits, UInt32 sid, UInt32 *dest)
|
||||
@@ -571,23 +571,30 @@ HRESULT CDatabase::Open(IInStream *inStream)
|
||||
RINOK(AddNode(-1, root.SonDid));
|
||||
|
||||
unsigned numCabs = 0;
|
||||
|
||||
FOR_VECTOR (i, Refs)
|
||||
{
|
||||
const CItem &item = Items[Refs[i].Did];
|
||||
if (item.IsDir() || numCabs > 1)
|
||||
continue;
|
||||
bool isMsiName;
|
||||
UString msiName = ConvertName(item.Name, isMsiName);
|
||||
if (isMsiName)
|
||||
const UString msiName = ConvertName(item.Name, isMsiName);
|
||||
if (isMsiName && !msiName.IsEmpty())
|
||||
{
|
||||
// bool isThereExt = (msiName.Find(L'.') >= 0);
|
||||
bool isMsiSpec = (msiName[0] == k_Msi_SpecChar);
|
||||
if (msiName.Len() >= 4 && StringsAreEqualNoCase_Ascii(msiName.RightPtr(4), ".cab")
|
||||
|| msiName.Len() >= 3 && msiName[0] != k_Msi_SpecChar && StringsAreEqualNoCase_Ascii(msiName.RightPtr(3), "exe"))
|
||||
|| !isMsiSpec && msiName.Len() >= 3 && StringsAreEqualNoCase_Ascii(msiName.RightPtr(3), "exe")
|
||||
// || !isMsiSpec && !isThereExt
|
||||
)
|
||||
|
||||
{
|
||||
numCabs++;
|
||||
MainSubfile = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (numCabs > 1)
|
||||
MainSubfile = -1;
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -81,7 +81,7 @@ HRESULT CMultiMethodProps::SetProperty(const wchar_t *nameSpec, const PROPVARIAN
|
||||
}
|
||||
|
||||
UInt32 number;
|
||||
int index = ParseStringToUInt32(name, number);
|
||||
unsigned index = ParseStringToUInt32(name, number);
|
||||
UString realName = name.Ptr(index);
|
||||
if (index == 0)
|
||||
{
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -583,13 +583,13 @@ HRESULT CHandler::ReadBlock(UInt64 blockIndex, Byte *dest, size_t blockSize)
|
||||
}
|
||||
}
|
||||
|
||||
bool be = _h.be;
|
||||
const Byte *p = _data + (_curBlocksOffset + (UInt32)blockIndex * 4);
|
||||
UInt32 start = (blockIndex == 0 ? _curBlocksOffset + _curNumBlocks * 4: Get32(p - 4));
|
||||
UInt32 end = Get32(p);
|
||||
const bool be = _h.be;
|
||||
const Byte *p2 = _data + (_curBlocksOffset + (UInt32)blockIndex * 4);
|
||||
const UInt32 start = (blockIndex == 0 ? _curBlocksOffset + _curNumBlocks * 4: Get32(p2 - 4));
|
||||
const UInt32 end = Get32(p2);
|
||||
if (end < start || end > _size)
|
||||
return S_FALSE;
|
||||
UInt32 inSize = end - start;
|
||||
const UInt32 inSize = end - start;
|
||||
|
||||
if (_method == k_Flags_Method_LZMA)
|
||||
{
|
||||
@@ -707,7 +707,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
{
|
||||
RINOK(hres);
|
||||
{
|
||||
HRESULT hres = copyCoder->Code(inSeqStream, outStream, NULL, NULL, progress);
|
||||
hres = copyCoder->Code(inSeqStream, outStream, NULL, NULL, progress);
|
||||
if (hres == S_OK)
|
||||
{
|
||||
if (copyCoderSpec->TotalSize == curSize)
|
||||
|
||||
@@ -26,6 +26,7 @@ HINSTANCE g_hInstance;
|
||||
|
||||
#define NT_CHECK_FAIL_ACTION return FALSE;
|
||||
|
||||
#ifdef _WIN32
|
||||
extern "C"
|
||||
BOOL WINAPI DllMain(
|
||||
#ifdef UNDER_CE
|
||||
@@ -49,6 +50,7 @@ BOOL WINAPI DllMain(
|
||||
*/
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
DEFINE_GUID(CLSID_CArchiveHandler,
|
||||
k_7zip_GUID_Data1,
|
||||
|
||||
@@ -34,48 +34,35 @@
|
||||
|
||||
static const Byte k_Base64Table[256] =
|
||||
{
|
||||
64,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,
|
||||
77,77,77,77,77,77,77,77,77,77,77,62,77,64,77,63,52,53,54,55,56,57,58,59,60,61,77,77,77,77,77,77,
|
||||
77, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,77,77,77,77,77,
|
||||
77,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,77,77,77,77,77,
|
||||
77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,
|
||||
77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,
|
||||
77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,
|
||||
77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77
|
||||
66,77,77,77,77,77,77,77,77,65,65,77,77,65,77,77,
|
||||
77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,
|
||||
65,77,77,77,77,77,77,77,77,77,77,62,77,77,77,63,
|
||||
52,53,54,55,56,57,58,59,60,61,77,77,77,64,77,77,
|
||||
77, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,
|
||||
15,16,17,18,19,20,21,22,23,24,25,77,77,77,77,77,
|
||||
77,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,
|
||||
41,42,43,44,45,46,47,48,49,50,51,77,77,77,77,77,
|
||||
77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,
|
||||
77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,
|
||||
77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,
|
||||
77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,
|
||||
77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,
|
||||
77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,
|
||||
77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,
|
||||
77,77,77,77,77,77,77,77,77,77,77,77,77,77,77,77
|
||||
};
|
||||
|
||||
static Byte *Base64ToBin(Byte *dest, const char *src)
|
||||
{
|
||||
UInt32 val = 1;
|
||||
UInt32 c = k_Base64Table[(Byte)(*src++)];
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/*
|
||||
UInt32 c = (Byte)(*src++);
|
||||
if (c >= 'A')
|
||||
{
|
||||
if (c <= 'Z') c -= 'A';
|
||||
else if (c >= 'a' && c <= 'z') c -= 'a' - 26;
|
||||
else continue;
|
||||
}
|
||||
else if (c >= '0')
|
||||
{
|
||||
if (c <= '9') c += 52 - '0';
|
||||
else if (c == '=') break;
|
||||
else continue;
|
||||
}
|
||||
else if (c == '+') c = 62;
|
||||
else if (c == '/') c = 63;
|
||||
else if (c == 0) break;
|
||||
else continue;
|
||||
*/
|
||||
UInt32 c = k_Base64Table[(Byte)(*src++)];
|
||||
|
||||
// UInt32 c = k_Base64Table[(Byte)(*src++)];
|
||||
if (c < 64)
|
||||
{
|
||||
val = (val << 6) | c;
|
||||
c = k_Base64Table[(Byte)(*src++)];
|
||||
if ((val & ((UInt32)1 << 24)) == 0)
|
||||
continue;
|
||||
dest[0] = (Byte)(val >> 16);
|
||||
@@ -85,19 +72,41 @@ static Byte *Base64ToBin(Byte *dest, const char *src)
|
||||
val = 1;
|
||||
continue;
|
||||
}
|
||||
if (c == 64)
|
||||
|
||||
if (c == 65) // space
|
||||
continue;
|
||||
|
||||
if (c == 64) // '='
|
||||
break;
|
||||
c = k_Base64Table[(Byte)(*src++)];
|
||||
|
||||
if (c == 66 && val == 1) // end of string
|
||||
return dest;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (val >= ((UInt32)1 << 12))
|
||||
if (val < (1 << 12))
|
||||
return NULL;
|
||||
|
||||
if (val & (1 << 18))
|
||||
{
|
||||
if (val >= ((UInt32)1 << 18))
|
||||
*dest++ = (Byte)(val >> 16);
|
||||
*dest++ = (Byte)(val);
|
||||
*dest++ = (Byte)(val >> 10);
|
||||
*dest++ = (Byte)(val >> 2);
|
||||
}
|
||||
else if (k_Base64Table[(Byte)(*src++)] != 64) // '='
|
||||
return NULL;
|
||||
else
|
||||
*dest++ = (Byte)(val >> 4);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
Byte c = k_Base64Table[(Byte)(*src++)];
|
||||
if (c == 65) // space
|
||||
continue;
|
||||
if (c == 66) // end of string
|
||||
return dest;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
||||
@@ -720,7 +729,13 @@ HRESULT CHandler::Open2(IInStream *stream)
|
||||
return S_FALSE;
|
||||
destLen = dataString->Len() / 4 * 3 + 4;
|
||||
rawBuf.Alloc(destLen);
|
||||
destLen = (unsigned)(Base64ToBin(rawBuf, *dataString) - rawBuf);
|
||||
{
|
||||
const Byte *endPtr = Base64ToBin(rawBuf, *dataString);
|
||||
if (!endPtr)
|
||||
return S_FALSE;
|
||||
destLen = (unsigned)(endPtr - rawBuf);
|
||||
}
|
||||
|
||||
#ifdef DMG_SHOW_RAW
|
||||
CExtraFile &extra = _extras.AddNew();
|
||||
{
|
||||
|
||||
@@ -1118,7 +1118,7 @@ HRESULT CHandler::SeekAndRead(IInStream *inStream, UInt64 block, Byte *data, siz
|
||||
{
|
||||
if (block == 0 || block >= _h.NumBlocks)
|
||||
return S_FALSE;
|
||||
if (((size + (1 << _h.BlockBits) + 1) >> _h.BlockBits) > _h.NumBlocks - block)
|
||||
if (((size + ((size_t)1 << _h.BlockBits) - 1) >> _h.BlockBits) > _h.NumBlocks - block)
|
||||
return S_FALSE;
|
||||
RINOK(inStream->Seek((UInt64)block << _h.BlockBits, STREAM_SEEK_SET, NULL));
|
||||
_totalRead += size;
|
||||
@@ -1167,6 +1167,9 @@ HRESULT CHandler::Open2(IInStream *inStream)
|
||||
RINOK(_openCallback->SetTotal(NULL, &_phySize));
|
||||
}
|
||||
|
||||
UInt64 fileSize = 0;
|
||||
RINOK(inStream->Seek(0, STREAM_SEEK_END, &fileSize));
|
||||
|
||||
CRecordVector<CGroupDescriptor> groups;
|
||||
|
||||
{
|
||||
@@ -1213,6 +1216,21 @@ HRESULT CHandler::Open2(IInStream *inStream)
|
||||
|
||||
if (_h.NumInodes < _h.NumFreeInodes)
|
||||
return S_FALSE;
|
||||
|
||||
UInt32 numNodes = _h.InodesPerGroup;
|
||||
if (numNodes > _h.NumInodes)
|
||||
numNodes = _h.NumInodes;
|
||||
size_t nodesDataSize = (size_t)numNodes * _h.InodeSize;
|
||||
|
||||
if (nodesDataSize / _h.InodeSize != numNodes)
|
||||
return S_FALSE;
|
||||
|
||||
// that code to reduce false detecting cases
|
||||
if (nodesDataSize > fileSize)
|
||||
{
|
||||
if (numNodes > (1 << 24))
|
||||
return S_FALSE;
|
||||
}
|
||||
|
||||
UInt32 numReserveInodes = _h.NumInodes - _h.NumFreeInodes + 1;
|
||||
// numReserveInodes = _h.NumInodes + 1;
|
||||
@@ -1222,13 +1240,6 @@ HRESULT CHandler::Open2(IInStream *inStream)
|
||||
_refs.Reserve(numReserveInodes);
|
||||
}
|
||||
|
||||
UInt32 numNodes = _h.InodesPerGroup;
|
||||
if (numNodes > _h.NumInodes)
|
||||
numNodes = _h.NumInodes;
|
||||
size_t nodesDataSize = numNodes * _h.InodeSize;
|
||||
if (nodesDataSize / _h.InodeSize != numNodes)
|
||||
return S_FALSE;
|
||||
|
||||
CByteBuffer nodesData;
|
||||
nodesData.Alloc(nodesDataSize);
|
||||
|
||||
@@ -2799,7 +2810,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
{
|
||||
RINOK(hres);
|
||||
{
|
||||
HRESULT hres = copyCoder->Code(inSeqStream, outStream, NULL, NULL, progress);
|
||||
hres = copyCoder->Code(inSeqStream, outStream, NULL, NULL, progress);
|
||||
if (hres == S_OK)
|
||||
{
|
||||
if (copyCoderSpec->TotalSize == unpackSize)
|
||||
|
||||
@@ -160,10 +160,13 @@ bool CHeader::Parse(const Byte *p)
|
||||
if (NumFats < 1 || NumFats > 4)
|
||||
return false;
|
||||
|
||||
// we also support images that contain 0 in offset field.
|
||||
bool isOkOffset = (codeOffset == 0 || (p[0] == 0xEB && p[1] == 0));
|
||||
|
||||
UInt16 numRootDirEntries = Get16(p + 17);
|
||||
if (numRootDirEntries == 0)
|
||||
{
|
||||
if (codeOffset < 90)
|
||||
if (codeOffset < 90 && !isOkOffset)
|
||||
return false;
|
||||
NumFatBits = 32;
|
||||
NumRootDirSectors = 0;
|
||||
@@ -171,7 +174,7 @@ bool CHeader::Parse(const Byte *p)
|
||||
else
|
||||
{
|
||||
// Some FAT12s don't contain VolFields
|
||||
if (codeOffset < 62 - 24)
|
||||
if (codeOffset < 62 - 24 && !isOkOffset)
|
||||
return false;
|
||||
NumFatBits = 0;
|
||||
UInt32 mask = (1 << (SectorSizeLog - 5)) - 1;
|
||||
|
||||
@@ -87,6 +87,9 @@ struct CPartType
|
||||
static const CPartType kPartTypes[] =
|
||||
{
|
||||
// { 0x0, 0, "Unused" },
|
||||
|
||||
{ 0x21686148, 0, "BIOS Boot" },
|
||||
|
||||
{ 0xC12A7328, 0, "EFI System" },
|
||||
{ 0x024DEE41, 0, "MBR" },
|
||||
|
||||
@@ -98,10 +101,13 @@ static const CPartType kPartTypes[] =
|
||||
// { 0x37AFFC90, 0, "IBM GPFS" },
|
||||
// { 0xE75CAF8F, 0, "Windows Storage Spaces" },
|
||||
|
||||
{ 0x83BD6B9D, 0, "FreeBSD Boot" },
|
||||
{ 0x0FC63DAF, 0, "Linux Data" },
|
||||
{ 0x0657FD6D, 0, "Linux Swap" },
|
||||
|
||||
{ 0x83BD6B9D, 0, "FreeBSD Boot" },
|
||||
{ 0x516E7CB4, 0, "FreeBSD Data" },
|
||||
{ 0x516E7CB5, 0, "FreeBSD Swap" },
|
||||
{ 0x516E7CB6, "ufs", "FreeBSD UFS" },
|
||||
{ 0x516E7CB6, "ufs", "FreeBSD UFS" },
|
||||
{ 0x516E7CB8, 0, "FreeBSD Vinum" },
|
||||
{ 0x516E7CB8, "zfs", "FreeBSD ZFS" },
|
||||
|
||||
@@ -335,6 +341,12 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
break;
|
||||
s += c;
|
||||
}
|
||||
if (s.IsEmpty())
|
||||
{
|
||||
char temp[16];
|
||||
ConvertUInt32ToString(index, temp);
|
||||
s.AddAscii(temp);
|
||||
}
|
||||
{
|
||||
int typeIndex = FindPartType(item.Type);
|
||||
s += L'.';
|
||||
|
||||
@@ -876,7 +876,7 @@ HRESULT CDatabase::LoadCatalog(const CFork &fork, const CObjectVector<CIdExtents
|
||||
// CNodeDescriptor nodeDesc;
|
||||
// nodeDesc.Parse(p);
|
||||
CHeaderRec hr;
|
||||
hr.Parse(p + kNodeDescriptor_Size);
|
||||
RINOK(hr.Parse(p + kNodeDescriptor_Size));
|
||||
|
||||
// CaseSensetive = (Header.IsHfsX() && hr.KeyCompareType == 0xBC);
|
||||
|
||||
@@ -987,7 +987,9 @@ HRESULT CDatabase::LoadCatalog(const CFork &fork, const CObjectVector<CIdExtents
|
||||
item.GroupID = Get32(r + 0x24);
|
||||
item.AdminFlags = r[0x28];
|
||||
item.OwnerFlags = r[0x29];
|
||||
*/
|
||||
item.FileMode = Get16(r + 0x2A);
|
||||
/*
|
||||
item.special.iNodeNum = Get16(r + 0x2C); // or .linkCount
|
||||
item.FileType = Get32(r + 0x30);
|
||||
item.FileCreator = Get32(r + 0x34);
|
||||
@@ -1572,6 +1574,9 @@ HRESULT CHandler::ExtractZlibFile(
|
||||
|
||||
UInt32 size = GetUi32(tableBuf + i * 8 + 4);
|
||||
|
||||
if (size > buf.Size() || size > kCompressionBlockSize + 1)
|
||||
return S_FALSE;
|
||||
|
||||
RINOK(ReadStream_FALSE(inStream, buf, size));
|
||||
|
||||
if ((buf[0] & 0xF) == 0xF)
|
||||
@@ -1759,7 +1764,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
if (rem == 0)
|
||||
{
|
||||
// Here we check that there are no extra (empty) blocks in last extent.
|
||||
if (extentRem >= (UInt64)((UInt32)1 << Header.BlockSizeLog))
|
||||
if (extentRem >= ((UInt64)1 << Header.BlockSizeLog))
|
||||
res = NExtract::NOperationResult::kDataError;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -358,7 +358,7 @@ STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
|
||||
UInt64 blockIndex;
|
||||
UInt64 currentItemSize;
|
||||
|
||||
if (index < (UInt32)_archive.Refs.Size())
|
||||
if (index < _archive.Refs.Size())
|
||||
{
|
||||
const CRef &ref = _archive.Refs[index];
|
||||
const CDir &item = ref.Dir->_subItems[ref.Index];
|
||||
@@ -375,14 +375,14 @@ STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
|
||||
UInt64 virtOffset = 0;
|
||||
for (UInt32 i = 0; i < ref.NumExtents; i++)
|
||||
{
|
||||
const CDir &item = ref.Dir->_subItems[ref.Index + i];
|
||||
if (item.Size == 0)
|
||||
const CDir &item2 = ref.Dir->_subItems[ref.Index + i];
|
||||
if (item2.Size == 0)
|
||||
continue;
|
||||
CSeekExtent se;
|
||||
se.Phy = (UInt64)item.ExtentLocation * kBlockSize;
|
||||
se.Phy = (UInt64)item2.ExtentLocation * kBlockSize;
|
||||
se.Virt = virtOffset;
|
||||
extentStreamSpec->Extents.Add(se);
|
||||
virtOffset += item.Size;
|
||||
virtOffset += item2.Size;
|
||||
}
|
||||
if (virtOffset != ref.TotalSize)
|
||||
return S_FALSE;
|
||||
@@ -394,6 +394,7 @@ STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
|
||||
*stream = extentStream.Detach();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
currentItemSize = item.Size;
|
||||
blockIndex = item.ExtentLocation;
|
||||
}
|
||||
|
||||
@@ -294,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' };
|
||||
|
||||
@@ -170,7 +170,7 @@ struct CBootInitialEntry
|
||||
// Partition Table found in the boot image.
|
||||
UInt16 SectorCount; // This is the number of virtual/emulated sectors the system
|
||||
// will store at Load Segment during the initial boot procedure.
|
||||
UInt32 LoadRBA; // This is the start address of the virtual disk. CD<EFBFBD>s use
|
||||
UInt32 LoadRBA; // This is the start address of the virtual disk. CDs use
|
||||
// Relative/Logical block addressing.
|
||||
|
||||
Byte VendorSpec[20];
|
||||
|
||||
@@ -79,7 +79,7 @@ struct CDirRecord
|
||||
while (rem >= 5)
|
||||
{
|
||||
unsigned len = p[2];
|
||||
if (len > rem)
|
||||
if (len < 3 || len > rem)
|
||||
return 0;
|
||||
if (p[0] == 'N' && p[1] == 'M' && p[3] == 1)
|
||||
{
|
||||
|
||||
@@ -110,7 +110,7 @@ HRESULT CDecoder::Create(bool filteredMode, ISequentialInStream *inStream)
|
||||
{
|
||||
_filterCoder = new CFilterCoder(false);
|
||||
CMyComPtr<ICompressCoder> coder = _filterCoder;
|
||||
_filterCoder->Filter = new CBcjCoder(false);
|
||||
_filterCoder->Filter = new NCompress::NBcj::CCoder(false);
|
||||
_bcjStream = _filterCoder;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ HRESULT CDecoder::Init(ISequentialInStream *inStream, bool &useFilter)
|
||||
{
|
||||
_filter = new CFilterCoder(false);
|
||||
_filterInStream = _filter;
|
||||
_filter->Filter = new CBcjCoder(false);
|
||||
_filter->Filter = new NCompress::NBcj::CCoder(false);
|
||||
}
|
||||
RINOK(_filter->SetInStream(_codecInStream));
|
||||
_decoderInStream = _filterInStream;
|
||||
|
||||
@@ -88,7 +88,7 @@ enum
|
||||
EW_SENDMESSAGE, // SendMessage
|
||||
EW_ISWINDOW, // IsWindow
|
||||
EW_GETDLGITEM, // GetDlgItem
|
||||
EW_SETCTLCOLORS, // SerCtlColors
|
||||
EW_SETCTLCOLORS, // SetCtlColors
|
||||
EW_SETBRANDINGIMAGE, // SetBrandingImage
|
||||
EW_CREATEFONT, // CreateFont
|
||||
EW_SHOWWINDOW, // ShowWindow, EnableWindow, HideWindow
|
||||
@@ -1155,9 +1155,13 @@ bool CInArchive::IsGoodString(UInt32 param) const
|
||||
if (param == 0)
|
||||
return true;
|
||||
const Byte *p = _data + _stringsPos;
|
||||
unsigned c;
|
||||
if (IsUnicode)
|
||||
return (Get16(p + param * 2 - 2)) == 0;
|
||||
return p[param - 1] == 0;
|
||||
c = Get16(p + param * 2 - 2);
|
||||
else
|
||||
c = p[param - 1];
|
||||
// some files have '\\' character before string?
|
||||
return (c == 0 || c == '\\');
|
||||
}
|
||||
|
||||
bool CInArchive::AreTwoParamStringsEqual(UInt32 param1, UInt32 param2) const
|
||||
@@ -1509,7 +1513,7 @@ static const UInt32 CMD_REF_Pre = (1 << 2);
|
||||
static const UInt32 CMD_REF_Show = (1 << 3);
|
||||
static const UInt32 CMD_REF_Leave = (1 << 4);
|
||||
static const UInt32 CMD_REF_OnFunc = (1 << 5);
|
||||
static const UInt32 CMD_REF_Section = (1 << 6);
|
||||
static const UInt32 CMD_REF_Section = (1 << 6);
|
||||
static const UInt32 CMD_REF_InitPluginDir = (1 << 7);
|
||||
// static const UInt32 CMD_REF_Creator = (1 << 5); // _Pre is used instead
|
||||
static const unsigned CMD_REF_OnFunc_NumShifts = 28; // it uses for onFunc too
|
||||
@@ -3357,7 +3361,7 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
|
||||
|
||||
#ifdef NSIS_SCRIPT
|
||||
s += isSetOutPath ? "SetOutPath" : "CreateDirectory";
|
||||
AddParam(params[0]);
|
||||
AddParam(params[0]);
|
||||
#endif
|
||||
|
||||
break;
|
||||
@@ -3571,15 +3575,16 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
|
||||
|
||||
AddParam(params[0]);
|
||||
|
||||
SmallSpaceComment();
|
||||
|
||||
/*
|
||||
for (int i = 1; i < 3; i++)
|
||||
AddParam_UInt(params[i]);
|
||||
*/
|
||||
|
||||
if (params[3] != 0)
|
||||
{
|
||||
SmallSpaceComment();
|
||||
AddParam(params[3]);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -421,7 +421,11 @@ public:
|
||||
|
||||
const char *kRemoveStr = "$INSTDIR\\";
|
||||
if (s.IsPrefixedBy_Ascii_NoCase(kRemoveStr))
|
||||
{
|
||||
s.Delete(0, MyStringLen(kRemoveStr));
|
||||
if (s[0] == L'\\')
|
||||
s.DeleteFrontal(1);
|
||||
}
|
||||
if (item.IsUninstaller && ExeStub.Size() == 0)
|
||||
s += L".nsis";
|
||||
return s;
|
||||
|
||||
@@ -630,24 +630,27 @@ static size_t Lznt1Dec(Byte *dest, size_t outBufLim, size_t destLen, const Byte
|
||||
{
|
||||
if (srcLen < 2 || (destSize & 0xFFF) != 0)
|
||||
break;
|
||||
UInt32 v = Get16(src);
|
||||
if (v == 0)
|
||||
break;
|
||||
src += 2;
|
||||
srcLen -= 2;
|
||||
UInt32 comprSize = (v & 0xFFF) + 1;
|
||||
if (comprSize > srcLen)
|
||||
break;
|
||||
srcLen -= comprSize;
|
||||
if ((v & 0x8000) == 0)
|
||||
UInt32 comprSize;
|
||||
{
|
||||
if (comprSize != (1 << 12))
|
||||
const UInt32 v = Get16(src);
|
||||
if (v == 0)
|
||||
break;
|
||||
memcpy(dest + destSize, src, comprSize);
|
||||
src += comprSize;
|
||||
destSize += comprSize;
|
||||
src += 2;
|
||||
srcLen -= 2;
|
||||
comprSize = (v & 0xFFF) + 1;
|
||||
if (comprSize > srcLen)
|
||||
break;
|
||||
srcLen -= comprSize;
|
||||
if ((v & 0x8000) == 0)
|
||||
{
|
||||
if (comprSize != (1 << 12))
|
||||
break;
|
||||
memcpy(dest + destSize, src, comprSize);
|
||||
src += comprSize;
|
||||
destSize += comprSize;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (destSize + (1 << 12) > outBufLim || (src[0] & 1) != 0)
|
||||
return 0;
|
||||
@@ -672,7 +675,7 @@ static size_t Lznt1Dec(Byte *dest, size_t outBufLim, size_t destLen, const Byte
|
||||
{
|
||||
if (comprSize < 2)
|
||||
return 0;
|
||||
UInt32 v = Get16(src + pos);
|
||||
const UInt32 v = Get16(src + pos);
|
||||
pos += 2;
|
||||
comprSize -= 2;
|
||||
|
||||
@@ -709,9 +712,12 @@ STDMETHODIMP CInStream::Read(void *data, UInt32 size, UInt32 *processedSize)
|
||||
return (Size == _virtPos) ? S_OK: E_FAIL;
|
||||
if (size == 0)
|
||||
return S_OK;
|
||||
UInt64 rem = Size - _virtPos;
|
||||
if (size > rem)
|
||||
size = (UInt32)rem;
|
||||
{
|
||||
const UInt64 rem = Size - _virtPos;
|
||||
if (size > rem)
|
||||
size = (UInt32)rem;
|
||||
}
|
||||
|
||||
if (_virtPos >= InitializedSize)
|
||||
{
|
||||
memset((Byte *)data, 0, size);
|
||||
@@ -719,9 +725,12 @@ STDMETHODIMP CInStream::Read(void *data, UInt32 size, UInt32 *processedSize)
|
||||
*processedSize = size;
|
||||
return S_OK;
|
||||
}
|
||||
rem = InitializedSize - _virtPos;
|
||||
if (size > rem)
|
||||
size = (UInt32)rem;
|
||||
|
||||
{
|
||||
const UInt64 rem = InitializedSize - _virtPos;
|
||||
if (size > rem)
|
||||
size = (UInt32)rem;
|
||||
}
|
||||
|
||||
while (_curRem == 0)
|
||||
{
|
||||
@@ -838,7 +847,7 @@ STDMETHODIMP CInStream::Read(void *data, UInt32 size, UInt32 *processedSize)
|
||||
}
|
||||
size_t destLenMax = GetCuSize();
|
||||
size_t destLen = destLenMax;
|
||||
UInt64 rem = Size - (virtBlock2 << BlockSizeLog);
|
||||
const UInt64 rem = Size - (virtBlock2 << BlockSizeLog);
|
||||
if (destLen > rem)
|
||||
destLen = (size_t)rem;
|
||||
|
||||
@@ -895,10 +904,13 @@ STDMETHODIMP CInStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPositio
|
||||
static HRESULT DataParseExtents(unsigned clusterSizeLog, const CObjectVector<CAttr> &attrs,
|
||||
unsigned attrIndex, unsigned attrIndexLim, UInt64 numPhysClusters, CRecordVector<CExtent> &Extents)
|
||||
{
|
||||
CExtent e;
|
||||
e.Virt = 0;
|
||||
e.Phy = kEmptyExtent;
|
||||
Extents.Add(e);
|
||||
{
|
||||
CExtent e;
|
||||
e.Virt = 0;
|
||||
e.Phy = kEmptyExtent;
|
||||
Extents.Add(e);
|
||||
}
|
||||
|
||||
const CAttr &attr0 = attrs[attrIndex];
|
||||
|
||||
if (attr0.AllocatedSize < attr0.Size ||
|
||||
@@ -1075,20 +1087,22 @@ HRESULT CMftRec::GetStream(IInStream *mainStream, int dataIndex,
|
||||
{
|
||||
if (numNonResident != ref.Num || !attr0.IsCompressionUnitSupported())
|
||||
return S_FALSE;
|
||||
CInStream *streamSpec = new CInStream;
|
||||
CMyComPtr<IInStream> streamTemp = streamSpec;
|
||||
RINOK(DataParseExtents(clusterSizeLog, DataAttrs, ref.Start, ref.Start + ref.Num, numPhysClusters, streamSpec->Extents));
|
||||
streamSpec->Size = attr0.Size;
|
||||
streamSpec->InitializedSize = attr0.InitializedSize;
|
||||
streamSpec->Stream = mainStream;
|
||||
streamSpec->BlockSizeLog = clusterSizeLog;
|
||||
streamSpec->InUse = InUse();
|
||||
RINOK(streamSpec->InitAndSeek(attr0.CompressionUnit));
|
||||
*destStream = streamTemp.Detach();
|
||||
CInStream *ss = new CInStream;
|
||||
CMyComPtr<IInStream> streamTemp2 = ss;
|
||||
RINOK(DataParseExtents(clusterSizeLog, DataAttrs, ref.Start, ref.Start + ref.Num, numPhysClusters, ss->Extents));
|
||||
ss->Size = attr0.Size;
|
||||
ss->InitializedSize = attr0.InitializedSize;
|
||||
ss->Stream = mainStream;
|
||||
ss->BlockSizeLog = clusterSizeLog;
|
||||
ss->InUse = InUse();
|
||||
RINOK(ss->InitAndSeek(attr0.CompressionUnit));
|
||||
*destStream = streamTemp2.Detach();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
streamSpec->Buf = attr0.Data;
|
||||
}
|
||||
|
||||
streamSpec->Init();
|
||||
*destStream = streamTemp.Detach();
|
||||
return S_OK;
|
||||
@@ -1148,8 +1162,16 @@ bool CMftRec::Parse(Byte *p, unsigned sectorSizeLog, UInt32 numSectors, UInt32 r
|
||||
return false;
|
||||
|
||||
if (usaOffset >= 0x30) // NTFS 3.1+
|
||||
if (Get32(p + 0x2C) != recNumber)
|
||||
return false;
|
||||
{
|
||||
UInt32 iii = Get32(p + 0x2C);
|
||||
if (iii != recNumber)
|
||||
{
|
||||
// ntfs-3g probably writes 0 (that probably is incorrect value) to this field for unused records.
|
||||
// so we support that "bad" case.
|
||||
if (iii != 0)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
UInt16 usn = Get16(p + usaOffset);
|
||||
// PRF(printf("\nusn = %d", usn));
|
||||
@@ -1683,36 +1705,40 @@ HRESULT CDatabase::Open()
|
||||
if ((mftSize >> 4) > Header.GetPhySize_Clusters())
|
||||
return S_FALSE;
|
||||
|
||||
UInt64 numFiles = mftSize >> RecSizeLog;
|
||||
if (numFiles > (1 << 30))
|
||||
return S_FALSE;
|
||||
if (OpenCallback)
|
||||
{
|
||||
RINOK(OpenCallback->SetTotal(&numFiles, &mftSize));
|
||||
}
|
||||
|
||||
const size_t kBufSize = (1 << 15);
|
||||
const size_t recSize = ((size_t)1 << RecSizeLog);
|
||||
if (kBufSize < recSize)
|
||||
return S_FALSE;
|
||||
|
||||
ByteBuf.Alloc(kBufSize);
|
||||
Recs.ClearAndReserve((unsigned)numFiles);
|
||||
{
|
||||
const UInt64 numFiles = mftSize >> RecSizeLog;
|
||||
if (numFiles > (1 << 30))
|
||||
return S_FALSE;
|
||||
if (OpenCallback)
|
||||
{
|
||||
RINOK(OpenCallback->SetTotal(&numFiles, &mftSize));
|
||||
}
|
||||
|
||||
ByteBuf.Alloc(kBufSize);
|
||||
Recs.ClearAndReserve((unsigned)numFiles);
|
||||
}
|
||||
|
||||
for (UInt64 pos64 = 0;;)
|
||||
{
|
||||
if (OpenCallback)
|
||||
{
|
||||
UInt64 numFiles = Recs.Size();
|
||||
const UInt64 numFiles = Recs.Size();
|
||||
if ((numFiles & 0x3FF) == 0)
|
||||
{
|
||||
RINOK(OpenCallback->SetCompleted(&numFiles, &pos64));
|
||||
}
|
||||
}
|
||||
size_t readSize = kBufSize;
|
||||
UInt64 rem = mftSize - pos64;
|
||||
if (readSize > rem)
|
||||
readSize = (size_t)rem;
|
||||
{
|
||||
const UInt64 rem = mftSize - pos64;
|
||||
if (readSize > rem)
|
||||
readSize = (size_t)rem;
|
||||
}
|
||||
if (readSize < recSize)
|
||||
break;
|
||||
RINOK(ReadStream_FALSE(mftStream, ByteBuf, readSize));
|
||||
@@ -2660,7 +2686,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
RINOK(hres);
|
||||
if (inStream)
|
||||
{
|
||||
HRESULT hres = copyCoder->Code(inStream, outStream, NULL, NULL, progress);
|
||||
hres = copyCoder->Code(inStream, outStream, NULL, NULL, progress);
|
||||
if (hres != S_OK && hres != S_FALSE)
|
||||
{
|
||||
RINOK(hres);
|
||||
|
||||
@@ -242,7 +242,7 @@ struct COptHeader
|
||||
|
||||
int GetNumFileAlignBits() const
|
||||
{
|
||||
for (int i = 9; i <= 16; i++)
|
||||
for (unsigned i = 0; i <= 31; i++)
|
||||
if (((UInt32)1 << i) == FileAlign)
|
||||
return i;
|
||||
return -1;
|
||||
@@ -347,18 +347,24 @@ struct CSection
|
||||
|
||||
CSection(): IsRealSect(false), IsDebug(false), IsAdditionalSection(false) {}
|
||||
|
||||
const UInt32 GetSizeExtract() const { return PSize; }
|
||||
const UInt32 GetSizeMin() const { return MyMin(PSize, VSize); }
|
||||
|
||||
void UpdateTotalSize(UInt32 &totalSize) const
|
||||
{
|
||||
UInt32 t = Pa + PSize;
|
||||
if (totalSize < t)
|
||||
totalSize = t;
|
||||
}
|
||||
|
||||
void Parse(const Byte *p);
|
||||
|
||||
int Compare(const CSection &s) const
|
||||
{
|
||||
RINOZ(MyCompare(Pa, s.Pa));
|
||||
return MyCompare(PSize, s.PSize);
|
||||
UInt32 size1 = GetSizeExtract();
|
||||
UInt32 size2 = s.GetSizeExtract();
|
||||
return MyCompare(size1, size2);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1039,7 +1045,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
switch (propID)
|
||||
{
|
||||
case kpidPath: prop = MultiByteToUnicodeString(item.Name); break;
|
||||
case kpidSize: prop = (UInt64)MyMin(item.PSize, item.VSize); break;
|
||||
case kpidSize: prop = (UInt64)item.PSize; break;
|
||||
case kpidPackSize: prop = (UInt64)item.PSize; break;
|
||||
case kpidVirtualSize: prop = (UInt64)item.VSize; break;
|
||||
case kpidOffset: prop = item.Pa; break;
|
||||
@@ -1148,7 +1154,7 @@ HRESULT CHandler::ReadTable(UInt32 offset, CRecordVector<CTableItem> &items)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static const UInt32 kFileSizeMax = (UInt32)1 << 30;
|
||||
static const UInt32 kFileSizeMax = (UInt32)1 << 31;
|
||||
static const unsigned kNumResItemsMax = (unsigned)1 << 23;
|
||||
static const unsigned kNumStringLangsMax = 256;
|
||||
|
||||
@@ -1883,31 +1889,70 @@ static bool ParseVersion(const Byte *p, UInt32 size, CTextFile &f, CObjectVector
|
||||
}
|
||||
f.CloseBlock(2);
|
||||
}
|
||||
|
||||
f.CloseBlock(0);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
HRESULT CHandler::OpenResources(unsigned sectionIndex, IInStream *stream, IArchiveOpenCallback *callback)
|
||||
{
|
||||
const CSection § = _sections[sectionIndex];
|
||||
size_t fileSize = sect.PSize; // Maybe we need sect.VSize here !!!
|
||||
if (fileSize > kFileSizeMax)
|
||||
return S_FALSE;
|
||||
size_t fileSize = sect.PSize;
|
||||
{
|
||||
UInt64 fileSize64 = fileSize;
|
||||
if (callback)
|
||||
RINOK(callback->SetTotal(NULL, &fileSize64));
|
||||
RINOK(stream->Seek(sect.Pa, STREAM_SEEK_SET, NULL));
|
||||
_buf.Alloc(fileSize);
|
||||
for (size_t pos = 0; pos < fileSize;)
|
||||
size_t fileSizeMin = sect.PSize;
|
||||
|
||||
if (sect.VSize < sect.PSize)
|
||||
{
|
||||
UInt64 offset64 = pos;
|
||||
fileSize = fileSizeMin = sect.VSize;
|
||||
const int numBits = _optHeader.GetNumFileAlignBits();
|
||||
if (numBits > 0)
|
||||
{
|
||||
const UInt32 mask = ((UInt32)1 << numBits) - 1;
|
||||
const size_t end = (size_t)((sect.VSize + mask) & (UInt32)~mask);
|
||||
if (end > sect.VSize)
|
||||
if (end <= sect.PSize)
|
||||
fileSize = end;
|
||||
else
|
||||
fileSize = sect.PSize;
|
||||
}
|
||||
}
|
||||
|
||||
if (fileSize > kFileSizeMax)
|
||||
return S_FALSE;
|
||||
|
||||
{
|
||||
const UInt64 fileSize64 = fileSize;
|
||||
if (callback)
|
||||
RINOK(callback->SetCompleted(NULL, &offset64))
|
||||
RINOK(callback->SetTotal(NULL, &fileSize64));
|
||||
}
|
||||
|
||||
RINOK(stream->Seek(sect.Pa, STREAM_SEEK_SET, NULL));
|
||||
|
||||
_buf.Alloc(fileSize);
|
||||
|
||||
size_t pos;
|
||||
|
||||
for (pos = 0; pos < fileSize;)
|
||||
{
|
||||
{
|
||||
const UInt64 offset64 = pos;
|
||||
if (callback)
|
||||
RINOK(callback->SetCompleted(NULL, &offset64))
|
||||
}
|
||||
size_t rem = MyMin(fileSize - pos, (size_t)(1 << 22));
|
||||
RINOK(ReadStream_FALSE(stream, _buf + pos, rem));
|
||||
RINOK(ReadStream(stream, _buf + pos, &rem));
|
||||
if (rem == 0)
|
||||
{
|
||||
if (pos < fileSizeMin)
|
||||
return S_FALSE;
|
||||
break;
|
||||
}
|
||||
pos += rem;
|
||||
}
|
||||
|
||||
if (pos < fileSize)
|
||||
memset(_buf + pos, 0, fileSize - pos);
|
||||
}
|
||||
|
||||
_usedRes.Alloc(fileSize);
|
||||
@@ -1917,6 +1962,7 @@ HRESULT CHandler::OpenResources(unsigned sectionIndex, IInStream *stream, IArchi
|
||||
_oneLang = true;
|
||||
bool stringsOk = true;
|
||||
size_t maxOffset = 0;
|
||||
|
||||
FOR_VECTOR (i, specItems)
|
||||
{
|
||||
const CTableItem &item1 = specItems[i];
|
||||
@@ -1998,6 +2044,7 @@ HRESULT CHandler::OpenResources(unsigned sectionIndex, IInStream *stream, IArchi
|
||||
}
|
||||
// PrintError("ver.Parse error");
|
||||
}
|
||||
|
||||
item.Enabled = true;
|
||||
_items.Add(item);
|
||||
}
|
||||
@@ -2026,16 +2073,13 @@ HRESULT CHandler::OpenResources(unsigned sectionIndex, IInStream *stream, IArchi
|
||||
|
||||
_usedRes.Free();
|
||||
|
||||
int numBits = _optHeader.GetNumFileAlignBits();
|
||||
if (numBits >= 0)
|
||||
{
|
||||
UInt32 mask = (1 << numBits) - 1;
|
||||
size_t end = ((maxOffset + mask) & ~mask);
|
||||
// 9.29: we use only PSize. PSize can be larger than VSize
|
||||
if (/* end < sect.VSize && */ end <= sect.PSize)
|
||||
// PSize can be much larger than VSize in some exe installers.
|
||||
// it contains archive data after PE resources.
|
||||
// So we need to use PSize here!
|
||||
if (maxOffset < sect.PSize)
|
||||
{
|
||||
CSection sect2;
|
||||
sect2.Flags = 0;
|
||||
size_t end = fileSize;
|
||||
|
||||
// we skip Zeros to start of aligned block
|
||||
size_t i;
|
||||
@@ -2045,12 +2089,15 @@ HRESULT CHandler::OpenResources(unsigned sectionIndex, IInStream *stream, IArchi
|
||||
if (i == end)
|
||||
maxOffset = end;
|
||||
|
||||
CSection sect2;
|
||||
sect2.Flags = 0;
|
||||
sect2.Pa = sect.Pa + (UInt32)maxOffset;
|
||||
sect2.Va = sect.Va + (UInt32)maxOffset;
|
||||
|
||||
// 9.29: we use sect.PSize instead of sect.VSize to support some CAB-SFX
|
||||
// the code for .rsrc_2 is commented.
|
||||
sect2.PSize = sect.PSize - (UInt32)maxOffset;
|
||||
|
||||
if (sect2.PSize != 0)
|
||||
{
|
||||
sect2.VSize = sect2.PSize;
|
||||
@@ -2196,14 +2243,14 @@ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
|
||||
}
|
||||
*/
|
||||
|
||||
size_t i;
|
||||
for (i = 0; i < processed; i++)
|
||||
if (buf[i] != 0)
|
||||
size_t k;
|
||||
for (k = 0; k < processed; k++)
|
||||
if (buf[k] != 0)
|
||||
break;
|
||||
if (processed < size && processed < 100)
|
||||
_totalSize += (UInt32)processed;
|
||||
else if (((_totalSize + i) & 0x1FF) == 0 || processed < size)
|
||||
_totalSize += (UInt32)i;
|
||||
else if (((_totalSize + k) & 0x1FF) == 0 || processed < size)
|
||||
_totalSize += (UInt32)k;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2233,9 +2280,9 @@ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
|
||||
sections.Sort();
|
||||
UInt32 limit = (1 << 12);
|
||||
unsigned num = 0;
|
||||
FOR_VECTOR (i, sections)
|
||||
FOR_VECTOR (k, sections)
|
||||
{
|
||||
const CSection &s = sections[i];
|
||||
const CSection &s = sections[k];
|
||||
if (s.Pa > limit)
|
||||
{
|
||||
CSection &s2 = _sections.AddNew();
|
||||
@@ -2463,7 +2510,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
else if (mixItem.ResourceIndex >= 0)
|
||||
size = _items[mixItem.ResourceIndex].GetSize();
|
||||
else
|
||||
size = _sections[mixItem.SectionIndex].PSize;
|
||||
size = _sections[mixItem.SectionIndex].GetSizeExtract();
|
||||
totalSize += size;
|
||||
}
|
||||
extractCallback->SetTotal(totalSize);
|
||||
@@ -2539,7 +2586,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
}
|
||||
else
|
||||
{
|
||||
currentItemSize = sect.PSize;
|
||||
currentItemSize = sect.GetSizeExtract();
|
||||
if (!testMode && !outStream)
|
||||
continue;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* PpmdHandler.c -- PPMd format handler
|
||||
2010-03-10 : Igor Pavlov : Public domain
|
||||
/* PpmdHandler.cpp -- PPMd format handler
|
||||
2015-11-30 : Igor Pavlov : Public domain
|
||||
This code is based on:
|
||||
PPMd var.H (2001) / var.I (2002): Dmitry Shkarin : Public domain
|
||||
Carryless rangecoder (1999): Dmitry Subbotin : Public domain */
|
||||
@@ -349,6 +349,7 @@ struct CPpmdCpp
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
Int32 testMode, IArchiveExtractCallback *extractCallback)
|
||||
{
|
||||
@@ -386,13 +387,17 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
CPpmdCpp ppmd(_item.Ver);
|
||||
if (!ppmd.Alloc(_item.MemInMB))
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
Int32 opRes = NExtract::NOperationResult::kUnsupportedMethod;
|
||||
|
||||
if (_item.IsSupported())
|
||||
{
|
||||
opRes = NExtract::NOperationResult::kDataError;
|
||||
|
||||
ppmd.Init(_item.Order, _item.Restor);
|
||||
inBuf.Init();
|
||||
UInt64 outSize = 0;
|
||||
|
||||
if (ppmd.InitRc(&inBuf) && !inBuf.Extra && inBuf.Res == S_OK)
|
||||
for (;;)
|
||||
{
|
||||
@@ -431,6 +436,13 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
{
|
||||
RINOK(WriteStream(realOutStream, outBuf.Buf, i));
|
||||
}
|
||||
|
||||
if (inBuf.Extra)
|
||||
{
|
||||
opRes = NExtract::NOperationResult::kUnexpectedEnd;
|
||||
break;
|
||||
}
|
||||
|
||||
if (sym < 0)
|
||||
{
|
||||
if (sym == -1 && ppmd.IsFinishedOK())
|
||||
@@ -438,12 +450,15 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
RINOK(inBuf.Res);
|
||||
}
|
||||
|
||||
realOutStream.Release();
|
||||
return extractCallback->SetOperationResult(opRes);
|
||||
}
|
||||
|
||||
|
||||
static const Byte k_Signature[] = { 0x8F, 0xAF, 0xAC, 0x84 };
|
||||
|
||||
REGISTER_ARC_I(
|
||||
|
||||
@@ -463,22 +463,26 @@ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *openCallback)
|
||||
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;
|
||||
CByteBuffer &buf2 = _tables.AddNew();
|
||||
|
||||
{
|
||||
UInt64 v = Get64((const Byte *)table + (size_t)i * 8);
|
||||
v &= offsetMask;
|
||||
if (v == 0)
|
||||
continue;
|
||||
|
||||
buf2.Alloc((size_t)1 << (_numMidBits + 3));
|
||||
RINOK(stream->Seek(v, STREAM_SEEK_SET, NULL));
|
||||
RINOK(ReadStream_FALSE(stream, buf2, clusterSize));
|
||||
|
||||
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;
|
||||
const 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);
|
||||
const UInt64 v = Get64((const Byte *)buf2 + (size_t)k);
|
||||
if (v == 0)
|
||||
continue;
|
||||
UInt64 offset = v & offsetMask;
|
||||
|
||||
@@ -189,8 +189,8 @@ bool CItem::FindExtra_Version(UInt64 &version) const
|
||||
return false;
|
||||
const Byte *p = Extra + (unsigned)offset;
|
||||
|
||||
UInt64 Flags;
|
||||
unsigned num = ReadVarInt(p, size, &Flags);
|
||||
UInt64 flags;
|
||||
unsigned num = ReadVarInt(p, size, &flags);
|
||||
if (num == 0) return false; p += num; size -= num;
|
||||
|
||||
num = ReadVarInt(p, size, &version);
|
||||
@@ -1292,6 +1292,18 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
|
||||
break;
|
||||
}
|
||||
|
||||
case kpidError:
|
||||
{
|
||||
if (/* &_missingVol || */ !_missingVolName.IsEmpty())
|
||||
{
|
||||
UString s;
|
||||
s.SetFromAscii("Missing volume : ");
|
||||
s += _missingVolName;
|
||||
prop = s;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case kpidErrorFlags:
|
||||
{
|
||||
UInt32 v = _errorFlags;
|
||||
@@ -1813,6 +1825,8 @@ HRESULT CHandler::Open2(IInStream *stream,
|
||||
int prevSplitFile = -1;
|
||||
int prevMainFile = -1;
|
||||
|
||||
bool nextVol_is_Required = false;
|
||||
|
||||
CInArchive arch;
|
||||
|
||||
for (;;)
|
||||
@@ -1840,13 +1854,19 @@ HRESULT CHandler::Open2(IInStream *stream,
|
||||
break;
|
||||
}
|
||||
|
||||
HRESULT result = openVolumeCallback->GetStream(seqName.GetNextName(), &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;
|
||||
}
|
||||
}
|
||||
|
||||
UInt64 endPos = 0;
|
||||
@@ -1861,6 +1881,7 @@ HRESULT CHandler::Open2(IInStream *stream,
|
||||
}
|
||||
|
||||
CInArcInfo arcInfoOpen;
|
||||
{
|
||||
HRESULT res = arch.Open(inStream, maxCheckStartPosition, getTextPassword, arcInfoOpen);
|
||||
if (arch.IsArc && arch.UnexpectedEnd)
|
||||
_errorFlags |= kpv_ErrorFlags_UnexpectedEnd;
|
||||
@@ -1877,6 +1898,7 @@ HRESULT CHandler::Open2(IInStream *stream,
|
||||
return res;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
CArc &arc = _arcs.AddNew();
|
||||
CInArcInfo &arcInfo = arc.Info;
|
||||
@@ -2048,12 +2070,12 @@ HRESULT CHandler::Open2(IInStream *stream,
|
||||
{
|
||||
if (prevSplitFile >= 0)
|
||||
{
|
||||
CRefItem &ref = _refs[prevSplitFile];
|
||||
CItem &prevItem = _items[ref.Last];
|
||||
CRefItem &ref2 = _refs[prevSplitFile];
|
||||
CItem &prevItem = _items[ref2.Last];
|
||||
if (item.IsNextForItem(prevItem))
|
||||
{
|
||||
ref.Last = _items.Size();
|
||||
prevItem.NextItem = ref.Last;
|
||||
ref2.Last = _items.Size();
|
||||
prevItem.NextItem = ref2.Last;
|
||||
needAdd = false;
|
||||
}
|
||||
}
|
||||
@@ -2094,11 +2116,18 @@ HRESULT CHandler::Open2(IInStream *stream,
|
||||
}
|
||||
|
||||
curBytes += endPos;
|
||||
|
||||
nextVol_is_Required = false;
|
||||
|
||||
if (!arcInfo.IsVolume())
|
||||
break;
|
||||
if (arcInfo.EndOfArchive_was_Read
|
||||
&& !arcInfo.AreMoreVolumes())
|
||||
break;
|
||||
|
||||
if (arcInfo.EndOfArchive_was_Read)
|
||||
{
|
||||
if (!arcInfo.AreMoreVolumes())
|
||||
break;
|
||||
nextVol_is_Required = true;
|
||||
}
|
||||
}
|
||||
|
||||
FillLinks();
|
||||
@@ -2120,6 +2149,7 @@ STDMETHODIMP CHandler::Open(IInStream *stream,
|
||||
STDMETHODIMP CHandler::Close()
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
_missingVolName.Empty();
|
||||
_errorFlags = 0;
|
||||
// _warningFlags = 0;
|
||||
_isArc = false;
|
||||
@@ -2305,6 +2335,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
|
||||
{
|
||||
UInt64 total = 0;
|
||||
bool isThereUndefinedSize = false;
|
||||
bool thereAreLinks = false;
|
||||
|
||||
{
|
||||
@@ -2314,9 +2345,14 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
unsigned index = allFilesMode ? t : indices[t];
|
||||
const CRefItem &ref = _refs[index];
|
||||
const CItem &item = _items[ref.Item];
|
||||
const CItem &lastItem = _items[ref.Last];
|
||||
|
||||
extractStatuses[index] |= kStatus_Extract;
|
||||
total += item.Size;
|
||||
|
||||
if (!lastItem.Is_UnknownSize())
|
||||
total += lastItem.Size;
|
||||
else
|
||||
isThereUndefinedSize = true;
|
||||
|
||||
if (ref.Link >= 0)
|
||||
{
|
||||
@@ -2324,11 +2360,18 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
{
|
||||
if ((unsigned)ref.Link < index)
|
||||
{
|
||||
const CItem &linkItem = _items[_refs[(unsigned)ref.Link].Item];
|
||||
const CRefItem &linkRef = _refs[(unsigned)ref.Link];
|
||||
const CItem &linkItem = _items[linkRef.Item];
|
||||
if (linkItem.IsSolid() && linkItem.Size <= k_CopyLinkFile_MaxSize)
|
||||
{
|
||||
if (extractStatuses[(unsigned)ref.Link] == 0)
|
||||
total += linkItem.Size;
|
||||
{
|
||||
const CItem &lastLinkItem = _items[linkRef.Last];
|
||||
if (!lastLinkItem.Is_UnknownSize())
|
||||
total += lastLinkItem.Size;
|
||||
else
|
||||
isThereUndefinedSize = true;
|
||||
}
|
||||
extractStatuses[(unsigned)ref.Link] |= kStatus_Link;
|
||||
thereAreLinks = true;
|
||||
}
|
||||
@@ -2347,11 +2390,18 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
while (j > solidLimit)
|
||||
{
|
||||
j--;
|
||||
const CItem &item2 = _items[_refs[j].Item];
|
||||
const CRefItem &ref2 = _refs[j];
|
||||
const CItem &item2 = _items[ref2.Item];
|
||||
if (!item2.IsService())
|
||||
{
|
||||
if (extractStatuses[j] == 0)
|
||||
total += item2.Size;
|
||||
{
|
||||
const CItem &lastItem2 = _items[ref2.Last];
|
||||
if (!lastItem2.Is_UnknownSize())
|
||||
total += lastItem2.Size;
|
||||
else
|
||||
isThereUndefinedSize = true;
|
||||
}
|
||||
extractStatuses[j] |= kStatus_Skip;
|
||||
if (!item2.IsSolid())
|
||||
break;
|
||||
@@ -2387,13 +2437,20 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
while (j > solidLimit)
|
||||
{
|
||||
j--;
|
||||
const CItem &item2 = _items[_refs[j].Item];
|
||||
const CRefItem &ref2 = _refs[j];
|
||||
const CItem &item2 = _items[ref2.Item];
|
||||
if (!item2.IsService())
|
||||
{
|
||||
if (extractStatuses[j] != 0)
|
||||
break;
|
||||
extractStatuses[j] = kStatus_Skip;
|
||||
total += item2.Size;
|
||||
{
|
||||
const CItem &lastItem2 = _items[ref2.Last];
|
||||
if (!lastItem2.Is_UnknownSize())
|
||||
total += lastItem2.Size;
|
||||
else
|
||||
isThereUndefinedSize = true;
|
||||
}
|
||||
if (!item2.IsSolid())
|
||||
break;
|
||||
}
|
||||
@@ -2421,7 +2478,10 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
}
|
||||
}
|
||||
|
||||
RINOK(extractCallback->SetTotal(total));
|
||||
if (total != 0 || !isThereUndefinedSize)
|
||||
{
|
||||
RINOK(extractCallback->SetTotal(total));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2474,8 +2534,12 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
|
||||
const CRefItem *ref = &_refs[index];
|
||||
const CItem *item = &_items[ref->Item];
|
||||
const CItem &lastItem = _items[ref->Last];
|
||||
|
||||
curUnpackSize = 0;
|
||||
if (!lastItem.Is_UnknownSize())
|
||||
curUnpackSize = lastItem.Size;
|
||||
|
||||
curUnpackSize = item->Size;
|
||||
curPackSize = GetPackSize(index);
|
||||
|
||||
RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
|
||||
@@ -2504,11 +2568,15 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
{
|
||||
const CRefItem &ref2 = _refs[index2];
|
||||
const CItem &item2 = _items[ref2.Item];
|
||||
const CItem &lastItem2 = _items[ref2.Last];
|
||||
if (!item2.IsSolid())
|
||||
{
|
||||
item = &item2;
|
||||
ref = &ref2;
|
||||
curUnpackSize = item->Size;
|
||||
if (!lastItem2.Is_UnknownSize())
|
||||
curUnpackSize = lastItem2.Size;
|
||||
else
|
||||
curUnpackSize = 0;
|
||||
curPackSize = GetPackSize(index2);
|
||||
}
|
||||
else if ((unsigned)index2 < index)
|
||||
|
||||
@@ -381,6 +381,7 @@ private:
|
||||
// UInt32 _warningFlags;
|
||||
bool _isArc;
|
||||
CByteBuffer _comment;
|
||||
UString _missingVolName;
|
||||
|
||||
DECL_EXTERNAL_CODECS_VARS
|
||||
|
||||
|
||||
@@ -640,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)
|
||||
@@ -648,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)
|
||||
@@ -657,6 +659,7 @@ HRESULT CInArchive::GetNextItem(CItem &item, ICryptoGetTextPassword *getTextPass
|
||||
|
||||
ArcInfo.EndOfArchive_was_Read = true;
|
||||
}
|
||||
|
||||
m_Position += processed;
|
||||
FinishCryptoBlock();
|
||||
ArcInfo.EndPos = m_Position;
|
||||
@@ -699,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)
|
||||
@@ -855,8 +860,21 @@ 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:
|
||||
{
|
||||
UInt32 v = _errorFlags;
|
||||
@@ -935,6 +953,8 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
NCOM::CPropVariant prop;
|
||||
const CRefItem &refItem = _refItems[index];
|
||||
const CItem &item = _items[refItem.ItemIndex];
|
||||
const CItem &lastItem = _items[refItem.ItemIndex + refItem.NumItems - 1];
|
||||
|
||||
/*
|
||||
const CItem *mainItem = &item;
|
||||
if (item.BaseFileIndex >= 0)
|
||||
@@ -954,7 +974,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
break;
|
||||
}
|
||||
case kpidIsDir: prop = item.IsDir(); break;
|
||||
case kpidSize: prop = item.Size; break;
|
||||
case kpidSize: if (lastItem.Is_Size_Defined()) prop = lastItem.Size; break;
|
||||
case kpidPackSize: prop = GetPackSize(index); break;
|
||||
case kpidMTime: RarTimeToProp(item.MTime, prop); break;
|
||||
case kpidCTime: if (item.CTimeDefined) RarTimeToProp(item.CTime, prop); break;
|
||||
@@ -967,7 +987,6 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
case kpidSplitAfter: prop = _items[refItem.ItemIndex + refItem.NumItems - 1].IsSplitAfter(); break;
|
||||
case kpidCRC:
|
||||
{
|
||||
const CItem &lastItem = _items[refItem.ItemIndex + refItem.NumItems - 1];
|
||||
prop = ((lastItem.IsSplitAfter()) ? item.FileCRC : lastItem.FileCRC);
|
||||
break;
|
||||
}
|
||||
@@ -1019,7 +1038,10 @@ HRESULT CHandler::Open2(IInStream *stream,
|
||||
openCallback->QueryInterface(IID_ICryptoGetTextPassword, (void **)&getTextPassword);
|
||||
}
|
||||
|
||||
bool nextVol_is_Required = false;
|
||||
|
||||
CInArchive archive;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
CMyComPtr<IInStream> inStream;
|
||||
@@ -1050,14 +1072,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;
|
||||
@@ -1174,6 +1201,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1216,6 +1255,7 @@ STDMETHODIMP CHandler::Close()
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
// _errorMessage.Empty();
|
||||
_missingVolName.Empty();
|
||||
_errorFlags = 0;
|
||||
_warningFlags = 0;
|
||||
_isArc = false;
|
||||
@@ -1339,34 +1379,52 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
CRecordVector<unsigned> importantIndexes;
|
||||
CRecordVector<bool> extractStatuses;
|
||||
|
||||
bool isThereUndefinedSize = false;
|
||||
|
||||
for (UInt32 t = 0; t < numItems; t++)
|
||||
{
|
||||
unsigned index = allFilesMode ? t : indices[t];
|
||||
const CRefItem &refItem = _refItems[index];
|
||||
const CItem &item = _items[refItem.ItemIndex];
|
||||
censoredTotalUnPacked += item.Size;
|
||||
// censoredTotalPacked += item.PackSize;
|
||||
|
||||
{
|
||||
const CRefItem &refItem = _refItems[index];
|
||||
const CItem &item = _items[refItem.ItemIndex + refItem.NumItems - 1];
|
||||
|
||||
if (item.Is_Size_Defined())
|
||||
censoredTotalUnPacked += item.Size;
|
||||
else
|
||||
isThereUndefinedSize = true;
|
||||
|
||||
// censoredTotalPacked += item.PackSize;
|
||||
}
|
||||
|
||||
unsigned j;
|
||||
for (j = lastIndex; j <= index; j++)
|
||||
// if (!_items[_refItems[j].ItemIndex].IsSolid())
|
||||
if (!IsSolid(j))
|
||||
lastIndex = j;
|
||||
|
||||
for (j = lastIndex; j <= index; j++)
|
||||
{
|
||||
const CRefItem &refItem = _refItems[j];
|
||||
const CItem &item = _items[refItem.ItemIndex];
|
||||
const CItem &item = _items[refItem.ItemIndex + refItem.NumItems - 1];
|
||||
|
||||
// const CItem &item = _items[j];
|
||||
|
||||
importantTotalUnPacked += item.Size;
|
||||
if (item.Is_Size_Defined())
|
||||
importantTotalUnPacked += item.Size;
|
||||
else
|
||||
isThereUndefinedSize = true;
|
||||
// importantTotalPacked += item.PackSize;
|
||||
importantIndexes.Add(j);
|
||||
extractStatuses.Add(j == index);
|
||||
}
|
||||
|
||||
lastIndex = index + 1;
|
||||
}
|
||||
|
||||
RINOK(extractCallback->SetTotal(importantTotalUnPacked));
|
||||
if (importantTotalUnPacked != 0 || !isThereUndefinedSize)
|
||||
{
|
||||
RINOK(extractCallback->SetTotal(importantTotalUnPacked));
|
||||
}
|
||||
|
||||
UInt64 currentImportantTotalUnPacked = 0;
|
||||
UInt64 currentImportantTotalPacked = 0;
|
||||
UInt64 currentUnPackSize, currentPackSize;
|
||||
@@ -1392,13 +1450,19 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
lps->Init(extractCallback, false);
|
||||
|
||||
bool solidStart = true;
|
||||
for (unsigned i = 0; i < importantIndexes.Size(); i++,
|
||||
|
||||
for (unsigned i = 0;;
|
||||
i++,
|
||||
currentImportantTotalUnPacked += currentUnPackSize,
|
||||
currentImportantTotalPacked += currentPackSize)
|
||||
{
|
||||
lps->InSize = currentImportantTotalPacked;
|
||||
lps->OutSize = currentImportantTotalUnPacked;
|
||||
RINOK(lps->SetCur());
|
||||
|
||||
if (i >= importantIndexes.Size())
|
||||
break;
|
||||
|
||||
CMyComPtr<ISequentialOutStream> realOutStream;
|
||||
|
||||
Int32 askMode;
|
||||
@@ -1413,8 +1477,15 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
|
||||
const CRefItem &refItem = _refItems[index];
|
||||
const CItem &item = _items[refItem.ItemIndex];
|
||||
|
||||
currentUnPackSize = item.Size;
|
||||
const CItem &lastItem = _items[refItem.ItemIndex + refItem.NumItems - 1];
|
||||
|
||||
UInt64 outSize = (UInt64)(Int64)-1;
|
||||
currentUnPackSize = 0;
|
||||
if (lastItem.Is_Size_Defined())
|
||||
{
|
||||
outSize = lastItem.Size;
|
||||
currentUnPackSize = outSize;
|
||||
}
|
||||
|
||||
currentPackSize = GetPackSize(index);
|
||||
|
||||
@@ -1531,11 +1602,11 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
if (len > kPasswordLen_MAX)
|
||||
len = kPasswordLen_MAX;
|
||||
CByteArr buffer(len * 2);
|
||||
for (unsigned i = 0; i < len; i++)
|
||||
for (unsigned k = 0; k < len; k++)
|
||||
{
|
||||
wchar_t c = password[i];
|
||||
((Byte *)buffer)[i * 2] = (Byte)c;
|
||||
((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8);
|
||||
wchar_t c = password[k];
|
||||
((Byte *)buffer)[k * 2] = (Byte)c;
|
||||
((Byte *)buffer)[k * 2 + 1] = (Byte)(c >> 8);
|
||||
}
|
||||
rar3CryptoDecoderSpec->SetPassword((const Byte *)buffer, len * 2);
|
||||
}
|
||||
@@ -1639,12 +1710,14 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
continue;
|
||||
}
|
||||
|
||||
HRESULT result = commonCoder->Code(inStream, outStream, &packSize, &item.Size, progress);
|
||||
HRESULT result = commonCoder->Code(inStream, outStream, &packSize, &outSize, progress);
|
||||
|
||||
if (item.IsEncrypted())
|
||||
filterStreamSpec->ReleaseInStream();
|
||||
|
||||
const CItem &lastItem = _items[refItem.ItemIndex + refItem.NumItems - 1];
|
||||
if (outSize == (UInt64)(Int64)-1)
|
||||
currentUnPackSize = outStreamSpec->GetSize();
|
||||
|
||||
int opRes = (volsInStreamSpec->CrcIsOK && outStreamSpec->GetCRC() == lastItem.FileCRC) ?
|
||||
NExtract::NOperationResult::kOK:
|
||||
NExtract::NOperationResult::kCRCError;
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -42,6 +42,8 @@ struct CItem
|
||||
|
||||
Byte Salt[8];
|
||||
|
||||
bool Is_Size_Defined() const { return Size != (UInt64)(Int64)-1; }
|
||||
|
||||
bool IsEncrypted() const { return (Flags & NHeader::NFile::kEncrypted) != 0; }
|
||||
bool IsSolid() const { return (Flags & NHeader::NFile::kSolid) != 0; }
|
||||
bool IsCommented() const { return (Flags & NHeader::NFile::kComment) != 0; }
|
||||
|
||||
@@ -187,11 +187,15 @@ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
|
||||
|
||||
UInt64 size;
|
||||
{
|
||||
/*
|
||||
NCOM::CPropVariant prop;
|
||||
RINOK(volumeCallback->GetProperty(kpidSize, &prop));
|
||||
if (prop.vt != VT_UI8)
|
||||
return E_INVALIDARG;
|
||||
size = prop.uhVal.QuadPart;
|
||||
*/
|
||||
RINOK(stream->Seek(0, STREAM_SEEK_END, &size));
|
||||
RINOK(stream->Seek(0, STREAM_SEEK_SET, NULL));
|
||||
}
|
||||
|
||||
_totalSize += size;
|
||||
@@ -217,11 +221,15 @@ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
|
||||
if (!stream)
|
||||
break;
|
||||
{
|
||||
/*
|
||||
NCOM::CPropVariant prop;
|
||||
RINOK(volumeCallback->GetProperty(kpidSize, &prop));
|
||||
if (prop.vt != VT_UI8)
|
||||
return E_INVALIDARG;
|
||||
size = prop.uhVal.QuadPart;
|
||||
*/
|
||||
RINOK(stream->Seek(0, STREAM_SEEK_END, &size));
|
||||
RINOK(stream->Seek(0, STREAM_SEEK_SET, NULL));
|
||||
}
|
||||
_totalSize += size;
|
||||
_sizes.Add(size);
|
||||
|
||||
@@ -296,23 +296,25 @@ struct CNode
|
||||
|
||||
UInt32 CNode::Parse1(const Byte *p, UInt32 size, const CHeader &_h)
|
||||
{
|
||||
bool be = _h.be;
|
||||
const bool be = _h.be;
|
||||
if (size < 4)
|
||||
return 0;
|
||||
UInt16 t = Get16(p);
|
||||
if (be)
|
||||
{
|
||||
Type = (UInt16)(t >> 12);
|
||||
Mode = (UInt16)(t & 0xFFF);
|
||||
Uid = (UInt16)(p[2] >> 4);
|
||||
Gid = (UInt16)(p[2] & 0xF);
|
||||
}
|
||||
else
|
||||
{
|
||||
Type = (UInt16)(t & 0xF);
|
||||
Mode = (UInt16)(t >> 4);
|
||||
Uid = (UInt16)(p[2] & 0xF);
|
||||
Gid = (UInt16)(p[2] >> 4);
|
||||
const UInt32 t = Get16(p);
|
||||
if (be)
|
||||
{
|
||||
Type = (UInt16)(t >> 12);
|
||||
Mode = (UInt16)(t & 0xFFF);
|
||||
Uid = (UInt16)(p[2] >> 4);
|
||||
Gid = (UInt16)(p[2] & 0xF);
|
||||
}
|
||||
else
|
||||
{
|
||||
Type = (UInt16)(t & 0xF);
|
||||
Mode = (UInt16)(t >> 4);
|
||||
Uid = (UInt16)(p[2] & 0xF);
|
||||
Gid = (UInt16)(p[2] >> 4);
|
||||
}
|
||||
}
|
||||
|
||||
// Xattr = kXattr_Empty;
|
||||
@@ -402,17 +404,20 @@ UInt32 CNode::Parse2(const Byte *p, UInt32 size, const CHeader &_h)
|
||||
bool be = _h.be;
|
||||
if (size < 4)
|
||||
return 0;
|
||||
UInt16 t = Get16(p);
|
||||
if (be)
|
||||
{
|
||||
Type = (UInt16)(t >> 12);
|
||||
Mode = (UInt16)(t & 0xFFF);
|
||||
}
|
||||
else
|
||||
{
|
||||
Type = (UInt16)(t & 0xF);
|
||||
Mode = (UInt16)(t >> 4);
|
||||
const UInt32 t = Get16(p);
|
||||
if (be)
|
||||
{
|
||||
Type = (UInt16)(t >> 12);
|
||||
Mode = (UInt16)(t & 0xFFF);
|
||||
}
|
||||
else
|
||||
{
|
||||
Type = (UInt16)(t & 0xF);
|
||||
Mode = (UInt16)(t >> 4);
|
||||
}
|
||||
}
|
||||
|
||||
Uid = p[2];
|
||||
Gid = p[3];
|
||||
|
||||
@@ -532,17 +537,21 @@ UInt32 CNode::Parse3(const Byte *p, UInt32 size, const CHeader &_h)
|
||||
bool be = _h.be;
|
||||
if (size < 12)
|
||||
return 0;
|
||||
UInt16 t = Get16(p);
|
||||
if (be)
|
||||
|
||||
{
|
||||
Type = (UInt16)(t >> 12);
|
||||
Mode = (UInt16)(t & 0xFFF);
|
||||
}
|
||||
else
|
||||
{
|
||||
Type = (UInt16)(t & 0xF);
|
||||
Mode = (UInt16)(t >> 4);
|
||||
const UInt32 t = Get16(p);
|
||||
if (be)
|
||||
{
|
||||
Type = (UInt16)(t >> 12);
|
||||
Mode = (UInt16)(t & 0xFFF);
|
||||
}
|
||||
else
|
||||
{
|
||||
Type = (UInt16)(t & 0xF);
|
||||
Mode = (UInt16)(t >> 4);
|
||||
}
|
||||
}
|
||||
|
||||
Uid = p[2];
|
||||
Gid = p[3];
|
||||
// GET_32 (4, MTime);
|
||||
@@ -2115,7 +2124,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
{
|
||||
RINOK(hres);
|
||||
{
|
||||
HRESULT hres = copyCoder->Code(inSeqStream, outStream, NULL, NULL, progress);
|
||||
hres = copyCoder->Code(inSeqStream, outStream, NULL, NULL, progress);
|
||||
if (hres == S_OK)
|
||||
{
|
||||
if (copyCoderSpec->TotalSize == unpackSize)
|
||||
|
||||
@@ -98,6 +98,7 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
|
||||
if (!_archive.IsArc) v |= kpv_ErrorFlags_IsNotArc;
|
||||
if (_archive.Unsupported) v |= kpv_ErrorFlags_UnsupportedFeature;
|
||||
if (_archive.UnexpectedEnd) v |= kpv_ErrorFlags_UnexpectedEnd;
|
||||
if (_archive.NoEndAnchor) v |= kpv_ErrorFlags_HeadersError;
|
||||
prop = v;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -389,7 +389,10 @@ HRESULT CInArchive::ReadFileItem(int volIndex, int fsIndex, const CLongAllocDesc
|
||||
return S_FALSE;
|
||||
CFile &file = Files.Back();
|
||||
const CLogVol &vol = LogVols[volIndex];
|
||||
CPartition &partition = Partitions[vol.PartitionMaps[lad.Location.PartitionRef].PartitionIndex];
|
||||
unsigned partitionRef = lad.Location.PartitionRef;
|
||||
if (partitionRef >= vol.PartitionMaps.Size())
|
||||
return S_FALSE;
|
||||
CPartition &partition = Partitions[vol.PartitionMaps[partitionRef].PartitionIndex];
|
||||
|
||||
UInt32 key = lad.Location.Pos;
|
||||
UInt32 value;
|
||||
@@ -425,7 +428,7 @@ HRESULT CInArchive::ReadItem(int volIndex, int fsIndex, const CLongAllocDesc &la
|
||||
if (lad.GetLen() != vol.BlockSize)
|
||||
return S_FALSE;
|
||||
|
||||
size_t size = lad.GetLen();
|
||||
const size_t size = lad.GetLen();
|
||||
CByteBuffer buf(size);
|
||||
RINOK(Read(volIndex, lad, buf));
|
||||
|
||||
@@ -515,20 +518,20 @@ HRESULT CInArchive::ReadItem(int volIndex, int fsIndex, const CLongAllocDesc &la
|
||||
{
|
||||
if (!item.CheckChunkSizes() || !CheckItemExtents(volIndex, item))
|
||||
return S_FALSE;
|
||||
CByteBuffer buf;
|
||||
RINOK(ReadFromFile(volIndex, item, buf));
|
||||
CByteBuffer buf2;
|
||||
RINOK(ReadFromFile(volIndex, item, buf2));
|
||||
item.Size = 0;
|
||||
item.Extents.ClearAndFree();
|
||||
item.InlineData.Free();
|
||||
|
||||
const Byte *p = buf;
|
||||
size = buf.Size();
|
||||
const Byte *p2 = buf2;
|
||||
const size_t size2 = buf2.Size();
|
||||
size_t processedTotal = 0;
|
||||
for (; processedTotal < size;)
|
||||
for (; processedTotal < size2;)
|
||||
{
|
||||
size_t processedCur;
|
||||
CFileId fileId;
|
||||
RINOK(fileId.Parse(p + processedTotal, size - processedTotal, processedCur));
|
||||
RINOK(fileId.Parse(p2 + processedTotal, size2 - processedTotal, processedCur));
|
||||
if (!fileId.IsItLinkParent())
|
||||
{
|
||||
CFile file;
|
||||
@@ -596,8 +599,8 @@ API_FUNC_IsArc IsArc_Udf(const Byte *p, size_t size)
|
||||
{
|
||||
if (SecLogSize < 8)
|
||||
return res;
|
||||
UInt32 offset = (UInt32)256 << SecLogSize;
|
||||
size_t bufSize = (UInt32)1 << SecLogSize;
|
||||
const UInt32 offset = (UInt32)256 << SecLogSize;
|
||||
const UInt32 bufSize = (UInt32)1 << SecLogSize;
|
||||
if (offset + bufSize > size)
|
||||
res = k_IsArc_Res_NEED_MORE;
|
||||
else
|
||||
@@ -610,6 +613,7 @@ API_FUNC_IsArc IsArc_Udf(const Byte *p, size_t size)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
HRESULT CInArchive::Open2()
|
||||
{
|
||||
Clear();
|
||||
@@ -644,8 +648,10 @@ HRESULT CInArchive::Open2()
|
||||
CExtent extentVDS;
|
||||
extentVDS.Parse(buf + i + 16);
|
||||
*/
|
||||
|
||||
const size_t kBufSize = 1 << 11;
|
||||
Byte buf[kBufSize];
|
||||
|
||||
for (SecLogSize = 11;; SecLogSize -= 3)
|
||||
{
|
||||
if (SecLogSize < 8)
|
||||
@@ -654,7 +660,7 @@ HRESULT CInArchive::Open2()
|
||||
if (offset >= fileSize)
|
||||
continue;
|
||||
RINOK(_stream->Seek(offset, STREAM_SEEK_SET, NULL));
|
||||
size_t bufSize = (UInt32)1 << SecLogSize;
|
||||
const size_t bufSize = (size_t)1 << SecLogSize;
|
||||
size_t readSize = bufSize;
|
||||
RINOK(ReadStream(_stream, buf, &readSize));
|
||||
if (readSize == bufSize)
|
||||
@@ -665,6 +671,7 @@ HRESULT CInArchive::Open2()
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
PhySize = (UInt32)(256 + 1) << SecLogSize;
|
||||
IsArc = true;
|
||||
|
||||
@@ -679,8 +686,7 @@ HRESULT CInArchive::Open2()
|
||||
|
||||
for (UInt32 location = 0; ; location++)
|
||||
{
|
||||
size_t bufSize = (UInt32)1 << SecLogSize;
|
||||
size_t pos = 0;
|
||||
const size_t bufSize = (size_t)1 << SecLogSize;
|
||||
if (((UInt64)(location + 1) << SecLogSize) > extentVDS.Len)
|
||||
return S_FALSE;
|
||||
|
||||
@@ -693,7 +699,10 @@ HRESULT CInArchive::Open2()
|
||||
|
||||
|
||||
CTag tag;
|
||||
RINOK(tag.Parse(buf + pos, bufSize - pos));
|
||||
{
|
||||
const size_t pos = 0;
|
||||
RINOK(tag.Parse(buf + pos, bufSize - pos));
|
||||
}
|
||||
if (tag.Id == DESC_TYPE_Terminating)
|
||||
break;
|
||||
|
||||
@@ -855,9 +864,9 @@ HRESULT CInArchive::Open2()
|
||||
{
|
||||
if (nextExtent.GetLen() < 512)
|
||||
return S_FALSE;
|
||||
CByteBuffer buf(nextExtent.GetLen());
|
||||
RINOK(Read(volIndex, nextExtent, buf));
|
||||
const Byte *p = buf;
|
||||
CByteBuffer buf2(nextExtent.GetLen());
|
||||
RINOK(Read(volIndex, nextExtent, buf2));
|
||||
const Byte *p = buf2;
|
||||
size_t size = nextExtent.GetLen();
|
||||
|
||||
CTag tag;
|
||||
@@ -946,28 +955,63 @@ HRESULT CInArchive::Open2()
|
||||
}
|
||||
|
||||
{
|
||||
UInt32 secMask = ((UInt32)1 << SecLogSize) - 1;
|
||||
const UInt32 secMask = ((UInt32)1 << SecLogSize) - 1;
|
||||
PhySize = (PhySize + secMask) & ~(UInt64)secMask;
|
||||
}
|
||||
|
||||
NoEndAnchor = true;
|
||||
|
||||
if (PhySize < fileSize)
|
||||
{
|
||||
UInt64 rem = fileSize - PhySize;
|
||||
const size_t secSize = (size_t)1 << SecLogSize;
|
||||
|
||||
RINOK(_stream->Seek(PhySize, STREAM_SEEK_SET, NULL));
|
||||
size_t bufSize = (UInt32)1 << SecLogSize;
|
||||
size_t readSize = bufSize;
|
||||
RINOK(ReadStream(_stream, buf, &readSize));
|
||||
if (readSize == bufSize)
|
||||
|
||||
// some UDF images contain ZEROs before "Anchor Volume Descriptor Pointer" at the end
|
||||
|
||||
for (unsigned sec = 0; sec < 1024; sec++)
|
||||
{
|
||||
CTag tag;
|
||||
if (tag.Parse(buf, readSize) == S_OK)
|
||||
if (tag.Id == DESC_TYPE_AnchorVolPtr)
|
||||
if (rem == 0)
|
||||
break;
|
||||
|
||||
size_t readSize = secSize;
|
||||
if (readSize > rem)
|
||||
readSize = (size_t)rem;
|
||||
|
||||
RINOK(ReadStream(_stream, buf, &readSize));
|
||||
|
||||
if (readSize == 0)
|
||||
break;
|
||||
|
||||
if (readSize == secSize && NoEndAnchor)
|
||||
{
|
||||
CTag tag;
|
||||
if (tag.Parse(buf, readSize) == S_OK &&
|
||||
tag.Id == DESC_TYPE_AnchorVolPtr)
|
||||
{
|
||||
PhySize += bufSize;
|
||||
NoEndAnchor = false;
|
||||
rem -= readSize;
|
||||
PhySize = fileSize - rem;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
size_t i;
|
||||
for (i = 0; i < readSize && buf[i] == 0; i++);
|
||||
if (i != readSize)
|
||||
break;
|
||||
rem -= readSize;
|
||||
}
|
||||
|
||||
if (rem == 0)
|
||||
PhySize = fileSize;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
HRESULT CInArchive::Open(IInStream *inStream, CProgressVirt *progress)
|
||||
{
|
||||
_progress = progress;
|
||||
@@ -1000,6 +1044,7 @@ void CInArchive::Clear()
|
||||
IsArc = false;
|
||||
Unsupported = false;
|
||||
UnexpectedEnd = false;
|
||||
NoEndAnchor = false;
|
||||
|
||||
PhySize = 0;
|
||||
FileSize = 0;
|
||||
|
||||
@@ -370,6 +370,7 @@ public:
|
||||
bool IsArc;
|
||||
bool Unsupported;
|
||||
bool UnexpectedEnd;
|
||||
bool NoEndAnchor;
|
||||
|
||||
void UpdatePhySize(UInt64 val)
|
||||
{
|
||||
|
||||
@@ -702,9 +702,10 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
int cur = item2.Parent;
|
||||
while (cur >= 0)
|
||||
{
|
||||
const CItem2 &item2 = _items2[cur];
|
||||
path = item2.Name + CHAR_PATH_SEPARATOR + path;
|
||||
cur = item2.Parent;
|
||||
const CItem2 &item3 = _items2[cur];
|
||||
path.InsertAtFront(CHAR_PATH_SEPARATOR);
|
||||
path.Insert(0, item3.Name);
|
||||
cur = item3.Parent;
|
||||
}
|
||||
prop = path;
|
||||
break;
|
||||
|
||||
@@ -532,9 +532,11 @@ STDMETHODIMP CHandler::Read(void *data, UInt32 size, UInt32 *processedSize)
|
||||
*processedSize = 0;
|
||||
if (_virtPos >= Footer.CurrentSize)
|
||||
return S_OK;
|
||||
UInt64 rem = Footer.CurrentSize - _virtPos;
|
||||
if (size > rem)
|
||||
size = (UInt32)rem;
|
||||
{
|
||||
const UInt64 rem = Footer.CurrentSize - _virtPos;
|
||||
if (size > rem)
|
||||
size = (UInt32)rem;
|
||||
}
|
||||
if (size == 0)
|
||||
return S_OK;
|
||||
UInt32 blockIndex = (UInt32)(_virtPos >> Dyn.BlockSizeLog);
|
||||
@@ -565,7 +567,7 @@ STDMETHODIMP CHandler::Read(void *data, UInt32 size, UInt32 *processedSize)
|
||||
RINOK(ReadPhy(newPos + BitMap.Size() + offsetInBlock, data, size));
|
||||
for (UInt32 cur = 0; cur < size;)
|
||||
{
|
||||
UInt32 rem = MyMin(0x200 - (offsetInBlock & 0x1FF), size - cur);
|
||||
const UInt32 rem = MyMin(0x200 - (offsetInBlock & 0x1FF), size - cur);
|
||||
UInt32 bmi = offsetInBlock >> kSectorSize_Log;
|
||||
if (((BitMap[bmi >> 3] >> (7 - (bmi & 7))) & 1) == 0)
|
||||
{
|
||||
@@ -682,9 +684,9 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
|
||||
{
|
||||
s += " -> ";
|
||||
const CHandler *p = this;
|
||||
while (p != 0 && p->NeedParent())
|
||||
while (p && p->NeedParent())
|
||||
p = p->Parent;
|
||||
if (p == 0)
|
||||
if (!p)
|
||||
s += '?';
|
||||
else
|
||||
s += p->Footer.GetTypeString();
|
||||
@@ -750,26 +752,24 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
|
||||
HRESULT CHandler::Open2(IInStream *stream, CHandler *child, IArchiveOpenCallback *openArchiveCallback, unsigned level)
|
||||
{
|
||||
Close();
|
||||
Stream = stream;
|
||||
if (level > (1 << 12)) // Maybe we need to increase that limit
|
||||
return S_FALSE;
|
||||
|
||||
RINOK(Open3());
|
||||
|
||||
if (child && memcmp(child->Dyn.ParentId, Footer.Id, 16) != 0)
|
||||
return S_FALSE;
|
||||
if (Footer.Type != kDiskType_Diff)
|
||||
return S_OK;
|
||||
CMyComPtr<IArchiveOpenVolumeCallback> openVolumeCallback;
|
||||
if (openArchiveCallback->QueryInterface(IID_IArchiveOpenVolumeCallback, (void **)&openVolumeCallback) != S_OK)
|
||||
{
|
||||
// return S_FALSE;
|
||||
}
|
||||
CMyComPtr<IInStream> nextStream;
|
||||
|
||||
bool useRelative;
|
||||
UString name;
|
||||
|
||||
if (!Dyn.RelativeParentNameFromLocator.IsEmpty())
|
||||
{
|
||||
useRelative = true;
|
||||
@@ -780,11 +780,17 @@ HRESULT CHandler::Open2(IInStream *stream, CHandler *child, IArchiveOpenCallback
|
||||
useRelative = false;
|
||||
name = Dyn.ParentName;
|
||||
}
|
||||
|
||||
Dyn.RelativeNameWasUsed = useRelative;
|
||||
|
||||
CMyComPtr<IArchiveOpenVolumeCallback> openVolumeCallback;
|
||||
openArchiveCallback->QueryInterface(IID_IArchiveOpenVolumeCallback, (void **)&openVolumeCallback);
|
||||
|
||||
if (openVolumeCallback)
|
||||
{
|
||||
CMyComPtr<IInStream> nextStream;
|
||||
HRESULT res = openVolumeCallback->GetStream(name, &nextStream);
|
||||
|
||||
if (res == S_FALSE)
|
||||
{
|
||||
if (useRelative && Dyn.ParentName != Dyn.RelativeParentNameFromLocator)
|
||||
@@ -793,19 +799,35 @@ HRESULT CHandler::Open2(IInStream *stream, CHandler *child, IArchiveOpenCallback
|
||||
if (res == S_OK)
|
||||
Dyn.RelativeNameWasUsed = false;
|
||||
}
|
||||
if (res == S_FALSE)
|
||||
return S_OK;
|
||||
}
|
||||
RINOK(res);
|
||||
|
||||
if (res != S_OK && res != S_FALSE)
|
||||
return res;
|
||||
|
||||
if (res == S_FALSE || !nextStream)
|
||||
{
|
||||
UString s;
|
||||
s.SetFromAscii("Missing volume : ");
|
||||
s += name;
|
||||
AddErrorMessage(s);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
Parent = new CHandler;
|
||||
ParentStream = Parent;
|
||||
|
||||
res = Parent->Open2(nextStream, this, openArchiveCallback, level + 1);
|
||||
if (res == S_FALSE)
|
||||
|
||||
if (res != S_OK)
|
||||
{
|
||||
Parent = NULL;
|
||||
ParentStream.Release();
|
||||
if (res == E_ABORT)
|
||||
return res;
|
||||
if (res != S_FALSE)
|
||||
{
|
||||
// we must show that error code
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
@@ -813,7 +835,7 @@ HRESULT CHandler::Open2(IInStream *stream, CHandler *child, IArchiveOpenCallback
|
||||
while (p->NeedParent())
|
||||
{
|
||||
p = p->Parent;
|
||||
if (p == 0)
|
||||
if (!p)
|
||||
{
|
||||
AddErrorMessage(L"Can't open parent VHD file:");
|
||||
AddErrorMessage(Dyn.ParentName);
|
||||
@@ -824,12 +846,13 @@ HRESULT CHandler::Open2(IInStream *stream, CHandler *child, IArchiveOpenCallback
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
void CHandler::CloseAtError()
|
||||
{
|
||||
_phySize = 0;
|
||||
Bat.Clear();
|
||||
NumUsedBlocks = 0;
|
||||
Parent = 0;
|
||||
Parent = NULL;
|
||||
Stream.Release();
|
||||
ParentStream.Release();
|
||||
Dyn.Clear();
|
||||
|
||||
@@ -450,6 +450,8 @@ class CHandler: public CHandlerImg
|
||||
|
||||
CByteBuffer _descriptorBuf;
|
||||
CDescriptor _descriptor;
|
||||
|
||||
UString _missingVolName;
|
||||
|
||||
void InitAndSeekMain()
|
||||
{
|
||||
@@ -882,6 +884,19 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
|
||||
|
||||
case kpidNumVolumes: if (_isMultiVol) prop = (UInt32)_extents.Size(); break;
|
||||
|
||||
case kpidError:
|
||||
{
|
||||
if (_missingVol || !_missingVolName.IsEmpty())
|
||||
{
|
||||
UString s;
|
||||
s.SetFromAscii("Missing volume : ");
|
||||
if (!_missingVolName.IsEmpty())
|
||||
s += _missingVolName;
|
||||
prop = s;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case kpidErrorFlags:
|
||||
{
|
||||
UInt32 v = 0;
|
||||
@@ -889,7 +904,7 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
|
||||
if (_unsupported) v |= kpv_ErrorFlags_UnsupportedMethod;
|
||||
if (_unsupportedSome) v |= kpv_ErrorFlags_UnsupportedMethod;
|
||||
if (_headerError) v |= kpv_ErrorFlags_HeadersError;
|
||||
if (_missingVol) v |= kpv_ErrorFlags_UnexpectedEnd;
|
||||
// if (_missingVol) v |= kpv_ErrorFlags_UnexpectedEnd;
|
||||
if (v != 0)
|
||||
prop = v;
|
||||
break;
|
||||
@@ -1081,15 +1096,14 @@ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *openCallback)
|
||||
}
|
||||
|
||||
HRESULT result = volumeCallback->GetStream(u, &nextStream);
|
||||
if (result == S_FALSE)
|
||||
{
|
||||
_missingVol = true;
|
||||
continue;
|
||||
}
|
||||
if (result != S_OK)
|
||||
|
||||
if (result != S_OK && result != S_FALSE)
|
||||
return result;
|
||||
if (!nextStream)
|
||||
|
||||
if (!nextStream || result != S_OK)
|
||||
{
|
||||
if (_missingVolName.IsEmpty())
|
||||
_missingVolName = u;
|
||||
_missingVol = true;
|
||||
continue;
|
||||
}
|
||||
@@ -1335,43 +1349,45 @@ HRESULT CExtent::Open3(IInStream *stream, IArchiveOpenCallback *openCallback,
|
||||
|
||||
for (size_t i = 0; i < numGdeEntries; i++)
|
||||
{
|
||||
UInt32 v = Get32((const Byte *)table + (size_t)i * 4);
|
||||
CByteBuffer &buf = Tables.AddNew();
|
||||
if (v == 0 || v == ZeroSector)
|
||||
continue;
|
||||
if (openCallback && (i - numProcessed_Prev) >= 1024)
|
||||
{
|
||||
const UInt64 comp = complexityStart + ((UInt64)i << (k_NumMidBits + 2));
|
||||
const UInt64 volIndex2 = volIndex;
|
||||
RINOK(openCallback->SetCompleted(numVols == 1 ? NULL : &volIndex2, &comp));
|
||||
numProcessed_Prev = i;
|
||||
}
|
||||
|
||||
const size_t k_NumSectors = (size_t)1 << (k_NumMidBits - 9 + 2);
|
||||
|
||||
if (h.Is_Marker())
|
||||
{
|
||||
Byte buf2[1 << 9];
|
||||
if (ReadForHeader(stream, v - 1, buf2, 1) != S_OK)
|
||||
return S_FALSE;
|
||||
{
|
||||
CMarker m;
|
||||
m.Parse(buf2);
|
||||
if (m.Type != k_Marker_GRAIN_TABLE
|
||||
|| m.NumSectors != k_NumSectors
|
||||
|| m.SpecSize != 0)
|
||||
return S_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
const size_t k_NumMidItems = (size_t)1 << k_NumMidBits;
|
||||
|
||||
buf.Alloc(k_NumMidItems * 4);
|
||||
RINOK(ReadForHeader(stream, v, buf, k_NumSectors));
|
||||
CByteBuffer &buf = Tables.AddNew();
|
||||
|
||||
{
|
||||
const UInt32 v = Get32((const Byte *)table + (size_t)i * 4);
|
||||
if (v == 0 || v == ZeroSector)
|
||||
continue;
|
||||
if (openCallback && (i - numProcessed_Prev) >= 1024)
|
||||
{
|
||||
const UInt64 comp = complexityStart + ((UInt64)i << (k_NumMidBits + 2));
|
||||
const UInt64 volIndex2 = volIndex;
|
||||
RINOK(openCallback->SetCompleted(numVols == 1 ? NULL : &volIndex2, &comp));
|
||||
numProcessed_Prev = i;
|
||||
}
|
||||
|
||||
if (h.Is_Marker())
|
||||
{
|
||||
Byte buf2[1 << 9];
|
||||
if (ReadForHeader(stream, v - 1, buf2, 1) != S_OK)
|
||||
return S_FALSE;
|
||||
{
|
||||
CMarker m;
|
||||
m.Parse(buf2);
|
||||
if (m.Type != k_Marker_GRAIN_TABLE
|
||||
|| m.NumSectors != k_NumSectors
|
||||
|| m.SpecSize != 0)
|
||||
return S_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
buf.Alloc(k_NumMidItems * 4);
|
||||
RINOK(ReadForHeader(stream, v, buf, k_NumSectors));
|
||||
}
|
||||
|
||||
for (size_t k = 0; k < k_NumMidItems; k++)
|
||||
{
|
||||
UInt32 v = Get32((const Byte *)buf + (size_t)k * 4);
|
||||
const UInt32 v = Get32((const Byte *)buf + (size_t)k * 4);
|
||||
if (v == 0 || v == ZeroSector)
|
||||
continue;
|
||||
if (v < h.overHead)
|
||||
@@ -1431,6 +1447,8 @@ STDMETHODIMP CHandler::Close()
|
||||
_isMultiVol = false;
|
||||
_needDeflate = false;
|
||||
|
||||
_missingVolName.Empty();
|
||||
|
||||
_descriptorBuf.Free();
|
||||
_descriptor.Clear();
|
||||
|
||||
|
||||
@@ -130,9 +130,9 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
|
||||
int index = -1;
|
||||
FOR_VECTOR (i, xml.Images)
|
||||
{
|
||||
const CImageInfo &image = xml.Images[i];
|
||||
if (image.CTimeDefined)
|
||||
if (index < 0 || ::CompareFileTime(&image.CTime, &xml.Images[index].CTime) < 0)
|
||||
const CImageInfo &image2 = xml.Images[i];
|
||||
if (image2.CTimeDefined)
|
||||
if (index < 0 || ::CompareFileTime(&image2.CTime, &xml.Images[index].CTime) < 0)
|
||||
index = i;
|
||||
}
|
||||
if (index >= 0)
|
||||
@@ -147,9 +147,9 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
|
||||
int index = -1;
|
||||
FOR_VECTOR (i, xml.Images)
|
||||
{
|
||||
const CImageInfo &image = xml.Images[i];
|
||||
if (image.MTimeDefined)
|
||||
if (index < 0 || ::CompareFileTime(&image.MTime, &xml.Images[index].MTime) > 0)
|
||||
const CImageInfo &image2 = xml.Images[i];
|
||||
if (image2.MTimeDefined)
|
||||
if (index < 0 || ::CompareFileTime(&image2.MTime, &xml.Images[index].MTime) > 0)
|
||||
index = i;
|
||||
}
|
||||
if (index >= 0)
|
||||
@@ -158,7 +158,7 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
|
||||
break;
|
||||
|
||||
case kpidComment:
|
||||
if (image != NULL)
|
||||
if (image)
|
||||
{
|
||||
if (_xmlInComments)
|
||||
{
|
||||
@@ -475,14 +475,10 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
|
||||
case kpidPackSize:
|
||||
{
|
||||
UInt64 size = 0;
|
||||
if (si)
|
||||
{
|
||||
if (!si->Resource.IsSolidSmall())
|
||||
{
|
||||
size = si->Resource.PackSize;
|
||||
prop = size;
|
||||
}
|
||||
prop = si->Resource.PackSize;
|
||||
else
|
||||
{
|
||||
if (si->Resource.SolidIndex >= 0)
|
||||
@@ -493,12 +489,14 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!item.IsDir)
|
||||
prop = (UInt64)0;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case kpidSize:
|
||||
{
|
||||
UInt64 size = 0;
|
||||
if (si)
|
||||
{
|
||||
if (si->Resource.IsSolid())
|
||||
@@ -507,22 +505,19 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
{
|
||||
if (si->Resource.SolidIndex >= 0)
|
||||
{
|
||||
CSolid &ss = _db.Solids[(unsigned)si->Resource.SolidIndex];
|
||||
const CSolid &ss = _db.Solids[(unsigned)si->Resource.SolidIndex];
|
||||
prop = ss.UnpackSize;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
size = si->Resource.PackSize;
|
||||
prop = size;
|
||||
}
|
||||
prop = si->Resource.PackSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
size = si->Resource.UnpackSize;
|
||||
prop = size;
|
||||
}
|
||||
prop = si->Resource.UnpackSize;
|
||||
}
|
||||
else if (!item.IsDir)
|
||||
prop = (UInt64)0;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1028,6 +1023,7 @@ STDMETHODIMP CHandler::Open(IInStream *inStream, const UInt64 *, IArchiveOpenCal
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
|
||||
STDMETHODIMP CHandler::Close()
|
||||
{
|
||||
_firstVolumeIndex = -1;
|
||||
@@ -1093,7 +1089,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
CMyComPtr<ICompressProgressInfo> progress = lps;
|
||||
lps->Init(extractCallback, false);
|
||||
|
||||
for (i = 0; i < numItems;
|
||||
for (i = 0;; i++,
|
||||
currentTotalUnPacked += currentItemUnPacked)
|
||||
{
|
||||
currentItemUnPacked = 0;
|
||||
@@ -1102,14 +1098,18 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
lps->OutSize = currentTotalUnPacked;
|
||||
|
||||
RINOK(lps->SetCur());
|
||||
|
||||
if (i >= numItems)
|
||||
break;
|
||||
|
||||
UInt32 index = allFilesMode ? i : indices[i];
|
||||
i++;
|
||||
Int32 askMode = testMode ?
|
||||
NExtract::NAskMode::kTest :
|
||||
NExtract::NAskMode::kExtract;
|
||||
|
||||
CMyComPtr<ISequentialOutStream> realOutStream;
|
||||
RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
|
||||
|
||||
if (index >= _db.SortedItems.Size())
|
||||
{
|
||||
if (!testMode && !realOutStream)
|
||||
@@ -1153,13 +1153,16 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
continue;
|
||||
RINOK(extractCallback->PrepareOperation(askMode));
|
||||
Int32 opRes = NExtract::NOperationResult::kOK;
|
||||
|
||||
if (streamIndex != prevSuccessStreamIndex || realOutStream)
|
||||
{
|
||||
Byte digest[kHashSize];
|
||||
const CVolume &vol = _volumes[si.PartNumber];
|
||||
bool needDigest = !si.IsEmptyHash();
|
||||
|
||||
HRESULT res = unpacker.Unpack(vol.Stream, si.Resource, vol.Header, &_db,
|
||||
realOutStream, progress, needDigest ? digest : NULL);
|
||||
|
||||
if (res == S_OK)
|
||||
{
|
||||
if (!needDigest || memcmp(digest, si.Hash, kHashSize) == 0)
|
||||
@@ -1174,13 +1177,16 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
else
|
||||
return res;
|
||||
}
|
||||
|
||||
realOutStream.Release();
|
||||
RINOK(extractCallback->SetOperationResult(opRes));
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
|
||||
STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
|
||||
{
|
||||
*numItems = _db.SortedItems.Size() +
|
||||
|
||||
@@ -1351,9 +1351,11 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outSeqStream, UInt32 nu
|
||||
header.ChunkSizeBits = srcHeader.ChunkSizeBits;
|
||||
}
|
||||
|
||||
Byte buf[kHeaderSizeMax];
|
||||
header.WriteTo(buf);
|
||||
RINOK(WriteStream(outStream, buf, kHeaderSizeMax));
|
||||
{
|
||||
Byte buf[kHeaderSizeMax];
|
||||
header.WriteTo(buf);
|
||||
RINOK(WriteStream(outStream, buf, kHeaderSizeMax));
|
||||
}
|
||||
|
||||
UInt64 curPos = kHeaderSizeMax;
|
||||
|
||||
@@ -1754,14 +1756,14 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outSeqStream, UInt32 nu
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned i;
|
||||
for (i = 0; i < secBufs.Size(); i++, pos += 8)
|
||||
unsigned k;
|
||||
for (k = 0; k < secBufs.Size(); k++, pos += 8)
|
||||
{
|
||||
Set64(meta + pos, secBufs[i].Size());
|
||||
Set64(meta + pos, secBufs[k].Size());
|
||||
}
|
||||
for (i = 0; i < secBufs.Size(); i++)
|
||||
for (k = 0; k < secBufs.Size(); k++)
|
||||
{
|
||||
const CByteBuffer &buf = secBufs[i];
|
||||
const CByteBuffer &buf = secBufs[k];
|
||||
size_t size = buf.Size();
|
||||
if (size != 0)
|
||||
{
|
||||
@@ -1888,8 +1890,11 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outSeqStream, UInt32 nu
|
||||
|
||||
outStream->Seek(0, STREAM_SEEK_SET, NULL);
|
||||
header.NumImages = trees.Size();
|
||||
header.WriteTo(buf);
|
||||
return WriteStream(outStream, buf, kHeaderSizeMax);
|
||||
{
|
||||
Byte buf[kHeaderSizeMax];
|
||||
header.WriteTo(buf);
|
||||
return WriteStream(outStream, buf, kHeaderSizeMax);
|
||||
}
|
||||
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
@@ -255,7 +255,12 @@ HRESULT CUnpacker::Unpack2(
|
||||
|
||||
_solidIndex = resource.SolidIndex;
|
||||
_unpackedChunkIndex = chunkIndex;
|
||||
|
||||
if (cur < offsetInChunk)
|
||||
return E_FAIL;
|
||||
|
||||
cur -= offsetInChunk;
|
||||
|
||||
if (cur > rem)
|
||||
cur = (size_t)rem;
|
||||
|
||||
@@ -584,7 +589,7 @@ HRESULT CDatabase::ParseDirItem(size_t pos, int parent)
|
||||
RINOK(OpenCallback->SetCompleted(&numFiles, NULL));
|
||||
}
|
||||
|
||||
size_t rem = DirSize - pos;
|
||||
const size_t rem = DirSize - pos;
|
||||
if (pos < DirStartOffset || pos > DirSize || rem < 8)
|
||||
return S_FALSE;
|
||||
|
||||
@@ -656,15 +661,15 @@ HRESULT CDatabase::ParseDirItem(size_t pos, int parent)
|
||||
|
||||
for (UInt32 i = 0; i < numAltStreams; i++)
|
||||
{
|
||||
const size_t rem = DirSize - pos;
|
||||
if (pos < DirStartOffset || pos > DirSize || rem < 8)
|
||||
const size_t rem2 = DirSize - pos;
|
||||
if (pos < DirStartOffset || pos > DirSize || rem2 < 8)
|
||||
return S_FALSE;
|
||||
const Byte *p = DirData + pos;
|
||||
const UInt64 len = Get64(p);
|
||||
if ((len & align) != 0 || rem < len || len < (IsOldVersion ? 0x18 : 0x28))
|
||||
const Byte *p2 = DirData + pos;
|
||||
const UInt64 len2 = Get64(p2);
|
||||
if ((len2 & align) != 0 || rem2 < len2 || len2 < (IsOldVersion ? 0x18 : 0x28))
|
||||
return S_FALSE;
|
||||
|
||||
DirProcessed += (size_t)len;
|
||||
DirProcessed += (size_t)len2;
|
||||
if (DirProcessed > DirSize)
|
||||
return S_FALSE;
|
||||
|
||||
@@ -674,29 +679,29 @@ HRESULT CDatabase::ParseDirItem(size_t pos, int parent)
|
||||
extraOffset = 0x10;
|
||||
else
|
||||
{
|
||||
if (Get64(p + 8) != 0)
|
||||
if (Get64(p2 + 8) != 0)
|
||||
return S_FALSE;
|
||||
extraOffset = 0x24;
|
||||
}
|
||||
|
||||
UInt32 fileNameLen = Get16(p + extraOffset);
|
||||
if ((fileNameLen & 1) != 0)
|
||||
const UInt32 fileNameLen111 = Get16(p2 + extraOffset);
|
||||
if ((fileNameLen111 & 1) != 0)
|
||||
return S_FALSE;
|
||||
/* Probably different versions of ImageX can use different number of
|
||||
additional ZEROs. So we don't use exact check. */
|
||||
UInt32 fileNameLen2 = (fileNameLen == 0 ? fileNameLen : fileNameLen + 2);
|
||||
if (((extraOffset + 2 + fileNameLen2 + align) & ~align) > len)
|
||||
const UInt32 fileNameLen222 = (fileNameLen111 == 0 ? fileNameLen111 : fileNameLen111 + 2);
|
||||
if (((extraOffset + 2 + fileNameLen222 + align) & ~align) > len2)
|
||||
return S_FALSE;
|
||||
|
||||
{
|
||||
const Byte *p2 = p + extraOffset + 2;
|
||||
if (*(const UInt16 *)(p2 + fileNameLen) != 0)
|
||||
const Byte *p3 = p2 + extraOffset + 2;
|
||||
if (*(const UInt16 *)(p3 + fileNameLen111) != 0)
|
||||
return S_FALSE;
|
||||
for (UInt32 j = 0; j < fileNameLen; j += 2)
|
||||
if (*(const UInt16 *)(p2 + j) == 0)
|
||||
for (UInt32 j = 0; j < fileNameLen111; j += 2)
|
||||
if (*(const UInt16 *)(p3 + j) == 0)
|
||||
return S_FALSE;
|
||||
|
||||
// PRF(printf("\n %S", p2));
|
||||
// PRF(printf("\n %S", p3));
|
||||
}
|
||||
|
||||
|
||||
@@ -707,16 +712,16 @@ HRESULT CDatabase::ParseDirItem(size_t pos, int parent)
|
||||
|
||||
Byte *prevMeta = DirData + item.Offset;
|
||||
|
||||
if (fileNameLen == 0 &&
|
||||
if (fileNameLen111 == 0 &&
|
||||
((attrib & FILE_ATTRIBUTE_REPARSE_POINT) || !item.IsDir)
|
||||
&& (IsOldVersion || IsEmptySha(prevMeta + 0x40)))
|
||||
{
|
||||
if (IsOldVersion)
|
||||
memcpy(prevMeta + 0x10, p + 8, 4); // It's 32-bit Id
|
||||
else if (!IsEmptySha(p + 0x10))
|
||||
memcpy(prevMeta + 0x10, p2 + 8, 4); // It's 32-bit Id
|
||||
else if (!IsEmptySha(p2 + 0x10))
|
||||
{
|
||||
// if (IsEmptySha(prevMeta + 0x40))
|
||||
memcpy(prevMeta + 0x40, p + 0x10, kHashSize);
|
||||
memcpy(prevMeta + 0x40, p2 + 0x10, kHashSize);
|
||||
// else HeadersError = true;
|
||||
}
|
||||
}
|
||||
@@ -731,7 +736,7 @@ HRESULT CDatabase::ParseDirItem(size_t pos, int parent)
|
||||
Items.Add(item2);
|
||||
}
|
||||
|
||||
pos += (size_t)len;
|
||||
pos += (size_t)len2;
|
||||
}
|
||||
|
||||
if (parent < 0 && numItems == 0 && shortNameLen == 0 && fileNameLen == 0 && item.IsDir)
|
||||
@@ -968,10 +973,15 @@ static HRESULT ReadStreams(IInStream *inStream, const CHeader &h, CDatabase &db)
|
||||
RINOK(unpacker.UnpackData(inStream, h.OffsetResource, h, NULL, offsetBuf, NULL));
|
||||
|
||||
const size_t streamInfoSize = h.IsOldVersion() ? kStreamInfoSize + 2 : kStreamInfoSize;
|
||||
unsigned numItems = (unsigned)(offsetBuf.Size() / streamInfoSize);
|
||||
if ((size_t)numItems * streamInfoSize != offsetBuf.Size())
|
||||
return S_FALSE;
|
||||
db.DataStreams.Reserve(numItems);
|
||||
{
|
||||
const unsigned numItems = (unsigned)(offsetBuf.Size() / streamInfoSize);
|
||||
if ((size_t)numItems * streamInfoSize != offsetBuf.Size())
|
||||
return S_FALSE;
|
||||
const unsigned numItems2 = db.DataStreams.Size() + numItems;
|
||||
if (numItems2 < numItems)
|
||||
return S_FALSE;
|
||||
db.DataStreams.Reserve(numItems2);
|
||||
}
|
||||
|
||||
bool keepSolid = false;
|
||||
|
||||
|
||||
@@ -486,14 +486,14 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
int cur = index;
|
||||
do
|
||||
{
|
||||
const CFile &item = _files[cur];
|
||||
const CFile &item2 = _files[cur];
|
||||
if (!path.IsEmpty())
|
||||
path.InsertAtFront(CHAR_PATH_SEPARATOR);
|
||||
if (item.Name.IsEmpty())
|
||||
if (item2.Name.IsEmpty())
|
||||
path.Insert(0, "unknown");
|
||||
else
|
||||
path.Insert(0, item.Name);
|
||||
cur = item.Parent;
|
||||
path.Insert(0, item2.Name);
|
||||
cur = item2.Parent;
|
||||
}
|
||||
while (cur >= 0);
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include "../../Common/Defs.h"
|
||||
#include "../../Common/IntToString.h"
|
||||
|
||||
#include "../../Windows/PropVariant.h"
|
||||
|
||||
#include "../ICoder.h"
|
||||
|
||||
#include "../Common/CWrappers.h"
|
||||
@@ -21,7 +23,9 @@
|
||||
|
||||
#include "IArchive.h"
|
||||
|
||||
#ifndef EXTRACT_ONLY
|
||||
#include "Common/HandlerOut.h"
|
||||
#endif
|
||||
|
||||
#include "XzHandler.h"
|
||||
|
||||
@@ -83,14 +87,19 @@ class CHandler:
|
||||
CMyComPtr<IInStream> _stream;
|
||||
CMyComPtr<ISequentialInStream> _seqStream;
|
||||
|
||||
UInt32 _filterId;
|
||||
AString _methodsString;
|
||||
|
||||
#ifndef EXTRACT_ONLY
|
||||
|
||||
UInt32 _filterId;
|
||||
|
||||
void Init()
|
||||
{
|
||||
_filterId = 0;
|
||||
CMultiMethodProps::Init();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
HRESULT Open2(IInStream *inStream, /* UInt32 flags, */ IArchiveOpenCallback *callback);
|
||||
|
||||
@@ -126,9 +135,12 @@ public:
|
||||
|
||||
CHandler::CHandler()
|
||||
{
|
||||
#ifndef EXTRACT_ONLY
|
||||
Init();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static const Byte kProps[] =
|
||||
{
|
||||
kpidSize,
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "../../../Common/ComTry.h"
|
||||
#include "../../../Common/IntToString.h"
|
||||
#include "../../../Common/StringConvert.h"
|
||||
|
||||
#include "../../../Windows/PropVariant.h"
|
||||
#include "../../../Windows/TimeUtils.h"
|
||||
@@ -11,6 +12,7 @@
|
||||
#include "../../IPassword.h"
|
||||
|
||||
#include "../../Common/FilterCoder.h"
|
||||
#include "../../Common/LimitedStreams.h"
|
||||
#include "../../Common/ProgressUtils.h"
|
||||
#include "../../Common/StreamObjects.h"
|
||||
#include "../../Common/StreamUtils.h"
|
||||
@@ -141,14 +143,19 @@ static const Byte kProps[] =
|
||||
kpidCRC,
|
||||
kpidMethod,
|
||||
kpidHostOS,
|
||||
kpidUnpackVer
|
||||
kpidUnpackVer,
|
||||
kpidVolumeIndex
|
||||
};
|
||||
|
||||
static const Byte kArcProps[] =
|
||||
{
|
||||
kpidEmbeddedStubSize,
|
||||
kpidBit64,
|
||||
kpidComment
|
||||
kpidComment,
|
||||
kpidTotalPhySize,
|
||||
kpidIsVolume,
|
||||
kpidVolumeIndex,
|
||||
kpidNumVolumes
|
||||
};
|
||||
|
||||
CHandler::CHandler()
|
||||
@@ -174,18 +181,23 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
|
||||
{
|
||||
case kpidBit64: if (m_Archive.IsZip64) prop = m_Archive.IsZip64; break;
|
||||
case kpidComment: if (m_Archive.ArcInfo.Comment.Size() != 0) prop = MultiByteToUnicodeString(BytesToString(m_Archive.ArcInfo.Comment), CP_ACP); break;
|
||||
case kpidPhySize: prop = m_Archive.ArcInfo.GetPhySize(); break;
|
||||
case kpidOffset: /* if (m_Archive.ArcInfo.Base != 0) */
|
||||
prop = m_Archive.ArcInfo.Base; break;
|
||||
|
||||
case kpidPhySize: prop = m_Archive.GetPhySize(); break;
|
||||
case kpidOffset: prop = m_Archive.GetOffset(); break;
|
||||
|
||||
case kpidEmbeddedStubSize:
|
||||
{
|
||||
UInt64 stubSize = m_Archive.ArcInfo.GetEmbeddedStubSize();
|
||||
UInt64 stubSize = m_Archive.GetEmbeddedStubSize();
|
||||
if (stubSize != 0)
|
||||
prop = stubSize;
|
||||
break;
|
||||
}
|
||||
|
||||
case kpidTotalPhySize: if (m_Archive.IsMultiVol) prop = m_Archive.Vols.GetTotalSize(); break;
|
||||
case kpidVolumeIndex: if (m_Archive.IsMultiVol) prop = (UInt32)m_Archive.Vols.StartVolIndex; break;
|
||||
case kpidIsVolume: if (m_Archive.IsMultiVol) prop = true; break;
|
||||
case kpidNumVolumes: if (m_Archive.IsMultiVol) prop = (UInt32)m_Archive.Vols.Streams.Size(); break;
|
||||
|
||||
case kpidWarningFlags:
|
||||
{
|
||||
UInt32 v = 0;
|
||||
@@ -196,6 +208,18 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
|
||||
break;
|
||||
}
|
||||
|
||||
case kpidError:
|
||||
{
|
||||
if (!m_Archive.Vols.MissingName.IsEmpty())
|
||||
{
|
||||
UString s;
|
||||
s.SetFromAscii("Missing volume : ");
|
||||
s += m_Archive.Vols.MissingName;
|
||||
prop = s;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case kpidErrorFlags:
|
||||
{
|
||||
UInt32 v = 0;
|
||||
@@ -208,7 +232,7 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
|
||||
but the stream has access only to zip part.
|
||||
In that case we ignore UnavailableStart error.
|
||||
maybe we must show warning in that case. */
|
||||
UInt64 stubSize = m_Archive.ArcInfo.GetEmbeddedStubSize();
|
||||
UInt64 stubSize = m_Archive.GetEmbeddedStubSize();
|
||||
if (stubSize < (UInt64)-m_Archive.ArcInfo.Base)
|
||||
v |= kpv_ErrorFlags_UnavailableStart;
|
||||
}
|
||||
@@ -241,12 +265,14 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
COM_TRY_BEGIN
|
||||
NWindows::NCOM::CPropVariant prop;
|
||||
const CItemEx &item = m_Items[index];
|
||||
const CExtraBlock &extra = item.GetMainExtra();
|
||||
|
||||
switch (propID)
|
||||
{
|
||||
case kpidPath:
|
||||
{
|
||||
UString res;
|
||||
item.GetUnicodeString(item.Name, res, _forceCodePage, _specifiedCodePage);
|
||||
item.GetUnicodeString(res, item.Name, false, _forceCodePage, _specifiedCodePage);
|
||||
NItemName::ConvertToOSName2(res);
|
||||
prop = res;
|
||||
break;
|
||||
@@ -261,9 +287,9 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
FILETIME ft;
|
||||
UInt32 unixTime;
|
||||
UInt32 type;
|
||||
if (item.CentralExtra.GetNtfsTime(NFileHeader::NNtfsExtra::kMTime, ft))
|
||||
if (extra.GetNtfsTime(NFileHeader::NNtfsExtra::kMTime, ft))
|
||||
type = NFileTimeType::kWindows;
|
||||
else if (item.CentralExtra.GetUnixTime(true, NFileHeader::NUnixTime::kMTime, unixTime))
|
||||
else if (extra.GetUnixTime(true, NFileHeader::NUnixTime::kMTime, unixTime))
|
||||
type = NFileTimeType::kUnix;
|
||||
else
|
||||
type = NFileTimeType::kDOS;
|
||||
@@ -274,7 +300,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
case kpidCTime:
|
||||
{
|
||||
FILETIME ft;
|
||||
if (item.CentralExtra.GetNtfsTime(NFileHeader::NNtfsExtra::kCTime, ft))
|
||||
if (extra.GetNtfsTime(NFileHeader::NNtfsExtra::kCTime, ft))
|
||||
prop = ft;
|
||||
break;
|
||||
}
|
||||
@@ -282,7 +308,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
case kpidATime:
|
||||
{
|
||||
FILETIME ft;
|
||||
if (item.CentralExtra.GetNtfsTime(NFileHeader::NNtfsExtra::kATime, ft))
|
||||
if (extra.GetNtfsTime(NFileHeader::NNtfsExtra::kATime, ft))
|
||||
prop = ft;
|
||||
break;
|
||||
}
|
||||
@@ -291,10 +317,10 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
{
|
||||
FILETIME utc;
|
||||
bool defined = true;
|
||||
if (!item.CentralExtra.GetNtfsTime(NFileHeader::NNtfsExtra::kMTime, utc))
|
||||
if (!extra.GetNtfsTime(NFileHeader::NNtfsExtra::kMTime, utc))
|
||||
{
|
||||
UInt32 unixTime = 0;
|
||||
if (item.CentralExtra.GetUnixTime(true, NFileHeader::NUnixTime::kMTime, unixTime))
|
||||
if (extra.GetUnixTime(true, NFileHeader::NUnixTime::kMTime, unixTime))
|
||||
NTime::UnixTimeToFileTime(unixTime, utc);
|
||||
else
|
||||
{
|
||||
@@ -328,7 +354,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
if (item.Comment.Size() != 0)
|
||||
{
|
||||
UString res;
|
||||
item.GetUnicodeString(BytesToString(item.Comment), res, _forceCodePage, _specifiedCodePage);
|
||||
item.GetUnicodeString(res, BytesToString(item.Comment), true, _forceCodePage, _specifiedCodePage);
|
||||
prop = res;
|
||||
}
|
||||
break;
|
||||
@@ -347,7 +373,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
{
|
||||
m += kMethod_AES;
|
||||
CWzAesExtra aesField;
|
||||
if (item.CentralExtra.GetWzAes(aesField))
|
||||
if (extra.GetWzAes(aesField))
|
||||
{
|
||||
char s[16];
|
||||
s[0] = '-';
|
||||
@@ -360,7 +386,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
{
|
||||
CStrongCryptoExtra f;
|
||||
f.AlgId = 0;
|
||||
if (item.CentralExtra.GetStrongCrypto(f))
|
||||
if (extra.GetStrongCrypto(f))
|
||||
{
|
||||
const char *s = FindNameForId(k_StrongCryptoPairs, ARRAY_SIZE(k_StrongCryptoPairs), f.AlgId);
|
||||
if (s)
|
||||
@@ -373,6 +399,8 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
ConvertUInt32ToString(f.AlgId, temp + 1);
|
||||
m += temp;
|
||||
}
|
||||
if (f.CertificateIsUsed())
|
||||
m += "-Cert";
|
||||
}
|
||||
else
|
||||
m += kMethod_StrongCrypto;
|
||||
@@ -424,36 +452,17 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
case kpidUnpackVer:
|
||||
prop = (UInt32)item.ExtractVersion.Version;
|
||||
break;
|
||||
|
||||
case kpidVolumeIndex:
|
||||
prop = item.Disk;
|
||||
break;
|
||||
}
|
||||
|
||||
prop.Detach(value);
|
||||
return S_OK;
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
class CProgressImp: public CProgressVirt
|
||||
{
|
||||
CMyComPtr<IArchiveOpenCallback> _callback;
|
||||
public:
|
||||
virtual HRESULT SetCompletedLocal(UInt64 numFiles, UInt64 numBytes);
|
||||
virtual HRESULT SetTotalCD(UInt64 numFiles);
|
||||
virtual HRESULT SetCompletedCD(UInt64 numFiles);
|
||||
CProgressImp(IArchiveOpenCallback *callback): _callback(callback) {}
|
||||
};
|
||||
|
||||
HRESULT CProgressImp::SetCompletedLocal(UInt64 numFiles, UInt64 numBytes)
|
||||
{
|
||||
return _callback->SetCompleted(&numFiles, &numBytes);
|
||||
}
|
||||
|
||||
HRESULT CProgressImp::SetTotalCD(UInt64 numFiles)
|
||||
{
|
||||
return _callback->SetTotal(&numFiles, NULL);
|
||||
}
|
||||
|
||||
HRESULT CProgressImp::SetCompletedCD(UInt64 numFiles)
|
||||
{
|
||||
return _callback->SetCompleted(&numFiles, NULL);
|
||||
}
|
||||
|
||||
STDMETHODIMP CHandler::Open(IInStream *inStream,
|
||||
const UInt64 *maxCheckStartPosition, IArchiveOpenCallback *callback)
|
||||
@@ -462,9 +471,13 @@ STDMETHODIMP CHandler::Open(IInStream *inStream,
|
||||
try
|
||||
{
|
||||
Close();
|
||||
RINOK(m_Archive.Open(inStream, maxCheckStartPosition));
|
||||
CProgressImp progressImp(callback);
|
||||
return m_Archive.ReadHeaders(m_Items, callback ? &progressImp : NULL);
|
||||
HRESULT res = m_Archive.Open(inStream, maxCheckStartPosition, callback, m_Items);
|
||||
if (res != S_OK)
|
||||
{
|
||||
m_Items.Clear();
|
||||
m_Archive.ClearRefs();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
catch(...) { Close(); throw; }
|
||||
COM_TRY_END
|
||||
@@ -477,8 +490,6 @@ STDMETHODIMP CHandler::Close()
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
// CHandler::DecompressItems
|
||||
|
||||
class CLzmaDecoder:
|
||||
public ICompressCoder,
|
||||
@@ -544,6 +555,8 @@ struct CMethodItem
|
||||
CMyComPtr<ICompressCoder> Coder;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class CZipDecoder
|
||||
{
|
||||
NCrypto::NZip::CDecoder *_zipCryptoDecoderSpec;
|
||||
@@ -578,6 +591,24 @@ public:
|
||||
Int32 &res);
|
||||
};
|
||||
|
||||
|
||||
static HRESULT SkipStreamData(ISequentialInStream *stream, UInt64 size)
|
||||
{
|
||||
const size_t kBufSize = 1 << 12;
|
||||
Byte buf[kBufSize];
|
||||
for (;;)
|
||||
{
|
||||
if (size == 0)
|
||||
return S_OK;
|
||||
size_t curSize = kBufSize;
|
||||
if (curSize > size)
|
||||
curSize = (size_t)size;
|
||||
RINOK(ReadStream_FALSE(stream, buf, curSize));
|
||||
size -= curSize;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
HRESULT CZipDecoder::Decode(
|
||||
DECL_EXTERNAL_CODECS_LOC_VARS
|
||||
CInArchive &archive, const CItemEx &item,
|
||||
@@ -615,7 +646,7 @@ HRESULT CZipDecoder::Decode(
|
||||
if (!pkAesMode && id == NFileHeader::NCompressionMethod::kWzAES)
|
||||
{
|
||||
CWzAesExtra aesField;
|
||||
if (item.CentralExtra.GetWzAes(aesField))
|
||||
if (item.GetMainExtra().GetWzAes(aesField))
|
||||
{
|
||||
wzAesMode = true;
|
||||
needCRC = aesField.NeedCrc();
|
||||
@@ -628,9 +659,11 @@ HRESULT CZipDecoder::Decode(
|
||||
outStreamSpec->SetStream(realOutStream);
|
||||
outStreamSpec->Init(needCRC);
|
||||
|
||||
UInt64 authenticationPos;
|
||||
|
||||
CMyComPtr<ISequentialInStream> inStream;
|
||||
CMyComPtr<ISequentialInStream> packStream;
|
||||
|
||||
CLimitedSequentialInStream *limitedStreamSpec = new CLimitedSequentialInStream;
|
||||
CMyComPtr<ISequentialInStream> inStream(limitedStreamSpec);
|
||||
|
||||
{
|
||||
UInt64 packSize = item.PackSize;
|
||||
if (wzAesMode)
|
||||
@@ -639,9 +672,14 @@ HRESULT CZipDecoder::Decode(
|
||||
return S_OK;
|
||||
packSize -= NCrypto::NWzAes::kMacSize;
|
||||
}
|
||||
UInt64 dataPos = item.GetDataPosition();
|
||||
inStream.Attach(archive.CreateLimitedStream(dataPos, packSize));
|
||||
authenticationPos = dataPos + packSize;
|
||||
RINOK(archive.GetItemStream(item, true, packStream));
|
||||
if (!packStream)
|
||||
{
|
||||
res = NExtract::NOperationResult::kUnavailable;
|
||||
return S_OK;
|
||||
}
|
||||
limitedStreamSpec->SetStream(packStream);
|
||||
limitedStreamSpec->Init(packSize);
|
||||
}
|
||||
|
||||
CMyComPtr<ICompressFilter> cryptoFilter;
|
||||
@@ -651,7 +689,7 @@ HRESULT CZipDecoder::Decode(
|
||||
if (wzAesMode)
|
||||
{
|
||||
CWzAesExtra aesField;
|
||||
if (!item.CentralExtra.GetWzAes(aesField))
|
||||
if (!item.GetMainExtra().GetWzAes(aesField))
|
||||
return S_OK;
|
||||
id = aesField.Method;
|
||||
if (!_wzAesDecoder)
|
||||
@@ -906,9 +944,15 @@ HRESULT CZipDecoder::Decode(
|
||||
bool authOk = true;
|
||||
if (needCRC)
|
||||
crcOK = (outStreamSpec->GetCRC() == item.Crc);
|
||||
|
||||
if (wzAesMode)
|
||||
{
|
||||
inStream.Attach(archive.CreateLimitedStream(authenticationPos, NCrypto::NWzAes::kMacSize));
|
||||
const UInt64 rem = limitedStreamSpec->GetRem();
|
||||
if (rem != 0)
|
||||
if (SkipStreamData(inStream, rem) != S_OK)
|
||||
authOk = false;
|
||||
|
||||
limitedStreamSpec->Init(NCrypto::NWzAes::kMacSize);
|
||||
if (_wzAesDecoderSpec->CheckMac(inStream, authOk) != S_OK)
|
||||
authOk = false;
|
||||
}
|
||||
@@ -982,16 +1026,21 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kUnavailable));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!item.FromLocal)
|
||||
{
|
||||
HRESULT res = m_Archive.ReadLocalItemAfterCdItem(item);
|
||||
bool isAvail = true;
|
||||
HRESULT res = m_Archive.ReadLocalItemAfterCdItem(item, isAvail);
|
||||
if (res == S_FALSE)
|
||||
{
|
||||
if (item.IsDir() || realOutStream || testMode)
|
||||
{
|
||||
RINOK(extractCallback->PrepareOperation(askMode));
|
||||
realOutStream.Release();
|
||||
RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kHeadersError));
|
||||
RINOK(extractCallback->SetOperationResult(
|
||||
isAvail ?
|
||||
NExtract::NOperationResult::kHeadersError :
|
||||
NExtract::NOperationResult::kUnavailable));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -1028,6 +1077,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
|
||||
RINOK(extractCallback->SetOperationResult(res))
|
||||
}
|
||||
|
||||
lps->InSize = currentTotalPacked;
|
||||
lps->OutSize = currentTotalUnPacked;
|
||||
return lps->SetCur();
|
||||
|
||||
@@ -18,9 +18,8 @@ namespace NSignature
|
||||
const UInt32 kEcd = 0x06054B50;
|
||||
const UInt32 kEcd64 = 0x06064B50;
|
||||
const UInt32 kEcd64Locator = 0x07064B50;
|
||||
|
||||
// const UInt32 kSpan = 0x08074B50;
|
||||
const UInt32 kNoSpan = 0x30304b50; // PK00, replaces kSpan, if there is only 1 segment
|
||||
const UInt32 kSpan = 0x08074B50;
|
||||
const UInt32 kNoSpan = 0x30304B50; // PK00, replaces kSpan, if there is only 1 segment
|
||||
}
|
||||
|
||||
const unsigned kLocalHeaderSize = 4 + 26; // including signature
|
||||
@@ -84,6 +83,8 @@ namespace NFileHeader
|
||||
kNTFS = 0x0A,
|
||||
kStrongEncrypt = 0x17,
|
||||
kUnixTime = 0x5455,
|
||||
kIzUnicodeComment = 0x6375,
|
||||
kIzUnicodeName = 0x7075,
|
||||
kWzAES = 0x9901
|
||||
};
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -28,6 +28,7 @@ public:
|
||||
{ return LocalHeaderPos + LocalFullHeaderSize; }
|
||||
};
|
||||
|
||||
|
||||
struct CInArchiveInfo
|
||||
{
|
||||
Int64 Base; /* Base offset of start of archive in stream.
|
||||
@@ -40,74 +41,195 @@ struct CInArchiveInfo
|
||||
Base = ArcInfo.MarkerPos; */
|
||||
|
||||
/* The following *Pos variables contain absolute offsets in Stream */
|
||||
UInt64 MarkerPos; /* Pos of first signature, it can point to PK00 signature
|
||||
|
||||
UInt64 MarkerPos; /* Pos of first signature, it can point to kSpan/kNoSpan signature
|
||||
= MarkerPos2 in most archives
|
||||
= MarkerPos2 - 4 if there is PK00 signature */
|
||||
= MarkerPos2 - 4 if there is kSpan/kNoSpan signature */
|
||||
UInt64 MarkerPos2; // Pos of first local item signature in stream
|
||||
UInt64 FinishPos; // Finish pos of archive data
|
||||
UInt64 FinishPos; // Finish pos of archive data in starting volume
|
||||
UInt64 FileEndPos; // Finish pos of stream
|
||||
|
||||
UInt64 FirstItemRelatOffset; /* Relative offset of first local (read from cd) (relative to Base).
|
||||
= 0 in most archives
|
||||
= size of stub for some SFXs */
|
||||
bool CdWasRead;
|
||||
bool IsSpanMode;
|
||||
bool ThereIsTail;
|
||||
|
||||
// UInt32 BaseVolIndex;
|
||||
|
||||
CByteBuffer Comment;
|
||||
|
||||
CInArchiveInfo(): Base(0), MarkerPos(0), MarkerPos2(0), FinishPos(0), FileEndPos(0),
|
||||
FirstItemRelatOffset(0), CdWasRead(false) {}
|
||||
|
||||
UInt64 GetPhySize() const { return FinishPos - Base; }
|
||||
UInt64 GetEmbeddedStubSize() const
|
||||
{
|
||||
if (CdWasRead)
|
||||
return FirstItemRelatOffset;
|
||||
return MarkerPos2 - Base;
|
||||
}
|
||||
bool ThereIsTail() const { return FileEndPos > FinishPos; }
|
||||
|
||||
CInArchiveInfo():
|
||||
Base(0),
|
||||
MarkerPos(0),
|
||||
MarkerPos2(0),
|
||||
FinishPos(0),
|
||||
FileEndPos(0),
|
||||
FirstItemRelatOffset(0),
|
||||
CdWasRead(false),
|
||||
IsSpanMode(false),
|
||||
ThereIsTail(false)
|
||||
// BaseVolIndex(0)
|
||||
{}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
// BaseVolIndex = 0;
|
||||
Base = 0;
|
||||
MarkerPos = 0;
|
||||
MarkerPos2 = 0;
|
||||
FinishPos = 0;
|
||||
FileEndPos = 0;
|
||||
ThereIsTail = false;
|
||||
|
||||
FirstItemRelatOffset = 0;
|
||||
|
||||
CdWasRead = false;
|
||||
IsSpanMode = false;
|
||||
|
||||
Comment.Free();
|
||||
}
|
||||
};
|
||||
|
||||
struct CProgressVirt
|
||||
{
|
||||
virtual HRESULT SetCompletedLocal(UInt64 numFiles, UInt64 numBytes) = 0;
|
||||
virtual HRESULT SetTotalCD(UInt64 numFiles) = 0;
|
||||
virtual HRESULT SetCompletedCD(UInt64 numFiles) = 0;
|
||||
};
|
||||
|
||||
struct CCdInfo
|
||||
{
|
||||
// 64
|
||||
UInt16 VersionMade;
|
||||
UInt16 VersionNeedExtract;
|
||||
|
||||
// old zip
|
||||
UInt32 ThisDisk;
|
||||
UInt32 CdDisk;
|
||||
UInt64 NumEntries_in_ThisDisk;
|
||||
UInt64 NumEntries;
|
||||
UInt64 Size;
|
||||
UInt64 Offset;
|
||||
|
||||
void ParseEcd(const Byte *p);
|
||||
void ParseEcd64(const Byte *p);
|
||||
UInt16 CommentSize;
|
||||
|
||||
CCdInfo() { memset(this, 0, sizeof(*this)); }
|
||||
|
||||
void ParseEcd32(const Byte *p); // (p) includes signature
|
||||
void ParseEcd64e(const Byte *p); // (p) exclude signature
|
||||
};
|
||||
|
||||
|
||||
class CVols
|
||||
{
|
||||
public:
|
||||
|
||||
struct CSubStreamInfo
|
||||
{
|
||||
CMyComPtr<IInStream> Stream;
|
||||
UInt64 Size;
|
||||
|
||||
CSubStreamInfo(): Size(0) {}
|
||||
};
|
||||
|
||||
CObjectVector<CSubStreamInfo> Streams;
|
||||
int StreamIndex;
|
||||
bool NeedSeek;
|
||||
|
||||
CMyComPtr<IInStream> ZipStream;
|
||||
|
||||
bool StartIsExe; // is .exe
|
||||
bool StartIsZ; // is .zip or .zNN
|
||||
bool StartIsZip; // is .zip
|
||||
bool IsUpperCase;
|
||||
Int32 StartVolIndex; // = (NN - 1), if StartStream is .zNN
|
||||
|
||||
Int32 StartParsingVol; // if we need local parsing, we must use that stream
|
||||
unsigned NumVols;
|
||||
|
||||
int EndVolIndex; // index of last volume (ecd volume),
|
||||
// -1, if is not multivol
|
||||
|
||||
UString BaseName; // including '.'
|
||||
|
||||
UString MissingName;
|
||||
|
||||
CCdInfo ecd;
|
||||
bool ecd_wasRead;
|
||||
|
||||
void Clear()
|
||||
{
|
||||
StreamIndex = -1;
|
||||
NeedSeek = false;
|
||||
|
||||
|
||||
StartIsExe = false;
|
||||
StartIsZ = false;
|
||||
StartIsZip = false;
|
||||
IsUpperCase = false;
|
||||
|
||||
StartVolIndex = -1;
|
||||
StartParsingVol = 0;
|
||||
NumVols = 0;
|
||||
EndVolIndex = -1;
|
||||
|
||||
BaseName.Empty();
|
||||
MissingName.Empty();
|
||||
|
||||
ecd_wasRead = false;
|
||||
|
||||
Streams.Clear();
|
||||
ZipStream.Release();
|
||||
}
|
||||
|
||||
HRESULT ParseArcName(IArchiveOpenVolumeCallback *volCallback);
|
||||
|
||||
HRESULT Read(void *data, UInt32 size, UInt32 *processedSize);
|
||||
|
||||
UInt64 GetTotalSize() const
|
||||
{
|
||||
UInt64 total = 0;
|
||||
FOR_VECTOR (i, Streams)
|
||||
total += Streams[i].Size;
|
||||
return total;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class CVolStream:
|
||||
public ISequentialInStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
public:
|
||||
CVols *Vols;
|
||||
|
||||
MY_UNKNOWN_IMP1(ISequentialInStream)
|
||||
|
||||
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
|
||||
};
|
||||
|
||||
|
||||
class CInArchive
|
||||
{
|
||||
CInBuffer _inBuffer;
|
||||
bool _inBufMode;
|
||||
UInt32 m_Signature;
|
||||
UInt64 m_Position;
|
||||
|
||||
UInt64 _processedCnt;
|
||||
|
||||
bool CanStartNewVol;
|
||||
|
||||
CMyComPtr<IInStream> StreamRef;
|
||||
IInStream *Stream;
|
||||
IInStream *StartStream;
|
||||
|
||||
bool IsArcOpen;
|
||||
|
||||
HRESULT ReadVols2(IArchiveOpenVolumeCallback *volCallback,
|
||||
unsigned start, int lastDisk, int zipDisk, unsigned numMissingVolsMax, unsigned &numMissingVols);
|
||||
HRESULT ReadVols();
|
||||
|
||||
HRESULT Seek(UInt64 offset);
|
||||
HRESULT FindAndReadMarker(IInStream *stream, const UInt64 *searchHeaderSizeLimit);
|
||||
HRESULT IncreaseRealPosition(Int64 addValue);
|
||||
HRESULT FindMarker(IInStream *stream, const UInt64 *searchLimit);
|
||||
HRESULT IncreaseRealPosition(Int64 addValue, bool &isFinished);
|
||||
|
||||
HRESULT ReadBytes(void *data, UInt32 size, UInt32 *processedSize);
|
||||
void SafeReadBytes(void *data, unsigned size);
|
||||
@@ -126,12 +248,14 @@ class CInArchive
|
||||
HRESULT ReadLocalItemDescriptor(CItemEx &item);
|
||||
HRESULT ReadCdItem(CItemEx &item);
|
||||
HRESULT TryEcd64(UInt64 offset, CCdInfo &cdInfo);
|
||||
HRESULT FindCd(CCdInfo &cdInfo);
|
||||
HRESULT TryReadCd(CObjectVector<CItemEx> &items, UInt64 cdOffset, UInt64 cdSize, CProgressVirt *progress);
|
||||
HRESULT ReadCd(CObjectVector<CItemEx> &items, UInt64 &cdOffset, UInt64 &cdSize, CProgressVirt *progress);
|
||||
HRESULT ReadLocals(CObjectVector<CItemEx> &localItems, CProgressVirt *progress);
|
||||
HRESULT FindCd(bool checkOffsetMode);
|
||||
HRESULT TryReadCd(CObjectVector<CItemEx> &items, const CCdInfo &cdInfo, UInt64 cdOffset, UInt64 cdSize);
|
||||
HRESULT ReadCd(CObjectVector<CItemEx> &items, UInt32 &cdDisk, UInt64 &cdOffset, UInt64 &cdSize);
|
||||
HRESULT ReadLocals(CObjectVector<CItemEx> &localItems);
|
||||
|
||||
HRESULT ReadHeaders2(CObjectVector<CItemEx> &items, CProgressVirt *progress);
|
||||
HRESULT ReadHeaders2(CObjectVector<CItemEx> &items);
|
||||
|
||||
HRESULT GetVolStream(unsigned vol, UInt64 pos, CMyComPtr<ISequentialInStream> &stream);
|
||||
public:
|
||||
CInArchiveInfo ArcInfo;
|
||||
|
||||
@@ -142,46 +266,87 @@ public:
|
||||
bool ExtraMinorError;
|
||||
bool UnexpectedEnd;
|
||||
bool NoCentralDir;
|
||||
|
||||
CMyComPtr<IInStream> Stream;
|
||||
|
||||
void Close();
|
||||
HRESULT Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit);
|
||||
HRESULT ReadHeaders(CObjectVector<CItemEx> &items, CProgressVirt *progress);
|
||||
|
||||
bool IsOpen() const { return Stream != NULL; }
|
||||
bool AreThereErrors() const { return HeadersError || UnexpectedEnd; }
|
||||
bool MarkerIsFound;
|
||||
|
||||
bool IsMultiVol;
|
||||
bool UseDisk_in_SingleVol;
|
||||
UInt32 EcdVolIndex;
|
||||
|
||||
CVols Vols;
|
||||
|
||||
IArchiveOpenCallback *Callback;
|
||||
|
||||
CInArchive(): Stream(NULL), Callback(NULL), IsArcOpen(false) {}
|
||||
|
||||
UInt64 GetPhySize() const
|
||||
{
|
||||
if (IsMultiVol)
|
||||
return ArcInfo.FinishPos;
|
||||
else
|
||||
return ArcInfo.FinishPos - ArcInfo.Base;
|
||||
}
|
||||
|
||||
UInt64 GetOffset() const
|
||||
{
|
||||
if (IsMultiVol)
|
||||
return 0;
|
||||
else
|
||||
return ArcInfo.Base;
|
||||
}
|
||||
|
||||
|
||||
void ClearRefs();
|
||||
void Close();
|
||||
HRESULT Open(IInStream *stream, const UInt64 *searchLimit, IArchiveOpenCallback *callback, CObjectVector<CItemEx> &items);
|
||||
HRESULT ReadHeaders(CObjectVector<CItemEx> &items);
|
||||
|
||||
bool IsOpen() const { return IsArcOpen; }
|
||||
|
||||
bool AreThereErrors() const
|
||||
{
|
||||
return HeadersError
|
||||
|| UnexpectedEnd
|
||||
|| !Vols.MissingName.IsEmpty();
|
||||
}
|
||||
|
||||
bool IsLocalOffsetOK(const CItemEx &item) const
|
||||
{
|
||||
if (item.FromLocal)
|
||||
return true;
|
||||
return /* ArcInfo.Base >= 0 || */ ArcInfo.Base + (Int64)item.LocalHeaderPos >= 0;
|
||||
return (Int64)GetOffset() + (Int64)item.LocalHeaderPos >= 0;
|
||||
}
|
||||
|
||||
HRESULT ReadLocalItemAfterCdItem(CItemEx &item);
|
||||
UInt64 GetEmbeddedStubSize() const
|
||||
{
|
||||
if (ArcInfo.CdWasRead)
|
||||
return ArcInfo.FirstItemRelatOffset;
|
||||
if (IsMultiVol)
|
||||
return 0;
|
||||
return ArcInfo.MarkerPos2 - ArcInfo.Base;
|
||||
}
|
||||
|
||||
|
||||
HRESULT ReadLocalItemAfterCdItem(CItemEx &item, bool &isAvail);
|
||||
HRESULT ReadLocalItemAfterCdItemFull(CItemEx &item);
|
||||
|
||||
ISequentialInStream *CreateLimitedStream(UInt64 position, UInt64 size);
|
||||
HRESULT GetItemStream(const CItemEx &item, bool seekPackData, CMyComPtr<ISequentialInStream> &stream);
|
||||
|
||||
UInt64 GetOffsetInStream(UInt64 offsetFromArc) const { return ArcInfo.Base + offsetFromArc; }
|
||||
IInStream *GetBaseStream() { return StreamRef; }
|
||||
|
||||
bool CanUpdate() const
|
||||
{
|
||||
if (AreThereErrors())
|
||||
return false;
|
||||
if (ArcInfo.Base < 0)
|
||||
return false;
|
||||
if ((Int64)ArcInfo.MarkerPos2 < ArcInfo.Base)
|
||||
if (AreThereErrors()
|
||||
|| IsMultiVol
|
||||
|| ArcInfo.Base < 0
|
||||
|| (Int64)ArcInfo.MarkerPos2 < ArcInfo.Base
|
||||
|| ArcInfo.ThereIsTail
|
||||
|| GetEmbeddedStubSize() != 0)
|
||||
return false;
|
||||
|
||||
// 7-zip probably can update archives with embedded stubs.
|
||||
// we just disable that feature for more safety.
|
||||
if (ArcInfo.GetEmbeddedStubSize() != 0)
|
||||
return false;
|
||||
|
||||
if (ArcInfo.ThereIsTail())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "../../../../C/CpuArch.h"
|
||||
#include "../../../../C/7zCrc.h"
|
||||
|
||||
#include "../../../Common/MyLinux.h"
|
||||
#include "../../../Common/StringConvert.h"
|
||||
|
||||
#include "../Common/ItemNameUtils.h"
|
||||
|
||||
@@ -80,6 +82,30 @@ bool CExtraSubBlock::ExtractUnixTime(bool isCentral, unsigned index, UInt32 &res
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool CExtraBlock::GetNtfsTime(unsigned index, FILETIME &ft) const
|
||||
{
|
||||
FOR_VECTOR (i, SubBlocks)
|
||||
{
|
||||
const CExtraSubBlock &sb = SubBlocks[i];
|
||||
if (sb.ID == NFileHeader::NExtraID::kNTFS)
|
||||
return sb.ExtractNtfsTime(index, ft);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CExtraBlock::GetUnixTime(bool isCentral, unsigned index, UInt32 &res) const
|
||||
{
|
||||
FOR_VECTOR (i, SubBlocks)
|
||||
{
|
||||
const CExtraSubBlock &sb = SubBlocks[i];
|
||||
if (sb.ID == NFileHeader::NExtraID::kUnixTime)
|
||||
return sb.ExtractUnixTime(isCentral, index, res);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool CLocalItem::IsDir() const
|
||||
{
|
||||
return NItemName::HasTailSlash(Name, GetCodePage());
|
||||
@@ -89,12 +115,29 @@ bool CItem::IsDir() const
|
||||
{
|
||||
if (NItemName::HasTailSlash(Name, GetCodePage()))
|
||||
return true;
|
||||
|
||||
Byte hostOS = GetHostOS();
|
||||
|
||||
if (Size == 0 && PackSize == 0 && !Name.IsEmpty() && Name.Back() == '\\')
|
||||
{
|
||||
// do we need to use CharPrevExA?
|
||||
// .NET Framework 4.5 : System.IO.Compression::CreateFromDirectory() probably writes backslashes to headers?
|
||||
// so we support that case
|
||||
switch (hostOS)
|
||||
{
|
||||
case NHostOS::kFAT:
|
||||
case NHostOS::kNTFS:
|
||||
case NHostOS::kHPFS:
|
||||
case NHostOS::kVFAT:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!FromCentral)
|
||||
return false;
|
||||
|
||||
UInt16 highAttrib = (UInt16)((ExternalAttrib >> 16 ) & 0xFFFF);
|
||||
|
||||
Byte hostOS = GetHostOS();
|
||||
switch (hostOS)
|
||||
{
|
||||
case NHostOS::kAMIGA:
|
||||
@@ -158,4 +201,53 @@ bool CItem::GetPosixAttrib(UInt32 &attrib) const
|
||||
return false;
|
||||
}
|
||||
|
||||
void CItem::GetUnicodeString(UString &res, const AString &s, bool isComment, bool useSpecifiedCodePage, UINT codePage) const
|
||||
{
|
||||
bool isUtf8 = IsUtf8();
|
||||
bool ignore_Utf8_Errors = true;
|
||||
|
||||
if (!isUtf8)
|
||||
{
|
||||
{
|
||||
const unsigned id = isComment ?
|
||||
NFileHeader::NExtraID::kIzUnicodeComment:
|
||||
NFileHeader::NExtraID::kIzUnicodeName;
|
||||
const CObjectVector<CExtraSubBlock> &subBlocks = GetMainExtra().SubBlocks;
|
||||
|
||||
FOR_VECTOR (i, subBlocks)
|
||||
{
|
||||
const CExtraSubBlock &sb = subBlocks[i];
|
||||
if (sb.ID == id)
|
||||
{
|
||||
AString utf;
|
||||
if (sb.ExtractIzUnicode(CrcCalc(s, s.Len()), utf))
|
||||
if (ConvertUTF8ToUnicode(utf, res))
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (useSpecifiedCodePage)
|
||||
isUtf8 = (codePage == CP_UTF8);
|
||||
#ifdef _WIN32
|
||||
else if (GetHostOS() == NFileHeader::NHostOS::kUnix)
|
||||
{
|
||||
/* Some ZIP archives in Unix use UTF-8 encoding without Utf8 flag in header.
|
||||
We try to get name as UTF-8.
|
||||
Do we need to do it in POSIX version also? */
|
||||
isUtf8 = true;
|
||||
ignore_Utf8_Errors = false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
if (isUtf8)
|
||||
if (ConvertUTF8ToUnicode(s, res) || ignore_Utf8_Errors)
|
||||
return;
|
||||
|
||||
MultiByteToUnicodeString2(res, s, useSpecifiedCodePage ? codePage : GetCodePage());
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include "../../../Common/MyBuffer.h"
|
||||
#include "../../../Common/MyString.h"
|
||||
#include "../../../Common/StringConvert.h"
|
||||
#include "../../../Common/UTFConvert.h"
|
||||
|
||||
#include "ZipHeader.h"
|
||||
@@ -28,6 +27,23 @@ struct CExtraSubBlock
|
||||
|
||||
bool ExtractNtfsTime(unsigned index, FILETIME &ft) const;
|
||||
bool ExtractUnixTime(bool isCentral, unsigned index, UInt32 &res) const;
|
||||
|
||||
bool ExtractIzUnicode(UInt32 crc, AString &name) const
|
||||
{
|
||||
unsigned size = (unsigned)Data.Size();
|
||||
if (size < 1 + 4)
|
||||
return false;
|
||||
const Byte *p = (const Byte *)Data;
|
||||
if (p[0] > 1)
|
||||
return false;
|
||||
if (crc != GetUi32(p + 1))
|
||||
return false;
|
||||
size -= 5;
|
||||
name.SetFrom_CalcLen((const char *)p + 5, size);
|
||||
if (size != name.Len())
|
||||
return false;
|
||||
return CheckUTF8(name, false);
|
||||
}
|
||||
};
|
||||
|
||||
const unsigned k_WzAesExtra_Size = 7;
|
||||
@@ -109,6 +125,8 @@ struct CStrongCryptoExtra
|
||||
Flags = GetUi16(p + 6);
|
||||
return (Format == 2);
|
||||
}
|
||||
|
||||
bool CertificateIsUsed() const { return (Flags > 0x0001); }
|
||||
};
|
||||
|
||||
struct CExtraBlock
|
||||
@@ -155,27 +173,8 @@ struct CExtraBlock
|
||||
}
|
||||
*/
|
||||
|
||||
bool GetNtfsTime(unsigned index, FILETIME &ft) const
|
||||
{
|
||||
FOR_VECTOR (i, SubBlocks)
|
||||
{
|
||||
const CExtraSubBlock &sb = SubBlocks[i];
|
||||
if (sb.ID == NFileHeader::NExtraID::kNTFS)
|
||||
return sb.ExtractNtfsTime(index, ft);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GetUnixTime(bool isCentral, unsigned index, UInt32 &res) const
|
||||
{
|
||||
FOR_VECTOR (i, SubBlocks)
|
||||
{
|
||||
const CExtraSubBlock &sb = SubBlocks[i];
|
||||
if (sb.ID == NFileHeader::NExtraID::kUnixTime)
|
||||
return sb.ExtractUnixTime(isCentral, index, res);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool GetNtfsTime(unsigned index, FILETIME &ft) const;
|
||||
bool GetUnixTime(bool isCentral, unsigned index, UInt32 &res) const;
|
||||
|
||||
void RemoveUnknownSubBlocks()
|
||||
{
|
||||
@@ -200,6 +199,8 @@ public:
|
||||
UInt64 PackSize;
|
||||
UInt32 Time;
|
||||
UInt32 Crc;
|
||||
|
||||
UInt32 Disk;
|
||||
|
||||
AString Name;
|
||||
|
||||
@@ -272,45 +273,22 @@ public:
|
||||
MadeByVersion.HostOS = 0;
|
||||
}
|
||||
|
||||
const CExtraBlock &GetMainExtra() const { return *(FromCentral ? &CentralExtra : &LocalExtra); }
|
||||
|
||||
bool IsDir() const;
|
||||
UInt32 GetWinAttrib() const;
|
||||
bool GetPosixAttrib(UInt32 &attrib) const;
|
||||
|
||||
Byte GetHostOS() const { return FromCentral ? MadeByVersion.HostOS : ExtractVersion.HostOS; }
|
||||
|
||||
void GetUnicodeString(const AString &s, UString &res, bool useSpecifiedCodePage, UINT codePage) const
|
||||
{
|
||||
bool isUtf8 = IsUtf8();
|
||||
bool ignore_Utf8_Errors = true;
|
||||
|
||||
#ifdef _WIN32
|
||||
if (!isUtf8)
|
||||
{
|
||||
if (useSpecifiedCodePage)
|
||||
isUtf8 = (codePage == CP_UTF8);
|
||||
else if (GetHostOS() == NFileHeader::NHostOS::kUnix)
|
||||
{
|
||||
/* Some ZIP archives in Unix use UTF-8 encoding without Utf8 flag in header.
|
||||
We try to get name as UTF-8.
|
||||
Do we need to do it in POSIX version also? */
|
||||
isUtf8 = true;
|
||||
ignore_Utf8_Errors = false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (isUtf8)
|
||||
if (ConvertUTF8ToUnicode(s, res) || ignore_Utf8_Errors)
|
||||
return;
|
||||
MultiByteToUnicodeString2(res, s, useSpecifiedCodePage ? codePage : GetCodePage());
|
||||
}
|
||||
void GetUnicodeString(UString &res, const AString &s, bool isComment, bool useSpecifiedCodePage, UINT codePage) const;
|
||||
|
||||
bool IsThereCrc() const
|
||||
{
|
||||
if (Method == NFileHeader::NCompressionMethod::kWzAES)
|
||||
{
|
||||
CWzAesExtra aesField;
|
||||
if (CentralExtra.GetWzAes(aesField))
|
||||
if (GetMainExtra().GetWzAes(aesField))
|
||||
return aesField.NeedCrc();
|
||||
}
|
||||
return (Crc != 0 || !IsDir());
|
||||
@@ -320,8 +298,10 @@ public:
|
||||
{
|
||||
Byte hostOS = GetHostOS();
|
||||
return (UINT)((
|
||||
hostOS == NFileHeader::NHostOS::kFAT ||
|
||||
hostOS == NFileHeader::NHostOS::kNTFS) ? CP_OEMCP : CP_ACP);
|
||||
hostOS == NFileHeader::NHostOS::kFAT
|
||||
|| hostOS == NFileHeader::NHostOS::kNTFS
|
||||
|| hostOS == NFileHeader::NHostOS::kUnix // do we need it?
|
||||
) ? CP_OEMCP : CP_ACP);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -12,10 +12,11 @@ namespace NZip {
|
||||
static const Byte k_Signature[] = {
|
||||
4, 0x50, 0x4B, 0x03, 0x04,
|
||||
4, 0x50, 0x4B, 0x05, 0x06,
|
||||
6, 0x50, 0x4B, 0x07, 0x08, 0x50, 0x4B,
|
||||
6, 0x50, 0x4B, 0x30, 0x30, 0x50, 0x4B };
|
||||
|
||||
REGISTER_ARC_IO(
|
||||
"zip", "zip zipx jar xpi odt ods docx xlsx epub", 0, 1,
|
||||
"zip", "zip z01 zipx jar xpi odt ods docx xlsx epub", 0, 1,
|
||||
k_Signature,
|
||||
0,
|
||||
NArcInfoFlags::kFindSignature |
|
||||
|
||||
@@ -52,16 +52,6 @@ static HRESULT CopyBlockToArchive(ISequentialInStream *inStream, UInt64 size,
|
||||
return NCompress::CopyStream_ExactSize(inStream, outStream, size, progress);
|
||||
}
|
||||
|
||||
static HRESULT WriteRange(IInStream *inStream, COutArchive &outArchive,
|
||||
const CUpdateRange &range, ICompressProgressInfo *progress)
|
||||
{
|
||||
UInt64 position;
|
||||
RINOK(inStream->Seek(range.Position, STREAM_SEEK_SET, &position));
|
||||
RINOK(CopyBlockToArchive(inStream, range.Size, outArchive, progress));
|
||||
return progress->SetRatioInfo(&range.Size, &range.Size);
|
||||
}
|
||||
|
||||
|
||||
static void SetFileHeader(
|
||||
COutArchive &archive,
|
||||
const CCompressionMethodMode &options,
|
||||
@@ -358,9 +348,12 @@ static HRESULT UpdateItemOldData(
|
||||
return E_NOTIMPL;
|
||||
|
||||
// use old name size.
|
||||
// CUpdateRange range(item.GetLocalExtraPosition(), item.LocalExtraSize + item.PackSize);
|
||||
CUpdateRange range(inArchive->GetOffsetInStream(itemEx.GetDataPosition()), itemEx.PackSize);
|
||||
|
||||
CMyComPtr<ISequentialInStream> packStream;
|
||||
RINOK(inArchive->GetItemStream(itemEx, true, packStream));
|
||||
if (!packStream)
|
||||
return E_NOTIMPL;
|
||||
|
||||
// we keep ExternalAttrib and some another properties from old archive
|
||||
// item.ExternalAttrib = ui.Attrib;
|
||||
|
||||
@@ -378,19 +371,27 @@ static HRESULT UpdateItemOldData(
|
||||
|
||||
archive.PrepareWriteCompressedData2(item.Name.Len(), item.Size, item.PackSize, item.LocalExtra.HasWzAes());
|
||||
archive.WriteLocalHeader(item);
|
||||
RINOK(WriteRange(inArchive->Stream, archive, range, progress));
|
||||
complexity += range.Size;
|
||||
|
||||
RINOK(CopyBlockToArchive(packStream, itemEx.PackSize, archive, progress));
|
||||
|
||||
complexity += itemEx.PackSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
CUpdateRange range(inArchive->GetOffsetInStream(itemEx.LocalHeaderPos), itemEx.GetLocalFullSize());
|
||||
CMyComPtr<ISequentialInStream> packStream;
|
||||
RINOK(inArchive->GetItemStream(itemEx, false, packStream));
|
||||
if (!packStream)
|
||||
return E_NOTIMPL;
|
||||
|
||||
// set new header position
|
||||
item.LocalHeaderPos = archive.GetCurPos();
|
||||
|
||||
RINOK(WriteRange(inArchive->Stream, archive, range, progress));
|
||||
complexity += range.Size;
|
||||
archive.MoveCurPos(range.Size);
|
||||
const UInt64 rangeSize = itemEx.GetLocalFullSize();
|
||||
|
||||
RINOK(CopyBlockToArchive(packStream, rangeSize, archive, progress));
|
||||
|
||||
complexity += rangeSize;
|
||||
archive.MoveCurPos(rangeSize);
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
@@ -595,6 +596,7 @@ static HRESULT Update2(
|
||||
UInt64 numBytesToCompress = 0;
|
||||
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < updateItems.Size(); i++)
|
||||
{
|
||||
const CUpdateItem &ui = updateItems[i];
|
||||
@@ -730,7 +732,6 @@ static HRESULT Update2(
|
||||
for (i = 0; i < updateItems.Size(); i++)
|
||||
refs.Refs.Add(CMemBlocks2());
|
||||
|
||||
UInt32 i;
|
||||
for (i = 0; i < numThreads; i++)
|
||||
threads.Threads.Add(CThreadInfo(options2));
|
||||
|
||||
@@ -803,9 +804,9 @@ static HRESULT Update2(
|
||||
RINOK(updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK));
|
||||
}
|
||||
|
||||
for (UInt32 i = 0; i < numThreads; i++)
|
||||
for (UInt32 k = 0; k < numThreads; k++)
|
||||
{
|
||||
CThreadInfo &threadInfo = threads.Threads[i];
|
||||
CThreadInfo &threadInfo = threads.Threads[k];
|
||||
if (threadInfo.IsFree)
|
||||
{
|
||||
threadInfo.IsFree = false;
|
||||
@@ -821,7 +822,7 @@ static HRESULT Update2(
|
||||
threadInfo.UpdateIndex = mtItemIndex - 1;
|
||||
|
||||
compressingCompletedEvents.Add(threadInfo.CompressionCompletedEvent);
|
||||
threadIndices.Add(i);
|
||||
threadIndices.Add(k);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -926,10 +927,10 @@ static HRESULT Update2(
|
||||
}
|
||||
else
|
||||
{
|
||||
CMemBlocks2 &memRef = refs.Refs[threadInfo.UpdateIndex];
|
||||
threadInfo.OutStreamSpec->DetachData(memRef);
|
||||
memRef.CompressingResult = threadInfo.CompressingResult;
|
||||
memRef.Defined = true;
|
||||
CMemBlocks2 &memRef2 = refs.Refs[threadInfo.UpdateIndex];
|
||||
threadInfo.OutStreamSpec->DetachData(memRef2);
|
||||
memRef2.CompressingResult = threadInfo.CompressingResult;
|
||||
memRef2.Defined = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -1191,10 +1192,11 @@ HRESULT Update(
|
||||
|
||||
if (inArchive)
|
||||
{
|
||||
if (inArchive->ArcInfo.Base > 0 && !removeSfx)
|
||||
if (!inArchive->IsMultiVol && inArchive->ArcInfo.Base > 0 && !removeSfx)
|
||||
{
|
||||
RINOK(inArchive->Stream->Seek(0, STREAM_SEEK_SET, NULL));
|
||||
RINOK(NCompress::CopyStream_ExactSize(inArchive->Stream, outStreamReal, inArchive->ArcInfo.Base, NULL));
|
||||
IInStream *baseStream = inArchive->GetBaseStream();
|
||||
RINOK(baseStream->Seek(0, STREAM_SEEK_SET, NULL));
|
||||
RINOK(NCompress::CopyStream_ExactSize(baseStream, outStreamReal, inArchive->ArcInfo.Base, NULL));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1210,11 +1212,12 @@ HRESULT Update(
|
||||
|
||||
if (inArchive)
|
||||
{
|
||||
if ((Int64)inArchive->ArcInfo.MarkerPos2 > inArchive->ArcInfo.Base)
|
||||
if (!inArchive->IsMultiVol && (Int64)inArchive->ArcInfo.MarkerPos2 > inArchive->ArcInfo.Base)
|
||||
{
|
||||
RINOK(inArchive->Stream->Seek(inArchive->ArcInfo.Base, STREAM_SEEK_SET, NULL));
|
||||
IInStream *baseStream = inArchive->GetBaseStream();
|
||||
RINOK(baseStream->Seek(inArchive->ArcInfo.Base, STREAM_SEEK_SET, NULL));
|
||||
UInt64 embStubSize = inArchive->ArcInfo.MarkerPos2 - inArchive->ArcInfo.Base;
|
||||
RINOK(NCompress::CopyStream_ExactSize(inArchive->Stream, outStream, embStubSize, NULL));
|
||||
RINOK(NCompress::CopyStream_ExactSize(baseStream, outStream, embStubSize, NULL));
|
||||
outArchive.MoveCurPos(embStubSize);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -554,14 +554,6 @@ SOURCE=..\..\Common\CreateCoder.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Archive\Common\CrossThreadProgress.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Archive\Common\CrossThreadProgress.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Common\CWrappers.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@@ -1285,14 +1277,6 @@ SOURCE=..\..\Archive\7z\7zFolderInStream.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Archive\7z\7zFolderOutStream.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Archive\7z\7zFolderOutStream.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Archive\7z\7zHandler.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
@@ -77,7 +77,6 @@ AR_OBJS = \
|
||||
|
||||
AR_COMMON_OBJS = \
|
||||
$O\CoderMixer2.obj \
|
||||
$O\CrossThreadProgress.obj \
|
||||
$O\DummyOutStream.obj \
|
||||
$O\FindSignature.obj \
|
||||
$O\HandlerOut.obj \
|
||||
@@ -94,7 +93,6 @@ AR_COMMON_OBJS = \
|
||||
$O\7zEncode.obj \
|
||||
$O\7zExtract.obj \
|
||||
$O\7zFolderInStream.obj \
|
||||
$O\7zFolderOutStream.obj \
|
||||
$O\7zHandler.obj \
|
||||
$O\7zHandlerOut.obj \
|
||||
$O\7zHeader.obj \
|
||||
|
||||
@@ -546,14 +546,6 @@ SOURCE=..\..\Common\CreateCoder.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Archive\Common\CrossThreadProgress.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Archive\Common\CrossThreadProgress.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Common\CWrappers.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@@ -812,14 +804,6 @@ SOURCE=..\..\Compress\LzmaEncoder.h
|
||||
|
||||
SOURCE=..\..\Compress\LzmaRegister.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Compress\RangeCoder.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Compress\RangeCoderBit.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Archive"
|
||||
|
||||
@@ -865,14 +849,6 @@ SOURCE=..\..\Archive\7z\7zFolderInStream.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Archive\7z\7zFolderOutStream.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Archive\7z\7zFolderOutStream.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Archive\7z\7zHandler.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user