mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-17 16:11:52 -06:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
603abd5528 | ||
|
|
232ce79574 | ||
|
|
1eddf527ca | ||
|
|
bec3b479dc |
25
C/7zArcIn.c
25
C/7zArcIn.c
@@ -1,5 +1,5 @@
|
||||
/* 7zArcIn.c -- 7z Input functions
|
||||
2016-03-31 : Igor Pavlov : Public domain */
|
||||
2016-05-16 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
@@ -1100,13 +1100,11 @@ static SRes SzReadHeader2(
|
||||
ISzAlloc *allocTemp
|
||||
)
|
||||
{
|
||||
UInt64 type;
|
||||
UInt32 numFiles = 0;
|
||||
UInt32 numEmptyStreams = 0;
|
||||
CSubStreamInfo ssi;
|
||||
const Byte *emptyStreams = NULL;
|
||||
const Byte *emptyFiles = NULL;
|
||||
|
||||
{
|
||||
UInt64 type;
|
||||
|
||||
SzData_Clear(&ssi.sdSizes);
|
||||
SzData_Clear(&ssi.sdCRCs);
|
||||
SzData_Clear(&ssi.sdNumSubStreams);
|
||||
@@ -1120,9 +1118,9 @@ static SRes SzReadHeader2(
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
UInt64 type;
|
||||
RINOK(ReadID(sd, &type));
|
||||
if (type == k7zIdEnd)
|
||||
UInt64 type2;
|
||||
RINOK(ReadID(sd, &type2));
|
||||
if (type2 == k7zIdEnd)
|
||||
break;
|
||||
RINOK(SkipData(sd));
|
||||
}
|
||||
@@ -1160,6 +1158,13 @@ static SRes SzReadHeader2(
|
||||
|
||||
if (type != k7zIdFilesInfo)
|
||||
return SZ_ERROR_ARCHIVE;
|
||||
}
|
||||
|
||||
{
|
||||
UInt32 numFiles = 0;
|
||||
UInt32 numEmptyStreams = 0;
|
||||
const Byte *emptyStreams = NULL;
|
||||
const Byte *emptyFiles = NULL;
|
||||
|
||||
RINOK(SzReadNumber32(sd, &numFiles));
|
||||
p->NumFiles = numFiles;
|
||||
@@ -1458,7 +1463,7 @@ static SRes SzReadHeader2(
|
||||
if (ssi.sdNumSubStreams.Data && ssi.sdNumSubStreams.Size != 0)
|
||||
return SZ_ERROR_ARCHIVE;
|
||||
}
|
||||
|
||||
}
|
||||
return SZ_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#define MY_VER_MAJOR 16
|
||||
#define MY_VER_MINOR 00
|
||||
#define MY_VER_MINOR 04
|
||||
#define MY_VER_BUILD 0
|
||||
#define MY_VERSION_NUMBERS "16.00"
|
||||
#define MY_VERSION "16.00"
|
||||
#define MY_DATE "2016-05-10"
|
||||
#define MY_VERSION_NUMBERS "16.04"
|
||||
#define MY_VERSION "16.04"
|
||||
#define MY_DATE "2016-10-04"
|
||||
#undef MY_COPYRIGHT
|
||||
#undef MY_VERSION_COPYRIGHT_DATE
|
||||
#define MY_AUTHOR_NAME "Igor Pavlov"
|
||||
|
||||
10
C/Aes.c
10
C/Aes.c
@@ -1,5 +1,5 @@
|
||||
/* Aes.c -- AES encryption / decryption
|
||||
2015-02-23 : Igor Pavlov : Public domain */
|
||||
2016-05-21 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
@@ -167,10 +167,10 @@ void MY_FAST_CALL Aes_SetKey_Dec(UInt32 *w, const Byte *key, unsigned keySize)
|
||||
{
|
||||
UInt32 r = w[i];
|
||||
w[i] =
|
||||
D[ Sbox[gb0(r)]] ^
|
||||
D[0x100 + Sbox[gb1(r)]] ^
|
||||
D[0x200 + Sbox[gb2(r)]] ^
|
||||
D[0x300 + Sbox[gb3(r)]];
|
||||
D[ (unsigned)Sbox[gb0(r)]] ^
|
||||
D[0x100 + (unsigned)Sbox[gb1(r)]] ^
|
||||
D[0x200 + (unsigned)Sbox[gb2(r)]] ^
|
||||
D[0x300 + (unsigned)Sbox[gb3(r)]];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* CpuArch.h -- CPU specific code
|
||||
2015-12-01: Igor Pavlov : Public domain */
|
||||
2016-06-09: Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __CPU_ARCH_H
|
||||
#define __CPU_ARCH_H
|
||||
@@ -66,6 +66,7 @@ MY_CPU_LE_UNALIGN means that CPU is LITTLE ENDIAN and CPU supports unaligned mem
|
||||
|| defined(__MIPSEL__) \
|
||||
|| defined(__MIPSEL) \
|
||||
|| defined(_MIPSEL) \
|
||||
|| defined(__BFIN__) \
|
||||
|| (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
|
||||
#define MY_CPU_LE
|
||||
#endif
|
||||
|
||||
87
C/DllSecur.c
Normal file
87
C/DllSecur.c
Normal file
@@ -0,0 +1,87 @@
|
||||
/* DllSecur.c -- DLL loading security
|
||||
2016-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include "DllSecur.h"
|
||||
|
||||
#ifndef UNDER_CE
|
||||
|
||||
typedef BOOL (WINAPI *Func_SetDefaultDllDirectories)(DWORD DirectoryFlags);
|
||||
|
||||
#define MY_LOAD_LIBRARY_SEARCH_USER_DIRS 0x400
|
||||
#define MY_LOAD_LIBRARY_SEARCH_SYSTEM32 0x800
|
||||
|
||||
static const char * const g_Dlls =
|
||||
#ifndef _CONSOLE
|
||||
"UXTHEME\0"
|
||||
#endif
|
||||
"USERENV\0"
|
||||
"SETUPAPI\0"
|
||||
"APPHELP\0"
|
||||
"PROPSYS\0"
|
||||
"DWMAPI\0"
|
||||
"CRYPTBASE\0"
|
||||
"OLEACC\0"
|
||||
"CLBCATQ\0"
|
||||
;
|
||||
|
||||
#endif
|
||||
|
||||
void LoadSecurityDlls()
|
||||
{
|
||||
#ifndef UNDER_CE
|
||||
|
||||
wchar_t buf[MAX_PATH + 100];
|
||||
|
||||
{
|
||||
// at Vista (ver 6.0) : CoCreateInstance(CLSID_ShellLink, ...) doesn't work after SetDefaultDllDirectories() : Check it ???
|
||||
OSVERSIONINFO vi;
|
||||
vi.dwOSVersionInfoSize = sizeof(vi);
|
||||
if (!GetVersionEx(&vi) || vi.dwMajorVersion != 6 || vi.dwMinorVersion != 0)
|
||||
{
|
||||
Func_SetDefaultDllDirectories setDllDirs = (Func_SetDefaultDllDirectories)
|
||||
GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "SetDefaultDllDirectories");
|
||||
if (setDllDirs)
|
||||
if (setDllDirs(MY_LOAD_LIBRARY_SEARCH_SYSTEM32 | MY_LOAD_LIBRARY_SEARCH_USER_DIRS))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
unsigned len = GetSystemDirectoryW(buf, MAX_PATH + 2);
|
||||
if (len == 0 || len > MAX_PATH)
|
||||
return;
|
||||
}
|
||||
{
|
||||
const char *dll;
|
||||
unsigned pos = (unsigned)lstrlenW(buf);
|
||||
|
||||
if (buf[pos - 1] != '\\')
|
||||
buf[pos++] = '\\';
|
||||
|
||||
for (dll = g_Dlls; dll[0] != 0;)
|
||||
{
|
||||
unsigned k = 0;
|
||||
for (;;)
|
||||
{
|
||||
char c = *dll++;
|
||||
buf[pos + k] = c;
|
||||
k++;
|
||||
if (c == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
lstrcatW(buf, L".dll");
|
||||
LoadLibraryExW(buf, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
19
C/DllSecur.h
Normal file
19
C/DllSecur.h
Normal file
@@ -0,0 +1,19 @@
|
||||
/* DllSecur.h -- DLL loading for security
|
||||
2016-06-08 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __DLL_SECUR_H
|
||||
#define __DLL_SECUR_H
|
||||
|
||||
#include "7zTypes.h"
|
||||
|
||||
EXTERN_C_BEGIN
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
void LoadSecurityDlls();
|
||||
|
||||
#endif
|
||||
|
||||
EXTERN_C_END
|
||||
|
||||
#endif
|
||||
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]]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* Lzma86Dec.c -- LZMA + x86 (BCJ) Filter Decoder
|
||||
2015-11-08 : Igor Pavlov : Public domain */
|
||||
2016-05-16 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
@@ -9,9 +9,6 @@
|
||||
#include "Bra.h"
|
||||
#include "LzmaDec.h"
|
||||
|
||||
static void *SzAlloc(void *p, size_t size) { UNUSED_VAR(p); return MyAlloc(size); }
|
||||
static void SzFree(void *p, void *address) { UNUSED_VAR(p); MyFree(address); }
|
||||
|
||||
SRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize)
|
||||
{
|
||||
unsigned i;
|
||||
@@ -25,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,5 @@
|
||||
/* Lzma86Enc.c -- LZMA + x86 (BCJ) Filter Encoder
|
||||
2015-11-08 : Igor Pavlov : Public domain */
|
||||
2016-05-16 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
@@ -13,13 +13,9 @@
|
||||
|
||||
#define SZE_OUT_OVERFLOW SZE_DATA_ERROR
|
||||
|
||||
static void *SzAlloc(void *p, size_t size) { UNUSED_VAR(p); return MyAlloc(size); }
|
||||
static void SzFree(void *p, void *address) { UNUSED_VAR(p); MyFree(address); }
|
||||
|
||||
int Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen,
|
||||
int level, UInt32 dictSize, int filterMode)
|
||||
{
|
||||
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
|
||||
|
||||
39
C/LzmaEnc.c
39
C/LzmaEnc.c
@@ -1,5 +1,5 @@
|
||||
/* LzmaEnc.c -- LZMA Encoder
|
||||
2015-11-08 : 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))) ? \
|
||||
@@ -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];
|
||||
@@ -1176,8 +1181,11 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
for (;;)
|
||||
{
|
||||
UInt32 numAvail;
|
||||
UInt32 numAvailFull, newLen, numPairs, posPrev, state, posState, startLen;
|
||||
UInt32 curPrice, curAnd1Price, matchPrice, repMatchPrice;
|
||||
Bool nextIsChar;
|
||||
@@ -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])
|
||||
{
|
||||
@@ -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++)
|
||||
|
||||
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
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* Ppmd7.c -- PPMdH codec
|
||||
2015-09-28 : Igor Pavlov : Public domain
|
||||
2016-05-21 : Igor Pavlov : Public domain
|
||||
This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
@@ -639,10 +639,10 @@ CPpmd_See *Ppmd7_MakeEscFreq(CPpmd7 *p, unsigned numMasked, UInt32 *escFreq)
|
||||
unsigned nonMasked = p->MinContext->NumStats - numMasked;
|
||||
if (p->MinContext->NumStats != 256)
|
||||
{
|
||||
see = p->See[p->NS2Indx[nonMasked - 1]] +
|
||||
see = p->See[(unsigned)p->NS2Indx[nonMasked - 1]] +
|
||||
(nonMasked < (unsigned)SUFFIX(p->MinContext)->NumStats - p->MinContext->NumStats) +
|
||||
2 * (p->MinContext->SummFreq < 11 * p->MinContext->NumStats) +
|
||||
4 * (numMasked > nonMasked) +
|
||||
2 * (unsigned)(p->MinContext->SummFreq < 11 * p->MinContext->NumStats) +
|
||||
4 * (unsigned)(numMasked > nonMasked) +
|
||||
p->HiBitsFlag;
|
||||
{
|
||||
unsigned r = (see->Summ >> see->Shift);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* Ppmd7.h -- PPMdH compression codec
|
||||
2010-03-12 : Igor Pavlov : Public domain
|
||||
2016-05-21 : Igor Pavlov : Public domain
|
||||
This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
|
||||
|
||||
/* This code supports virtual RangeDecoder and includes the implementation
|
||||
@@ -86,10 +86,10 @@ void Ppmd7_Update2(CPpmd7 *p);
|
||||
void Ppmd7_UpdateBin(CPpmd7 *p);
|
||||
|
||||
#define Ppmd7_GetBinSumm(p) \
|
||||
&p->BinSumm[Ppmd7Context_OneState(p->MinContext)->Freq - 1][p->PrevSuccess + \
|
||||
&p->BinSumm[(unsigned)Ppmd7Context_OneState(p->MinContext)->Freq - 1][p->PrevSuccess + \
|
||||
p->NS2BSIndx[Ppmd7_GetContext(p, p->MinContext->Suffix)->NumStats - 1] + \
|
||||
(p->HiBitsFlag = p->HB2Flag[p->FoundState->Symbol]) + \
|
||||
2 * p->HB2Flag[Ppmd7Context_OneState(p->MinContext)->Symbol] + \
|
||||
2 * p->HB2Flag[(unsigned)Ppmd7Context_OneState(p->MinContext)->Symbol] + \
|
||||
((p->RunLength >> 26) & 0x20)]
|
||||
|
||||
CPpmd_See *Ppmd7_MakeEscFreq(CPpmd7 *p, unsigned numMasked, UInt32 *scale);
|
||||
|
||||
38
C/Ppmd8.c
38
C/Ppmd8.c
@@ -1,5 +1,5 @@
|
||||
/* Ppmd8.c -- PPMdI codec
|
||||
2015-09-28 : Igor Pavlov : Public domain
|
||||
2016-05-21 : 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);
|
||||
}
|
||||
@@ -1038,9 +1038,9 @@ CPpmd_See *Ppmd8_MakeEscFreq(CPpmd8 *p, unsigned numMasked1, UInt32 *escFreq)
|
||||
CPpmd_See *see;
|
||||
if (p->MinContext->NumStats != 0xFF)
|
||||
{
|
||||
see = p->See[p->NS2Indx[p->MinContext->NumStats + 2] - 3] +
|
||||
see = p->See[(unsigned)p->NS2Indx[(unsigned)p->MinContext->NumStats + 2] - 3] +
|
||||
(p->MinContext->SummFreq > 11 * ((unsigned)p->MinContext->NumStats + 1)) +
|
||||
2 * (2 * (unsigned)p->MinContext->NumStats <
|
||||
2 * (unsigned)(2 * (unsigned)p->MinContext->NumStats <
|
||||
((unsigned)SUFFIX(p->MinContext)->NumStats + numMasked1)) +
|
||||
p->MinContext->Flags;
|
||||
{
|
||||
|
||||
7
C/Sha1.c
7
C/Sha1.c
@@ -1,5 +1,5 @@
|
||||
/* Sha1.c -- SHA-1 Hash
|
||||
2016-02-09 : Igor Pavlov : Public domain
|
||||
2016-05-20 : Igor Pavlov : Public domain
|
||||
This code is based on public domain code of Steve Reid from Wei Dai's Crypto++ library. */
|
||||
|
||||
#include "Precomp.h"
|
||||
@@ -212,7 +212,7 @@ void Sha1_Update(CSha1 *p, const Byte *data, size_t size)
|
||||
}
|
||||
}
|
||||
|
||||
void Sha1_Update_Rar(CSha1 *p, Byte *data, size_t size, int rar350Mode)
|
||||
void Sha1_Update_Rar(CSha1 *p, Byte *data, size_t size /* , int rar350Mode */)
|
||||
{
|
||||
int returnRes = False;
|
||||
|
||||
@@ -246,7 +246,8 @@ void Sha1_Update_Rar(CSha1 *p, Byte *data, size_t size, int rar350Mode)
|
||||
SetUi32(prev, d);
|
||||
}
|
||||
}
|
||||
returnRes = rar350Mode;
|
||||
// returnRes = rar350Mode;
|
||||
returnRes = True;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
4
C/Sha1.h
4
C/Sha1.h
@@ -1,5 +1,5 @@
|
||||
/* Sha1.h -- SHA-1 Hash
|
||||
2015-03-04 : Igor Pavlov : Public domain */
|
||||
2016-05-20 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __7Z_SHA1_H
|
||||
#define __7Z_SHA1_H
|
||||
@@ -27,7 +27,7 @@ void Sha1_GetBlockDigest(CSha1 *p, const UInt32 *data, UInt32 *destDigest);
|
||||
void Sha1_Update(CSha1 *p, const Byte *data, size_t size);
|
||||
void Sha1_Final(CSha1 *p, Byte *digest);
|
||||
|
||||
void Sha1_Update_Rar(CSha1 *p, Byte *data, size_t size, int rar350Mode);
|
||||
void Sha1_Update_Rar(CSha1 *p, Byte *data, size_t size /* , int rar350Mode */);
|
||||
|
||||
void Sha1_32_PrepareBlock(const CSha1 *p, UInt32 *block, unsigned size);
|
||||
void Sha1_32_Update(CSha1 *p, const UInt32 *data, size_t size);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* 7zipInstall.c - 7-Zip Installer
|
||||
2015-12-09 : Igor Pavlov : Public domain */
|
||||
2016-06-08 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "../../7zFile.h"
|
||||
#include "../../7zVersion.h"
|
||||
#include "../../CpuArch.h"
|
||||
#include "../../DllSecur.h"
|
||||
|
||||
#include "resource.h"
|
||||
|
||||
@@ -876,6 +877,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
||||
UNUSED_VAR(nCmdShow)
|
||||
|
||||
#ifndef UNDER_CE
|
||||
LoadSecurityDlls();
|
||||
CoInitialize(NULL);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -191,6 +191,14 @@ SOURCE=..\..\Delta.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\DllSecur.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\DllSecur.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Lzma2Dec.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
@@ -25,6 +25,7 @@ C_OBJS = \
|
||||
$O\7zStream.obj \
|
||||
$O\Bcj2.obj \
|
||||
$O\CpuArch.obj \
|
||||
$O\DllSecur.obj \
|
||||
$O\LzmaDec.obj \
|
||||
|
||||
OBJS = \
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* 7zipUninstall.c - 7-Zip Uninstaller
|
||||
2015-12-26 : 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;
|
||||
@@ -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;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* SfxSetup.c - 7z SFX Setup
|
||||
2015-11-08 : Igor Pavlov : Public domain */
|
||||
2016-05-16 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Precomp.h"
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "../../7zCrc.h"
|
||||
#include "../../7zFile.h"
|
||||
#include "../../CpuArch.h"
|
||||
#include "../../DllSecur.h"
|
||||
|
||||
#define k_EXE_ExtIndex 2
|
||||
|
||||
@@ -254,6 +255,8 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
||||
Bool useShellExecute = True;
|
||||
DWORD exitCode = 0;
|
||||
|
||||
LoadSecurityDlls();
|
||||
|
||||
#ifdef _CONSOLE
|
||||
SetConsoleCtrlHandler(HandlerRoutine, TRUE);
|
||||
#else
|
||||
@@ -396,11 +399,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;
|
||||
|
||||
@@ -187,6 +187,14 @@ SOURCE=..\..\Delta.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\DllSecur.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\DllSecur.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Lzma2Dec.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
@@ -16,6 +16,7 @@ C_OBJS = \
|
||||
$O\BraIA64.obj \
|
||||
$O\CpuArch.obj \
|
||||
$O\Delta.obj \
|
||||
$O\DllSecur.obj \
|
||||
$O\Lzma2Dec.obj \
|
||||
$O\LzmaDec.obj \
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ C_OBJS = \
|
||||
$O\BraIA64.obj \
|
||||
$O\CpuArch.obj \
|
||||
$O\Delta.obj \
|
||||
$O\DllSecur.obj \
|
||||
$O\Lzma2Dec.obj \
|
||||
$O\LzmaDec.obj \
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,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())
|
||||
|
||||
@@ -429,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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1097,7 +1097,10 @@ HRESULT CInArchive::ReadAndDecodePackedStreams(
|
||||
if (CrcCalc(data, unpackSize) != folders.FolderCRCs.Vals[i])
|
||||
ThrowIncorrect();
|
||||
}
|
||||
HeadersSize += folders.PackPositions[folders.NumPackStreams];
|
||||
|
||||
if (folders.PackPositions)
|
||||
HeadersSize += folders.PackPositions[folders.NumPackStreams];
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@@ -1150,9 +1153,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;
|
||||
@@ -1174,8 +1176,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())
|
||||
@@ -1184,9 +1186,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:
|
||||
{
|
||||
@@ -1220,7 +1222,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];
|
||||
@@ -1263,7 +1265,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++;
|
||||
|
||||
@@ -1337,7 +1339,7 @@ HRESULT CInArchive::ReadHeader(
|
||||
if (isKnownType)
|
||||
{
|
||||
if (addPropIdToList)
|
||||
db.ArcInfo.FileInfoPopIDs.Add(type);
|
||||
db.ArcInfo.FileInfoPopIDs.Add(type2);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1358,6 +1360,9 @@ HRESULT CInArchive::ReadHeader(
|
||||
CNum sizeIndex = 0;
|
||||
|
||||
CNum numAntiItems = 0;
|
||||
|
||||
CNum i;
|
||||
|
||||
for (i = 0; i < numEmptyStreams; i++)
|
||||
if (antiFileVector[i])
|
||||
numAntiItems++;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -38,7 +38,7 @@ struct CFilterMode
|
||||
{
|
||||
if (Id == k_IA64)
|
||||
Delta = 16;
|
||||
else if (Id == k_ARM || Id == k_PPC || Id == k_PPC)
|
||||
else if (Id == k_ARM || Id == k_PPC || Id == k_SPARC)
|
||||
Delta = 4;
|
||||
else if (Id == k_ARMT)
|
||||
Delta = 2;
|
||||
@@ -779,7 +779,7 @@ struct CSolidGroup
|
||||
CRecordVector<CFolderRepack> folderRefs;
|
||||
};
|
||||
|
||||
static const char *g_ExeExts[] =
|
||||
static const char * const g_ExeExts[] =
|
||||
{
|
||||
"dll"
|
||||
, "exe"
|
||||
@@ -1681,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1753,7 +1754,7 @@ HRESULT Update(
|
||||
|
||||
const CCompressionMethodMode &method = *options.Method;
|
||||
|
||||
for (i = 0; i < updateItems.Size(); i++)
|
||||
FOR_VECTOR (i, updateItems)
|
||||
{
|
||||
const CUpdateItem &ui = updateItems[i];
|
||||
if (!ui.NewData || !ui.HasStream())
|
||||
@@ -1857,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];
|
||||
@@ -1919,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
|
||||
@@ -1927,7 +1931,8 @@ HRESULT Update(
|
||||
#endif
|
||||
);
|
||||
|
||||
RINOK(res);
|
||||
RINOK(res);
|
||||
}
|
||||
|
||||
if (filterMode.Encrypted)
|
||||
{
|
||||
@@ -2266,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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
|
||||
|
||||
case kpidVolumeIndex:
|
||||
{
|
||||
if (m_Database.Volumes.Size() == 1)
|
||||
if (!m_Database.Volumes.IsEmpty())
|
||||
{
|
||||
const CDatabaseEx &db = m_Database.Volumes[0];
|
||||
const CInArcInfo &ai = db.ArcInfo;
|
||||
@@ -1017,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;
|
||||
@@ -1029,7 +1029,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
extractStatuses.Add(false);
|
||||
extractStatuses.Add(true);
|
||||
startIndex++;
|
||||
curUnpack = item.GetEndOffset();
|
||||
curUnpack = item2.GetEndOffset();
|
||||
}
|
||||
|
||||
CFolderOutStream *cabFolderOutStream = new CFolderOutStream;
|
||||
@@ -1104,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.
|
||||
@@ -1138,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);
|
||||
@@ -1180,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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -156,7 +156,7 @@ bool CHeader::Parse(const Byte *p)
|
||||
|
||||
#define PT_PHDR 6
|
||||
|
||||
static const char *g_SegnmentTypes[] =
|
||||
static const char * const g_SegnmentTypes[] =
|
||||
{
|
||||
"Unused",
|
||||
"Loadable segment",
|
||||
@@ -554,13 +554,31 @@ static const CUInt32PCharPair g_OS[] =
|
||||
{ 255, "Standalone" }
|
||||
};
|
||||
|
||||
#define k_Machine_ARM 40
|
||||
|
||||
/*
|
||||
#define EF_ARM_ABIMASK 0xFF000000
|
||||
#define EF_ARM_BE8 0x00800000
|
||||
#define EF_ARM_GCCMASK 0x00400FFF
|
||||
#define EF_ARM_ABI_FLOAT_SOFT 0x00000200
|
||||
#define EF_ARM_ABI_FLOAT_HARD 0x00000400
|
||||
*/
|
||||
|
||||
static const CUInt32PCharPair g_ARM_Flags[] =
|
||||
{
|
||||
{ 9, "SF" },
|
||||
{ 10, "HF" },
|
||||
{ 23, "BE8" }
|
||||
};
|
||||
|
||||
|
||||
#define ET_NONE 0
|
||||
#define ET_REL 1
|
||||
#define ET_EXEC 2
|
||||
#define ET_DYN 3
|
||||
#define ET_CORE 4
|
||||
|
||||
static const char *g_Types[] =
|
||||
static const char * const g_Types[] =
|
||||
{
|
||||
"None",
|
||||
"Relocatable file",
|
||||
@@ -569,6 +587,9 @@ static const char *g_Types[] =
|
||||
"Core file"
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class CHandler:
|
||||
public IInArchive,
|
||||
public IArchiveAllowTail,
|
||||
@@ -659,7 +680,29 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
|
||||
case kpidBit64: if (_header.Mode64) prop = _header.Mode64; break;
|
||||
case kpidBigEndian: if (_header.Be) prop = _header.Be; break;
|
||||
case kpidShortComment:
|
||||
case kpidCpu: PAIR_TO_PROP(g_Machines, _header.Machine, prop); break;
|
||||
|
||||
case kpidCpu:
|
||||
{
|
||||
AString s = TypePairToString(g_Machines, ARRAY_SIZE(g_Machines), _header.Machine);
|
||||
UInt32 flags = _header.Flags;
|
||||
if (flags != 0)
|
||||
{
|
||||
char sz[16];
|
||||
s.Add_Space();
|
||||
if (_header.Machine == k_Machine_ARM)
|
||||
{
|
||||
s += FlagsToString(g_ARM_Flags, ARRAY_SIZE(g_ARM_Flags), flags & (((UInt32)1 << 24) - 1));
|
||||
s += " ABI:";
|
||||
ConvertUInt32ToString(flags >> 24, sz);
|
||||
}
|
||||
else
|
||||
ConvertUInt32ToHex(flags, sz);
|
||||
s += sz;
|
||||
}
|
||||
prop = s;
|
||||
break;
|
||||
}
|
||||
|
||||
case kpidHostOS: PAIR_TO_PROP(g_OS, _header.Os, prop); break;
|
||||
case kpidCharacts: TYPE_TO_PROP(g_Types, _header.Type, prop); break;
|
||||
case kpidExtension:
|
||||
|
||||
@@ -2810,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)
|
||||
|
||||
@@ -93,7 +93,7 @@ static const Byte kProps[] =
|
||||
IMP_IInArchive_Props
|
||||
IMP_IInArchive_ArcProps_NO_Table
|
||||
|
||||
static const char *g_AudioTypes[16] =
|
||||
static const char * const g_AudioTypes[16] =
|
||||
{
|
||||
"pcm"
|
||||
, "adpcm"
|
||||
@@ -113,7 +113,7 @@ static const char *g_AudioTypes[16] =
|
||||
, "audio15"
|
||||
};
|
||||
|
||||
static const char *g_VideoTypes[16] =
|
||||
static const char * const g_VideoTypes[16] =
|
||||
{
|
||||
"video0"
|
||||
, "jpeg"
|
||||
@@ -133,7 +133,7 @@ static const char *g_VideoTypes[16] =
|
||||
, "video15"
|
||||
};
|
||||
|
||||
static const char *g_Rates[4] =
|
||||
static const char * const g_Rates[4] =
|
||||
{
|
||||
"5.5 kHz"
|
||||
, "11 kHz"
|
||||
|
||||
@@ -244,9 +244,31 @@ HRESULT CHandler::Open2(IInStream *stream)
|
||||
_items.Add(item);
|
||||
}
|
||||
|
||||
UInt64 end = (backupLba + 1) * kSectorSize;
|
||||
if (_totalSize < end)
|
||||
_totalSize = end;
|
||||
{
|
||||
const UInt64 end = (backupLba + 1) * kSectorSize;
|
||||
if (_totalSize < end)
|
||||
_totalSize = end;
|
||||
}
|
||||
|
||||
{
|
||||
UInt64 fileEnd;
|
||||
RINOK(stream->Seek(0, STREAM_SEEK_END, &fileEnd));
|
||||
|
||||
if (_totalSize < fileEnd)
|
||||
{
|
||||
const UInt64 rem = fileEnd - _totalSize;
|
||||
const UInt64 kRemMax = 1 << 22;
|
||||
if (rem <= kRemMax)
|
||||
{
|
||||
RINOK(stream->Seek(_totalSize, STREAM_SEEK_SET, NULL));
|
||||
bool areThereNonZeros = false;
|
||||
UInt64 numZeros = 0;
|
||||
if (ReadZeroTail(stream, areThereNonZeros, numZeros, kRemMax) == S_OK)
|
||||
if (!areThereNonZeros)
|
||||
_totalSize += numZeros;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@@ -507,7 +507,7 @@ HRESULT CHeaderRec::Parse(const Byte *p)
|
||||
// LeafRecords = Get32(p + 6);
|
||||
FirstLeafNode = Get32(p + 0xA);
|
||||
// LastLeafNode = Get32(p + 0xE);
|
||||
UInt32 nodeSize = Get16(p + 0x12);
|
||||
const UInt32 nodeSize = Get16(p + 0x12);
|
||||
|
||||
unsigned i;
|
||||
for (i = 9; ((UInt32)1 << i) != nodeSize; i++)
|
||||
@@ -583,9 +583,9 @@ HRESULT CDatabase::LoadExtentFile(const CFork &fork, IInStream *inStream, CObjec
|
||||
|
||||
for (unsigned i = 0; i < desc.NumRecords; i++)
|
||||
{
|
||||
UInt32 nodeSize = (UInt32)1 << hr.NodeSizeLog;
|
||||
UInt32 offs = Get16(p + nodeOffset + nodeSize - (i + 1) * 2);
|
||||
UInt32 offsNext = Get16(p + nodeOffset + nodeSize - (i + 2) * 2);
|
||||
const UInt32 nodeSize = (UInt32)1 << hr.NodeSizeLog;
|
||||
const UInt32 offs = Get16(p + nodeOffset + nodeSize - (i + 1) * 2);
|
||||
const UInt32 offsNext = Get16(p + nodeOffset + nodeSize - (i + 2) * 2);
|
||||
if (offs > nodeSize || offsNext > nodeSize)
|
||||
return S_FALSE;
|
||||
UInt32 recSize = offsNext - offs;
|
||||
@@ -727,12 +727,12 @@ HRESULT CDatabase::LoadAttrs(const CFork &fork, IInStream *inStream, IArchiveOpe
|
||||
|
||||
for (unsigned i = 0; i < desc.NumRecords; i++)
|
||||
{
|
||||
UInt32 nodeSize = (1 << hr.NodeSizeLog);
|
||||
UInt32 offs = Get16(p + nodeOffset + nodeSize - (i + 1) * 2);
|
||||
UInt32 offsNext = Get16(p + nodeOffset + nodeSize - (i + 2) * 2);
|
||||
const UInt32 nodeSize = (1 << hr.NodeSizeLog);
|
||||
const UInt32 offs = Get16(p + nodeOffset + nodeSize - (i + 1) * 2);
|
||||
const UInt32 offsNext = Get16(p + nodeOffset + nodeSize - (i + 2) * 2);
|
||||
UInt32 recSize = offsNext - offs;
|
||||
if (offs >= nodeSize
|
||||
|| offsNext >= nodeSize
|
||||
|| offsNext > nodeSize
|
||||
|| offsNext < offs)
|
||||
return S_FALSE;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -898,7 +898,7 @@ HRESULT CDatabase::LoadCatalog(const CFork &fork, const CObjectVector<CIdExtents
|
||||
return S_FALSE;
|
||||
usedBuf[node] = 1;
|
||||
|
||||
size_t nodeOffset = (size_t)node << hr.NodeSizeLog;
|
||||
const size_t nodeOffset = (size_t)node << hr.NodeSizeLog;
|
||||
CNodeDescriptor desc;
|
||||
desc.Parse(p + nodeOffset);
|
||||
if (!desc.CheckNumRecords(hr.NodeSizeLog))
|
||||
@@ -908,12 +908,12 @@ HRESULT CDatabase::LoadCatalog(const CFork &fork, const CObjectVector<CIdExtents
|
||||
|
||||
for (unsigned i = 0; i < desc.NumRecords; i++)
|
||||
{
|
||||
UInt32 nodeSize = (1 << hr.NodeSizeLog);
|
||||
UInt32 offs = Get16(p + nodeOffset + nodeSize - (i + 1) * 2);
|
||||
UInt32 offsNext = Get16(p + nodeOffset + nodeSize - (i + 2) * 2);
|
||||
const UInt32 nodeSize = (1 << hr.NodeSizeLog);
|
||||
const UInt32 offs = Get16(p + nodeOffset + nodeSize - (i + 1) * 2);
|
||||
const UInt32 offsNext = Get16(p + nodeOffset + nodeSize - (i + 2) * 2);
|
||||
UInt32 recSize = offsNext - offs;
|
||||
if (offs >= nodeSize
|
||||
|| offs >= nodeSize
|
||||
|| offsNext > nodeSize
|
||||
|| offsNext < offs
|
||||
|| recSize < 6)
|
||||
return S_FALSE;
|
||||
@@ -1764,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;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,14 @@ static const Byte kProps[] =
|
||||
kpidIsDir,
|
||||
kpidSize,
|
||||
kpidPackSize,
|
||||
kpidMTime
|
||||
kpidMTime,
|
||||
// kpidCTime,
|
||||
// kpidATime,
|
||||
kpidPosixAttrib,
|
||||
// kpidUser,
|
||||
// kpidGroup,
|
||||
// kpidLinks,
|
||||
kpidSymLink
|
||||
};
|
||||
|
||||
static const Byte kArcProps[] =
|
||||
@@ -213,17 +220,87 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
prop = s;
|
||||
}
|
||||
break;
|
||||
|
||||
case kpidSymLink:
|
||||
if (_archive.IsSusp)
|
||||
{
|
||||
UString s;
|
||||
UInt32 mode;
|
||||
if (item.GetPx(_archive.SuspSkipSize, k_Px_Mode, mode))
|
||||
{
|
||||
if (((mode >> 12) & 0xF) == 10)
|
||||
{
|
||||
AString s8;
|
||||
if (item.GetSymLink(_archive.SuspSkipSize, s8))
|
||||
{
|
||||
s = MultiByteToUnicodeString(s8, CP_OEMCP);
|
||||
prop = s;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case kpidPosixAttrib:
|
||||
/*
|
||||
case kpidLinks:
|
||||
case kpidUser:
|
||||
case kpidGroup:
|
||||
*/
|
||||
{
|
||||
if (_archive.IsSusp)
|
||||
{
|
||||
UInt32 t = 0;
|
||||
switch (propID)
|
||||
{
|
||||
case kpidPosixAttrib: t = k_Px_Mode; break;
|
||||
/*
|
||||
case kpidLinks: t = k_Px_Links; break;
|
||||
case kpidUser: t = k_Px_User; break;
|
||||
case kpidGroup: t = k_Px_Group; break;
|
||||
*/
|
||||
}
|
||||
UInt32 v;
|
||||
if (item.GetPx(_archive.SuspSkipSize, t, v))
|
||||
prop = v;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case kpidIsDir: prop = item.IsDir(); break;
|
||||
case kpidSize:
|
||||
case kpidPackSize:
|
||||
if (!item.IsDir())
|
||||
prop = (UInt64)ref.TotalSize;
|
||||
break;
|
||||
|
||||
case kpidMTime:
|
||||
// case kpidCTime:
|
||||
// case kpidATime:
|
||||
{
|
||||
FILETIME utc;
|
||||
if (item.DateTime.GetFileTime(utc))
|
||||
if (/* propID == kpidMTime && */ item.DateTime.GetFileTime(utc))
|
||||
prop = utc;
|
||||
/*
|
||||
else
|
||||
{
|
||||
UInt32 t = 0;
|
||||
switch (propID)
|
||||
{
|
||||
case kpidMTime: t = k_Tf_MTime; break;
|
||||
case kpidCTime: t = k_Tf_CTime; break;
|
||||
case kpidATime: t = k_Tf_ATime; break;
|
||||
}
|
||||
CRecordingDateTime dt;
|
||||
if (item.GetTf(_archive.SuspSkipSize, t, dt))
|
||||
{
|
||||
FILETIME utc;
|
||||
if (dt.GetFileTime(utc))
|
||||
prop = utc;
|
||||
}
|
||||
}
|
||||
*/
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -321,8 +398,10 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
UInt64 offset = 0;
|
||||
for (UInt32 e = 0; e < ref.NumExtents; e++)
|
||||
{
|
||||
lps->InSize = lps->OutSize = currentTotalSize + offset;
|
||||
const CDir &item2 = ref.Dir->_subItems[ref.Index + e];
|
||||
if (item2.Size == 0)
|
||||
continue;
|
||||
lps->InSize = lps->OutSize = currentTotalSize + offset;
|
||||
RINOK(_stream->Seek((UInt64)item2.ExtentLocation * kBlockSize, STREAM_SEEK_SET, NULL));
|
||||
streamSpec->Init(item2.Size);
|
||||
RINOK(copyCoder->Code(inStream, realOutStream, NULL, NULL, progress));
|
||||
@@ -358,7 +437,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 +454,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 +473,7 @@ STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
|
||||
*stream = extentStream.Detach();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
currentItemSize = item.Size;
|
||||
blockIndex = item.ExtentLocation;
|
||||
}
|
||||
|
||||
@@ -608,7 +608,7 @@ HRESULT CInArchive::Open2()
|
||||
for (UInt32 j = 0; j < ref.NumExtents; j++)
|
||||
{
|
||||
const CDir &item = ref.Dir->_subItems[ref.Index + j];
|
||||
if (!item.IsDir())
|
||||
if (!item.IsDir() && item.Size != 0)
|
||||
UpdatePhySize(item.ExtentLocation, item.Size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#ifndef __ARCHIVE_ISO_ITEM_H
|
||||
#define __ARCHIVE_ISO_ITEM_H
|
||||
|
||||
#include "../../../../C/CpuArch.h"
|
||||
|
||||
#include "../../../Common/MyString.h"
|
||||
#include "../../../Common/MyBuffer.h"
|
||||
|
||||
@@ -38,6 +40,32 @@ struct CRecordingDateTime
|
||||
}
|
||||
};
|
||||
|
||||
enum EPx
|
||||
{
|
||||
k_Px_Mode,
|
||||
k_Px_Links,
|
||||
k_Px_User,
|
||||
k_Px_Group,
|
||||
k_Px_SerialNumber
|
||||
|
||||
// k_Px_Num
|
||||
};
|
||||
|
||||
/*
|
||||
enum ETf
|
||||
{
|
||||
k_Tf_CTime,
|
||||
k_Tf_MTime,
|
||||
k_Tf_ATime,
|
||||
k_Tf_Attrib,
|
||||
k_Tf_Backup,
|
||||
k_Tf_Expiration,
|
||||
k_Tf_Effective
|
||||
|
||||
// k_Tf_Num
|
||||
};
|
||||
*/
|
||||
|
||||
struct CDirRecord
|
||||
{
|
||||
UInt32 ExtentLocation;
|
||||
@@ -69,7 +97,8 @@ struct CDirRecord
|
||||
return (b == 0 || b == 1);
|
||||
}
|
||||
|
||||
const Byte* FindSuspName(unsigned skipSize, unsigned &lenRes) const
|
||||
|
||||
const Byte* FindSuspRecord(unsigned skipSize, Byte id0, Byte id1, unsigned &lenRes) const
|
||||
{
|
||||
lenRes = 0;
|
||||
if (SystemUse.Size() < skipSize)
|
||||
@@ -81,12 +110,12 @@ struct CDirRecord
|
||||
unsigned len = p[2];
|
||||
if (len < 3 || len > rem)
|
||||
return 0;
|
||||
if (p[0] == 'N' && p[1] == 'M' && p[3] == 1)
|
||||
if (p[0] == id0 && p[1] == id1 && p[3] == 1)
|
||||
{
|
||||
if (len < 5)
|
||||
if (len < 4)
|
||||
return 0; // Check it
|
||||
lenRes = len - 5;
|
||||
return p + 5;
|
||||
lenRes = len - 4;
|
||||
return p + 4;
|
||||
}
|
||||
p += len;
|
||||
rem -= len;
|
||||
@@ -94,17 +123,23 @@ struct CDirRecord
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
const Byte* GetNameCur(bool checkSusp, int skipSize, unsigned &nameLenRes) const
|
||||
{
|
||||
const Byte *res = NULL;
|
||||
unsigned len = 0;
|
||||
if (checkSusp)
|
||||
res = FindSuspName(skipSize, len);
|
||||
if (!res)
|
||||
res = FindSuspRecord(skipSize, 'N', 'M', len);
|
||||
if (!res || len < 1)
|
||||
{
|
||||
res = (const Byte *)FileId;
|
||||
len = (unsigned)FileId.Size();
|
||||
}
|
||||
else
|
||||
{
|
||||
res++;
|
||||
len--;
|
||||
}
|
||||
unsigned i;
|
||||
for (i = 0; i < len; i++)
|
||||
if (res[i] == 0)
|
||||
@@ -114,6 +149,141 @@ struct CDirRecord
|
||||
}
|
||||
|
||||
|
||||
const bool GetSymLink(int skipSize, AString &link) const
|
||||
{
|
||||
link.Empty();
|
||||
const Byte *p = NULL;
|
||||
unsigned len = 0;
|
||||
p = FindSuspRecord(skipSize, 'S', 'L', len);
|
||||
if (!p || len < 1)
|
||||
return false;
|
||||
|
||||
if (*p != 0)
|
||||
return false;
|
||||
|
||||
p++;
|
||||
len--;
|
||||
|
||||
while (len != 0)
|
||||
{
|
||||
if (len < 2)
|
||||
return false;
|
||||
unsigned flags = p[0];
|
||||
unsigned cl = p[1];
|
||||
p += 2;
|
||||
len -= 2;
|
||||
|
||||
if (cl > len)
|
||||
return false;
|
||||
|
||||
bool needSlash = false;
|
||||
|
||||
if (flags & (1 << 1)) link += "./";
|
||||
else if (flags & (1 << 2)) link += "../";
|
||||
else if (flags & (1 << 3)) link += '/';
|
||||
else
|
||||
needSlash = true;
|
||||
|
||||
for (unsigned i = 0; i < cl; i++)
|
||||
{
|
||||
char c = p[i];
|
||||
if (c == 0)
|
||||
{
|
||||
break;
|
||||
// return false;
|
||||
}
|
||||
link += c;
|
||||
}
|
||||
|
||||
p += cl;
|
||||
len -= cl;
|
||||
|
||||
if (len == 0)
|
||||
break;
|
||||
|
||||
if (needSlash)
|
||||
link += '/';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static const bool GetLe32Be32(const Byte *p, UInt32 &dest)
|
||||
{
|
||||
UInt32 v1 = GetUi32(p);
|
||||
UInt32 v2 = GetBe32(p + 4);
|
||||
if (v1 == v2)
|
||||
{
|
||||
dest = v1;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
const bool GetPx(int skipSize, unsigned pxType, UInt32 &val) const
|
||||
{
|
||||
const Byte *p = NULL;
|
||||
unsigned len = 0;
|
||||
p = FindSuspRecord(skipSize, 'P', 'X', len);
|
||||
if (!p)
|
||||
return false;
|
||||
// px.Clear();
|
||||
if (len < ((unsigned)pxType + 1) * 8)
|
||||
return false;
|
||||
|
||||
return GetLe32Be32(p + pxType * 8, val);
|
||||
}
|
||||
|
||||
/*
|
||||
const bool GetTf(int skipSize, unsigned pxType, CRecordingDateTime &t) const
|
||||
{
|
||||
const Byte *p = NULL;
|
||||
unsigned len = 0;
|
||||
p = FindSuspRecord(skipSize, 'T', 'F', len);
|
||||
if (!p)
|
||||
return false;
|
||||
if (len < 1)
|
||||
return false;
|
||||
Byte flags = *p++;
|
||||
len--;
|
||||
|
||||
unsigned step = 7;
|
||||
if (flags & 0x80)
|
||||
{
|
||||
step = 17;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((flags & (1 << pxType)) == 0)
|
||||
return false;
|
||||
|
||||
for (unsigned i = 0; i < pxType; i++)
|
||||
{
|
||||
if (len < step)
|
||||
return false;
|
||||
if (flags & (1 << i))
|
||||
{
|
||||
p += step;
|
||||
len -= step;
|
||||
}
|
||||
}
|
||||
|
||||
if (len < step)
|
||||
return false;
|
||||
|
||||
t.Year = p[0];
|
||||
t.Month = p[1];
|
||||
t.Day = p[2];
|
||||
t.Hour = p[3];
|
||||
t.Minute = p[4];
|
||||
t.Second = p[5];
|
||||
t.GmtOffset = (signed char)p[6];
|
||||
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
bool CheckSusp(const Byte *p, unsigned &startPos) const
|
||||
{
|
||||
if (p[0] == 'S' &&
|
||||
|
||||
@@ -75,7 +75,7 @@ static const CUInt32PCharPair g_CpuPairs[] =
|
||||
|
||||
#define SECT_ATTR_ZEROFILL 1
|
||||
|
||||
static const char *g_SectTypes[] =
|
||||
static const char * const g_SectTypes[] =
|
||||
{
|
||||
"REGULAR"
|
||||
, "ZEROFILL"
|
||||
@@ -108,7 +108,7 @@ enum EFileType
|
||||
kType_DSYM
|
||||
};
|
||||
|
||||
static const char *g_FileTypes[] =
|
||||
static const char * const g_FileTypes[] =
|
||||
{
|
||||
"0"
|
||||
, "OBJECT"
|
||||
@@ -124,7 +124,7 @@ static const char *g_FileTypes[] =
|
||||
};
|
||||
|
||||
|
||||
static const char *g_ArcFlags[] =
|
||||
static const char * const g_ArcFlags[] =
|
||||
{
|
||||
"NOUNDEFS"
|
||||
, "INCRLINK"
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
#include "../../Compress/BcjCoder.h"
|
||||
#include "../../Compress/BZip2Decoder.h"
|
||||
#include "../../Compress/DeflateDecoder.h"
|
||||
|
||||
#define Get32(p) GetUi32(p)
|
||||
|
||||
@@ -27,12 +26,16 @@ HRESULT CDecoder::Init(ISequentialInStream *inStream, bool &useFilter)
|
||||
if (Method != _curMethod)
|
||||
Release();
|
||||
_curMethod = Method;
|
||||
|
||||
if (!_codecInStream)
|
||||
{
|
||||
switch (Method)
|
||||
{
|
||||
// case NMethodType::kCopy: return E_NOTIMPL;
|
||||
case NMethodType::kDeflate: _codecInStream = new NCompress::NDeflate::NDecoder::CNsisCOMCoder(); break;
|
||||
case NMethodType::kDeflate:
|
||||
_deflateDecoder = new NCompress::NDeflate::NDecoder::CCOMCoder();
|
||||
_codecInStream = _deflateDecoder;
|
||||
break;
|
||||
case NMethodType::kBZip2: _codecInStream = new NCompress::NBZip2::CNsisDecoder(); break;
|
||||
case NMethodType::kLZMA:
|
||||
_lzmaDecoder = new NCompress::NLzma::CDecoder();
|
||||
@@ -42,6 +45,9 @@ HRESULT CDecoder::Init(ISequentialInStream *inStream, bool &useFilter)
|
||||
}
|
||||
}
|
||||
|
||||
if (Method == NMethodType::kDeflate)
|
||||
_deflateDecoder->SetNsisMode(IsNsisDeflate);
|
||||
|
||||
if (FilterFlag)
|
||||
{
|
||||
Byte flag;
|
||||
@@ -199,9 +205,8 @@ HRESULT CDecoder::Decode(CByteBuffer *outBuf, bool unpackSizeDefined, UInt32 unp
|
||||
|
||||
if (outBuf)
|
||||
{
|
||||
if (!unpackSizeDefined)
|
||||
return S_FALSE;
|
||||
outBuf->Alloc(unpackSize);
|
||||
if (unpackSizeDefined)
|
||||
outBuf->Alloc(unpackSize);
|
||||
}
|
||||
|
||||
UInt64 inSizeStart = 0;
|
||||
@@ -213,6 +218,8 @@ HRESULT CDecoder::Decode(CByteBuffer *outBuf, bool unpackSizeDefined, UInt32 unp
|
||||
unpackSize = 0xFFFFFFFF;
|
||||
UInt32 offset = 0;
|
||||
|
||||
HRESULT res = S_OK;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
size_t rem = unpackSize - offset;
|
||||
@@ -225,11 +232,25 @@ HRESULT CDecoder::Decode(CByteBuffer *outBuf, bool unpackSizeDefined, UInt32 unp
|
||||
if (size == 0)
|
||||
{
|
||||
if (unpackSizeDefined)
|
||||
return S_FALSE;
|
||||
res = S_FALSE;
|
||||
break;
|
||||
}
|
||||
|
||||
if (outBuf)
|
||||
{
|
||||
size_t nextSize = offset + size;
|
||||
if (outBuf->Size() < nextSize)
|
||||
{
|
||||
{
|
||||
const size_t nextSize2 = outBuf->Size() * 2;
|
||||
if (nextSize < nextSize2)
|
||||
nextSize = nextSize2;
|
||||
}
|
||||
outBuf->ChangeSize_KeepData(nextSize, offset);
|
||||
}
|
||||
memcpy((Byte *)*outBuf + (size_t)offset, Buffer, size);
|
||||
}
|
||||
|
||||
StreamPos += size;
|
||||
offset += (UInt32)size;
|
||||
|
||||
@@ -243,9 +264,17 @@ HRESULT CDecoder::Decode(CByteBuffer *outBuf, bool unpackSizeDefined, UInt32 unp
|
||||
UInt64 outSize = offset;
|
||||
RINOK(progress->SetRatioInfo(&inSize, &outSize));
|
||||
if (realOutStream)
|
||||
RINOK(WriteStream(realOutStream, Buffer, size));
|
||||
{
|
||||
res = WriteStream(realOutStream, Buffer, size);
|
||||
if (res != S_OK)
|
||||
break;
|
||||
}
|
||||
}
|
||||
return S_OK;
|
||||
|
||||
if (outBuf && offset != outBuf->Size())
|
||||
outBuf->ChangeSize_KeepData(offset, offset);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "../../Common/FilterCoder.h"
|
||||
#include "../../Common/StreamUtils.h"
|
||||
|
||||
#include "../../Compress/DeflateDecoder.h"
|
||||
#include "../../Compress/LzmaDecoder.h"
|
||||
|
||||
namespace NArchive {
|
||||
@@ -37,6 +38,7 @@ class CDecoder
|
||||
CMyComPtr<ISequentialInStream> _codecInStream;
|
||||
CMyComPtr<ISequentialInStream> _decoderInStream;
|
||||
|
||||
NCompress::NDeflate::NDecoder::CCOMCoder *_deflateDecoder;
|
||||
NCompress::NLzma::CDecoder *_lzmaDecoder;
|
||||
|
||||
public:
|
||||
@@ -46,9 +48,16 @@ public:
|
||||
NMethodType::EEnum Method;
|
||||
bool FilterFlag;
|
||||
bool Solid;
|
||||
bool IsNsisDeflate;
|
||||
|
||||
CByteBuffer Buffer; // temp buf.
|
||||
|
||||
CDecoder():
|
||||
FilterFlag(false),
|
||||
Solid(true),
|
||||
IsNsisDeflate(true)
|
||||
{}
|
||||
|
||||
void Release()
|
||||
{
|
||||
_filterInStream.Release();
|
||||
|
||||
@@ -175,7 +175,7 @@ static const CCommandInfo k_Commands[kNumCmds] =
|
||||
{ 0 }, // "BringToFront" },
|
||||
{ 2 }, // "SetDetailsView" },
|
||||
{ 2 }, // "SetFileAttributes" },
|
||||
{ 2 }, // CreateDirectory, SetOutPath
|
||||
{ 3 }, // CreateDirectory, SetOutPath
|
||||
{ 3 }, // "IfFileExists" },
|
||||
{ 3 }, // SetRebootFlag, ...
|
||||
{ 4 }, // "If" }, // IfAbort, IfSilent, IfErrors, IfRebootFlag
|
||||
@@ -1395,7 +1395,7 @@ void CInArchive::AddRegRoot(UInt32 val)
|
||||
Script += s;
|
||||
}
|
||||
|
||||
static const char *g_WinAttrib[] =
|
||||
static const char * const g_WinAttrib[] =
|
||||
{
|
||||
"READONLY"
|
||||
, "HIDDEN"
|
||||
@@ -3362,6 +3362,11 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
|
||||
#ifdef NSIS_SCRIPT
|
||||
s += isSetOutPath ? "SetOutPath" : "CreateDirectory";
|
||||
AddParam(params[0]);
|
||||
if (params[2] != 0)
|
||||
{
|
||||
SmallSpaceComment();
|
||||
s += "CreateRestrictedDirectory";
|
||||
}
|
||||
#endif
|
||||
|
||||
break;
|
||||
@@ -3378,11 +3383,8 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
|
||||
params[2] == 0 &&
|
||||
params[3] == 0)
|
||||
{
|
||||
if (IsVarStr(params[1], kVar_OUTDIR))
|
||||
{
|
||||
spec_outdir_U = UPrefixes.Back(); // outdir_U;
|
||||
spec_outdir_A = APrefixes.Back();// outdir_A;
|
||||
}
|
||||
spec_outdir_U = UPrefixes.Back(); // outdir_U;
|
||||
spec_outdir_A = APrefixes.Back(); // outdir_A;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5045,6 +5047,9 @@ HRESULT CInArchive::Parse()
|
||||
|
||||
DetectNsisType(bhEntries, _data + bhEntries.Offset);
|
||||
|
||||
Decoder.IsNsisDeflate = (NsisType != k_NsisType_Nsis3);
|
||||
|
||||
|
||||
#ifdef NSIS_SCRIPT
|
||||
|
||||
{
|
||||
@@ -5606,6 +5611,9 @@ HRESULT CInArchive::Open2(const Byte *sig, size_t size)
|
||||
Decoder.Method = Method;
|
||||
Decoder.FilterFlag = FilterFlag;
|
||||
Decoder.Solid = IsSolid;
|
||||
|
||||
Decoder.IsNsisDeflate = true; // we need some smart check that NSIS is not NSIS3 here.
|
||||
|
||||
Decoder.InputStream = _stream;
|
||||
Decoder.Buffer.Alloc(kInputBufSize);
|
||||
Decoder.StreamPos = 0;
|
||||
|
||||
@@ -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;
|
||||
@@ -1691,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));
|
||||
@@ -2139,7 +2157,7 @@ STDMETHODIMP CHandler::GetRawProp(UInt32 index, PROPID propID, const void **data
|
||||
return S_OK;
|
||||
const CItem &item = Items[index];
|
||||
const CMftRec &rec = Recs[item.RecIndex];
|
||||
if (rec.SiAttr.SecurityId >= 0)
|
||||
if (rec.SiAttr.SecurityId > 0)
|
||||
{
|
||||
UInt64 offset;
|
||||
UInt32 size;
|
||||
@@ -2151,6 +2169,7 @@ STDMETHODIMP CHandler::GetRawProp(UInt32 index, PROPID propID, const void **data
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@@ -2668,7 +2687,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;
|
||||
@@ -321,7 +321,7 @@ bool COptHeader::Parse(const Byte *p, UInt32 size)
|
||||
if (NumDirItems > (1 << 16))
|
||||
return false;
|
||||
pos += 4;
|
||||
if (pos + 8 * NumDirItems != size)
|
||||
if (pos + 8 * NumDirItems > size)
|
||||
return false;
|
||||
for (UInt32 i = 0; i < NumDirItems && i < kNumDirItemsMax; i++)
|
||||
DirItems[i].Parse(p + pos + i * 8);
|
||||
@@ -1154,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;
|
||||
|
||||
@@ -1898,25 +1898,61 @@ static bool ParseVersion(const Byte *p, UInt32 size, CTextFile &f, CObjectVector
|
||||
HRESULT CHandler::OpenResources(unsigned sectionIndex, IInStream *stream, IArchiveOpenCallback *callback)
|
||||
{
|
||||
const CSection § = _sections[sectionIndex];
|
||||
const size_t fileSize = sect.GetSizeMin();
|
||||
|
||||
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);
|
||||
@@ -2037,19 +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);
|
||||
|
||||
// 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 (/* end < sect.VSize && */ end <= sect.PSize)
|
||||
if (maxOffset < sect.PSize)
|
||||
{
|
||||
CSection sect2;
|
||||
sect2.Flags = 0;
|
||||
size_t end = fileSize;
|
||||
|
||||
// we skip Zeros to start of aligned block
|
||||
size_t i;
|
||||
@@ -2059,6 +2089,8 @@ 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;
|
||||
|
||||
@@ -2211,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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2248,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();
|
||||
|
||||
@@ -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);
|
||||
@@ -231,6 +231,18 @@ bool CItem::Is_CopyLink() const
|
||||
return FindExtra_Link(link) && link.Type == NLinkType::kFileCopy;
|
||||
}
|
||||
|
||||
bool CItem::Is_HardLink() const
|
||||
{
|
||||
CLinkInfo link;
|
||||
return FindExtra_Link(link) && link.Type == NLinkType::kHardLink;
|
||||
}
|
||||
|
||||
bool CItem::Is_CopyLink_or_HardLink() const
|
||||
{
|
||||
CLinkInfo link;
|
||||
return FindExtra_Link(link) && (link.Type == NLinkType::kFileCopy || link.Type == NLinkType::kHardLink);
|
||||
}
|
||||
|
||||
void CItem::Link_to_Prop(unsigned linkType, NWindows::NCOM::CPropVariant &prop) const
|
||||
{
|
||||
CLinkInfo link;
|
||||
@@ -1881,6 +1893,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;
|
||||
@@ -1897,6 +1910,7 @@ HRESULT CHandler::Open2(IInStream *stream,
|
||||
return res;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
CArc &arc = _arcs.AddNew();
|
||||
CInArcInfo &arcInfo = arc.Info;
|
||||
@@ -2068,12 +2082,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;
|
||||
}
|
||||
}
|
||||
@@ -2585,7 +2599,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
{
|
||||
if (testMode)
|
||||
{
|
||||
if (item->Is_CopyLink() && item->PackSize == 0)
|
||||
if (item->NeedUse_as_CopyLink_or_HardLink())
|
||||
{
|
||||
RINOK(extractCallback->PrepareOperation(askMode));
|
||||
RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
|
||||
@@ -2597,6 +2611,9 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
if (item->IsService())
|
||||
continue;
|
||||
|
||||
if (item->NeedUse_as_HardLink())
|
||||
continue;
|
||||
|
||||
bool needDecode = false;
|
||||
|
||||
for (unsigned n = i + 1; n < _refs.Size(); n++)
|
||||
@@ -2637,7 +2654,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
continue;
|
||||
}
|
||||
|
||||
if (item->Is_CopyLink() && item->PackSize == 0)
|
||||
if (item->NeedUse_as_CopyLink())
|
||||
{
|
||||
RINOK(extractCallback->SetOperationResult(
|
||||
realOutStream ?
|
||||
|
||||
@@ -262,8 +262,12 @@ struct CItem
|
||||
bool FindExtra_Link(CLinkInfo &link) const;
|
||||
void Link_to_Prop(unsigned linkType, NWindows::NCOM::CPropVariant &prop) const;
|
||||
bool Is_CopyLink() const;
|
||||
bool Is_HardLink() const;
|
||||
bool Is_CopyLink_or_HardLink() const;
|
||||
|
||||
bool NeedUse_as_CopyLink() const { return PackSize == 0 && Is_CopyLink(); }
|
||||
bool NeedUse_as_HardLink() const { return PackSize == 0 && Is_HardLink(); }
|
||||
bool NeedUse_as_CopyLink_or_HardLink() const { return PackSize == 0 && Is_CopyLink_or_HardLink(); }
|
||||
|
||||
bool GetAltStreamName(AString &name) const;
|
||||
|
||||
|
||||
@@ -220,6 +220,8 @@ HRESULT CInArchive::Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit)
|
||||
ArcInfo.Flags = Get16(buf + 3);
|
||||
|
||||
UInt32 headerSize = NHeader::NArchive::kArchiveHeaderSize;
|
||||
|
||||
/*
|
||||
if (ArcInfo.IsThereEncryptVer())
|
||||
{
|
||||
if (blockSize <= headerSize)
|
||||
@@ -229,6 +231,8 @@ HRESULT CInArchive::Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit)
|
||||
ArcInfo.EncryptVersion = buf[NHeader::NArchive::kArchiveHeaderSize];
|
||||
headerSize += 1;
|
||||
}
|
||||
*/
|
||||
|
||||
if (blockSize < headerSize
|
||||
|| buf[2] != NHeader::NBlockType::kArchiveHeader
|
||||
|| !CheckHeaderCrc(buf, headerSize))
|
||||
@@ -509,7 +513,7 @@ HRESULT CInArchive::GetNextItem(CItem &item, ICryptoGetTextPassword *getTextPass
|
||||
m_RarAESSpec = new NCrypto::NRar3::CDecoder;
|
||||
m_RarAES = m_RarAESSpec;
|
||||
}
|
||||
m_RarAESSpec->SetRar350Mode(ArcInfo.IsEncryptOld());
|
||||
// m_RarAESSpec->SetRar350Mode(ArcInfo.IsEncryptOld());
|
||||
|
||||
// Salt
|
||||
const UInt32 kSaltSize = 8;
|
||||
@@ -1552,7 +1556,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
rar3CryptoDecoderSpec = new NCrypto::NRar3::CDecoder;
|
||||
rar3CryptoDecoder = rar3CryptoDecoderSpec;
|
||||
}
|
||||
rar3CryptoDecoderSpec->SetRar350Mode(item.UnPackVersion < 36);
|
||||
// rar3CryptoDecoderSpec->SetRar350Mode(item.UnPackVersion < 36);
|
||||
/*
|
||||
CMyComPtr<ICompressSetDecoderProperties2> cryptoProperties;
|
||||
RINOK(rar3CryptoDecoder.QueryInterface(IID_ICompressSetDecoderProperties2,
|
||||
@@ -1602,11 +1606,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);
|
||||
}
|
||||
|
||||
@@ -41,9 +41,9 @@ struct CInArcInfo
|
||||
bool IsRecovery() const { return (Flags & NHeader::NArchive::kRecovery) != 0; }
|
||||
bool IsEncrypted() const { return (Flags & NHeader::NArchive::kBlockEncryption) != 0; }
|
||||
bool IsFirstVolume() const { return (Flags & NHeader::NArchive::kFirstVolume) != 0; }
|
||||
bool IsThereEncryptVer() const { return (Flags & NHeader::NArchive::kEncryptVer) != 0; }
|
||||
|
||||
bool IsEncryptOld() const { return (!IsThereEncryptVer() || EncryptVersion < 36); }
|
||||
// bool IsThereEncryptVer() const { return (Flags & NHeader::NArchive::kEncryptVer) != 0; }
|
||||
// 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; }
|
||||
|
||||
@@ -41,7 +41,8 @@ namespace NArchive
|
||||
const UInt16 kRecovery = 0x40;
|
||||
const UInt16 kBlockEncryption = 0x80;
|
||||
const UInt16 kFirstVolume = 0x100; // (set only by RAR 3.0 and later)
|
||||
const UInt16 kEncryptVer = 0x200; // RAR 3.6 there is EncryptVer Byte in End of MainHeader
|
||||
|
||||
// const UInt16 kEncryptVer = 0x200; // RAR 3.6 : that feature was discarded by origial RAR
|
||||
|
||||
const UInt16 kEndOfArc_Flags_NextVol = 1;
|
||||
const UInt16 kEndOfArc_Flags_DataCRC = 2;
|
||||
|
||||
@@ -203,7 +203,7 @@ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
|
||||
_streams.Add(stream);
|
||||
|
||||
{
|
||||
UInt64 numFiles = _streams.Size();
|
||||
const UInt64 numFiles = _streams.Size();
|
||||
RINOK(callback->SetCompleted(&numFiles, NULL));
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
|
||||
break;
|
||||
if (result != S_OK)
|
||||
return result;
|
||||
if (!stream)
|
||||
if (!nextStream)
|
||||
break;
|
||||
{
|
||||
/*
|
||||
@@ -228,14 +228,14 @@ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
|
||||
return E_INVALIDARG;
|
||||
size = prop.uhVal.QuadPart;
|
||||
*/
|
||||
RINOK(stream->Seek(0, STREAM_SEEK_END, &size));
|
||||
RINOK(stream->Seek(0, STREAM_SEEK_SET, NULL));
|
||||
RINOK(nextStream->Seek(0, STREAM_SEEK_END, &size));
|
||||
RINOK(nextStream->Seek(0, STREAM_SEEK_SET, NULL));
|
||||
}
|
||||
_totalSize += size;
|
||||
_sizes.Add(size);
|
||||
_streams.Add(nextStream);
|
||||
{
|
||||
UInt64 numFiles = _streams.Size();
|
||||
const UInt64 numFiles = _streams.Size();
|
||||
RINOK(callback->SetCompleted(&numFiles, NULL));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
@@ -950,7 +959,7 @@ static HRESULT LzoDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *src
|
||||
*srcLen = 0;
|
||||
const Byte *destStart = dest;
|
||||
const Byte *srcStart = src;
|
||||
unsigned mode = 2;
|
||||
unsigned mode = 0;
|
||||
|
||||
{
|
||||
if (srcRem == 0)
|
||||
@@ -961,7 +970,7 @@ static HRESULT LzoDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *src
|
||||
src++;
|
||||
srcRem--;
|
||||
b -= 17;
|
||||
mode = (b < 4 ? 0 : 1);
|
||||
mode = (b < 4 ? 1 : 4);
|
||||
if (b > srcRem || b > destRem)
|
||||
return S_FALSE;
|
||||
srcRem -= b;
|
||||
@@ -979,6 +988,7 @@ static HRESULT LzoDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *src
|
||||
UInt32 b = *src++;
|
||||
srcRem--;
|
||||
UInt32 len, back;
|
||||
|
||||
if (b >= 64)
|
||||
{
|
||||
srcRem--;
|
||||
@@ -987,7 +997,7 @@ static HRESULT LzoDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *src
|
||||
}
|
||||
else if (b < 16)
|
||||
{
|
||||
if (mode == 2)
|
||||
if (mode == 0)
|
||||
{
|
||||
if (b == 0)
|
||||
{
|
||||
@@ -1004,21 +1014,23 @@ static HRESULT LzoDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *src
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
b += 3;
|
||||
if (b > srcRem || b > destRem)
|
||||
return S_FALSE;
|
||||
srcRem -= b;
|
||||
destRem -= b;
|
||||
mode = 1;
|
||||
mode = 4;
|
||||
do
|
||||
*dest++ = *src++;
|
||||
while (--b);
|
||||
continue;
|
||||
}
|
||||
|
||||
srcRem--;
|
||||
back = (b >> 2) + (*src++ << 2);
|
||||
len = 2;
|
||||
if (mode == 1)
|
||||
if (mode == 4)
|
||||
{
|
||||
back += (1 << 11);
|
||||
len = 3;
|
||||
@@ -1029,6 +1041,7 @@ static HRESULT LzoDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *src
|
||||
UInt32 bOld = b;
|
||||
b = (b < 32 ? 7 : 31);
|
||||
len = bOld & b;
|
||||
|
||||
if (len == 0)
|
||||
{
|
||||
for (len = b;; len += 255)
|
||||
@@ -1044,6 +1057,7 @@ static HRESULT LzoDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *src
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
len += 2;
|
||||
if (srcRem < 2)
|
||||
return S_FALSE;
|
||||
@@ -1053,38 +1067,39 @@ static HRESULT LzoDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *src
|
||||
srcRem -= 2;
|
||||
if (bOld < 32)
|
||||
{
|
||||
back += ((bOld & 8) << 11);
|
||||
if (back == 0)
|
||||
{
|
||||
*destLen = dest - destStart;
|
||||
*srcLen = src - srcStart;
|
||||
return S_OK;
|
||||
}
|
||||
back += ((bOld & 8) << 11) + (1 << 14) - 1;
|
||||
back += (1 << 14) - 1;
|
||||
}
|
||||
}
|
||||
|
||||
back++;
|
||||
if (len > destRem || (size_t)(dest - destStart) < back)
|
||||
return S_FALSE;
|
||||
destRem -= len;
|
||||
Byte *destTemp = dest - back;
|
||||
dest += len;
|
||||
|
||||
do
|
||||
{
|
||||
*(destTemp + back) = *destTemp;
|
||||
destTemp++;
|
||||
}
|
||||
while (--len);
|
||||
|
||||
b &= 3;
|
||||
mode = b;
|
||||
if (b == 0)
|
||||
{
|
||||
mode = 2;
|
||||
continue;
|
||||
}
|
||||
if (b > srcRem || b > destRem)
|
||||
return S_FALSE;
|
||||
srcRem -= b;
|
||||
destRem -= b;
|
||||
mode = 0;
|
||||
*dest++ = *src++;
|
||||
if (b > 1)
|
||||
{
|
||||
@@ -2115,7 +2130,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)
|
||||
|
||||
@@ -646,7 +646,7 @@ STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static const char *g_TagDesc[92] =
|
||||
static const char * const g_TagDesc[92] =
|
||||
{
|
||||
"End"
|
||||
, "ShowFrame"
|
||||
|
||||
@@ -72,6 +72,13 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
|
||||
break;
|
||||
}
|
||||
|
||||
case kpidWarningFlags:
|
||||
{
|
||||
if (_warning)
|
||||
prop = kpv_ErrorFlags_HeadersError;
|
||||
break;
|
||||
}
|
||||
|
||||
case kpidCodePage:
|
||||
{
|
||||
const char *name = NULL;
|
||||
@@ -98,7 +105,13 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
|
||||
HRESULT CHandler::ReadItem2(ISequentialInStream *stream, bool &filled, CItemEx &item)
|
||||
{
|
||||
item.HeaderPos = _phySize;
|
||||
RINOK(ReadItem(stream, filled, item, _error));
|
||||
EErrorType error;
|
||||
HRESULT res = ReadItem(stream, filled, item, error);
|
||||
if (error == k_ErrorType_Warning)
|
||||
_warning = true;
|
||||
else if (error != k_ErrorType_OK)
|
||||
_error = error;
|
||||
RINOK(res);
|
||||
if (filled)
|
||||
{
|
||||
/*
|
||||
@@ -233,6 +246,7 @@ STDMETHODIMP CHandler::OpenSeq(ISequentialInStream *stream)
|
||||
STDMETHODIMP CHandler::Close()
|
||||
{
|
||||
_isArc = false;
|
||||
_warning = false;
|
||||
_error = k_ErrorType_OK;
|
||||
|
||||
_phySizeDefined = false;
|
||||
|
||||
@@ -37,6 +37,7 @@ private:
|
||||
UInt64 _headersSize;
|
||||
bool _phySizeDefined;
|
||||
EErrorType _error;
|
||||
bool _warning;
|
||||
bool _isArc;
|
||||
|
||||
// bool _isSparse;
|
||||
|
||||
@@ -75,7 +75,7 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
|
||||
if ((_stream && (_error != k_ErrorType_OK /* || _isSparse */)) || _seqStream)
|
||||
if ((_stream && (_error != k_ErrorType_OK || _warning /* || _isSparse */)) || _seqStream)
|
||||
return E_NOTIMPL;
|
||||
CObjectVector<CUpdateItem> updateItems;
|
||||
UINT codePage = (_forceCodePage ? _specifiedCodePage : _openCodePage);
|
||||
|
||||
@@ -328,13 +328,63 @@ static HRESULT GetNextItemReal(ISequentialInStream *stream, bool &filled, CItemE
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
static HRESULT ReadDataToString(ISequentialInStream *stream, CItemEx &item, AString &s, EErrorType &error)
|
||||
{
|
||||
const unsigned packSize = (unsigned)item.GetPackSizeAligned();
|
||||
size_t processedSize = packSize;
|
||||
HRESULT res = ReadStream(stream, s.GetBuf(packSize), &processedSize);
|
||||
item.HeaderSize += (unsigned)processedSize;
|
||||
s.ReleaseBuf_CalcLen((unsigned)item.PackSize);
|
||||
RINOK(res);
|
||||
if (processedSize != packSize)
|
||||
error = k_ErrorType_UnexpectedEnd;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static bool ParsePaxLongName(const AString &src, AString &dest)
|
||||
{
|
||||
dest.Empty();
|
||||
for (unsigned pos = 0;;)
|
||||
{
|
||||
if (pos >= src.Len())
|
||||
return false;
|
||||
const char *start = src.Ptr(pos);
|
||||
const char *end;
|
||||
const UInt32 lineLen = ConvertStringToUInt32(start, &end);
|
||||
if (end == start)
|
||||
return false;
|
||||
if (*end != ' ')
|
||||
return false;
|
||||
if (lineLen > src.Len() - pos)
|
||||
return false;
|
||||
unsigned offset = (unsigned)(end - start) + 1;
|
||||
if (lineLen < offset)
|
||||
return false;
|
||||
if (IsString1PrefixedByString2(src.Ptr(pos + offset), "path="))
|
||||
{
|
||||
offset += 5; // "path="
|
||||
dest = src.Mid(pos + offset, lineLen - offset);
|
||||
if (dest.IsEmpty())
|
||||
return false;
|
||||
if (dest.Back() != '\n')
|
||||
return false;
|
||||
dest.DeleteBack();
|
||||
return true;
|
||||
}
|
||||
pos += lineLen;
|
||||
}
|
||||
}
|
||||
|
||||
HRESULT ReadItem(ISequentialInStream *stream, bool &filled, CItemEx &item, EErrorType &error)
|
||||
{
|
||||
item.HeaderSize = 0;
|
||||
|
||||
bool flagL = false;
|
||||
bool flagK = false;
|
||||
AString nameL;
|
||||
AString nameK;
|
||||
AString pax;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
@@ -363,18 +413,11 @@ HRESULT ReadItem(ISequentialInStream *stream, bool &filled, CItemEx &item, EErro
|
||||
return S_OK;
|
||||
if (item.PackSize > (1 << 14))
|
||||
return S_OK;
|
||||
unsigned packSize = (unsigned)item.GetPackSizeAligned();
|
||||
char *buf = name->GetBuf(packSize);
|
||||
size_t processedSize = packSize;
|
||||
HRESULT res = ReadStream(stream, buf, &processedSize);
|
||||
item.HeaderSize += (unsigned)processedSize;
|
||||
name->ReleaseBuf_CalcLen((unsigned)item.PackSize);
|
||||
RINOK(res);
|
||||
if (processedSize != packSize)
|
||||
{
|
||||
error = k_ErrorType_UnexpectedEnd;
|
||||
|
||||
RINOK(ReadDataToString(stream, item, *name, error));
|
||||
if (error != k_ErrorType_OK)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -385,6 +428,14 @@ HRESULT ReadItem(ISequentialInStream *stream, bool &filled, CItemEx &item, EErro
|
||||
case 'X':
|
||||
{
|
||||
// pax Extended Header
|
||||
if (item.Name.IsPrefixedBy("PaxHeader/"))
|
||||
{
|
||||
RINOK(ReadDataToString(stream, item, pax, error));
|
||||
if (error != k_ErrorType_OK)
|
||||
return S_OK;
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case NFileHeader::NLinkFlag::kDumpDir:
|
||||
@@ -415,6 +466,16 @@ HRESULT ReadItem(ISequentialInStream *stream, bool &filled, CItemEx &item, EErro
|
||||
}
|
||||
|
||||
error = k_ErrorType_OK;
|
||||
|
||||
if (!pax.IsEmpty())
|
||||
{
|
||||
AString name;
|
||||
if (ParsePaxLongName(pax, name))
|
||||
item.Name = name;
|
||||
else
|
||||
error = k_ErrorType_Warning;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ enum EErrorType
|
||||
k_ErrorType_OK,
|
||||
k_ErrorType_Corrupted,
|
||||
k_ErrorType_UnexpectedEnd,
|
||||
k_ErrorType_Warning
|
||||
};
|
||||
|
||||
HRESULT ReadItem(ISequentialInStream *stream, bool &filled, CItemEx &itemInfo, EErrorType &error);
|
||||
|
||||
@@ -428,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));
|
||||
|
||||
@@ -518,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;
|
||||
@@ -599,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
|
||||
@@ -660,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)
|
||||
@@ -686,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;
|
||||
|
||||
@@ -700,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;
|
||||
|
||||
@@ -862,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;
|
||||
|
||||
@@ -225,7 +225,7 @@ enum
|
||||
FV_FILETYPE_FFS_PAD = 0xF0
|
||||
};
|
||||
|
||||
static const char *g_FileTypes[] =
|
||||
static const char * const g_FileTypes[] =
|
||||
{
|
||||
"ALL"
|
||||
, "RAW"
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -1349,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)
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
@@ -298,7 +298,8 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
|
||||
|
||||
AString res;
|
||||
|
||||
bool numMethods = 0;
|
||||
unsigned numMethods = 0;
|
||||
|
||||
for (unsigned i = 0; i < ARRAY_SIZE(k_Methods); i++)
|
||||
{
|
||||
if (methodMask & ((UInt32)1 << i))
|
||||
@@ -388,7 +389,7 @@ static void MethodToProp(int method, int chunksSizeBits, NCOM::CPropVariant &pro
|
||||
char temp[32];
|
||||
|
||||
if ((unsigned)method < ARRAY_SIZE(k_Methods))
|
||||
strcpy(temp, k_Methods[method]);
|
||||
strcpy(temp, k_Methods[(unsigned)method]);
|
||||
else
|
||||
ConvertUInt32ToString((unsigned)method, temp);
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -589,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;
|
||||
|
||||
@@ -661,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;
|
||||
|
||||
@@ -679,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));
|
||||
}
|
||||
|
||||
|
||||
@@ -712,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;
|
||||
}
|
||||
}
|
||||
@@ -736,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)
|
||||
@@ -973,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;
|
||||
|
||||
|
||||
@@ -255,13 +255,13 @@ static bool AddItem(const CXmlItem &item, CObjectVector<CFile> &files, int paren
|
||||
if (encodingItem.IsTag)
|
||||
{
|
||||
AString s = encodingItem.GetPropVal("style");
|
||||
if (s.Len() >= 0)
|
||||
if (!s.IsEmpty())
|
||||
{
|
||||
AString appl = "application/";
|
||||
const AString appl = "application/";
|
||||
if (s.IsPrefixedBy(appl))
|
||||
{
|
||||
s.DeleteFrontal(appl.Len());
|
||||
AString xx = "x-";
|
||||
const AString xx = "x-";
|
||||
if (s.IsPrefixedBy(xx))
|
||||
{
|
||||
s.DeleteFrontal(xx.Len());
|
||||
@@ -365,12 +365,12 @@ HRESULT CHandler::Open2(IInStream *stream)
|
||||
{
|
||||
const CFile &file = _files[i];
|
||||
file.UpdateTotalPackSize(totalPackSize);
|
||||
if (file.Name == "Payload")
|
||||
if (file.Name == "Payload" || file.Name == "Content")
|
||||
{
|
||||
_mainSubfile = i;
|
||||
numMainFiles++;
|
||||
}
|
||||
if (file.Name == "PackageInfo")
|
||||
else if (file.Name == "PackageInfo")
|
||||
_is_pkg = true;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -723,7 +723,7 @@ STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
|
||||
static const Byte k_Signature[] = { 'x', 'a', 'r', '!', 0, 0x1C };
|
||||
|
||||
REGISTER_ARC_I(
|
||||
"Xar", "xar pkg", 0, 0xE1,
|
||||
"Xar", "xar pkg xip", 0, 0xE1,
|
||||
k_Signature,
|
||||
0,
|
||||
0,
|
||||
|
||||
@@ -276,7 +276,7 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
|
||||
EXTERNAL_CODECS_VARS
|
||||
m_Items, updateItems, outStream,
|
||||
m_Archive.IsOpen() ? &m_Archive : NULL, _removeSfxBlock,
|
||||
&options, callback);
|
||||
options, callback);
|
||||
|
||||
COM_TRY_END2
|
||||
}
|
||||
|
||||
@@ -297,11 +297,14 @@ HRESULT CInArchive::FindMarker(IInStream *stream, const UInt64 *searchLimit)
|
||||
if (searchLimit && *searchLimit == 0)
|
||||
{
|
||||
Byte startBuf[kMarkerSize];
|
||||
size_t processed = kMarkerSize;
|
||||
RINOK(ReadStream(stream, startBuf, &processed));
|
||||
m_Position += processed;
|
||||
if (processed < kMarkerSize)
|
||||
return S_FALSE;
|
||||
{
|
||||
size_t processed = kMarkerSize;
|
||||
RINOK(ReadStream(stream, startBuf, &processed));
|
||||
m_Position += processed;
|
||||
if (processed != kMarkerSize)
|
||||
return S_FALSE;
|
||||
}
|
||||
|
||||
m_Signature = Get32(startBuf);
|
||||
|
||||
if (m_Signature != NSignature::kEcd &&
|
||||
@@ -318,7 +321,7 @@ HRESULT CInArchive::FindMarker(IInStream *stream, const UInt64 *searchLimit)
|
||||
size_t processed = kMarkerSize;
|
||||
RINOK(ReadStream(stream, startBuf, &processed));
|
||||
m_Position += processed;
|
||||
if (processed < kMarkerSize)
|
||||
if (processed != kMarkerSize)
|
||||
return S_FALSE;
|
||||
m_Signature = Get32(startBuf);
|
||||
if (m_Signature != NSignature::kEcd &&
|
||||
@@ -1451,7 +1454,10 @@ HRESULT CVols::ParseArcName(IArchiveOpenVolumeCallback *volCallback)
|
||||
if (result == S_FALSE || !ZipStream)
|
||||
{
|
||||
if (MissingName.IsEmpty())
|
||||
{
|
||||
MissingZip = true;
|
||||
MissingName = volName;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@@ -1567,7 +1573,7 @@ HRESULT CInArchive::ReadVols()
|
||||
if (Vols.StartIsZip)
|
||||
Vols.ZipStream = StartStream;
|
||||
|
||||
bool cdOK = false;
|
||||
// bool cdOK = false;
|
||||
|
||||
if (Vols.ZipStream)
|
||||
{
|
||||
@@ -1589,12 +1595,16 @@ HRESULT CInArchive::ReadVols()
|
||||
// Vols.EndVolIndex = ecd.ThisDisk;
|
||||
unsigned numMissingVols;
|
||||
if (cdDisk == zipDisk)
|
||||
cdOK = true;
|
||||
{
|
||||
// cdOK = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
RINOK(ReadVols2(volCallback, cdDisk, zipDisk, zipDisk, 0, numMissingVols));
|
||||
if (numMissingVols == 0)
|
||||
cdOK = false;
|
||||
{
|
||||
// cdOK = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (res != S_FALSE)
|
||||
@@ -1981,6 +1991,12 @@ HRESULT CInArchive::ReadHeaders2(CObjectVector<CItemEx> &items)
|
||||
|
||||
if (!IsMultiVol)
|
||||
{
|
||||
if (EcdVolIndex == 0 && Vols.MissingZip && Vols.StartIsExe)
|
||||
{
|
||||
Vols.MissingName.Empty();
|
||||
Vols.MissingZip = false;
|
||||
}
|
||||
|
||||
UseDisk_in_SingleVol = true;
|
||||
|
||||
if (localsWereRead)
|
||||
|
||||
@@ -139,6 +139,7 @@ public:
|
||||
bool StartIsZ; // is .zip or .zNN
|
||||
bool StartIsZip; // is .zip
|
||||
bool IsUpperCase;
|
||||
bool MissingZip;
|
||||
Int32 StartVolIndex; // = (NN - 1), if StartStream is .zNN
|
||||
|
||||
Int32 StartParsingVol; // if we need local parsing, we must use that stream
|
||||
@@ -173,6 +174,7 @@ public:
|
||||
BaseName.Empty();
|
||||
MissingName.Empty();
|
||||
|
||||
MissingZip = false;
|
||||
ecd_wasRead = false;
|
||||
|
||||
Streams.Clear();
|
||||
|
||||
@@ -584,7 +584,7 @@ static HRESULT Update2(
|
||||
CInArchive *inArchive,
|
||||
const CObjectVector<CItemEx> &inputItems,
|
||||
CObjectVector<CUpdateItem> &updateItems,
|
||||
const CCompressionMethodMode *options,
|
||||
const CCompressionMethodMode &options,
|
||||
const CByteBuffer *comment,
|
||||
IArchiveUpdateCallback *updateCallback)
|
||||
{
|
||||
@@ -596,6 +596,7 @@ static HRESULT Update2(
|
||||
UInt64 numBytesToCompress = 0;
|
||||
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < updateItems.Size(); i++)
|
||||
{
|
||||
const CUpdateItem &ui = updateItems[i];
|
||||
@@ -628,17 +629,15 @@ static HRESULT Update2(
|
||||
|
||||
UInt64 totalComplexity = complexity;
|
||||
|
||||
CAddCommon compressor(*options);
|
||||
CAddCommon compressor(options);
|
||||
|
||||
complexity = 0;
|
||||
|
||||
CCompressionMethodMode options2;
|
||||
if (options != 0)
|
||||
options2 = *options;
|
||||
CCompressionMethodMode options2 = options;
|
||||
|
||||
#ifndef _7ZIP_ST
|
||||
|
||||
UInt32 numThreads = options->NumThreads;
|
||||
UInt32 numThreads = options.NumThreads;
|
||||
const UInt32 kNumMaxThreads = 64;
|
||||
if (numThreads > kNumMaxThreads)
|
||||
numThreads = kNumMaxThreads;
|
||||
@@ -651,12 +650,12 @@ static HRESULT Update2(
|
||||
const size_t kMemPerThread = (1 << 25);
|
||||
const size_t kBlockSize = 1 << 16;
|
||||
|
||||
bool mtMode = ((options != 0) && (numThreads > 1));
|
||||
bool mtMode = (numThreads > 1);
|
||||
|
||||
if (numFilesToCompress <= 1)
|
||||
mtMode = false;
|
||||
|
||||
Byte method = options->MethodSequence.Front();
|
||||
Byte method = options.MethodSequence.Front();
|
||||
|
||||
if (!mtMode)
|
||||
{
|
||||
@@ -669,7 +668,7 @@ static HRESULT Update2(
|
||||
}
|
||||
else
|
||||
{
|
||||
if (method == NFileHeader::NCompressionMethod::kStored && !options->PasswordIsDefined)
|
||||
if (method == NFileHeader::NCompressionMethod::kStored && !options.PasswordIsDefined)
|
||||
numThreads = 1;
|
||||
if (method == NFileHeader::NCompressionMethod::kBZip2)
|
||||
{
|
||||
@@ -731,7 +730,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));
|
||||
|
||||
@@ -804,9 +802,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;
|
||||
@@ -822,7 +820,7 @@ static HRESULT Update2(
|
||||
threadInfo.UpdateIndex = mtItemIndex - 1;
|
||||
|
||||
compressingCompletedEvents.Add(threadInfo.CompressionCompletedEvent);
|
||||
threadIndices.Add(i);
|
||||
threadIndices.Add(k);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -855,16 +853,16 @@ static HRESULT Update2(
|
||||
|
||||
if (isDir)
|
||||
{
|
||||
WriteDirHeader(archive, options, ui, item);
|
||||
WriteDirHeader(archive, &options, ui, item);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (lastRealStreamItemIndex < (int)itemIndex)
|
||||
{
|
||||
lastRealStreamItemIndex = itemIndex;
|
||||
SetFileHeader(archive, *options, ui, item);
|
||||
SetFileHeader(archive, options, ui, item);
|
||||
// file Size can be 64-bit !!!
|
||||
archive.PrepareWriteCompressedData(item.Name.Len(), ui.Size, options->IsRealAesMode());
|
||||
archive.PrepareWriteCompressedData(item.Name.Len(), ui.Size, options.IsRealAesMode());
|
||||
}
|
||||
|
||||
CMemBlocks2 &memRef = refs.Refs[itemIndex];
|
||||
@@ -874,12 +872,12 @@ static HRESULT Update2(
|
||||
CMyComPtr<IOutStream> outStream;
|
||||
archive.CreateStreamForCompressing(&outStream);
|
||||
memRef.WriteToStream(memManager.GetBlockSize(), outStream);
|
||||
SetFileHeader(archive, *options, ui, item);
|
||||
SetFileHeader(archive, options, ui, item);
|
||||
// the BUG was fixed in 9.26:
|
||||
// SetItemInfoFromCompressingResult must be after SetFileHeader
|
||||
// to write correct Size.
|
||||
SetItemInfoFromCompressingResult(memRef.CompressingResult,
|
||||
options->IsRealAesMode(), options->AesKeyMode, item);
|
||||
options.IsRealAesMode(), options.AesKeyMode, item);
|
||||
archive.WriteLocalHeader_And_SeekToNextFile(item);
|
||||
// RINOK(updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK));
|
||||
memRef.FreeOpt(&memManager);
|
||||
@@ -920,17 +918,17 @@ static HRESULT Update2(
|
||||
{
|
||||
RINOK(threadInfo.OutStreamSpec->WriteToRealStream());
|
||||
threadInfo.OutStreamSpec->ReleaseOutStream();
|
||||
SetFileHeader(archive, *options, ui, item);
|
||||
SetFileHeader(archive, options, ui, item);
|
||||
SetItemInfoFromCompressingResult(threadInfo.CompressingResult,
|
||||
options->IsRealAesMode(), options->AesKeyMode, item);
|
||||
options.IsRealAesMode(), options.AesKeyMode, item);
|
||||
archive.WriteLocalHeader_And_SeekToNextFile(item);
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1173,7 +1171,7 @@ HRESULT Update(
|
||||
CObjectVector<CUpdateItem> &updateItems,
|
||||
ISequentialOutStream *seqOutStream,
|
||||
CInArchive *inArchive, bool removeSfx,
|
||||
CCompressionMethodMode *compressionMethodMode,
|
||||
const CCompressionMethodMode &compressionMethodMode,
|
||||
IArchiveUpdateCallback *updateCallback)
|
||||
{
|
||||
if (inArchive)
|
||||
|
||||
@@ -51,7 +51,7 @@ HRESULT Update(
|
||||
CObjectVector<CUpdateItem> &updateItems,
|
||||
ISequentialOutStream *seqOutStream,
|
||||
CInArchive *inArchive, bool removeSfx,
|
||||
CCompressionMethodMode *compressionMethodMode,
|
||||
const CCompressionMethodMode &compressionMethodMode,
|
||||
IArchiveUpdateCallback *updateCallback);
|
||||
|
||||
}}
|
||||
|
||||
@@ -749,11 +749,10 @@ static int main2(int numArgs, const char *args[])
|
||||
}
|
||||
}
|
||||
|
||||
if (!stdOutMode)
|
||||
Print_Size("Output size: ", outStreamSpec->ProcessedSize);
|
||||
|
||||
if (outStreamSpec)
|
||||
{
|
||||
if (!stdOutMode)
|
||||
Print_Size("Output size: ", outStreamSpec->ProcessedSize);
|
||||
if (outStreamSpec->Close() != S_OK)
|
||||
throw "File closing error";
|
||||
}
|
||||
|
||||
@@ -804,6 +804,15 @@ SOURCE=..\..\..\..\C\Delta.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\DllSecur.c
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\DllSecur.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\Lzma2Dec.c
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
# End Source File
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
|
||||
#include "../../MyVersion.h"
|
||||
|
||||
#include "../../../../C/DllSecur.h"
|
||||
|
||||
using namespace NWindows;
|
||||
using namespace NFile;
|
||||
using namespace NDir;
|
||||
@@ -103,7 +105,7 @@ static const wchar_t *kUniversalWildcard = L"*";
|
||||
static const int kCommandIndex = 0;
|
||||
|
||||
static const char *kHelpString =
|
||||
"\nUsage: 7zSFX [<command>] [<switches>...]\n"
|
||||
"\nUsage: 7zSFX [<command>] [<switches>...] [<file_name>...]\n"
|
||||
"\n"
|
||||
"<Commands>\n"
|
||||
// " l: List contents of archive\n"
|
||||
@@ -222,13 +224,6 @@ void AddCommandLineWildcardToCensor(NWildcard::CCensor &wildcardCensor,
|
||||
ShowMessageAndThrowException(kIncorrectWildcardInCommandLine, NExitCode::kUserError);
|
||||
}
|
||||
|
||||
void AddToCensorFromNonSwitchesStrings(NWildcard::CCensor &wildcardCensor,
|
||||
const UStringVector & /* nonSwitchStrings */, NRecursedType::EEnum type,
|
||||
bool /* thereAreSwitchIncludeWildcards */)
|
||||
{
|
||||
AddCommandLineWildcardToCensor(wildcardCensor, kUniversalWildcard, true, type);
|
||||
}
|
||||
|
||||
|
||||
#ifndef _WIN32
|
||||
static void GetArguments(int numArgs, const char *args[], UStringVector &parts)
|
||||
@@ -248,6 +243,11 @@ int Main2(
|
||||
#endif
|
||||
)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
// do we need load Security DLLs for console program?
|
||||
LoadSecurityDlls();
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) && !defined(UNDER_CE)
|
||||
SetFileApisToOEM();
|
||||
#endif
|
||||
@@ -283,9 +283,16 @@ int Main2(
|
||||
commandStrings.Delete(0);
|
||||
|
||||
NCommandLineParser::CParser parser(kNumSwitches);
|
||||
|
||||
try
|
||||
{
|
||||
parser.ParseStrings(kSwitchForms, commandStrings);
|
||||
if (!parser.ParseStrings(kSwitchForms, commandStrings))
|
||||
{
|
||||
g_StdOut << "Command line error:" << endl
|
||||
<< parser.ErrorMessage << endl
|
||||
<< parser.ErrorLine << endl;
|
||||
return NExitCode::kUserError;
|
||||
}
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
@@ -297,19 +304,23 @@ int Main2(
|
||||
PrintHelp();
|
||||
return 0;
|
||||
}
|
||||
|
||||
const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;
|
||||
|
||||
int numNonSwitchStrings = nonSwitchStrings.Size();
|
||||
unsigned curCommandIndex = 0;
|
||||
|
||||
CArchiveCommand command;
|
||||
if (numNonSwitchStrings == 0)
|
||||
if (nonSwitchStrings.IsEmpty())
|
||||
command.CommandType = NCommandType::kFullExtract;
|
||||
else
|
||||
{
|
||||
if (numNonSwitchStrings > 1)
|
||||
PrintHelpAndExit();
|
||||
if (!ParseArchiveCommand(nonSwitchStrings[kCommandIndex], command))
|
||||
PrintHelpAndExit();
|
||||
const UString &cmd = nonSwitchStrings[curCommandIndex];
|
||||
if (!ParseArchiveCommand(cmd, command))
|
||||
{
|
||||
g_StdOut << "ERROR: Unknown command:" << endl << cmd << endl;
|
||||
return NExitCode::kUserError;
|
||||
}
|
||||
curCommandIndex = 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -318,11 +329,17 @@ int Main2(
|
||||
|
||||
NWildcard::CCensor wildcardCensor;
|
||||
|
||||
bool thereAreSwitchIncludeWildcards;
|
||||
thereAreSwitchIncludeWildcards = false;
|
||||
|
||||
AddToCensorFromNonSwitchesStrings(wildcardCensor, nonSwitchStrings, recursedType,
|
||||
thereAreSwitchIncludeWildcards);
|
||||
{
|
||||
if (nonSwitchStrings.Size() == curCommandIndex)
|
||||
AddCommandLineWildcardToCensor(wildcardCensor, kUniversalWildcard, true, recursedType);
|
||||
for (; curCommandIndex < nonSwitchStrings.Size(); curCommandIndex++)
|
||||
{
|
||||
const UString &s = nonSwitchStrings[curCommandIndex];
|
||||
if (s.IsEmpty())
|
||||
throw "Empty file path";
|
||||
AddCommandLineWildcardToCensor(wildcardCensor, s, true, recursedType);
|
||||
}
|
||||
}
|
||||
|
||||
bool yesToAll = parser[NKey::kYes].ThereIs;
|
||||
|
||||
@@ -363,9 +380,11 @@ int Main2(
|
||||
IUnknown
|
||||
#endif
|
||||
> compressCodecsInfo = codecs;
|
||||
HRESULT result = codecs->Load();
|
||||
if (result != S_OK)
|
||||
throw CSystemException(result);
|
||||
{
|
||||
HRESULT result = codecs->Load();
|
||||
if (result != S_OK)
|
||||
throw CSystemException(result);
|
||||
}
|
||||
|
||||
if (command.CommandType != NCommandType::kList)
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@ CFLAGS = $(CFLAGS) \
|
||||
-DEXTRACT_ONLY \
|
||||
-DNO_READ_FROM_CODER \
|
||||
-D_SFX \
|
||||
-D_CONSOLE \
|
||||
|
||||
CURRENT_OBJS = \
|
||||
$O\SfxCon.obj \
|
||||
@@ -114,6 +115,7 @@ C_OBJS = \
|
||||
$O\BraIA64.obj \
|
||||
$O\CpuArch.obj \
|
||||
$O\Delta.obj \
|
||||
$O\DllSecur.obj \
|
||||
$O\Lzma2Dec.obj \
|
||||
$O\LzmaDec.obj \
|
||||
$O\Ppmd7.obj \
|
||||
|
||||
@@ -55,8 +55,7 @@ struct CThreadExtracting
|
||||
Result = ArchiveLink.Open2(options, ExtractCallbackSpec);
|
||||
if (Result != S_OK)
|
||||
{
|
||||
if (Result != S_OK)
|
||||
ErrorMessage = kCantOpenArchive;
|
||||
ErrorMessage = kCantOpenArchive;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -706,6 +706,15 @@ SOURCE=..\..\..\..\C\Delta.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\DllSecur.c
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\DllSecur.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\Lzma2Dec.c
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
# End Source File
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
|
||||
#include "ExtractEngine.h"
|
||||
|
||||
#include "../../../../C/DllSecur.h"
|
||||
|
||||
#include "resource.h"
|
||||
|
||||
using namespace NWindows;
|
||||
@@ -135,6 +137,10 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
|
||||
|
||||
NT_CHECK
|
||||
|
||||
#ifdef _WIN32
|
||||
LoadSecurityDlls();
|
||||
#endif
|
||||
|
||||
// InitCommonControls();
|
||||
|
||||
UString archiveName, switches;
|
||||
@@ -207,11 +213,13 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
|
||||
|
||||
CCodecs *codecs = new CCodecs;
|
||||
CMyComPtr<IUnknown> compressCodecsInfo = codecs;
|
||||
HRESULT result = codecs->Load();
|
||||
if (result != S_OK)
|
||||
{
|
||||
ShowErrorMessage(L"Can not load codecs");
|
||||
return 1;
|
||||
HRESULT result = codecs->Load();
|
||||
if (result != S_OK)
|
||||
{
|
||||
ShowErrorMessage(L"Can not load codecs");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
const FString tempDirPath = tempDir.GetPath();
|
||||
|
||||
@@ -100,6 +100,7 @@ C_OBJS = \
|
||||
$O\BraIA64.obj \
|
||||
$O\CpuArch.obj \
|
||||
$O\Delta.obj \
|
||||
$O\DllSecur.obj \
|
||||
$O\Lzma2Dec.obj \
|
||||
$O\LzmaDec.obj \
|
||||
$O\Threads.obj \
|
||||
|
||||
@@ -888,6 +888,15 @@ SOURCE=..\..\..\..\C\Delta.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\DllSecur.c
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\DllSecur.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\Lzma2Dec.c
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
# End Source File
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
#include "../../UI/GUI/ExtractGUI.h"
|
||||
#include "../../UI/GUI/ExtractRes.h"
|
||||
|
||||
#include "../../../../C/DllSecur.h"
|
||||
|
||||
using namespace NWindows;
|
||||
using namespace NFile;
|
||||
using namespace NDir;
|
||||
@@ -220,6 +222,10 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
|
||||
|
||||
try
|
||||
{
|
||||
#ifdef _WIN32
|
||||
LoadSecurityDlls();
|
||||
#endif
|
||||
|
||||
return WinMain2();
|
||||
}
|
||||
catch(const CNewException &)
|
||||
|
||||
@@ -131,8 +131,9 @@ C_OBJS = \
|
||||
$O\Bra.obj \
|
||||
$O\Bra86.obj \
|
||||
$O\BraIA64.obj \
|
||||
$O\Delta.obj \
|
||||
$O\CpuArch.obj \
|
||||
$O\Delta.obj \
|
||||
$O\DllSecur.obj \
|
||||
$O\Lzma2Dec.obj \
|
||||
$O\LzmaDec.obj \
|
||||
$O\Ppmd7.obj \
|
||||
|
||||
@@ -403,9 +403,9 @@ HRESULT CMethodProps::ParseParamsFromPROPVARIANT(const UString &realName, const
|
||||
if (value.vt == VT_EMPTY)
|
||||
{
|
||||
// {realName}=[empty]
|
||||
UString name, value;
|
||||
SplitParam(realName, name, value);
|
||||
return SetParam(name, value);
|
||||
UString name, valueStr;
|
||||
SplitParam(realName, name, valueStr);
|
||||
return SetParam(name, valueStr);
|
||||
}
|
||||
|
||||
// {realName}=value
|
||||
|
||||
@@ -449,7 +449,7 @@ void CThreadInfo::EncodeBlock(const Byte *block, UInt32 blockSize)
|
||||
}
|
||||
while (++i < kGroupSize && mtfPos < mtfArraySize);
|
||||
|
||||
UInt32 bestPrice = 0xFFFFFFFF;
|
||||
UInt32 bestPrice2 = 0xFFFFFFFF;
|
||||
unsigned t = 0;
|
||||
do
|
||||
{
|
||||
@@ -459,10 +459,10 @@ void CThreadInfo::EncodeBlock(const Byte *block, UInt32 blockSize)
|
||||
do
|
||||
price += lens[symbols[j]];
|
||||
while (++j < i);
|
||||
if (price < bestPrice)
|
||||
if (price < bestPrice2)
|
||||
{
|
||||
m_Selectors[g] = (Byte)t;
|
||||
bestPrice = price;
|
||||
bestPrice2 = price;
|
||||
}
|
||||
}
|
||||
while (++t < numTables);
|
||||
|
||||
@@ -514,13 +514,13 @@ HRESULT CDecoder::Code(ISequentialInStream * const *inStreams, const UInt64 * co
|
||||
|
||||
STDMETHODIMP CDecoder::SetInStream2(UInt32 streamIndex, ISequentialInStream *inStream)
|
||||
{
|
||||
inStreams[streamIndex] = inStream;
|
||||
_inStreams[streamIndex] = inStream;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CDecoder::ReleaseInStream2(UInt32 streamIndex)
|
||||
{
|
||||
inStreams[streamIndex].Release();
|
||||
_inStreams[streamIndex].Release();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@@ -601,7 +601,7 @@ STDMETHODIMP CDecoder::Read(void *data, UInt32 size, UInt32 *processedSize)
|
||||
do
|
||||
{
|
||||
UInt32 curSize = _bufsCurSizes[dec.state] - (UInt32)totalRead;
|
||||
HRESULT res2 = inStreams[dec.state]->Read(_bufs[dec.state] + totalRead, curSize, &curSize);
|
||||
HRESULT res2 = _inStreams[dec.state]->Read(_bufs[dec.state] + totalRead, curSize, &curSize);
|
||||
_readRes[dec.state] = res2;
|
||||
if (curSize == 0)
|
||||
break;
|
||||
|
||||
@@ -72,7 +72,7 @@ class CDecoder:
|
||||
unsigned _extraReadSizes[BCJ2_NUM_STREAMS];
|
||||
UInt64 _inStreamsProcessed[BCJ2_NUM_STREAMS];
|
||||
HRESULT _readRes[BCJ2_NUM_STREAMS];
|
||||
CMyComPtr<ISequentialInStream> inStreams[BCJ2_NUM_STREAMS];
|
||||
CMyComPtr<ISequentialInStream> _inStreams[BCJ2_NUM_STREAMS];
|
||||
|
||||
bool _finishMode;
|
||||
bool _outSizeDefined;
|
||||
|
||||
@@ -8,9 +8,9 @@ namespace NCompress {
|
||||
namespace NDeflate {
|
||||
namespace NDecoder {
|
||||
|
||||
CCoder::CCoder(bool deflate64Mode, bool deflateNSIS):
|
||||
CCoder::CCoder(bool deflate64Mode):
|
||||
_deflate64Mode(deflate64Mode),
|
||||
_deflateNSIS(deflateNSIS),
|
||||
_deflateNSIS(false),
|
||||
_keepHistory(false),
|
||||
_needFinishInput(false),
|
||||
_needInitInStream(true),
|
||||
|
||||
@@ -79,9 +79,11 @@ public:
|
||||
bool ZlibMode;
|
||||
Byte ZlibFooter[4];
|
||||
|
||||
CCoder(bool deflate64Mode, bool deflateNSIS = false);
|
||||
CCoder(bool deflate64Mode);
|
||||
virtual ~CCoder() {};
|
||||
|
||||
void SetNsisMode(bool nsisMode) { _deflateNSIS = nsisMode; }
|
||||
|
||||
void Set_KeepHistory(bool keepHistory) { _keepHistory = keepHistory; }
|
||||
void Set_NeedFinishInput(bool needFinishInput) { _needFinishInput = needFinishInput; }
|
||||
|
||||
@@ -147,7 +149,6 @@ public:
|
||||
};
|
||||
|
||||
class CCOMCoder : public CCoder { public: CCOMCoder(): CCoder(false) {} };
|
||||
class CNsisCOMCoder : public CCoder { public: CNsisCOMCoder(): CCoder(false, true) {} };
|
||||
class CCOMCoder64 : public CCoder { public: CCOMCoder64(): CCoder(true) {} };
|
||||
|
||||
}}}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user