This commit is contained in:
Igor Pavlov
2017-04-30 00:00:00 +00:00
committed by Kornel
parent 603abd5528
commit 2efa10565a
442 changed files with 15479 additions and 8525 deletions

12
C/7z.h
View File

@@ -1,5 +1,5 @@
/* 7z.h -- 7z interface /* 7z.h -- 7z interface
2015-11-18 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#ifndef __7Z_H #ifndef __7Z_H
#define __7Z_H #define __7Z_H
@@ -98,7 +98,7 @@ UInt64 SzAr_GetFolderUnpackSize(const CSzAr *p, UInt32 folderIndex);
SRes SzAr_DecodeFolder(const CSzAr *p, UInt32 folderIndex, SRes SzAr_DecodeFolder(const CSzAr *p, UInt32 folderIndex,
ILookInStream *stream, UInt64 startPos, ILookInStream *stream, UInt64 startPos,
Byte *outBuffer, size_t outSize, Byte *outBuffer, size_t outSize,
ISzAlloc *allocMain); ISzAllocPtr allocMain);
typedef struct typedef struct
{ {
@@ -131,7 +131,7 @@ typedef struct
#define SzArEx_GetFileSize(p, i) ((p)->UnpackPositions[(i) + 1] - (p)->UnpackPositions[i]) #define SzArEx_GetFileSize(p, i) ((p)->UnpackPositions[(i) + 1] - (p)->UnpackPositions[i])
void SzArEx_Init(CSzArEx *p); void SzArEx_Init(CSzArEx *p);
void SzArEx_Free(CSzArEx *p, ISzAlloc *alloc); void SzArEx_Free(CSzArEx *p, ISzAllocPtr alloc);
UInt64 SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder); UInt64 SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder);
int SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, UInt64 *resSize); int SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, UInt64 *resSize);
@@ -179,8 +179,8 @@ SRes SzArEx_Extract(
size_t *outBufferSize, /* buffer size for output buffer */ size_t *outBufferSize, /* buffer size for output buffer */
size_t *offset, /* offset of stream for required file in *outBuffer */ size_t *offset, /* offset of stream for required file in *outBuffer */
size_t *outSizeProcessed, /* size of file in *outBuffer */ size_t *outSizeProcessed, /* size of file in *outBuffer */
ISzAlloc *allocMain, ISzAllocPtr allocMain,
ISzAlloc *allocTemp); ISzAllocPtr allocTemp);
/* /*
@@ -195,7 +195,7 @@ SZ_ERROR_FAIL
*/ */
SRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream, SRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream,
ISzAlloc *allocMain, ISzAlloc *allocTemp); ISzAllocPtr allocMain, ISzAllocPtr allocTemp);
EXTERN_C_END EXTERN_C_END

View File

@@ -1,8 +1,10 @@
/* 7zAlloc.c -- Allocation functions /* 7zAlloc.c -- Allocation functions
2015-11-09 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
#include <stdlib.h>
#include "7zAlloc.h" #include "7zAlloc.h"
/* #define _SZ_ALLOC_DEBUG */ /* #define _SZ_ALLOC_DEBUG */
@@ -20,7 +22,7 @@ int g_allocCountTemp = 0;
#endif #endif
void *SzAlloc(void *p, size_t size) void *SzAlloc(ISzAllocPtr p, size_t size)
{ {
UNUSED_VAR(p); UNUSED_VAR(p);
if (size == 0) if (size == 0)
@@ -32,7 +34,7 @@ void *SzAlloc(void *p, size_t size)
return malloc(size); return malloc(size);
} }
void SzFree(void *p, void *address) void SzFree(ISzAllocPtr p, void *address)
{ {
UNUSED_VAR(p); UNUSED_VAR(p);
#ifdef _SZ_ALLOC_DEBUG #ifdef _SZ_ALLOC_DEBUG
@@ -45,7 +47,7 @@ void SzFree(void *p, void *address)
free(address); free(address);
} }
void *SzAllocTemp(void *p, size_t size) void *SzAllocTemp(ISzAllocPtr p, size_t size)
{ {
UNUSED_VAR(p); UNUSED_VAR(p);
if (size == 0) if (size == 0)
@@ -60,7 +62,7 @@ void *SzAllocTemp(void *p, size_t size)
return malloc(size); return malloc(size);
} }
void SzFreeTemp(void *p, void *address) void SzFreeTemp(ISzAllocPtr p, void *address)
{ {
UNUSED_VAR(p); UNUSED_VAR(p);
#ifdef _SZ_ALLOC_DEBUG #ifdef _SZ_ALLOC_DEBUG

View File

@@ -1,23 +1,19 @@
/* 7zAlloc.h -- Allocation functions /* 7zAlloc.h -- Allocation functions
2013-03-25 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#ifndef __7Z_ALLOC_H #ifndef __7Z_ALLOC_H
#define __7Z_ALLOC_H #define __7Z_ALLOC_H
#include <stdlib.h> #include "7zTypes.h"
#ifdef __cplusplus EXTERN_C_BEGIN
extern "C" {
#endif
void *SzAlloc(void *p, size_t size); void *SzAlloc(ISzAllocPtr p, size_t size);
void SzFree(void *p, void *address); void SzFree(ISzAllocPtr p, void *address);
void *SzAllocTemp(void *p, size_t size); void *SzAllocTemp(ISzAllocPtr p, size_t size);
void SzFreeTemp(void *p, void *address); void SzFreeTemp(ISzAllocPtr p, void *address);
#ifdef __cplusplus EXTERN_C_END
}
#endif
#endif #endif

View File

@@ -1,5 +1,5 @@
/* 7zArcIn.c -- 7z Input functions /* 7zArcIn.c -- 7z Input functions
2016-05-16 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@@ -11,7 +11,7 @@
#include "CpuArch.h" #include "CpuArch.h"
#define MY_ALLOC(T, p, size, alloc) { \ #define MY_ALLOC(T, p, size, alloc) { \
if ((p = (T *)IAlloc_Alloc(alloc, (size) * sizeof(T))) == NULL) return SZ_ERROR_MEM; } if ((p = (T *)ISzAlloc_Alloc(alloc, (size) * sizeof(T))) == NULL) return SZ_ERROR_MEM; }
#define MY_ALLOC_ZE(T, p, size, alloc) { if ((size) == 0) p = NULL; else MY_ALLOC(T, p, size, alloc) } #define MY_ALLOC_ZE(T, p, size, alloc) { if ((size) == 0) p = NULL; else MY_ALLOC(T, p, size, alloc) }
@@ -60,7 +60,7 @@ const Byte k7zSignature[k7zSignatureSize] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};
#define SzBitUi32s_Init(p) { (p)->Defs = NULL; (p)->Vals = NULL; } #define SzBitUi32s_Init(p) { (p)->Defs = NULL; (p)->Vals = NULL; }
static SRes SzBitUi32s_Alloc(CSzBitUi32s *p, size_t num, ISzAlloc *alloc) static SRes SzBitUi32s_Alloc(CSzBitUi32s *p, size_t num, ISzAllocPtr alloc)
{ {
if (num == 0) if (num == 0)
{ {
@@ -75,18 +75,18 @@ static SRes SzBitUi32s_Alloc(CSzBitUi32s *p, size_t num, ISzAlloc *alloc)
return SZ_OK; return SZ_OK;
} }
void SzBitUi32s_Free(CSzBitUi32s *p, ISzAlloc *alloc) void SzBitUi32s_Free(CSzBitUi32s *p, ISzAllocPtr alloc)
{ {
IAlloc_Free(alloc, p->Defs); p->Defs = NULL; ISzAlloc_Free(alloc, p->Defs); p->Defs = NULL;
IAlloc_Free(alloc, p->Vals); p->Vals = NULL; ISzAlloc_Free(alloc, p->Vals); p->Vals = NULL;
} }
#define SzBitUi64s_Init(p) { (p)->Defs = NULL; (p)->Vals = NULL; } #define SzBitUi64s_Init(p) { (p)->Defs = NULL; (p)->Vals = NULL; }
void SzBitUi64s_Free(CSzBitUi64s *p, ISzAlloc *alloc) void SzBitUi64s_Free(CSzBitUi64s *p, ISzAllocPtr alloc)
{ {
IAlloc_Free(alloc, p->Defs); p->Defs = NULL; ISzAlloc_Free(alloc, p->Defs); p->Defs = NULL;
IAlloc_Free(alloc, p->Vals); p->Vals = NULL; ISzAlloc_Free(alloc, p->Vals); p->Vals = NULL;
} }
@@ -107,18 +107,18 @@ static void SzAr_Init(CSzAr *p)
p->CodersData = NULL; p->CodersData = NULL;
} }
static void SzAr_Free(CSzAr *p, ISzAlloc *alloc) static void SzAr_Free(CSzAr *p, ISzAllocPtr alloc)
{ {
IAlloc_Free(alloc, p->PackPositions); ISzAlloc_Free(alloc, p->PackPositions);
SzBitUi32s_Free(&p->FolderCRCs, alloc); SzBitUi32s_Free(&p->FolderCRCs, alloc);
IAlloc_Free(alloc, p->FoCodersOffsets); ISzAlloc_Free(alloc, p->FoCodersOffsets);
IAlloc_Free(alloc, p->FoStartPackStreamIndex); ISzAlloc_Free(alloc, p->FoStartPackStreamIndex);
IAlloc_Free(alloc, p->FoToCoderUnpackSizes); ISzAlloc_Free(alloc, p->FoToCoderUnpackSizes);
IAlloc_Free(alloc, p->FoToMainUnpackSizeIndex); ISzAlloc_Free(alloc, p->FoToMainUnpackSizeIndex);
IAlloc_Free(alloc, p->CoderUnpackSizes); ISzAlloc_Free(alloc, p->CoderUnpackSizes);
IAlloc_Free(alloc, p->CodersData); ISzAlloc_Free(alloc, p->CodersData);
SzAr_Init(p); SzAr_Init(p);
} }
@@ -147,16 +147,16 @@ void SzArEx_Init(CSzArEx *p)
SzBitUi64s_Init(&p->CTime); SzBitUi64s_Init(&p->CTime);
} }
void SzArEx_Free(CSzArEx *p, ISzAlloc *alloc) void SzArEx_Free(CSzArEx *p, ISzAllocPtr alloc)
{ {
IAlloc_Free(alloc, p->UnpackPositions); ISzAlloc_Free(alloc, p->UnpackPositions);
IAlloc_Free(alloc, p->IsDirs); ISzAlloc_Free(alloc, p->IsDirs);
IAlloc_Free(alloc, p->FolderToFile); ISzAlloc_Free(alloc, p->FolderToFile);
IAlloc_Free(alloc, p->FileToFolder); ISzAlloc_Free(alloc, p->FileToFolder);
IAlloc_Free(alloc, p->FileNameOffsets); ISzAlloc_Free(alloc, p->FileNameOffsets);
IAlloc_Free(alloc, p->FileNames); ISzAlloc_Free(alloc, p->FileNames);
SzBitUi32s_Free(&p->CRCs, alloc); SzBitUi32s_Free(&p->CRCs, alloc);
SzBitUi32s_Free(&p->Attribs, alloc); SzBitUi32s_Free(&p->Attribs, alloc);
@@ -305,7 +305,7 @@ static UInt32 CountDefinedBits(const Byte *bits, UInt32 numItems)
return sum; return sum;
} }
static MY_NO_INLINE SRes ReadBitVector(CSzData *sd, UInt32 numItems, Byte **v, ISzAlloc *alloc) static MY_NO_INLINE SRes ReadBitVector(CSzData *sd, UInt32 numItems, Byte **v, ISzAllocPtr alloc)
{ {
Byte allAreDefined; Byte allAreDefined;
Byte *v2; Byte *v2;
@@ -328,12 +328,12 @@ static MY_NO_INLINE SRes ReadBitVector(CSzData *sd, UInt32 numItems, Byte **v, I
{ {
unsigned numBits = (unsigned)numItems & 7; unsigned numBits = (unsigned)numItems & 7;
if (numBits != 0) if (numBits != 0)
v2[numBytes - 1] = (Byte)((((UInt32)1 << numBits) - 1) << (8 - numBits)); v2[(size_t)numBytes - 1] = (Byte)((((UInt32)1 << numBits) - 1) << (8 - numBits));
} }
return SZ_OK; return SZ_OK;
} }
static MY_NO_INLINE SRes ReadUi32s(CSzData *sd2, UInt32 numItems, CSzBitUi32s *crcs, ISzAlloc *alloc) static MY_NO_INLINE SRes ReadUi32s(CSzData *sd2, UInt32 numItems, CSzBitUi32s *crcs, ISzAllocPtr alloc)
{ {
UInt32 i; UInt32 i;
CSzData sd; CSzData sd;
@@ -354,7 +354,7 @@ static MY_NO_INLINE SRes ReadUi32s(CSzData *sd2, UInt32 numItems, CSzBitUi32s *c
return SZ_OK; return SZ_OK;
} }
static SRes ReadBitUi32s(CSzData *sd, UInt32 numItems, CSzBitUi32s *crcs, ISzAlloc *alloc) static SRes ReadBitUi32s(CSzData *sd, UInt32 numItems, CSzBitUi32s *crcs, ISzAllocPtr alloc)
{ {
SzBitUi32s_Free(crcs, alloc); SzBitUi32s_Free(crcs, alloc);
RINOK(ReadBitVector(sd, numItems, &crcs->Defs, alloc)); RINOK(ReadBitVector(sd, numItems, &crcs->Defs, alloc));
@@ -380,7 +380,7 @@ static SRes SkipBitUi32s(CSzData *sd, UInt32 numItems)
return SZ_OK; return SZ_OK;
} }
static SRes ReadPackInfo(CSzAr *p, CSzData *sd, ISzAlloc *alloc) static SRes ReadPackInfo(CSzAr *p, CSzData *sd, ISzAllocPtr alloc)
{ {
RINOK(SzReadNumber32(sd, &p->NumPackStreams)); RINOK(SzReadNumber32(sd, &p->NumPackStreams));
@@ -635,7 +635,7 @@ static SRes ReadUnpackInfo(CSzAr *p,
CSzData *sd2, CSzData *sd2,
UInt32 numFoldersMax, UInt32 numFoldersMax,
const CBuf *tempBufs, UInt32 numTempBufs, const CBuf *tempBufs, UInt32 numTempBufs,
ISzAlloc *alloc) ISzAllocPtr alloc)
{ {
CSzData sd; CSzData sd;
@@ -934,7 +934,7 @@ static SRes SzReadStreamsInfo(CSzAr *p,
UInt32 numFoldersMax, const CBuf *tempBufs, UInt32 numTempBufs, UInt32 numFoldersMax, const CBuf *tempBufs, UInt32 numTempBufs,
UInt64 *dataOffset, UInt64 *dataOffset,
CSubStreamInfo *ssi, CSubStreamInfo *ssi,
ISzAlloc *alloc) ISzAllocPtr alloc)
{ {
UInt64 type; UInt64 type;
@@ -976,7 +976,7 @@ static SRes SzReadAndDecodePackedStreams(
UInt32 numFoldersMax, UInt32 numFoldersMax,
UInt64 baseOffset, UInt64 baseOffset,
CSzAr *p, CSzAr *p,
ISzAlloc *allocTemp) ISzAllocPtr allocTemp)
{ {
UInt64 dataStartPos; UInt64 dataStartPos;
UInt32 fo; UInt32 fo;
@@ -1043,7 +1043,7 @@ static SRes SzReadFileNames(const Byte *data, size_t size, UInt32 numFiles, size
static MY_NO_INLINE SRes ReadTime(CSzBitUi64s *p, UInt32 num, static MY_NO_INLINE SRes ReadTime(CSzBitUi64s *p, UInt32 num,
CSzData *sd2, CSzData *sd2,
const CBuf *tempBufs, UInt32 numTempBufs, const CBuf *tempBufs, UInt32 numTempBufs,
ISzAlloc *alloc) ISzAllocPtr alloc)
{ {
CSzData sd; CSzData sd;
UInt32 i; UInt32 i;
@@ -1096,8 +1096,8 @@ static SRes SzReadHeader2(
CSzData *sd, CSzData *sd,
ILookInStream *inStream, ILookInStream *inStream,
CBuf *tempBufs, UInt32 *numTempBufs, CBuf *tempBufs, UInt32 *numTempBufs,
ISzAlloc *allocMain, ISzAllocPtr allocMain,
ISzAlloc *allocTemp ISzAllocPtr allocTemp
) )
{ {
CSubStreamInfo ssi; CSubStreamInfo ssi;
@@ -1472,8 +1472,8 @@ static SRes SzReadHeader(
CSzArEx *p, CSzArEx *p,
CSzData *sd, CSzData *sd,
ILookInStream *inStream, ILookInStream *inStream,
ISzAlloc *allocMain, ISzAllocPtr allocMain,
ISzAlloc *allocTemp) ISzAllocPtr allocTemp)
{ {
UInt32 i; UInt32 i;
UInt32 numTempBufs = 0; UInt32 numTempBufs = 0;
@@ -1501,8 +1501,8 @@ static SRes SzReadHeader(
static SRes SzArEx_Open2( static SRes SzArEx_Open2(
CSzArEx *p, CSzArEx *p,
ILookInStream *inStream, ILookInStream *inStream,
ISzAlloc *allocMain, ISzAllocPtr allocMain,
ISzAlloc *allocTemp) ISzAllocPtr allocTemp)
{ {
Byte header[k7zStartHeaderSize]; Byte header[k7zStartHeaderSize];
Int64 startArcPos; Int64 startArcPos;
@@ -1513,7 +1513,7 @@ static SRes SzArEx_Open2(
SRes res; SRes res;
startArcPos = 0; startArcPos = 0;
RINOK(inStream->Seek(inStream, &startArcPos, SZ_SEEK_CUR)); RINOK(ILookInStream_Seek(inStream, &startArcPos, SZ_SEEK_CUR));
RINOK(LookInStream_Read2(inStream, header, k7zStartHeaderSize, SZ_ERROR_NO_ARCHIVE)); RINOK(LookInStream_Read2(inStream, header, k7zStartHeaderSize, SZ_ERROR_NO_ARCHIVE));
@@ -1542,7 +1542,7 @@ static SRes SzArEx_Open2(
{ {
Int64 pos = 0; Int64 pos = 0;
RINOK(inStream->Seek(inStream, &pos, SZ_SEEK_END)); RINOK(ILookInStream_Seek(inStream, &pos, SZ_SEEK_END));
if ((UInt64)pos < startArcPos + nextHeaderOffset || if ((UInt64)pos < startArcPos + nextHeaderOffset ||
(UInt64)pos < startArcPos + k7zStartHeaderSize + nextHeaderOffset || (UInt64)pos < startArcPos + k7zStartHeaderSize + nextHeaderOffset ||
(UInt64)pos < startArcPos + k7zStartHeaderSize + nextHeaderOffset + nextHeaderSize) (UInt64)pos < startArcPos + k7zStartHeaderSize + nextHeaderOffset + nextHeaderSize)
@@ -1623,7 +1623,7 @@ static SRes SzArEx_Open2(
SRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream, SRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream,
ISzAlloc *allocMain, ISzAlloc *allocTemp) ISzAllocPtr allocMain, ISzAllocPtr allocTemp)
{ {
SRes res = SzArEx_Open2(p, inStream, allocMain, allocTemp); SRes res = SzArEx_Open2(p, inStream, allocMain, allocTemp);
if (res != SZ_OK) if (res != SZ_OK)
@@ -1641,8 +1641,8 @@ SRes SzArEx_Extract(
size_t *outBufferSize, size_t *outBufferSize,
size_t *offset, size_t *offset,
size_t *outSizeProcessed, size_t *outSizeProcessed,
ISzAlloc *allocMain, ISzAllocPtr allocMain,
ISzAlloc *allocTemp) ISzAllocPtr allocTemp)
{ {
UInt32 folderIndex = p->FileToFolder[fileIndex]; UInt32 folderIndex = p->FileToFolder[fileIndex];
SRes res = SZ_OK; SRes res = SZ_OK;
@@ -1652,7 +1652,7 @@ SRes SzArEx_Extract(
if (folderIndex == (UInt32)-1) if (folderIndex == (UInt32)-1)
{ {
IAlloc_Free(allocMain, *tempBuf); ISzAlloc_Free(allocMain, *tempBuf);
*blockIndex = folderIndex; *blockIndex = folderIndex;
*tempBuf = NULL; *tempBuf = NULL;
*outBufferSize = 0; *outBufferSize = 0;
@@ -1664,7 +1664,7 @@ SRes SzArEx_Extract(
UInt64 unpackSizeSpec = SzAr_GetFolderUnpackSize(&p->db, folderIndex); UInt64 unpackSizeSpec = SzAr_GetFolderUnpackSize(&p->db, folderIndex);
/* /*
UInt64 unpackSizeSpec = UInt64 unpackSizeSpec =
p->UnpackPositions[p->FolderToFile[folderIndex + 1]] - p->UnpackPositions[p->FolderToFile[(size_t)folderIndex + 1]] -
p->UnpackPositions[p->FolderToFile[folderIndex]]; p->UnpackPositions[p->FolderToFile[folderIndex]];
*/ */
size_t unpackSize = (size_t)unpackSizeSpec; size_t unpackSize = (size_t)unpackSizeSpec;
@@ -1672,7 +1672,7 @@ SRes SzArEx_Extract(
if (unpackSize != unpackSizeSpec) if (unpackSize != unpackSizeSpec)
return SZ_ERROR_MEM; return SZ_ERROR_MEM;
*blockIndex = folderIndex; *blockIndex = folderIndex;
IAlloc_Free(allocMain, *tempBuf); ISzAlloc_Free(allocMain, *tempBuf);
*tempBuf = NULL; *tempBuf = NULL;
if (res == SZ_OK) if (res == SZ_OK)
@@ -1680,7 +1680,7 @@ SRes SzArEx_Extract(
*outBufferSize = unpackSize; *outBufferSize = unpackSize;
if (unpackSize != 0) if (unpackSize != 0)
{ {
*tempBuf = (Byte *)IAlloc_Alloc(allocMain, unpackSize); *tempBuf = (Byte *)ISzAlloc_Alloc(allocMain, unpackSize);
if (*tempBuf == NULL) if (*tempBuf == NULL)
res = SZ_ERROR_MEM; res = SZ_ERROR_MEM;
} }
@@ -1697,7 +1697,7 @@ SRes SzArEx_Extract(
{ {
UInt64 unpackPos = p->UnpackPositions[fileIndex]; UInt64 unpackPos = p->UnpackPositions[fileIndex];
*offset = (size_t)(unpackPos - p->UnpackPositions[p->FolderToFile[folderIndex]]); *offset = (size_t)(unpackPos - p->UnpackPositions[p->FolderToFile[folderIndex]]);
*outSizeProcessed = (size_t)(p->UnpackPositions[fileIndex + 1] - unpackPos); *outSizeProcessed = (size_t)(p->UnpackPositions[(size_t)fileIndex + 1] - unpackPos);
if (*offset + *outSizeProcessed > *outBufferSize) if (*offset + *outSizeProcessed > *outBufferSize)
return SZ_ERROR_FAIL; return SZ_ERROR_FAIL;
if (SzBitWithVals_Check(&p->CRCs, fileIndex)) if (SzBitWithVals_Check(&p->CRCs, fileIndex))

View File

@@ -1,5 +1,5 @@
/* 7zBuf.c -- Byte Buffer /* 7zBuf.c -- Byte Buffer
2013-01-21 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@@ -11,7 +11,7 @@ void Buf_Init(CBuf *p)
p->size = 0; p->size = 0;
} }
int Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc) int Buf_Create(CBuf *p, size_t size, ISzAllocPtr alloc)
{ {
p->size = 0; p->size = 0;
if (size == 0) if (size == 0)
@@ -19,8 +19,8 @@ int Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc)
p->data = 0; p->data = 0;
return 1; return 1;
} }
p->data = (Byte *)alloc->Alloc(alloc, size); p->data = (Byte *)ISzAlloc_Alloc(alloc, size);
if (p->data != 0) if (p->data)
{ {
p->size = size; p->size = size;
return 1; return 1;
@@ -28,9 +28,9 @@ int Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc)
return 0; return 0;
} }
void Buf_Free(CBuf *p, ISzAlloc *alloc) void Buf_Free(CBuf *p, ISzAllocPtr alloc)
{ {
alloc->Free(alloc, p->data); ISzAlloc_Free(alloc, p->data);
p->data = 0; p->data = 0;
p->size = 0; p->size = 0;
} }

View File

@@ -1,5 +1,5 @@
/* 7zBuf.h -- Byte Buffer /* 7zBuf.h -- Byte Buffer
2013-01-18 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#ifndef __7Z_BUF_H #ifndef __7Z_BUF_H
#define __7Z_BUF_H #define __7Z_BUF_H
@@ -15,8 +15,8 @@ typedef struct
} CBuf; } CBuf;
void Buf_Init(CBuf *p); void Buf_Init(CBuf *p);
int Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc); int Buf_Create(CBuf *p, size_t size, ISzAllocPtr alloc);
void Buf_Free(CBuf *p, ISzAlloc *alloc); void Buf_Free(CBuf *p, ISzAllocPtr alloc);
typedef struct typedef struct
{ {
@@ -27,8 +27,8 @@ typedef struct
void DynBuf_Construct(CDynBuf *p); void DynBuf_Construct(CDynBuf *p);
void DynBuf_SeekToBeg(CDynBuf *p); void DynBuf_SeekToBeg(CDynBuf *p);
int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc); int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAllocPtr alloc);
void DynBuf_Free(CDynBuf *p, ISzAlloc *alloc); void DynBuf_Free(CDynBuf *p, ISzAllocPtr alloc);
EXTERN_C_END EXTERN_C_END

View File

@@ -1,5 +1,5 @@
/* 7zBuf2.c -- Byte Buffer /* 7zBuf2.c -- Byte Buffer
2014-08-22 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@@ -19,19 +19,20 @@ void DynBuf_SeekToBeg(CDynBuf *p)
p->pos = 0; p->pos = 0;
} }
int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc) int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAllocPtr alloc)
{ {
if (size > p->size - p->pos) if (size > p->size - p->pos)
{ {
size_t newSize = p->pos + size; size_t newSize = p->pos + size;
Byte *data; Byte *data;
newSize += newSize / 4; newSize += newSize / 4;
data = (Byte *)alloc->Alloc(alloc, newSize); data = (Byte *)ISzAlloc_Alloc(alloc, newSize);
if (data == 0) if (!data)
return 0; return 0;
p->size = newSize; p->size = newSize;
memcpy(data, p->data, p->pos); if (p->pos != 0)
alloc->Free(alloc, p->data); memcpy(data, p->data, p->pos);
ISzAlloc_Free(alloc, p->data);
p->data = data; p->data = data;
} }
if (size != 0) if (size != 0)
@@ -42,9 +43,9 @@ int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc)
return 1; return 1;
} }
void DynBuf_Free(CDynBuf *p, ISzAlloc *alloc) void DynBuf_Free(CDynBuf *p, ISzAllocPtr alloc)
{ {
alloc->Free(alloc, p->data); ISzAlloc_Free(alloc, p->data);
p->data = 0; p->data = 0;
p->size = 0; p->size = 0;
p->pos = 0; p->pos = 0;

View File

@@ -1,5 +1,5 @@
/* 7zCrc.c -- CRC32 init /* 7zCrc.c -- CRC32 init
2015-03-10 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@@ -61,12 +61,12 @@ void MY_FAST_CALL CrcGenerateTable()
UInt32 r = i; UInt32 r = i;
unsigned j; unsigned j;
for (j = 0; j < 8; j++) for (j = 0; j < 8; j++)
r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1)); r = (r >> 1) ^ (kCrcPoly & ((UInt32)0 - (r & 1)));
g_CrcTable[i] = r; g_CrcTable[i] = r;
} }
for (; i < 256 * CRC_NUM_TABLES; i++) for (i = 256; i < 256 * CRC_NUM_TABLES; i++)
{ {
UInt32 r = g_CrcTable[i - 256]; UInt32 r = g_CrcTable[(size_t)i - 256];
g_CrcTable[i] = g_CrcTable[r & 0xFF] ^ (r >> 8); g_CrcTable[i] = g_CrcTable[r & 0xFF] ^ (r >> 8);
} }
@@ -111,7 +111,7 @@ void MY_FAST_CALL CrcGenerateTable()
{ {
for (i = 256 * CRC_NUM_TABLES - 1; i >= 256; i--) for (i = 256 * CRC_NUM_TABLES - 1; i >= 256; i--)
{ {
UInt32 x = g_CrcTable[i - 256]; UInt32 x = g_CrcTable[(size_t)i - 256];
g_CrcTable[i] = CRC_UINT32_SWAP(x); g_CrcTable[i] = CRC_UINT32_SWAP(x);
} }
g_CrcUpdateT4 = CrcUpdateT1_BeT4; g_CrcUpdateT4 = CrcUpdateT1_BeT4;

View File

@@ -1,5 +1,5 @@
/* 7zCrcOpt.c -- CRC32 calculation /* 7zCrcOpt.c -- CRC32 calculation
2015-03-01 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@@ -18,10 +18,10 @@ UInt32 MY_FAST_CALL CrcUpdateT4(UInt32 v, const void *data, size_t size, const U
{ {
v ^= *(const UInt32 *)p; v ^= *(const UInt32 *)p;
v = v =
table[0x300 + ((v ) & 0xFF)] (table + 0x300)[((v ) & 0xFF)]
^ table[0x200 + ((v >> 8) & 0xFF)] ^ (table + 0x200)[((v >> 8) & 0xFF)]
^ table[0x100 + ((v >> 16) & 0xFF)] ^ (table + 0x100)[((v >> 16) & 0xFF)]
^ table[0x000 + ((v >> 24))]; ^ (table + 0x000)[((v >> 24))];
} }
for (; size > 0; size--, p++) for (; size > 0; size--, p++)
v = CRC_UPDATE_BYTE_2(v, *p); v = CRC_UPDATE_BYTE_2(v, *p);
@@ -38,16 +38,16 @@ UInt32 MY_FAST_CALL CrcUpdateT8(UInt32 v, const void *data, size_t size, const U
UInt32 d; UInt32 d;
v ^= *(const UInt32 *)p; v ^= *(const UInt32 *)p;
v = v =
table[0x700 + ((v ) & 0xFF)] (table + 0x700)[((v ) & 0xFF)]
^ table[0x600 + ((v >> 8) & 0xFF)] ^ (table + 0x600)[((v >> 8) & 0xFF)]
^ table[0x500 + ((v >> 16) & 0xFF)] ^ (table + 0x500)[((v >> 16) & 0xFF)]
^ table[0x400 + ((v >> 24))]; ^ (table + 0x400)[((v >> 24))];
d = *((const UInt32 *)p + 1); d = *((const UInt32 *)p + 1);
v ^= v ^=
table[0x300 + ((d ) & 0xFF)] (table + 0x300)[((d ) & 0xFF)]
^ table[0x200 + ((d >> 8) & 0xFF)] ^ (table + 0x200)[((d >> 8) & 0xFF)]
^ table[0x100 + ((d >> 16) & 0xFF)] ^ (table + 0x100)[((d >> 16) & 0xFF)]
^ table[0x000 + ((d >> 24))]; ^ (table + 0x000)[((d >> 24))];
} }
for (; size > 0; size--, p++) for (; size > 0; size--, p++)
v = CRC_UPDATE_BYTE_2(v, *p); v = CRC_UPDATE_BYTE_2(v, *p);
@@ -74,10 +74,10 @@ UInt32 MY_FAST_CALL CrcUpdateT1_BeT4(UInt32 v, const void *data, size_t size, co
{ {
v ^= *(const UInt32 *)p; v ^= *(const UInt32 *)p;
v = v =
table[0x000 + ((v ) & 0xFF)] (table + 0x000)[((v ) & 0xFF)]
^ table[0x100 + ((v >> 8) & 0xFF)] ^ (table + 0x100)[((v >> 8) & 0xFF)]
^ table[0x200 + ((v >> 16) & 0xFF)] ^ (table + 0x200)[((v >> 16) & 0xFF)]
^ table[0x300 + ((v >> 24))]; ^ (table + 0x300)[((v >> 24))];
} }
for (; size > 0; size--, p++) for (; size > 0; size--, p++)
v = CRC_UPDATE_BYTE_2_BE(v, *p); v = CRC_UPDATE_BYTE_2_BE(v, *p);
@@ -96,16 +96,16 @@ UInt32 MY_FAST_CALL CrcUpdateT1_BeT8(UInt32 v, const void *data, size_t size, co
UInt32 d; UInt32 d;
v ^= *(const UInt32 *)p; v ^= *(const UInt32 *)p;
v = v =
table[0x400 + ((v ) & 0xFF)] (table + 0x400)[((v ) & 0xFF)]
^ table[0x500 + ((v >> 8) & 0xFF)] ^ (table + 0x500)[((v >> 8) & 0xFF)]
^ table[0x600 + ((v >> 16) & 0xFF)] ^ (table + 0x600)[((v >> 16) & 0xFF)]
^ table[0x700 + ((v >> 24))]; ^ (table + 0x700)[((v >> 24))];
d = *((const UInt32 *)p + 1); d = *((const UInt32 *)p + 1);
v ^= v ^=
table[0x000 + ((d ) & 0xFF)] (table + 0x000)[((d ) & 0xFF)]
^ table[0x100 + ((d >> 8) & 0xFF)] ^ (table + 0x100)[((d >> 8) & 0xFF)]
^ table[0x200 + ((d >> 16) & 0xFF)] ^ (table + 0x200)[((d >> 16) & 0xFF)]
^ table[0x300 + ((d >> 24))]; ^ (table + 0x300)[((d >> 24))];
} }
for (; size > 0; size--, p++) for (; size > 0; size--, p++)
v = CRC_UPDATE_BYTE_2_BE(v, *p); v = CRC_UPDATE_BYTE_2_BE(v, *p);

View File

@@ -1,5 +1,5 @@
/* 7zDec.c -- Decoding from 7z folder /* 7zDec.c -- Decoding from 7z folder
2015-11-18 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@@ -39,28 +39,28 @@
typedef struct typedef struct
{ {
IByteIn p; IByteIn vt;
const Byte *cur; const Byte *cur;
const Byte *end; const Byte *end;
const Byte *begin; const Byte *begin;
UInt64 processed; UInt64 processed;
Bool extra; Bool extra;
SRes res; SRes res;
ILookInStream *inStream; const ILookInStream *inStream;
} CByteInToLook; } CByteInToLook;
static Byte ReadByte(void *pp) static Byte ReadByte(const IByteIn *pp)
{ {
CByteInToLook *p = (CByteInToLook *)pp; CByteInToLook *p = CONTAINER_FROM_VTBL(pp, CByteInToLook, vt);
if (p->cur != p->end) if (p->cur != p->end)
return *p->cur++; return *p->cur++;
if (p->res == SZ_OK) if (p->res == SZ_OK)
{ {
size_t size = p->cur - p->begin; size_t size = p->cur - p->begin;
p->processed += size; p->processed += size;
p->res = p->inStream->Skip(p->inStream, size); p->res = ILookInStream_Skip(p->inStream, size);
size = (1 << 25); size = (1 << 25);
p->res = p->inStream->Look(p->inStream, (const void **)&p->begin, &size); p->res = ILookInStream_Look(p->inStream, (const void **)&p->begin, &size);
p->cur = p->begin; p->cur = p->begin;
p->end = p->begin + size; p->end = p->begin + size;
if (size != 0) if (size != 0)
@@ -70,14 +70,14 @@ static Byte ReadByte(void *pp)
return 0; return 0;
} }
static SRes SzDecodePpmd(const Byte *props, unsigned propsSize, UInt64 inSize, ILookInStream *inStream, static SRes SzDecodePpmd(const Byte *props, unsigned propsSize, UInt64 inSize, const ILookInStream *inStream,
Byte *outBuffer, SizeT outSize, ISzAlloc *allocMain) Byte *outBuffer, SizeT outSize, ISzAllocPtr allocMain)
{ {
CPpmd7 ppmd; CPpmd7 ppmd;
CByteInToLook s; CByteInToLook s;
SRes res = SZ_OK; SRes res = SZ_OK;
s.p.Read = ReadByte; s.vt.Read = ReadByte;
s.inStream = inStream; s.inStream = inStream;
s.begin = s.end = s.cur = NULL; s.begin = s.end = s.cur = NULL;
s.extra = False; s.extra = False;
@@ -103,7 +103,7 @@ static SRes SzDecodePpmd(const Byte *props, unsigned propsSize, UInt64 inSize, I
{ {
CPpmd7z_RangeDec rc; CPpmd7z_RangeDec rc;
Ppmd7z_RangeDec_CreateVTable(&rc); Ppmd7z_RangeDec_CreateVTable(&rc);
rc.Stream = &s.p; rc.Stream = &s.vt;
if (!Ppmd7z_RangeDec_Init(&rc)) if (!Ppmd7z_RangeDec_Init(&rc))
res = SZ_ERROR_DATA; res = SZ_ERROR_DATA;
else if (s.extra) else if (s.extra)
@@ -113,7 +113,7 @@ static SRes SzDecodePpmd(const Byte *props, unsigned propsSize, UInt64 inSize, I
SizeT i; SizeT i;
for (i = 0; i < outSize; i++) for (i = 0; i < outSize; i++)
{ {
int sym = Ppmd7_DecodeSymbol(&ppmd, &rc.p); int sym = Ppmd7_DecodeSymbol(&ppmd, &rc.vt);
if (s.extra || sym < 0) if (s.extra || sym < 0)
break; break;
outBuffer[i] = (Byte)sym; outBuffer[i] = (Byte)sym;
@@ -132,7 +132,7 @@ static SRes SzDecodePpmd(const Byte *props, unsigned propsSize, UInt64 inSize, I
static SRes SzDecodeLzma(const Byte *props, unsigned propsSize, UInt64 inSize, ILookInStream *inStream, static SRes SzDecodeLzma(const Byte *props, unsigned propsSize, UInt64 inSize, ILookInStream *inStream,
Byte *outBuffer, SizeT outSize, ISzAlloc *allocMain) Byte *outBuffer, SizeT outSize, ISzAllocPtr allocMain)
{ {
CLzmaDec state; CLzmaDec state;
SRes res = SZ_OK; SRes res = SZ_OK;
@@ -149,7 +149,7 @@ static SRes SzDecodeLzma(const Byte *props, unsigned propsSize, UInt64 inSize, I
size_t lookahead = (1 << 18); size_t lookahead = (1 << 18);
if (lookahead > inSize) if (lookahead > inSize)
lookahead = (size_t)inSize; lookahead = (size_t)inSize;
res = inStream->Look(inStream, &inBuf, &lookahead); res = ILookInStream_Look(inStream, &inBuf, &lookahead);
if (res != SZ_OK) if (res != SZ_OK)
break; break;
@@ -178,7 +178,7 @@ static SRes SzDecodeLzma(const Byte *props, unsigned propsSize, UInt64 inSize, I
break; break;
} }
res = inStream->Skip((void *)inStream, inProcessed); res = ILookInStream_Skip(inStream, inProcessed);
if (res != SZ_OK) if (res != SZ_OK)
break; break;
} }
@@ -192,7 +192,7 @@ static SRes SzDecodeLzma(const Byte *props, unsigned propsSize, UInt64 inSize, I
#ifndef _7Z_NO_METHOD_LZMA2 #ifndef _7Z_NO_METHOD_LZMA2
static SRes SzDecodeLzma2(const Byte *props, unsigned propsSize, UInt64 inSize, ILookInStream *inStream, static SRes SzDecodeLzma2(const Byte *props, unsigned propsSize, UInt64 inSize, ILookInStream *inStream,
Byte *outBuffer, SizeT outSize, ISzAlloc *allocMain) Byte *outBuffer, SizeT outSize, ISzAllocPtr allocMain)
{ {
CLzma2Dec state; CLzma2Dec state;
SRes res = SZ_OK; SRes res = SZ_OK;
@@ -211,7 +211,7 @@ static SRes SzDecodeLzma2(const Byte *props, unsigned propsSize, UInt64 inSize,
size_t lookahead = (1 << 18); size_t lookahead = (1 << 18);
if (lookahead > inSize) if (lookahead > inSize)
lookahead = (size_t)inSize; lookahead = (size_t)inSize;
res = inStream->Look(inStream, &inBuf, &lookahead); res = ILookInStream_Look(inStream, &inBuf, &lookahead);
if (res != SZ_OK) if (res != SZ_OK)
break; break;
@@ -237,7 +237,7 @@ static SRes SzDecodeLzma2(const Byte *props, unsigned propsSize, UInt64 inSize,
break; break;
} }
res = inStream->Skip((void *)inStream, inProcessed); res = ILookInStream_Skip(inStream, inProcessed);
if (res != SZ_OK) if (res != SZ_OK)
break; break;
} }
@@ -258,13 +258,13 @@ static SRes SzDecodeCopy(UInt64 inSize, ILookInStream *inStream, Byte *outBuffer
size_t curSize = (1 << 18); size_t curSize = (1 << 18);
if (curSize > inSize) if (curSize > inSize)
curSize = (size_t)inSize; curSize = (size_t)inSize;
RINOK(inStream->Look(inStream, &inBuf, &curSize)); RINOK(ILookInStream_Look(inStream, &inBuf, &curSize));
if (curSize == 0) if (curSize == 0)
return SZ_ERROR_INPUT_EOF; return SZ_ERROR_INPUT_EOF;
memcpy(outBuffer, inBuf, curSize); memcpy(outBuffer, inBuf, curSize);
outBuffer += curSize; outBuffer += curSize;
inSize -= curSize; inSize -= curSize;
RINOK(inStream->Skip((void *)inStream, curSize)); RINOK(ILookInStream_Skip(inStream, curSize));
} }
return SZ_OK; return SZ_OK;
} }
@@ -372,7 +372,7 @@ static SRes SzFolder_Decode2(const CSzFolder *folder,
const UInt64 *unpackSizes, const UInt64 *unpackSizes,
const UInt64 *packPositions, const UInt64 *packPositions,
ILookInStream *inStream, UInt64 startPos, ILookInStream *inStream, UInt64 startPos,
Byte *outBuffer, SizeT outSize, ISzAlloc *allocMain, Byte *outBuffer, SizeT outSize, ISzAllocPtr allocMain,
Byte *tempBuf[]) Byte *tempBuf[])
{ {
UInt32 ci; UInt32 ci;
@@ -404,7 +404,7 @@ static SRes SzFolder_Decode2(const CSzFolder *folder,
outSizeCur = (SizeT)unpackSize; outSizeCur = (SizeT)unpackSize;
if (outSizeCur != unpackSize) if (outSizeCur != unpackSize)
return SZ_ERROR_MEM; return SZ_ERROR_MEM;
temp = (Byte *)IAlloc_Alloc(allocMain, outSizeCur); temp = (Byte *)ISzAlloc_Alloc(allocMain, outSizeCur);
if (!temp && outSizeCur != 0) if (!temp && outSizeCur != 0)
return SZ_ERROR_MEM; return SZ_ERROR_MEM;
outBufCur = tempBuf[1 - ci] = temp; outBufCur = tempBuf[1 - ci] = temp;
@@ -421,7 +421,7 @@ static SRes SzFolder_Decode2(const CSzFolder *folder,
return SZ_ERROR_UNSUPPORTED; return SZ_ERROR_UNSUPPORTED;
} }
offset = packPositions[si]; offset = packPositions[si];
inSize = packPositions[si + 1] - offset; inSize = packPositions[(size_t)si + 1] - offset;
RINOK(LookInStream_SeekTo(inStream, startPos + offset)); RINOK(LookInStream_SeekTo(inStream, startPos + offset));
if (coder->MethodID == k_Copy) if (coder->MethodID == k_Copy)
@@ -460,7 +460,7 @@ static SRes SzFolder_Decode2(const CSzFolder *folder,
tempSizes[2] = (SizeT)s3Size; tempSizes[2] = (SizeT)s3Size;
if (tempSizes[2] != s3Size) if (tempSizes[2] != s3Size)
return SZ_ERROR_MEM; return SZ_ERROR_MEM;
tempBuf[2] = (Byte *)IAlloc_Alloc(allocMain, tempSizes[2]); tempBuf[2] = (Byte *)ISzAlloc_Alloc(allocMain, tempSizes[2]);
if (!tempBuf[2] && tempSizes[2] != 0) if (!tempBuf[2] && tempSizes[2] != 0)
return SZ_ERROR_MEM; return SZ_ERROR_MEM;
@@ -549,7 +549,7 @@ static SRes SzFolder_Decode2(const CSzFolder *folder,
SRes SzAr_DecodeFolder(const CSzAr *p, UInt32 folderIndex, SRes SzAr_DecodeFolder(const CSzAr *p, UInt32 folderIndex,
ILookInStream *inStream, UInt64 startPos, ILookInStream *inStream, UInt64 startPos,
Byte *outBuffer, size_t outSize, Byte *outBuffer, size_t outSize,
ISzAlloc *allocMain) ISzAllocPtr allocMain)
{ {
SRes res; SRes res;
CSzFolder folder; CSzFolder folder;
@@ -557,7 +557,7 @@ SRes SzAr_DecodeFolder(const CSzAr *p, UInt32 folderIndex,
const Byte *data = p->CodersData + p->FoCodersOffsets[folderIndex]; const Byte *data = p->CodersData + p->FoCodersOffsets[folderIndex];
sd.Data = data; sd.Data = data;
sd.Size = p->FoCodersOffsets[folderIndex + 1] - p->FoCodersOffsets[folderIndex]; sd.Size = p->FoCodersOffsets[(size_t)folderIndex + 1] - p->FoCodersOffsets[folderIndex];
res = SzGetNextFolderItem(&folder, &sd); res = SzGetNextFolderItem(&folder, &sd);
@@ -579,7 +579,7 @@ SRes SzAr_DecodeFolder(const CSzAr *p, UInt32 folderIndex,
outBuffer, (SizeT)outSize, allocMain, tempBuf); outBuffer, (SizeT)outSize, allocMain, tempBuf);
for (i = 0; i < 3; i++) for (i = 0; i < 3; i++)
IAlloc_Free(allocMain, tempBuf[i]); ISzAlloc_Free(allocMain, tempBuf[i]);
if (res == SZ_OK) if (res == SZ_OK)
if (SzBitWithVals_Check(&p->FolderCRCs, folderIndex)) if (SzBitWithVals_Check(&p->FolderCRCs, folderIndex))

View File

@@ -1,5 +1,5 @@
/* 7zFile.c -- File IO /* 7zFile.c -- File IO
2009-11-24 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@@ -238,49 +238,49 @@ WRes File_GetLength(CSzFile *p, UInt64 *length)
/* ---------- FileSeqInStream ---------- */ /* ---------- FileSeqInStream ---------- */
static SRes FileSeqInStream_Read(void *pp, void *buf, size_t *size) static SRes FileSeqInStream_Read(const ISeqInStream *pp, void *buf, size_t *size)
{ {
CFileSeqInStream *p = (CFileSeqInStream *)pp; CFileSeqInStream *p = CONTAINER_FROM_VTBL(pp, CFileSeqInStream, vt);
return File_Read(&p->file, buf, size) == 0 ? SZ_OK : SZ_ERROR_READ; return File_Read(&p->file, buf, size) == 0 ? SZ_OK : SZ_ERROR_READ;
} }
void FileSeqInStream_CreateVTable(CFileSeqInStream *p) void FileSeqInStream_CreateVTable(CFileSeqInStream *p)
{ {
p->s.Read = FileSeqInStream_Read; p->vt.Read = FileSeqInStream_Read;
} }
/* ---------- FileInStream ---------- */ /* ---------- FileInStream ---------- */
static SRes FileInStream_Read(void *pp, void *buf, size_t *size) static SRes FileInStream_Read(const ISeekInStream *pp, void *buf, size_t *size)
{ {
CFileInStream *p = (CFileInStream *)pp; CFileInStream *p = CONTAINER_FROM_VTBL(pp, CFileInStream, vt);
return (File_Read(&p->file, buf, size) == 0) ? SZ_OK : SZ_ERROR_READ; return (File_Read(&p->file, buf, size) == 0) ? SZ_OK : SZ_ERROR_READ;
} }
static SRes FileInStream_Seek(void *pp, Int64 *pos, ESzSeek origin) static SRes FileInStream_Seek(const ISeekInStream *pp, Int64 *pos, ESzSeek origin)
{ {
CFileInStream *p = (CFileInStream *)pp; CFileInStream *p = CONTAINER_FROM_VTBL(pp, CFileInStream, vt);
return File_Seek(&p->file, pos, origin); return File_Seek(&p->file, pos, origin);
} }
void FileInStream_CreateVTable(CFileInStream *p) void FileInStream_CreateVTable(CFileInStream *p)
{ {
p->s.Read = FileInStream_Read; p->vt.Read = FileInStream_Read;
p->s.Seek = FileInStream_Seek; p->vt.Seek = FileInStream_Seek;
} }
/* ---------- FileOutStream ---------- */ /* ---------- FileOutStream ---------- */
static size_t FileOutStream_Write(void *pp, const void *data, size_t size) static size_t FileOutStream_Write(const ISeqOutStream *pp, const void *data, size_t size)
{ {
CFileOutStream *p = (CFileOutStream *)pp; CFileOutStream *p = CONTAINER_FROM_VTBL(pp, CFileOutStream, vt);
File_Write(&p->file, data, &size); File_Write(&p->file, data, &size);
return size; return size;
} }
void FileOutStream_CreateVTable(CFileOutStream *p) void FileOutStream_CreateVTable(CFileOutStream *p)
{ {
p->s.Write = FileOutStream_Write; p->vt.Write = FileOutStream_Write;
} }

View File

@@ -1,5 +1,5 @@
/* 7zFile.h -- File IO /* 7zFile.h -- File IO
2013-01-18 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#ifndef __7Z_FILE_H #ifndef __7Z_FILE_H
#define __7Z_FILE_H #define __7Z_FILE_H
@@ -54,7 +54,7 @@ WRes File_GetLength(CSzFile *p, UInt64 *length);
typedef struct typedef struct
{ {
ISeqInStream s; ISeqInStream vt;
CSzFile file; CSzFile file;
} CFileSeqInStream; } CFileSeqInStream;
@@ -63,7 +63,7 @@ void FileSeqInStream_CreateVTable(CFileSeqInStream *p);
typedef struct typedef struct
{ {
ISeekInStream s; ISeekInStream vt;
CSzFile file; CSzFile file;
} CFileInStream; } CFileInStream;
@@ -72,7 +72,7 @@ void FileInStream_CreateVTable(CFileInStream *p);
typedef struct typedef struct
{ {
ISeqOutStream s; ISeqOutStream vt;
CSzFile file; CSzFile file;
} CFileOutStream; } CFileOutStream;

View File

@@ -1,5 +1,5 @@
/* 7zStream.c -- 7z Stream functions /* 7zStream.c -- 7z Stream functions
2013-11-12 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@@ -7,12 +7,12 @@
#include "7zTypes.h" #include "7zTypes.h"
SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType) SRes SeqInStream_Read2(const ISeqInStream *stream, void *buf, size_t size, SRes errorType)
{ {
while (size != 0) while (size != 0)
{ {
size_t processed = size; size_t processed = size;
RINOK(stream->Read(stream, buf, &processed)); RINOK(ISeqInStream_Read(stream, buf, &processed));
if (processed == 0) if (processed == 0)
return errorType; return errorType;
buf = (void *)((Byte *)buf + processed); buf = (void *)((Byte *)buf + processed);
@@ -21,40 +21,42 @@ SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorT
return SZ_OK; return SZ_OK;
} }
SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size) SRes SeqInStream_Read(const ISeqInStream *stream, void *buf, size_t size)
{ {
return SeqInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF); return SeqInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);
} }
SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf) SRes SeqInStream_ReadByte(const ISeqInStream *stream, Byte *buf)
{ {
size_t processed = 1; size_t processed = 1;
RINOK(stream->Read(stream, buf, &processed)); RINOK(ISeqInStream_Read(stream, buf, &processed));
return (processed == 1) ? SZ_OK : SZ_ERROR_INPUT_EOF; return (processed == 1) ? SZ_OK : SZ_ERROR_INPUT_EOF;
} }
SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset)
SRes LookInStream_SeekTo(const ILookInStream *stream, UInt64 offset)
{ {
Int64 t = offset; Int64 t = offset;
return stream->Seek(stream, &t, SZ_SEEK_SET); return ILookInStream_Seek(stream, &t, SZ_SEEK_SET);
} }
SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size) SRes LookInStream_LookRead(const ILookInStream *stream, void *buf, size_t *size)
{ {
const void *lookBuf; const void *lookBuf;
if (*size == 0) if (*size == 0)
return SZ_OK; return SZ_OK;
RINOK(stream->Look(stream, &lookBuf, size)); RINOK(ILookInStream_Look(stream, &lookBuf, size));
memcpy(buf, lookBuf, *size); memcpy(buf, lookBuf, *size);
return stream->Skip(stream, *size); return ILookInStream_Skip(stream, *size);
} }
SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType) SRes LookInStream_Read2(const ILookInStream *stream, void *buf, size_t size, SRes errorType)
{ {
while (size != 0) while (size != 0)
{ {
size_t processed = size; size_t processed = size;
RINOK(stream->Read(stream, buf, &processed)); RINOK(ILookInStream_Read(stream, buf, &processed));
if (processed == 0) if (processed == 0)
return errorType; return errorType;
buf = (void *)((Byte *)buf + processed); buf = (void *)((Byte *)buf + processed);
@@ -63,61 +65,67 @@ SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes erro
return SZ_OK; return SZ_OK;
} }
SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size) SRes LookInStream_Read(const ILookInStream *stream, void *buf, size_t size)
{ {
return LookInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF); return LookInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);
} }
static SRes LookToRead_Look_Lookahead(void *pp, const void **buf, size_t *size)
#define GET_LookToRead2 CLookToRead2 *p = CONTAINER_FROM_VTBL(pp, CLookToRead2, vt);
static SRes LookToRead2_Look_Lookahead(const ILookInStream *pp, const void **buf, size_t *size)
{ {
SRes res = SZ_OK; SRes res = SZ_OK;
CLookToRead *p = (CLookToRead *)pp; GET_LookToRead2
size_t size2 = p->size - p->pos; size_t size2 = p->size - p->pos;
if (size2 == 0 && *size > 0) if (size2 == 0 && *size != 0)
{ {
p->pos = 0; p->pos = 0;
size2 = LookToRead_BUF_SIZE; p->size = 0;
res = p->realStream->Read(p->realStream, p->buf, &size2); size2 = p->bufSize;
res = ISeekInStream_Read(p->realStream, p->buf, &size2);
p->size = size2; p->size = size2;
} }
if (size2 < *size) if (*size > size2)
*size = size2; *size = size2;
*buf = p->buf + p->pos; *buf = p->buf + p->pos;
return res; return res;
} }
static SRes LookToRead_Look_Exact(void *pp, const void **buf, size_t *size) static SRes LookToRead2_Look_Exact(const ILookInStream *pp, const void **buf, size_t *size)
{ {
SRes res = SZ_OK; SRes res = SZ_OK;
CLookToRead *p = (CLookToRead *)pp; GET_LookToRead2
size_t size2 = p->size - p->pos; size_t size2 = p->size - p->pos;
if (size2 == 0 && *size > 0) if (size2 == 0 && *size != 0)
{ {
p->pos = 0; p->pos = 0;
if (*size > LookToRead_BUF_SIZE) p->size = 0;
*size = LookToRead_BUF_SIZE; if (*size > p->bufSize)
res = p->realStream->Read(p->realStream, p->buf, size); *size = p->bufSize;
res = ISeekInStream_Read(p->realStream, p->buf, size);
size2 = p->size = *size; size2 = p->size = *size;
} }
if (size2 < *size) if (*size > size2)
*size = size2; *size = size2;
*buf = p->buf + p->pos; *buf = p->buf + p->pos;
return res; return res;
} }
static SRes LookToRead_Skip(void *pp, size_t offset) static SRes LookToRead2_Skip(const ILookInStream *pp, size_t offset)
{ {
CLookToRead *p = (CLookToRead *)pp; GET_LookToRead2
p->pos += offset; p->pos += offset;
return SZ_OK; return SZ_OK;
} }
static SRes LookToRead_Read(void *pp, void *buf, size_t *size) static SRes LookToRead2_Read(const ILookInStream *pp, void *buf, size_t *size)
{ {
CLookToRead *p = (CLookToRead *)pp; GET_LookToRead2
size_t rem = p->size - p->pos; size_t rem = p->size - p->pos;
if (rem == 0) if (rem == 0)
return p->realStream->Read(p->realStream, buf, size); return ISeekInStream_Read(p->realStream, buf, size);
if (rem > *size) if (rem > *size)
rem = *size; rem = *size;
memcpy(buf, p->buf + p->pos, rem); memcpy(buf, p->buf + p->pos, rem);
@@ -126,46 +134,43 @@ static SRes LookToRead_Read(void *pp, void *buf, size_t *size)
return SZ_OK; return SZ_OK;
} }
static SRes LookToRead_Seek(void *pp, Int64 *pos, ESzSeek origin) static SRes LookToRead2_Seek(const ILookInStream *pp, Int64 *pos, ESzSeek origin)
{ {
CLookToRead *p = (CLookToRead *)pp; GET_LookToRead2
p->pos = p->size = 0; p->pos = p->size = 0;
return p->realStream->Seek(p->realStream, pos, origin); return ISeekInStream_Seek(p->realStream, pos, origin);
} }
void LookToRead_CreateVTable(CLookToRead *p, int lookahead) void LookToRead2_CreateVTable(CLookToRead2 *p, int lookahead)
{ {
p->s.Look = lookahead ? p->vt.Look = lookahead ?
LookToRead_Look_Lookahead : LookToRead2_Look_Lookahead :
LookToRead_Look_Exact; LookToRead2_Look_Exact;
p->s.Skip = LookToRead_Skip; p->vt.Skip = LookToRead2_Skip;
p->s.Read = LookToRead_Read; p->vt.Read = LookToRead2_Read;
p->s.Seek = LookToRead_Seek; p->vt.Seek = LookToRead2_Seek;
} }
void LookToRead_Init(CLookToRead *p)
{
p->pos = p->size = 0;
}
static SRes SecToLook_Read(void *pp, void *buf, size_t *size)
static SRes SecToLook_Read(const ISeqInStream *pp, void *buf, size_t *size)
{ {
CSecToLook *p = (CSecToLook *)pp; CSecToLook *p = CONTAINER_FROM_VTBL(pp, CSecToLook, vt);
return LookInStream_LookRead(p->realStream, buf, size); return LookInStream_LookRead(p->realStream, buf, size);
} }
void SecToLook_CreateVTable(CSecToLook *p) void SecToLook_CreateVTable(CSecToLook *p)
{ {
p->s.Read = SecToLook_Read; p->vt.Read = SecToLook_Read;
} }
static SRes SecToRead_Read(void *pp, void *buf, size_t *size) static SRes SecToRead_Read(const ISeqInStream *pp, void *buf, size_t *size)
{ {
CSecToRead *p = (CSecToRead *)pp; CSecToRead *p = CONTAINER_FROM_VTBL(pp, CSecToRead, vt);
return p->realStream->Read(p->realStream, buf, size); return ILookInStream_Read(p->realStream, buf, size);
} }
void SecToRead_CreateVTable(CSecToRead *p) void SecToRead_CreateVTable(CSecToRead *p)
{ {
p->s.Read = SecToRead_Read; p->vt.Read = SecToRead_Read;
} }

View File

@@ -1,5 +1,5 @@
/* 7zTypes.h -- Basic types /* 7zTypes.h -- Basic types
2013-11-12 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#ifndef __7Z_TYPES_H #ifndef __7Z_TYPES_H
#define __7Z_TYPES_H #define __7Z_TYPES_H
@@ -112,48 +112,72 @@ typedef int Bool;
#define MY_NO_INLINE #define MY_NO_INLINE
#endif #endif
#define MY_FORCE_INLINE __forceinline
#define MY_CDECL __cdecl #define MY_CDECL __cdecl
#define MY_FAST_CALL __fastcall #define MY_FAST_CALL __fastcall
#else #else
#define MY_NO_INLINE #define MY_NO_INLINE
#define MY_FORCE_INLINE
#define MY_CDECL #define MY_CDECL
#define MY_FAST_CALL #define MY_FAST_CALL
/* inline keyword : for C++ / C99 */
/* GCC, clang: */
/*
#if defined (__GNUC__) && (__GNUC__ >= 4)
#define MY_FORCE_INLINE __attribute__((always_inline))
#define MY_NO_INLINE __attribute__((noinline))
#endif
*/
#endif #endif
/* The following interfaces use first parameter as pointer to structure */ /* The following interfaces use first parameter as pointer to structure */
typedef struct typedef struct IByteIn IByteIn;
struct IByteIn
{ {
Byte (*Read)(void *p); /* reads one byte, returns 0 in case of EOF or error */ Byte (*Read)(const IByteIn *p); /* reads one byte, returns 0 in case of EOF or error */
} IByteIn; };
#define IByteIn_Read(p) (p)->Read(p)
typedef struct
{
void (*Write)(void *p, Byte b);
} IByteOut;
typedef struct typedef struct IByteOut IByteOut;
struct IByteOut
{ {
SRes (*Read)(void *p, void *buf, size_t *size); void (*Write)(const IByteOut *p, Byte b);
};
#define IByteOut_Write(p, b) (p)->Write(p, b)
typedef struct ISeqInStream ISeqInStream;
struct ISeqInStream
{
SRes (*Read)(const ISeqInStream *p, void *buf, size_t *size);
/* if (input(*size) != 0 && output(*size) == 0) means end_of_stream. /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
(output(*size) < input(*size)) is allowed */ (output(*size) < input(*size)) is allowed */
} ISeqInStream; };
#define ISeqInStream_Read(p, buf, size) (p)->Read(p, buf, size)
/* it can return SZ_ERROR_INPUT_EOF */ /* it can return SZ_ERROR_INPUT_EOF */
SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size); SRes SeqInStream_Read(const ISeqInStream *stream, void *buf, size_t size);
SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType); SRes SeqInStream_Read2(const ISeqInStream *stream, void *buf, size_t size, SRes errorType);
SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf); SRes SeqInStream_ReadByte(const ISeqInStream *stream, Byte *buf);
typedef struct
typedef struct ISeqOutStream ISeqOutStream;
struct ISeqOutStream
{ {
size_t (*Write)(void *p, const void *buf, size_t size); size_t (*Write)(const ISeqOutStream *p, const void *buf, size_t size);
/* Returns: result - the number of actually written bytes. /* Returns: result - the number of actually written bytes.
(result < size) means error */ (result < size) means error */
} ISeqOutStream; };
#define ISeqOutStream_Write(p, buf, size) (p)->Write(p, buf, size)
typedef enum typedef enum
{ {
@@ -162,78 +186,162 @@ typedef enum
SZ_SEEK_END = 2 SZ_SEEK_END = 2
} ESzSeek; } ESzSeek;
typedef struct
{
SRes (*Read)(void *p, void *buf, size_t *size); /* same as ISeqInStream::Read */
SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
} ISeekInStream;
typedef struct typedef struct ISeekInStream ISeekInStream;
struct ISeekInStream
{ {
SRes (*Look)(void *p, const void **buf, size_t *size); SRes (*Read)(const ISeekInStream *p, void *buf, size_t *size); /* same as ISeqInStream::Read */
SRes (*Seek)(const ISeekInStream *p, Int64 *pos, ESzSeek origin);
};
#define ISeekInStream_Read(p, buf, size) (p)->Read(p, buf, size)
#define ISeekInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)
typedef struct ILookInStream ILookInStream;
struct ILookInStream
{
SRes (*Look)(const ILookInStream *p, const void **buf, size_t *size);
/* if (input(*size) != 0 && output(*size) == 0) means end_of_stream. /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
(output(*size) > input(*size)) is not allowed (output(*size) > input(*size)) is not allowed
(output(*size) < input(*size)) is allowed */ (output(*size) < input(*size)) is allowed */
SRes (*Skip)(void *p, size_t offset); SRes (*Skip)(const ILookInStream *p, size_t offset);
/* offset must be <= output(*size) of Look */ /* offset must be <= output(*size) of Look */
SRes (*Read)(void *p, void *buf, size_t *size); SRes (*Read)(const ILookInStream *p, void *buf, size_t *size);
/* reads directly (without buffer). It's same as ISeqInStream::Read */ /* reads directly (without buffer). It's same as ISeqInStream::Read */
SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin); SRes (*Seek)(const ILookInStream *p, Int64 *pos, ESzSeek origin);
} ILookInStream; };
SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size); #define ILookInStream_Look(p, buf, size) (p)->Look(p, buf, size)
SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset); #define ILookInStream_Skip(p, offset) (p)->Skip(p, offset)
#define ILookInStream_Read(p, buf, size) (p)->Read(p, buf, size)
#define ILookInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)
SRes LookInStream_LookRead(const ILookInStream *stream, void *buf, size_t *size);
SRes LookInStream_SeekTo(const ILookInStream *stream, UInt64 offset);
/* reads via ILookInStream::Read */ /* reads via ILookInStream::Read */
SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType); SRes LookInStream_Read2(const ILookInStream *stream, void *buf, size_t size, SRes errorType);
SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size); SRes LookInStream_Read(const ILookInStream *stream, void *buf, size_t size);
#define LookToRead_BUF_SIZE (1 << 14)
typedef struct typedef struct
{ {
ILookInStream s; ILookInStream vt;
ISeekInStream *realStream; const ISeekInStream *realStream;
size_t pos; size_t pos;
size_t size; size_t size; /* it's data size */
Byte buf[LookToRead_BUF_SIZE];
} CLookToRead; /* the following variables must be set outside */
Byte *buf;
size_t bufSize;
} CLookToRead2;
void LookToRead2_CreateVTable(CLookToRead2 *p, int lookahead);
#define LookToRead2_Init(p) { (p)->pos = (p)->size = 0; }
void LookToRead_CreateVTable(CLookToRead *p, int lookahead);
void LookToRead_Init(CLookToRead *p);
typedef struct typedef struct
{ {
ISeqInStream s; ISeqInStream vt;
ILookInStream *realStream; const ILookInStream *realStream;
} CSecToLook; } CSecToLook;
void SecToLook_CreateVTable(CSecToLook *p); void SecToLook_CreateVTable(CSecToLook *p);
typedef struct typedef struct
{ {
ISeqInStream s; ISeqInStream vt;
ILookInStream *realStream; const ILookInStream *realStream;
} CSecToRead; } CSecToRead;
void SecToRead_CreateVTable(CSecToRead *p); void SecToRead_CreateVTable(CSecToRead *p);
typedef struct
typedef struct ICompressProgress ICompressProgress;
struct ICompressProgress
{ {
SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize); SRes (*Progress)(const ICompressProgress *p, UInt64 inSize, UInt64 outSize);
/* Returns: result. (result != SZ_OK) means break. /* Returns: result. (result != SZ_OK) means break.
Value (UInt64)(Int64)-1 for size means unknown value. */ Value (UInt64)(Int64)-1 for size means unknown value. */
} ICompressProgress; };
#define ICompressProgress_Progress(p, inSize, outSize) (p)->Progress(p, inSize, outSize)
typedef struct
typedef struct ISzAlloc ISzAlloc;
typedef const ISzAlloc * ISzAllocPtr;
struct ISzAlloc
{ {
void *(*Alloc)(void *p, size_t size); void *(*Alloc)(ISzAllocPtr p, size_t size);
void (*Free)(void *p, void *address); /* address can be 0 */ void (*Free)(ISzAllocPtr p, void *address); /* address can be 0 */
} ISzAlloc; };
#define ISzAlloc_Alloc(p, size) (p)->Alloc(p, size)
#define ISzAlloc_Free(p, a) (p)->Free(p, a)
/* deprecated */
#define IAlloc_Alloc(p, size) ISzAlloc_Alloc(p, size)
#define IAlloc_Free(p, a) ISzAlloc_Free(p, a)
#ifndef MY_offsetof
#ifdef offsetof
#define MY_offsetof(type, m) offsetof(type, m)
/*
#define MY_offsetof(type, m) FIELD_OFFSET(type, m)
*/
#else
#define MY_offsetof(type, m) ((size_t)&(((type *)0)->m))
#endif
#endif
#ifndef MY_container_of
/*
#define MY_container_of(ptr, type, m) container_of(ptr, type, m)
#define MY_container_of(ptr, type, m) CONTAINING_RECORD(ptr, type, m)
#define MY_container_of(ptr, type, m) ((type *)((char *)(ptr) - offsetof(type, m)))
#define MY_container_of(ptr, type, m) (&((type *)0)->m == (ptr), ((type *)(((char *)(ptr)) - MY_offsetof(type, m))))
*/
/*
GCC shows warning: "perhaps the 'offsetof' macro was used incorrectly"
GCC 3.4.4 : classes with constructor
GCC 4.8.1 : classes with non-public variable members"
*/
#define MY_container_of(ptr, type, m) ((type *)((char *)(1 ? (ptr) : &((type *)0)->m) - MY_offsetof(type, m)))
#endif
#define CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) ((type *)(ptr))
/*
#define CONTAINER_FROM_VTBL(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
*/
#define CONTAINER_FROM_VTBL(ptr, type, m) MY_container_of(ptr, type, m)
#define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
/*
#define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL(ptr, type, m)
*/
#define IAlloc_Alloc(p, size) (p)->Alloc((p), size)
#define IAlloc_Free(p, a) (p)->Free((p), a)
#ifdef _WIN32 #ifdef _WIN32

View File

@@ -1,14 +1,21 @@
#define MY_VER_MAJOR 16 #define MY_VER_MAJOR 17
#define MY_VER_MINOR 04 #define MY_VER_MINOR 00
#define MY_VER_BUILD 0 #define MY_VER_BUILD 0
#define MY_VERSION_NUMBERS "16.04" #define MY_VERSION_NUMBERS "17.00 beta"
#define MY_VERSION "16.04" #define MY_VERSION MY_VERSION_NUMBERS
#define MY_DATE "2016-10-04"
#ifdef MY_CPU_NAME
#define MY_VERSION_CPU MY_VERSION " (" MY_CPU_NAME ")"
#else
#define MY_VERSION_CPU MY_VERSION
#endif
#define MY_DATE "2017-04-29"
#undef MY_COPYRIGHT #undef MY_COPYRIGHT
#undef MY_VERSION_COPYRIGHT_DATE #undef MY_VERSION_COPYRIGHT_DATE
#define MY_AUTHOR_NAME "Igor Pavlov" #define MY_AUTHOR_NAME "Igor Pavlov"
#define MY_COPYRIGHT_PD "Igor Pavlov : Public domain" #define MY_COPYRIGHT_PD "Igor Pavlov : Public domain"
#define MY_COPYRIGHT_CR "Copyright (c) 1999-2016 Igor Pavlov" #define MY_COPYRIGHT_CR "Copyright (c) 1999-2017 Igor Pavlov"
#ifdef USE_COPYRIGHT_CR #ifdef USE_COPYRIGHT_CR
#define MY_COPYRIGHT MY_COPYRIGHT_CR #define MY_COPYRIGHT MY_COPYRIGHT_CR
@@ -16,4 +23,5 @@
#define MY_COPYRIGHT MY_COPYRIGHT_PD #define MY_COPYRIGHT MY_COPYRIGHT_PD
#endif #endif
#define MY_VERSION_COPYRIGHT_DATE MY_VERSION " : " MY_COPYRIGHT " : " MY_DATE #define MY_COPYRIGHT_DATE MY_COPYRIGHT " : " MY_DATE
#define MY_VERSION_COPYRIGHT_DATE MY_VERSION_CPU " : " MY_COPYRIGHT " : " MY_DATE

67
C/Aes.c
View File

@@ -1,5 +1,5 @@
/* Aes.c -- AES encryption / decryption /* Aes.c -- AES encryption / decryption
2016-05-21 : Igor Pavlov : Public domain */ 2017-01-24 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@@ -49,7 +49,13 @@ static const Byte Rcon[11] = { 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0
#define gb0(x) ( (x) & 0xFF) #define gb0(x) ( (x) & 0xFF)
#define gb1(x) (((x) >> ( 8)) & 0xFF) #define gb1(x) (((x) >> ( 8)) & 0xFF)
#define gb2(x) (((x) >> (16)) & 0xFF) #define gb2(x) (((x) >> (16)) & 0xFF)
#define gb3(x) (((x) >> (24)) & 0xFF) #define gb3(x) (((x) >> (24)))
#define gb(n, x) gb ## n(x)
#define TT(x) (T + (x << 8))
#define DD(x) (D + (x << 8))
void AesGenTables(void) void AesGenTables(void)
{ {
@@ -63,10 +69,10 @@ void AesGenTables(void)
UInt32 a1 = Sbox[i]; UInt32 a1 = Sbox[i];
UInt32 a2 = xtime(a1); UInt32 a2 = xtime(a1);
UInt32 a3 = a2 ^ a1; UInt32 a3 = a2 ^ a1;
T[ i] = Ui32(a2, a1, a1, a3); TT(0)[i] = Ui32(a2, a1, a1, a3);
T[0x100 + i] = Ui32(a3, a2, a1, a1); TT(1)[i] = Ui32(a3, a2, a1, a1);
T[0x200 + i] = Ui32(a1, a3, a2, a1); TT(2)[i] = Ui32(a1, a3, a2, a1);
T[0x300 + i] = Ui32(a1, a1, a3, a2); TT(3)[i] = Ui32(a1, a1, a3, a2);
} }
{ {
UInt32 a1 = InvS[i]; UInt32 a1 = InvS[i];
@@ -77,10 +83,10 @@ void AesGenTables(void)
UInt32 aB = a8 ^ a2 ^ a1; UInt32 aB = a8 ^ a2 ^ a1;
UInt32 aD = a8 ^ a4 ^ a1; UInt32 aD = a8 ^ a4 ^ a1;
UInt32 aE = a8 ^ a4 ^ a2; UInt32 aE = a8 ^ a4 ^ a2;
D[ i] = Ui32(aE, a9, aD, aB); DD(0)[i] = Ui32(aE, a9, aD, aB);
D[0x100 + i] = Ui32(aB, aE, a9, aD); DD(1)[i] = Ui32(aB, aE, a9, aD);
D[0x200 + i] = Ui32(aD, aB, aE, a9); DD(2)[i] = Ui32(aD, aB, aE, a9);
D[0x300 + i] = Ui32(a9, aD, aB, aE); DD(3)[i] = Ui32(a9, aD, aB, aE);
} }
} }
@@ -99,7 +105,7 @@ void AesGenTables(void)
} }
#define HT(i, x, s) (T + (x << 8))[gb ## x(s[(i + x) & 3])] #define HT(i, x, s) TT(x)[gb(x, s[(i + x) & 3])]
#define HT4(m, i, s, p) m[i] = \ #define HT4(m, i, s, p) m[i] = \
HT(i, 0, s) ^ \ HT(i, 0, s) ^ \
@@ -113,11 +119,11 @@ void AesGenTables(void)
HT4(m, 2, s, p); \ HT4(m, 2, s, p); \
HT4(m, 3, s, p); \ HT4(m, 3, s, p); \
#define FT(i, x) Sbox[gb ## x(m[(i + x) & 3])] #define FT(i, x) Sbox[gb(x, m[(i + x) & 3])]
#define FT4(i) dest[i] = Ui32(FT(i, 0), FT(i, 1), FT(i, 2), FT(i, 3)) ^ w[i]; #define FT4(i) dest[i] = Ui32(FT(i, 0), FT(i, 1), FT(i, 2), FT(i, 3)) ^ w[i];
#define HD(i, x, s) (D + (x << 8))[gb ## x(s[(i - x) & 3])] #define HD(i, x, s) DD(x)[gb(x, s[(i - x) & 3])]
#define HD4(m, i, s, p) m[i] = \ #define HD4(m, i, s, p) m[i] = \
HD(i, 0, s) ^ \ HD(i, 0, s) ^ \
@@ -131,7 +137,7 @@ void AesGenTables(void)
HD4(m, 2, s, p); \ HD4(m, 2, s, p); \
HD4(m, 3, s, p); \ HD4(m, 3, s, p); \
#define FD(i, x) InvS[gb ## x(m[(i - x) & 3])] #define FD(i, x) InvS[gb(x, m[(i - x) & 3])]
#define FD4(i) dest[i] = Ui32(FD(i, 0), FD(i, 1), FD(i, 2), FD(i, 3)) ^ w[i]; #define FD4(i) dest[i] = Ui32(FD(i, 0), FD(i, 1), FD(i, 2), FD(i, 3)) ^ w[i];
void MY_FAST_CALL Aes_SetKey_Enc(UInt32 *w, const Byte *key, unsigned keySize) void MY_FAST_CALL Aes_SetKey_Enc(UInt32 *w, const Byte *key, unsigned keySize)
@@ -147,7 +153,7 @@ void MY_FAST_CALL Aes_SetKey_Enc(UInt32 *w, const Byte *key, unsigned keySize)
for (; i < wSize; i++) for (; i < wSize; i++)
{ {
UInt32 t = w[i - 1]; UInt32 t = w[(size_t)i - 1];
unsigned rem = i % keySize; unsigned rem = i % keySize;
if (rem == 0) if (rem == 0)
t = Ui32(Sbox[gb1(t)] ^ Rcon[i / keySize], Sbox[gb2(t)], Sbox[gb3(t)], Sbox[gb0(t)]); t = Ui32(Sbox[gb1(t)] ^ Rcon[i / keySize], Sbox[gb2(t)], Sbox[gb3(t)], Sbox[gb0(t)]);
@@ -167,10 +173,10 @@ void MY_FAST_CALL Aes_SetKey_Dec(UInt32 *w, const Byte *key, unsigned keySize)
{ {
UInt32 r = w[i]; UInt32 r = w[i];
w[i] = w[i] =
D[ (unsigned)Sbox[gb0(r)]] ^ DD(0)[Sbox[gb0(r)]] ^
D[0x100 + (unsigned)Sbox[gb1(r)]] ^ DD(1)[Sbox[gb1(r)]] ^
D[0x200 + (unsigned)Sbox[gb2(r)]] ^ DD(2)[Sbox[gb2(r)]] ^
D[0x300 + (unsigned)Sbox[gb3(r)]]; DD(3)[Sbox[gb3(r)]];
} }
} }
@@ -276,20 +282,25 @@ void MY_FAST_CALL AesCtr_Code(UInt32 *p, Byte *data, size_t numBlocks)
for (; numBlocks != 0; numBlocks--) for (; numBlocks != 0; numBlocks--)
{ {
UInt32 temp[4]; UInt32 temp[4];
Byte buf[16]; unsigned i;
int i;
if (++p[0] == 0) if (++p[0] == 0)
p[1]++; p[1]++;
Aes_Encode(p + 4, temp, p); Aes_Encode(p + 4, temp, p);
SetUi32(buf, temp[0]); for (i = 0; i < 4; i++, data += 4)
SetUi32(buf + 4, temp[1]); {
SetUi32(buf + 8, temp[2]); UInt32 t = temp[i];
SetUi32(buf + 12, temp[3]);
#ifdef MY_CPU_LE_UNALIGN
for (i = 0; i < 16; i++) *((UInt32 *)data) ^= t;
*data++ ^= buf[i]; #else
data[0] ^= (t & 0xFF);
data[1] ^= ((t >> 8) & 0xFF);
data[2] ^= ((t >> 16) & 0xFF);
data[3] ^= ((t >> 24));
#endif
}
} }
} }

View File

@@ -1,5 +1,5 @@
/* Alloc.c -- Memory allocation functions /* Alloc.c -- Memory allocation functions
2015-02-21 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@@ -127,10 +127,10 @@ void BigFree(void *address)
#endif #endif
static void *SzAlloc(void *p, size_t size) { UNUSED_VAR(p); return MyAlloc(size); } static void *SzAlloc(ISzAllocPtr p, size_t size) { UNUSED_VAR(p); return MyAlloc(size); }
static void SzFree(void *p, void *address) { UNUSED_VAR(p); MyFree(address); } static void SzFree(ISzAllocPtr p, void *address) { UNUSED_VAR(p); MyFree(address); }
ISzAlloc g_Alloc = { SzAlloc, SzFree }; ISzAlloc const g_Alloc = { SzAlloc, SzFree };
static void *SzBigAlloc(void *p, size_t size) { UNUSED_VAR(p); return BigAlloc(size); } static void *SzBigAlloc(ISzAllocPtr p, size_t size) { UNUSED_VAR(p); return BigAlloc(size); }
static void SzBigFree(void *p, void *address) { UNUSED_VAR(p); BigFree(address); } static void SzBigFree(ISzAllocPtr p, void *address) { UNUSED_VAR(p); BigFree(address); }
ISzAlloc g_BigAlloc = { SzBigAlloc, SzBigFree }; ISzAlloc const g_BigAlloc = { SzBigAlloc, SzBigFree };

View File

@@ -1,5 +1,5 @@
/* Alloc.h -- Memory allocation functions /* Alloc.h -- Memory allocation functions
2015-02-21 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#ifndef __COMMON_ALLOC_H #ifndef __COMMON_ALLOC_H
#define __COMMON_ALLOC_H #define __COMMON_ALLOC_H
@@ -29,8 +29,8 @@ void BigFree(void *address);
#endif #endif
extern ISzAlloc g_Alloc; extern const ISzAlloc g_Alloc;
extern ISzAlloc g_BigAlloc; extern const ISzAlloc g_BigAlloc;
EXTERN_C_END EXTERN_C_END

View File

@@ -1,5 +1,5 @@
/* Bcj2.c -- BCJ2 Decoder (Converter for x86 code) /* Bcj2.c -- BCJ2 Decoder (Converter for x86 code)
2015-08-01 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@@ -61,7 +61,8 @@ SRes Bcj2Dec_Decode(CBcj2Dec *p)
Byte *dest = p->dest; Byte *dest = p->dest;
if (dest == p->destLim) if (dest == p->destLim)
return SZ_OK; return SZ_OK;
*dest = p->temp[p->state++ - BCJ2_DEC_STATE_ORIG_0]; *dest = p->temp[(size_t)p->state - BCJ2_DEC_STATE_ORIG_0];
p->state++;
p->dest = dest + 1; p->dest = dest + 1;
} }
} }

View File

@@ -1,5 +1,5 @@
/* Bcj2Enc.c -- BCJ2 Encoder (Converter for x86 code) /* Bcj2Enc.c -- BCJ2 Encoder (Converter for x86 code)
2014-11-10 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@@ -271,7 +271,7 @@ void Bcj2Enc_Encode(CBcj2Enc *p)
unsigned i; unsigned i;
p->tempPos = tempPos; p->tempPos = tempPos;
for (i = 0; i < tempPos; i++) for (i = 0; i < tempPos; i++)
p->temp[i] = p->temp[i + num]; p->temp[i] = p->temp[(size_t)i + num];
p->src = src; p->src = src;
p->srcLim = srcLim; p->srcLim = srcLim;

289
C/Bra.c
View File

@@ -1,135 +1,230 @@
/* Bra.c -- Converters for RISC code /* Bra.c -- Converters for RISC code
2010-04-16 : Igor Pavlov : Public domain */ 2017-04-04 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
#include "CpuArch.h"
#include "Bra.h" #include "Bra.h"
SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
{ {
SizeT i; Byte *p;
if (size < 4) const Byte *lim;
return 0; size &= ~(size_t)3;
size -= 4; ip += 4;
ip += 8; p = data;
for (i = 0; i <= size; i += 4) lim = data + size;
if (encoding)
for (;;)
{ {
if (data[i + 3] == 0xEB) for (;;)
{ {
UInt32 dest; if (p >= lim)
UInt32 src = ((UInt32)data[i + 2] << 16) | ((UInt32)data[i + 1] << 8) | (data[i + 0]); return p - data;
src <<= 2; p += 4;
if (encoding) if (p[-1] == 0xEB)
dest = ip + (UInt32)i + src; break;
else }
dest = src - (ip + (UInt32)i); {
dest >>= 2; UInt32 v = GetUi32(p - 4);
data[i + 2] = (Byte)(dest >> 16); v <<= 2;
data[i + 1] = (Byte)(dest >> 8); v += ip + (UInt32)(p - data);
data[i + 0] = (Byte)dest; v >>= 2;
v &= 0x00FFFFFF;
v |= 0xEB000000;
SetUi32(p - 4, v);
}
}
for (;;)
{
for (;;)
{
if (p >= lim)
return p - data;
p += 4;
if (p[-1] == 0xEB)
break;
}
{
UInt32 v = GetUi32(p - 4);
v <<= 2;
v -= ip + (UInt32)(p - data);
v >>= 2;
v &= 0x00FFFFFF;
v |= 0xEB000000;
SetUi32(p - 4, v);
} }
} }
return i;
} }
SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
{ {
SizeT i; Byte *p;
if (size < 4) const Byte *lim;
return 0; size &= ~(size_t)1;
size -= 4; p = data;
ip += 4; lim = data + size - 4;
for (i = 0; i <= size; i += 2)
if (encoding)
for (;;)
{ {
if ((data[i + 1] & 0xF8) == 0xF0 && UInt32 b1;
(data[i + 3] & 0xF8) == 0xF8) for (;;)
{ {
UInt32 dest; UInt32 b3;
UInt32 src = if (p > lim)
(((UInt32)data[i + 1] & 0x7) << 19) | return p - data;
((UInt32)data[i + 0] << 11) | b1 = p[1];
(((UInt32)data[i + 3] & 0x7) << 8) | b3 = p[3];
(data[i + 2]); p += 2;
b1 ^= 8;
src <<= 1; if ((b3 & b1) >= 0xF8)
if (encoding) break;
dest = ip + (UInt32)i + src; }
else {
dest = src - (ip + (UInt32)i); UInt32 v =
dest >>= 1; ((UInt32)b1 << 19)
+ (((UInt32)p[1] & 0x7) << 8)
data[i + 1] = (Byte)(0xF0 | ((dest >> 19) & 0x7)); + (((UInt32)p[-2] << 11))
data[i + 0] = (Byte)(dest >> 11); + (p[0]);
data[i + 3] = (Byte)(0xF8 | ((dest >> 8) & 0x7));
data[i + 2] = (Byte)dest; p += 2;
i += 2; {
UInt32 cur = (ip + (UInt32)(p - data)) >> 1;
v += cur;
}
p[-4] = (Byte)(v >> 11);
p[-3] = (Byte)(0xF0 | ((v >> 19) & 0x7));
p[-2] = (Byte)v;
p[-1] = (Byte)(0xF8 | (v >> 8));
}
}
for (;;)
{
UInt32 b1;
for (;;)
{
UInt32 b3;
if (p > lim)
return p - data;
b1 = p[1];
b3 = p[3];
p += 2;
b1 ^= 8;
if ((b3 & b1) >= 0xF8)
break;
}
{
UInt32 v =
((UInt32)b1 << 19)
+ (((UInt32)p[1] & 0x7) << 8)
+ (((UInt32)p[-2] << 11))
+ (p[0]);
p += 2;
{
UInt32 cur = (ip + (UInt32)(p - data)) >> 1;
v -= cur;
}
/*
SetUi16(p - 4, (UInt16)(((v >> 11) & 0x7FF) | 0xF000));
SetUi16(p - 2, (UInt16)(v | 0xF800));
*/
p[-4] = (Byte)(v >> 11);
p[-3] = (Byte)(0xF0 | ((v >> 19) & 0x7));
p[-2] = (Byte)v;
p[-1] = (Byte)(0xF8 | (v >> 8));
} }
} }
return i;
} }
SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
{ {
SizeT i; Byte *p;
if (size < 4) const Byte *lim;
return 0; size &= ~(size_t)3;
size -= 4; ip -= 4;
for (i = 0; i <= size; i += 4) p = data;
lim = data + size;
for (;;)
{ {
if ((data[i] >> 2) == 0x12 && (data[i + 3] & 3) == 1) for (;;)
{ {
UInt32 src = ((UInt32)(data[i + 0] & 3) << 24) | if (p >= lim)
((UInt32)data[i + 1] << 16) | return p - data;
((UInt32)data[i + 2] << 8) | p += 4;
((UInt32)data[i + 3] & (~3)); /* if ((v & 0xFC000003) == 0x48000001) */
if ((p[-4] & 0xFC) == 0x48 && (p[-1] & 3) == 1)
UInt32 dest; break;
}
{
UInt32 v = GetBe32(p - 4);
if (encoding) if (encoding)
dest = ip + (UInt32)i + src; v += ip + (UInt32)(p - data);
else else
dest = src - (ip + (UInt32)i); v -= ip + (UInt32)(p - data);
data[i + 0] = (Byte)(0x48 | ((dest >> 24) & 0x3)); v &= 0x03FFFFFF;
data[i + 1] = (Byte)(dest >> 16); v |= 0x48000000;
data[i + 2] = (Byte)(dest >> 8); SetBe32(p - 4, v);
data[i + 3] &= 0x3;
data[i + 3] |= dest;
} }
} }
return i;
} }
SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
{ {
UInt32 i; Byte *p;
if (size < 4) const Byte *lim;
return 0; size &= ~(size_t)3;
size -= 4; ip -= 4;
for (i = 0; i <= size; i += 4) p = data;
{ lim = data + size;
if ((data[i] == 0x40 && (data[i + 1] & 0xC0) == 0x00) ||
(data[i] == 0x7F && (data[i + 1] & 0xC0) == 0xC0))
{
UInt32 src =
((UInt32)data[i + 0] << 24) |
((UInt32)data[i + 1] << 16) |
((UInt32)data[i + 2] << 8) |
((UInt32)data[i + 3]);
UInt32 dest;
src <<= 2;
if (encoding)
dest = ip + i + src;
else
dest = src - (ip + i);
dest >>= 2;
dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000;
data[i + 0] = (Byte)(dest >> 24); for (;;)
data[i + 1] = (Byte)(dest >> 16); {
data[i + 2] = (Byte)(dest >> 8); for (;;)
data[i + 3] = (Byte)dest; {
if (p >= lim)
return p - data;
/*
v = GetBe32(p);
p += 4;
m = v + ((UInt32)5 << 29);
m ^= (UInt32)7 << 29;
m += (UInt32)1 << 22;
if ((m & ((UInt32)0x1FF << 23)) == 0)
break;
*/
p += 4;
if ((p[-4] == 0x40 && (p[-3] & 0xC0) == 0) ||
(p[-4] == 0x7F && (p[-3] >= 0xC0)))
break;
}
{
UInt32 v = GetBe32(p - 4);
v <<= 2;
if (encoding)
v += ip + (UInt32)(p - data);
else
v -= ip + (UInt32)(p - data);
v &= 0x01FFFFFF;
v -= (UInt32)1 << 24;
v ^= 0xFF000000;
v >>= 2;
v |= 0x40000000;
SetBe32(p - 4, v);
} }
} }
return i;
} }

View File

@@ -1,5 +1,5 @@
/* Bra86.c -- Converter for x86 code (BCJ) /* Bra86.c -- Converter for x86 code (BCJ)
2013-11-12 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@@ -37,7 +37,7 @@ SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding
else else
{ {
mask >>= (unsigned)d; mask >>= (unsigned)d;
if (mask != 0 && (mask > 4 || mask == 3 || Test86MSByte(p[(mask >> 1) + 1]))) if (mask != 0 && (mask > 4 || mask == 3 || Test86MSByte(p[(size_t)(mask >> 1) + 1])))
{ {
mask = (mask >> 1) | 4; mask = (mask >> 1) | 4;
pos++; pos++;

View File

@@ -1,69 +1,53 @@
/* BraIA64.c -- Converter for IA-64 code /* BraIA64.c -- Converter for IA-64 code
2013-11-12 : Igor Pavlov : Public domain */ 2017-01-26 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
#include "CpuArch.h"
#include "Bra.h" #include "Bra.h"
static const Byte kBranchTable[32] =
{
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
4, 4, 6, 6, 0, 0, 7, 7,
4, 4, 0, 0, 4, 4, 0, 0
};
SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
{ {
SizeT i; SizeT i;
if (size < 16) if (size < 16)
return 0; return 0;
size -= 16; size -= 16;
for (i = 0; i <= size; i += 16) i = 0;
do
{ {
UInt32 instrTemplate = data[i] & 0x1F; unsigned m = ((UInt32)0x334B0000 >> (data[i] & 0x1E)) & 3;
UInt32 mask = kBranchTable[instrTemplate]; if (m)
UInt32 bitPos = 5;
int slot;
for (slot = 0; slot < 3; slot++, bitPos += 41)
{ {
UInt32 bytePos, bitRes; m++;
UInt64 instruction, instNorm; do
int j;
if (((mask >> slot) & 1) == 0)
continue;
bytePos = (bitPos >> 3);
bitRes = bitPos & 0x7;
instruction = 0;
for (j = 0; j < 6; j++)
instruction += (UInt64)data[i + j + bytePos] << (8 * j);
instNorm = instruction >> bitRes;
if (((instNorm >> 37) & 0xF) == 0x5 && ((instNorm >> 9) & 0x7) == 0)
{ {
UInt32 src = (UInt32)((instNorm >> 13) & 0xFFFFF); Byte *p = data + (i + (size_t)m * 5 - 8);
UInt32 dest; if (((p[3] >> m) & 15) == 5
src |= ((UInt32)(instNorm >> 36) & 1) << 20; && (((p[-1] | ((UInt32)p[0] << 8)) >> m) & 0x70) == 0)
{
src <<= 4; unsigned raw = GetUi32(p);
unsigned v = raw >> m;
if (encoding) v = (v & 0xFFFFF) | ((v & (1 << 23)) >> 3);
dest = ip + (UInt32)i + src;
else v <<= 4;
dest = src - (ip + (UInt32)i); if (encoding)
v += ip + (UInt32)i;
dest >>= 4; else
v -= ip + (UInt32)i;
instNorm &= ~((UInt64)(0x8FFFFF) << 13); v >>= 4;
instNorm |= ((UInt64)(dest & 0xFFFFF) << 13);
instNorm |= ((UInt64)(dest & 0x100000) << (36 - 20)); v &= 0x1FFFFF;
v += 0x700000;
instruction &= (1 << bitRes) - 1; v &= 0x8FFFFF;
instruction |= (instNorm << bitRes); raw &= ~((UInt32)0x8FFFFF << m);
for (j = 0; j < 6; j++) raw |= (v << m);
data[i + j + bytePos] = (Byte)(instruction >> (8 * j)); SetUi32(p, raw);
}
} }
while (++m <= 4);
} }
i += 16;
} }
while (i <= size);
return i; return i;
} }

View File

@@ -1,5 +1,5 @@
/* BwtSort.c -- BWT block sorting /* BwtSort.c -- BWT block sorting
2013-11-12 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@@ -314,7 +314,7 @@ UInt32 NO_INLINE SortGroup(UInt32 BlockSize, UInt32 NumSortedBytes, UInt32 group
#ifndef BLOCK_SORT_EXTERNAL_FLAGS #ifndef BLOCK_SORT_EXTERNAL_FLAGS
UInt32 subGroupSize = ((ind2[j] & ~0xC0000000) >> kNumBitsMax); UInt32 subGroupSize = ((ind2[j] & ~0xC0000000) >> kNumBitsMax);
if ((ind2[j] & 0x40000000) != 0) if ((ind2[j] & 0x40000000) != 0)
subGroupSize += ((ind2[j + 1] >> kNumBitsMax) << kNumExtra0Bits); subGroupSize += ((ind2[(size_t)j + 1] >> kNumBitsMax) << kNumExtra0Bits);
subGroupSize++; subGroupSize++;
for (;;) for (;;)
{ {
@@ -362,7 +362,7 @@ UInt32 BlockSort(UInt32 *Indices, const Byte *data, UInt32 blockSize)
for (i = 0; i < kNumHashValues; i++) for (i = 0; i < kNumHashValues; i++)
counters[i] = 0; counters[i] = 0;
for (i = 0; i < blockSize - 1; i++) for (i = 0; i < blockSize - 1; i++)
counters[((UInt32)data[i] << 8) | data[i + 1]]++; counters[((UInt32)data[i] << 8) | data[(size_t)i + 1]]++;
counters[((UInt32)data[i] << 8) | data[0]]++; counters[((UInt32)data[i] << 8) | data[0]]++;
Groups = counters + BS_TEMP_SIZE; Groups = counters + BS_TEMP_SIZE;
@@ -392,11 +392,11 @@ UInt32 BlockSort(UInt32 *Indices, const Byte *data, UInt32 blockSize)
} }
for (i = 0; i < blockSize - 1; i++) for (i = 0; i < blockSize - 1; i++)
Groups[i] = counters[((UInt32)data[i] << 8) | data[i + 1]]; Groups[i] = counters[((UInt32)data[i] << 8) | data[(size_t)i + 1]];
Groups[i] = counters[((UInt32)data[i] << 8) | data[0]]; Groups[i] = counters[((UInt32)data[i] << 8) | data[0]];
for (i = 0; i < blockSize - 1; i++) for (i = 0; i < blockSize - 1; i++)
Indices[counters[((UInt32)data[i] << 8) | data[i + 1]]++] = i; Indices[counters[((UInt32)data[i] << 8) | data[(size_t)i + 1]]++] = i;
Indices[counters[((UInt32)data[i] << 8) | data[0]]++] = i; Indices[counters[((UInt32)data[i] << 8) | data[0]]++] = i;
#ifndef BLOCK_SORT_EXTERNAL_FLAGS #ifndef BLOCK_SORT_EXTERNAL_FLAGS
@@ -451,8 +451,8 @@ UInt32 BlockSort(UInt32 *Indices, const Byte *data, UInt32 blockSize)
Bool finishedGroup = ((Indices[i] & 0x80000000) == 0); Bool finishedGroup = ((Indices[i] & 0x80000000) == 0);
if ((Indices[i] & 0x40000000) != 0) if ((Indices[i] & 0x40000000) != 0)
{ {
groupSize += ((Indices[i + 1] >> kNumBitsMax) << kNumExtra0Bits); groupSize += ((Indices[(size_t)i + 1] >> kNumBitsMax) << kNumExtra0Bits);
Indices[i + 1] &= kIndexMask; Indices[(size_t)i + 1] &= kIndexMask;
} }
Indices[i] &= kIndexMask; Indices[i] &= kIndexMask;
groupSize++; groupSize++;
@@ -460,7 +460,7 @@ UInt32 BlockSort(UInt32 *Indices, const Byte *data, UInt32 blockSize)
{ {
Indices[i - finishedGroupSize] &= kIndexMask; Indices[i - finishedGroupSize] &= kIndexMask;
if (finishedGroupSize > 1) if (finishedGroupSize > 1)
Indices[i - finishedGroupSize + 1] &= kIndexMask; Indices[(size_t)(i - finishedGroupSize) + 1] &= kIndexMask;
{ {
UInt32 newGroupSize = groupSize + finishedGroupSize; UInt32 newGroupSize = groupSize + finishedGroupSize;
SetFinishedGroupSize(Indices + i - finishedGroupSize, newGroupSize); SetFinishedGroupSize(Indices + i - finishedGroupSize, newGroupSize);
@@ -503,8 +503,8 @@ UInt32 BlockSort(UInt32 *Indices, const Byte *data, UInt32 blockSize)
UInt32 groupSize = ((Indices[i] & ~0xC0000000) >> kNumBitsMax); UInt32 groupSize = ((Indices[i] & ~0xC0000000) >> kNumBitsMax);
if ((Indices[i] & 0x40000000) != 0) if ((Indices[i] & 0x40000000) != 0)
{ {
groupSize += ((Indices[i + 1] >> kNumBitsMax) << kNumExtra0Bits); groupSize += ((Indices[(size_t)i + 1] >> kNumBitsMax) << kNumExtra0Bits);
Indices[i + 1] &= kIndexMask; Indices[(size_t)i + 1] &= kIndexMask;
} }
Indices[i] &= kIndexMask; Indices[i] &= kIndexMask;
groupSize++; groupSize++;

View File

@@ -1,5 +1,5 @@
/* Compiler.h /* Compiler.h
2015-08-02 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#ifndef __7Z_COMPILER_H #ifndef __7Z_COMPILER_H
#define __7Z_COMPILER_H #define __7Z_COMPILER_H
@@ -21,6 +21,7 @@
#pragma warning(disable : 4514) // unreferenced inline function has been removed #pragma warning(disable : 4514) // unreferenced inline function has been removed
#pragma warning(disable : 4702) // unreachable code #pragma warning(disable : 4702) // unreachable code
#pragma warning(disable : 4710) // not inlined #pragma warning(disable : 4710) // not inlined
#pragma warning(disable : 4714) // function marked as __forceinline not inlined
#pragma warning(disable : 4786) // identifier was truncated to '255' characters in the debug information #pragma warning(disable : 4786) // identifier was truncated to '255' characters in the debug information
#endif #endif

View File

@@ -1,5 +1,5 @@
/* CpuArch.h -- CPU specific code /* CpuArch.h -- CPU specific code
2016-06-09: Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#ifndef __CPU_ARCH_H #ifndef __CPU_ARCH_H
#define __CPU_ARCH_H #define __CPU_ARCH_H
@@ -16,48 +16,122 @@ If MY_CPU_LE and MY_CPU_BE are not defined, we don't know about ENDIANNESS of pl
MY_CPU_LE_UNALIGN means that CPU is LITTLE ENDIAN and CPU supports unaligned memory accesses. MY_CPU_LE_UNALIGN means that CPU is LITTLE ENDIAN and CPU supports unaligned memory accesses.
*/ */
#if defined(_M_X64) \ #if defined(_M_X64) \
|| defined(_M_AMD64) \ || defined(_M_AMD64) \
|| defined(__x86_64__) \ || defined(__x86_64__) \
|| defined(__AMD64__) \ || defined(__AMD64__) \
|| defined(__amd64__) || defined(__amd64__)
#define MY_CPU_AMD64 #define MY_CPU_AMD64
#endif #ifdef __ILP32__
#define MY_CPU_NAME "x32"
#if defined(MY_CPU_AMD64) \ #else
|| defined(_M_IA64) \ #define MY_CPU_NAME "x64"
|| defined(__AARCH64EL__) \ #endif
|| defined(__AARCH64EB__)
#define MY_CPU_64BIT #define MY_CPU_64BIT
#endif #endif
#if defined(_M_IX86) || defined(__i386__)
#define MY_CPU_X86 #if defined(_M_IX86) \
|| defined(__i386__)
#define MY_CPU_X86
#define MY_CPU_NAME "x86"
#define MY_CPU_32BIT
#endif #endif
#if defined(_M_ARM64) \
|| defined(__AARCH64EL__) \
|| defined(__AARCH64EB__) \
|| defined(__aarch64__)
#define MY_CPU_ARM64
#define MY_CPU_NAME "arm64"
#define MY_CPU_64BIT
#endif
#if defined(_M_ARM) \
|| defined(_M_ARM_NT) \
|| defined(_M_ARMT) \
|| defined(__arm__) \
|| defined(__thumb__) \
|| defined(__ARMEL__) \
|| defined(__ARMEB__) \
|| defined(__THUMBEL__) \
|| defined(__THUMBEB__)
#define MY_CPU_ARM
#define MY_CPU_NAME "arm"
#define MY_CPU_32BIT
#endif
#if defined(_M_IA64) \
|| defined(__ia64__)
#define MY_CPU_IA64
#define MY_CPU_NAME "ia64"
#define MY_CPU_64BIT
#endif
#if defined(__mips64) \
|| defined(__mips64__) \
|| (defined(__mips) && (__mips == 64 || __mips == 4 || __mips == 3))
#define MY_CPU_NAME "mips64"
#define MY_CPU_64BIT
#elif defined(__mips__)
#define MY_CPU_NAME "mips"
/* #define MY_CPU_32BIT */
#endif
#if defined(__ppc64__) \
|| defined(__powerpc64__)
#ifdef __ILP32__
#define MY_CPU_NAME "ppc64-32"
#else
#define MY_CPU_NAME "ppc64"
#endif
#define MY_CPU_64BIT
#elif defined(__ppc__) \
|| defined(__powerpc__)
#define MY_CPU_NAME "ppc"
#define MY_CPU_32BIT
#endif
#if defined(__sparc64__)
#define MY_CPU_NAME "sparc64"
#define MY_CPU_64BIT
#elif defined(__sparc__)
#define MY_CPU_NAME "sparc"
/* #define MY_CPU_32BIT */
#endif
#if defined(MY_CPU_X86) || defined(MY_CPU_AMD64) #if defined(MY_CPU_X86) || defined(MY_CPU_AMD64)
#define MY_CPU_X86_OR_AMD64 #define MY_CPU_X86_OR_AMD64
#endif #endif
#if defined(MY_CPU_X86) \
|| defined(_M_ARM) \ #ifdef _WIN32
|| defined(__ARMEL__) \
|| defined(__THUMBEL__) \ #ifdef MY_CPU_ARM
|| defined(__ARMEB__) \ #define MY_CPU_ARM_LE
|| defined(__THUMBEB__) #endif
#define MY_CPU_32BIT
#ifdef MY_CPU_ARM64
#define MY_CPU_ARM64_LE
#endif
#ifdef _M_IA64
#define MY_CPU_IA64_LE
#endif
#endif #endif
#if defined(_WIN32) && defined(_M_ARM)
#define MY_CPU_ARM_LE
#endif
#if defined(_WIN32) && defined(_M_IA64)
#define MY_CPU_IA64_LE
#endif
#if defined(MY_CPU_X86_OR_AMD64) \ #if defined(MY_CPU_X86_OR_AMD64) \
|| defined(MY_CPU_ARM_LE) \ || defined(MY_CPU_ARM_LE) \
|| defined(MY_CPU_ARM64_LE) \
|| defined(MY_CPU_IA64_LE) \ || defined(MY_CPU_IA64_LE) \
|| defined(__LITTLE_ENDIAN__) \ || defined(__LITTLE_ENDIAN__) \
|| defined(__ARMEL__) \ || defined(__ARMEL__) \
@@ -86,14 +160,38 @@ MY_CPU_LE_UNALIGN means that CPU is LITTLE ENDIAN and CPU supports unaligned mem
#define MY_CPU_BE #define MY_CPU_BE
#endif #endif
#if defined(MY_CPU_LE) && defined(MY_CPU_BE) #if defined(MY_CPU_LE) && defined(MY_CPU_BE)
Stop_Compiling_Bad_Endian #error Stop_Compiling_Bad_Endian
#endif #endif
#if defined(MY_CPU_32BIT) && defined(MY_CPU_64BIT)
#error Stop_Compiling_Bad_32_64_BIT
#endif
#ifndef MY_CPU_NAME
#ifdef MY_CPU_LE
#define MY_CPU_NAME "LE"
#elif MY_CPU_BE
#define MY_CPU_NAME "BE"
#else
/*
#define MY_CPU_NAME ""
*/
#endif
#endif
#ifdef MY_CPU_LE #ifdef MY_CPU_LE
#if defined(MY_CPU_X86_OR_AMD64) \ #if defined(MY_CPU_X86_OR_AMD64) \
/* || defined(__AARCH64EL__) */ || defined(MY_CPU_ARM64) \
|| defined(__ARM_FEATURE_UNALIGNED) \
|| defined(__AARCH64EL__)
#define MY_CPU_LE_UNALIGN #define MY_CPU_LE_UNALIGN
#endif #endif
#endif #endif

View File

@@ -1,5 +1,5 @@
/* HuffEnc.c -- functions for Huffman encoding /* HuffEnc.c -- functions for Huffman encoding
2016-05-16 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@@ -113,7 +113,7 @@ void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 numSymb
if (len >= maxLen) if (len >= maxLen)
for (len = maxLen - 1; lenCounters[len] == 0; len--); for (len = maxLen - 1; lenCounters[len] == 0; len--);
lenCounters[len]--; lenCounters[len]--;
lenCounters[len + 1] += 2; lenCounters[(size_t)len + 1] += 2;
} }
{ {
@@ -133,7 +133,7 @@ void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 numSymb
UInt32 code = 0; UInt32 code = 0;
UInt32 len; UInt32 len;
for (len = 1; len <= kMaxLen; len++) for (len = 1; len <= kMaxLen; len++)
nextCodes[len] = code = (code + lenCounters[len - 1]) << 1; nextCodes[len] = code = (code + lenCounters[(size_t)len - 1]) << 1;
} }
/* if (code + lenCounters[kMaxLen] - 1 != (1 << kMaxLen) - 1) throw 1; */ /* if (code + lenCounters[kMaxLen] - 1 != (1 << kMaxLen) - 1) throw 1; */

View File

@@ -1,5 +1,5 @@
/* LzFind.c -- Match finder for LZ algorithms /* LzFind.c -- Match finder for LZ algorithms
2015-10-15 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@@ -16,18 +16,18 @@
#define kStartMaxLen 3 #define kStartMaxLen 3
static void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc) static void LzInWindow_Free(CMatchFinder *p, ISzAllocPtr alloc)
{ {
if (!p->directInput) if (!p->directInput)
{ {
alloc->Free(alloc, p->bufferBase); ISzAlloc_Free(alloc, p->bufferBase);
p->bufferBase = NULL; p->bufferBase = NULL;
} }
} }
/* keepSizeBefore + keepSizeAfter + keepSizeReserv must be < 4G) */ /* keepSizeBefore + keepSizeAfter + keepSizeReserv must be < 4G) */
static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc) static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAllocPtr alloc)
{ {
UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv; UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;
if (p->directInput) if (p->directInput)
@@ -39,7 +39,7 @@ static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *a
{ {
LzInWindow_Free(p, alloc); LzInWindow_Free(p, alloc);
p->blockSize = blockSize; p->blockSize = blockSize;
p->bufferBase = (Byte *)alloc->Alloc(alloc, (size_t)blockSize); p->bufferBase = (Byte *)ISzAlloc_Alloc(alloc, (size_t)blockSize);
} }
return (p->bufferBase != NULL); return (p->bufferBase != NULL);
} }
@@ -81,7 +81,7 @@ static void MatchFinder_ReadBlock(CMatchFinder *p)
if (size == 0) if (size == 0)
return; return;
p->result = p->stream->Read(p->stream, dest, &size); p->result = ISeqInStream_Read(p->stream, dest, &size);
if (p->result != SZ_OK) if (p->result != SZ_OK)
return; return;
if (size == 0) if (size == 0)
@@ -149,34 +149,34 @@ void MatchFinder_Construct(CMatchFinder *p)
UInt32 r = i; UInt32 r = i;
unsigned j; unsigned j;
for (j = 0; j < 8; j++) for (j = 0; j < 8; j++)
r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1)); r = (r >> 1) ^ (kCrcPoly & ((UInt32)0 - (r & 1)));
p->crc[i] = r; p->crc[i] = r;
} }
} }
static void MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAlloc *alloc) static void MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAllocPtr alloc)
{ {
alloc->Free(alloc, p->hash); ISzAlloc_Free(alloc, p->hash);
p->hash = NULL; p->hash = NULL;
} }
void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc) void MatchFinder_Free(CMatchFinder *p, ISzAllocPtr alloc)
{ {
MatchFinder_FreeThisClassMemory(p, alloc); MatchFinder_FreeThisClassMemory(p, alloc);
LzInWindow_Free(p, alloc); LzInWindow_Free(p, alloc);
} }
static CLzRef* AllocRefs(size_t num, ISzAlloc *alloc) static CLzRef* AllocRefs(size_t num, ISzAllocPtr alloc)
{ {
size_t sizeInBytes = (size_t)num * sizeof(CLzRef); size_t sizeInBytes = (size_t)num * sizeof(CLzRef);
if (sizeInBytes / sizeof(CLzRef) != num) if (sizeInBytes / sizeof(CLzRef) != num)
return NULL; return NULL;
return (CLzRef *)alloc->Alloc(alloc, sizeInBytes); return (CLzRef *)ISzAlloc_Alloc(alloc, sizeInBytes);
} }
int MatchFinder_Create(CMatchFinder *p, UInt32 historySize, int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter, UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
ISzAlloc *alloc) ISzAllocPtr alloc)
{ {
UInt32 sizeReserv; UInt32 sizeReserv;
@@ -558,10 +558,10 @@ static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
d2 = pos - hash[h2]; d2 = pos - hash[h2];
curMatch = hash[kFix3HashSize + hv]; curMatch = (hash + kFix3HashSize)[hv];
hash[h2] = pos; hash[h2] = pos;
hash[kFix3HashSize + hv] = pos; (hash + kFix3HashSize)[hv] = pos;
maxLen = 2; maxLen = 2;
offset = 0; offset = 0;
@@ -594,13 +594,13 @@ static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
pos = p->pos; pos = p->pos;
d2 = pos - hash[ h2]; d2 = pos - hash[ h2];
d3 = pos - hash[kFix3HashSize + h3]; d3 = pos - (hash + kFix3HashSize)[h3];
curMatch = hash[kFix4HashSize + hv]; curMatch = (hash + kFix4HashSize)[hv];
hash[ h2] = pos; hash[ h2] = pos;
hash[kFix3HashSize + h3] = pos; (hash + kFix3HashSize)[h3] = pos;
hash[kFix4HashSize + hv] = pos; (hash + kFix4HashSize)[hv] = pos;
maxLen = 0; maxLen = 0;
offset = 0; offset = 0;
@@ -615,7 +615,7 @@ static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
if (d2 != d3 && d3 < p->cyclicBufferSize && *(cur - d3) == *cur) if (d2 != d3 && d3 < p->cyclicBufferSize && *(cur - d3) == *cur)
{ {
maxLen = 3; maxLen = 3;
distances[offset + 1] = d3 - 1; distances[(size_t)offset + 1] = d3 - 1;
offset += 2; offset += 2;
d2 = d3; d2 = d3;
} }
@@ -623,7 +623,7 @@ static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
if (offset != 0) if (offset != 0)
{ {
UPDATE_maxLen UPDATE_maxLen
distances[offset - 2] = maxLen; distances[(size_t)offset - 2] = maxLen;
if (maxLen == lenLimit) if (maxLen == lenLimit)
{ {
SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));
@@ -650,15 +650,15 @@ static UInt32 Bt5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
pos = p->pos; pos = p->pos;
d2 = pos - hash[ h2]; d2 = pos - hash[ h2];
d3 = pos - hash[kFix3HashSize + h3]; d3 = pos - (hash + kFix3HashSize)[h3];
d4 = pos - hash[kFix4HashSize + h4]; d4 = pos - (hash + kFix4HashSize)[h4];
curMatch = hash[kFix5HashSize + hv]; curMatch = (hash + kFix5HashSize)[hv];
hash[ h2] = pos; hash[ h2] = pos;
hash[kFix3HashSize + h3] = pos; (hash + kFix3HashSize)[h3] = pos;
hash[kFix4HashSize + h4] = pos; (hash + kFix4HashSize)[h4] = pos;
hash[kFix5HashSize + hv] = pos; (hash + kFix5HashSize)[hv] = pos;
maxLen = 0; maxLen = 0;
offset = 0; offset = 0;
@@ -691,7 +691,7 @@ static UInt32 Bt5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
&& *(cur - d4 + 3) == *(cur + 3)) && *(cur - d4 + 3) == *(cur + 3))
{ {
maxLen = 4; maxLen = 4;
distances[offset + 1] = d4 - 1; distances[(size_t)offset + 1] = d4 - 1;
offset += 2; offset += 2;
d2 = d4; d2 = d4;
} }
@@ -699,7 +699,7 @@ static UInt32 Bt5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
if (offset != 0) if (offset != 0)
{ {
UPDATE_maxLen UPDATE_maxLen
distances[offset - 2] = maxLen; distances[(size_t)offset - 2] = maxLen;
if (maxLen == lenLimit) if (maxLen == lenLimit)
{ {
SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));
@@ -726,13 +726,13 @@ static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
pos = p->pos; pos = p->pos;
d2 = pos - hash[ h2]; d2 = pos - hash[ h2];
d3 = pos - hash[kFix3HashSize + h3]; d3 = pos - (hash + kFix3HashSize)[h3];
curMatch = hash[kFix4HashSize + hv]; curMatch = (hash + kFix4HashSize)[hv];
hash[ h2] = pos; hash[ h2] = pos;
hash[kFix3HashSize + h3] = pos; (hash + kFix3HashSize)[h3] = pos;
hash[kFix4HashSize + hv] = pos; (hash + kFix4HashSize)[hv] = pos;
maxLen = 0; maxLen = 0;
offset = 0; offset = 0;
@@ -747,7 +747,7 @@ static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
if (d2 != d3 && d3 < p->cyclicBufferSize && *(cur - d3) == *cur) if (d2 != d3 && d3 < p->cyclicBufferSize && *(cur - d3) == *cur)
{ {
maxLen = 3; maxLen = 3;
distances[offset + 1] = d3 - 1; distances[(size_t)offset + 1] = d3 - 1;
offset += 2; offset += 2;
d2 = d3; d2 = d3;
} }
@@ -755,7 +755,7 @@ static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
if (offset != 0) if (offset != 0)
{ {
UPDATE_maxLen UPDATE_maxLen
distances[offset - 2] = maxLen; distances[(size_t)offset - 2] = maxLen;
if (maxLen == lenLimit) if (maxLen == lenLimit)
{ {
p->son[p->cyclicBufferPos] = curMatch; p->son[p->cyclicBufferPos] = curMatch;
@@ -784,15 +784,15 @@ static UInt32 Hc5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
pos = p->pos; pos = p->pos;
d2 = pos - hash[ h2]; d2 = pos - hash[ h2];
d3 = pos - hash[kFix3HashSize + h3]; d3 = pos - (hash + kFix3HashSize)[h3];
d4 = pos - hash[kFix4HashSize + h4]; d4 = pos - (hash + kFix4HashSize)[h4];
curMatch = hash[kFix5HashSize + hv]; curMatch = (hash + kFix5HashSize)[hv];
hash[ h2] = pos; hash[ h2] = pos;
hash[kFix3HashSize + h3] = pos; (hash + kFix3HashSize)[h3] = pos;
hash[kFix4HashSize + h4] = pos; (hash + kFix4HashSize)[h4] = pos;
hash[kFix5HashSize + hv] = pos; (hash + kFix5HashSize)[hv] = pos;
maxLen = 0; maxLen = 0;
offset = 0; offset = 0;
@@ -825,7 +825,7 @@ static UInt32 Hc5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
&& *(cur - d4 + 3) == *(cur + 3)) && *(cur - d4 + 3) == *(cur + 3))
{ {
maxLen = 4; maxLen = 4;
distances[offset + 1] = d4 - 1; distances[(size_t)offset + 1] = d4 - 1;
offset += 2; offset += 2;
d2 = d4; d2 = d4;
} }
@@ -833,7 +833,7 @@ static UInt32 Hc5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
if (offset != 0) if (offset != 0)
{ {
UPDATE_maxLen UPDATE_maxLen
distances[offset - 2] = maxLen; distances[(size_t)offset - 2] = maxLen;
if (maxLen == lenLimit) if (maxLen == lenLimit)
{ {
p->son[p->cyclicBufferPos] = curMatch; p->son[p->cyclicBufferPos] = curMatch;
@@ -897,9 +897,9 @@ static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
SKIP_HEADER(3) SKIP_HEADER(3)
HASH3_CALC; HASH3_CALC;
hash = p->hash; hash = p->hash;
curMatch = hash[kFix3HashSize + hv]; curMatch = (hash + kFix3HashSize)[hv];
hash[h2] = hash[h2] =
hash[kFix3HashSize + hv] = p->pos; (hash + kFix3HashSize)[hv] = p->pos;
SKIP_FOOTER SKIP_FOOTER
} }
while (--num != 0); while (--num != 0);
@@ -914,10 +914,10 @@ static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
SKIP_HEADER(4) SKIP_HEADER(4)
HASH4_CALC; HASH4_CALC;
hash = p->hash; hash = p->hash;
curMatch = hash[kFix4HashSize + hv]; curMatch = (hash + kFix4HashSize)[hv];
hash[ h2] = hash[ h2] =
hash[kFix3HashSize + h3] = (hash + kFix3HashSize)[h3] =
hash[kFix4HashSize + hv] = p->pos; (hash + kFix4HashSize)[hv] = p->pos;
SKIP_FOOTER SKIP_FOOTER
} }
while (--num != 0); while (--num != 0);
@@ -933,11 +933,11 @@ static void Bt5_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
SKIP_HEADER(5) SKIP_HEADER(5)
HASH5_CALC; HASH5_CALC;
hash = p->hash; hash = p->hash;
curMatch = hash[kFix5HashSize + hv]; curMatch = (hash + kFix5HashSize)[hv];
hash[ h2] = hash[ h2] =
hash[kFix3HashSize + h3] = (hash + kFix3HashSize)[h3] =
hash[kFix4HashSize + h4] = (hash + kFix4HashSize)[h4] =
hash[kFix5HashSize + hv] = p->pos; (hash + kFix5HashSize)[hv] = p->pos;
SKIP_FOOTER SKIP_FOOTER
} }
while (--num != 0); while (--num != 0);
@@ -953,10 +953,10 @@ static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
SKIP_HEADER(4) SKIP_HEADER(4)
HASH4_CALC; HASH4_CALC;
hash = p->hash; hash = p->hash;
curMatch = hash[kFix4HashSize + hv]; curMatch = (hash + kFix4HashSize)[hv];
hash[ h2] = hash[ h2] =
hash[kFix3HashSize + h3] = (hash + kFix3HashSize)[h3] =
hash[kFix4HashSize + hv] = p->pos; (hash + kFix4HashSize)[hv] = p->pos;
p->son[p->cyclicBufferPos] = curMatch; p->son[p->cyclicBufferPos] = curMatch;
MOVE_POS MOVE_POS
} }
@@ -973,11 +973,11 @@ static void Hc5_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
SKIP_HEADER(5) SKIP_HEADER(5)
HASH5_CALC; HASH5_CALC;
hash = p->hash; hash = p->hash;
curMatch = p->hash[kFix5HashSize + hv]; curMatch = hash + kFix5HashSize)[hv];
hash[ h2] = hash[ h2] =
hash[kFix3HashSize + h3] = (hash + kFix3HashSize)[h3] =
hash[kFix4HashSize + h4] = (hash + kFix4HashSize)[h4] =
hash[kFix5HashSize + hv] = p->pos; (hash + kFix5HashSize)[hv] = p->pos;
p->son[p->cyclicBufferPos] = curMatch; p->son[p->cyclicBufferPos] = curMatch;
MOVE_POS MOVE_POS
} }

View File

@@ -1,5 +1,5 @@
/* LzFind.h -- Match finder for LZ algorithms /* LzFind.h -- Match finder for LZ algorithms
2015-10-15 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#ifndef __LZ_FIND_H #ifndef __LZ_FIND_H
#define __LZ_FIND_H #define __LZ_FIND_H
@@ -71,8 +71,8 @@ void MatchFinder_Construct(CMatchFinder *p);
*/ */
int MatchFinder_Create(CMatchFinder *p, UInt32 historySize, int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter, UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
ISzAlloc *alloc); ISzAllocPtr alloc);
void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc); void MatchFinder_Free(CMatchFinder *p, ISzAllocPtr alloc);
void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, size_t numItems); void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, size_t numItems);
void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue); void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);

View File

@@ -1,5 +1,5 @@
/* LzFindMt.c -- multithreaded Match finder for LZ algorithms /* LzFindMt.c -- multithreaded Match finder for LZ algorithms
2015-10-15 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@@ -443,13 +443,13 @@ void MatchFinderMt_Construct(CMatchFinderMt *p)
MtSync_Construct(&p->btSync); MtSync_Construct(&p->btSync);
} }
static void MatchFinderMt_FreeMem(CMatchFinderMt *p, ISzAlloc *alloc) static void MatchFinderMt_FreeMem(CMatchFinderMt *p, ISzAllocPtr alloc)
{ {
alloc->Free(alloc, p->hashBuf); ISzAlloc_Free(alloc, p->hashBuf);
p->hashBuf = NULL; p->hashBuf = NULL;
} }
void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc) void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAllocPtr alloc)
{ {
MtSync_Destruct(&p->hashSync); MtSync_Destruct(&p->hashSync);
MtSync_Destruct(&p->btSync); MtSync_Destruct(&p->btSync);
@@ -472,7 +472,7 @@ static THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE BtThreadFunc2(void *p)
} }
SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore, SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,
UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc) UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAllocPtr alloc)
{ {
CMatchFinder *mf = p->MatchFinder; CMatchFinder *mf = p->MatchFinder;
p->historySize = historySize; p->historySize = historySize;
@@ -480,7 +480,7 @@ SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddB
return SZ_ERROR_PARAM; return SZ_ERROR_PARAM;
if (!p->hashBuf) if (!p->hashBuf)
{ {
p->hashBuf = (UInt32 *)alloc->Alloc(alloc, (kHashBufferSize + kBtBufferSize) * sizeof(UInt32)); p->hashBuf = (UInt32 *)ISzAlloc_Alloc(alloc, (kHashBufferSize + kBtBufferSize) * sizeof(UInt32));
if (!p->hashBuf) if (!p->hashBuf)
return SZ_ERROR_MEM; return SZ_ERROR_MEM;
p->btBuf = p->hashBuf + kHashBufferSize; p->btBuf = p->hashBuf + kHashBufferSize;
@@ -591,10 +591,10 @@ static UInt32 * MixMatches3(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *dista
MT_HASH3_CALC MT_HASH3_CALC
curMatch2 = hash[ h2]; curMatch2 = hash[ h2];
curMatch3 = hash[kFix3HashSize + h3]; curMatch3 = (hash + kFix3HashSize)[h3];
hash[ h2] = lzPos; hash[ h2] = lzPos;
hash[kFix3HashSize + h3] = lzPos; (hash + kFix3HashSize)[h3] = lzPos;
if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0]) if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])
{ {
@@ -627,12 +627,12 @@ static UInt32 *MixMatches4(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distan
MT_HASH4_CALC MT_HASH4_CALC
curMatch2 = hash[ h2]; curMatch2 = hash[ h2];
curMatch3 = hash[kFix3HashSize + h3]; curMatch3 = (hash + kFix3HashSize)[h3];
curMatch4 = hash[kFix4HashSize + h4]; curMatch4 = (hash + kFix4HashSize)[h4];
hash[ h2] = lzPos; hash[ h2] = lzPos;
hash[kFix3HashSize + h3] = lzPos; (hash + kFix3HashSize)[h3] = lzPos;
hash[kFix4HashSize + h4] = lzPos; (hash + kFix4HashSize)[h4] = lzPos;
if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0]) if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])
{ {
@@ -746,7 +746,7 @@ static void MatchFinderMt3_Skip(CMatchFinderMt *p, UInt32 num)
SKIP_HEADER_MT(3) SKIP_HEADER_MT(3)
UInt32 h2, h3; UInt32 h2, h3;
MT_HASH3_CALC MT_HASH3_CALC
hash[kFix3HashSize + h3] = (hash + kFix3HashSize)[h3] =
hash[ h2] = hash[ h2] =
p->lzPos; p->lzPos;
SKIP_FOOTER_MT SKIP_FOOTER_MT
@@ -758,8 +758,8 @@ static void MatchFinderMt4_Skip(CMatchFinderMt *p, UInt32 num)
SKIP_HEADER_MT(4) SKIP_HEADER_MT(4)
UInt32 h2, h3, h4; UInt32 h2, h3, h4;
MT_HASH4_CALC MT_HASH4_CALC
hash[kFix4HashSize + h4] = (hash + kFix4HashSize)[h4] =
hash[kFix3HashSize + h3] = (hash + kFix3HashSize)[h3] =
hash[ h2] = hash[ h2] =
p->lzPos; p->lzPos;
SKIP_FOOTER_MT SKIP_FOOTER_MT

View File

@@ -1,5 +1,5 @@
/* LzFindMt.h -- multithreaded Match finder for LZ algorithms /* LzFindMt.h -- multithreaded Match finder for LZ algorithms
2015-05-03 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#ifndef __LZ_FIND_MT_H #ifndef __LZ_FIND_MT_H
#define __LZ_FIND_MT_H #define __LZ_FIND_MT_H
@@ -90,9 +90,9 @@ typedef struct _CMatchFinderMt
} CMatchFinderMt; } CMatchFinderMt;
void MatchFinderMt_Construct(CMatchFinderMt *p); void MatchFinderMt_Construct(CMatchFinderMt *p);
void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc); void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAllocPtr alloc);
SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore, SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,
UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc); UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAllocPtr alloc);
void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable); void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable);
void MatchFinderMt_ReleaseStream(CMatchFinderMt *p); void MatchFinderMt_ReleaseStream(CMatchFinderMt *p);

View File

@@ -1,5 +1,5 @@
/* Lzma2Dec.c -- LZMA2 Decoder /* Lzma2Dec.c -- LZMA2 Decoder
2015-11-09 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
/* #define SHOW_DEBUG_INFO */ /* #define SHOW_DEBUG_INFO */
@@ -74,14 +74,14 @@ static SRes Lzma2Dec_GetOldProps(Byte prop, Byte *props)
return SZ_OK; return SZ_OK;
} }
SRes Lzma2Dec_AllocateProbs(CLzma2Dec *p, Byte prop, ISzAlloc *alloc) SRes Lzma2Dec_AllocateProbs(CLzma2Dec *p, Byte prop, ISzAllocPtr alloc)
{ {
Byte props[LZMA_PROPS_SIZE]; Byte props[LZMA_PROPS_SIZE];
RINOK(Lzma2Dec_GetOldProps(prop, props)); RINOK(Lzma2Dec_GetOldProps(prop, props));
return LzmaDec_AllocateProbs(&p->decoder, props, LZMA_PROPS_SIZE, alloc); return LzmaDec_AllocateProbs(&p->decoder, props, LZMA_PROPS_SIZE, alloc);
} }
SRes Lzma2Dec_Allocate(CLzma2Dec *p, Byte prop, ISzAlloc *alloc) SRes Lzma2Dec_Allocate(CLzma2Dec *p, Byte prop, ISzAllocPtr alloc)
{ {
Byte props[LZMA_PROPS_SIZE]; Byte props[LZMA_PROPS_SIZE];
RINOK(Lzma2Dec_GetOldProps(prop, props)); RINOK(Lzma2Dec_GetOldProps(prop, props));
@@ -105,16 +105,16 @@ static ELzma2State Lzma2Dec_UpdateState(CLzma2Dec *p, Byte b)
p->control = b; p->control = b;
PRF(printf("\n %4X ", (unsigned)p->decoder.dicPos)); PRF(printf("\n %4X ", (unsigned)p->decoder.dicPos));
PRF(printf(" %2X", (unsigned)b)); PRF(printf(" %2X", (unsigned)b));
if (p->control == 0) if (b == 0)
return LZMA2_STATE_FINISHED; return LZMA2_STATE_FINISHED;
if (LZMA2_IS_UNCOMPRESSED_STATE(p)) if (LZMA2_IS_UNCOMPRESSED_STATE(p))
{ {
if ((p->control & 0x7F) > 2) if (b > 2)
return LZMA2_STATE_ERROR; return LZMA2_STATE_ERROR;
p->unpackSize = 0; p->unpackSize = 0;
} }
else else
p->unpackSize = (UInt32)(p->control & 0x1F) << 16; p->unpackSize = (UInt32)(b & 0x1F) << 16;
return LZMA2_STATE_UNPACK0; return LZMA2_STATE_UNPACK0;
case LZMA2_STATE_UNPACK0: case LZMA2_STATE_UNPACK0:
@@ -169,6 +169,7 @@ static void LzmaDec_UpdateWithUncompressed(CLzmaDec *p, const Byte *src, SizeT s
void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState); void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState);
SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit, SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit,
const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status) const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
{ {
@@ -176,12 +177,17 @@ SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit,
*srcLen = 0; *srcLen = 0;
*status = LZMA_STATUS_NOT_SPECIFIED; *status = LZMA_STATUS_NOT_SPECIFIED;
while (p->state != LZMA2_STATE_FINISHED) while (p->state != LZMA2_STATE_ERROR)
{ {
SizeT dicPos = p->decoder.dicPos; SizeT dicPos;
if (p->state == LZMA2_STATE_FINISHED)
{
*status = LZMA_STATUS_FINISHED_WITH_MARK;
return SZ_OK;
}
if (p->state == LZMA2_STATE_ERROR) dicPos = p->decoder.dicPos;
return SZ_ERROR_DATA;
if (dicPos == dicLimit && finishMode == LZMA_FINISH_ANY) if (dicPos == dicLimit && finishMode == LZMA_FINISH_ANY)
{ {
@@ -198,29 +204,25 @@ SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit,
} }
(*srcLen)++; (*srcLen)++;
p->state = Lzma2Dec_UpdateState(p, *src++); p->state = Lzma2Dec_UpdateState(p, *src++);
if (dicPos == dicLimit && p->state != LZMA2_STATE_FINISHED) if (dicPos == dicLimit && p->state != LZMA2_STATE_FINISHED)
{ break;
p->state = LZMA2_STATE_ERROR;
return SZ_ERROR_DATA;
}
continue; continue;
} }
{ {
SizeT destSizeCur = dicLimit - dicPos; SizeT inCur = inSize - *srcLen;
SizeT srcSizeCur = inSize - *srcLen; SizeT outCur = dicLimit - dicPos;
ELzmaFinishMode curFinishMode = LZMA_FINISH_ANY; ELzmaFinishMode curFinishMode = LZMA_FINISH_ANY;
if (p->unpackSize <= destSizeCur) if (outCur >= p->unpackSize)
{ {
destSizeCur = (SizeT)p->unpackSize; outCur = (SizeT)p->unpackSize;
curFinishMode = LZMA_FINISH_END; curFinishMode = LZMA_FINISH_END;
} }
if (LZMA2_IS_UNCOMPRESSED_STATE(p)) if (LZMA2_IS_UNCOMPRESSED_STATE(p))
{ {
if (*srcLen == inSize) if (inCur == 0)
{ {
*status = LZMA_STATUS_NEEDS_MORE_INPUT; *status = LZMA_STATUS_NEEDS_MORE_INPUT;
return SZ_OK; return SZ_OK;
@@ -232,33 +234,25 @@ SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit,
if (initDic) if (initDic)
p->needInitProp = p->needInitState = True; p->needInitProp = p->needInitState = True;
else if (p->needInitDic) else if (p->needInitDic)
{ break;
p->state = LZMA2_STATE_ERROR;
return SZ_ERROR_DATA;
}
p->needInitDic = False; p->needInitDic = False;
LzmaDec_InitDicAndState(&p->decoder, initDic, False); LzmaDec_InitDicAndState(&p->decoder, initDic, False);
} }
if (srcSizeCur > destSizeCur) if (inCur > outCur)
srcSizeCur = destSizeCur; inCur = outCur;
if (inCur == 0)
break;
if (srcSizeCur == 0) LzmaDec_UpdateWithUncompressed(&p->decoder, src, inCur);
{
p->state = LZMA2_STATE_ERROR;
return SZ_ERROR_DATA;
}
LzmaDec_UpdateWithUncompressed(&p->decoder, src, srcSizeCur); src += inCur;
*srcLen += inCur;
src += srcSizeCur; p->unpackSize -= (UInt32)inCur;
*srcLen += srcSizeCur;
p->unpackSize -= (UInt32)srcSizeCur;
p->state = (p->unpackSize == 0) ? LZMA2_STATE_CONTROL : LZMA2_STATE_DATA_CONT; p->state = (p->unpackSize == 0) ? LZMA2_STATE_CONTROL : LZMA2_STATE_DATA_CONT;
} }
else else
{ {
SizeT outSizeProcessed;
SRes res; SRes res;
if (p->state == LZMA2_STATE_DATA) if (p->state == LZMA2_STATE_DATA)
@@ -267,96 +261,98 @@ SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit,
Bool initDic = (mode == 3); Bool initDic = (mode == 3);
Bool initState = (mode != 0); Bool initState = (mode != 0);
if ((!initDic && p->needInitDic) || (!initState && p->needInitState)) if ((!initDic && p->needInitDic) || (!initState && p->needInitState))
{ break;
p->state = LZMA2_STATE_ERROR;
return SZ_ERROR_DATA;
}
LzmaDec_InitDicAndState(&p->decoder, initDic, initState); LzmaDec_InitDicAndState(&p->decoder, initDic, initState);
p->needInitDic = False; p->needInitDic = False;
p->needInitState = False; p->needInitState = False;
p->state = LZMA2_STATE_DATA_CONT; p->state = LZMA2_STATE_DATA_CONT;
} }
if (srcSizeCur > p->packSize) if (inCur > p->packSize)
srcSizeCur = (SizeT)p->packSize; inCur = (SizeT)p->packSize;
res = LzmaDec_DecodeToDic(&p->decoder, dicPos + destSizeCur, src, &srcSizeCur, curFinishMode, status); res = LzmaDec_DecodeToDic(&p->decoder, dicPos + outCur, src, &inCur, curFinishMode, status);
src += srcSizeCur; src += inCur;
*srcLen += srcSizeCur; *srcLen += inCur;
p->packSize -= (UInt32)srcSizeCur; p->packSize -= (UInt32)inCur;
outCur = p->decoder.dicPos - dicPos;
p->unpackSize -= (UInt32)outCur;
outSizeProcessed = p->decoder.dicPos - dicPos; if (res != 0)
p->unpackSize -= (UInt32)outSizeProcessed; break;
RINOK(res);
if (*status == LZMA_STATUS_NEEDS_MORE_INPUT) if (*status == LZMA_STATUS_NEEDS_MORE_INPUT)
return res; {
if (p->packSize == 0)
break;
return SZ_OK;
}
if (srcSizeCur == 0 && outSizeProcessed == 0) if (inCur == 0 && outCur == 0)
{ {
if (*status != LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK if (*status != LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
|| p->unpackSize != 0 || p->unpackSize != 0
|| p->packSize != 0) || p->packSize != 0)
{ break;
p->state = LZMA2_STATE_ERROR;
return SZ_ERROR_DATA;
}
p->state = LZMA2_STATE_CONTROL; p->state = LZMA2_STATE_CONTROL;
} }
if (*status == LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK) *status = LZMA_STATUS_NOT_SPECIFIED;
*status = LZMA_STATUS_NOT_FINISHED;
} }
} }
} }
*status = LZMA_STATUS_FINISHED_WITH_MARK; *status = LZMA_STATUS_NOT_SPECIFIED;
return SZ_OK; p->state = LZMA2_STATE_ERROR;
return SZ_ERROR_DATA;
} }
SRes Lzma2Dec_DecodeToBuf(CLzma2Dec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status) SRes Lzma2Dec_DecodeToBuf(CLzma2Dec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
{ {
SizeT outSize = *destLen, inSize = *srcLen; SizeT outSize = *destLen, inSize = *srcLen;
*srcLen = *destLen = 0; *srcLen = *destLen = 0;
for (;;) for (;;)
{ {
SizeT srcSizeCur = inSize, outSizeCur, dicPos; SizeT inCur = inSize, outCur, dicPos;
ELzmaFinishMode curFinishMode; ELzmaFinishMode curFinishMode;
SRes res; SRes res;
if (p->decoder.dicPos == p->decoder.dicBufSize) if (p->decoder.dicPos == p->decoder.dicBufSize)
p->decoder.dicPos = 0; p->decoder.dicPos = 0;
dicPos = p->decoder.dicPos; dicPos = p->decoder.dicPos;
if (outSize > p->decoder.dicBufSize - dicPos) curFinishMode = LZMA_FINISH_ANY;
outCur = p->decoder.dicBufSize - dicPos;
if (outCur >= outSize)
{ {
outSizeCur = p->decoder.dicBufSize; outCur = outSize;
curFinishMode = LZMA_FINISH_ANY;
}
else
{
outSizeCur = dicPos + outSize;
curFinishMode = finishMode; curFinishMode = finishMode;
} }
res = Lzma2Dec_DecodeToDic(p, outSizeCur, src, &srcSizeCur, curFinishMode, status); res = Lzma2Dec_DecodeToDic(p, dicPos + outCur, src, &inCur, curFinishMode, status);
src += srcSizeCur;
inSize -= srcSizeCur; src += inCur;
*srcLen += srcSizeCur; inSize -= inCur;
outSizeCur = p->decoder.dicPos - dicPos; *srcLen += inCur;
memcpy(dest, p->decoder.dic + dicPos, outSizeCur); outCur = p->decoder.dicPos - dicPos;
dest += outSizeCur; memcpy(dest, p->decoder.dic + dicPos, outCur);
outSize -= outSizeCur; dest += outCur;
*destLen += outSizeCur; outSize -= outCur;
*destLen += outCur;
if (res != 0) if (res != 0)
return res; return res;
if (outSizeCur == 0 || outSize == 0) if (outCur == 0 || outSize == 0)
return SZ_OK; return SZ_OK;
} }
} }
SRes Lzma2Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, SRes Lzma2Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
Byte prop, ELzmaFinishMode finishMode, ELzmaStatus *status, ISzAlloc *alloc) Byte prop, ELzmaFinishMode finishMode, ELzmaStatus *status, ISzAllocPtr alloc)
{ {
CLzma2Dec p; CLzma2Dec p;
SRes res; SRes res;

View File

@@ -1,5 +1,5 @@
/* Lzma2Dec.h -- LZMA2 Decoder /* Lzma2Dec.h -- LZMA2 Decoder
2015-05-13 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#ifndef __LZMA2_DEC_H #ifndef __LZMA2_DEC_H
#define __LZMA2_DEC_H #define __LZMA2_DEC_H
@@ -26,8 +26,8 @@ typedef struct
#define Lzma2Dec_FreeProbs(p, alloc) LzmaDec_FreeProbs(&(p)->decoder, alloc); #define Lzma2Dec_FreeProbs(p, alloc) LzmaDec_FreeProbs(&(p)->decoder, alloc);
#define Lzma2Dec_Free(p, alloc) LzmaDec_Free(&(p)->decoder, alloc); #define Lzma2Dec_Free(p, alloc) LzmaDec_Free(&(p)->decoder, alloc);
SRes Lzma2Dec_AllocateProbs(CLzma2Dec *p, Byte prop, ISzAlloc *alloc); SRes Lzma2Dec_AllocateProbs(CLzma2Dec *p, Byte prop, ISzAllocPtr alloc);
SRes Lzma2Dec_Allocate(CLzma2Dec *p, Byte prop, ISzAlloc *alloc); SRes Lzma2Dec_Allocate(CLzma2Dec *p, Byte prop, ISzAllocPtr alloc);
void Lzma2Dec_Init(CLzma2Dec *p); void Lzma2Dec_Init(CLzma2Dec *p);
@@ -73,7 +73,7 @@ Returns:
*/ */
SRes Lzma2Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, SRes Lzma2Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
Byte prop, ELzmaFinishMode finishMode, ELzmaStatus *status, ISzAlloc *alloc); Byte prop, ELzmaFinishMode finishMode, ELzmaStatus *status, ISzAllocPtr alloc);
EXTERN_C_END EXTERN_C_END

View File

@@ -1,5 +1,5 @@
/* Lzma2Enc.c -- LZMA2 Encoder /* Lzma2Enc.c -- LZMA2 Encoder
2015-10-04 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@@ -60,9 +60,9 @@ static SRes Lzma2EncInt_Init(CLzma2EncInt *p, const CLzma2EncProps *props)
} }
SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp, ISeqInStream *inStream, UInt32 keepWindowSize, SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp, ISeqInStream *inStream, UInt32 keepWindowSize,
ISzAlloc *alloc, ISzAlloc *allocBig); ISzAllocPtr alloc, ISzAllocPtr allocBig);
SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen, SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,
UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig); UInt32 keepWindowSize, ISzAllocPtr alloc, ISzAllocPtr allocBig);
SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit, SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,
Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize); Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize);
const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp); const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp);
@@ -126,7 +126,7 @@ static SRes Lzma2EncInt_EncodeSubblock(CLzma2EncInt *p, Byte *outBuf,
if (outStream) if (outStream)
{ {
*packSizeRes += destPos; *packSizeRes += destPos;
if (outStream->Write(outStream, outBuf, destPos) != destPos) if (ISeqOutStream_Write(outStream, outBuf, destPos) != destPos)
return SZ_ERROR_WRITE; return SZ_ERROR_WRITE;
destPos = 0; destPos = 0;
} }
@@ -162,7 +162,7 @@ static SRes Lzma2EncInt_EncodeSubblock(CLzma2EncInt *p, Byte *outBuf,
p->srcPos += unpackSize; p->srcPos += unpackSize;
if (outStream) if (outStream)
if (outStream->Write(outStream, outBuf, destPos) != destPos) if (ISeqOutStream_Write(outStream, outBuf, destPos) != destPos)
return SZ_ERROR_WRITE; return SZ_ERROR_WRITE;
*packSizeRes = destPos; *packSizeRes = destPos;
@@ -264,7 +264,7 @@ void Lzma2EncProps_Normalize(CLzma2EncProps *p)
static SRes Progress(ICompressProgress *p, UInt64 inSize, UInt64 outSize) static SRes Progress(ICompressProgress *p, UInt64 inSize, UInt64 outSize)
{ {
return (p && p->Progress(p, inSize, outSize) != SZ_OK) ? SZ_ERROR_PROGRESS : SZ_OK; return (p && ICompressProgress_Progress(p, inSize, outSize) != SZ_OK) ? SZ_ERROR_PROGRESS : SZ_OK;
} }
@@ -277,8 +277,8 @@ typedef struct
Byte *outBuf; Byte *outBuf;
ISzAlloc *alloc; ISzAllocPtr alloc;
ISzAlloc *allocBig; ISzAllocPtr allocBig;
CLzma2EncInt coders[NUM_MT_CODER_THREADS_MAX]; CLzma2EncInt coders[NUM_MT_CODER_THREADS_MAX];
@@ -299,7 +299,7 @@ static SRes Lzma2Enc_EncodeMt1(CLzma2EncInt *p, CLzma2Enc *mainEncoder,
if (!mainEncoder->outBuf) if (!mainEncoder->outBuf)
{ {
mainEncoder->outBuf = (Byte *)IAlloc_Alloc(mainEncoder->alloc, LZMA2_CHUNK_SIZE_COMPRESSED_MAX); mainEncoder->outBuf = (Byte *)ISzAlloc_Alloc(mainEncoder->alloc, LZMA2_CHUNK_SIZE_COMPRESSED_MAX);
if (!mainEncoder->outBuf) if (!mainEncoder->outBuf)
return SZ_ERROR_MEM; return SZ_ERROR_MEM;
} }
@@ -327,7 +327,7 @@ static SRes Lzma2Enc_EncodeMt1(CLzma2EncInt *p, CLzma2Enc *mainEncoder,
if (res == SZ_OK) if (res == SZ_OK)
{ {
Byte b = 0; Byte b = 0;
if (outStream->Write(outStream, &b, 1) != 1) if (ISeqOutStream_Write(outStream, &b, 1) != 1)
return SZ_ERROR_WRITE; return SZ_ERROR_WRITE;
} }
@@ -343,10 +343,10 @@ typedef struct
CLzma2Enc *lzma2Enc; CLzma2Enc *lzma2Enc;
} CMtCallbackImp; } CMtCallbackImp;
static SRes MtCallbackImp_Code(void *pp, unsigned index, Byte *dest, size_t *destSize, static SRes MtCallbackImp_Code(const IMtCoderCallback *pp, unsigned index, Byte *dest, size_t *destSize,
const Byte *src, size_t srcSize, int finished) const Byte *src, size_t srcSize, int finished)
{ {
CMtCallbackImp *imp = (CMtCallbackImp *)pp; CMtCallbackImp *imp = CONTAINER_FROM_VTBL(pp, CMtCallbackImp, funcTable);
CLzma2Enc *mainEncoder = imp->lzma2Enc; CLzma2Enc *mainEncoder = imp->lzma2Enc;
CLzma2EncInt *p = &mainEncoder->coders[index]; CLzma2EncInt *p = &mainEncoder->coders[index];
@@ -403,9 +403,9 @@ static SRes MtCallbackImp_Code(void *pp, unsigned index, Byte *dest, size_t *des
/* ---------- Lzma2Enc ---------- */ /* ---------- Lzma2Enc ---------- */
CLzma2EncHandle Lzma2Enc_Create(ISzAlloc *alloc, ISzAlloc *allocBig) CLzma2EncHandle Lzma2Enc_Create(ISzAllocPtr alloc, ISzAllocPtr allocBig)
{ {
CLzma2Enc *p = (CLzma2Enc *)alloc->Alloc(alloc, sizeof(CLzma2Enc)); CLzma2Enc *p = (CLzma2Enc *)ISzAlloc_Alloc(alloc, sizeof(CLzma2Enc));
if (!p) if (!p)
return NULL; return NULL;
Lzma2EncProps_Init(&p->props); Lzma2EncProps_Init(&p->props);
@@ -444,8 +444,8 @@ void Lzma2Enc_Destroy(CLzma2EncHandle pp)
MtCoder_Destruct(&p->mtCoder); MtCoder_Destruct(&p->mtCoder);
#endif #endif
IAlloc_Free(p->alloc, p->outBuf); ISzAlloc_Free(p->alloc, p->outBuf);
IAlloc_Free(p->alloc, pp); ISzAlloc_Free(p->alloc, pp);
} }
SRes Lzma2Enc_SetProps(CLzma2EncHandle pp, const CLzma2EncProps *props) SRes Lzma2Enc_SetProps(CLzma2EncHandle pp, const CLzma2EncProps *props)

View File

@@ -1,5 +1,5 @@
/* Lzma2Enc.h -- LZMA2 Encoder /* Lzma2Enc.h -- LZMA2 Encoder
2013-01-18 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#ifndef __LZMA2_ENC_H #ifndef __LZMA2_ENC_H
#define __LZMA2_ENC_H #define __LZMA2_ENC_H
@@ -33,7 +33,7 @@ Returns:
typedef void * CLzma2EncHandle; typedef void * CLzma2EncHandle;
CLzma2EncHandle Lzma2Enc_Create(ISzAlloc *alloc, ISzAlloc *allocBig); CLzma2EncHandle Lzma2Enc_Create(ISzAllocPtr alloc, ISzAllocPtr allocBig);
void Lzma2Enc_Destroy(CLzma2EncHandle p); void Lzma2Enc_Destroy(CLzma2EncHandle p);
SRes Lzma2Enc_SetProps(CLzma2EncHandle p, const CLzma2EncProps *props); SRes Lzma2Enc_SetProps(CLzma2EncHandle p, const CLzma2EncProps *props);
Byte Lzma2Enc_WriteProperties(CLzma2EncHandle p); Byte Lzma2Enc_WriteProperties(CLzma2EncHandle p);
@@ -54,7 +54,7 @@ Return code:
/* /*
SRes Lzma2Encode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen, SRes Lzma2Encode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
const CLzmaEncProps *props, Byte *propsEncoded, int writeEndMark, const CLzmaEncProps *props, Byte *propsEncoded, int writeEndMark,
ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig); ICompressProgress *progress, ISzAllocPtr alloc, ISzAllocPtr allocBig);
*/ */
EXTERN_C_END EXTERN_C_END

View File

@@ -1,5 +1,5 @@
/* LzmaDec.c -- LZMA Decoder /* LzmaDec.c -- LZMA Decoder
2016-05-16 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@@ -975,19 +975,19 @@ SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *sr
} }
} }
void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc) void LzmaDec_FreeProbs(CLzmaDec *p, ISzAllocPtr alloc)
{ {
alloc->Free(alloc, p->probs); ISzAlloc_Free(alloc, p->probs);
p->probs = NULL; p->probs = NULL;
} }
static void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc) static void LzmaDec_FreeDict(CLzmaDec *p, ISzAllocPtr alloc)
{ {
alloc->Free(alloc, p->dic); ISzAlloc_Free(alloc, p->dic);
p->dic = NULL; p->dic = NULL;
} }
void LzmaDec_Free(CLzmaDec *p, ISzAlloc *alloc) void LzmaDec_Free(CLzmaDec *p, ISzAllocPtr alloc)
{ {
LzmaDec_FreeProbs(p, alloc); LzmaDec_FreeProbs(p, alloc);
LzmaDec_FreeDict(p, alloc); LzmaDec_FreeDict(p, alloc);
@@ -1019,13 +1019,13 @@ SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)
return SZ_OK; return SZ_OK;
} }
static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc) static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAllocPtr alloc)
{ {
UInt32 numProbs = LzmaProps_GetNumProbs(propNew); UInt32 numProbs = LzmaProps_GetNumProbs(propNew);
if (!p->probs || numProbs != p->numProbs) if (!p->probs || numProbs != p->numProbs)
{ {
LzmaDec_FreeProbs(p, alloc); LzmaDec_FreeProbs(p, alloc);
p->probs = (CLzmaProb *)alloc->Alloc(alloc, numProbs * sizeof(CLzmaProb)); p->probs = (CLzmaProb *)ISzAlloc_Alloc(alloc, numProbs * sizeof(CLzmaProb));
p->numProbs = numProbs; p->numProbs = numProbs;
if (!p->probs) if (!p->probs)
return SZ_ERROR_MEM; return SZ_ERROR_MEM;
@@ -1033,7 +1033,7 @@ static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAl
return SZ_OK; return SZ_OK;
} }
SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc) SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAllocPtr alloc)
{ {
CLzmaProps propNew; CLzmaProps propNew;
RINOK(LzmaProps_Decode(&propNew, props, propsSize)); RINOK(LzmaProps_Decode(&propNew, props, propsSize));
@@ -1042,7 +1042,7 @@ SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, I
return SZ_OK; return SZ_OK;
} }
SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc) SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAllocPtr alloc)
{ {
CLzmaProps propNew; CLzmaProps propNew;
SizeT dicBufSize; SizeT dicBufSize;
@@ -1062,7 +1062,7 @@ SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAll
if (!p->dic || dicBufSize != p->dicBufSize) if (!p->dic || dicBufSize != p->dicBufSize)
{ {
LzmaDec_FreeDict(p, alloc); LzmaDec_FreeDict(p, alloc);
p->dic = (Byte *)alloc->Alloc(alloc, dicBufSize); p->dic = (Byte *)ISzAlloc_Alloc(alloc, dicBufSize);
if (!p->dic) if (!p->dic)
{ {
LzmaDec_FreeProbs(p, alloc); LzmaDec_FreeProbs(p, alloc);
@@ -1076,7 +1076,7 @@ SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAll
SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode, const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
ELzmaStatus *status, ISzAlloc *alloc) ELzmaStatus *status, ISzAllocPtr alloc)
{ {
CLzmaDec p; CLzmaDec p;
SRes res; SRes res;

View File

@@ -1,5 +1,5 @@
/* LzmaDec.h -- LZMA Decoder /* LzmaDec.h -- LZMA Decoder
2013-01-18 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#ifndef __LZMA_DEC_H #ifndef __LZMA_DEC_H
#define __LZMA_DEC_H #define __LZMA_DEC_H
@@ -129,11 +129,11 @@ LzmaDec_Allocate* can return:
SZ_ERROR_UNSUPPORTED - Unsupported properties SZ_ERROR_UNSUPPORTED - Unsupported properties
*/ */
SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc); SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAllocPtr alloc);
void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc); void LzmaDec_FreeProbs(CLzmaDec *p, ISzAllocPtr alloc);
SRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc); SRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAllocPtr alloc);
void LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc); void LzmaDec_Free(CLzmaDec *state, ISzAllocPtr alloc);
/* ---------- Dictionary Interface ---------- */ /* ---------- Dictionary Interface ---------- */
@@ -220,7 +220,7 @@ Returns:
SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode, const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
ELzmaStatus *status, ISzAlloc *alloc); ELzmaStatus *status, ISzAllocPtr alloc);
EXTERN_C_END EXTERN_C_END

View File

@@ -1,5 +1,5 @@
/* LzmaEnc.c -- LZMA Encoder /* LzmaEnc.c -- LZMA Encoder
2016-05-16 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@@ -512,11 +512,11 @@ static void RangeEnc_Construct(CRangeEnc *p)
#define RangeEnc_GetProcessed(p) ((p)->processed + ((p)->buf - (p)->bufBase) + (p)->cacheSize) #define RangeEnc_GetProcessed(p) ((p)->processed + ((p)->buf - (p)->bufBase) + (p)->cacheSize)
#define RC_BUF_SIZE (1 << 16) #define RC_BUF_SIZE (1 << 16)
static int RangeEnc_Alloc(CRangeEnc *p, ISzAlloc *alloc) static int RangeEnc_Alloc(CRangeEnc *p, ISzAllocPtr alloc)
{ {
if (!p->bufBase) if (!p->bufBase)
{ {
p->bufBase = (Byte *)alloc->Alloc(alloc, RC_BUF_SIZE); p->bufBase = (Byte *)ISzAlloc_Alloc(alloc, RC_BUF_SIZE);
if (!p->bufBase) if (!p->bufBase)
return 0; return 0;
p->bufLim = p->bufBase + RC_BUF_SIZE; p->bufLim = p->bufBase + RC_BUF_SIZE;
@@ -524,9 +524,9 @@ static int RangeEnc_Alloc(CRangeEnc *p, ISzAlloc *alloc)
return 1; return 1;
} }
static void RangeEnc_Free(CRangeEnc *p, ISzAlloc *alloc) static void RangeEnc_Free(CRangeEnc *p, ISzAllocPtr alloc)
{ {
alloc->Free(alloc, p->bufBase); ISzAlloc_Free(alloc, p->bufBase);
p->bufBase = 0; p->bufBase = 0;
} }
@@ -550,7 +550,7 @@ static void RangeEnc_FlushStream(CRangeEnc *p)
if (p->res != SZ_OK) if (p->res != SZ_OK)
return; return;
num = p->buf - p->bufBase; num = p->buf - p->bufBase;
if (num != p->outStream->Write(p->outStream, p->bufBase, num)) if (num != ISeqOutStream_Write(p->outStream, p->bufBase, num))
p->res = SZ_ERROR_WRITE; p->res = SZ_ERROR_WRITE;
p->processed += num; p->processed += num;
p->buf = p->bufBase; p->buf = p->bufBase;
@@ -882,7 +882,7 @@ static UInt32 ReadMatchDistances(CLzmaEnc *p, UInt32 *numDistancePairsRes)
if (numPairs > 0) if (numPairs > 0)
{ {
lenRes = p->matches[numPairs - 2]; lenRes = p->matches[(size_t)numPairs - 2];
if (lenRes == p->numFastBytes) if (lenRes == p->numFastBytes)
{ {
UInt32 numAvail = p->numAvail; UInt32 numAvail = p->numAvail;
@@ -891,7 +891,7 @@ static UInt32 ReadMatchDistances(CLzmaEnc *p, UInt32 *numDistancePairsRes)
{ {
const Byte *pbyCur = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1; const Byte *pbyCur = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
const Byte *pby = pbyCur + lenRes; const Byte *pby = pbyCur + lenRes;
ptrdiff_t dif = (ptrdiff_t)-1 - p->matches[numPairs - 1]; ptrdiff_t dif = (ptrdiff_t)-1 - p->matches[(size_t)numPairs - 1];
const Byte *pbyLim = pbyCur + numAvail; const Byte *pbyLim = pbyCur + numAvail;
for (; pby != pbyLim && *pby == pby[dif]; pby++); for (; pby != pbyLim && *pby == pby[dif]; pby++);
lenRes = (UInt32)(pby - pbyCur); lenRes = (UInt32)(pby - pbyCur);
@@ -939,7 +939,7 @@ static UInt32 GetPureRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 state, UInt32
static UInt32 GetRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 len, UInt32 state, UInt32 posState) static UInt32 GetRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 len, UInt32 state, UInt32 posState)
{ {
return p->repLenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN] + return p->repLenEnc.prices[posState][(size_t)len - LZMA_MATCH_LEN_MIN] +
GetPureRepPrice(p, repIndex, state, posState); GetPureRepPrice(p, repIndex, state, posState);
} }
@@ -956,9 +956,9 @@ static UInt32 Backward(CLzmaEnc *p, UInt32 *backRes, UInt32 cur)
p->opt[posMem].posPrev = posMem - 1; p->opt[posMem].posPrev = posMem - 1;
if (p->opt[cur].prev2) if (p->opt[cur].prev2)
{ {
p->opt[posMem - 1].prev1IsChar = False; p->opt[(size_t)posMem - 1].prev1IsChar = False;
p->opt[posMem - 1].posPrev = p->opt[cur].posPrev2; p->opt[(size_t)posMem - 1].posPrev = p->opt[cur].posPrev2;
p->opt[posMem - 1].backPrev = p->opt[cur].backPrev2; p->opt[(size_t)posMem - 1].backPrev = p->opt[cur].backPrev2;
} }
} }
{ {
@@ -1051,7 +1051,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
matches = p->matches; matches = p->matches;
if (mainLen >= p->numFastBytes) if (mainLen >= p->numFastBytes)
{ {
*backRes = matches[numPairs - 1] + LZMA_NUM_REPS; *backRes = matches[(size_t)numPairs - 1] + LZMA_NUM_REPS;
MovePos(p, mainLen - 1); MovePos(p, mainLen - 1);
return mainLen; return mainLen;
} }
@@ -1116,7 +1116,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
price = repMatchPrice + GetPureRepPrice(p, i, p->state, posState); price = repMatchPrice + GetPureRepPrice(p, i, p->state, posState);
do do
{ {
UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][repLen - 2]; UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][(size_t)repLen - 2];
COptimal *opt = &p->opt[repLen]; COptimal *opt = &p->opt[repLen];
if (curAndLenPrice < opt->price) if (curAndLenPrice < opt->price)
{ {
@@ -1140,9 +1140,9 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
for (; ; len++) for (; ; len++)
{ {
COptimal *opt; COptimal *opt;
UInt32 distance = matches[offs + 1]; UInt32 distance = matches[(size_t)offs + 1];
UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN]; UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][(size_t)len - LZMA_MATCH_LEN_MIN];
UInt32 lenToPosState = GetLenToPosState(len); UInt32 lenToPosState = GetLenToPosState(len);
if (distance < kNumFullDistances) if (distance < kNumFullDistances)
curAndLenPrice += p->distancesPrices[lenToPosState][distance]; curAndLenPrice += p->distancesPrices[lenToPosState][distance];
@@ -1256,7 +1256,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
UInt32 i; UInt32 i;
reps[0] = prevOpt->backs[pos]; reps[0] = prevOpt->backs[pos];
for (i = 1; i <= pos; i++) for (i = 1; i <= pos; i++)
reps[i] = prevOpt->backs[i - 1]; reps[i] = prevOpt->backs[(size_t)i - 1];
for (; i < LZMA_NUM_REPS; i++) for (; i < LZMA_NUM_REPS; i++)
reps[i] = prevOpt->backs[i]; reps[i] = prevOpt->backs[i];
} }
@@ -1265,7 +1265,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
UInt32 i; UInt32 i;
reps[0] = (pos - LZMA_NUM_REPS); reps[0] = (pos - LZMA_NUM_REPS);
for (i = 1; i < LZMA_NUM_REPS; i++) for (i = 1; i < LZMA_NUM_REPS; i++)
reps[i] = prevOpt->backs[i - 1]; reps[i] = prevOpt->backs[(size_t)i - 1];
} }
} }
curOpt->state = (CState)state; curOpt->state = (CState)state;
@@ -1292,7 +1292,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
LitEnc_GetPrice(probs, curByte, p->ProbPrices)); LitEnc_GetPrice(probs, curByte, p->ProbPrices));
} }
nextOpt = &p->opt[cur + 1]; nextOpt = &p->opt[(size_t)cur + 1];
if (curAnd1Price < nextOpt->price) if (curAnd1Price < nextOpt->price)
{ {
@@ -1385,7 +1385,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
price = repMatchPrice + GetPureRepPrice(p, repIndex, state, posState); price = repMatchPrice + GetPureRepPrice(p, repIndex, state, posState);
do do
{ {
UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][lenTest - 2]; UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][(size_t)lenTest - 2];
COptimal *opt = &p->opt[cur + lenTest]; COptimal *opt = &p->opt[cur + lenTest];
if (curAndLenPrice < opt->price) if (curAndLenPrice < opt->price)
{ {
@@ -1415,9 +1415,9 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
UInt32 state2 = kRepNextStates[state]; UInt32 state2 = kRepNextStates[state];
UInt32 posStateNext = (position + lenTest) & p->pbMask; UInt32 posStateNext = (position + lenTest) & p->pbMask;
UInt32 curAndLenCharPrice = UInt32 curAndLenCharPrice =
price + p->repLenEnc.prices[posState][lenTest - 2] + price + p->repLenEnc.prices[posState][(size_t)lenTest - 2] +
GET_PRICE_0(p->isMatch[state2][posStateNext]) + GET_PRICE_0(p->isMatch[state2][posStateNext]) +
LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[lenTest - 1]), LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[(size_t)lenTest - 1]),
data[lenTest], data2[lenTest], p->ProbPrices); data[lenTest], data2[lenTest], p->ProbPrices);
state2 = kLiteralNextStates[state2]; state2 = kLiteralNextStates[state2];
posStateNext = (position + lenTest + 1) & p->pbMask; posStateNext = (position + lenTest + 1) & p->pbMask;
@@ -1468,11 +1468,11 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
offs = 0; offs = 0;
while (startLen > matches[offs]) while (startLen > matches[offs])
offs += 2; offs += 2;
curBack = matches[offs + 1]; curBack = matches[(size_t)offs + 1];
GetPosSlot2(curBack, posSlot); GetPosSlot2(curBack, posSlot);
for (lenTest = /*2*/ startLen; ; lenTest++) for (lenTest = /*2*/ startLen; ; lenTest++)
{ {
UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][lenTest - LZMA_MATCH_LEN_MIN]; UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][(size_t)lenTest - LZMA_MATCH_LEN_MIN];
{ {
UInt32 lenToPosState = GetLenToPosState(lenTest); UInt32 lenToPosState = GetLenToPosState(lenTest);
COptimal *opt; COptimal *opt;
@@ -1508,7 +1508,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
UInt32 posStateNext = (position + lenTest) & p->pbMask; UInt32 posStateNext = (position + lenTest) & p->pbMask;
UInt32 curAndLenCharPrice = curAndLenPrice + UInt32 curAndLenCharPrice = curAndLenPrice +
GET_PRICE_0(p->isMatch[state2][posStateNext]) + GET_PRICE_0(p->isMatch[state2][posStateNext]) +
LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[lenTest - 1]), LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[(size_t)lenTest - 1]),
data[lenTest], data2[lenTest], p->ProbPrices); data[lenTest], data2[lenTest], p->ProbPrices);
state2 = kLiteralNextStates[state2]; state2 = kLiteralNextStates[state2];
posStateNext = (posStateNext + 1) & p->pbMask; posStateNext = (posStateNext + 1) & p->pbMask;
@@ -1540,7 +1540,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
offs += 2; offs += 2;
if (offs == numPairs) if (offs == numPairs)
break; break;
curBack = matches[offs + 1]; curBack = matches[(size_t)offs + 1];
if (curBack >= kNumFullDistances) if (curBack >= kNumFullDistances)
GetPosSlot2(curBack, posSlot); GetPosSlot2(curBack, posSlot);
} }
@@ -1597,7 +1597,7 @@ static UInt32 GetOptimumFast(CLzmaEnc *p, UInt32 *backRes)
matches = p->matches; matches = p->matches;
if (mainLen >= p->numFastBytes) if (mainLen >= p->numFastBytes)
{ {
*backRes = matches[numPairs - 1] + LZMA_NUM_REPS; *backRes = matches[(size_t)numPairs - 1] + LZMA_NUM_REPS;
MovePos(p, mainLen - 1); MovePos(p, mainLen - 1);
return mainLen; return mainLen;
} }
@@ -1605,14 +1605,14 @@ static UInt32 GetOptimumFast(CLzmaEnc *p, UInt32 *backRes)
mainDist = 0; /* for GCC */ mainDist = 0; /* for GCC */
if (mainLen >= 2) if (mainLen >= 2)
{ {
mainDist = matches[numPairs - 1]; mainDist = matches[(size_t)numPairs - 1];
while (numPairs > 2 && mainLen == matches[numPairs - 4] + 1) while (numPairs > 2 && mainLen == matches[(size_t)numPairs - 4] + 1)
{ {
if (!ChangePair(matches[numPairs - 3], mainDist)) if (!ChangePair(matches[(size_t)numPairs - 3], mainDist))
break; break;
numPairs -= 2; numPairs -= 2;
mainLen = matches[numPairs - 2]; mainLen = matches[(size_t)numPairs - 2];
mainDist = matches[numPairs - 1]; mainDist = matches[(size_t)numPairs - 1];
} }
if (mainLen == 2 && mainDist >= 0x80) if (mainLen == 2 && mainDist >= 0x80)
mainLen = 1; mainLen = 1;
@@ -1634,7 +1634,7 @@ static UInt32 GetOptimumFast(CLzmaEnc *p, UInt32 *backRes)
p->longestMatchLength = ReadMatchDistances(p, &p->numPairs); p->longestMatchLength = ReadMatchDistances(p, &p->numPairs);
if (p->longestMatchLength >= 2) if (p->longestMatchLength >= 2)
{ {
UInt32 newDistance = matches[p->numPairs - 1]; UInt32 newDistance = matches[(size_t)p->numPairs - 1];
if ((p->longestMatchLength >= mainLen && newDistance < mainDist) || if ((p->longestMatchLength >= mainLen && newDistance < mainDist) ||
(p->longestMatchLength == mainLen + 1 && !ChangePair(mainDist, newDistance)) || (p->longestMatchLength == mainLen + 1 && !ChangePair(mainDist, newDistance)) ||
(p->longestMatchLength > mainLen + 1) || (p->longestMatchLength > mainLen + 1) ||
@@ -1762,24 +1762,24 @@ void LzmaEnc_Construct(CLzmaEnc *p)
p->saveState.litProbs = NULL; p->saveState.litProbs = NULL;
} }
CLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc) CLzmaEncHandle LzmaEnc_Create(ISzAllocPtr alloc)
{ {
void *p; void *p;
p = alloc->Alloc(alloc, sizeof(CLzmaEnc)); p = ISzAlloc_Alloc(alloc, sizeof(CLzmaEnc));
if (p) if (p)
LzmaEnc_Construct((CLzmaEnc *)p); LzmaEnc_Construct((CLzmaEnc *)p);
return p; return p;
} }
void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc) void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAllocPtr alloc)
{ {
alloc->Free(alloc, p->litProbs); ISzAlloc_Free(alloc, p->litProbs);
alloc->Free(alloc, p->saveState.litProbs); ISzAlloc_Free(alloc, p->saveState.litProbs);
p->litProbs = NULL; p->litProbs = NULL;
p->saveState.litProbs = NULL; p->saveState.litProbs = NULL;
} }
void LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig) void LzmaEnc_Destruct(CLzmaEnc *p, ISzAllocPtr alloc, ISzAllocPtr allocBig)
{ {
#ifndef _7ZIP_ST #ifndef _7ZIP_ST
MatchFinderMt_Destruct(&p->matchFinderMt, allocBig); MatchFinderMt_Destruct(&p->matchFinderMt, allocBig);
@@ -1790,10 +1790,10 @@ void LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig)
RangeEnc_Free(&p->rc, alloc); RangeEnc_Free(&p->rc, alloc);
} }
void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig) void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAllocPtr alloc, ISzAllocPtr allocBig)
{ {
LzmaEnc_Destruct((CLzmaEnc *)p, alloc, allocBig); LzmaEnc_Destruct((CLzmaEnc *)p, alloc, allocBig);
alloc->Free(alloc, p); ISzAlloc_Free(alloc, p);
} }
static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize, UInt32 maxUnpackSize) static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize, UInt32 maxUnpackSize)
@@ -1960,7 +1960,7 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize
#define kBigHashDicLimit ((UInt32)1 << 24) #define kBigHashDicLimit ((UInt32)1 << 24)
static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig) static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAllocPtr alloc, ISzAllocPtr allocBig)
{ {
UInt32 beforeSize = kNumOpts; UInt32 beforeSize = kNumOpts;
if (!RangeEnc_Alloc(&p->rc, alloc)) if (!RangeEnc_Alloc(&p->rc, alloc))
@@ -1975,8 +1975,8 @@ static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, I
if (!p->litProbs || !p->saveState.litProbs || p->lclp != lclp) if (!p->litProbs || !p->saveState.litProbs || p->lclp != lclp)
{ {
LzmaEnc_FreeLits(p, alloc); LzmaEnc_FreeLits(p, alloc);
p->litProbs = (CLzmaProb *)alloc->Alloc(alloc, ((UInt32)0x300 << lclp) * sizeof(CLzmaProb)); p->litProbs = (CLzmaProb *)ISzAlloc_Alloc(alloc, ((UInt32)0x300 << lclp) * sizeof(CLzmaProb));
p->saveState.litProbs = (CLzmaProb *)alloc->Alloc(alloc, ((UInt32)0x300 << lclp) * sizeof(CLzmaProb)); p->saveState.litProbs = (CLzmaProb *)ISzAlloc_Alloc(alloc, ((UInt32)0x300 << lclp) * sizeof(CLzmaProb));
if (!p->litProbs || !p->saveState.litProbs) if (!p->litProbs || !p->saveState.litProbs)
{ {
LzmaEnc_FreeLits(p, alloc); LzmaEnc_FreeLits(p, alloc);
@@ -2084,7 +2084,7 @@ void LzmaEnc_InitPrices(CLzmaEnc *p)
LenPriceEnc_UpdateTables(&p->repLenEnc, 1 << p->pb, p->ProbPrices); LenPriceEnc_UpdateTables(&p->repLenEnc, 1 << p->pb, p->ProbPrices);
} }
static SRes LzmaEnc_AllocAndInit(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig) static SRes LzmaEnc_AllocAndInit(CLzmaEnc *p, UInt32 keepWindowSize, ISzAllocPtr alloc, ISzAllocPtr allocBig)
{ {
UInt32 i; UInt32 i;
for (i = 0; i < (UInt32)kDicLogSizeMaxCompress; i++) for (i = 0; i < (UInt32)kDicLogSizeMaxCompress; i++)
@@ -2102,7 +2102,7 @@ static SRes LzmaEnc_AllocAndInit(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *a
} }
static SRes LzmaEnc_Prepare(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream, static SRes LzmaEnc_Prepare(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream,
ISzAlloc *alloc, ISzAlloc *allocBig) ISzAllocPtr alloc, ISzAllocPtr allocBig)
{ {
CLzmaEnc *p = (CLzmaEnc *)pp; CLzmaEnc *p = (CLzmaEnc *)pp;
p->matchFinderBase.stream = inStream; p->matchFinderBase.stream = inStream;
@@ -2113,7 +2113,7 @@ static SRes LzmaEnc_Prepare(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInS
SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp, SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp,
ISeqInStream *inStream, UInt32 keepWindowSize, ISeqInStream *inStream, UInt32 keepWindowSize,
ISzAlloc *alloc, ISzAlloc *allocBig) ISzAllocPtr alloc, ISzAllocPtr allocBig)
{ {
CLzmaEnc *p = (CLzmaEnc *)pp; CLzmaEnc *p = (CLzmaEnc *)pp;
p->matchFinderBase.stream = inStream; p->matchFinderBase.stream = inStream;
@@ -2129,7 +2129,7 @@ static void LzmaEnc_SetInputBuf(CLzmaEnc *p, const Byte *src, SizeT srcLen)
} }
SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen, SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,
UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig) UInt32 keepWindowSize, ISzAllocPtr alloc, ISzAllocPtr allocBig)
{ {
CLzmaEnc *p = (CLzmaEnc *)pp; CLzmaEnc *p = (CLzmaEnc *)pp;
LzmaEnc_SetInputBuf(p, src, srcLen); LzmaEnc_SetInputBuf(p, src, srcLen);
@@ -2158,9 +2158,9 @@ typedef struct
Bool overflow; Bool overflow;
} CSeqOutStreamBuf; } CSeqOutStreamBuf;
static size_t MyWrite(void *pp, const void *data, size_t size) static size_t MyWrite(const ISeqOutStream *pp, const void *data, size_t size)
{ {
CSeqOutStreamBuf *p = (CSeqOutStreamBuf *)pp; CSeqOutStreamBuf *p = CONTAINER_FROM_VTBL(pp, CSeqOutStreamBuf, funcTable);
if (p->rem < size) if (p->rem < size)
{ {
size = p->rem; size = p->rem;
@@ -2239,7 +2239,7 @@ static SRes LzmaEnc_Encode2(CLzmaEnc *p, ICompressProgress *progress)
break; break;
if (progress) if (progress)
{ {
res = progress->Progress(progress, p->nowPos64, RangeEnc_GetProcessed(&p->rc)); res = ICompressProgress_Progress(progress, p->nowPos64, RangeEnc_GetProcessed(&p->rc));
if (res != SZ_OK) if (res != SZ_OK)
{ {
res = SZ_ERROR_PROGRESS; res = SZ_ERROR_PROGRESS;
@@ -2251,7 +2251,7 @@ static SRes LzmaEnc_Encode2(CLzmaEnc *p, ICompressProgress *progress)
LzmaEnc_Finish(p); LzmaEnc_Finish(p);
/* /*
if (res == S_OK && !Inline_MatchFinder_IsFinishedOK(&p->matchFinderBase)) if (res == SZ_OK && !Inline_MatchFinder_IsFinishedOK(&p->matchFinderBase))
res = SZ_ERROR_FAIL; res = SZ_ERROR_FAIL;
} }
*/ */
@@ -2261,7 +2261,7 @@ static SRes LzmaEnc_Encode2(CLzmaEnc *p, ICompressProgress *progress)
SRes LzmaEnc_Encode(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress, SRes LzmaEnc_Encode(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress,
ISzAlloc *alloc, ISzAlloc *allocBig) ISzAllocPtr alloc, ISzAllocPtr allocBig)
{ {
RINOK(LzmaEnc_Prepare(pp, outStream, inStream, alloc, allocBig)); RINOK(LzmaEnc_Prepare(pp, outStream, inStream, alloc, allocBig));
return LzmaEnc_Encode2((CLzmaEnc *)pp, progress); return LzmaEnc_Encode2((CLzmaEnc *)pp, progress);
@@ -2296,8 +2296,14 @@ SRes LzmaEnc_WriteProperties(CLzmaEncHandle pp, Byte *props, SizeT *size)
} }
unsigned LzmaEnc_IsWriteEndMark(CLzmaEncHandle pp)
{
return ((CLzmaEnc *)pp)->writeEndMark;
}
SRes LzmaEnc_MemEncode(CLzmaEncHandle pp, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen, SRes LzmaEnc_MemEncode(CLzmaEncHandle pp, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig) int writeEndMark, ICompressProgress *progress, ISzAllocPtr alloc, ISzAllocPtr allocBig)
{ {
SRes res; SRes res;
CLzmaEnc *p = (CLzmaEnc *)pp; CLzmaEnc *p = (CLzmaEnc *)pp;
@@ -2330,7 +2336,7 @@ SRes LzmaEnc_MemEncode(CLzmaEncHandle pp, Byte *dest, SizeT *destLen, const Byte
SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen, SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark, const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig) ICompressProgress *progress, ISzAllocPtr alloc, ISzAllocPtr allocBig)
{ {
CLzmaEnc *p = (CLzmaEnc *)LzmaEnc_Create(alloc); CLzmaEnc *p = (CLzmaEnc *)LzmaEnc_Create(alloc);
SRes res; SRes res;

View File

@@ -1,5 +1,5 @@
/* LzmaEnc.h -- LZMA Encoder /* LzmaEnc.h -- LZMA Encoder
2013-01-18 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#ifndef __LZMA_ENC_H #ifndef __LZMA_ENC_H
#define __LZMA_ENC_H #define __LZMA_ENC_H
@@ -49,14 +49,15 @@ Returns:
typedef void * CLzmaEncHandle; typedef void * CLzmaEncHandle;
CLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc); CLzmaEncHandle LzmaEnc_Create(ISzAllocPtr alloc);
void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig); void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAllocPtr alloc, ISzAllocPtr allocBig);
SRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props); SRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props);
SRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size); SRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size);
unsigned LzmaEnc_IsWriteEndMark(CLzmaEncHandle p);
SRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream, SRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream,
ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig); ICompressProgress *progress, ISzAllocPtr alloc, ISzAllocPtr allocBig);
SRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen, SRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig); int writeEndMark, ICompressProgress *progress, ISzAllocPtr alloc, ISzAllocPtr allocBig);
/* ---------- One Call Interface ---------- */ /* ---------- One Call Interface ---------- */
@@ -71,7 +72,7 @@ Return code:
SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen, SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark, const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig); ICompressProgress *progress, ISzAllocPtr alloc, ISzAllocPtr allocBig);
EXTERN_C_END EXTERN_C_END

View File

@@ -1,5 +1,5 @@
/* MtCoder.c -- Multi-thread Coder /* MtCoder.c -- Multi-thread Coder
2015-10-13 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@@ -55,7 +55,7 @@ WRes LoopThread_WaitSubThread(CLoopThread *p) { return Event_Wait(&p->finishedEv
static SRes Progress(ICompressProgress *p, UInt64 inSize, UInt64 outSize) static SRes Progress(ICompressProgress *p, UInt64 inSize, UInt64 outSize)
{ {
return (p && p->Progress(p, inSize, outSize) != SZ_OK) ? SZ_ERROR_PROGRESS : SZ_OK; return (p && ICompressProgress_Progress(p, inSize, outSize) != SZ_OK) ? SZ_ERROR_PROGRESS : SZ_OK;
} }
static void MtProgress_Init(CMtProgress *p, ICompressProgress *progress) static void MtProgress_Init(CMtProgress *p, ICompressProgress *progress)
@@ -137,18 +137,18 @@ static void CMtThread_Destruct(CMtThread *p)
} }
if (p->mtCoder->alloc) if (p->mtCoder->alloc)
IAlloc_Free(p->mtCoder->alloc, p->outBuf); ISzAlloc_Free(p->mtCoder->alloc, p->outBuf);
p->outBuf = 0; p->outBuf = 0;
if (p->mtCoder->alloc) if (p->mtCoder->alloc)
IAlloc_Free(p->mtCoder->alloc, p->inBuf); ISzAlloc_Free(p->mtCoder->alloc, p->inBuf);
p->inBuf = 0; p->inBuf = 0;
} }
#define MY_BUF_ALLOC(buf, size, newSize) \ #define MY_BUF_ALLOC(buf, size, newSize) \
if (buf == 0 || size != newSize) \ if (buf == 0 || size != newSize) \
{ IAlloc_Free(p->mtCoder->alloc, buf); \ { ISzAlloc_Free(p->mtCoder->alloc, buf); \
size = newSize; buf = (Byte *)IAlloc_Alloc(p->mtCoder->alloc, size); \ size = newSize; buf = (Byte *)ISzAlloc_Alloc(p->mtCoder->alloc, size); \
if (buf == 0) return SZ_ERROR_MEM; } if (buf == 0) return SZ_ERROR_MEM; }
static SRes CMtThread_Prepare(CMtThread *p) static SRes CMtThread_Prepare(CMtThread *p)
@@ -171,7 +171,7 @@ static SRes FullRead(ISeqInStream *stream, Byte *data, size_t *processedSize)
while (size != 0) while (size != 0)
{ {
size_t curSize = size; size_t curSize = size;
SRes res = stream->Read(stream, data, &curSize); SRes res = ISeqInStream_Read(stream, data, &curSize);
*processedSize += curSize; *processedSize += curSize;
data += curSize; data += curSize;
size -= curSize; size -= curSize;
@@ -208,7 +208,7 @@ static SRes MtThread_Process(CMtThread *p, Bool *stop)
if (Event_Set(&next->canRead) != 0) if (Event_Set(&next->canRead) != 0)
return SZ_ERROR_THREAD; return SZ_ERROR_THREAD;
RINOK(p->mtCoder->mtCallback->Code(p->mtCoder->mtCallback, p->index, RINOK(IMtCoderCallback_Code(p->mtCoder->mtCallback, p->index,
p->outBuf, &destSize, p->inBuf, size, *stop)); p->outBuf, &destSize, p->inBuf, size, *stop));
MtProgress_Reinit(&p->mtCoder->mtProgress, p->index); MtProgress_Reinit(&p->mtCoder->mtProgress, p->index);
@@ -217,7 +217,7 @@ static SRes MtThread_Process(CMtThread *p, Bool *stop)
return SZ_ERROR_THREAD; return SZ_ERROR_THREAD;
if (p->stopWriting) if (p->stopWriting)
return SZ_ERROR_FAIL; return SZ_ERROR_FAIL;
if (p->mtCoder->outStream->Write(p->mtCoder->outStream, p->outBuf, destSize) != destSize) if (ISeqOutStream_Write(p->mtCoder->outStream, p->outBuf, destSize) != destSize)
return SZ_ERROR_WRITE; return SZ_ERROR_WRITE;
return Event_Set(&next->canWrite) == 0 ? SZ_OK : SZ_ERROR_THREAD; return Event_Set(&next->canWrite) == 0 ? SZ_OK : SZ_ERROR_THREAD;
} }

View File

@@ -1,5 +1,5 @@
/* MtCoder.h -- Multi-thread Coder /* MtCoder.h -- Multi-thread Coder
2009-11-19 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#ifndef __MT_CODER_H #ifndef __MT_CODER_H
#define __MT_CODER_H #define __MT_CODER_H
@@ -64,11 +64,15 @@ typedef struct
CAutoResetEvent canWrite; CAutoResetEvent canWrite;
} CMtThread; } CMtThread;
typedef struct
typedef struct IMtCoderCallback IMtCoderCallback;
struct IMtCoderCallback
{ {
SRes (*Code)(void *p, unsigned index, Byte *dest, size_t *destSize, SRes (*Code)(const IMtCoderCallback *p, unsigned index, Byte *dest, size_t *destSize,
const Byte *src, size_t srcSize, int finished); const Byte *src, size_t srcSize, int finished);
} IMtCoderCallback; };
#define IMtCoderCallback_Code(p, index, dest, destSize, src, srcSize, finished) (p)->Code(p, index, dest, destSize, src, srcSize, finished)
typedef struct _CMtCoder typedef struct _CMtCoder
{ {
@@ -79,7 +83,7 @@ typedef struct _CMtCoder
ISeqInStream *inStream; ISeqInStream *inStream;
ISeqOutStream *outStream; ISeqOutStream *outStream;
ICompressProgress *progress; ICompressProgress *progress;
ISzAlloc *alloc; ISzAllocPtr alloc;
IMtCoderCallback *mtCallback; IMtCoderCallback *mtCallback;
CCriticalSection cs; CCriticalSection cs;

View File

@@ -1,5 +1,5 @@
/* Ppmd.h -- PPMD codec common code /* Ppmd.h -- PPMD codec common code
2016-05-16 : Igor Pavlov : Public domain 2017-04-03 : Igor Pavlov : Public domain
This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */ This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
#ifndef __PPMD_H #ifndef __PPMD_H
@@ -77,7 +77,7 @@ typedef
CPpmd_Byte_Ref; CPpmd_Byte_Ref;
#define PPMD_SetAllBitsIn256Bytes(p) \ #define PPMD_SetAllBitsIn256Bytes(p) \
{ unsigned z; for (z = 0; z < 256 / sizeof(p[0]); z += 8) { \ { size_t 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; }} 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 EXTERN_C_END

View File

@@ -1,5 +1,5 @@
/* Ppmd7.c -- PPMdH codec /* Ppmd7.c -- PPMdH codec
2016-05-21 : Igor Pavlov : Public domain 2017-04-03 : Igor Pavlov : Public domain
This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */ This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
#include "Precomp.h" #include "Precomp.h"
@@ -15,7 +15,7 @@ static const UInt16 kInitBinEsc[] = { 0x3CDD, 0x1F3F, 0x59BF, 0x48F3, 0x64A1, 0x
#define UNIT_SIZE 12 #define UNIT_SIZE 12
#define U2B(nu) ((UInt32)(nu) * UNIT_SIZE) #define U2B(nu) ((UInt32)(nu) * UNIT_SIZE)
#define U2I(nu) (p->Units2Indx[(nu) - 1]) #define U2I(nu) (p->Units2Indx[(size_t)(nu) - 1])
#define I2U(indx) (p->Indx2Units[indx]) #define I2U(indx) (p->Indx2Units[indx])
#ifdef PPMD_32BIT #ifdef PPMD_32BIT
@@ -88,29 +88,31 @@ void Ppmd7_Construct(CPpmd7 *p)
memset(p->HB2Flag + 0x40, 8, 0x100 - 0x40); memset(p->HB2Flag + 0x40, 8, 0x100 - 0x40);
} }
void Ppmd7_Free(CPpmd7 *p, ISzAlloc *alloc) void Ppmd7_Free(CPpmd7 *p, ISzAllocPtr alloc)
{ {
alloc->Free(alloc, p->Base); ISzAlloc_Free(alloc, p->Base);
p->Size = 0; p->Size = 0;
p->Base = 0; p->Base = 0;
} }
Bool Ppmd7_Alloc(CPpmd7 *p, UInt32 size, ISzAlloc *alloc) Bool Ppmd7_Alloc(CPpmd7 *p, UInt32 size, ISzAllocPtr alloc)
{ {
if (p->Base == 0 || p->Size != size) if (!p->Base || p->Size != size)
{ {
size_t size2;
Ppmd7_Free(p, alloc); Ppmd7_Free(p, alloc);
size2 = 0
#ifndef PPMD_32BIT
+ UNIT_SIZE
#endif
;
p->AlignOffset = p->AlignOffset =
#ifdef PPMD_32BIT #ifdef PPMD_32BIT
(4 - size) & 3; (4 - size) & 3;
#else #else
4 - (size & 3); 4 - (size & 3);
#endif #endif
if ((p->Base = (Byte *)alloc->Alloc(alloc, p->AlignOffset + size if ((p->Base = (Byte *)ISzAlloc_Alloc(alloc, p->AlignOffset + size + size2)) == 0)
#ifndef PPMD_32BIT
+ UNIT_SIZE
#endif
)) == 0)
return False; return False;
p->Size = size; p->Size = size;
} }
@@ -513,7 +515,7 @@ static void UpdateModel(CPpmd7 *p)
/* Expand for one UNIT */ /* Expand for one UNIT */
unsigned oldNU = ns1 >> 1; unsigned oldNU = ns1 >> 1;
unsigned i = U2I(oldNU); unsigned i = U2I(oldNU);
if (i != U2I(oldNU + 1)) if (i != U2I((size_t)oldNU + 1))
{ {
void *ptr = AllocUnits(p, i + 1); void *ptr = AllocUnits(p, i + 1);
void *oldPtr; void *oldPtr;
@@ -639,7 +641,7 @@ CPpmd_See *Ppmd7_MakeEscFreq(CPpmd7 *p, unsigned numMasked, UInt32 *escFreq)
unsigned nonMasked = p->MinContext->NumStats - numMasked; unsigned nonMasked = p->MinContext->NumStats - numMasked;
if (p->MinContext->NumStats != 256) if (p->MinContext->NumStats != 256)
{ {
see = p->See[(unsigned)p->NS2Indx[nonMasked - 1]] + see = p->See[(unsigned)p->NS2Indx[(size_t)nonMasked - 1]] +
(nonMasked < (unsigned)SUFFIX(p->MinContext)->NumStats - p->MinContext->NumStats) + (nonMasked < (unsigned)SUFFIX(p->MinContext)->NumStats - p->MinContext->NumStats) +
2 * (unsigned)(p->MinContext->SummFreq < 11 * p->MinContext->NumStats) + 2 * (unsigned)(p->MinContext->SummFreq < 11 * p->MinContext->NumStats) +
4 * (unsigned)(numMasked > nonMasked) + 4 * (unsigned)(numMasked > nonMasked) +

View File

@@ -1,5 +1,5 @@
/* Ppmd7.h -- PPMdH compression codec /* Ppmd7.h -- PPMdH compression codec
2016-05-21 : Igor Pavlov : Public domain 2017-04-03 : Igor Pavlov : Public domain
This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */ This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
/* This code supports virtual RangeDecoder and includes the implementation /* This code supports virtual RangeDecoder and includes the implementation
@@ -60,8 +60,8 @@ typedef struct
} CPpmd7; } CPpmd7;
void Ppmd7_Construct(CPpmd7 *p); void Ppmd7_Construct(CPpmd7 *p);
Bool Ppmd7_Alloc(CPpmd7 *p, UInt32 size, ISzAlloc *alloc); Bool Ppmd7_Alloc(CPpmd7 *p, UInt32 size, ISzAllocPtr alloc);
void Ppmd7_Free(CPpmd7 *p, ISzAlloc *alloc); void Ppmd7_Free(CPpmd7 *p, ISzAllocPtr alloc);
void Ppmd7_Init(CPpmd7 *p, unsigned maxOrder); void Ppmd7_Init(CPpmd7 *p, unsigned maxOrder);
#define Ppmd7_WasAllocated(p) ((p)->Base != NULL) #define Ppmd7_WasAllocated(p) ((p)->Base != NULL)
@@ -86,8 +86,8 @@ void Ppmd7_Update2(CPpmd7 *p);
void Ppmd7_UpdateBin(CPpmd7 *p); void Ppmd7_UpdateBin(CPpmd7 *p);
#define Ppmd7_GetBinSumm(p) \ #define Ppmd7_GetBinSumm(p) \
&p->BinSumm[(unsigned)Ppmd7Context_OneState(p->MinContext)->Freq - 1][p->PrevSuccess + \ &p->BinSumm[(size_t)(unsigned)Ppmd7Context_OneState(p->MinContext)->Freq - 1][p->PrevSuccess + \
p->NS2BSIndx[Ppmd7_GetContext(p, p->MinContext->Suffix)->NumStats - 1] + \ p->NS2BSIndx[(size_t)Ppmd7_GetContext(p, p->MinContext->Suffix)->NumStats - 1] + \
(p->HiBitsFlag = p->HB2Flag[p->FoundState->Symbol]) + \ (p->HiBitsFlag = p->HB2Flag[p->FoundState->Symbol]) + \
2 * p->HB2Flag[(unsigned)Ppmd7Context_OneState(p->MinContext)->Symbol] + \ 2 * p->HB2Flag[(unsigned)Ppmd7Context_OneState(p->MinContext)->Symbol] + \
((p->RunLength >> 26) & 0x20)] ((p->RunLength >> 26) & 0x20)]
@@ -97,16 +97,18 @@ CPpmd_See *Ppmd7_MakeEscFreq(CPpmd7 *p, unsigned numMasked, UInt32 *scale);
/* ---------- Decode ---------- */ /* ---------- Decode ---------- */
typedef struct typedef struct IPpmd7_RangeDec IPpmd7_RangeDec;
struct IPpmd7_RangeDec
{ {
UInt32 (*GetThreshold)(void *p, UInt32 total); UInt32 (*GetThreshold)(const IPpmd7_RangeDec *p, UInt32 total);
void (*Decode)(void *p, UInt32 start, UInt32 size); void (*Decode)(const IPpmd7_RangeDec *p, UInt32 start, UInt32 size);
UInt32 (*DecodeBit)(void *p, UInt32 size0); UInt32 (*DecodeBit)(const IPpmd7_RangeDec *p, UInt32 size0);
} IPpmd7_RangeDec; };
typedef struct typedef struct
{ {
IPpmd7_RangeDec p; IPpmd7_RangeDec vt;
UInt32 Range; UInt32 Range;
UInt32 Code; UInt32 Code;
IByteIn *Stream; IByteIn *Stream;
@@ -116,7 +118,7 @@ void Ppmd7z_RangeDec_CreateVTable(CPpmd7z_RangeDec *p);
Bool Ppmd7z_RangeDec_Init(CPpmd7z_RangeDec *p); Bool Ppmd7z_RangeDec_Init(CPpmd7z_RangeDec *p);
#define Ppmd7z_RangeDec_IsFinishedOK(p) ((p)->Code == 0) #define Ppmd7z_RangeDec_IsFinishedOK(p) ((p)->Code == 0)
int Ppmd7_DecodeSymbol(CPpmd7 *p, IPpmd7_RangeDec *rc); int Ppmd7_DecodeSymbol(CPpmd7 *p, const IPpmd7_RangeDec *rc);
/* ---------- Encode ---------- */ /* ---------- Encode ---------- */

View File

@@ -1,5 +1,5 @@
/* Ppmd7Dec.c -- PPMdH Decoder /* Ppmd7Dec.c -- PPMdH Decoder
2010-03-12 : Igor Pavlov : Public domain 2017-04-03 : Igor Pavlov : Public domain
This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */ This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
#include "Precomp.h" #include "Precomp.h"
@@ -13,44 +13,46 @@ Bool Ppmd7z_RangeDec_Init(CPpmd7z_RangeDec *p)
unsigned i; unsigned i;
p->Code = 0; p->Code = 0;
p->Range = 0xFFFFFFFF; p->Range = 0xFFFFFFFF;
if (p->Stream->Read((void *)p->Stream) != 0) if (IByteIn_Read(p->Stream) != 0)
return False; return False;
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
p->Code = (p->Code << 8) | p->Stream->Read((void *)p->Stream); p->Code = (p->Code << 8) | IByteIn_Read(p->Stream);
return (p->Code < 0xFFFFFFFF); return (p->Code < 0xFFFFFFFF);
} }
static UInt32 Range_GetThreshold(void *pp, UInt32 total) #define GET_Ppmd7z_RangeDec CPpmd7z_RangeDec *p = CONTAINER_FROM_VTBL(pp, CPpmd7z_RangeDec, vt);
static UInt32 Range_GetThreshold(const IPpmd7_RangeDec *pp, UInt32 total)
{ {
CPpmd7z_RangeDec *p = (CPpmd7z_RangeDec *)pp; GET_Ppmd7z_RangeDec
return (p->Code) / (p->Range /= total); return p->Code / (p->Range /= total);
} }
static void Range_Normalize(CPpmd7z_RangeDec *p) static void Range_Normalize(CPpmd7z_RangeDec *p)
{ {
if (p->Range < kTopValue) if (p->Range < kTopValue)
{ {
p->Code = (p->Code << 8) | p->Stream->Read((void *)p->Stream); p->Code = (p->Code << 8) | IByteIn_Read(p->Stream);
p->Range <<= 8; p->Range <<= 8;
if (p->Range < kTopValue) if (p->Range < kTopValue)
{ {
p->Code = (p->Code << 8) | p->Stream->Read((void *)p->Stream); p->Code = (p->Code << 8) | IByteIn_Read(p->Stream);
p->Range <<= 8; p->Range <<= 8;
} }
} }
} }
static void Range_Decode(void *pp, UInt32 start, UInt32 size) static void Range_Decode(const IPpmd7_RangeDec *pp, UInt32 start, UInt32 size)
{ {
CPpmd7z_RangeDec *p = (CPpmd7z_RangeDec *)pp; GET_Ppmd7z_RangeDec
p->Code -= start * p->Range; p->Code -= start * p->Range;
p->Range *= size; p->Range *= size;
Range_Normalize(p); Range_Normalize(p);
} }
static UInt32 Range_DecodeBit(void *pp, UInt32 size0) static UInt32 Range_DecodeBit(const IPpmd7_RangeDec *pp, UInt32 size0)
{ {
CPpmd7z_RangeDec *p = (CPpmd7z_RangeDec *)pp; GET_Ppmd7z_RangeDec
UInt32 newBound = (p->Range >> 14) * size0; UInt32 newBound = (p->Range >> 14) * size0;
UInt32 symbol; UInt32 symbol;
if (p->Code < newBound) if (p->Code < newBound)
@@ -70,15 +72,15 @@ static UInt32 Range_DecodeBit(void *pp, UInt32 size0)
void Ppmd7z_RangeDec_CreateVTable(CPpmd7z_RangeDec *p) void Ppmd7z_RangeDec_CreateVTable(CPpmd7z_RangeDec *p)
{ {
p->p.GetThreshold = Range_GetThreshold; p->vt.GetThreshold = Range_GetThreshold;
p->p.Decode = Range_Decode; p->vt.Decode = Range_Decode;
p->p.DecodeBit = Range_DecodeBit; p->vt.DecodeBit = Range_DecodeBit;
} }
#define MASK(sym) ((signed char *)charMask)[sym] #define MASK(sym) ((signed char *)charMask)[sym]
int Ppmd7_DecodeSymbol(CPpmd7 *p, IPpmd7_RangeDec *rc) int Ppmd7_DecodeSymbol(CPpmd7 *p, const IPpmd7_RangeDec *rc)
{ {
size_t charMask[256 / sizeof(size_t)]; size_t charMask[256 / sizeof(size_t)];
if (p->MinContext->NumStats != 1) if (p->MinContext->NumStats != 1)

View File

@@ -1,5 +1,5 @@
/* Ppmd7Enc.c -- PPMdH Encoder /* Ppmd7Enc.c -- PPMdH Encoder
2015-09-28 : Igor Pavlov : Public domain 2017-04-03 : Igor Pavlov : Public domain
This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */ This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
#include "Precomp.h" #include "Precomp.h"
@@ -23,7 +23,7 @@ static void RangeEnc_ShiftLow(CPpmd7z_RangeEnc *p)
Byte temp = p->Cache; Byte temp = p->Cache;
do do
{ {
p->Stream->Write(p->Stream, (Byte)(temp + (Byte)(p->Low >> 32))); IByteOut_Write(p->Stream, (Byte)(temp + (Byte)(p->Low >> 32)));
temp = 0xFF; temp = 0xFF;
} }
while (--p->CacheSize != 0); while (--p->CacheSize != 0);

View File

@@ -1,5 +1,5 @@
/* Ppmd8.c -- PPMdI codec /* Ppmd8.c -- PPMdI codec
2016-05-21 : Igor Pavlov : Public domain 2017-04-03 : Igor Pavlov : Public domain
This code is based on PPMd var.I (2002): Dmitry Shkarin : Public domain */ This code is based on PPMd var.I (2002): Dmitry Shkarin : Public domain */
#include "Precomp.h" #include "Precomp.h"
@@ -15,7 +15,7 @@ static const UInt16 kInitBinEsc[] = { 0x3CDD, 0x1F3F, 0x59BF, 0x48F3, 0x64A1, 0x
#define UNIT_SIZE 12 #define UNIT_SIZE 12
#define U2B(nu) ((UInt32)(nu) * UNIT_SIZE) #define U2B(nu) ((UInt32)(nu) * UNIT_SIZE)
#define U2I(nu) (p->Units2Indx[(nu) - 1]) #define U2I(nu) (p->Units2Indx[(size_t)(nu) - 1])
#define I2U(indx) (p->Indx2Units[indx]) #define I2U(indx) (p->Indx2Units[indx])
#ifdef PPMD_32BIT #ifdef PPMD_32BIT
@@ -86,16 +86,16 @@ void Ppmd8_Construct(CPpmd8 *p)
} }
} }
void Ppmd8_Free(CPpmd8 *p, ISzAlloc *alloc) void Ppmd8_Free(CPpmd8 *p, ISzAllocPtr alloc)
{ {
alloc->Free(alloc, p->Base); ISzAlloc_Free(alloc, p->Base);
p->Size = 0; p->Size = 0;
p->Base = 0; p->Base = 0;
} }
Bool Ppmd8_Alloc(CPpmd8 *p, UInt32 size, ISzAlloc *alloc) Bool Ppmd8_Alloc(CPpmd8 *p, UInt32 size, ISzAllocPtr alloc)
{ {
if (p->Base == 0 || p->Size != size) if (!p->Base || p->Size != size)
{ {
Ppmd8_Free(p, alloc); Ppmd8_Free(p, alloc);
p->AlignOffset = p->AlignOffset =
@@ -104,7 +104,7 @@ Bool Ppmd8_Alloc(CPpmd8 *p, UInt32 size, ISzAlloc *alloc)
#else #else
4 - (size & 3); 4 - (size & 3);
#endif #endif
if ((p->Base = (Byte *)alloc->Alloc(alloc, p->AlignOffset + size)) == 0) if ((p->Base = (Byte *)ISzAlloc_Alloc(alloc, p->AlignOffset + size)) == 0)
return False; return False;
p->Size = size; p->Size = size;
} }
@@ -386,7 +386,7 @@ static void RestartModel(CPpmd8 *p)
for (i = m = 0; m < 24; m++) for (i = m = 0; m < 24; m++)
{ {
while (p->NS2Indx[i + 3] == m + 3) while (p->NS2Indx[(size_t)i + 3] == m + 3)
i++; i++;
for (k = 0; k < 32; k++) for (k = 0; k < 32; k++)
{ {
@@ -905,7 +905,7 @@ static void UpdateModel(CPpmd8 *p)
/* Expand for one UNIT */ /* Expand for one UNIT */
unsigned oldNU = (ns1 + 1) >> 1; unsigned oldNU = (ns1 + 1) >> 1;
unsigned i = U2I(oldNU); unsigned i = U2I(oldNU);
if (i != U2I(oldNU + 1)) if (i != U2I((size_t)oldNU + 1))
{ {
void *ptr = AllocUnits(p, i + 1); void *ptr = AllocUnits(p, i + 1);
void *oldPtr; void *oldPtr;
@@ -1038,7 +1038,7 @@ CPpmd_See *Ppmd8_MakeEscFreq(CPpmd8 *p, unsigned numMasked1, UInt32 *escFreq)
CPpmd_See *see; CPpmd_See *see;
if (p->MinContext->NumStats != 0xFF) if (p->MinContext->NumStats != 0xFF)
{ {
see = p->See[(unsigned)p->NS2Indx[(unsigned)p->MinContext->NumStats + 2] - 3] + see = p->See[(size_t)(unsigned)p->NS2Indx[(size_t)(unsigned)p->MinContext->NumStats + 2] - 3] +
(p->MinContext->SummFreq > 11 * ((unsigned)p->MinContext->NumStats + 1)) + (p->MinContext->SummFreq > 11 * ((unsigned)p->MinContext->NumStats + 1)) +
2 * (unsigned)(2 * (unsigned)p->MinContext->NumStats < 2 * (unsigned)(2 * (unsigned)p->MinContext->NumStats <
((unsigned)SUFFIX(p->MinContext)->NumStats + numMasked1)) + ((unsigned)SUFFIX(p->MinContext)->NumStats + numMasked1)) +

View File

@@ -1,5 +1,5 @@
/* Ppmd8.h -- PPMdI codec /* Ppmd8.h -- PPMdI codec
2011-01-27 : Igor Pavlov : Public domain 2017-04-03 : Igor Pavlov : Public domain
This code is based on: This code is based on:
PPMd var.I (2002): Dmitry Shkarin : Public domain PPMd var.I (2002): Dmitry Shkarin : Public domain
Carryless rangecoder (1999): Dmitry Subbotin : Public domain */ Carryless rangecoder (1999): Dmitry Subbotin : Public domain */
@@ -86,8 +86,8 @@ typedef struct
} CPpmd8; } CPpmd8;
void Ppmd8_Construct(CPpmd8 *p); void Ppmd8_Construct(CPpmd8 *p);
Bool Ppmd8_Alloc(CPpmd8 *p, UInt32 size, ISzAlloc *alloc); Bool Ppmd8_Alloc(CPpmd8 *p, UInt32 size, ISzAllocPtr alloc);
void Ppmd8_Free(CPpmd8 *p, ISzAlloc *alloc); void Ppmd8_Free(CPpmd8 *p, ISzAllocPtr alloc);
void Ppmd8_Init(CPpmd8 *p, unsigned maxOrder, unsigned restoreMethod); void Ppmd8_Init(CPpmd8 *p, unsigned maxOrder, unsigned restoreMethod);
#define Ppmd8_WasAllocated(p) ((p)->Base != NULL) #define Ppmd8_WasAllocated(p) ((p)->Base != NULL)
@@ -112,7 +112,7 @@ void Ppmd8_Update2(CPpmd8 *p);
void Ppmd8_UpdateBin(CPpmd8 *p); void Ppmd8_UpdateBin(CPpmd8 *p);
#define Ppmd8_GetBinSumm(p) \ #define Ppmd8_GetBinSumm(p) \
&p->BinSumm[p->NS2Indx[Ppmd8Context_OneState(p->MinContext)->Freq - 1]][ \ &p->BinSumm[p->NS2Indx[(size_t)Ppmd8Context_OneState(p->MinContext)->Freq - 1]][ \
p->NS2BSIndx[Ppmd8_GetContext(p, p->MinContext->Suffix)->NumStats] + \ p->NS2BSIndx[Ppmd8_GetContext(p, p->MinContext->Suffix)->NumStats] + \
p->PrevSuccess + p->MinContext->Flags + ((p->RunLength >> 26) & 0x20)] p->PrevSuccess + p->MinContext->Flags + ((p->RunLength >> 26) & 0x20)]

View File

@@ -1,5 +1,5 @@
/* Ppmd8Dec.c -- PPMdI Decoder /* Ppmd8Dec.c -- PPMdI Decoder
2010-04-16 : Igor Pavlov : Public domain 2017-04-03 : Igor Pavlov : Public domain
This code is based on: This code is based on:
PPMd var.I (2002): Dmitry Shkarin : Public domain PPMd var.I (2002): Dmitry Shkarin : Public domain
Carryless rangecoder (1999): Dmitry Subbotin : Public domain */ Carryless rangecoder (1999): Dmitry Subbotin : Public domain */
@@ -18,7 +18,7 @@ Bool Ppmd8_RangeDec_Init(CPpmd8 *p)
p->Range = 0xFFFFFFFF; p->Range = 0xFFFFFFFF;
p->Code = 0; p->Code = 0;
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
p->Code = (p->Code << 8) | p->Stream.In->Read(p->Stream.In); p->Code = (p->Code << 8) | IByteIn_Read(p->Stream.In);
return (p->Code < 0xFFFFFFFF); return (p->Code < 0xFFFFFFFF);
} }
@@ -37,7 +37,7 @@ static void RangeDec_Decode(CPpmd8 *p, UInt32 start, UInt32 size)
while ((p->Low ^ (p->Low + p->Range)) < kTop || while ((p->Low ^ (p->Low + p->Range)) < kTop ||
(p->Range < kBot && ((p->Range = (0 - p->Low) & (kBot - 1)), 1))) (p->Range < kBot && ((p->Range = (0 - p->Low) & (kBot - 1)), 1)))
{ {
p->Code = (p->Code << 8) | p->Stream.In->Read(p->Stream.In); p->Code = (p->Code << 8) | IByteIn_Read(p->Stream.In);
p->Range <<= 8; p->Range <<= 8;
p->Low <<= 8; p->Low <<= 8;
} }

View File

@@ -1,5 +1,5 @@
/* Ppmd8Enc.c -- PPMdI Encoder /* Ppmd8Enc.c -- PPMdI Encoder
2010-04-16 : Igor Pavlov : Public domain 2017-04-03 : Igor Pavlov : Public domain
This code is based on: This code is based on:
PPMd var.I (2002): Dmitry Shkarin : Public domain PPMd var.I (2002): Dmitry Shkarin : Public domain
Carryless rangecoder (1999): Dmitry Subbotin : Public domain */ Carryless rangecoder (1999): Dmitry Subbotin : Public domain */
@@ -15,7 +15,7 @@ void Ppmd8_RangeEnc_FlushData(CPpmd8 *p)
{ {
unsigned i; unsigned i;
for (i = 0; i < 4; i++, p->Low <<= 8 ) for (i = 0; i < 4; i++, p->Low <<= 8 )
p->Stream.Out->Write(p->Stream.Out, (Byte)(p->Low >> 24)); IByteOut_Write(p->Stream.Out, (Byte)(p->Low >> 24));
} }
static void RangeEnc_Normalize(CPpmd8 *p) static void RangeEnc_Normalize(CPpmd8 *p)
@@ -23,7 +23,7 @@ static void RangeEnc_Normalize(CPpmd8 *p)
while ((p->Low ^ (p->Low + p->Range)) < kTop || while ((p->Low ^ (p->Low + p->Range)) < kTop ||
(p->Range < kBot && ((p->Range = (0 - p->Low) & (kBot - 1)), 1))) (p->Range < kBot && ((p->Range = (0 - p->Low) & (kBot - 1)), 1)))
{ {
p->Stream.Out->Write(p->Stream.Out, (Byte)(p->Low >> 24)); IByteOut_Write(p->Stream.Out, (Byte)(p->Low >> 24));
p->Range <<= 8; p->Range <<= 8;
p->Low <<= 8; p->Low <<= 8;
} }

View File

@@ -1,5 +1,5 @@
/* Sha1.c -- SHA-1 Hash /* Sha1.c -- SHA-1 Hash
2016-05-20 : Igor Pavlov : Public domain 2017-04-03 : Igor Pavlov : Public domain
This code is based on public domain code of Steve Reid from Wei Dai's Crypto++ library. */ This code is based on public domain code of Steve Reid from Wei Dai's Crypto++ library. */
#include "Precomp.h" #include "Precomp.h"
@@ -62,8 +62,8 @@ This code is based on public domain code of Steve Reid from Wei Dai's Crypto++ l
#else #else
#define RX_15 { unsigned i; for (i = 0; i < 15; i += 5) { RX_5(R0, i); } } #define RX_15 { size_t i; for (i = 0; i < 15; i += 5) { RX_5(R0, i); } }
#define RX_20(rx, ii) { unsigned i; i = ii; for (; i < ii + 20; i += 5) { RX_5(rx, i); } } #define RX_20(rx, ii) { size_t i; i = ii; for (; i < ii + 20; i += 5) { RX_5(rx, i); } }
#endif #endif
@@ -131,7 +131,7 @@ void Sha1_UpdateBlock_Rar(CSha1 *p, UInt32 *data, int returnRes)
if (returnRes) if (returnRes)
{ {
unsigned i; size_t i;
for (i = 0 ; i < SHA1_NUM_BLOCK_WORDS; i++) for (i = 0 ; i < SHA1_NUM_BLOCK_WORDS; i++)
data[i] = W[kNumW - SHA1_NUM_BLOCK_WORDS + i]; data[i] = W[kNumW - SHA1_NUM_BLOCK_WORDS + i];
} }
@@ -176,7 +176,7 @@ void Sha1_Update(CSha1 *p, const Byte *data, size_t size)
{ {
for (;;) for (;;)
{ {
unsigned i; size_t i;
Sha1_UpdateBlock(p); Sha1_UpdateBlock(p);
if (size < SHA1_BLOCK_SIZE) if (size < SHA1_BLOCK_SIZE)
break; break;
@@ -238,7 +238,7 @@ void Sha1_Update_Rar(CSha1 *p, Byte *data, size_t size /* , int rar350Mode */)
Sha1_UpdateBlock_Rar(p, p->buffer, returnRes); Sha1_UpdateBlock_Rar(p, p->buffer, returnRes);
if (returnRes) if (returnRes)
{ {
unsigned i; size_t i;
for (i = 0; i < SHA1_NUM_BLOCK_WORDS; i++) for (i = 0; i < SHA1_NUM_BLOCK_WORDS; i++)
{ {
UInt32 d = p->buffer[i]; UInt32 d = p->buffer[i];

View File

@@ -1,5 +1,5 @@
/* Crypto/Sha256.c -- SHA-256 Hash /* Crypto/Sha256.c -- SHA-256 Hash
2015-11-14 : Igor Pavlov : Public domain 2017-04-03 : Igor Pavlov : Public domain
This code is based on public domain code from Wei Dai's Crypto++ library. */ This code is based on public domain code from Wei Dai's Crypto++ library. */
#include "Precomp.h" #include "Precomp.h"
@@ -45,7 +45,7 @@ void Sha256_Init(CSha256 *p)
#ifdef _SHA256_UNROLL2 #ifdef _SHA256_UNROLL2
#define R(a,b,c,d,e,f,g,h, i) \ #define R(a,b,c,d,e,f,g,h, i) \
h += S1(e) + Ch(e,f,g) + K[(i)+(j)] + (j ? blk2(i) : blk0(i)); \ h += S1(e) + Ch(e,f,g) + K[(i)+(size_t)(j)] + (j ? blk2(i) : blk0(i)); \
d += h; \ d += h; \
h += S0(a) + Maj(a, b, c) h += S0(a) + Maj(a, b, c)
@@ -73,7 +73,7 @@ void Sha256_Init(CSha256 *p)
#define h(i) T[(7-(i))&7] #define h(i) T[(7-(i))&7]
#define R(i) \ #define R(i) \
h(i) += S1(e(i)) + Ch(e(i),f(i),g(i)) + K[(i)+(j)] + (j ? blk2(i) : blk0(i)); \ h(i) += S1(e(i)) + Ch(e(i),f(i),g(i)) + K[(i)+(size_t)(j)] + (j ? blk2(i) : blk0(i)); \
d(i) += h(i); \ d(i) += h(i); \
h(i) += S0(a(i)) + Maj(a(i), b(i), c(i)) \ h(i) += S0(a(i)) + Maj(a(i), b(i), c(i)) \

View File

@@ -1,11 +1,13 @@
/* 7zMain.c - Test application for 7z Decoder /* 7zMain.c - Test application for 7z Decoder
2016-05-16 : Igor Pavlov : Public domain */ 2017-04-05 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "../../CpuArch.h"
#include "../../7z.h" #include "../../7z.h"
#include "../../7zAlloc.h" #include "../../7zAlloc.h"
#include "../../7zBuf.h" #include "../../7zBuf.h"
@@ -23,7 +25,17 @@
#endif #endif
#endif #endif
static ISzAlloc g_Alloc = { SzAlloc, SzFree };
#define kInputBufSize ((size_t)1 << 18)
static const ISzAlloc g_Alloc = { SzAlloc, SzFree };
static void Print(const char *s)
{
fputs(s, stdout);
}
static int Buf_EnsureSize(CBuf *dest, size_t size) static int Buf_EnsureSize(CBuf *dest, size_t size)
{ {
@@ -227,6 +239,7 @@ static WRes OutFile_OpenUtf16(CSzFile *p, const UInt16 *name)
#endif #endif
} }
static SRes PrintString(const UInt16 *s) static SRes PrintString(const UInt16 *s)
{ {
CBuf buf; CBuf buf;
@@ -238,12 +251,12 @@ static SRes PrintString(const UInt16 *s)
#endif #endif
); );
if (res == SZ_OK) if (res == SZ_OK)
fputs((const char *)buf.data, stdout); Print((const char *)buf.data);
Buf_Free(&buf, &g_Alloc); Buf_Free(&buf, &g_Alloc);
return res; return res;
} }
static void UInt64ToStr(UInt64 value, char *s) static void UInt64ToStr(UInt64 value, char *s, int numDigits)
{ {
char temp[32]; char temp[32];
int pos = 0; int pos = 0;
@@ -253,6 +266,10 @@ static void UInt64ToStr(UInt64 value, char *s)
value /= 10; value /= 10;
} }
while (value != 0); while (value != 0);
for (numDigits -= pos; numDigits > 0; numDigits--)
*s++ = ' ';
do do
*s++ = temp[--pos]; *s++ = temp[--pos];
while (pos); while (pos);
@@ -266,8 +283,10 @@ static char *UIntToStr(char *s, unsigned value, int numDigits)
do do
temp[pos++] = (char)('0' + (value % 10)); temp[pos++] = (char)('0' + (value % 10));
while (value /= 10); while (value /= 10);
for (numDigits -= pos; numDigits > 0; numDigits--) for (numDigits -= pos; numDigits > 0; numDigits--)
*s++ = '0'; *s++ = '0';
do do
*s++ = temp[--pos]; *s++ = temp[--pos];
while (pos); while (pos);
@@ -323,9 +342,16 @@ static void ConvertFileTimeToString(const CNtfsFileTime *nt, char *s)
UIntToStr_2(s, sec); s[2] = 0; UIntToStr_2(s, sec); s[2] = 0;
} }
void PrintError(char *sz) static void PrintLF()
{ {
printf("\nERROR: %s\n", sz); Print("\n");
}
static void PrintError(char *s)
{
Print("\nERROR: ");
Print(s);
PrintLF();
} }
static void GetAttribString(UInt32 wa, Bool isDir, char *s) static void GetAttribString(UInt32 wa, Bool isDir, char *s)
@@ -343,25 +369,27 @@ static void GetAttribString(UInt32 wa, Bool isDir, char *s)
#endif #endif
} }
// #define NUM_PARENTS_MAX 128 // #define NUM_PARENTS_MAX 128
int MY_CDECL main(int numargs, char *args[]) int MY_CDECL main(int numargs, char *args[])
{ {
CFileInStream archiveStream;
CLookToRead lookStream;
CSzArEx db;
SRes res;
ISzAlloc allocImp; ISzAlloc allocImp;
ISzAlloc allocTempImp; ISzAlloc allocTempImp;
CFileInStream archiveStream;
CLookToRead2 lookStream;
CSzArEx db;
SRes res;
UInt16 *temp = NULL; UInt16 *temp = NULL;
size_t tempSize = 0; size_t tempSize = 0;
// UInt32 parents[NUM_PARENTS_MAX]; // UInt32 parents[NUM_PARENTS_MAX];
printf("\n7z ANSI-C Decoder " MY_VERSION_COPYRIGHT_DATE "\n\n"); Print("\n7z Decoder " MY_VERSION_CPU " : " MY_COPYRIGHT_DATE "\n\n");
if (numargs == 1) if (numargs == 1)
{ {
printf( Print(
"Usage: 7zDec <command> <archive_name>\n\n" "Usage: 7zDec <command> <archive_name>\n\n"
"<Commands>\n" "<Commands>\n"
" e: Extract files from archive (without using directory names)\n" " e: Extract files from archive (without using directory names)\n"
@@ -370,7 +398,7 @@ int MY_CDECL main(int numargs, char *args[])
" x: eXtract files with full paths\n"); " x: eXtract files with full paths\n");
return 0; return 0;
} }
if (numargs < 3) if (numargs < 3)
{ {
PrintError("incorrect command"); PrintError("incorrect command");
@@ -381,11 +409,9 @@ int MY_CDECL main(int numargs, char *args[])
g_FileCodePage = AreFileApisANSI() ? CP_ACP : CP_OEMCP; g_FileCodePage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
#endif #endif
allocImp.Alloc = SzAlloc;
allocImp.Free = SzFree;
allocTempImp.Alloc = SzAllocTemp; allocImp = g_Alloc;
allocTempImp.Free = SzFreeTemp; allocTempImp = g_Alloc;
#ifdef UNDER_CE #ifdef UNDER_CE
if (InFile_OpenW(&archiveStream.file, L"\test.7z")) if (InFile_OpenW(&archiveStream.file, L"\test.7z"))
@@ -398,16 +424,31 @@ int MY_CDECL main(int numargs, char *args[])
} }
FileInStream_CreateVTable(&archiveStream); FileInStream_CreateVTable(&archiveStream);
LookToRead_CreateVTable(&lookStream, False); LookToRead2_CreateVTable(&lookStream, False);
lookStream.buf = NULL;
lookStream.realStream = &archiveStream.s;
LookToRead_Init(&lookStream);
res = SZ_OK;
{
lookStream.buf = ISzAlloc_Alloc(&allocImp, kInputBufSize);
if (!lookStream.buf)
res = SZ_ERROR_MEM;
else
{
lookStream.bufSize = kInputBufSize;
lookStream.realStream = &archiveStream.vt;
LookToRead2_Init(&lookStream);
}
}
CrcGenerateTable(); CrcGenerateTable();
SzArEx_Init(&db); SzArEx_Init(&db);
res = SzArEx_Open(&db, &lookStream.s, &allocImp, &allocTempImp); if (res == SZ_OK)
{
res = SzArEx_Open(&db, &lookStream.vt, &allocImp, &allocTempImp);
}
if (res == SZ_OK) if (res == SZ_OK)
{ {
@@ -477,7 +518,7 @@ int MY_CDECL main(int numargs, char *args[])
GetAttribString(SzBitWithVals_Check(&db.Attribs, i) ? db.Attribs.Vals[i] : 0, isDir, attr); GetAttribString(SzBitWithVals_Check(&db.Attribs, i) ? db.Attribs.Vals[i] : 0, isDir, attr);
fileSize = SzArEx_GetFileSize(&db, i); fileSize = SzArEx_GetFileSize(&db, i);
UInt64ToStr(fileSize, s); UInt64ToStr(fileSize, s, 10);
if (SzBitWithVals_Check(&db.MTime, i)) if (SzBitWithVals_Check(&db.MTime, i))
ConvertFileTimeToString(&db.MTime.Vals[i], t); ConvertFileTimeToString(&db.MTime.Vals[i], t);
@@ -489,29 +530,33 @@ int MY_CDECL main(int numargs, char *args[])
t[j] = '\0'; t[j] = '\0';
} }
printf("%s %s %10s ", t, attr, s); Print(t);
Print(" ");
Print(attr);
Print(" ");
Print(s);
Print(" ");
res = PrintString(temp); res = PrintString(temp);
if (res != SZ_OK) if (res != SZ_OK)
break; break;
if (isDir) if (isDir)
printf("/"); Print("/");
printf("\n"); PrintLF();
continue; continue;
} }
fputs(testCommand ? Print(testCommand ?
"Testing ": "Testing ":
"Extracting ", "Extracting ");
stdout);
res = PrintString(temp); res = PrintString(temp);
if (res != SZ_OK) if (res != SZ_OK)
break; break;
if (isDir) if (isDir)
printf("/"); Print("/");
else else
{ {
res = SzArEx_Extract(&db, &lookStream.s, i, res = SzArEx_Extract(&db, &lookStream.vt, i,
&blockIndex, &outBuffer, &outBufferSize, &blockIndex, &outBuffer, &outBufferSize,
&offset, &outSizeProcessed, &offset, &outSizeProcessed,
&allocImp, &allocTempImp); &allocImp, &allocTempImp);
@@ -543,7 +588,7 @@ int MY_CDECL main(int numargs, char *args[])
if (isDir) if (isDir)
{ {
MyCreateDir(destPath); MyCreateDir(destPath);
printf("\n"); PrintLF();
continue; continue;
} }
else if (OutFile_OpenUtf16(&outFile, destPath)) else if (OutFile_OpenUtf16(&outFile, destPath))
@@ -574,20 +619,21 @@ int MY_CDECL main(int numargs, char *args[])
SetFileAttributesW(destPath, db.Attribs.Vals[i]); SetFileAttributesW(destPath, db.Attribs.Vals[i]);
#endif #endif
} }
printf("\n"); PrintLF();
} }
IAlloc_Free(&allocImp, outBuffer); ISzAlloc_Free(&allocImp, outBuffer);
} }
} }
SzArEx_Free(&db, &allocImp);
SzFree(NULL, temp); SzFree(NULL, temp);
SzArEx_Free(&db, &allocImp);
ISzAlloc_Free(&allocImp, lookStream.buf);
File_Close(&archiveStream.file); File_Close(&archiveStream.file);
if (res == SZ_OK) if (res == SZ_OK)
{ {
printf("\nEverything is Ok\n"); Print("\nEverything is Ok\n");
return 0; return 0;
} }
@@ -598,7 +644,11 @@ int MY_CDECL main(int numargs, char *args[])
else if (res == SZ_ERROR_CRC) else if (res == SZ_ERROR_CRC)
PrintError("CRC error"); PrintError("CRC error");
else else
printf("\nERROR #%d\n", res); {
char s[32];
UInt64ToStr(res, s, 0);
PrintError(s);
}
return 1; return 1;
} }

View File

@@ -1,5 +1,5 @@
/* 7zipInstall.c - 7-Zip Installer /* 7zipInstall.c - 7-Zip Installer
2016-06-08 : Igor Pavlov : Public domain */ 2017-04-04 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@@ -25,9 +25,22 @@
#include "resource.h" #include "resource.h"
static const WCHAR *k_7zip = L"7-Zip";
static const WCHAR *k_Reg_Software_7zip = L"Software\\7-Zip"; #define wcscat lstrcatW
#define wcslen lstrlenW
#define wcscpy lstrcpyW
#define wcsncpy lstrcpynW
#define kInputBufSize ((size_t)1 << 18)
#define _7ZIP_CUR_VER ((MY_VER_MAJOR << 16) | MY_VER_MINOR)
#define _7ZIP_DLL_VER_COMPAT ((16 << 16) | 3)
static LPCWSTR const k_7zip = L"7-Zip";
static LPCWSTR const k_Reg_Software_7zip = L"Software\\7-Zip";
// #define _64BIT_INSTALLER 1 // #define _64BIT_INSTALLER 1
@@ -43,13 +56,13 @@ static const WCHAR *k_Reg_Software_7zip = L"Software\\7-Zip";
#define k_7zip_with_Ver k_7zip_with_Ver_base #define k_7zip_with_Ver k_7zip_with_Ver_base
#endif #endif
static const WCHAR *k_7zip_with_Ver_str = k_7zip_with_Ver; static LPCWSTR const k_7zip_with_Ver_str = k_7zip_with_Ver;
static const WCHAR *k_7zip_Setup = k_7zip_with_Ver L" Setup"; static LPCWSTR const k_7zip_Setup = k_7zip_with_Ver L" Setup";
static const WCHAR *k_Reg_Path = L"Path"; static LPCWSTR const k_Reg_Path = L"Path";
static const WCHAR *k_Reg_Path32 = L"Path" static LPCWSTR const k_Reg_Path32 = L"Path"
#ifdef _64BIT_INSTALLER #ifdef _64BIT_INSTALLER
L"64" L"64"
#else #else
@@ -71,8 +84,8 @@ static const WCHAR *k_Reg_Path32 = L"Path"
#define k_7zip_CLSID L"{23170F69-40C1-278A-1000-000100020000}" #define k_7zip_CLSID L"{23170F69-40C1-278A-1000-000100020000}"
static const WCHAR *k_Reg_CLSID_7zip = L"CLSID\\" k_7zip_CLSID; static LPCWSTR const k_Reg_CLSID_7zip = L"CLSID\\" k_7zip_CLSID;
static const WCHAR *k_Reg_CLSID_7zip_Inproc = L"CLSID\\" k_7zip_CLSID L"\\InprocServer32"; static LPCWSTR const k_Reg_CLSID_7zip_Inproc = L"CLSID\\" k_7zip_CLSID L"\\InprocServer32";
#define g_AllUsers True #define g_AllUsers True
@@ -107,7 +120,35 @@ static void PrintErrorMessage(const char *s)
MessageBoxW(g_HWND, s2, k_7zip_with_Ver_str, MB_ICONERROR); MessageBoxW(g_HWND, s2, k_7zip_with_Ver_str, MB_ICONERROR);
} }
static WRes MyCreateDir(const WCHAR *name)
static DWORD GetFileVersion(LPCWSTR s)
{
DWORD size = 0;
BYTE *vi = NULL;
DWORD version = 0;
size = GetFileVersionInfoSizeW(s, NULL);
if (size == 0)
return 0;
vi = malloc(size);
if (!vi)
return 0;
if (GetFileVersionInfoW(s, 0, size, vi))
{
VS_FIXEDFILEINFO *fi = NULL;
UINT fiLen = 0;
if (VerQueryValueW(vi, L"\\", (LPVOID *)&fi, &fiLen))
version = fi->dwFileVersionMS;
}
free(vi);
return version;
}
static WRes MyCreateDir(LPCWSTR name)
{ {
return CreateDirectoryW(name, NULL) ? 0 : GetLastError(); return CreateDirectoryW(name, NULL) ? 0 : GetLastError();
} }
@@ -455,7 +496,7 @@ static wchar_t MyWCharLower_Ascii(wchar_t c)
return c; return c;
} }
static const WCHAR *FindSubString(const WCHAR *s1, const char *s2) static LPCWSTR FindSubString(LPCWSTR s1, const char *s2)
{ {
for (;;) for (;;)
{ {
@@ -702,8 +743,8 @@ static void SetShellProgramsGroup(HWND hwndOwner)
#endif #endif
} }
static const WCHAR *k_Shell_Approved = L"Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved"; static LPCWSTR const k_Shell_Approved = L"Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved";
static const WCHAR *k_7zip_ShellExtension = L"7-Zip Shell Extension"; static LPCWSTR const k_7zip_ShellExtension = L"7-Zip Shell Extension";
static void WriteCLSID() static void WriteCLSID()
{ {
@@ -747,7 +788,7 @@ static void WriteCLSID()
} }
} }
static const WCHAR * const k_ShellEx_Items[] = static LPCWSTR const k_ShellEx_Items[] =
{ {
L"*\\shellex\\ContextMenuHandlers" L"*\\shellex\\ContextMenuHandlers"
, L"Directory\\shellex\\ContextMenuHandlers" , L"Directory\\shellex\\ContextMenuHandlers"
@@ -916,7 +957,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
num = s2 - s; num = s2 - s;
if (num > MAX_PATH) if (num > MAX_PATH)
num = MAX_PATH; num = MAX_PATH;
wcsncpy(path, s, num); wcsncpy(path, s, (unsigned)num);
RemoveQuotes(path); RemoveQuotes(path);
} }
} }
@@ -1059,6 +1100,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
} }
} }
static Bool GetErrorMessage(DWORD errorCode, WCHAR *message) static Bool GetErrorMessage(DWORD errorCode, WCHAR *message)
{ {
LPVOID msgBuf; LPVOID msgBuf;
@@ -1073,10 +1115,12 @@ static Bool GetErrorMessage(DWORD errorCode, WCHAR *message)
return True; return True;
} }
static int Install() static int Install()
{ {
CFileInStream archiveStream; CFileInStream archiveStream;
CLookToRead lookStream; CLookToRead2 lookStream;
CSzArEx db; CSzArEx db;
SRes res = SZ_OK; SRes res = SZ_OK;
@@ -1087,7 +1131,7 @@ static int Install()
ISzAlloc allocTempImp; ISzAlloc allocTempImp;
WCHAR sfxPath[MAX_PATH + 2]; WCHAR sfxPath[MAX_PATH + 2];
Bool needReboot = False; int needRebootLevel = 0;
allocImp.Alloc = SzAlloc; allocImp.Alloc = SzAlloc;
allocImp.Free = SzFree; allocImp.Free = SzFree;
@@ -1127,7 +1171,8 @@ if (res == SZ_OK)
} }
FileInStream_CreateVTable(&archiveStream); FileInStream_CreateVTable(&archiveStream);
LookToRead_CreateVTable(&lookStream, False); LookToRead2_CreateVTable(&lookStream, False);
lookStream.buf = NULL;
{ {
// Remove post spaces // Remove post spaces
@@ -1150,17 +1195,28 @@ if (res == SZ_OK)
winRes = CreateComplexDir(); winRes = CreateComplexDir();
if (winRes != 0) if (winRes != 0)
res = E_FAIL; res = SZ_ERROR_FAIL;
pathLen = wcslen(path); pathLen = wcslen(path);
if (res == SZ_OK)
{
lookStream.buf = ISzAlloc_Alloc(&allocImp, kInputBufSize);
if (!lookStream.buf)
res = SZ_ERROR_MEM;
else
{
lookStream.bufSize = kInputBufSize;
lookStream.realStream = &archiveStream.vt;
LookToRead2_Init(&lookStream);
}
}
SzArEx_Init(&db); SzArEx_Init(&db);
if (res == SZ_OK) if (res == SZ_OK)
{ {
lookStream.realStream = &archiveStream.s; res = SzArEx_Open(&db, &lookStream.vt, &allocImp, &allocTempImp);
LookToRead_Init(&lookStream);
res = SzArEx_Open(&db, &lookStream.s, &allocImp, &allocTempImp);
} }
if (res == SZ_OK) if (res == SZ_OK)
@@ -1222,7 +1278,7 @@ if (res == SZ_OK)
SetWindowTextW(g_InfoLine_HWND, temp); SetWindowTextW(g_InfoLine_HWND, temp);
{ {
res = SzArEx_Extract(&db, &lookStream.s, i, res = SzArEx_Extract(&db, &lookStream.vt, i,
&blockIndex, &outBuf, &outBufSize, &blockIndex, &outBuf, &outBufSize,
&offset, &outSizeProcessed, &offset, &outSizeProcessed,
&allocImp, &allocTempImp); &allocImp, &allocTempImp);
@@ -1236,6 +1292,7 @@ if (res == SZ_OK)
size_t j; size_t j;
// size_t nameStartPos = 0; // size_t nameStartPos = 0;
UInt32 tempIndex = 0; UInt32 tempIndex = 0;
int fileLevel = 1 << 2;
WCHAR origPath[MAX_PATH * 2 + 10]; WCHAR origPath[MAX_PATH * 2 + 10];
for (j = 0; temp[j] != 0; j++) for (j = 0; temp[j] != 0; j++)
@@ -1289,13 +1346,20 @@ if (res == SZ_OK)
break; break;
} }
if (tempIndex != 0 if (tempIndex != 0)
|| FindSubString(temp, "7-zip.dll") {
tempIndex++;
continue;
}
if (FindSubString(temp, "7-zip.dll")
#ifdef _64BIT_INSTALLER #ifdef _64BIT_INSTALLER
|| FindSubString(temp, "7-zip32.dll") || FindSubString(temp, "7-zip32.dll")
#endif #endif
) )
{ {
DWORD ver = GetFileVersion(path);
fileLevel = ((ver < _7ZIP_DLL_VER_COMPAT || ver > _7ZIP_CUR_VER) ? 2 : 1);
tempIndex++; tempIndex++;
continue; continue;
} }
@@ -1339,7 +1403,7 @@ if (res == SZ_OK)
*/ */
} }
// if (res = S_OK) // if (res == SZ_OK)
{ {
processedSize = outSizeProcessed; processedSize = outSizeProcessed;
winRes = File_Write(&outFile, outBuf + offset, &processedSize); winRes = File_Write(&outFile, outBuf + offset, &processedSize);
@@ -1388,14 +1452,14 @@ if (res == SZ_OK)
winRes = GetLastError(); winRes = GetLastError();
break; break;
} }
needReboot = True; needRebootLevel |= fileLevel;
#endif #endif
} }
} }
} }
IAlloc_Free(&allocImp, outBuf); ISzAlloc_Free(&allocImp, outBuf);
if (!g_SilentMode) if (!g_SilentMode)
SendMessage(g_Progress_HWND, PBM_SETPOS, i, 0); SendMessage(g_Progress_HWND, PBM_SETPOS, i, 0);
@@ -1416,6 +1480,8 @@ if (res == SZ_OK)
SzArEx_Free(&db, &allocImp); SzArEx_Free(&db, &allocImp);
ISzAlloc_Free(&allocImp, lookStream.buf);
File_Close(&archiveStream.file); File_Close(&archiveStream.file);
} }
@@ -1425,7 +1491,7 @@ if (res == SZ_OK)
if (res == SZ_OK) if (res == SZ_OK)
{ {
if (!g_SilentMode && needReboot) if (!g_SilentMode && needRebootLevel > 1)
{ {
if (MessageBoxW(g_HWND, L"You must restart your system to complete the installation.\nRestart now?", if (MessageBoxW(g_HWND, L"You must restart your system to complete the installation.\nRestart now?",
k_7zip_Setup, MB_YESNO | MB_DEFBUTTON2) == IDYES) k_7zip_Setup, MB_YESNO | MB_DEFBUTTON2) == IDYES)

View File

@@ -40,9 +40,10 @@ RSC=rc.exe
# PROP Use_Debug_Libraries 0 # PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release" # PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release" # PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir "" # PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MD /W4 /WX /GX /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_UNICODE2" /D "UNICODE2" /Yu"Precomp.h" /FD /c # ADD CPP /nologo /Gr /MD /W4 /WX /GX /O1 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_UNICODE2" /D "UNICODE2" /Yu"Precomp.h" /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x419 /d "NDEBUG" # ADD BASE RSC /l 0x419 /d "NDEBUG"
@@ -52,7 +53,7 @@ BSC32=bscmake.exe
# ADD BSC32 /nologo # ADD BSC32 /nologo
LINK32=link.exe LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib version.lib /nologo /subsystem:windows /machine:I386
!ELSEIF "$(CFG)" == "7zipInstall - Win32 Debug" !ELSEIF "$(CFG)" == "7zipInstall - Win32 Debug"
@@ -78,7 +79,7 @@ BSC32=bscmake.exe
# ADD BSC32 /nologo # ADD BSC32 /nologo
LINK32=link.exe LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib version.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
!ENDIF !ENDIF

View File

@@ -1,5 +1,7 @@
PROG = 7zipInstall.exe PROG = 7zipInstall.exe
LIBS = $(LIBS) version.lib
!IFDEF _64BIT_INSTALLER !IFDEF _64BIT_INSTALLER
CFLAGS = $(CFLAGS) -D_64BIT_INSTALLER CFLAGS = $(CFLAGS) -D_64BIT_INSTALLER
!ENDIF !ENDIF

View File

@@ -1,5 +1,5 @@
/* 7zipUninstall.c - 7-Zip Uninstaller /* 7zipUninstall.c - 7-Zip Uninstaller
2016-05-16 : Igor Pavlov : Public domain */ 2017-04-04 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@@ -20,7 +20,7 @@
#define LLL_(quote) L##quote #define LLL_(quote) L##quote
#define LLL(quote) LLL_(quote) #define LLL(quote) LLL_(quote)
// static const WCHAR *k_7zip = L"7-Zip"; // static const WCHAR * const k_7zip = L"7-Zip";
// #define _64BIT_INSTALLER 1 // #define _64BIT_INSTALLER 1
@@ -36,13 +36,13 @@
#define k_7zip_with_Ver k_7zip_with_Ver_base #define k_7zip_with_Ver k_7zip_with_Ver_base
#endif #endif
// static const WCHAR *k_7zip_with_Ver_str = k_7zip_with_Ver; // static const WCHAR * const k_7zip_with_Ver_str = k_7zip_with_Ver;
static const WCHAR *k_Reg_Software_7zip = L"Software\\7-Zip"; static const WCHAR * const k_Reg_Software_7zip = L"Software\\7-Zip";
static const WCHAR *k_Reg_Path = L"Path"; static const WCHAR * const k_Reg_Path = L"Path";
static const WCHAR *k_Reg_Path32 = L"Path" static const WCHAR * const k_Reg_Path32 = L"Path"
#ifdef _64BIT_INSTALLER #ifdef _64BIT_INSTALLER
L"64" L"64"
#else #else
@@ -64,8 +64,8 @@ static const WCHAR *k_Reg_Path32 = L"Path"
#define k_7zip_CLSID L"{23170F69-40C1-278A-1000-000100020000}" #define k_7zip_CLSID L"{23170F69-40C1-278A-1000-000100020000}"
static const WCHAR *k_Reg_CLSID_7zip = L"CLSID\\" k_7zip_CLSID; static const WCHAR * const k_Reg_CLSID_7zip = L"CLSID\\" k_7zip_CLSID;
static const WCHAR *k_Reg_CLSID_7zip_Inproc = L"CLSID\\" k_7zip_CLSID L"\\InprocServer32"; static const WCHAR * const k_Reg_CLSID_7zip_Inproc = L"CLSID\\" k_7zip_CLSID L"\\InprocServer32";
#define g_AllUsers True #define g_AllUsers True
@@ -90,7 +90,7 @@ static WCHAR tempPath[MAX_PATH * 2 + 40];
static WCHAR cmdLine[MAX_PATH * 3 + 40]; static WCHAR cmdLine[MAX_PATH * 3 + 40];
static WCHAR copyPath[MAX_PATH * 2 + 40]; static WCHAR copyPath[MAX_PATH * 2 + 40];
static const WCHAR *kUninstallExe = L"Uninstall.exe"; static const WCHAR * const kUninstallExe = L"Uninstall.exe";
#define MAKE_CHAR_UPPER(c) ((((c) >= 'a' && (c) <= 'z') ? (c) -= 0x20 : (c))) #define MAKE_CHAR_UPPER(c) ((((c) >= 'a' && (c) <= 'z') ? (c) -= 0x20 : (c)))
@@ -340,11 +340,11 @@ static const WCHAR * const k_ShellEx_Items[] =
, L"Drive\\shellex\\DragDropHandlers" , L"Drive\\shellex\\DragDropHandlers"
}; };
static const WCHAR *k_Shell_Approved = L"Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved"; static const WCHAR * const k_Shell_Approved = L"Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved";
static const WCHAR *k_AppPaths_7zFm = L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\7zFM.exe"; static const WCHAR * const k_AppPaths_7zFm = L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\7zFM.exe";
#define k_REG_Uninstall L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" #define k_REG_Uninstall L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"
static const WCHAR *k_Uninstall_7zip = k_REG_Uninstall L"7-Zip"; static const WCHAR * const k_Uninstall_7zip = k_REG_Uninstall L"7-Zip";
static Bool AreEqual_Path_PrefixName(const wchar_t *s, const wchar_t *prefix, const wchar_t *name) static Bool AreEqual_Path_PrefixName(const wchar_t *s, const wchar_t *prefix, const wchar_t *name)
@@ -556,7 +556,7 @@ static BOOL RemoveDir()
#define NUM_FILES (NUM_LANG_TXT_FILES + 1 + 13 + NUM_EXTRA_FILES_64BIT) #define NUM_FILES (NUM_LANG_TXT_FILES + 1 + 13 + NUM_EXTRA_FILES_64BIT)
static const char *k_Names = static const char * const k_Names =
"af an ar ast az ba be bg bn br ca co cs cy da de el eo es et eu ext" "af an ar ast az ba be bg bn br ca co cs cy da de el eo es et eu ext"
" fa fi fr fur fy ga gl gu he hi hr hu hy id io is it ja ka kaa kk ko ku ku-ckb ky" " fa fi fr fur fy ga gl gu he hi hr hu hy id io is it ja ka kaa kk ko ku ku-ckb ky"
" lij lt lv mk mn mng mng2 mr ms nb ne nl nn pa-in pl ps pt pt-br ro ru" " lij lt lv mk mn mng mng2 mr ms nb ne nl nn pa-in pl ps pt pt-br ro ru"

View File

@@ -43,7 +43,7 @@ RSC=rc.exe
# PROP Ignore_Export_Lib 0 # PROP Ignore_Export_Lib 0
# PROP Target_Dir "" # PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MD /W4 /WX /GX /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_UNICODE2" /D "UNICODE2" /Yu"Precomp.h" /FD /c # ADD CPP /nologo /Gr /MD /W4 /WX /GX /O1 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_UNICODE2" /D "UNICODE2" /FAcs /Yu"Precomp.h" /FD /GF /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x419 /d "NDEBUG" # ADD BASE RSC /l 0x419 /d "NDEBUG"

View File

@@ -1,5 +1,5 @@
/* LzmaUtil.c -- Test application for LZMA compression /* LzmaUtil.c -- Test application for LZMA compression
2015-11-08 : Igor Pavlov : Public domain */ 2017-04-27 : Igor Pavlov : Public domain */
#include "../../Precomp.h" #include "../../Precomp.h"
@@ -7,26 +7,29 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "../../CpuArch.h"
#include "../../Alloc.h" #include "../../Alloc.h"
#include "../../7zFile.h" #include "../../7zFile.h"
#include "../../7zVersion.h" #include "../../7zVersion.h"
#include "../../LzmaDec.h" #include "../../LzmaDec.h"
#include "../../LzmaEnc.h" #include "../../LzmaEnc.h"
const char *kCantReadMessage = "Can not read input file"; static const char * const kCantReadMessage = "Can not read input file";
const char *kCantWriteMessage = "Can not write output file"; static const char * const kCantWriteMessage = "Can not write output file";
const char *kCantAllocateMessage = "Can not allocate memory"; static const char * const kCantAllocateMessage = "Can not allocate memory";
const char *kDataErrorMessage = "Data error"; static const char * const kDataErrorMessage = "Data error";
void PrintHelp(char *buffer) static void PrintHelp(char *buffer)
{ {
strcat(buffer, "\nLZMA Utility " MY_VERSION_COPYRIGHT_DATE "\n" strcat(buffer,
"\nUsage: lzma <e|d> inputFile outputFile\n" "\nLZMA-C " MY_VERSION_CPU " : " MY_COPYRIGHT_DATE "\n\n"
" e: encode file\n" "Usage: lzma <e|d> inputFile outputFile\n"
" d: decode file\n"); " e: encode file\n"
" d: decode file\n");
} }
int PrintError(char *buffer, const char *message) static int PrintError(char *buffer, const char *message)
{ {
strcat(buffer, "\nError: "); strcat(buffer, "\nError: ");
strcat(buffer, message); strcat(buffer, message);
@@ -34,20 +37,22 @@ int PrintError(char *buffer, const char *message)
return 1; return 1;
} }
int PrintErrorNumber(char *buffer, SRes val) static int PrintErrorNumber(char *buffer, SRes val)
{ {
sprintf(buffer + strlen(buffer), "\nError code: %x\n", (unsigned)val); sprintf(buffer + strlen(buffer), "\nError code: %x\n", (unsigned)val);
return 1; return 1;
} }
int PrintUserError(char *buffer) static int PrintUserError(char *buffer)
{ {
return PrintError(buffer, "Incorrect command"); return PrintError(buffer, "Incorrect command");
} }
#define IN_BUF_SIZE (1 << 16) #define IN_BUF_SIZE (1 << 16)
#define OUT_BUF_SIZE (1 << 16) #define OUT_BUF_SIZE (1 << 16)
static SRes Decode2(CLzmaDec *state, ISeqOutStream *outStream, ISeqInStream *inStream, static SRes Decode2(CLzmaDec *state, ISeqOutStream *outStream, ISeqInStream *inStream,
UInt64 unpackSize) UInt64 unpackSize)
{ {
@@ -101,6 +106,7 @@ static SRes Decode2(CLzmaDec *state, ISeqOutStream *outStream, ISeqInStream *inS
} }
} }
static SRes Decode(ISeqOutStream *outStream, ISeqInStream *inStream) static SRes Decode(ISeqOutStream *outStream, ISeqInStream *inStream)
{ {
UInt64 unpackSize; UInt64 unpackSize;
@@ -163,7 +169,8 @@ static SRes Encode(ISeqOutStream *outStream, ISeqInStream *inStream, UInt64 file
return res; return res;
} }
int main2(int numArgs, const char *args[], char *rs)
static int main2(int numArgs, const char *args[], char *rs)
{ {
CFileSeqInStream inStream; CFileSeqInStream inStream;
CFileOutStream outStream; CFileOutStream outStream;
@@ -215,11 +222,11 @@ int main2(int numArgs, const char *args[], char *rs)
{ {
UInt64 fileSize; UInt64 fileSize;
File_GetLength(&inStream.file, &fileSize); File_GetLength(&inStream.file, &fileSize);
res = Encode(&outStream.s, &inStream.s, fileSize, rs); res = Encode(&outStream.vt, &inStream.vt, fileSize, rs);
} }
else else
{ {
res = Decode(&outStream.s, useOutFile ? &inStream.s : NULL); res = Decode(&outStream.vt, useOutFile ? &inStream.vt : NULL);
} }
if (useOutFile) if (useOutFile)
@@ -241,6 +248,7 @@ int main2(int numArgs, const char *args[], char *rs)
return 0; return 0;
} }
int MY_CDECL main(int numArgs, const char *args[]) int MY_CDECL main(int numArgs, const char *args[])
{ {
char rs[800] = { 0 }; char rs[800] = { 0 };

View File

@@ -1,5 +1,5 @@
/* SfxSetup.c - 7z SFX Setup /* SfxSetup.c - 7z SFX Setup
2016-05-16 : Igor Pavlov : Public domain */ 2017-04-04 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@@ -24,6 +24,8 @@
#define k_EXE_ExtIndex 2 #define k_EXE_ExtIndex 2
#define kInputBufSize ((size_t)1 << 18)
static const char * const kExts[] = static const char * const kExts[] =
{ {
"bat" "bat"
@@ -238,7 +240,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
#endif #endif
{ {
CFileInStream archiveStream; CFileInStream archiveStream;
CLookToRead lookStream; CLookToRead2 lookStream;
CSzArEx db; CSzArEx db;
SRes res = SZ_OK; SRes res = SZ_OK;
ISzAlloc allocImp; ISzAlloc allocImp;
@@ -275,7 +277,8 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
allocTempImp.Free = SzFreeTemp; allocTempImp.Free = SzFreeTemp;
FileInStream_CreateVTable(&archiveStream); FileInStream_CreateVTable(&archiveStream);
LookToRead_CreateVTable(&lookStream, False); LookToRead2_CreateVTable(&lookStream, False);
lookStream.buf = NULL;
winRes = GetModuleFileNameW(NULL, sfxPath, MAX_PATH); winRes = GetModuleFileNameW(NULL, sfxPath, MAX_PATH);
if (winRes == 0 || winRes > MAX_PATH) if (winRes == 0 || winRes > MAX_PATH)
@@ -376,14 +379,22 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
if (res == SZ_OK) if (res == SZ_OK)
{ {
lookStream.realStream = &archiveStream.s; lookStream.buf = ISzAlloc_Alloc(&allocImp, kInputBufSize);
LookToRead_Init(&lookStream); if (!lookStream.buf)
res = SZ_ERROR_MEM;
else
{
lookStream.bufSize = kInputBufSize;
lookStream.realStream = &archiveStream.vt;
LookToRead2_Init(&lookStream);
}
} }
SzArEx_Init(&db); SzArEx_Init(&db);
if (res == SZ_OK) if (res == SZ_OK)
{ {
res = SzArEx_Open(&db, &lookStream.s, &allocImp, &allocTempImp); res = SzArEx_Open(&db, &lookStream.vt, &allocImp, &allocTempImp);
} }
if (res == SZ_OK) if (res == SZ_OK)
@@ -411,7 +422,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
SzArEx_GetFileNameUtf16(&db, i, temp); SzArEx_GetFileNameUtf16(&db, i, temp);
{ {
res = SzArEx_Extract(&db, &lookStream.s, i, res = SzArEx_Extract(&db, &lookStream.vt, i,
&blockIndex, &outBuffer, &outBufferSize, &blockIndex, &outBuffer, &outBufferSize,
&offset, &outSizeProcessed, &offset, &outSizeProcessed,
&allocImp, &allocTempImp); &allocImp, &allocTempImp);
@@ -522,10 +533,13 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
temp[j] = CHAR_PATH_SEPARATOR; temp[j] = CHAR_PATH_SEPARATOR;
} }
} }
IAlloc_Free(&allocImp, outBuffer); ISzAlloc_Free(&allocImp, outBuffer);
} }
SzArEx_Free(&db, &allocImp); SzArEx_Free(&db, &allocImp);
ISzAlloc_Free(&allocImp, lookStream.buf);
File_Close(&archiveStream.file); File_Close(&archiveStream.file);
if (res == SZ_OK) if (res == SZ_OK)

8
C/Xz.c
View File

@@ -1,5 +1,5 @@
/* Xz.c - Xz /* Xz.c - Xz
2015-05-01 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@@ -20,7 +20,7 @@ unsigned Xz_WriteVarInt(Byte *buf, UInt64 v)
v >>= 7; v >>= 7;
} }
while (v != 0); while (v != 0);
buf[i - 1] &= 0x7F; buf[(size_t)i - 1] &= 0x7F;
return i; return i;
} }
@@ -31,9 +31,9 @@ void Xz_Construct(CXzStream *p)
p->flags = 0; p->flags = 0;
} }
void Xz_Free(CXzStream *p, ISzAlloc *alloc) void Xz_Free(CXzStream *p, ISzAllocPtr alloc)
{ {
alloc->Free(alloc, p->blocks); ISzAlloc_Free(alloc, p->blocks);
p->numBlocks = p->numBlocksAllocated = 0; p->numBlocks = p->numBlocksAllocated = 0;
p->blocks = 0; p->blocks = 0;
} }

18
C/Xz.h
View File

@@ -1,5 +1,5 @@
/* Xz.h - Xz interface /* Xz.h - Xz interface
2015-05-01 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#ifndef __XZ_H #ifndef __XZ_H
#define __XZ_H #define __XZ_H
@@ -112,7 +112,7 @@ typedef struct
} CXzStream; } CXzStream;
void Xz_Construct(CXzStream *p); void Xz_Construct(CXzStream *p);
void Xz_Free(CXzStream *p, ISzAlloc *alloc); void Xz_Free(CXzStream *p, ISzAllocPtr alloc);
#define XZ_SIZE_OVERFLOW ((UInt64)(Int64)-1) #define XZ_SIZE_OVERFLOW ((UInt64)(Int64)-1)
@@ -127,8 +127,8 @@ typedef struct
} CXzs; } CXzs;
void Xzs_Construct(CXzs *p); void Xzs_Construct(CXzs *p);
void Xzs_Free(CXzs *p, ISzAlloc *alloc); void Xzs_Free(CXzs *p, ISzAllocPtr alloc);
SRes Xzs_ReadBackward(CXzs *p, ILookInStream *inStream, Int64 *startOffset, ICompressProgress *progress, ISzAlloc *alloc); SRes Xzs_ReadBackward(CXzs *p, ILookInStream *inStream, Int64 *startOffset, ICompressProgress *progress, ISzAllocPtr alloc);
UInt64 Xzs_GetNumBlocks(const CXzs *p); UInt64 Xzs_GetNumBlocks(const CXzs *p);
UInt64 Xzs_GetUnpackSize(const CXzs *p); UInt64 Xzs_GetUnpackSize(const CXzs *p);
@@ -150,8 +150,8 @@ typedef enum
typedef struct _IStateCoder typedef struct _IStateCoder
{ {
void *p; void *p;
void (*Free)(void *p, ISzAlloc *alloc); void (*Free)(void *p, ISzAllocPtr alloc);
SRes (*SetProps)(void *p, const Byte *props, size_t propSize, ISzAlloc *alloc); SRes (*SetProps)(void *p, const Byte *props, size_t propSize, ISzAllocPtr alloc);
void (*Init)(void *p); void (*Init)(void *p);
SRes (*Code)(void *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, SRes (*Code)(void *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
int srcWasFinished, ECoderFinishMode finishMode, int *wasFinished); int srcWasFinished, ECoderFinishMode finishMode, int *wasFinished);
@@ -161,7 +161,7 @@ typedef struct _IStateCoder
typedef struct typedef struct
{ {
ISzAlloc *alloc; ISzAllocPtr alloc;
Byte *buf; Byte *buf;
unsigned numCoders; unsigned numCoders;
int finished[MIXCODER_NUM_FILTERS_MAX - 1]; int finished[MIXCODER_NUM_FILTERS_MAX - 1];
@@ -171,7 +171,7 @@ typedef struct
IStateCoder coders[MIXCODER_NUM_FILTERS_MAX]; IStateCoder coders[MIXCODER_NUM_FILTERS_MAX];
} CMixCoder; } CMixCoder;
void MixCoder_Construct(CMixCoder *p, ISzAlloc *alloc); void MixCoder_Construct(CMixCoder *p, ISzAllocPtr alloc);
void MixCoder_Free(CMixCoder *p); void MixCoder_Free(CMixCoder *p);
void MixCoder_Init(CMixCoder *p); void MixCoder_Init(CMixCoder *p);
SRes MixCoder_SetFromMethod(CMixCoder *p, unsigned coderIndex, UInt64 methodId); SRes MixCoder_SetFromMethod(CMixCoder *p, unsigned coderIndex, UInt64 methodId);
@@ -222,7 +222,7 @@ typedef struct
Byte buf[XZ_BLOCK_HEADER_SIZE_MAX]; Byte buf[XZ_BLOCK_HEADER_SIZE_MAX];
} CXzUnpacker; } CXzUnpacker;
void XzUnpacker_Construct(CXzUnpacker *p, ISzAlloc *alloc); void XzUnpacker_Construct(CXzUnpacker *p, ISzAllocPtr alloc);
void XzUnpacker_Init(CXzUnpacker *p); void XzUnpacker_Init(CXzUnpacker *p);
void XzUnpacker_Free(CXzUnpacker *p); void XzUnpacker_Free(CXzUnpacker *p);

View File

@@ -1,5 +1,5 @@
/* XzCrc64.c -- CRC64 calculation /* XzCrc64.c -- CRC64 calculation
2015-03-01 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@@ -52,12 +52,12 @@ void MY_FAST_CALL Crc64GenerateTable()
UInt64 r = i; UInt64 r = i;
unsigned j; unsigned j;
for (j = 0; j < 8; j++) for (j = 0; j < 8; j++)
r = (r >> 1) ^ (kCrc64Poly & ~((r & 1) - 1)); r = (r >> 1) ^ (kCrc64Poly & ((UInt64)0 - (r & 1)));
g_Crc64Table[i] = r; g_Crc64Table[i] = r;
} }
for (; i < 256 * CRC_NUM_TABLES; i++) for (i = 256; i < 256 * CRC_NUM_TABLES; i++)
{ {
UInt64 r = g_Crc64Table[i - 256]; UInt64 r = g_Crc64Table[(size_t)i - 256];
g_Crc64Table[i] = g_Crc64Table[r & 0xFF] ^ (r >> 8); g_Crc64Table[i] = g_Crc64Table[r & 0xFF] ^ (r >> 8);
} }
@@ -76,7 +76,7 @@ void MY_FAST_CALL Crc64GenerateTable()
{ {
for (i = 256 * CRC_NUM_TABLES - 1; i >= 256; i--) for (i = 256 * CRC_NUM_TABLES - 1; i >= 256; i--)
{ {
UInt64 x = g_Crc64Table[i - 256]; UInt64 x = g_Crc64Table[(size_t)i - 256];
g_Crc64Table[i] = CRC_UINT64_SWAP(x); g_Crc64Table[i] = CRC_UINT64_SWAP(x);
} }
g_Crc64Update = XzCrc64UpdateT1_BeT4; g_Crc64Update = XzCrc64UpdateT1_BeT4;

View File

@@ -1,5 +1,5 @@
/* XzCrc64Opt.c -- CRC64 calculation /* XzCrc64Opt.c -- CRC64 calculation
2015-03-01 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@@ -18,10 +18,10 @@ UInt64 MY_FAST_CALL XzCrc64UpdateT4(UInt64 v, const void *data, size_t size, con
{ {
UInt32 d = (UInt32)v ^ *(const UInt32 *)p; UInt32 d = (UInt32)v ^ *(const UInt32 *)p;
v = (v >> 32) v = (v >> 32)
^ table[0x300 + ((d ) & 0xFF)] ^ (table + 0x300)[((d ) & 0xFF)]
^ table[0x200 + ((d >> 8) & 0xFF)] ^ (table + 0x200)[((d >> 8) & 0xFF)]
^ table[0x100 + ((d >> 16) & 0xFF)] ^ (table + 0x100)[((d >> 16) & 0xFF)]
^ table[0x000 + ((d >> 24))]; ^ (table + 0x000)[((d >> 24))];
} }
for (; size > 0; size--, p++) for (; size > 0; size--, p++)
v = CRC_UPDATE_BYTE_2(v, *p); v = CRC_UPDATE_BYTE_2(v, *p);
@@ -56,10 +56,10 @@ UInt64 MY_FAST_CALL XzCrc64UpdateT1_BeT4(UInt64 v, const void *data, size_t size
{ {
UInt32 d = (UInt32)(v >> 32) ^ *(const UInt32 *)p; UInt32 d = (UInt32)(v >> 32) ^ *(const UInt32 *)p;
v = (v << 32) v = (v << 32)
^ table[0x000 + ((d ) & 0xFF)] ^ (table + 0x000)[((d ) & 0xFF)]
^ table[0x100 + ((d >> 8) & 0xFF)] ^ (table + 0x100)[((d >> 8) & 0xFF)]
^ table[0x200 + ((d >> 16) & 0xFF)] ^ (table + 0x200)[((d >> 16) & 0xFF)]
^ table[0x300 + ((d >> 24))]; ^ (table + 0x300)[((d >> 24))];
} }
for (; size > 0; size--, p++) for (; size > 0; size--, p++)
v = CRC_UPDATE_BYTE_2_BE(v, *p); v = CRC_UPDATE_BYTE_2_BE(v, *p);

View File

@@ -1,5 +1,5 @@
/* XzDec.c -- Xz Decode /* XzDec.c -- Xz Decode
2015-11-09 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@@ -28,7 +28,7 @@
#define XZ_CHECK_SIZE_MAX 64 #define XZ_CHECK_SIZE_MAX 64
#define CODER_BUF_SIZE (1 << 17) #define CODER_BUF_SIZE ((size_t)1 << 17)
unsigned Xz_ReadVarInt(const Byte *p, size_t maxSize, UInt64 *value) unsigned Xz_ReadVarInt(const Byte *p, size_t maxSize, UInt64 *value)
{ {
@@ -66,12 +66,12 @@ typedef struct
Byte buf[BRA_BUF_SIZE]; Byte buf[BRA_BUF_SIZE];
} CBraState; } CBraState;
static void BraState_Free(void *pp, ISzAlloc *alloc) static void BraState_Free(void *pp, ISzAllocPtr alloc)
{ {
alloc->Free(alloc, pp); ISzAlloc_Free(alloc, pp);
} }
static SRes BraState_SetProps(void *pp, const Byte *props, size_t propSize, ISzAlloc *alloc) static SRes BraState_SetProps(void *pp, const Byte *props, size_t propSize, ISzAllocPtr alloc)
{ {
CBraState *p = ((CBraState *)pp); CBraState *p = ((CBraState *)pp);
UNUSED_VAR(alloc); UNUSED_VAR(alloc);
@@ -197,7 +197,7 @@ static SRes BraState_Code(void *pp, Byte *dest, SizeT *destLen, const Byte *src,
return SZ_OK; return SZ_OK;
} }
SRes BraState_SetFromMethod(IStateCoder *p, UInt64 id, int encodeMode, ISzAlloc *alloc) SRes BraState_SetFromMethod(IStateCoder *p, UInt64 id, int encodeMode, ISzAllocPtr alloc)
{ {
CBraState *decoder; CBraState *decoder;
if (id != XZ_ID_Delta && if (id != XZ_ID_Delta &&
@@ -209,8 +209,8 @@ SRes BraState_SetFromMethod(IStateCoder *p, UInt64 id, int encodeMode, ISzAlloc
id != XZ_ID_SPARC) id != XZ_ID_SPARC)
return SZ_ERROR_UNSUPPORTED; return SZ_ERROR_UNSUPPORTED;
p->p = 0; p->p = 0;
decoder = (CBraState *)alloc->Alloc(alloc, sizeof(CBraState)); decoder = (CBraState *)ISzAlloc_Alloc(alloc, sizeof(CBraState));
if (decoder == 0) if (!decoder)
return SZ_ERROR_MEM; return SZ_ERROR_MEM;
decoder->methodId = (UInt32)id; decoder->methodId = (UInt32)id;
decoder->encodeMode = encodeMode; decoder->encodeMode = encodeMode;
@@ -226,14 +226,14 @@ SRes BraState_SetFromMethod(IStateCoder *p, UInt64 id, int encodeMode, ISzAlloc
#ifdef USE_SUBBLOCK #ifdef USE_SUBBLOCK
static void SbState_Free(void *pp, ISzAlloc *alloc) static void SbState_Free(void *pp, ISzAllocPtr alloc)
{ {
CSbDec *p = (CSbDec *)pp; CSbDec *p = (CSbDec *)pp;
SbDec_Free(p); SbDec_Free(p);
alloc->Free(alloc, pp); ISzAlloc_Free(alloc, pp);
} }
static SRes SbState_SetProps(void *pp, const Byte *props, size_t propSize, ISzAlloc *alloc) static SRes SbState_SetProps(void *pp, const Byte *props, size_t propSize, ISzAllocPtr alloc)
{ {
UNUSED_VAR(pp); UNUSED_VAR(pp);
UNUSED_VAR(props); UNUSED_VAR(props);
@@ -264,12 +264,12 @@ static SRes SbState_Code(void *pp, Byte *dest, SizeT *destLen, const Byte *src,
return res; return res;
} }
SRes SbState_SetFromMethod(IStateCoder *p, ISzAlloc *alloc) SRes SbState_SetFromMethod(IStateCoder *p, ISzAllocPtr alloc)
{ {
CSbDec *decoder; CSbDec *decoder;
p->p = 0; p->p = 0;
decoder = alloc->Alloc(alloc, sizeof(CSbDec)); decoder = ISzAlloc_Alloc(alloc, sizeof(CSbDec));
if (decoder == 0) if (!decoder)
return SZ_ERROR_MEM; return SZ_ERROR_MEM;
p->p = decoder; p->p = decoder;
p->Free = SbState_Free; p->Free = SbState_Free;
@@ -284,13 +284,13 @@ SRes SbState_SetFromMethod(IStateCoder *p, ISzAlloc *alloc)
/* ---------- Lzma2State ---------- */ /* ---------- Lzma2State ---------- */
static void Lzma2State_Free(void *pp, ISzAlloc *alloc) static void Lzma2State_Free(void *pp, ISzAllocPtr alloc)
{ {
Lzma2Dec_Free((CLzma2Dec *)pp, alloc); Lzma2Dec_Free((CLzma2Dec *)pp, alloc);
alloc->Free(alloc, pp); ISzAlloc_Free(alloc, pp);
} }
static SRes Lzma2State_SetProps(void *pp, const Byte *props, size_t propSize, ISzAlloc *alloc) static SRes Lzma2State_SetProps(void *pp, const Byte *props, size_t propSize, ISzAllocPtr alloc)
{ {
if (propSize != 1) if (propSize != 1)
return SZ_ERROR_UNSUPPORTED; return SZ_ERROR_UNSUPPORTED;
@@ -313,11 +313,11 @@ static SRes Lzma2State_Code(void *pp, Byte *dest, SizeT *destLen, const Byte *sr
return res; return res;
} }
static SRes Lzma2State_SetFromMethod(IStateCoder *p, ISzAlloc *alloc) static SRes Lzma2State_SetFromMethod(IStateCoder *p, ISzAllocPtr alloc)
{ {
CLzma2Dec *decoder = (CLzma2Dec *)alloc->Alloc(alloc, sizeof(CLzma2Dec)); CLzma2Dec *decoder = (CLzma2Dec *)ISzAlloc_Alloc(alloc, sizeof(CLzma2Dec));
p->p = decoder; p->p = decoder;
if (decoder == 0) if (!decoder)
return SZ_ERROR_MEM; return SZ_ERROR_MEM;
p->Free = Lzma2State_Free; p->Free = Lzma2State_Free;
p->SetProps = Lzma2State_SetProps; p->SetProps = Lzma2State_SetProps;
@@ -328,7 +328,7 @@ static SRes Lzma2State_SetFromMethod(IStateCoder *p, ISzAlloc *alloc)
} }
void MixCoder_Construct(CMixCoder *p, ISzAlloc *alloc) void MixCoder_Construct(CMixCoder *p, ISzAllocPtr alloc)
{ {
unsigned i; unsigned i;
p->alloc = alloc; p->alloc = alloc;
@@ -350,7 +350,7 @@ void MixCoder_Free(CMixCoder *p)
p->numCoders = 0; p->numCoders = 0;
if (p->buf) if (p->buf)
{ {
p->alloc->Free(p->alloc, p->buf); ISzAlloc_Free(p->alloc, p->buf);
p->buf = NULL; /* 9.31: the BUG was fixed */ p->buf = NULL; /* 9.31: the BUG was fixed */
} }
} }
@@ -400,7 +400,7 @@ SRes MixCoder_Code(CMixCoder *p, Byte *dest, SizeT *destLen,
if (!p->buf) if (!p->buf)
{ {
p->buf = (Byte *)p->alloc->Alloc(p->alloc, CODER_BUF_SIZE * (MIXCODER_NUM_FILTERS_MAX - 1)); p->buf = (Byte *)ISzAlloc_Alloc(p->alloc, CODER_BUF_SIZE * (MIXCODER_NUM_FILTERS_MAX - 1));
if (!p->buf) if (!p->buf)
return SZ_ERROR_MEM; return SZ_ERROR_MEM;
} }
@@ -435,9 +435,10 @@ SRes MixCoder_Code(CMixCoder *p, Byte *dest, SizeT *destLen,
} }
else else
{ {
srcCur = p->buf + (CODER_BUF_SIZE * (i - 1)) + p->pos[i - 1]; size_t k = i - 1;
srcLenCur = p->size[i - 1] - p->pos[i - 1]; srcCur = p->buf + (CODER_BUF_SIZE * k) + p->pos[k];
srcFinishedCur = p->finished[i - 1]; srcLenCur = p->size[k] - p->pos[k];
srcFinishedCur = p->finished[k];
} }
if (i == p->numCoders - 1) if (i == p->numCoders - 1)
@@ -465,7 +466,7 @@ SRes MixCoder_Code(CMixCoder *p, Byte *dest, SizeT *destLen,
} }
else else
{ {
p->pos[i - 1] += srcLenCur; p->pos[(size_t)i - 1] += srcLenCur;
} }
if (i == p->numCoders - 1) if (i == p->numCoders - 1)
@@ -616,7 +617,7 @@ void XzUnpacker_Init(CXzUnpacker *p)
p->padSize = 0; p->padSize = 0;
} }
void XzUnpacker_Construct(CXzUnpacker *p, ISzAlloc *alloc) void XzUnpacker_Construct(CXzUnpacker *p, ISzAllocPtr alloc)
{ {
MixCoder_Construct(&p->decoder, alloc); MixCoder_Construct(&p->decoder, alloc);
XzUnpacker_Init(p); XzUnpacker_Init(p);

View File

@@ -1,7 +1,5 @@
/* XzEnc.c -- Xz Encode /* XzEnc.c -- Xz Encode
2015-09-16 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#include "Precomp.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@@ -26,7 +24,7 @@
static SRes WriteBytes(ISeqOutStream *s, const void *buf, UInt32 size) static SRes WriteBytes(ISeqOutStream *s, const void *buf, UInt32 size)
{ {
return (s->Write(s, buf, size) == size) ? SZ_OK : SZ_ERROR_WRITE; return (ISeqOutStream_Write(s, buf, size) == size) ? SZ_OK : SZ_ERROR_WRITE;
} }
static SRes WriteBytesAndCrc(ISeqOutStream *s, const void *buf, UInt32 size, UInt32 *crc) static SRes WriteBytesAndCrc(ISeqOutStream *s, const void *buf, UInt32 size, UInt32 *crc)
@@ -127,7 +125,7 @@ static SRes Xz_WriteFooter(CXzStream *p, ISeqOutStream *s)
} }
static SRes Xz_AddIndexRecord(CXzStream *p, UInt64 unpackSize, UInt64 totalSize, ISzAlloc *alloc) static SRes Xz_AddIndexRecord(CXzStream *p, UInt64 unpackSize, UInt64 totalSize, ISzAllocPtr alloc)
{ {
if (!p->blocks || p->numBlocksAllocated == p->numBlocks) if (!p->blocks || p->numBlocksAllocated == p->numBlocks)
{ {
@@ -136,13 +134,13 @@ static SRes Xz_AddIndexRecord(CXzStream *p, UInt64 unpackSize, UInt64 totalSize,
CXzBlockSizes *blocks; CXzBlockSizes *blocks;
if (newSize / sizeof(CXzBlockSizes) != num) if (newSize / sizeof(CXzBlockSizes) != num)
return SZ_ERROR_MEM; return SZ_ERROR_MEM;
blocks = (CXzBlockSizes *)alloc->Alloc(alloc, newSize); blocks = (CXzBlockSizes *)ISzAlloc_Alloc(alloc, newSize);
if (!blocks) if (!blocks)
return SZ_ERROR_MEM; return SZ_ERROR_MEM;
if (p->numBlocks != 0) if (p->numBlocks != 0)
{ {
memcpy(blocks, p->blocks, p->numBlocks * sizeof(CXzBlockSizes)); memcpy(blocks, p->blocks, p->numBlocks * sizeof(CXzBlockSizes));
alloc->Free(alloc, p->blocks); ISzAlloc_Free(alloc, p->blocks);
} }
p->blocks = blocks; p->blocks = blocks;
p->numBlocksAllocated = num; p->numBlocksAllocated = num;
@@ -160,7 +158,7 @@ static SRes Xz_AddIndexRecord(CXzStream *p, UInt64 unpackSize, UInt64 totalSize,
typedef struct typedef struct
{ {
ISeqInStream p; ISeqInStream vt;
ISeqInStream *realStream; ISeqInStream *realStream;
UInt64 processed; UInt64 processed;
CXzCheck check; CXzCheck check;
@@ -177,10 +175,10 @@ static void SeqCheckInStream_GetDigest(CSeqCheckInStream *p, Byte *digest)
XzCheck_Final(&p->check, digest); XzCheck_Final(&p->check, digest);
} }
static SRes SeqCheckInStream_Read(void *pp, void *data, size_t *size) static SRes SeqCheckInStream_Read(const ISeqInStream *pp, void *data, size_t *size)
{ {
CSeqCheckInStream *p = (CSeqCheckInStream *)pp; CSeqCheckInStream *p = CONTAINER_FROM_VTBL(pp, CSeqCheckInStream, vt);
SRes res = p->realStream->Read(p->realStream, data, size); SRes res = ISeqInStream_Read(p->realStream, data, size);
XzCheck_Update(&p->check, data, *size); XzCheck_Update(&p->check, data, *size);
p->processed += *size; p->processed += *size;
return res; return res;
@@ -191,15 +189,15 @@ static SRes SeqCheckInStream_Read(void *pp, void *data, size_t *size)
typedef struct typedef struct
{ {
ISeqOutStream p; ISeqOutStream vt;
ISeqOutStream *realStream; ISeqOutStream *realStream;
UInt64 processed; UInt64 processed;
} CSeqSizeOutStream; } CSeqSizeOutStream;
static size_t MyWrite(void *pp, const void *data, size_t size) static size_t MyWrite(const ISeqOutStream *pp, const void *data, size_t size)
{ {
CSeqSizeOutStream *p = (CSeqSizeOutStream *)pp; CSeqSizeOutStream *p = CONTAINER_FROM_VTBL(pp, CSeqSizeOutStream, vt);
size = p->realStream->Write(p->realStream, data, size); size = ISeqOutStream_Write(p->realStream, data, size);
p->processed += size; p->processed += size;
return size; return size;
} }
@@ -220,9 +218,9 @@ typedef struct
int srcWasFinished; int srcWasFinished;
} CSeqInFilter; } CSeqInFilter;
static SRes SeqInFilter_Read(void *pp, void *data, size_t *size) static SRes SeqInFilter_Read(const ISeqInStream *pp, void *data, size_t *size)
{ {
CSeqInFilter *p = (CSeqInFilter *)pp; CSeqInFilter *p = CONTAINER_FROM_VTBL(pp, CSeqInFilter, p);
size_t sizeOriginal = *size; size_t sizeOriginal = *size;
if (sizeOriginal == 0) if (sizeOriginal == 0)
return SZ_OK; return SZ_OK;
@@ -234,7 +232,7 @@ static SRes SeqInFilter_Read(void *pp, void *data, size_t *size)
{ {
p->curPos = 0; p->curPos = 0;
p->endPos = FILTER_BUF_SIZE; p->endPos = FILTER_BUF_SIZE;
RINOK(p->realStream->Read(p->realStream, p->buf, &p->endPos)); RINOK(ISeqInStream_Read(p->realStream, p->buf, &p->endPos));
if (p->endPos == 0) if (p->endPos == 0)
p->srcWasFinished = 1; p->srcWasFinished = 1;
} }
@@ -262,18 +260,18 @@ static void SeqInFilter_Free(CSeqInFilter *p)
{ {
if (p->buf) if (p->buf)
{ {
g_Alloc.Free(&g_Alloc, p->buf); ISzAlloc_Free(&g_Alloc, p->buf);
p->buf = NULL; p->buf = NULL;
} }
} }
SRes BraState_SetFromMethod(IStateCoder *p, UInt64 id, int encodeMode, ISzAlloc *alloc); SRes BraState_SetFromMethod(IStateCoder *p, UInt64 id, int encodeMode, ISzAllocPtr alloc);
static SRes SeqInFilter_Init(CSeqInFilter *p, const CXzFilter *props) static SRes SeqInFilter_Init(CSeqInFilter *p, const CXzFilter *props)
{ {
if (!p->buf) if (!p->buf)
{ {
p->buf = g_Alloc.Alloc(&g_Alloc, FILTER_BUF_SIZE); p->buf = ISzAlloc_Alloc(&g_Alloc, FILTER_BUF_SIZE);
if (!p->buf) if (!p->buf)
return SZ_ERROR_MEM; return SZ_ERROR_MEM;
} }
@@ -292,17 +290,17 @@ static SRes SeqInFilter_Init(CSeqInFilter *p, const CXzFilter *props)
typedef struct typedef struct
{ {
ISeqInStream p; ISeqInStream vt;
ISeqInStream *inStream; ISeqInStream *inStream;
CSbEnc enc; CSbEnc enc;
} CSbEncInStream; } CSbEncInStream;
static SRes SbEncInStream_Read(void *pp, void *data, size_t *size) static SRes SbEncInStream_Read(const ISeqInStream *pp, void *data, size_t *size)
{ {
CSbEncInStream *p = (CSbEncInStream *)pp; CSbEncInStream *p = CONTAINER_FROM_VTBL(pp, CSbEncInStream, vt);
size_t sizeOriginal = *size; size_t sizeOriginal = *size;
if (sizeOriginal == 0) if (sizeOriginal == 0)
return S_OK; return SZ_OK;
for (;;) for (;;)
{ {
@@ -322,14 +320,14 @@ static SRes SbEncInStream_Read(void *pp, void *data, size_t *size)
*size = sizeOriginal; *size = sizeOriginal;
RINOK(SbEnc_Read(&p->enc, data, size)); RINOK(SbEnc_Read(&p->enc, data, size));
if (*size != 0 || !p->enc.needRead) if (*size != 0 || !p->enc.needRead)
return S_OK; return SZ_OK;
} }
} }
void SbEncInStream_Construct(CSbEncInStream *p, ISzAlloc *alloc) void SbEncInStream_Construct(CSbEncInStream *p, ISzAllocPtr alloc)
{ {
SbEnc_Construct(&p->enc, alloc); SbEnc_Construct(&p->enc, alloc);
p->p.Read = SbEncInStream_Read; p->vt.Read = SbEncInStream_Read;
} }
SRes SbEncInStream_Init(CSbEncInStream *p) SRes SbEncInStream_Init(CSbEncInStream *p)
@@ -352,12 +350,12 @@ typedef struct
CSbEncInStream sb; CSbEncInStream sb;
#endif #endif
CSeqInFilter filter; CSeqInFilter filter;
ISzAlloc *alloc; ISzAllocPtr alloc;
ISzAlloc *bigAlloc; ISzAllocPtr bigAlloc;
} CLzma2WithFilters; } CLzma2WithFilters;
static void Lzma2WithFilters_Construct(CLzma2WithFilters *p, ISzAlloc *alloc, ISzAlloc *bigAlloc) static void Lzma2WithFilters_Construct(CLzma2WithFilters *p, ISzAllocPtr alloc, ISzAllocPtr bigAlloc)
{ {
p->alloc = alloc; p->alloc = alloc;
p->bigAlloc = bigAlloc; p->bigAlloc = bigAlloc;
@@ -451,13 +449,13 @@ static SRes Xz_Compress(CXzStream *xz, CLzma2WithFilters *lzmaf,
f->props[0] = Lzma2Enc_WriteProperties(lzmaf->lzma2); f->props[0] = Lzma2Enc_WriteProperties(lzmaf->lzma2);
} }
seqSizeOutStream.p.Write = MyWrite; seqSizeOutStream.vt.Write = MyWrite;
seqSizeOutStream.realStream = outStream; seqSizeOutStream.realStream = outStream;
seqSizeOutStream.processed = 0; seqSizeOutStream.processed = 0;
RINOK(XzBlock_WriteHeader(&block, &seqSizeOutStream.p)); RINOK(XzBlock_WriteHeader(&block, &seqSizeOutStream.vt));
checkInStream.p.Read = SeqCheckInStream_Read; checkInStream.vt.Read = SeqCheckInStream_Read;
checkInStream.realStream = inStream; checkInStream.realStream = inStream;
SeqCheckInStream_Init(&checkInStream, XzFlags_GetCheckType(xz->flags)); SeqCheckInStream_Init(&checkInStream, XzFlags_GetCheckType(xz->flags));
@@ -466,13 +464,13 @@ static SRes Xz_Compress(CXzStream *xz, CLzma2WithFilters *lzmaf,
#ifdef USE_SUBBLOCK #ifdef USE_SUBBLOCK
if (fp->id == XZ_ID_Subblock) if (fp->id == XZ_ID_Subblock)
{ {
lzmaf->sb.inStream = &checkInStream.p; lzmaf->sb.inStream = &checkInStream.vt;
RINOK(SbEncInStream_Init(&lzmaf->sb)); RINOK(SbEncInStream_Init(&lzmaf->sb));
} }
else else
#endif #endif
{ {
lzmaf->filter.realStream = &checkInStream.p; lzmaf->filter.realStream = &checkInStream.vt;
RINOK(SeqInFilter_Init(&lzmaf->filter, filter)); RINOK(SeqInFilter_Init(&lzmaf->filter, filter));
} }
} }
@@ -480,13 +478,13 @@ static SRes Xz_Compress(CXzStream *xz, CLzma2WithFilters *lzmaf,
{ {
UInt64 packPos = seqSizeOutStream.processed; UInt64 packPos = seqSizeOutStream.processed;
SRes res = Lzma2Enc_Encode(lzmaf->lzma2, &seqSizeOutStream.p, SRes res = Lzma2Enc_Encode(lzmaf->lzma2, &seqSizeOutStream.vt,
fp ? fp ?
#ifdef USE_SUBBLOCK #ifdef USE_SUBBLOCK
(fp->id == XZ_ID_Subblock) ? &lzmaf->sb.p: (fp->id == XZ_ID_Subblock) ? &lzmaf->sb.vt:
#endif #endif
&lzmaf->filter.p: &lzmaf->filter.p:
&checkInStream.p, &checkInStream.vt,
progress); progress);
RINOK(res); RINOK(res);
@@ -500,7 +498,7 @@ static SRes Xz_Compress(CXzStream *xz, CLzma2WithFilters *lzmaf,
while ((((unsigned)block.packSize + padSize) & 3) != 0) while ((((unsigned)block.packSize + padSize) & 3) != 0)
buf[padSize++] = 0; buf[padSize++] = 0;
SeqCheckInStream_GetDigest(&checkInStream, buf + padSize); SeqCheckInStream_GetDigest(&checkInStream, buf + padSize);
RINOK(WriteBytes(&seqSizeOutStream.p, buf, padSize + XzFlags_GetCheckSize(xz->flags))); RINOK(WriteBytes(&seqSizeOutStream.vt, buf, padSize + XzFlags_GetCheckSize(xz->flags)));
RINOK(Xz_AddIndexRecord(xz, block.unpackSize, seqSizeOutStream.processed - padSize, &g_Alloc)); RINOK(Xz_AddIndexRecord(xz, block.unpackSize, seqSizeOutStream.processed - padSize, &g_Alloc));
} }
} }

View File

@@ -1,5 +1,5 @@
/* XzIn.c - Xz input /* XzIn.c - Xz input
2015-11-08 : Igor Pavlov : Public domain */ 2017-04-03 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@@ -70,7 +70,7 @@ SRes XzBlock_ReadFooter(CXzBlock *p, CXzStreamFlags f, ISeqInStream *inStream)
} }
*/ */
static SRes Xz_ReadIndex2(CXzStream *p, const Byte *buf, size_t size, ISzAlloc *alloc) static SRes Xz_ReadIndex2(CXzStream *p, const Byte *buf, size_t size, ISzAllocPtr alloc)
{ {
size_t numBlocks, pos = 1; size_t numBlocks, pos = 1;
UInt32 crc; UInt32 crc;
@@ -97,7 +97,7 @@ static SRes Xz_ReadIndex2(CXzStream *p, const Byte *buf, size_t size, ISzAlloc *
size_t i; size_t i;
p->numBlocks = numBlocks; p->numBlocks = numBlocks;
p->numBlocksAllocated = numBlocks; p->numBlocksAllocated = numBlocks;
p->blocks = alloc->Alloc(alloc, sizeof(CXzBlockSizes) * numBlocks); p->blocks = ISzAlloc_Alloc(alloc, sizeof(CXzBlockSizes) * numBlocks);
if (p->blocks == 0) if (p->blocks == 0)
return SZ_ERROR_MEM; return SZ_ERROR_MEM;
for (i = 0; i < numBlocks; i++) for (i = 0; i < numBlocks; i++)
@@ -115,7 +115,7 @@ static SRes Xz_ReadIndex2(CXzStream *p, const Byte *buf, size_t size, ISzAlloc *
return (pos == size) ? SZ_OK : SZ_ERROR_ARCHIVE; return (pos == size) ? SZ_OK : SZ_ERROR_ARCHIVE;
} }
static SRes Xz_ReadIndex(CXzStream *p, ILookInStream *stream, UInt64 indexSize, ISzAlloc *alloc) static SRes Xz_ReadIndex(CXzStream *p, ILookInStream *stream, UInt64 indexSize, ISzAllocPtr alloc)
{ {
SRes res; SRes res;
size_t size; size_t size;
@@ -125,13 +125,13 @@ static SRes Xz_ReadIndex(CXzStream *p, ILookInStream *stream, UInt64 indexSize,
size = (size_t)indexSize; size = (size_t)indexSize;
if (size != indexSize) if (size != indexSize)
return SZ_ERROR_UNSUPPORTED; return SZ_ERROR_UNSUPPORTED;
buf = alloc->Alloc(alloc, size); buf = ISzAlloc_Alloc(alloc, size);
if (buf == 0) if (buf == 0)
return SZ_ERROR_MEM; return SZ_ERROR_MEM;
res = LookInStream_Read2(stream, buf, size, SZ_ERROR_UNSUPPORTED); res = LookInStream_Read2(stream, buf, size, SZ_ERROR_UNSUPPORTED);
if (res == SZ_OK) if (res == SZ_OK)
res = Xz_ReadIndex2(p, buf, size, alloc); res = Xz_ReadIndex2(p, buf, size, alloc);
alloc->Free(alloc, buf); ISzAlloc_Free(alloc, buf);
return res; return res;
} }
@@ -142,7 +142,7 @@ static SRes LookInStream_SeekRead_ForArc(ILookInStream *stream, UInt64 offset, v
/* return LookInStream_Read2(stream, buf, size, SZ_ERROR_NO_ARCHIVE); */ /* return LookInStream_Read2(stream, buf, size, SZ_ERROR_NO_ARCHIVE); */
} }
static SRes Xz_ReadBackward(CXzStream *p, ILookInStream *stream, Int64 *startOffset, ISzAlloc *alloc) static SRes Xz_ReadBackward(CXzStream *p, ILookInStream *stream, Int64 *startOffset, ISzAllocPtr alloc)
{ {
UInt64 indexSize; UInt64 indexSize;
Byte buf[XZ_STREAM_FOOTER_SIZE]; Byte buf[XZ_STREAM_FOOTER_SIZE];
@@ -224,7 +224,7 @@ static SRes Xz_ReadBackward(CXzStream *p, ILookInStream *stream, Int64 *startOff
SecToRead_CreateVTable(&secToRead); SecToRead_CreateVTable(&secToRead);
secToRead.realStream = stream; secToRead.realStream = stream;
RINOK(Xz_ReadHeader(&headerFlags, &secToRead.s)); RINOK(Xz_ReadHeader(&headerFlags, &secToRead.vt));
return (p->flags == headerFlags) ? SZ_OK : SZ_ERROR_ARCHIVE; return (p->flags == headerFlags) ? SZ_OK : SZ_ERROR_ARCHIVE;
} }
} }
@@ -238,12 +238,12 @@ void Xzs_Construct(CXzs *p)
p->streams = 0; p->streams = 0;
} }
void Xzs_Free(CXzs *p, ISzAlloc *alloc) void Xzs_Free(CXzs *p, ISzAllocPtr alloc)
{ {
size_t i; size_t i;
for (i = 0; i < p->num; i++) for (i = 0; i < p->num; i++)
Xz_Free(&p->streams[i], alloc); Xz_Free(&p->streams[i], alloc);
alloc->Free(alloc, p->streams); ISzAlloc_Free(alloc, p->streams);
p->num = p->numAllocated = 0; p->num = p->numAllocated = 0;
p->streams = 0; p->streams = 0;
} }
@@ -277,10 +277,10 @@ UInt64 Xzs_GetPackSize(const CXzs *p)
} }
*/ */
SRes Xzs_ReadBackward(CXzs *p, ILookInStream *stream, Int64 *startOffset, ICompressProgress *progress, ISzAlloc *alloc) SRes Xzs_ReadBackward(CXzs *p, ILookInStream *stream, Int64 *startOffset, ICompressProgress *progress, ISzAllocPtr alloc)
{ {
Int64 endOffset = 0; Int64 endOffset = 0;
RINOK(stream->Seek(stream, &endOffset, SZ_SEEK_END)); RINOK(ILookInStream_Seek(stream, &endOffset, SZ_SEEK_END));
*startOffset = endOffset; *startOffset = endOffset;
for (;;) for (;;)
{ {
@@ -293,20 +293,20 @@ SRes Xzs_ReadBackward(CXzs *p, ILookInStream *stream, Int64 *startOffset, ICompr
if (p->num == p->numAllocated) if (p->num == p->numAllocated)
{ {
size_t newNum = p->num + p->num / 4 + 1; size_t newNum = p->num + p->num / 4 + 1;
Byte *data = (Byte *)alloc->Alloc(alloc, newNum * sizeof(CXzStream)); Byte *data = (Byte *)ISzAlloc_Alloc(alloc, newNum * sizeof(CXzStream));
if (data == 0) if (data == 0)
return SZ_ERROR_MEM; return SZ_ERROR_MEM;
p->numAllocated = newNum; p->numAllocated = newNum;
if (p->num != 0) if (p->num != 0)
memcpy(data, p->streams, p->num * sizeof(CXzStream)); memcpy(data, p->streams, p->num * sizeof(CXzStream));
alloc->Free(alloc, p->streams); ISzAlloc_Free(alloc, p->streams);
p->streams = (CXzStream *)data; p->streams = (CXzStream *)data;
} }
p->streams[p->num++] = st; p->streams[p->num++] = st;
if (*startOffset == 0) if (*startOffset == 0)
break; break;
RINOK(LookInStream_SeekTo(stream, *startOffset)); RINOK(LookInStream_SeekTo(stream, *startOffset));
if (progress && progress->Progress(progress, endOffset - *startOffset, (UInt64)(Int64)-1) != SZ_OK) if (progress && ICompressProgress_Progress(progress, endOffset - *startOffset, (UInt64)(Int64)-1) != SZ_OK)
return SZ_ERROR_PROGRESS; return SZ_ERROR_PROGRESS;
} }
return SZ_OK; return SZ_OK;

View File

@@ -1,7 +1,7 @@
C_OBJS = $(C_OBJS) \ C_OBJS = $(C_OBJS) \
$O\Aes.obj $O\Aes.obj
!IF "$(CPU)" != "IA64" && "$(CPU)" != "MIPS" && "$(CPU)" != "ARM" !IF "$(CPU)" != "IA64" && "$(CPU)" != "MIPS" && "$(CPU)" != "ARM" && "$(CPU)" != "ARM64"
ASM_OBJS = $(ASM_OBJS) \ ASM_OBJS = $(ASM_OBJS) \
$O\AesOpt.obj $O\AesOpt.obj
!ENDIF !ENDIF

View File

@@ -226,11 +226,13 @@ HRESULT CDecoder::Decode(
, ISequentialOutStream *outStream , ISequentialOutStream *outStream
, ICompressProgressInfo *compressProgress , ICompressProgressInfo *compressProgress
, ISequentialInStream ** , ISequentialInStream **
#ifdef USE_MIXER_ST
inStreamMainRes
#endif
#ifdef USE_MIXER_ST , bool &dataAfterEnd_Error
inStreamMainRes
#endif
_7Z_DECODER_CRYPRO_VARS_DECL _7Z_DECODER_CRYPRO_VARS_DECL
@@ -239,6 +241,8 @@ HRESULT CDecoder::Decode(
#endif #endif
) )
{ {
dataAfterEnd_Error = false;
const UInt64 *packPositions = &folders.PackPositions[folders.FoStartPackStreamIndex[folderIndex]]; const UInt64 *packPositions = &folders.PackPositions[folders.FoStartPackStreamIndex[folderIndex]];
CFolderEx folderInfo; CFolderEx folderInfo;
folders.ParseFolderEx(folderIndex, folderInfo); folders.ParseFolderEx(folderIndex, folderInfo);
@@ -415,12 +419,14 @@ HRESULT CDecoder::Decode(
} }
#endif #endif
bool finishMode = false;
{ {
CMyComPtr<ICompressSetFinishMode> setFinishMode; CMyComPtr<ICompressSetFinishMode> setFinishMode;
decoder->QueryInterface(IID_ICompressSetFinishMode, (void **)&setFinishMode); decoder->QueryInterface(IID_ICompressSetFinishMode, (void **)&setFinishMode);
if (setFinishMode) if (setFinishMode)
{ {
RINOK(setFinishMode->SetFinishMode(BoolToInt(fullUnpack))); finishMode = fullUnpack;
RINOK(setFinishMode->SetFinishMode(BoolToInt(finishMode)));
} }
} }
@@ -450,7 +456,7 @@ HRESULT CDecoder::Decode(
unpackSize : unpackSize :
&folders.CoderUnpackSizes[unpackStreamIndexStart + i]; &folders.CoderUnpackSizes[unpackStreamIndexStart + i];
_mixer->SetCoderInfo(i, unpackSizesPointer, packSizesPointers); _mixer->SetCoderInfo(i, unpackSizesPointer, packSizesPointers, finishMode);
} }
if (outStream) if (outStream)
@@ -530,7 +536,9 @@ HRESULT CDecoder::Decode(
progress2 = new CDecProgress(compressProgress); progress2 = new CDecProgress(compressProgress);
ISequentialOutStream *outStreamPointer = outStream; ISequentialOutStream *outStreamPointer = outStream;
return _mixer->Code(inStreamPointers, &outStreamPointer, progress2 ? (ICompressProgressInfo *)progress2 : compressProgress); return _mixer->Code(inStreamPointers, &outStreamPointer,
progress2 ? (ICompressProgressInfo *)progress2 : compressProgress,
dataAfterEnd_Error);
} }
#ifdef USE_MIXER_ST #ifdef USE_MIXER_ST

View File

@@ -53,7 +53,9 @@ public:
, ISequentialOutStream *outStream , ISequentialOutStream *outStream
, ICompressProgressInfo *compressProgress , ICompressProgressInfo *compressProgress
, ISequentialInStream **inStreamMainRes , ISequentialInStream **inStreamMainRes
, bool &dataAfterEnd_Error
_7Z_DECODER_CRYPRO_VARS_DECL _7Z_DECODER_CRYPRO_VARS_DECL

View File

@@ -333,7 +333,7 @@ HRESULT CEncoder::Encode(
} }
for (i = 0; i < numMethods; i++) for (i = 0; i < numMethods; i++)
_mixer->SetCoderInfo(i, NULL, NULL); _mixer->SetCoderInfo(i, NULL, NULL, false);
/* inStreamSize can be used by BCJ2 to set optimal range of conversion. /* inStreamSize can be used by BCJ2 to set optimal range of conversion.
@@ -429,10 +429,12 @@ HRESULT CEncoder::Encode(
for (i = 1; i < _bindInfo.PackStreams.Size(); i++) for (i = 1; i < _bindInfo.PackStreams.Size(); i++)
outStreamPointers.Add(tempBuffers[i - 1]); outStreamPointers.Add(tempBuffers[i - 1]);
bool dataAfterEnd_Error;
RINOK(_mixer->Code( RINOK(_mixer->Code(
&inStreamPointer, &inStreamPointer,
&outStreamPointers.Front(), &outStreamPointers.Front(),
mtProgress ? (ICompressProgressInfo *)mtProgress : compressProgress)); mtProgress ? (ICompressProgressInfo *)mtProgress : compressProgress, dataAfterEnd_Error));
if (_bindInfo.PackStreams.Size() != 0) if (_bindInfo.PackStreams.Size() != 0)
packSizes.Add(outStreamSizeCountSpec->GetSize()); packSizes.Add(outStreamSizeCountSpec->GetSize());

View File

@@ -348,6 +348,8 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
#endif #endif
bool dataAfterEnd_Error = false;
HRESULT result = decoder.Decode( HRESULT result = decoder.Decode(
EXTERNAL_CODECS_VARS EXTERNAL_CODECS_VARS
_inStream, _inStream,
@@ -358,6 +360,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
outStream, outStream,
progress, progress,
NULL // *inStreamMainRes NULL // *inStreamMainRes
, dataAfterEnd_Error
_7Z_DECODER_CRYPRO_VARS _7Z_DECODER_CRYPRO_VARS
#if !defined(_7ZIP_ST) && !defined(_SFX) #if !defined(_7ZIP_ST) && !defined(_SFX)
@@ -365,13 +368,19 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
#endif #endif
); );
if (result == S_FALSE || result == E_NOTIMPL) if (result == S_FALSE || result == E_NOTIMPL || dataAfterEnd_Error)
{ {
bool wasFinished = folderOutStream->WasWritingFinished(); bool wasFinished = folderOutStream->WasWritingFinished();
int resOp = (result == S_FALSE ? int resOp = NExtract::NOperationResult::kDataError;
NExtract::NOperationResult::kDataError :
NExtract::NOperationResult::kUnsupportedMethod); if (result != S_FALSE)
{
if (result == E_NOTIMPL)
resOp = NExtract::NOperationResult::kUnsupportedMethod;
else if (wasFinished && dataAfterEnd_Error)
resOp = NExtract::NOperationResult::kDataAfterEnd;
}
RINOK(folderOutStream->FlushCorrupted(resOp)); RINOK(folderOutStream->FlushCorrupted(resOp));

View File

@@ -540,7 +540,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
*/ */
const CFileItem &item = _db.Files[index]; const CFileItem &item = _db.Files[index];
UInt32 index2 = index; const UInt32 index2 = index;
switch (propID) switch (propID)
{ {
@@ -575,7 +575,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
case kpidCTime: SetFileTimeProp_From_UInt64Def(value, _db.CTime, index2); break; case kpidCTime: SetFileTimeProp_From_UInt64Def(value, _db.CTime, index2); break;
case kpidATime: SetFileTimeProp_From_UInt64Def(value, _db.ATime, index2); break; case kpidATime: SetFileTimeProp_From_UInt64Def(value, _db.ATime, index2); break;
case kpidMTime: SetFileTimeProp_From_UInt64Def(value, _db.MTime, index2); break; case kpidMTime: SetFileTimeProp_From_UInt64Def(value, _db.MTime, index2); break;
case kpidAttrib: if (item.AttribDefined) PropVarEm_Set_UInt32(value, item.Attrib); break; case kpidAttrib: if (_db.Attrib.ValidAndDefined(index2)) PropVarEm_Set_UInt32(value, _db.Attrib.Vals[index2]); break;
case kpidCRC: if (item.CrcDefined) PropVarEm_Set_UInt32(value, item.Crc); break; case kpidCRC: if (item.CrcDefined) PropVarEm_Set_UInt32(value, item.Crc); break;
case kpidEncrypted: PropVarEm_Set_Bool(value, IsFolderEncrypted(_db.FileIndexToFolderIndexMap[index2])); break; case kpidEncrypted: PropVarEm_Set_Bool(value, IsFolderEncrypted(_db.FileIndexToFolderIndexMap[index2])); break;
case kpidIsAnti: PropVarEm_Set_Bool(value, _db.IsItemAnti(index2)); break; case kpidIsAnti: PropVarEm_Set_Bool(value, _db.IsItemAnti(index2)); break;

View File

@@ -54,6 +54,7 @@ public:
CBoolPair Write_CTime; CBoolPair Write_CTime;
CBoolPair Write_ATime; CBoolPair Write_ATime;
CBoolPair Write_MTime; CBoolPair Write_MTime;
CBoolPair Write_Attrib;
bool _useMultiThreadMixer; bool _useMultiThreadMixer;

View File

@@ -18,11 +18,12 @@ using namespace NWindows;
namespace NArchive { namespace NArchive {
namespace N7z { namespace N7z {
static const char *k_LZMA_Name = "LZMA"; #define k_LZMA_Name "LZMA"
static const char *kDefaultMethodName = "LZMA2"; #define kDefaultMethodName "LZMA2"
static const char *k_Copy_Name = "Copy"; #define k_Copy_Name "Copy"
#define k_MatchFinder_ForHeaders "BT2"
static const char *k_MatchFinder_ForHeaders = "BT2";
static const UInt32 k_NumFastBytes_ForHeaders = 273; static const UInt32 k_NumFastBytes_ForHeaders = 273;
static const UInt32 k_Level_ForHeaders = 5; static const UInt32 k_Level_ForHeaders = 5;
static const UInt32 k_Dictionary_ForHeaders = static const UInt32 k_Dictionary_ForHeaders =
@@ -113,11 +114,11 @@ HRESULT CHandler::SetMainMethod(
FOR_VECTOR (i, methods) FOR_VECTOR (i, methods)
{ {
COneMethodInfo &oneMethodInfo = methods[i]; COneMethodInfo &oneMethodInfo = methods[i];
SetGlobalLevelAndThreads(oneMethodInfo
#ifndef _7ZIP_ST SetGlobalLevelTo(oneMethodInfo);
, numThreads #ifndef _7ZIP_ST
#endif CMultiMethodProps::SetMethodThreadsTo(oneMethodInfo, numThreads);
); #endif
CMethodFull &methodFull = methodMode.Methods.AddNew(); CMethodFull &methodFull = methodMode.Methods.AddNew();
RINOK(PropsMethod_To_FullMethod(methodFull, oneMethodInfo)); RINOK(PropsMethod_To_FullMethod(methodFull, oneMethodInfo));
@@ -282,15 +283,18 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
bool need_CTime = (Write_CTime.Def && Write_CTime.Val); bool need_CTime = (Write_CTime.Def && Write_CTime.Val);
bool need_ATime = (Write_ATime.Def && Write_ATime.Val); bool need_ATime = (Write_ATime.Def && Write_ATime.Val);
bool need_MTime = (Write_MTime.Def && Write_MTime.Val || !Write_MTime.Def); bool need_MTime = (Write_MTime.Def && Write_MTime.Val || !Write_MTime.Def);
bool need_Attrib = (Write_Attrib.Def && Write_Attrib.Val || !Write_Attrib.Def);
if (db && !db->Files.IsEmpty()) if (db && !db->Files.IsEmpty())
{ {
if (!Write_CTime.Def) need_CTime = !db->CTime.Defs.IsEmpty(); if (!Write_CTime.Def) need_CTime = !db->CTime.Defs.IsEmpty();
if (!Write_ATime.Def) need_ATime = !db->ATime.Defs.IsEmpty(); if (!Write_ATime.Def) need_ATime = !db->ATime.Defs.IsEmpty();
if (!Write_MTime.Def) need_MTime = !db->MTime.Defs.IsEmpty(); if (!Write_MTime.Def) need_MTime = !db->MTime.Defs.IsEmpty();
if (!Write_Attrib.Def) need_Attrib = !db->Attrib.Defs.IsEmpty();
} }
UString s; // UString s;
UString name;
for (UInt32 i = 0; i < numItems; i++) for (UInt32 i = 0; i < numItems; i++)
{ {
@@ -307,7 +311,7 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
ui.IsAnti = false; ui.IsAnti = false;
ui.Size = 0; ui.Size = 0;
UString name; name.Empty();
// bool isAltStream = false; // bool isAltStream = false;
if (ui.IndexInArchive != -1) if (ui.IndexInArchive != -1)
{ {
@@ -334,6 +338,7 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
if (ui.NewProps) if (ui.NewProps)
{ {
bool folderStatusIsDefined; bool folderStatusIsDefined;
if (need_Attrib)
{ {
NCOM::CPropVariant prop; NCOM::CPropVariant prop;
RINOK(updateCallback->GetProperty(i, kpidAttrib, &prop)); RINOK(updateCallback->GetProperty(i, kpidAttrib, &prop));
@@ -377,7 +382,8 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
return E_INVALIDARG; return E_INVALIDARG;
else else
{ {
name = NItemName::MakeLegalName(prop.bstrVal); name = prop.bstrVal;
NItemName::ReplaceSlashes_OsToUnix(name);
} }
} }
{ {
@@ -614,6 +620,7 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
options.HeaderOptions.WriteCTime = Write_CTime; options.HeaderOptions.WriteCTime = Write_CTime;
options.HeaderOptions.WriteATime = Write_ATime; options.HeaderOptions.WriteATime = Write_ATime;
options.HeaderOptions.WriteMTime = Write_MTime; options.HeaderOptions.WriteMTime = Write_MTime;
options.HeaderOptions.WriteAttrib = Write_Attrib;
*/ */
options.NumSolidFiles = _numSolidFiles; options.NumSolidFiles = _numSolidFiles;
@@ -705,6 +712,7 @@ void COutHandler::InitProps()
Write_CTime.Init(); Write_CTime.Init();
Write_ATime.Init(); Write_ATime.Init();
Write_MTime.Init(); Write_MTime.Init();
Write_Attrib.Init();
_useMultiThreadMixer = true; _useMultiThreadMixer = true;
@@ -830,6 +838,8 @@ HRESULT COutHandler::SetProperty(const wchar_t *nameSpec, const PROPVARIANT &val
if (name.IsEqualTo("ta")) return PROPVARIANT_to_BoolPair(value, Write_ATime); if (name.IsEqualTo("ta")) return PROPVARIANT_to_BoolPair(value, Write_ATime);
if (name.IsEqualTo("tm")) return PROPVARIANT_to_BoolPair(value, Write_MTime); if (name.IsEqualTo("tm")) return PROPVARIANT_to_BoolPair(value, Write_MTime);
if (name.IsEqualTo("tr")) return PROPVARIANT_to_BoolPair(value, Write_Attrib);
if (name.IsEqualTo("mtf")) return PROPVARIANT_to_bool(value, _useMultiThreadMixer); if (name.IsEqualTo("mtf")) return PROPVARIANT_to_bool(value, _useMultiThreadMixer);
if (name.IsEqualTo("qs")) return PROPVARIANT_to_bool(value, _useTypeSorting); if (name.IsEqualTo("qs")) return PROPVARIANT_to_bool(value, _useTypeSorting);

View File

@@ -32,6 +32,21 @@ using namespace NCOM;
namespace NArchive { namespace NArchive {
namespace N7z { namespace N7z {
unsigned BoolVector_CountSum(const CBoolVector &v)
{
unsigned sum = 0;
const unsigned size = v.Size();
for (unsigned i = 0; i < size; i++)
if (v[i])
sum++;
return sum;
}
static inline bool BoolVector_Item_IsValidAndTrue(const CBoolVector &v, unsigned i)
{
return (i < v.Size() ? v[i] : false);
}
static void BoolVector_Fill_False(CBoolVector &v, unsigned size) static void BoolVector_Fill_False(CBoolVector &v, unsigned size)
{ {
v.ClearAndSetSize(size); v.ClearAndSetSize(size);
@@ -40,6 +55,7 @@ static void BoolVector_Fill_False(CBoolVector &v, unsigned size)
p[i] = false; p[i] = false;
} }
class CInArchiveException {}; class CInArchiveException {};
class CUnsupportedFeatureException: public CInArchiveException {}; class CUnsupportedFeatureException: public CInArchiveException {};
@@ -566,21 +582,30 @@ void CInArchive::WaitId(UInt64 id)
} }
} }
void CInArchive::Read_UInt32_Vector(CUInt32DefVector &v)
{
unsigned numItems = v.Defs.Size();
v.Vals.ClearAndSetSize(numItems);
UInt32 *p = &v.Vals[0];
const bool *defs = &v.Defs[0];
for (unsigned i = 0; i < numItems; i++)
{
UInt32 a = 0;
if (defs[i])
a = ReadUInt32();
p[i] = a;
}
}
void CInArchive::ReadHashDigests(unsigned numItems, CUInt32DefVector &crcs) void CInArchive::ReadHashDigests(unsigned numItems, CUInt32DefVector &crcs)
{ {
ReadBoolVector2(numItems, crcs.Defs); ReadBoolVector2(numItems, crcs.Defs);
crcs.Vals.ClearAndSetSize(numItems); Read_UInt32_Vector(crcs);
UInt32 *p = &crcs.Vals[0];
const bool *defs = &crcs.Defs[0];
for (unsigned i = 0; i < numItems; i++)
{
UInt32 crc = 0;
if (defs[i])
crc = ReadUInt32();
p[i] = crc;
}
} }
#define k_Scan_NumCoders_MAX 64 #define k_Scan_NumCoders_MAX 64
#define k_Scan_NumCodersStreams_in_Folder_MAX 64 #define k_Scan_NumCodersStreams_in_Folder_MAX 64
@@ -1075,6 +1100,8 @@ HRESULT CInArchive::ReadAndDecodePackedStreams(
CMyComPtr<ISequentialOutStream> outStream = outStreamSpec; CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;
outStreamSpec->Init(data, unpackSize); outStreamSpec->Init(data, unpackSize);
bool dataAfterEnd_Error = false;
HRESULT result = decoder.Decode( HRESULT result = decoder.Decode(
EXTERNAL_CODECS_LOC_VARS EXTERNAL_CODECS_LOC_VARS
_stream, baseOffset + dataOffset, _stream, baseOffset + dataOffset,
@@ -1083,16 +1110,23 @@ HRESULT CInArchive::ReadAndDecodePackedStreams(
outStream, outStream,
NULL, // *compressProgress NULL, // *compressProgress
NULL // **inStreamMainRes NULL // **inStreamMainRes
, dataAfterEnd_Error
_7Z_DECODER_CRYPRO_VARS _7Z_DECODER_CRYPRO_VARS
#if !defined(_7ZIP_ST) && !defined(_SFX) #if !defined(_7ZIP_ST) && !defined(_SFX)
, false // mtMode , false // mtMode
, 1 // numThreads , 1 // numThreads
#endif #endif
); );
RINOK(result); RINOK(result);
if (dataAfterEnd_Error)
ThereIsHeaderError = true;
if (folders.FolderCRCs.ValidAndDefined(i)) if (folders.FolderCRCs.ValidAndDefined(i))
if (CrcCalc(data, unpackSize) != folders.FolderCRCs.Vals[i]) if (CrcCalc(data, unpackSize) != folders.FolderCRCs.Vals[i])
ThrowIncorrect(); ThrowIncorrect();
@@ -1148,19 +1182,10 @@ HRESULT CInArchive::ReadHeader(
type = ReadID(); type = ReadID();
} }
db.Files.Clear();
if (type == NID::kFilesInfo) if (type == NID::kFilesInfo)
{ {
const CNum numFiles = ReadNum(); const CNum numFiles = ReadNum();
db.Files.ClearAndSetSize(numFiles);
/*
db.Files.Reserve(numFiles);
CNum i;
for (i = 0; i < numFiles; i++)
db.Files.Add(CFileItem());
*/
db.ArcInfo.FileInfoPopIDs.Add(NID::kSize); db.ArcInfo.FileInfoPopIDs.Add(NID::kSize);
// if (!db.PackSizes.IsEmpty()) // if (!db.PackSizes.IsEmpty())
@@ -1169,7 +1194,6 @@ HRESULT CInArchive::ReadHeader(
db.ArcInfo.FileInfoPopIDs.Add(NID::kCRC); db.ArcInfo.FileInfoPopIDs.Add(NID::kCRC);
CBoolVector emptyStreamVector; CBoolVector emptyStreamVector;
BoolVector_Fill_False(emptyStreamVector, (unsigned)numFiles);
CBoolVector emptyFileVector; CBoolVector emptyFileVector;
CBoolVector antiFileVector; CBoolVector antiFileVector;
CNum numEmptyStreams = 0; CNum numEmptyStreams = 0;
@@ -1197,10 +1221,10 @@ HRESULT CInArchive::ReadHeader(
size_t rem = _inByteBack->GetRem(); size_t rem = _inByteBack->GetRem();
db.NamesBuf.Alloc(rem); db.NamesBuf.Alloc(rem);
ReadBytes(db.NamesBuf, rem); ReadBytes(db.NamesBuf, rem);
db.NameOffsets.Alloc(db.Files.Size() + 1); db.NameOffsets.Alloc(numFiles + 1);
size_t pos = 0; size_t pos = 0;
unsigned i; unsigned i;
for (i = 0; i < db.Files.Size(); i++) for (i = 0; i < numFiles; i++)
{ {
size_t curRem = (rem - pos) / 2; size_t curRem = (rem - pos) / 2;
const UInt16 *buf = (const UInt16 *)(db.NamesBuf + pos); const UInt16 *buf = (const UInt16 *)(db.NamesBuf + pos);
@@ -1216,36 +1240,31 @@ HRESULT CInArchive::ReadHeader(
ThereIsHeaderError = true; ThereIsHeaderError = true;
break; break;
} }
case NID::kWinAttrib: case NID::kWinAttrib:
{ {
CBoolVector boolVector; ReadBoolVector2(numFiles, db.Attrib.Defs);
ReadBoolVector2(db.Files.Size(), boolVector);
CStreamSwitch streamSwitch; CStreamSwitch streamSwitch;
streamSwitch.Set(this, &dataVector); streamSwitch.Set(this, &dataVector);
for (CNum i = 0; i < numFiles; i++) Read_UInt32_Vector(db.Attrib);
{
CFileItem &file = db.Files[i];
file.AttribDefined = boolVector[i];
if (file.AttribDefined)
file.Attrib = ReadUInt32();
}
break; break;
} }
/* /*
case NID::kIsAux: case NID::kIsAux:
{ {
ReadBoolVector(db.Files.Size(), db.IsAux); ReadBoolVector(numFiles, db.IsAux);
break; break;
} }
case NID::kParent: case NID::kParent:
{ {
db.IsTree = true; db.IsTree = true;
// CBoolVector boolVector; // CBoolVector boolVector;
// ReadBoolVector2(db.Files.Size(), boolVector); // ReadBoolVector2(numFiles, boolVector);
// CStreamSwitch streamSwitch; // CStreamSwitch streamSwitch;
// streamSwitch.Set(this, &dataVector); // streamSwitch.Set(this, &dataVector);
CBoolVector boolVector; CBoolVector boolVector;
ReadBoolVector2(db.Files.Size(), boolVector); ReadBoolVector2(numFiles, boolVector);
db.ThereAreAltStreams = false; db.ThereAreAltStreams = false;
for (i = 0; i < numFiles; i++) for (i = 0; i < numFiles; i++)
@@ -1264,14 +1283,9 @@ HRESULT CInArchive::ReadHeader(
case NID::kEmptyStream: case NID::kEmptyStream:
{ {
ReadBoolVector(numFiles, emptyStreamVector); ReadBoolVector(numFiles, emptyStreamVector);
numEmptyStreams = 0; numEmptyStreams = BoolVector_CountSum(emptyStreamVector);
for (CNum i = 0; i < (CNum)emptyStreamVector.Size(); i++) emptyFileVector.Clear();
if (emptyStreamVector[i]) antiFileVector.Clear();
numEmptyStreams++;
BoolVector_Fill_False(emptyFileVector, numEmptyStreams);
BoolVector_Fill_False(antiFileVector, numEmptyStreams);
break; break;
} }
case NID::kEmptyFile: ReadBoolVector(numEmptyStreams, emptyFileVector); break; case NID::kEmptyFile: ReadBoolVector(numEmptyStreams, emptyFileVector); break;
@@ -1314,7 +1328,7 @@ HRESULT CInArchive::ReadHeader(
ReadBytes(db.SecureBuf + offset, db.SecureOffsets[i + 1] - offset); ReadBytes(db.SecureBuf + offset, db.SecureOffsets[i + 1] - offset);
} }
db.SecureIDs.Clear(); db.SecureIDs.Clear();
for (unsigned i = 0; i < db.Files.Size(); i++) for (unsigned i = 0; i < numFiles; i++)
{ {
db.SecureIDs.Add(ReadNum()); db.SecureIDs.Add(ReadNum());
// db.SecureIDs.Add(ReadUInt32()); // db.SecureIDs.Add(ReadUInt32());
@@ -1359,22 +1373,21 @@ HRESULT CInArchive::ReadHeader(
CNum emptyFileIndex = 0; CNum emptyFileIndex = 0;
CNum sizeIndex = 0; CNum sizeIndex = 0;
CNum numAntiItems = 0; const CNum numAntiItems = BoolVector_CountSum(antiFileVector);
CNum i; if (numAntiItems != 0)
db.IsAnti.ClearAndSetSize(numFiles);
for (i = 0; i < numEmptyStreams; i++) db.Files.ClearAndSetSize(numFiles);
if (antiFileVector[i])
numAntiItems++;
for (i = 0; i < numFiles; i++) for (CNum i = 0; i < numFiles; i++)
{ {
CFileItem &file = db.Files[i]; CFileItem &file = db.Files[i];
bool isAnti; bool isAnti;
file.HasStream = !emptyStreamVector[i];
file.Crc = 0; file.Crc = 0;
if (file.HasStream) if (!BoolVector_Item_IsValidAndTrue(emptyStreamVector, i))
{ {
file.HasStream = true;
file.IsDir = false; file.IsDir = false;
isAnti = false; isAnti = false;
file.Size = unpackSizes[sizeIndex]; file.Size = unpackSizes[sizeIndex];
@@ -1385,26 +1398,31 @@ HRESULT CInArchive::ReadHeader(
} }
else else
{ {
file.IsDir = !emptyFileVector[emptyFileIndex]; file.HasStream = false;
isAnti = antiFileVector[emptyFileIndex]; file.IsDir = !BoolVector_Item_IsValidAndTrue(emptyFileVector, emptyFileIndex);
isAnti = BoolVector_Item_IsValidAndTrue(antiFileVector, emptyFileIndex);
emptyFileIndex++; emptyFileIndex++;
file.Size = 0; file.Size = 0;
file.CrcDefined = false; file.CrcDefined = false;
} }
if (numAntiItems != 0) if (numAntiItems != 0)
db.IsAnti.Add(isAnti); db.IsAnti[i] = isAnti;
} }
} }
db.FillLinks(); db.FillLinks();
/*
if (type != NID::kEnd) if (type != NID::kEnd || _inByteBack->GetRem() != 0)
ThrowIncorrect(); {
if (_inByteBack->GetRem() != 0) db.UnsupportedFeatureWarning = true;
ThrowIncorrect(); // ThrowIncorrect();
*/ }
return S_OK; return S_OK;
} }
void CDbEx::FillLinks() void CDbEx::FillLinks()
{ {
FolderStartFileIndex.Alloc(NumFolders); FolderStartFileIndex.Alloc(NumFolders);
@@ -1466,6 +1484,7 @@ void CDbEx::FillLinks()
} }
} }
HRESULT CInArchive::ReadDatabase2( HRESULT CInArchive::ReadDatabase2(
DECL_EXTERNAL_CODECS_LOC_VARS DECL_EXTERNAL_CODECS_LOC_VARS
CDbEx &db CDbEx &db
@@ -1610,6 +1629,7 @@ HRESULT CInArchive::ReadDatabase2(
); );
} }
HRESULT CInArchive::ReadDatabase( HRESULT CInArchive::ReadDatabase(
DECL_EXTERNAL_CODECS_LOC_VARS DECL_EXTERNAL_CODECS_LOC_VARS
CDbEx &db CDbEx &db

View File

@@ -115,6 +115,7 @@ struct CDatabase: public CFolders
CUInt64DefVector ATime; CUInt64DefVector ATime;
CUInt64DefVector MTime; CUInt64DefVector MTime;
CUInt64DefVector StartPos; CUInt64DefVector StartPos;
CUInt32DefVector Attrib;
CBoolVector IsAnti; CBoolVector IsAnti;
/* /*
CBoolVector IsAux; CBoolVector IsAux;
@@ -146,6 +147,7 @@ struct CDatabase: public CFolders
ATime.Clear(); ATime.Clear();
MTime.Clear(); MTime.Clear();
StartPos.Clear(); StartPos.Clear();
Attrib.Clear();
IsAnti.Clear(); IsAnti.Clear();
// IsAux.Clear(); // IsAux.Clear();
} }
@@ -369,6 +371,8 @@ class CInArchive
void SkipData() { _inByteBack->SkipData(); } void SkipData() { _inByteBack->SkipData(); }
void WaitId(UInt64 id); void WaitId(UInt64 id);
void Read_UInt32_Vector(CUInt32DefVector &v);
void ReadArchiveProperties(CInArchiveInfo &archiveInfo); void ReadArchiveProperties(CInArchiveInfo &archiveInfo);
void ReadHashDigests(unsigned numItems, CUInt32DefVector &crcs); void ReadHashDigests(unsigned numItems, CUInt32DefVector &crcs);

View File

@@ -26,12 +26,14 @@ struct CCoderInfo
bool IsSimpleCoder() const { return NumStreams == 1; } bool IsSimpleCoder() const { return NumStreams == 1; }
}; };
struct CBond struct CBond
{ {
UInt32 PackIndex; UInt32 PackIndex;
UInt32 UnpackIndex; UInt32 UnpackIndex;
}; };
struct CFolder struct CFolder
{ {
CLASS_NO_COPY(CFolder) CLASS_NO_COPY(CFolder)
@@ -87,6 +89,7 @@ public:
} }
}; };
struct CUInt32DefVector struct CUInt32DefVector
{ {
CBoolVector Defs; CBoolVector Defs;
@@ -110,9 +113,25 @@ struct CUInt32DefVector
Vals.ReserveDown(); Vals.ReserveDown();
} }
bool GetItem(unsigned index, UInt32 &value) const
{
if (index < Defs.Size() && Defs[index])
{
value = Vals[index];
return true;
}
value = 0;
return false;
}
bool ValidAndDefined(unsigned i) const { return i < Defs.Size() && Defs[i]; } bool ValidAndDefined(unsigned i) const { return i < Defs.Size() && Defs[i]; }
bool CheckSize(unsigned size) const { return Defs.Size() == size || Defs.Size() == 0; }
void SetItem(unsigned index, bool defined, UInt32 value);
}; };
struct CUInt64DefVector struct CUInt64DefVector
{ {
CBoolVector Defs; CBoolVector Defs;
@@ -141,15 +160,15 @@ struct CUInt64DefVector
return false; return false;
} }
void SetItem(unsigned index, bool defined, UInt64 value);
bool CheckSize(unsigned size) const { return Defs.Size() == size || Defs.Size() == 0; } bool CheckSize(unsigned size) const { return Defs.Size() == size || Defs.Size() == 0; }
void SetItem(unsigned index, bool defined, UInt64 value);
}; };
struct CFileItem struct CFileItem
{ {
UInt64 Size; UInt64 Size;
UInt32 Attrib;
UInt32 Crc; UInt32 Crc;
/* /*
int Parent; int Parent;
@@ -159,23 +178,23 @@ struct CFileItem
// stream in some folder. It can be empty stream // stream in some folder. It can be empty stream
bool IsDir; bool IsDir;
bool CrcDefined; bool CrcDefined;
bool AttribDefined;
/*
void Clear()
{
HasStream = true;
IsDir = false;
CrcDefined = false;
}
CFileItem(): CFileItem():
/* // Parent(-1),
Parent(-1), // IsAltStream(false),
IsAltStream(false),
*/
HasStream(true), HasStream(true),
IsDir(false), IsDir(false),
CrcDefined(false), CrcDefined(false),
AttribDefined(false)
{} {}
void SetAttrib(UInt32 attrib) */
{
AttribDefined = true;
Attrib = attrib;
}
}; };
}} }}

View File

@@ -330,13 +330,11 @@ void COutArchive::WritePropBoolVector(Byte id, const CBoolVector &boolVector)
WriteBoolVector(boolVector); WriteBoolVector(boolVector);
} }
unsigned BoolVector_CountSum(const CBoolVector &v);
void COutArchive::WriteHashDigests(const CUInt32DefVector &digests) void COutArchive::WriteHashDigests(const CUInt32DefVector &digests)
{ {
unsigned numDefined = 0; const unsigned numDefined = BoolVector_CountSum(digests.Defs);
unsigned i;
for (i = 0; i < digests.Defs.Size(); i++)
if (digests.Defs[i])
numDefined++;
if (numDefined == 0) if (numDefined == 0)
return; return;
@@ -348,7 +346,8 @@ void COutArchive::WriteHashDigests(const CUInt32DefVector &digests)
WriteByte(0); WriteByte(0);
WriteBoolVector(digests.Defs); WriteBoolVector(digests.Defs);
} }
for (i = 0; i < digests.Defs.Size(); i++)
for (unsigned i = 0; i < digests.Defs.Size(); i++)
if (digests.Defs[i]) if (digests.Defs[i])
WriteUInt32(digests.Vals[i]); WriteUInt32(digests.Vals[i]);
} }
@@ -453,10 +452,12 @@ void COutArchive::WriteSubStreamsInfo(const CObjectVector<CFolder> &folders,
// 7-Zip 4.50 - 4.58 contain BUG, so they do not support .7z archives with Unknown field. // 7-Zip 4.50 - 4.58 contain BUG, so they do not support .7z archives with Unknown field.
void COutArchive::SkipAlign(unsigned pos, unsigned alignSize) void COutArchive::SkipToAligned(unsigned pos, unsigned alignShifts)
{ {
if (!_useAlign) if (!_useAlign)
return; return;
const unsigned alignSize = (unsigned)1 << alignShifts;
pos += (unsigned)GetPos(); pos += (unsigned)GetPos();
pos &= (alignSize - 1); pos &= (alignSize - 1);
if (pos == 0) if (pos == 0)
@@ -471,11 +472,11 @@ void COutArchive::SkipAlign(unsigned pos, unsigned alignSize)
WriteByte(0); WriteByte(0);
} }
void COutArchive::WriteAlignedBoolHeader(const CBoolVector &v, unsigned numDefined, Byte type, unsigned itemSize) void COutArchive::WriteAlignedBools(const CBoolVector &v, unsigned numDefined, Byte type, unsigned itemSizeShifts)
{ {
const unsigned bvSize = (numDefined == v.Size()) ? 0 : Bv_GetSizeInBytes(v); const unsigned bvSize = (numDefined == v.Size()) ? 0 : Bv_GetSizeInBytes(v);
const UInt64 dataSize = (UInt64)numDefined * itemSize + bvSize + 2; const UInt64 dataSize = ((UInt64)numDefined << itemSizeShifts) + bvSize + 2;
SkipAlign(3 + (unsigned)bvSize + (unsigned)GetBigNumberSize(dataSize), itemSize); SkipToAligned(3 + (unsigned)bvSize + (unsigned)GetBigNumberSize(dataSize), itemSizeShifts);
WriteByte(type); WriteByte(type);
WriteNumber(dataSize); WriteNumber(dataSize);
@@ -486,24 +487,18 @@ void COutArchive::WriteAlignedBoolHeader(const CBoolVector &v, unsigned numDefin
WriteByte(0); WriteByte(0);
WriteBoolVector(v); WriteBoolVector(v);
} }
WriteByte(0); WriteByte(0); // 0 means no switching to external stream
} }
void COutArchive::WriteUInt64DefVector(const CUInt64DefVector &v, Byte type) void COutArchive::WriteUInt64DefVector(const CUInt64DefVector &v, Byte type)
{ {
unsigned numDefined = 0; const unsigned numDefined = BoolVector_CountSum(v.Defs);
unsigned i;
for (i = 0; i < v.Defs.Size(); i++)
if (v.Defs[i])
numDefined++;
if (numDefined == 0) if (numDefined == 0)
return; return;
WriteAlignedBoolHeader(v.Defs, numDefined, type, 8); WriteAlignedBools(v.Defs, numDefined, type, 3);
for (i = 0; i < v.Defs.Size(); i++) for (unsigned i = 0; i < v.Defs.Size(); i++)
if (v.Defs[i]) if (v.Defs[i])
WriteUInt64(v.Vals[i]); WriteUInt64(v.Vals[i]);
} }
@@ -648,7 +643,7 @@ void COutArchive::WriteHeader(
if (numDefined > 0) if (numDefined > 0)
{ {
namesDataSize++; namesDataSize++;
SkipAlign(2 + GetBigNumberSize(namesDataSize), 16); SkipToAligned(2 + GetBigNumberSize(namesDataSize), 4);
WriteByte(NID::kName); WriteByte(NID::kName);
WriteNumber(namesDataSize); WriteNumber(namesDataSize);
@@ -673,28 +668,15 @@ void COutArchive::WriteHeader(
{ {
/* ---------- Write Attrib ---------- */ /* ---------- Write Attrib ---------- */
CBoolVector boolVector; const unsigned numDefined = BoolVector_CountSum(db.Attrib.Defs);
boolVector.ClearAndSetSize(db.Files.Size());
unsigned numDefined = 0;
{
FOR_VECTOR (i, db.Files)
{
bool defined = db.Files[i].AttribDefined;
boolVector[i] = defined;
if (defined)
numDefined++;
}
}
if (numDefined != 0) if (numDefined != 0)
{ {
WriteAlignedBoolHeader(boolVector, numDefined, NID::kWinAttrib, 4); WriteAlignedBools(db.Attrib.Defs, numDefined, NID::kWinAttrib, 2);
FOR_VECTOR (i, db.Files) FOR_VECTOR (i, db.Attrib.Defs)
{ {
const CFileItem &file = db.Files[i]; if (db.Attrib.Defs[i])
if (file.AttribDefined) WriteUInt32(db.Attrib.Vals[i]);
WriteUInt32(file.Attrib);
} }
} }
} }
@@ -702,18 +684,8 @@ void COutArchive::WriteHeader(
/* /*
{ {
// ---------- Write IsAux ---------- // ---------- Write IsAux ----------
unsigned numAux = 0; if (BoolVector_CountSum(db.IsAux) != 0)
const CBoolVector &isAux = db.IsAux; WritePropBoolVector(NID::kIsAux, db.IsAux);
for (i = 0; i < isAux.Size(); i++)
if (isAux[i])
numAux++;
if (numAux > 0)
{
const unsigned bvSize = Bv_GetSizeInBytes(isAux);
WriteByte(NID::kIsAux);
WriteNumber(bvSize);
WriteBoolVector(isAux);
}
} }
{ {
@@ -734,10 +706,10 @@ void COutArchive::WriteHeader(
} }
if (numParentLinks > 0) if (numParentLinks > 0)
{ {
// WriteAlignedBoolHeader(boolVector, numDefined, NID::kParent, 4); // WriteAlignedBools(boolVector, numDefined, NID::kParent, 2);
const unsigned bvSize = (numIsDir == boolVector.Size()) ? 0 : Bv_GetSizeInBytes(boolVector); const unsigned bvSize = (numIsDir == boolVector.Size()) ? 0 : Bv_GetSizeInBytes(boolVector);
const UInt64 dataSize = (UInt64)db.Files.Size() * 4 + bvSize + 1; const UInt64 dataSize = (UInt64)db.Files.Size() * 4 + bvSize + 1;
SkipAlign(2 + (unsigned)bvSize + (unsigned)GetBigNumberSize(dataSize), 4); SkipToAligned(2 + (unsigned)bvSize + (unsigned)GetBigNumberSize(dataSize), 2);
WriteByte(NID::kParent); WriteByte(NID::kParent);
WriteNumber(dataSize); WriteNumber(dataSize);
@@ -765,7 +737,7 @@ void COutArchive::WriteHeader(
// secureDataSize += db.SecureIDs.Size() * 4; // secureDataSize += db.SecureIDs.Size() * 4;
for (i = 0; i < db.SecureIDs.Size(); i++) for (i = 0; i < db.SecureIDs.Size(); i++)
secureDataSize += GetBigNumberSize(db.SecureIDs[i]); secureDataSize += GetBigNumberSize(db.SecureIDs[i]);
SkipAlign(2 + GetBigNumberSize(secureDataSize), 4); SkipToAligned(2 + GetBigNumberSize(secureDataSize), 2);
WriteByte(NID::kNtSecure); WriteByte(NID::kNtSecure);
WriteNumber(secureDataSize); WriteNumber(secureDataSize);
WriteByte(0); WriteByte(0);
@@ -888,6 +860,18 @@ HRESULT COutArchive::WriteDatabase(
} }
} }
void CUInt32DefVector::SetItem(unsigned index, bool defined, UInt32 value)
{
while (index >= Defs.Size())
Defs.Add(false);
Defs[index] = defined;
if (!defined)
return;
while (index >= Vals.Size())
Vals.Add(0);
Vals[index] = value;
}
void CUInt64DefVector::SetItem(unsigned index, bool defined, UInt64 value) void CUInt64DefVector::SetItem(unsigned index, bool defined, UInt64 value)
{ {
while (index >= Defs.Size()) while (index >= Defs.Size())
@@ -907,6 +891,7 @@ void CArchiveDatabaseOut::AddFile(const CFileItem &file, const CFileItem2 &file2
ATime.SetItem(index, file2.ATimeDefined, file2.ATime); ATime.SetItem(index, file2.ATimeDefined, file2.ATime);
MTime.SetItem(index, file2.MTimeDefined, file2.MTime); MTime.SetItem(index, file2.MTimeDefined, file2.MTime);
StartPos.SetItem(index, file2.StartPosDefined, file2.StartPos); StartPos.SetItem(index, file2.StartPosDefined, file2.StartPos);
Attrib.SetItem(index, file2.AttribDefined, file2.Attrib);
SetItem_Anti(index, file2.IsAnti); SetItem_Anti(index, file2.IsAnti);
// SetItem_Aux(index, file2.IsAux); // SetItem_Aux(index, file2.IsAux);
Names.Add(name); Names.Add(name);

View File

@@ -45,6 +45,7 @@ public:
size_t GetPos() const { return _pos; } size_t GetPos() const { return _pos; }
}; };
struct CHeaderOptions struct CHeaderOptions
{ {
bool CompressMainHeader; bool CompressMainHeader;
@@ -71,24 +72,31 @@ struct CFileItem2
UInt64 ATime; UInt64 ATime;
UInt64 MTime; UInt64 MTime;
UInt64 StartPos; UInt64 StartPos;
UInt32 Attrib;
bool CTimeDefined; bool CTimeDefined;
bool ATimeDefined; bool ATimeDefined;
bool MTimeDefined; bool MTimeDefined;
bool StartPosDefined; bool StartPosDefined;
bool AttribDefined;
bool IsAnti; bool IsAnti;
// bool IsAux; // bool IsAux;
/*
void Init() void Init()
{ {
CTimeDefined = false; CTimeDefined = false;
ATimeDefined = false; ATimeDefined = false;
MTimeDefined = false; MTimeDefined = false;
StartPosDefined = false; StartPosDefined = false;
AttribDefined = false;
IsAnti = false; IsAnti = false;
// IsAux = false; // IsAux = false;
} }
*/
}; };
struct COutFolders struct COutFolders
{ {
CUInt32DefVector FolderUnpackCRCs; // Now we use it for headers only. CUInt32DefVector FolderUnpackCRCs; // Now we use it for headers only.
@@ -111,6 +119,7 @@ struct COutFolders
} }
}; };
struct CArchiveDatabaseOut: public COutFolders struct CArchiveDatabaseOut: public COutFolders
{ {
CRecordVector<UInt64> PackSizes; CRecordVector<UInt64> PackSizes;
@@ -123,10 +132,11 @@ struct CArchiveDatabaseOut: public COutFolders
CUInt64DefVector ATime; CUInt64DefVector ATime;
CUInt64DefVector MTime; CUInt64DefVector MTime;
CUInt64DefVector StartPos; CUInt64DefVector StartPos;
CRecordVector<bool> IsAnti; CUInt32DefVector Attrib;
CBoolVector IsAnti;
/* /*
CRecordVector<bool> IsAux; CBoolVector IsAux;
CByteBuffer SecureBuf; CByteBuffer SecureBuf;
CRecordVector<UInt32> SecureSizes; CRecordVector<UInt32> SecureSizes;
@@ -154,6 +164,7 @@ struct CArchiveDatabaseOut: public COutFolders
ATime.Clear(); ATime.Clear();
MTime.Clear(); MTime.Clear();
StartPos.Clear(); StartPos.Clear();
Attrib.Clear();
IsAnti.Clear(); IsAnti.Clear();
/* /*
@@ -176,6 +187,7 @@ struct CArchiveDatabaseOut: public COutFolders
ATime.ReserveDown(); ATime.ReserveDown();
MTime.ReserveDown(); MTime.ReserveDown();
StartPos.ReserveDown(); StartPos.ReserveDown();
Attrib.ReserveDown();
IsAnti.ReserveDown(); IsAnti.ReserveDown();
/* /*
@@ -196,11 +208,12 @@ struct CArchiveDatabaseOut: public COutFolders
{ {
unsigned size = Files.Size(); unsigned size = Files.Size();
return ( return (
CTime.CheckSize(size) && CTime.CheckSize(size)
ATime.CheckSize(size) && && ATime.CheckSize(size)
MTime.CheckSize(size) && && MTime.CheckSize(size)
StartPos.CheckSize(size) && && StartPos.CheckSize(size)
(size == IsAnti.Size() || IsAnti.Size() == 0)); && Attrib.CheckSize(size)
&& (size == IsAnti.Size() || IsAnti.Size() == 0));
} }
bool IsItemAnti(unsigned index) const { return (index < IsAnti.Size() && IsAnti[index]); } bool IsItemAnti(unsigned index) const { return (index < IsAnti.Size() && IsAnti[index]); }
@@ -224,6 +237,7 @@ struct CArchiveDatabaseOut: public COutFolders
void AddFile(const CFileItem &file, const CFileItem2 &file2, const UString &name); void AddFile(const CFileItem &file, const CFileItem2 &file2, const UString &name);
}; };
class COutArchive class COutArchive
{ {
UInt64 _prefixHeaderPos; UInt64 _prefixHeaderPos;
@@ -261,8 +275,8 @@ class COutArchive
const CRecordVector<UInt64> &unpackSizes, const CRecordVector<UInt64> &unpackSizes,
const CUInt32DefVector &digests); const CUInt32DefVector &digests);
void SkipAlign(unsigned pos, unsigned alignSize); void SkipToAligned(unsigned pos, unsigned alignShifts);
void WriteAlignedBoolHeader(const CBoolVector &v, unsigned numDefined, Byte type, unsigned itemSize); void WriteAlignedBools(const CBoolVector &v, unsigned numDefined, Byte type, unsigned itemSizeShifts);
void WriteUInt64DefVector(const CUInt64DefVector &v, Byte type); void WriteUInt64DefVector(const CUInt64DefVector &v, Byte type);
HRESULT EncodeStream( HRESULT EncodeStream(

View File

@@ -1088,18 +1088,23 @@ static HRESULT MakeExeMethod(CCompressionMethodMode &mode,
} }
static void FromUpdateItemToFileItem(const CUpdateItem &ui, static void UpdateItem_To_FileItem2(const CUpdateItem &ui, CFileItem2 &file2)
CFileItem &file, CFileItem2 &file2)
{ {
if (ui.AttribDefined) file2.Attrib = ui.Attrib; file2.AttribDefined = ui.AttribDefined;
file.SetAttrib(ui.Attrib);
file2.CTime = ui.CTime; file2.CTimeDefined = ui.CTimeDefined; file2.CTime = ui.CTime; file2.CTimeDefined = ui.CTimeDefined;
file2.ATime = ui.ATime; file2.ATimeDefined = ui.ATimeDefined; file2.ATime = ui.ATime; file2.ATimeDefined = ui.ATimeDefined;
file2.MTime = ui.MTime; file2.MTimeDefined = ui.MTimeDefined; file2.MTime = ui.MTime; file2.MTimeDefined = ui.MTimeDefined;
file2.IsAnti = ui.IsAnti; file2.IsAnti = ui.IsAnti;
// file2.IsAux = false; // file2.IsAux = false;
file2.StartPosDefined = false; file2.StartPosDefined = false;
// file2.StartPos = 0;
}
static void UpdateItem_To_FileItem(const CUpdateItem &ui,
CFileItem &file, CFileItem2 &file2)
{
UpdateItem_To_FileItem2(ui, file2);
file.Size = ui.Size; file.Size = ui.Size;
file.IsDir = ui.IsDir; file.IsDir = ui.IsDir;
@@ -1107,6 +1112,8 @@ static void FromUpdateItemToFileItem(const CUpdateItem &ui,
// file.IsAltStream = ui.IsAltStream; // file.IsAltStream = ui.IsAltStream;
} }
class CRepackInStreamWithSizes: class CRepackInStreamWithSizes:
public ISequentialInStream, public ISequentialInStream,
public ICompressGetSubStreamSize, public ICompressGetSubStreamSize,
@@ -1437,6 +1444,7 @@ public:
#ifndef _7ZIP_ST #ifndef _7ZIP_ST
bool dataAfterEnd_Error;
HRESULT Result; HRESULT Result;
CMyComPtr<IInStream> InStream; CMyComPtr<IInStream> InStream;
@@ -1479,7 +1487,9 @@ void CThreadDecoder::Execute()
bool passwordIsDefined = false; bool passwordIsDefined = false;
UString password; UString password;
#endif #endif
dataAfterEnd_Error = false;
Result = Decoder.Decode( Result = Decoder.Decode(
EXTERNAL_CODECS_LOC_VARS EXTERNAL_CODECS_LOC_VARS
InStream, InStream,
@@ -1491,12 +1501,15 @@ void CThreadDecoder::Execute()
Fos, Fos,
NULL, // compressProgress NULL, // compressProgress
NULL // *inStreamMainRes NULL // *inStreamMainRes
, dataAfterEnd_Error
_7Z_DECODER_CRYPRO_VARS _7Z_DECODER_CRYPRO_VARS
#ifndef _7ZIP_ST #ifndef _7ZIP_ST
, MtMode, NumThreads , MtMode, NumThreads
#endif #endif
); );
} }
catch(...) catch(...)
@@ -1541,6 +1554,7 @@ static void GetFile(const CDatabase &inDb, unsigned index, CFileItem &file, CFil
file2.ATimeDefined = inDb.ATime.GetItem(index, file2.ATime); file2.ATimeDefined = inDb.ATime.GetItem(index, file2.ATime);
file2.MTimeDefined = inDb.MTime.GetItem(index, file2.MTime); file2.MTimeDefined = inDb.MTime.GetItem(index, file2.MTime);
file2.StartPosDefined = inDb.StartPos.GetItem(index, file2.StartPos); file2.StartPosDefined = inDb.StartPos.GetItem(index, file2.StartPos);
file2.AttribDefined = inDb.Attrib.GetItem(index, file2.Attrib);
file2.IsAnti = inDb.IsItemAnti(index); file2.IsAnti = inDb.IsItemAnti(index);
// file2.IsAux = inDb.IsItemAux(index); // file2.IsAux = inDb.IsItemAux(index);
} }
@@ -1837,7 +1851,7 @@ HRESULT Update(
continue; continue;
secureID = ui.SecureIndex; secureID = ui.SecureIndex;
if (ui.NewProps) if (ui.NewProps)
FromUpdateItemToFileItem(ui, file, file2); UpdateItem_To_FileItem(ui, file, file2);
else else
GetFile(*db, ui.IndexInArchive, file, file2); GetFile(*db, ui.IndexInArchive, file, file2);
} }
@@ -1887,7 +1901,8 @@ HRESULT Update(
UString name; UString name;
if (ui.NewProps) if (ui.NewProps)
{ {
FromUpdateItemToFileItem(ui, file, file2); UpdateItem_To_FileItem(ui, file, file2);
file.CrcDefined = false;
name = ui.Name; name = ui.Name;
} }
else else
@@ -2107,6 +2122,8 @@ HRESULT Update(
#endif #endif
CMyComPtr<ISequentialInStream> decodedStream; CMyComPtr<ISequentialInStream> decodedStream;
bool dataAfterEnd_Error = false;
HRESULT res = threadDecoder.Decoder.Decode( HRESULT res = threadDecoder.Decoder.Decode(
EXTERNAL_CODECS_LOC_VARS EXTERNAL_CODECS_LOC_VARS
inStream, inStream,
@@ -2117,13 +2134,16 @@ HRESULT Update(
NULL, // *outStream NULL, // *outStream
NULL, // *compressProgress NULL, // *compressProgress
&decodedStream &decodedStream
, dataAfterEnd_Error
_7Z_DECODER_CRYPRO_VARS _7Z_DECODER_CRYPRO_VARS
#ifndef _7ZIP_ST #ifndef _7ZIP_ST
, false // mtMode , false // mtMode
, 1 // numThreads , 1 // numThreads
#endif #endif
); );
RINOK(res); RINOK(res);
@@ -2175,16 +2195,19 @@ HRESULT Update(
HRESULT decodeRes = threadDecoder.Result; HRESULT decodeRes = threadDecoder.Result;
// if (res == k_My_HRESULT_CRC_ERROR) // if (res == k_My_HRESULT_CRC_ERROR)
if (decodeRes == S_FALSE) if (decodeRes == S_FALSE || threadDecoder.dataAfterEnd_Error)
{ {
if (extractCallback) if (extractCallback)
{ {
RINOK(extractCallback->ReportExtractResult( RINOK(extractCallback->ReportExtractResult(
NEventIndexType::kInArcIndex, db->FolderStartFileIndex[folderIndex], NEventIndexType::kInArcIndex, db->FolderStartFileIndex[folderIndex],
// NEventIndexType::kBlockIndex, (UInt32)folderIndex, // NEventIndexType::kBlockIndex, (UInt32)folderIndex,
NExtract::NOperationResult::kDataError)); (decodeRes != S_OK ?
NExtract::NOperationResult::kDataError :
NExtract::NOperationResult::kDataAfterEnd)));
} }
return E_FAIL; if (decodeRes != S_OK)
return E_FAIL;
} }
RINOK(decodeRes); RINOK(decodeRes);
if (encodeRes == S_OK) if (encodeRes == S_OK)
@@ -2224,12 +2247,7 @@ HRESULT Update(
CNum indexInFolder = 0; CNum indexInFolder = 0;
for (CNum fi = db->FolderStartFileIndex[folderIndex]; indexInFolder < numUnpackStreams; fi++) for (CNum fi = db->FolderStartFileIndex[folderIndex]; indexInFolder < numUnpackStreams; fi++)
{ {
CFileItem file; if (db->Files[fi].HasStream)
CFileItem2 file2;
GetFile(*db, fi, file, file2);
UString name;
db->GetPath(fi, name);
if (file.HasStream)
{ {
indexInFolder++; indexInFolder++;
int updateIndex = fileIndexToUpdateIndexMap[fi]; int updateIndex = fileIndexToUpdateIndexMap[fi];
@@ -2238,17 +2256,21 @@ HRESULT Update(
const CUpdateItem &ui = updateItems[updateIndex]; const CUpdateItem &ui = updateItems[updateIndex];
if (ui.NewData) if (ui.NewData)
continue; continue;
UString name;
CFileItem file;
CFileItem2 file2;
GetFile(*db, fi, file, file2);
if (ui.NewProps) if (ui.NewProps)
{ {
CFileItem uf; UpdateItem_To_FileItem2(ui, file2);
FromUpdateItemToFileItem(ui, uf, file2); file.IsDir = ui.IsDir;
uf.Size = file.Size;
uf.Crc = file.Crc;
uf.CrcDefined = file.CrcDefined;
uf.HasStream = file.HasStream;
file = uf;
name = ui.Name; name = ui.Name;
} }
else
db->GetPath(fi, name);
/* /*
file.Parent = ui.ParentFolderIndex; file.Parent = ui.ParentFolderIndex;
if (ui.TreeFolderIndex >= 0) if (ui.TreeFolderIndex >= 0)
@@ -2292,7 +2314,7 @@ HRESULT Update(
const CUpdateItem &ui = updateItems[index]; const CUpdateItem &ui = updateItems[index];
CFileItem file; CFileItem file;
if (ui.NewProps) if (ui.NewProps)
FromUpdateItemToFileItem(ui, file); UpdateItem_To_FileItem(ui, file);
else else
file = db.Files[ui.IndexInArchive]; file = db.Files[ui.IndexInArchive];
if (file.IsAnti || file.IsDir) if (file.IsAnti || file.IsDir)
@@ -2367,7 +2389,7 @@ HRESULT Update(
UString name; UString name;
if (ui.NewProps) if (ui.NewProps)
{ {
FromUpdateItemToFileItem(ui, file, file2); UpdateItem_To_FileItem(ui, file, file2);
name = ui.Name; name = ui.Name;
} }
else else
@@ -2386,7 +2408,7 @@ HRESULT Update(
{ {
skippedSize += ui.Size; skippedSize += ui.Size;
continue; continue;
// file.Name.AddAscii(".locked"); // file.Name += ".locked";
} }
file.Crc = inStreamSpec->CRCs[subIndex]; file.Crc = inStreamSpec->CRCs[subIndex];

View File

@@ -6,7 +6,6 @@
#include "../../Common/ComTry.h" #include "../../Common/ComTry.h"
#include "../../Common/Defs.h" #include "../../Common/Defs.h"
#include "../../Common/IntToString.h"
#include "../../Windows/PropVariant.h" #include "../../Windows/PropVariant.h"
@@ -232,7 +231,7 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
int mainIndex = -1; int mainIndex = -1;
FOR_VECTOR (i, _items) FOR_VECTOR (i, _items)
{ {
AString s = GetString(_items[i].Type); AString s (GetString(_items[i].Type));
if (s != "Apple_Free" && if (s != "Apple_Free" &&
s != "Apple_partition_map") s != "Apple_partition_map")
{ {
@@ -279,14 +278,10 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
{ {
case kpidPath: case kpidPath:
{ {
AString s = GetString(item.Name); AString s (GetString(item.Name));
if (s.IsEmpty()) if (s.IsEmpty())
{ s.Add_UInt32(index);
char s2[32]; AString type (GetString(item.Type));
ConvertUInt32ToString(index, s2);
s = s2;
}
AString type = GetString(item.Type);
if (type == "Apple_HFS") if (type == "Apple_HFS")
type = "hfs"; type = "hfs";
if (!type.IsEmpty()) if (!type.IsEmpty())

View File

@@ -688,7 +688,7 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
case kpidShortComment: case kpidShortComment:
case kpidSubType: case kpidSubType:
{ {
AString s = k_TypeExtionsions[(unsigned)_type]; AString s (k_TypeExtionsions[(unsigned)_type]);
if (_subType == kSubType_BSD) if (_subType == kSubType_BSD)
s += ":BSD"; s += ":BSD";
prop = s; prop = s;
@@ -720,7 +720,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
if (item.TextFileIndex >= 0) if (item.TextFileIndex >= 0)
prop = (item.TextFileIndex == 0) ? "1.txt" : "2.txt"; prop = (item.TextFileIndex == 0) ? "1.txt" : "2.txt";
else else
prop = (const wchar_t *)NItemName::GetOSName2(MultiByteToUnicodeString(item.Name, CP_OEMCP)); prop = (const wchar_t *)NItemName::GetOsPath_Remove_TailSlash(MultiByteToUnicodeString(item.Name, CP_OEMCP));
break; break;
case kpidSize: case kpidSize:
case kpidPackSize: case kpidPackSize:

View File

@@ -5,10 +5,10 @@
#include "../../../C/CpuArch.h" #include "../../../C/CpuArch.h"
#include "../../Common/ComTry.h" #include "../../Common/ComTry.h"
#include "../../Common/IntToString.h"
#include "../../Common/StringConvert.h" #include "../../Common/StringConvert.h"
#include "../../Windows/PropVariant.h" #include "../../Windows/PropVariant.h"
#include "../../Windows/PropVariantUtils.h"
#include "../../Windows/TimeUtils.h" #include "../../Windows/TimeUtils.h"
#include "../Common/LimitedStreams.h" #include "../Common/LimitedStreams.h"
@@ -642,16 +642,7 @@ static void SetTime(UInt32 dosTime, NCOM::CPropVariant &prop)
static void SetHostOS(Byte hostOS, NCOM::CPropVariant &prop) static void SetHostOS(Byte hostOS, NCOM::CPropVariant &prop)
{ {
char temp[16]; TYPE_TO_PROP(kHostOS, hostOS, prop);
const char *s = NULL;
if (hostOS < ARRAY_SIZE(kHostOS))
s = kHostOS[hostOS];
else
{
ConvertUInt32ToString(hostOS, temp);
s = temp;
}
prop = s;
} }
static void SetUnicodeString(const AString &s, NCOM::CPropVariant &prop) static void SetUnicodeString(const AString &s, NCOM::CPropVariant &prop)
@@ -703,7 +694,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
const CItem &item = _items[index]; const CItem &item = _items[index];
switch (propID) switch (propID)
{ {
case kpidPath: prop = NItemName::GetOSName(MultiByteToUnicodeString(item.Name, CP_OEMCP)); break; case kpidPath: prop = NItemName::GetOsPath(MultiByteToUnicodeString(item.Name, CP_OEMCP)); break;
case kpidIsDir: prop = item.IsDir(); break; case kpidIsDir: prop = item.IsDir(); break;
case kpidSize: prop = item.Size; break; case kpidSize: prop = item.Size; break;
case kpidPackSize: prop = item.PackSize; break; case kpidPackSize: prop = item.PackSize; break;

View File

@@ -179,6 +179,7 @@ STDMETHODIMP CHandler::Close()
return S_OK; return S_OK;
} }
STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems, STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
Int32 testMode, IArchiveExtractCallback *extractCallback) Int32 testMode, IArchiveExtractCallback *extractCallback)
{ {
@@ -191,8 +192,6 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
if (_packSize_Defined) if (_packSize_Defined)
extractCallback->SetTotal(_packSize); extractCallback->SetTotal(_packSize);
// RINOK(extractCallback->SetCompleted(&packSize));
CMyComPtr<ISequentialOutStream> realOutStream; CMyComPtr<ISequentialOutStream> realOutStream;
Int32 askMode = testMode ? Int32 askMode = testMode ?
NExtract::NAskMode::kTest : NExtract::NAskMode::kTest :
@@ -203,7 +202,6 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
extractCallback->PrepareOperation(askMode); extractCallback->PrepareOperation(askMode);
if (_needSeekToStart) if (_needSeekToStart)
{ {
if (!_stream) if (!_stream)
@@ -213,14 +211,10 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
else else
_needSeekToStart = true; _needSeekToStart = true;
Int32 opRes; // try {
try
{
NCompress::NBZip2::CDecoder *decoderSpec = new NCompress::NBZip2::CDecoder; NCompress::NBZip2::CDecoder *decoderSpec = new NCompress::NBZip2::CDecoder;
CMyComPtr<ICompressCoder> decoder = decoderSpec; CMyComPtr<ICompressCoder> decoder = decoderSpec;
decoderSpec->SetInStream(_seqStream);
#ifndef _7ZIP_ST #ifndef _7ZIP_ST
RINOK(decoderSpec->SetNumberOfThreads(_props._numThreads)); RINOK(decoderSpec->SetNumberOfThreads(_props._numThreads));
@@ -237,74 +231,43 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
CMyComPtr<ICompressProgressInfo> progress = lps; CMyComPtr<ICompressProgressInfo> progress = lps;
lps->Init(extractCallback, true); lps->Init(extractCallback, true);
UInt64 packSize = 0; decoderSpec->FinishMode = true;
UInt64 unpackedSize = 0; decoderSpec->Base.DecodeAllStreams = true;
UInt64 numStreams = 0;
decoderSpec->InitNumBlocks();
HRESULT result = S_OK; _dataAfterEnd = false;
_needMoreInput = false;
for (;;) lps->InSize = 0;
lps->OutSize = 0;
HRESULT result = decoderSpec->Code(_seqStream, outStream, NULL, NULL, progress);
if (result != S_FALSE && result != S_OK)
return result;
if (decoderSpec->Base.NumStreams == 0)
{ {
lps->InSize = packSize; _isArc = false;
lps->OutSize = unpackedSize; result = S_FALSE;
RINOK(lps->SetCur());
result = decoderSpec->CodeResume(outStream, progress);
if (result != S_FALSE && result != S_OK)
return result;
if (decoderSpec->IsBz)
numStreams++;
else if (numStreams == 0)
{
_isArc = false;
result = S_FALSE;
break;
}
unpackedSize = outStreamSpec->GetSize();
UInt64 streamSize = decoderSpec->GetStreamSize();
if (streamSize == packSize)
{
// no new bytes in input stream, So it's good end of archive.
result = S_OK;
break;
}
if (!decoderSpec->IsBz)
{
_dataAfterEnd = true;
result = S_FALSE;
break;
}
if (decoderSpec->Base.BitDecoder.ExtraBitsWereRead())
{
_needMoreInput = true;
packSize = streamSize;
result = S_FALSE;
break;
}
packSize = decoderSpec->GetInputProcessedSize();
if (packSize > streamSize)
return E_FAIL;
if (result != S_OK)
break;
} }
else
if (numStreams != 0)
{ {
const UInt64 inProcessedSize = decoderSpec->GetInputProcessedSize();
UInt64 packSize = inProcessedSize;
if (decoderSpec->Base.NeedMoreInput)
_needMoreInput = true;
if (!decoderSpec->Base.IsBz)
{
packSize = decoderSpec->Base.FinishedPackSize;
if (packSize != inProcessedSize)
_dataAfterEnd = true;
}
_packSize = packSize; _packSize = packSize;
_unpackSize = unpackedSize; _unpackSize = decoderSpec->GetOutProcessedSize();
_numStreams = numStreams; _numStreams = decoderSpec->Base.NumStreams;
_numBlocks = decoderSpec->GetNumBlocks(); _numBlocks = decoderSpec->GetNumBlocks();
_packSize_Defined = true; _packSize_Defined = true;
@@ -313,32 +276,36 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
_numBlocks_Defined = true; _numBlocks_Defined = true;
} }
decoderSpec->ReleaseInStream();
outStream.Release(); outStream.Release();
Int32 opRes;
if (!_isArc) if (!_isArc)
opRes = NExtract::NOperationResult::kIsNotArc; opRes = NExtract::NOperationResult::kIsNotArc;
else if (_needMoreInput) else if (_needMoreInput)
opRes = NExtract::NOperationResult::kUnexpectedEnd; opRes = NExtract::NOperationResult::kUnexpectedEnd;
else if (decoderSpec->CrcError) else if (decoderSpec->GetCrcError())
opRes = NExtract::NOperationResult::kCRCError; opRes = NExtract::NOperationResult::kCRCError;
else if (_dataAfterEnd) else if (_dataAfterEnd)
opRes = NExtract::NOperationResult::kDataAfterEnd; opRes = NExtract::NOperationResult::kDataAfterEnd;
else if (result == S_FALSE) else if (result == S_FALSE)
opRes = NExtract::NOperationResult::kDataError; opRes = NExtract::NOperationResult::kDataError;
else if (decoderSpec->Base.MinorError)
opRes = NExtract::NOperationResult::kDataError;
else if (result == S_OK) else if (result == S_OK)
opRes = NExtract::NOperationResult::kOK; opRes = NExtract::NOperationResult::kOK;
else else
return result; return result;
}
catch(const CInBufferException &e) { return e.ErrorCode; }
return extractCallback->SetOperationResult(opRes); return extractCallback->SetOperationResult(opRes);
// } catch(...) { return E_FAIL; }
COM_TRY_END COM_TRY_END
} }
static HRESULT UpdateArchive( static HRESULT UpdateArchive(
UInt64 unpackSize, UInt64 unpackSize,
ISequentialOutStream *outStream, ISequentialOutStream *outStream,

View File

@@ -226,12 +226,9 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
if (ai.SetID != 0) if (ai.SetID != 0)
{ {
AString s; AString s;
char temp[32]; s.Add_UInt32(ai.SetID);
ConvertUInt32ToString(ai.SetID, temp);
s += temp;
ConvertUInt32ToString(ai.CabinetNumber + 1, temp);
s += '_'; s += '_';
s += temp; s.Add_UInt32(ai.CabinetNumber + 1);
s += ".cab"; s += ".cab";
prop = s; prop = s;
} }
@@ -288,7 +285,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
ConvertUTF8ToUnicode(item.Name, unicodeName); ConvertUTF8ToUnicode(item.Name, unicodeName);
else else
unicodeName = MultiByteToUnicodeString(item.Name, CP_ACP); unicodeName = MultiByteToUnicodeString(item.Name, CP_ACP);
prop = (const wchar_t *)NItemName::WinNameToOSName(unicodeName); prop = (const wchar_t *)NItemName::WinPathToOsPath(unicodeName);
break; break;
} }
@@ -491,7 +488,7 @@ STDMETHODIMP CHandler::Open(IInStream *inStream,
if (!_errorMessage.IsEmpty()) if (!_errorMessage.IsEmpty())
_errorMessage.Add_LF(); _errorMessage.Add_LF();
_errorMessage.AddAscii("Can't open volume: "); _errorMessage += "Can't open volume: ";
_errorMessage += fullName; _errorMessage += fullName;
if (prevChecked) if (prevChecked)

View File

@@ -135,7 +135,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
if (us.Len() > 1 && us[0] == L'/') if (us.Len() > 1 && us[0] == L'/')
us.Delete(0); us.Delete(0);
} }
NItemName::ConvertToOSName2(us); NItemName::ReplaceToOsSlashes_Remove_TailSlash(us);
prop = us; prop = us;
} }
break; break;

View File

@@ -38,20 +38,13 @@ struct CHeaderErrorException {};
// define CHM_LOW, if you want to see low level items // define CHM_LOW, if you want to see low level items
// #define CHM_LOW // #define CHM_LOW
static const GUID kChmLzxGuid = { 0x7FC28940, 0x9D31, 0x11D0, { 0x9B, 0x27, 0x00, 0xA0, 0xC9, 0x1E, 0x9C, 0x7C } }; static const Byte kChmLzxGuid[16] = { 0x40, 0x89, 0xC2, 0x7F, 0x31, 0x9D, 0xD0, 0x11, 0x9B, 0x27, 0x00, 0xA0, 0xC9, 0x1E, 0x9C, 0x7C };
static const GUID kHelp2LzxGuid = { 0x0A9007C6, 0x4076, 0x11D3, { 0x87, 0x89, 0x00, 0x00, 0xF8, 0x10, 0x57, 0x54 } }; static const Byte kHelp2LzxGuid[16] = { 0xC6, 0x07, 0x90, 0x0A, 0x76, 0x40, 0xD3, 0x11, 0x87, 0x89, 0x00, 0x00, 0xF8, 0x10, 0x57, 0x54 };
static const GUID kDesGuid = { 0x67F6E4A2, 0x60BF, 0x11D3, { 0x85, 0x40, 0x00, 0xC0, 0x4F, 0x58, 0xC3, 0xCF } }; static const Byte kDesGuid[16] = { 0xA2, 0xE4, 0xF6, 0x67, 0xBF, 0x60, 0xD3, 0x11, 0x85, 0x40, 0x00, 0xC0, 0x4F, 0x58, 0xC3, 0xCF };
static bool AreGuidsEqual(REFGUID g1, REFGUID g2) static bool inline AreGuidsEqual(const Byte *g1, const Byte *g2)
{ {
if (g1.Data1 != g2.Data1 || return memcmp(g1, g2, 16) == 0;
g1.Data2 != g2.Data2 ||
g1.Data3 != g2.Data3)
return false;
for (int i = 0; i < 8; i++)
if (g1.Data4[i] != g2.Data4[i])
return false;
return true;
} }
static char GetHex(unsigned v) static char GetHex(unsigned v)
@@ -65,35 +58,12 @@ static void PrintByte(Byte b, AString &s)
s += GetHex(b & 0xF); s += GetHex(b & 0xF);
} }
static void PrintUInt16(UInt16 v, AString &s)
{
PrintByte((Byte)(v >> 8), s);
PrintByte((Byte)v, s);
}
static void PrintUInt32(UInt32 v, AString &s)
{
PrintUInt16((UInt16)(v >> 16), s);
PrintUInt16((UInt16)v, s);
}
AString CMethodInfo::GetGuidString() const AString CMethodInfo::GetGuidString() const
{ {
AString s; char s[48];
s += '{'; RawLeGuidToString_Braced(Guid, s);
PrintUInt32(Guid.Data1, s); // MyStringUpper_Ascii(s);
s += '-'; return (AString)s;
PrintUInt16(Guid.Data2, s);
s += '-';
PrintUInt16(Guid.Data3, s);
s += '-';
PrintByte(Guid.Data4[0], s);
PrintByte(Guid.Data4[1], s);
s += '-';
for (int i = 2; i < 8; i++)
PrintByte(Guid.Data4[i], s);
s += '}';
return s;
} }
bool CMethodInfo::IsLzx() const bool CMethodInfo::IsLzx() const
@@ -108,32 +78,28 @@ bool CMethodInfo::IsDes() const
return AreGuidsEqual(Guid, kDesGuid); return AreGuidsEqual(Guid, kDesGuid);
} }
UString CMethodInfo::GetName() const AString CMethodInfo::GetName() const
{ {
UString s; AString s;
if (IsLzx()) if (IsLzx())
{ {
s.SetFromAscii("LZX:"); s = "LZX:";
char temp[16]; s.Add_UInt32(LzxInfo.GetNumDictBits());
ConvertUInt32ToString(LzxInfo.GetNumDictBits(), temp);
s.AddAscii(temp);
} }
else else
{ {
AString s2;
if (IsDes()) if (IsDes())
s2 = "DES"; s = "DES";
else else
{ {
s2 = GetGuidString(); s = GetGuidString();
if (ControlData.Size() > 0) if (ControlData.Size() > 0)
{ {
s2 += ':'; s += ':';
for (size_t i = 0; i < ControlData.Size(); i++) for (size_t i = 0; i < ControlData.Size(); i++)
PrintByte(ControlData[i], s2); PrintByte(ControlData[i], s);
} }
} }
ConvertUTF8ToUnicode(s2, s);
} }
return s; return s;
} }
@@ -153,7 +119,7 @@ UString CSectionInfo::GetMethodName() const
UString temp; UString temp;
if (ConvertUTF8ToUnicode(Name, temp)) if (ConvertUTF8ToUnicode(Name, temp))
s += temp; s += temp;
s.AddAscii(": "); s += ": ";
} }
FOR_VECTOR (i, Methods) FOR_VECTOR (i, Methods)
{ {
@@ -220,12 +186,9 @@ UInt64 CInArchive::ReadEncInt()
throw CHeaderErrorException(); throw CHeaderErrorException();
} }
void CInArchive::ReadGUID(GUID &g) void CInArchive::ReadGUID(Byte *g)
{ {
g.Data1 = ReadUInt32(); ReadBytes(g, 16);
g.Data2 = ReadUInt16();
g.Data3 = ReadUInt16();
ReadBytes(g.Data4, 8);
} }
void CInArchive::ReadString(unsigned size, AString &s) void CInArchive::ReadString(unsigned size, AString &s)
@@ -299,7 +262,7 @@ HRESULT CInArchive::OpenChm(IInStream *inStream, CDatabase &database)
// The third and fourth bytes may contain even more fractional bits. // The third and fourth bytes may contain even more fractional bits.
// The 4 least significant bits in the last byte are constant. // The 4 least significant bits in the last byte are constant.
/* UInt32 lang = */ ReadUInt32(); /* UInt32 lang = */ ReadUInt32();
GUID g; Byte g[16];
ReadGUID(g); // {7C01FD10-7BAA-11D0-9E0C-00A0-C922-E6EC} ReadGUID(g); // {7C01FD10-7BAA-11D0-9E0C-00A0-C922-E6EC}
ReadGUID(g); // {7C01FD11-7BAA-11D0-9E0C-00A0-C922-E6EC} ReadGUID(g); // {7C01FD11-7BAA-11D0-9E0C-00A0-C922-E6EC}
const unsigned kNumSections = 2; const unsigned kNumSections = 2;
@@ -422,7 +385,7 @@ HRESULT CInArchive::OpenHelp2(IInStream *inStream, CDatabase &database)
IsArc = true; IsArc = true;
ReadUInt32(); // Len of post-header table ReadUInt32(); // Len of post-header table
GUID g; Byte g[16];
ReadGUID(g); // {0A9007C1-4076-11D3-8789-0000F8105754} ReadGUID(g); // {0A9007C1-4076-11D3-8789-0000F8105754}
// header section table // header section table
@@ -637,18 +600,18 @@ HRESULT CInArchive::DecompressStream(IInStream *inStream, const CDatabase &datab
#define DATA_SPACE "::DataSpace/" #define DATA_SPACE "::DataSpace/"
static const char *kNameList = DATA_SPACE "NameList"; #define kNameList DATA_SPACE "NameList"
static const char *kStorage = DATA_SPACE "Storage/"; #define kStorage DATA_SPACE "Storage/"
static const char *kContent = "Content"; #define kContent "Content"
static const char *kControlData = "ControlData"; #define kControlData "ControlData"
static const char *kSpanInfo = "SpanInfo"; #define kSpanInfo "SpanInfo"
static const char *kTransform = "Transform/"; #define kTransform "Transform/"
static const char *kResetTable = "/InstanceData/ResetTable"; #define kResetTable "/InstanceData/ResetTable"
static const char *kTransformList = "List"; #define kTransformList "List"
static AString GetSectionPrefix(const AString &name) static AString GetSectionPrefix(const AString &name)
{ {
AString s = kStorage; AString s (kStorage);
s += name; s += name;
s += '/'; s += '/';
return s; return s;
@@ -743,7 +706,7 @@ HRESULT CInArchive::OpenHighLevel(IInStream *inStream, CFilesDatabase &database)
{ {
{ {
// The NameList file // The NameList file
RINOK(DecompressStream(inStream, database, kNameList)); RINOK(DecompressStream(inStream, database, (AString)kNameList));
/* UInt16 length = */ ReadUInt16(); /* UInt16 length = */ ReadUInt16();
UInt16 numSections = ReadUInt16(); UInt16 numSections = ReadUInt16();
for (unsigned i = 0; i < numSections; i++) for (unsigned i = 0; i < numSections; i++)
@@ -764,7 +727,7 @@ HRESULT CInArchive::OpenHighLevel(IInStream *inStream, CFilesDatabase &database)
for (si = 1; si < database.Sections.Size(); si++) for (si = 1; si < database.Sections.Size(); si++)
{ {
CSectionInfo &section = database.Sections[si]; CSectionInfo &section = database.Sections[si];
AString sectionPrefix = GetSectionPrefix(section.Name); AString sectionPrefix (GetSectionPrefix(section.Name));
{ {
// Content // Content
int index = database.FindItem(sectionPrefix + kContent); int index = database.FindItem(sectionPrefix + kContent);
@@ -774,7 +737,7 @@ HRESULT CInArchive::OpenHighLevel(IInStream *inStream, CFilesDatabase &database)
section.Offset = item.Offset; section.Offset = item.Offset;
section.CompressedSize = item.Size; section.CompressedSize = item.Size;
} }
AString transformPrefix = sectionPrefix + kTransform; AString transformPrefix (sectionPrefix + kTransform);
if (database.Help2Format) if (database.Help2Format)
{ {
// Transform List // Transform List
@@ -794,7 +757,7 @@ HRESULT CInArchive::OpenHighLevel(IInStream *inStream, CFilesDatabase &database)
else else
{ {
CMethodInfo method; CMethodInfo method;
method.Guid = kChmLzxGuid; memcpy(method.Guid, kChmLzxGuid, 16);
section.Methods.Add(method); section.Methods.Add(method);
} }

View File

@@ -149,14 +149,14 @@ struct CLzxInfo
struct CMethodInfo struct CMethodInfo
{ {
GUID Guid; Byte Guid[16];
CByteBuffer ControlData; CByteBuffer ControlData;
CLzxInfo LzxInfo; CLzxInfo LzxInfo;
bool IsLzx() const; bool IsLzx() const;
bool IsDes() const; bool IsDes() const;
AString GetGuidString() const; AString GetGuidString() const;
UString GetName() const; AString GetName() const;
}; };
@@ -243,7 +243,7 @@ class CInArchive
UInt64 ReadEncInt(); UInt64 ReadEncInt();
void ReadString(unsigned size, AString &s); void ReadString(unsigned size, AString &s);
void ReadUString(unsigned size, UString &s); void ReadUString(unsigned size, UString &s);
void ReadGUID(GUID &g); void ReadGUID(Byte *g);
HRESULT ReadChunk(IInStream *inStream, UInt64 pos, UInt64 size); HRESULT ReadChunk(IInStream *inStream, UInt64 pos, UInt64 size);

View File

@@ -239,9 +239,6 @@ HRESULT CDatabase::AddNode(int parent, UInt32 did)
return S_OK; return S_OK;
} }
static const wchar_t kCharOpenBracket = L'[';
static const wchar_t kCharCloseBracket = L']';
static UString CompoundNameToFileName(const UString &s) static UString CompoundNameToFileName(const UString &s)
{ {
UString res; UString res;
@@ -250,11 +247,9 @@ static UString CompoundNameToFileName(const UString &s)
wchar_t c = s[i]; wchar_t c = s[i];
if (c < 0x20) if (c < 0x20)
{ {
res += kCharOpenBracket; res += '[';
wchar_t buf[32]; res.Add_UInt32(c);
ConvertUInt32ToString(c, buf); res += ']';
res += buf;
res += kCharCloseBracket;
} }
else else
res += c; res += c;
@@ -265,8 +260,8 @@ static UString CompoundNameToFileName(const UString &s)
static const char k_Msi_Chars[] = static const char k_Msi_Chars[] =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz._"; "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz._";
// static const char *k_Msi_ID = ""; // "{msi}"; // static const char * const k_Msi_ID = ""; // "{msi}";
static const wchar_t k_Msi_SpecChar = L'!'; static const char k_Msi_SpecChar = '!';
static const unsigned k_Msi_NumBits = 6; static const unsigned k_Msi_NumBits = 6;
static const unsigned k_Msi_NumChars = 1 << k_Msi_NumBits; static const unsigned k_Msi_NumChars = 1 << k_Msi_NumBits;
@@ -316,10 +311,10 @@ static bool CompoundMsiNameToFileName(const UString &name, UString &res)
if (c1 <= k_Msi_NumChars) if (c1 <= k_Msi_NumChars)
{ {
res += (wchar_t)(Byte)k_Msi_Chars[c0]; res += k_Msi_Chars[c0];
if (c1 == k_Msi_NumChars) if (c1 == k_Msi_NumChars)
break; break;
res += (wchar_t)(Byte)k_Msi_Chars[c1]; res += k_Msi_Chars[c1];
} }
else else
res += k_Msi_SpecChar; res += k_Msi_SpecChar;

View File

@@ -60,6 +60,62 @@ static void BoolVector_Fill_False(CBoolVector &v, unsigned size)
p[i] = false; p[i] = false;
} }
HRESULT CCoder::CheckDataAfterEnd(bool &dataAfterEnd_Error /* , bool &InternalPackSizeError */) const
{
if (Coder)
{
if (PackSizePointers.IsEmpty() || !PackSizePointers[0])
return S_OK;
CMyComPtr<ICompressGetInStreamProcessedSize> getInStreamProcessedSize;
Coder.QueryInterface(IID_ICompressGetInStreamProcessedSize, (void **)&getInStreamProcessedSize);
// if (!getInStreamProcessedSize) return E_FAIL;
if (getInStreamProcessedSize)
{
UInt64 processed;
RINOK(getInStreamProcessedSize->GetInStreamProcessedSize(&processed));
if (processed != (UInt64)(Int64)-1)
{
const UInt64 size = PackSizes[0];
if (processed < size && Finish)
dataAfterEnd_Error = true;
if (processed > size)
{
// InternalPackSizeError = true;
// return S_FALSE;
}
}
}
}
else if (Coder2)
{
CMyComPtr<ICompressGetInStreamProcessedSize2> getInStreamProcessedSize2;
Coder2.QueryInterface(IID_ICompressGetInStreamProcessedSize2, (void **)&getInStreamProcessedSize2);
FOR_VECTOR (i, PackSizePointers)
{
if (!PackSizePointers[i])
continue;
UInt64 processed;
RINOK(getInStreamProcessedSize2->GetInStreamProcessedSize2(i, &processed));
if (processed != (UInt64)(Int64)-1)
{
const UInt64 size = PackSizes[i];
if (processed < size && Finish)
dataAfterEnd_Error = true;
else if (processed > size)
{
// InternalPackSizeError = true;
// return S_FALSE;
}
}
}
}
return S_OK;
}
class CBondsChecks class CBondsChecks
{ {
CBoolVector _coderUsed; CBoolVector _coderUsed;
@@ -151,8 +207,10 @@ bool CBindInfo::CalcMapsAndCheck()
} }
void CCoder::SetCoderInfo(const UInt64 *unpackSize, const UInt64 * const *packSizes) void CCoder::SetCoderInfo(const UInt64 *unpackSize, const UInt64 * const *packSizes, bool finish)
{ {
Finish = finish;
if (unpackSize) if (unpackSize)
{ {
UnpackSize = *unpackSize; UnpackSize = *unpackSize;
@@ -640,8 +698,12 @@ void CMixerST::SelectMainCoder(bool useFirst)
HRESULT CMixerST::Code( HRESULT CMixerST::Code(
ISequentialInStream * const *inStreams, ISequentialInStream * const *inStreams,
ISequentialOutStream * const *outStreams, ISequentialOutStream * const *outStreams,
ICompressProgressInfo *progress) ICompressProgressInfo *progress,
bool &dataAfterEnd_Error)
{ {
// InternalPackSizeError = false;
dataAfterEnd_Error = false;
_binderStreams.Clear(); _binderStreams.Clear();
unsigned ci = MainCoderIndex; unsigned ci = MainCoderIndex;
@@ -742,7 +804,16 @@ HRESULT CMixerST::Code(
if (res == k_My_HRESULT_WritingWasCut) if (res == k_My_HRESULT_WritingWasCut)
res = S_OK; res = S_OK;
return res;
if (res != S_OK)
return res;
for (i = 0; i < _coders.Size(); i++)
{
RINOK(_coders[i].CheckDataAfterEnd(dataAfterEnd_Error /*, InternalPackSizeError */));
}
return S_OK;
} }
@@ -988,8 +1059,12 @@ HRESULT CMixerMT::ReturnIfError(HRESULT code)
HRESULT CMixerMT::Code( HRESULT CMixerMT::Code(
ISequentialInStream * const *inStreams, ISequentialInStream * const *inStreams,
ISequentialOutStream * const *outStreams, ISequentialOutStream * const *outStreams,
ICompressProgressInfo *progress) ICompressProgressInfo *progress,
bool &dataAfterEnd_Error)
{ {
// InternalPackSizeError = false;
dataAfterEnd_Error = false;
Init(inStreams, outStreams); Init(inStreams, outStreams);
unsigned i; unsigned i;
@@ -1031,6 +1106,11 @@ HRESULT CMixerMT::Code(
return result; return result;
} }
for (i = 0; i < _coders.Size(); i++)
{
RINOK(_coders[i].CheckDataAfterEnd(dataAfterEnd_Error /* , InternalPackSizeError */));
}
return S_OK; return S_OK;
} }

View File

@@ -201,9 +201,13 @@ public:
CRecordVector<UInt64> PackSizes; CRecordVector<UInt64> PackSizes;
CRecordVector<const UInt64 *> PackSizePointers; CRecordVector<const UInt64 *> PackSizePointers;
CCoder() {} bool Finish;
void SetCoderInfo(const UInt64 *unpackSize, const UInt64 * const *packSizes); CCoder(): Finish(false) {}
void SetCoderInfo(const UInt64 *unpackSize, const UInt64 * const *packSizes, bool finish);
HRESULT CheckDataAfterEnd(bool &dataAfterEnd_Error /* , bool &InternalPackSizeError */) const;
IUnknown *GetUnknown() const IUnknown *GetUnknown() const
{ {
@@ -239,9 +243,12 @@ protected:
public: public:
unsigned MainCoderIndex; unsigned MainCoderIndex;
// bool InternalPackSizeError;
CMixer(bool encodeMode): CMixer(bool encodeMode):
EncodeMode(encodeMode), EncodeMode(encodeMode),
MainCoderIndex(0) MainCoderIndex(0)
// , InternalPackSizeError(false)
{} {}
/* /*
@@ -273,11 +280,12 @@ public:
virtual CCoder &GetCoder(unsigned index) = 0; virtual CCoder &GetCoder(unsigned index) = 0;
virtual void SelectMainCoder(bool useFirst) = 0; virtual void SelectMainCoder(bool useFirst) = 0;
virtual void ReInit() = 0; virtual void ReInit() = 0;
virtual void SetCoderInfo(unsigned coderIndex, const UInt64 *unpackSize, const UInt64 * const *packSizes) = 0; virtual void SetCoderInfo(unsigned coderIndex, const UInt64 *unpackSize, const UInt64 * const *packSizes, bool finish) = 0;
virtual HRESULT Code( virtual HRESULT Code(
ISequentialInStream * const *inStreams, ISequentialInStream * const *inStreams,
ISequentialOutStream * const *outStreams, ISequentialOutStream * const *outStreams,
ICompressProgressInfo *progress) = 0; ICompressProgressInfo *progress,
bool &dataAfterEnd_Error) = 0;
virtual UInt64 GetBondStreamSize(unsigned bondIndex) const = 0; virtual UInt64 GetBondStreamSize(unsigned bondIndex) const = 0;
bool Is_UnpackSize_Correct_for_Coder(UInt32 coderIndex); bool Is_UnpackSize_Correct_for_Coder(UInt32 coderIndex);
@@ -338,12 +346,13 @@ public:
virtual CCoder &GetCoder(unsigned index); virtual CCoder &GetCoder(unsigned index);
virtual void SelectMainCoder(bool useFirst); virtual void SelectMainCoder(bool useFirst);
virtual void ReInit(); virtual void ReInit();
virtual void SetCoderInfo(unsigned coderIndex, const UInt64 *unpackSize, const UInt64 * const *packSizes) virtual void SetCoderInfo(unsigned coderIndex, const UInt64 *unpackSize, const UInt64 * const *packSizes, bool finish)
{ _coders[coderIndex].SetCoderInfo(unpackSize, packSizes); } { _coders[coderIndex].SetCoderInfo(unpackSize, packSizes, finish); }
virtual HRESULT Code( virtual HRESULT Code(
ISequentialInStream * const *inStreams, ISequentialInStream * const *inStreams,
ISequentialOutStream * const *outStreams, ISequentialOutStream * const *outStreams,
ICompressProgressInfo *progress); ICompressProgressInfo *progress,
bool &dataAfterEnd_Error);
virtual UInt64 GetBondStreamSize(unsigned bondIndex) const; virtual UInt64 GetBondStreamSize(unsigned bondIndex) const;
HRESULT GetMainUnpackStream( HRESULT GetMainUnpackStream(
@@ -419,12 +428,13 @@ public:
virtual CCoder &GetCoder(unsigned index); virtual CCoder &GetCoder(unsigned index);
virtual void SelectMainCoder(bool useFirst); virtual void SelectMainCoder(bool useFirst);
virtual void ReInit(); virtual void ReInit();
virtual void SetCoderInfo(unsigned coderIndex, const UInt64 *unpackSize, const UInt64 * const *packSizes) virtual void SetCoderInfo(unsigned coderIndex, const UInt64 *unpackSize, const UInt64 * const *packSizes, bool finish)
{ _coders[coderIndex].SetCoderInfo(unpackSize, packSizes); } { _coders[coderIndex].SetCoderInfo(unpackSize, packSizes, finish); }
virtual HRESULT Code( virtual HRESULT Code(
ISequentialInStream * const *inStreams, ISequentialInStream * const *inStreams,
ISequentialOutStream * const *outStreams, ISequentialOutStream * const *outStreams,
ICompressProgressInfo *progress); ICompressProgressInfo *progress,
bool &dataAfterEnd_Error);
virtual UInt64 GetBondStreamSize(unsigned bondIndex) const; virtual UInt64 GetBondStreamSize(unsigned bondIndex) const;
CMixerMT(bool encodeMode): CMixer(encodeMode) {} CMixerMT(bool encodeMode): CMixer(encodeMode) {}

View File

@@ -20,21 +20,20 @@ static void SetMethodProp32(COneMethodInfo &m, PROPID propID, UInt32 value)
m.AddProp32(propID, value); m.AddProp32(propID, value);
} }
void CMultiMethodProps::SetGlobalLevelAndThreads(COneMethodInfo &oneMethodInfo void CMultiMethodProps::SetGlobalLevelTo(COneMethodInfo &oneMethodInfo) const
#ifndef _7ZIP_ST
, UInt32 numThreads
#endif
)
{ {
UInt32 level = _level; UInt32 level = _level;
if (level != (UInt32)(Int32)-1) if (level != (UInt32)(Int32)-1)
SetMethodProp32(oneMethodInfo, NCoderPropID::kLevel, (UInt32)level); SetMethodProp32(oneMethodInfo, NCoderPropID::kLevel, (UInt32)level);
#ifndef _7ZIP_ST
SetMethodProp32(oneMethodInfo, NCoderPropID::kNumThreads, numThreads);
#endif
} }
#ifndef _7ZIP_ST
void CMultiMethodProps::SetMethodThreadsTo(COneMethodInfo &oneMethodInfo, UInt32 numThreads)
{
SetMethodProp32(oneMethodInfo, NCoderPropID::kNumThreads, numThreads);
}
#endif
void CMultiMethodProps::Init() void CMultiMethodProps::Init()
{ {
#ifndef _7ZIP_ST #ifndef _7ZIP_ST
@@ -73,7 +72,7 @@ HRESULT CMultiMethodProps::SetProperty(const wchar_t *nameSpec, const PROPVARIAN
return S_OK; return S_OK;
} }
if (name.IsEqualTo("crc")) if (name.IsPrefixedBy_Ascii_NoCase("crc"))
{ {
name.Delete(0, 3); name.Delete(0, 3);
_crcSize = 4; _crcSize = 4;

View File

@@ -22,11 +22,13 @@ public:
COneMethodInfo _filterMethod; COneMethodInfo _filterMethod;
bool _autoFilter; bool _autoFilter;
void SetGlobalLevelAndThreads(COneMethodInfo &oneMethodInfo
#ifndef _7ZIP_ST void SetGlobalLevelTo(COneMethodInfo &oneMethodInfo) const;
, UInt32 numThreads
#endif #ifndef _7ZIP_ST
); static void SetMethodThreadsTo(COneMethodInfo &oneMethodInfo, UInt32 numThreads);
#endif
unsigned GetNumEmptyMethods() const unsigned GetNumEmptyMethods() const
{ {

View File

@@ -7,58 +7,57 @@
namespace NArchive { namespace NArchive {
namespace NItemName { namespace NItemName {
static const wchar_t kOSDirDelimiter = WCHAR_PATH_SEPARATOR; static const wchar_t kOsPathSepar = WCHAR_PATH_SEPARATOR;
static const wchar_t kDirDelimiter = L'/'; static const wchar_t kUnixPathSepar = L'/';
void ReplaceToOsPathSeparator(wchar_t *s) void ReplaceSlashes_OsToUnix
{ #if WCHAR_PATH_SEPARATOR != L'/'
#ifdef _WIN32 (UString &name)
for (;;)
{ {
wchar_t c = *s; name.Replace(kOsPathSepar, kUnixPathSepar);
if (c == 0)
break;
if (c == kDirDelimiter)
*s = kOSDirDelimiter;
s++;
} }
#else
(UString &) {}
#endif
UString GetOsPath(const UString &name)
{
#if WCHAR_PATH_SEPARATOR != L'/'
UString newName = name;
newName.Replace(kUnixPathSepar, kOsPathSepar);
return newName;
#else
return name;
#endif #endif
} }
UString MakeLegalName(const UString &name)
{
UString zipName = name;
zipName.Replace(kOSDirDelimiter, kDirDelimiter);
return zipName;
}
UString GetOSName(const UString &name) UString GetOsPath_Remove_TailSlash(const UString &name)
{
UString newName = name;
newName.Replace(kDirDelimiter, kOSDirDelimiter);
return newName;
}
UString GetOSName2(const UString &name)
{ {
if (name.IsEmpty()) if (name.IsEmpty())
return UString(); return UString();
UString newName = GetOSName(name); UString newName = GetOsPath(name);
if (newName.Back() == kOSDirDelimiter) if (newName.Back() == kOsPathSepar)
newName.DeleteBack(); newName.DeleteBack();
return newName; return newName;
} }
void ConvertToOSName2(UString &name)
void ReplaceToOsSlashes_Remove_TailSlash(UString &name)
{ {
if (!name.IsEmpty()) if (!name.IsEmpty())
{ {
name.Replace(kDirDelimiter, kOSDirDelimiter); #if WCHAR_PATH_SEPARATOR != L'/'
if (name.Back() == kOSDirDelimiter) name.Replace(kUnixPathSepar, kOsPathSepar);
#endif
if (name.Back() == kOsPathSepar)
name.DeleteBack(); name.DeleteBack();
} }
} }
bool HasTailSlash(const AString &name, UINT bool HasTailSlash(const AString &name, UINT
#if defined(_WIN32) && !defined(UNDER_CE) #if defined(_WIN32) && !defined(UNDER_CE)
codePage codePage
@@ -67,20 +66,21 @@ bool HasTailSlash(const AString &name, UINT
{ {
if (name.IsEmpty()) if (name.IsEmpty())
return false; return false;
LPCSTR prev = char c =
#if defined(_WIN32) && !defined(UNDER_CE) #if defined(_WIN32) && !defined(UNDER_CE)
CharPrevExA((WORD)codePage, name, &name[name.Len()], 0); *CharPrevExA((WORD)codePage, name, name.Ptr(name.Len()), 0);
#else #else
(LPCSTR)(name) + (name.Len() - 1); name.Back();
#endif #endif
return (*prev == '/'); return (c == '/');
} }
#ifndef _WIN32 #ifndef _WIN32
UString WinNameToOSName(const UString &name) UString WinPathToOsPath(const UString &name)
{ {
UString newName = name; UString newName = name;
newName.Replace(L'\\', kOSDirDelimiter); newName.Replace(L'\\', WCHAR_PATH_SEPARATOR);
return newName; return newName;
} }
#endif #endif

View File

@@ -8,19 +8,20 @@
namespace NArchive { namespace NArchive {
namespace NItemName { namespace NItemName {
void ReplaceToOsPathSeparator(wchar_t *s); void ReplaceSlashes_OsToUnix(UString &name);
UString MakeLegalName(const UString &name); UString GetOsPath(const UString &name);
UString GetOSName(const UString &name); UString GetOsPath_Remove_TailSlash(const UString &name);
UString GetOSName2(const UString &name);
void ConvertToOSName2(UString &name); void ReplaceToOsSlashes_Remove_TailSlash(UString &name);
bool HasTailSlash(const AString &name, UINT codePage);
bool HasTailSlash(const AString &name, UINT codePage);
#ifdef _WIN32
inline UString WinNameToOSName(const UString &name) { return name; } #ifdef _WIN32
#else inline UString WinPathToOsPath(const UString &name) { return name; }
UString WinNameToOSName(const UString &name); #else
#endif UString WinPathToOsPath(const UString &name);
#endif
}} }}

View File

@@ -36,7 +36,7 @@ static const Byte kMagicHex = '1'; // New ASCII Format
static const Byte kMagicHexCrc = '2'; // New CRC Format static const Byte kMagicHexCrc = '2'; // New CRC Format
static const Byte kMagicOct = '7'; // Portable ASCII Format static const Byte kMagicOct = '7'; // Portable ASCII Format
static const char *kName_TRAILER = "TRAILER!!!"; static const char * const kName_TRAILER = "TRAILER!!!";
static const unsigned k_BinRecord_Size = 2 + 8 * 2 + 2 * 4; static const unsigned k_BinRecord_Size = 2 + 8 * 2 + 2 * 4;
static const unsigned k_OctRecord_Size = 6 + 8 * 6 + 2 * 11; static const unsigned k_OctRecord_Size = 6 + 8 * 6 + 2 * 11;
@@ -627,7 +627,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
#endif #endif
if (needConvert) if (needConvert)
res = MultiByteToUnicodeString(item.Name, CP_OEMCP); res = MultiByteToUnicodeString(item.Name, CP_OEMCP);
prop = NItemName::GetOSName(res); prop = NItemName::GetOsPath(res);
break; break;
} }
case kpidIsDir: prop = item.IsDir(); break; case kpidIsDir: prop = item.IsDir(); break;

View File

@@ -183,6 +183,30 @@ struct CExtraFile
}; };
#endif #endif
struct CForkPair
{
UInt64 Offset;
UInt64 Len;
void Parse(const Byte *p)
{
Offset = Get64(p);
Len = Get64(p + 8);
}
bool UpdateTop(UInt64 limit, UInt64 &top)
{
if (Offset > limit || Len > limit - Offset)
return false;
UInt64 top2 = Offset + Len;
if (top <= top2)
top = top2;
return true;
}
};
class CHandler: class CHandler:
public IInArchive, public IInArchive,
public IInArchiveGetStream, public IInArchiveGetStream,
@@ -191,14 +215,19 @@ class CHandler:
CMyComPtr<IInStream> _inStream; CMyComPtr<IInStream> _inStream;
CObjectVector<CFile> _files; CObjectVector<CFile> _files;
bool _masterCrcError; bool _masterCrcError;
bool _headersError;
UInt64 _startPos; UInt64 _startPos;
UInt64 _phySize; UInt64 _phySize;
AString _name;
#ifdef DMG_SHOW_RAW #ifdef DMG_SHOW_RAW
CObjectVector<CExtraFile> _extras; CObjectVector<CExtraFile> _extras;
#endif #endif
HRESULT ReadData(IInStream *stream, const CForkPair &pair, CByteBuffer &buf);
bool ParseBlob(const CByteBuffer &data);
HRESULT Open2(IInStream *stream); HRESULT Open2(IInStream *stream);
HRESULT Extract(IInStream *stream); HRESULT Extract(IInStream *stream);
public: public:
@@ -249,24 +278,20 @@ void CMethods::GetString(AString &res) const
case METHOD_BZIP2: s = "BZip2"; break; case METHOD_BZIP2: s = "BZip2"; break;
default: ConvertUInt32ToString(type, buf); s = buf; default: ConvertUInt32ToString(type, buf); s = buf;
} }
res.Add_Space_if_NotEmpty(); res.Add_OptSpaced(s);
res += s;
} }
for (i = 0; i < ChecksumTypes.Size(); i++) for (i = 0; i < ChecksumTypes.Size(); i++)
{ {
res.Add_Space_if_NotEmpty();
UInt32 type = ChecksumTypes[i]; UInt32 type = ChecksumTypes[i];
char buf[32];
const char *s;
switch (type) switch (type)
{ {
case kCheckSumType_CRC: s = "CRC"; break; case kCheckSumType_CRC: res += "CRC"; break;
default: default:
ConvertUInt32ToString(type, MyStpCpy(buf, "Check")); res += "Check";
s = buf; res.Add_UInt32(type);
} }
res.Add_Space_if_NotEmpty();
res += s;
} }
} }
@@ -308,7 +333,8 @@ IMP_IInArchive_Props
static const Byte kArcProps[] = static const Byte kArcProps[] =
{ {
kpidMethod, kpidMethod,
kpidNumBlocks kpidNumBlocks,
kpidComment
}; };
STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value) STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
@@ -372,9 +398,30 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
case kpidWarning: case kpidWarning:
if (_masterCrcError) if (_masterCrcError)
prop = "Master CRC error"; prop = "Master CRC error";
case kpidWarningFlags:
{
UInt32 v = 0;
if (_headersError) v |= kpv_ErrorFlags_HeadersError;
if (v != 0)
prop = v;
break; break;
}
case kpidOffset: prop = _startPos; break; case kpidOffset: prop = _startPos; break;
case kpidPhySize: prop = _phySize; break; case kpidPhySize: prop = _phySize; break;
case kpidComment:
if (!_name.IsEmpty() && _name.Len() < 256)
prop = _name;
break;
case kpidName:
if (!_name.IsEmpty() && _name.Len() < 256)
{
prop = _name + ".dmg";
}
break;
} }
prop.Detach(value); prop.Detach(value);
return S_OK; return S_OK;
@@ -461,7 +508,7 @@ HRESULT CFile::Parse(const Byte *p, UInt32 size)
return S_OK; return S_OK;
} }
static int FindKeyPair(const CXmlItem &item, const AString &key, const AString &nextTag) static int FindKeyPair(const CXmlItem &item, const char *key, const char *nextTag)
{ {
for (unsigned i = 0; i + 1 < item.SubItems.Size(); i++) for (unsigned i = 0; i + 1 < item.SubItems.Size(); i++)
{ {
@@ -472,7 +519,7 @@ static int FindKeyPair(const CXmlItem &item, const AString &key, const AString &
return -1; return -1;
} }
static const AString *GetStringFromKeyPair(const CXmlItem &item, const AString &key, const AString &nextTag) static const AString *GetStringFromKeyPair(const CXmlItem &item, const char *key, const char *nextTag)
{ {
int index = FindKeyPair(item, key, nextTag); int index = FindKeyPair(item, key, nextTag);
if (index >= 0) if (index >= 0)
@@ -498,6 +545,83 @@ static inline bool IsKoly(const Byte *p)
*/ */
} }
HRESULT CHandler::ReadData(IInStream *stream, const CForkPair &pair, CByteBuffer &buf)
{
size_t size = (size_t)pair.Len;
if (size != pair.Len)
return E_OUTOFMEMORY;
buf.Alloc(size);
RINOK(stream->Seek(_startPos + pair.Offset, STREAM_SEEK_SET, NULL));
return ReadStream_FALSE(stream, buf, size);
}
bool CHandler::ParseBlob(const CByteBuffer &data)
{
if (data.Size() < 12)
return false;
const Byte *p = (const Byte *)data;
if (Get32(p) != 0xFADE0CC0)
return true;
const UInt32 size = Get32(p + 4);
if (size != data.Size())
return false;
const UInt32 num = Get32(p + 8);
if (num > (size - 12) / 8)
return false;
for (UInt32 i = 0; i < num; i++)
{
// UInt32 type = Get32(p + i * 8 + 12);
UInt32 offset = Get32(p + i * 8 + 12 + 4);
if (size - offset < 8)
return false;
const Byte *p2 = (const Byte *)data + offset;
const UInt32 magic = Get32(p2);
const UInt32 len = Get32(p2 + 4);
if (size - offset < len || len < 8)
return false;
#ifdef DMG_SHOW_RAW
CExtraFile &extra = _extras.AddNew();
extra.Name = "_blob_";
extra.Data.CopyFrom(p2, len);
#endif
if (magic == 0xFADE0C02)
{
#ifdef DMG_SHOW_RAW
extra.Name += "codedir";
#endif
if (len < 11 * 4)
return false;
UInt32 idOffset = Get32(p2 + 0x14);
if (idOffset >= len)
return false;
UInt32 len2 = len - idOffset;
if (len2 < (1 << 10))
_name.SetFrom_CalcLen((const char *)(p2 + idOffset), len2);
}
#ifdef DMG_SHOW_RAW
else if (magic == 0xFADE0C01)
extra.Name += "requirements";
else if (magic == 0xFADE0B01)
extra.Name += "signed";
else
{
char temp[16];
ConvertUInt32ToHex8Digits(magic, temp);
extra.Name += temp;
}
#endif
}
return true;
}
HRESULT CHandler::Open2(IInStream *stream) HRESULT CHandler::Open2(IInStream *stream)
{ {
RINOK(stream->Seek(0, STREAM_SEEK_CUR, &_startPos)); RINOK(stream->Seek(0, STREAM_SEEK_CUR, &_startPos));
@@ -522,35 +646,69 @@ HRESULT CHandler::Open2(IInStream *stream)
// UInt32 flags = Get32(buf + 12); // UInt32 flags = Get32(buf + 12);
// UInt64 runningDataForkOffset = Get64(buf + 0x10); // UInt64 runningDataForkOffset = Get64(buf + 0x10);
UInt64 dataForkOffset = Get64(buf + 0x18);
UInt64 dataForkLen = Get64(buf + 0x20); CForkPair dataForkPair, rsrcPair, xmlPair, blobPair;
UInt64 rsrcOffset = Get64(buf + 0x28);
UInt64 rsrcLen = Get64(buf + 0x30); dataForkPair.Parse(buf + 0x18);
rsrcPair.Parse(buf + 0x28);
xmlPair.Parse(buf + 0xD8);
blobPair.Parse(buf + 0x128);
// UInt32 segmentNumber = Get32(buf + 0x38); // UInt32 segmentNumber = Get32(buf + 0x38);
// UInt32 segmentCount = Get32(buf + 0x3C); // UInt32 segmentCount = Get32(buf + 0x3C);
// Byte segmentGUID[16]; // Byte segmentGUID[16];
// CChecksum dataForkChecksum; // CChecksum dataForkChecksum;
// dataForkChecksum.Parse(buf + 0x50); // dataForkChecksum.Parse(buf + 0x50);
UInt64 xmlOffset = Get64(buf + 0xD8);
UInt64 xmlLen = Get64(buf + 0xE0);
if ( headerPos < dataForkOffset _startPos = 0;
|| headerPos - dataForkOffset < dataForkLen
|| headerPos < rsrcOffset
|| headerPos - rsrcOffset < rsrcLen
|| headerPos < xmlOffset
|| headerPos - xmlOffset < xmlLen)
return S_FALSE;
UInt64 totalLen = dataForkLen + rsrcLen + xmlLen; UInt64 top = 0;
if (totalLen > headerPos) if (!dataForkPair.UpdateTop(headerPos, top)) return S_FALSE;
return S_FALSE; if (!xmlPair.UpdateTop(headerPos, top)) return S_FALSE;
_startPos = headerPos - totalLen; if (!rsrcPair.UpdateTop(headerPos, top)) return S_FALSE;
_phySize = totalLen + HEADER_SIZE;
headerPos = totalLen; /* Some old dmg files contain garbage data in blobPair field.
So we need to ignore such garbage case;
And we still need to detect offset of start of archive for "parser" mode. */
bool useBlob = blobPair.UpdateTop(headerPos, top);
_startPos = 0;
_phySize = headerPos + HEADER_SIZE;
if (top != headerPos)
{
CForkPair xmlPair2 = xmlPair;
const char *sz = "<?xml version";
const unsigned len = (unsigned)strlen(sz);
if (xmlPair2.Len > len)
xmlPair2.Len = len;
CByteBuffer buf2;
if (ReadData(stream, xmlPair2, buf2) != S_OK
|| memcmp(buf2, sz, len) != 0)
{
_startPos = headerPos - top;
_phySize = top + HEADER_SIZE;
}
}
// Byte reserved[0x78] // Byte reserved[0x78]
if (useBlob && blobPair.Len != 0)
{
#ifdef DMG_SHOW_RAW
CExtraFile &extra = _extras.AddNew();
extra.Name = "_blob.bin";
CByteBuffer &blobBuf = extra.Data;
#else
CByteBuffer blobBuf;
#endif
RINOK(ReadData(stream, blobPair, blobBuf));
if (!ParseBlob(blobBuf))
_headersError = true;
}
CChecksum masterChecksum; CChecksum masterChecksum;
masterChecksum.Parse(buf + 0x160); masterChecksum.Parse(buf + 0x160);
@@ -562,7 +720,7 @@ HRESULT CHandler::Open2(IInStream *stream)
// We don't know the size of the field "offset" in rsrc. // We don't know the size of the field "offset" in rsrc.
// We suppose that it uses 24 bits. So we use Rsrc, only if the rsrcLen < (1 << 24). // We suppose that it uses 24 bits. So we use Rsrc, only if the rsrcLen < (1 << 24).
bool useRsrc = (rsrcLen > RSRC_HEAD_SIZE && rsrcLen < ((UInt32)1 << 24)); bool useRsrc = (rsrcPair.Len > RSRC_HEAD_SIZE && rsrcPair.Len < ((UInt32)1 << 24));
// useRsrc = false; // useRsrc = false;
if (useRsrc) if (useRsrc)
@@ -575,21 +733,18 @@ HRESULT CHandler::Open2(IInStream *stream)
CByteBuffer rsrcBuf; CByteBuffer rsrcBuf;
#endif #endif
size_t rsrcLenT = (size_t)rsrcLen; RINOK(ReadData(stream, rsrcPair, rsrcBuf));
rsrcBuf.Alloc(rsrcLenT);
RINOK(stream->Seek(_startPos + rsrcOffset, STREAM_SEEK_SET, NULL));
RINOK(ReadStream_FALSE(stream, rsrcBuf, rsrcLenT));
const Byte *p = rsrcBuf; const Byte *p = rsrcBuf;
UInt32 headSize = Get32(p + 0); UInt32 headSize = Get32(p + 0);
UInt32 footerOffset = Get32(p + 4); UInt32 footerOffset = Get32(p + 4);
UInt32 mainDataSize = Get32(p + 8); UInt32 mainDataSize = Get32(p + 8);
UInt32 footerSize = Get32(p + 12); UInt32 footerSize = Get32(p + 12);
if (headSize != RSRC_HEAD_SIZE || if (headSize != RSRC_HEAD_SIZE
footerOffset >= rsrcLenT || || footerOffset >= rsrcPair.Len
mainDataSize >= rsrcLenT || || mainDataSize >= rsrcPair.Len
footerOffset + footerSize != rsrcLenT || || footerOffset + footerSize != rsrcPair.Len
footerOffset != headSize + mainDataSize) || footerOffset != headSize + mainDataSize)
return S_FALSE; return S_FALSE;
if (footerSize < 16) if (footerSize < 16)
return S_FALSE; return S_FALSE;
@@ -600,7 +755,7 @@ HRESULT CHandler::Open2(IInStream *stream)
if ((UInt32)Get16(p + 0x18) != 0x1C) if ((UInt32)Get16(p + 0x18) != 0x1C)
return S_FALSE; return S_FALSE;
UInt32 namesOffset = Get16(p + 0x1A); const UInt32 namesOffset = Get16(p + 0x1A);
if (namesOffset > footerSize) if (namesOffset > footerSize)
return S_FALSE; return S_FALSE;
@@ -612,12 +767,15 @@ HRESULT CHandler::Open2(IInStream *stream)
{ {
const Byte *p2 = p + 0x1E + i * 8; const Byte *p2 = p + 0x1E + i * 8;
UInt32 typeId = Get32(p2); const UInt32 typeId = Get32(p2);
#ifndef DMG_SHOW_RAW
if (typeId != 0x626C6B78) // blkx if (typeId != 0x626C6B78) // blkx
continue; continue;
#endif
UInt32 numFiles = (UInt32)Get16(p2 + 4) + 1; const UInt32 numFiles = (UInt32)Get16(p2 + 4) + 1;
UInt32 offs = Get16(p2 + 6); const UInt32 offs = Get16(p2 + 6);
if (0x1C + offs + 12 * numFiles > namesOffset) if (0x1C + offs + 12 * numFiles > namesOffset)
return S_FALSE; return S_FALSE;
@@ -625,7 +783,7 @@ HRESULT CHandler::Open2(IInStream *stream)
{ {
const Byte *p3 = p + 0x1C + offs + k * 12; const Byte *p3 = p + 0x1C + offs + k * 12;
// UInt32 id = Get16(p3); // UInt32 id = Get16(p3);
UInt32 namePos = Get16(p3 + 2); const UInt32 namePos = Get16(p3 + 2);
// Byte attributes = p3[4]; // = 0x50 for blkx // Byte attributes = p3[4]; // = 0x50 for blkx
// we don't know how many bits we can use. So we use 24 bits only // we don't know how many bits we can use. So we use 24 bits only
UInt32 blockOffset = Get32(p3 + 4); UInt32 blockOffset = Get32(p3 + 4);
@@ -634,21 +792,12 @@ HRESULT CHandler::Open2(IInStream *stream)
if (blockOffset + 4 >= mainDataSize) if (blockOffset + 4 >= mainDataSize)
return S_FALSE; return S_FALSE;
const Byte *pBlock = rsrcBuf + headSize + blockOffset; const Byte *pBlock = rsrcBuf + headSize + blockOffset;
UInt32 blockSize = Get32(pBlock); const UInt32 blockSize = Get32(pBlock);
if (mainDataSize - (blockOffset + 4) < blockSize)
#ifdef DMG_SHOW_RAW return S_FALSE;
{
CExtraFile &extra = _extras.AddNew(); AString name;
{
char extraName[16];
ConvertUInt32ToString(_files.Size(), extraName);
extra.Name = extraName;
}
extra.Data.CopyFrom(pBlock + 4, blockSize);
}
#endif
CFile &file = _files.AddNew();
if (namePos != 0xFFFF) if (namePos != 0xFFFF)
{ {
UInt32 namesBlockSize = footerSize - namesOffset; UInt32 namesBlockSize = footerSize - namesOffset;
@@ -663,22 +812,56 @@ HRESULT CHandler::Open2(IInStream *stream)
Byte c = namePtr[r]; Byte c = namePtr[r];
if (c < 0x20 || c >= 0x80) if (c < 0x20 || c >= 0x80)
break; break;
file.Name += (char)c; name += (char)c;
} }
} }
RINOK(file.Parse(pBlock + 4, blockSize));
if (typeId == 0x626C6B78) // blkx
{
CFile &file = _files.AddNew();
file.Name = name;
RINOK(file.Parse(pBlock + 4, blockSize));
}
#ifdef DMG_SHOW_RAW
{
AString name2;
name2.Add_UInt32(i);
name2 += '_';
{
char temp[4 + 1] = { 0 };
memcpy(temp, p2, 4);
name2 += temp;
}
name2.Trim();
name2 += '_';
name2.Add_UInt32(k);
if (!name.IsEmpty())
{
name2 += '_';
name2 += name;
}
CExtraFile &extra = _extras.AddNew();
extra.Name = name2;
extra.Data.CopyFrom(pBlock + 4, blockSize);
}
#endif
} }
} }
} }
else else
{ {
if (xmlLen >= kXmlSizeMax || xmlLen == 0) if (xmlPair.Len >= kXmlSizeMax || xmlPair.Len == 0)
return S_FALSE; return S_FALSE;
size_t size = (size_t)xmlLen; size_t size = (size_t)xmlPair.Len;
if (size != xmlLen) if (size != xmlPair.Len)
return S_FALSE; return S_FALSE;
RINOK(stream->Seek(_startPos + dataForkLen, STREAM_SEEK_SET, NULL)); RINOK(stream->Seek(_startPos + xmlPair.Offset, STREAM_SEEK_SET, NULL));
CXml xml; CXml xml;
{ {
@@ -733,16 +916,12 @@ HRESULT CHandler::Open2(IInStream *stream)
const Byte *endPtr = Base64ToBin(rawBuf, *dataString); const Byte *endPtr = Base64ToBin(rawBuf, *dataString);
if (!endPtr) if (!endPtr)
return S_FALSE; return S_FALSE;
destLen = (unsigned)(endPtr - rawBuf); destLen = (unsigned)(endPtr - (const Byte *)rawBuf);
} }
#ifdef DMG_SHOW_RAW #ifdef DMG_SHOW_RAW
CExtraFile &extra = _extras.AddNew(); CExtraFile &extra = _extras.AddNew();
{ extra.Name.Add_UInt32(_files.Size());
char extraName[16];
ConvertUInt32ToString(_files.Size(), extraName);
extra.Name = extraName;
}
extra.Data.CopyFrom(rawBuf, destLen); extra.Data.CopyFrom(rawBuf, destLen);
#endif #endif
} }
@@ -800,6 +979,8 @@ STDMETHODIMP CHandler::Close()
_inStream.Release(); _inStream.Release();
_files.Clear(); _files.Clear();
_masterCrcError = false; _masterCrcError = false;
_headersError = false;
_name.Empty();
#ifdef DMG_SHOW_RAW #ifdef DMG_SHOW_RAW
_extras.Clear(); _extras.Clear();
#endif #endif
@@ -867,9 +1048,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
case kpidPath: case kpidPath:
{ {
UString name; UString name;
wchar_t s[16]; name.Add_UInt32(index);
ConvertUInt32ToString(index, s);
name = s;
unsigned num = 10; unsigned num = 10;
unsigned numDigits; unsigned numDigits;
for (numDigits = 1; num < _files.Size(); numDigits++) for (numDigits = 1; num < _files.Size(); numDigits++)
@@ -908,7 +1087,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
} }
UString name2; UString name2;
ConvertUTF8ToUnicode(subName, name2); ConvertUTF8ToUnicode(subName, name2);
name += L'.'; name += '.';
name += name2; name += name2;
} }
else else
@@ -916,7 +1095,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
UString name2; UString name2;
ConvertUTF8ToUnicode(item.Name, name2); ConvertUTF8ToUnicode(item.Name, name2);
if (!name2.IsEmpty()) if (!name2.IsEmpty())
name.AddAscii(" - "); name += "_";
name += name2; name += name2;
} }
prop = name; prop = name;

View File

@@ -158,21 +158,21 @@ bool CHeader::Parse(const Byte *p)
static const char * const g_SegnmentTypes[] = static const char * const g_SegnmentTypes[] =
{ {
"Unused", "Unused"
"Loadable segment", , "Loadable segment"
"Dynamic linking tables", , "Dynamic linking tables"
"Program interpreter path name", , "Program interpreter path name"
"Note section", , "Note section"
"SHLIB", , "SHLIB"
"Program header table", , "Program header table"
"TLS" , "TLS"
}; };
static const CUInt32PCharPair g_SegmentFlags[] = static const char * const g_SegmentFlags[] =
{ {
{ 0, "Execute" }, "Execute"
{ 1, "Write" }, , "Write"
{ 2, "Read" } , "Read"
}; };
struct CSegment struct CSegment
@@ -359,173 +359,215 @@ bool CSection::Parse(const Byte *p, bool mode64, bool be)
return true; return true;
} }
static const CUInt32PCharPair g_Machines[] =
static const char * const g_Machines[] =
{ {
{ 0, "None" }, "None"
{ 1, "AT&T WE 32100" }, , "AT&T WE 32100"
{ 2, "SPARC" }, , "SPARC"
{ 3, "Intel 386" }, , "Intel 386"
{ 4, "Motorola 68000" }, , "Motorola 68000"
{ 5, "Motorola 88000" }, , "Motorola 88000"
{ 6, "Intel 486" }, , "Intel 486"
{ 7, "Intel i860" }, , "Intel i860"
{ 8, "MIPS" }, , "MIPS"
{ 9, "IBM S/370" }, , "IBM S/370"
{ 10, "MIPS RS3000 LE" }, , "MIPS RS3000 LE"
{ 11, "RS6000" }, , "RS6000"
, NULL
, NULL
, NULL
, "PA-RISC"
, "nCUBE"
, "Fujitsu VPP500"
, "SPARC 32+"
, "Intel i960"
, "PowerPC"
, "PowerPC 64-bit"
, "IBM S/390"
, "SPU"
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "NEX v800"
, "Fujitsu FR20"
, "TRW RH-32"
, "Motorola RCE"
, "ARM"
, "Alpha"
, "Hitachi SH"
, "SPARC-V9"
, "Siemens Tricore"
, "ARC"
, "H8/300"
, "H8/300H"
, "H8S"
, "H8/500"
, "IA-64"
, "Stanford MIPS-X"
, "Motorola ColdFire"
, "M68HC12"
, "Fujitsu MMA"
, "Siemens PCP"
, "Sony nCPU"
, "Denso NDR1"
, "Motorola StarCore"
, "Toyota ME16"
, "ST100"
, "Advanced Logic TinyJ"
, "AMD64"
, "Sony DSP"
, NULL
, NULL
, "Siemens FX66"
, "ST9+"
, "ST7"
, "MC68HC16"
, "MC68HC11"
, "MC68HC08"
, "MC68HC05"
, "Silicon Graphics SVx"
, "ST19"
, "Digital VAX"
, "Axis CRIS"
, "Infineon JAVELIN"
, "Element 14 FirePath"
, "LSI ZSP"
, "MMIX"
, "HUANY"
, "SiTera Prism"
, "Atmel AVR"
, "Fujitsu FR30"
, "Mitsubishi D10V"
, "Mitsubishi D30V"
, "NEC v850"
, "Mitsubishi M32R"
, "Matsushita MN10300"
, "Matsushita MN10200"
, "picoJava"
, "OpenRISC"
, "ARC Tangent-A5"
, "Tensilica Xtensa"
, "Alphamosaic VideoCore"
, "Thompson MM GPP"
, "National Semiconductor 32K"
, "Tenor Network TPC"
, "Trebia SNP 1000"
, "ST200"
, "Ubicom IP2xxx"
, "MAX"
, "NS CompactRISC"
, "Fujitsu F2MC16"
, "TI msp430"
, "Blackfin (DSP)"
, "SE S1C33"
, "Sharp embedded"
, "Arca RISC"
, "Unicore"
, "eXcess"
, "DXP"
, "Altera Nios II"
, "NS CRX"
, "Motorola XGATE"
, "Infineon C16x/XC16x"
, "Renesas M16C"
, "Microchip Technology dsPIC30F"
, "Freescale CE"
, "Renesas M32C"
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "Altium TSK3000"
, "Freescale RS08"
, "Analog Devices SHARC"
, "Cyan Technology eCOG2"
, "Sunplus S+core7 RISC"
, "NJR 24-bit DSP"
, "Broadcom VideoCore III"
, "Lattice FPGA"
, "SE C17"
, "TI TMS320C6000"
, "TI TMS320C2000"
, "TI TMS320C55x"
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "STM 64bit VLIW Data Signal"
, "Cypress M8C"
, "Renesas R32C"
, "NXP TriMedia"
, "Qualcomm Hexagon"
, "Intel 8051"
, "STMicroelectronics STxP7x"
, "Andes"
, "Cyan Technology eCOG1X"
, "Dallas Semiconductor MAXQ30"
, "NJR 16-bit DSP"
, "M2000"
, "Cray NV2"
, "Renesas RX"
, "Imagination Technologies META"
, "MCST Elbrus"
, "Cyan Technology eCOG16"
, "National Semiconductor CR16"
, "Freescale ETPUnit"
, "Infineon SLE9X"
, "Intel L10M"
, "Intel K10M"
, NULL
, "ARM64"
, NULL
, "Atmel AVR32"
, "STM8"
, "Tilera TILE64"
, "Tilera TILEPro"
, "Xilinx MicroBlaze"
, "NVIDIA CUDA"
, "Tilera TILE-Gx"
, "CloudShield"
, "KIPO-KAIST Core-A 1st"
, "KIPO-KAIST Core-A 2nd"
, "Synopsys ARCompact V2"
, "Open8"
, "Renesas RL78"
, "Broadcom VideoCore V"
, "Renesas 78KOR"
, "Freescale 56800EX" // 200
};
{ 15, "PA-RISC" }, static const CUInt32PCharPair g_MachinePairs[] =
{ 16, "nCUBE" }, {
{ 17, "Fujitsu VPP500" }, { 47787, "Xilinx MicroBlaze" }
{ 18, "SPARC 32+" },
{ 19, "Intel i960" },
{ 20, "PowerPC" },
{ 21, "PowerPC 64-bit" },
{ 22, "IBM S/390" },
{ 23, "SPU" },
{ 36, "NEX v800" },
{ 37, "Fujitsu FR20" },
{ 38, "TRW RH-32" },
{ 39, "Motorola RCE" },
{ 40, "ARM" },
{ 41, "Alpha" },
{ 42, "Hitachi SH" },
{ 43, "SPARC-V9" },
{ 44, "Siemens Tricore" },
{ 45, "ARC" },
{ 46, "H8/300" },
{ 47, "H8/300H" },
{ 48, "H8S" },
{ 49, "H8/500" },
{ 50, "IA-64" },
{ 51, "Stanford MIPS-X" },
{ 52, "Motorola ColdFire" },
{ 53, "M68HC12" },
{ 54, "Fujitsu MMA" },
{ 55, "Siemens PCP" },
{ 56, "Sony nCPU" },
{ 57, "Denso NDR1" },
{ 58, "Motorola StarCore" },
{ 59, "Toyota ME16" },
{ 60, "ST100" },
{ 61, "Advanced Logic TinyJ" },
{ 62, "AMD64" },
{ 63, "Sony DSP" },
{ 66, "Siemens FX66" },
{ 67, "ST9+" },
{ 68, "ST7" },
{ 69, "MC68HC16" },
{ 70, "MC68HC11" },
{ 71, "MC68HC08" },
{ 72, "MC68HC05" },
{ 73, "Silicon Graphics SVx" },
{ 74, "ST19" },
{ 75, "Digital VAX" },
{ 76, "Axis CRIS" },
{ 77, "Infineon JAVELIN" },
{ 78, "Element 14 FirePath" },
{ 79, "LSI ZSP" },
{ 80, "MMIX" },
{ 81, "HUANY" },
{ 82, "SiTera Prism" },
{ 83, "Atmel AVR" },
{ 84, "Fujitsu FR30" },
{ 85, "Mitsubishi D10V" },
{ 86, "Mitsubishi D30V" },
{ 87, "NEC v850" },
{ 88, "Mitsubishi M32R" },
{ 89, "Matsushita MN10300" },
{ 90, "Matsushita MN10200" },
{ 91, "picoJava" },
{ 92, "OpenRISC" },
{ 93, "ARC Tangent-A5" },
{ 94, "Tensilica Xtensa" },
{ 95, "Alphamosaic VideoCore" },
{ 96, "Thompson MM GPP" },
{ 97, "National Semiconductor 32K" },
{ 98, "Tenor Network TPC" },
{ 99, "Trebia SNP 1000" },
{ 100, "ST200" },
{ 101, "Ubicom IP2xxx" },
{ 102, "MAX" },
{ 103, "NS CompactRISC" },
{ 104, "Fujitsu F2MC16" },
{ 105, "TI msp430" },
{ 106, "Blackfin (DSP)" },
{ 107, "SE S1C33" },
{ 108, "Sharp embedded" },
{ 109, "Arca RISC" },
{ 110, "Unicore" },
{ 111, "eXcess" },
{ 112, "DXP" },
{ 113, "Altera Nios II" },
{ 114, "NS CRX" },
{ 115, "Motorola XGATE" },
{ 116, "Infineon C16x/XC16x" },
{ 117, "Renesas M16C" },
{ 118, "Microchip Technology dsPIC30F" },
{ 119, "Freescale CE" },
{ 120, "Renesas M32C" },
{ 131, "Altium TSK3000" },
{ 132, "Freescale RS08" },
{ 133, "Analog Devices SHARC" },
{ 134, "Cyan Technology eCOG2" },
{ 135, "Sunplus S+core7 RISC" },
{ 136, "NJR 24-bit DSP" },
{ 137, "Broadcom VideoCore III" },
{ 138, "Lattice FPGA" },
{ 139, "SE C17" },
{ 140, "TI TMS320C6000" },
{ 141, "TI TMS320C2000" },
{ 142, "TI TMS320C55x" },
{ 160, "STM 64bit VLIW Data Signal" },
{ 161, "Cypress M8C" },
{ 162, "Renesas R32C" },
{ 163, "NXP TriMedia" },
{ 164, "Qualcomm Hexagon" },
{ 165, "Intel 8051" },
{ 166, "STMicroelectronics STxP7x" },
{ 167, "Andes" },
{ 168, "Cyan Technology eCOG1X" },
{ 169, "Dallas Semiconductor MAXQ30" },
{ 170, "NJR 16-bit DSP" },
{ 171, "M2000" },
{ 172, "Cray NV2" },
{ 173, "Renesas RX" },
{ 174, "Imagination Technologies META" },
{ 175, "MCST Elbrus" },
{ 176, "Cyan Technology eCOG16" },
{ 177, "National Semiconductor CR16" },
{ 178, "Freescale ETPUnit" },
{ 179, "Infineon SLE9X" },
{ 180, "Intel L10M" },
{ 181, "Intel K10M" },
{ 183, "ARM64" },
{ 185, "Atmel AVR32" },
{ 186, "STM8" },
{ 187, "Tilera TILE64" },
{ 188, "Tilera TILEPro" },
{ 189, "Xilinx MicroBlaze" },
{ 190, "NVIDIA CUDA" },
{ 191, "Tilera TILE-Gx" },
{ 192, "CloudShield" },
{ 193, "KIPO-KAIST Core-A 1st" },
{ 194, "KIPO-KAIST Core-A 2nd" },
{ 195, "Synopsys ARCompact V2" },
{ 196, "Open8" },
{ 197, "Renesas RL78" },
{ 198, "Broadcom VideoCore V" },
{ 199, "Renesas 78KOR" },
{ 200, "Freescale 56800EX" },
{ 47787, "Xilinx MicroBlaze" },
// { 0x9026, "Alpha" } // { 0x9026, "Alpha" }
}; };
@@ -554,6 +596,7 @@ static const CUInt32PCharPair g_OS[] =
{ 255, "Standalone" } { 255, "Standalone" }
}; };
#define k_Machine_MIPS 8
#define k_Machine_ARM 40 #define k_Machine_ARM 40
/* /*
@@ -566,12 +609,29 @@ static const CUInt32PCharPair g_OS[] =
static const CUInt32PCharPair g_ARM_Flags[] = static const CUInt32PCharPair g_ARM_Flags[] =
{ {
{ 1, "HasEntry" },
{ 9, "SF" }, { 9, "SF" },
{ 10, "HF" }, { 10, "HF" },
{ 23, "BE8" } { 23, "BE8" }
}; };
static const CUInt32PCharPair g_MIPS_Flags[] =
{
{ 0, "NOREORDER" },
{ 1, "PIC" },
{ 2, "CPIC" },
{ 3, "XGOT" },
{ 4, "64BIT_WHIRL" },
{ 5, "ABI2" },
{ 6, "ABI_ON32" },
{ 10, "NAN2008" },
{ 25, "MicroMIPS" },
{ 26, "M16" },
{ 27, "MDMX" }
};
#define ET_NONE 0 #define ET_NONE 0
#define ET_REL 1 #define ET_REL 1
#define ET_EXEC 2 #define ET_EXEC 2
@@ -580,11 +640,11 @@ static const CUInt32PCharPair g_ARM_Flags[] =
static const char * const g_Types[] = static const char * const g_Types[] =
{ {
"None", "None"
"Relocatable file", , "Relocatable file"
"Executable file", , "Executable file"
"Shared object file", , "Shared object file"
"Core file" , "Core file"
}; };
@@ -643,8 +703,7 @@ static const Byte kArcProps[] =
kpidBigEndian, kpidBigEndian,
kpidHostOS, kpidHostOS,
kpidCharacts, kpidCharacts,
kpidHeadersSize, kpidHeadersSize
kpidName
}; };
enum enum
@@ -683,21 +742,49 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
case kpidCpu: case kpidCpu:
{ {
AString s = TypePairToString(g_Machines, ARRAY_SIZE(g_Machines), _header.Machine); AString s;
if (_header.Machine < ARRAY_SIZE(g_Machines))
{
const char *name = g_Machines[_header.Machine];
if (name)
s = name;
}
if (s.IsEmpty())
s = TypePairToString(g_MachinePairs, ARRAY_SIZE(g_MachinePairs), _header.Machine);
UInt32 flags = _header.Flags; UInt32 flags = _header.Flags;
if (flags != 0) if (flags != 0)
{ {
char sz[16];
s.Add_Space(); s.Add_Space();
if (_header.Machine == k_Machine_ARM) if (_header.Machine == k_Machine_ARM)
{ {
s += FlagsToString(g_ARM_Flags, ARRAY_SIZE(g_ARM_Flags), flags & (((UInt32)1 << 24) - 1)); s += FlagsToString(g_ARM_Flags, ARRAY_SIZE(g_ARM_Flags), flags & (((UInt32)1 << 24) - 1));
s += " ABI:"; s += " ABI:";
ConvertUInt32ToString(flags >> 24, sz); s.Add_UInt32(flags >> 24);
}
else if (_header.Machine == k_Machine_MIPS)
{
UInt32 ver = flags >> 28;
s += "v";
s.Add_UInt32(ver);
flags &= (((UInt32)1 << 28) - 1);
UInt32 abi = (flags >> 12) & 7;
if (abi != 0)
{
s += " ABI:";
s.Add_UInt32(abi);
}
flags &= ~((UInt32)7 << 12);
s.Add_Space();
s += FlagsToString(g_MIPS_Flags, ARRAY_SIZE(g_MIPS_Flags), flags);
} }
else else
{
char sz[16];
ConvertUInt32ToHex(flags, sz); ConvertUInt32ToHex(flags, sz);
s += sz; s += sz;
}
} }
prop = s; prop = s;
break; break;

View File

@@ -20,7 +20,6 @@
#include "../../../C/CpuArch.h" #include "../../../C/CpuArch.h"
#include "../../Common/ComTry.h" #include "../../Common/ComTry.h"
#include "../../Common/IntToString.h"
#include "../../Common/MyLinux.h" #include "../../Common/MyLinux.h"
#include "../../Common/StringConvert.h" #include "../../Common/StringConvert.h"
#include "../../Common/UTFConvert.h" #include "../../Common/UTFConvert.h"
@@ -37,6 +36,8 @@
using namespace NWindows; using namespace NWindows;
UInt32 LzhCrc16Update(UInt32 crc, const void *data, size_t size);
namespace NArchive { namespace NArchive {
namespace NExt { namespace NExt {
@@ -87,33 +88,9 @@ static UInt32 Crc32C_Calc(Byte const *data, size_t size)
*/ */
// CRC-16-ANSI. The poly is 0x8005 (x^16 + x^15 + x^2 + 1)
static UInt16 g_Crc16Table[256];
static struct CInitCrc16
{
CInitCrc16()
{
for (unsigned i = 0; i < 256; i++)
{
UInt32 r = i;
unsigned j;
for (j = 0; j < 8; j++)
r = (r >> 1) ^ (0xA001 & ~((r & 1) - 1));
g_Crc16Table[i] = (UInt16)r;
}
}
} g_InitCrc16;
#define CRC16_UPDATE_BYTE(crc, b) (g_Crc16Table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))
#define CRC16_INIT_VAL 0xFFFF #define CRC16_INIT_VAL 0xFFFF
static UInt32 Crc16Update(UInt32 crc, Byte const *data, size_t size) #define Crc16Update(crc, data, size) LzhCrc16Update(crc, data, size)
{
for (size_t i = 0; i < size; i++)
crc = CRC16_UPDATE_BYTE(crc, data[i]);
return crc;
}
static UInt32 Crc16Calc(Byte const *data, size_t size) static UInt32 Crc16Calc(Byte const *data, size_t size)
{ {
@@ -161,64 +138,64 @@ static const char * const kHostOS[] =
, "Lites" , "Lites"
}; };
static const CUInt32PCharPair g_FeatureCompat_Flags[] = static const char * const g_FeatureCompat_Flags[] =
{ {
{ 0, "DIR_PREALLOC" }, "DIR_PREALLOC"
{ 1, "IMAGIC_INODES" }, , "IMAGIC_INODES"
{ 2, "HAS_JOURNAL" }, , "HAS_JOURNAL"
{ 3, "EXT_ATTR" }, , "EXT_ATTR"
{ 4, "RESIZE_INODE" }, , "RESIZE_INODE"
{ 5, "DIR_INDEX" }, , "DIR_INDEX"
{ 6, "LAZY_BG" }, // not in Linux , "LAZY_BG" // not in Linux
// { 7, "EXCLUDE_INODE" }, // not used , NULL // { 7, "EXCLUDE_INODE" // not used
// { 8, "EXCLUDE_BITMAP" }, // not in kernel , NULL // { 8, "EXCLUDE_BITMAP" // not in kernel
{ 9, "SPARSE_SUPER2" } , "SPARSE_SUPER2"
}; };
#define EXT4_FEATURE_INCOMPAT_FILETYPE (1 << 1) #define EXT4_FEATURE_INCOMPAT_FILETYPE (1 << 1)
#define EXT4_FEATURE_INCOMPAT_64BIT (1 << 7) #define EXT4_FEATURE_INCOMPAT_64BIT (1 << 7)
static const CUInt32PCharPair g_FeatureIncompat_Flags[] = static const char * const g_FeatureIncompat_Flags[] =
{ {
{ 0, "COMPRESSION" }, "COMPRESSION"
{ 1, "FILETYPE" }, , "FILETYPE"
{ 2, "RECOVER" }, /* Needs recovery */ , "RECOVER" /* Needs recovery */
{ 3, "JOURNAL_DEV" }, /* Journal device */ , "JOURNAL_DEV" /* Journal device */
{ 4, "META_BG" }, , "META_BG"
, NULL
{ 6, "EXTENTS" }, /* extents support */ , "EXTENTS" /* extents support */
{ 7, "64BIT" }, , "64BIT"
{ 8, "MMP" }, , "MMP"
{ 9, "FLEX_BG" }, , "FLEX_BG"
{ 10, "EA_INODE" }, /* EA in inode */ , "EA_INODE" /* EA in inode */
, NULL
{ 12, "DIRDATA" }, /* data in dirent */ , "DIRDATA" /* data in dirent */
{ 13, "BG_USE_META_CSUM" }, /* use crc32c for bg */ , "BG_USE_META_CSUM" /* use crc32c for bg */
{ 14, "LARGEDIR" }, /* >2GB or 3-lvl htree */ , "LARGEDIR" /* >2GB or 3-lvl htree */
{ 15, "INLINE_DATA" }, /* data in inode */ , "INLINE_DATA" /* data in inode */
{ 16, "ENCRYPT" } , "ENCRYPT" // 16
}; };
static const UInt32 RO_COMPAT_GDT_CSUM = 1 << 4; static const UInt32 RO_COMPAT_GDT_CSUM = 1 << 4;
static const UInt32 RO_COMPAT_METADATA_CSUM = 1 << 10; static const UInt32 RO_COMPAT_METADATA_CSUM = 1 << 10;
static const CUInt32PCharPair g_FeatureRoCompat_Flags[] = static const char * const g_FeatureRoCompat_Flags[] =
{ {
{ 0, "SPARSE_SUPER" }, "SPARSE_SUPER"
{ 1, "LARGE_FILE" }, , "LARGE_FILE"
{ 2, "BTREE_DIR" }, , "BTREE_DIR"
{ 3, "HUGE_FILE" }, , "HUGE_FILE"
{ 4, "GDT_CSUM" }, , "GDT_CSUM"
{ 5, "DIR_NLINK" }, , "DIR_NLINK"
{ 6, "EXTRA_ISIZE" }, , "EXTRA_ISIZE"
{ 7, "HAS_SNAPSHOT" }, , "HAS_SNAPSHOT"
{ 8, "QUOTA" }, , "QUOTA"
{ 9, "BIGALLOC" }, , "BIGALLOC"
{ 10, "METADATA_CSUM" }, , "METADATA_CSUM"
{ 11, "REPLICA" }, , "REPLICA"
{ 12, "READONLY" } , "READONLY" // 12
}; };
@@ -227,33 +204,37 @@ static const UInt32 k_NodeFlags_HUGE = (UInt32)1 << 18;
static const UInt32 k_NodeFlags_EXTENTS = (UInt32)1 << 19; static const UInt32 k_NodeFlags_EXTENTS = (UInt32)1 << 19;
static const CUInt32PCharPair g_NodeFlags[] = static const char * const g_NodeFlags[] =
{ {
{ 0, "SECRM" }, "SECRM"
{ 1, "UNRM" }, , "UNRM"
{ 2, "COMPR" }, , "COMPR"
{ 3, "SYNC" }, , "SYNC"
{ 4, "IMMUTABLE" }, , "IMMUTABLE"
{ 5, "APPEND" }, , "APPEND"
{ 6, "NODUMP" }, , "NODUMP"
{ 7, "NOATIME" }, , "NOATIME"
{ 8, "DIRTY" }, , "DIRTY"
{ 9, "COMPRBLK" }, , "COMPRBLK"
{ 10, "NOCOMPR" }, , "NOCOMPR"
{ 11, "ENCRYPT" }, , "ENCRYPT"
{ 12, "INDEX" }, , "INDEX"
{ 13, "IMAGIC" }, , "IMAGIC"
{ 14, "JOURNAL_DATA" }, , "JOURNAL_DATA"
{ 15, "NOTAIL" }, , "NOTAIL"
{ 16, "DIRSYNC" }, , "DIRSYNC"
{ 17, "TOPDIR" }, , "TOPDIR"
{ 18, "HUGE_FILE" }, , "HUGE_FILE"
{ 19, "EXTENTS" }, , "EXTENTS"
, NULL
{ 21, "EA_INODE" }, , "EA_INODE"
{ 22, "EOFBLOCKS" }, , "EOFBLOCKS"
, NULL
{ 28, "INLINE_DATA" } , NULL
, NULL
, NULL
, NULL
, "INLINE_DATA" // 28
}; };
@@ -1540,20 +1521,16 @@ HRESULT CHandler::Open2(IInStream *inStream)
useUnknown = true; useUnknown = true;
if (item.Name.IsEmpty()) if (item.Name.IsEmpty())
{ item.Name.Add_UInt32(item.Node);
char temp[16];
ConvertUInt32ToString(item.Node, temp);
item.Name = temp;
}
_items.Add(item); _items.Add(item);
} }
} }
if (useSys) if (useSys)
_auxSysIndex = _auxItems.Add("[SYS]"); _auxSysIndex = _auxItems.Add((AString)"[SYS]");
if (useUnknown) if (useUnknown)
_auxUnknownIndex = _auxItems.Add("[UNKNOWN]"); _auxUnknownIndex = _auxItems.Add((AString)"[UNKNOWN]");
} }
return S_OK; return S_OK;
@@ -1834,16 +1811,7 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
case kpidHostOS: case kpidHostOS:
{ {
char temp[16]; TYPE_TO_PROP(kHostOS, _h.CreatorOs, prop);
const char *s = NULL;
if (_h.CreatorOs < ARRAY_SIZE(kHostOS))
s = kHostOS[_h.CreatorOs];
else
{
ConvertUInt32ToString(_h.CreatorOs, temp);
s = temp;
}
prop = s;
break; break;
} }
@@ -1995,39 +1963,34 @@ STDMETHODIMP CHandler::GetRawProp(UInt32 index, PROPID propID, const void **data
static void ExtTimeToProp(const CExtTime &t, NCOM::CPropVariant &prop) static void ExtTimeToProp(const CExtTime &t, NCOM::CPropVariant &prop)
{ {
/* if (t.Val == 0 && t.Extra == 0)
UInt32 nano = 0;
if (t.Extra != 0)
{
UInt32 mask = t.Extra & 3;
if (mask != 0)
return;
nano = t.Extra >> 2;
}
UInt64 v;
if (t.Val == 0 && nano == 0)
return; return;
if (!NTime::UnixTime_to_FileTime64(t.Val, v))
return;
if (nano != 0)
v += nano / 100;
FILETIME ft; FILETIME ft;
ft.dwLowDateTime = (DWORD)v; // if (t.Extra != 0)
ft.dwHighDateTime = (DWORD)(v >> 32);
prop = ft;
*/
if (t.Val == 0)
return;
if (t.Extra != 0)
{ {
UInt32 mask = t.Extra & 3; // 1901-2446 :
if (mask != 0) Int64 v = (Int64)(Int32)t.Val;
return; v += (UInt64)(t.Extra & 3) << 32; // 2 low bits are offset for main timestamp
UInt64 ft64 = NTime::UnixTime64ToFileTime64(v);
const UInt32 ns = (t.Extra >> 2);
if (ns < 1000000000)
ft64 += ns / 100;
ft.dwLowDateTime = (DWORD)ft64;
ft.dwHighDateTime = (DWORD)(ft64 >> 32);
} }
FILETIME ft; /*
if (NTime::UnixTime64ToFileTime(t.Val, ft)) else
prop = ft; {
// 1901-2038 : that code is good for ext4 and compatibility with Extra
NTime::UnixTime64ToFileTime((Int32)t.Val, ft); // for
// 1970-2106 : that code is good if timestamp is used as unsigned 32-bit
// are there such systems?
// NTime::UnixTimeToFileTime(t.Val, ft); // for
}
*/
prop = ft;
} }
@@ -2043,8 +2006,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
case kpidPath: case kpidPath:
case kpidName: case kpidName:
{ {
AString s = _auxItems[index - _items.Size()]; prop = _auxItems[index - _items.Size()];
prop = s;
break; break;
} }
case kpidIsDir: prop = true; break; case kpidIsDir: prop = true; break;

Some files were not shown because too many files have changed in this diff Show More