win32: readd 7z headers and fix 2008 build

This commit is contained in:
zeromus 2009-11-15 05:19:23 +00:00
parent 3b5ee1f29f
commit d1c1aa9f7e
194 changed files with 14678 additions and 6 deletions

View File

@ -0,0 +1,24 @@
/* 7zCrc.h -- CRC32 calculation
2008-03-13
Igor Pavlov
Public domain */
#ifndef __7Z_CRC_H
#define __7Z_CRC_H
#include <stddef.h>
#include "Types.h"
extern UInt32 g_CrcTable[];
void MY_FAST_CALL CrcGenerateTable(void);
#define CRC_INIT_VAL 0xFFFFFFFF
#define CRC_GET_DIGEST(crc) ((crc) ^ 0xFFFFFFFF)
#define CRC_UPDATE_BYTE(crc, b) (g_CrcTable[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))
UInt32 MY_FAST_CALL CrcUpdate(UInt32 crc, const void *data, size_t size);
UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size);
#endif

View File

@ -0,0 +1,48 @@
/* Aes.h -- AES encryption / decryption
2008-08-05
Igor Pavlov
Public domain */
#ifndef __AES_H
#define __AES_H
#include "Types.h"
#define AES_BLOCK_SIZE 16
typedef struct
{
unsigned numRounds2; /* = numRounds / 2 */
UInt32 rkey[(14 + 1) * 4];
} CAes;
/* Call AesGenTables one time before other AES functions */
void AesGenTables(void);
/* keySize = 16 or 24 or 32 (bytes) */
void Aes_SetKeyEncode(CAes *p, const Byte *key, unsigned keySize);
void Aes_SetKeyDecode(CAes *p, const Byte *key, unsigned keySize);
/* Aes_Encode32 and Aes_Decode32 functions work with little-endian words.
src and dest are pointers to 4 UInt32 words.
arc and dest can point to same block */
void Aes_Encode32(const CAes *p, UInt32 *dest, const UInt32 *src);
void Aes_Decode32(const CAes *p, UInt32 *dest, const UInt32 *src);
typedef struct
{
UInt32 prev[4];
CAes aes;
} CAesCbc;
void AesCbc_Init(CAesCbc *p, const Byte *iv); /* iv size is AES_BLOCK_SIZE */
/* AesCbc_Encode and AesCbc_Decode:
if (res <= size): Filter have converted res bytes
if (res > size): Filter have not converted anything. And it needs at
least res = AES_BLOCK_SIZE bytes to convert one block */
SizeT AesCbc_Encode(CAesCbc *p, Byte *data, SizeT size);
SizeT AesCbc_Decode(CAesCbc *p, Byte *data, SizeT size);
#endif

View File

@ -0,0 +1,32 @@
/* Alloc.h -- Memory allocation functions
2008-03-13
Igor Pavlov
Public domain */
#ifndef __COMMON_ALLOC_H
#define __COMMON_ALLOC_H
#include <stddef.h>
void *MyAlloc(size_t size);
void MyFree(void *address);
#ifdef _WIN32
void SetLargePageSize();
void *MidAlloc(size_t size);
void MidFree(void *address);
void *BigAlloc(size_t size);
void BigFree(void *address);
#else
#define MidAlloc(size) MyAlloc(size)
#define MidFree(address) MyFree(address)
#define BigAlloc(size) MyAlloc(size)
#define BigFree(address) MyFree(address)
#endif
#endif

View File

@ -0,0 +1,60 @@
/* Bra.h -- Branch converters for executables
2008-10-04 : Igor Pavlov : Public domain */
#ifndef __BRA_H
#define __BRA_H
#include "Types.h"
/*
These functions convert relative addresses to absolute addresses
in CALL instructions to increase the compression ratio.
In:
data - data buffer
size - size of data
ip - current virtual Instruction Pinter (IP) value
state - state variable for x86 converter
encoding - 0 (for decoding), 1 (for encoding)
Out:
state - state variable for x86 converter
Returns:
The number of processed bytes. If you call these functions with multiple calls,
you must start next call with first byte after block of processed bytes.
Type Endian Alignment LookAhead
x86 little 1 4
ARMT little 2 2
ARM little 4 0
PPC big 4 0
SPARC big 4 0
IA64 little 16 0
size must be >= Alignment + LookAhead, if it's not last block.
If (size < Alignment + LookAhead), converter returns 0.
Example:
UInt32 ip = 0;
for ()
{
; size must be >= Alignment + LookAhead, if it's not last block
SizeT processed = Convert(data, size, ip, 1);
data += processed;
size -= processed;
ip += processed;
}
*/
#define x86_Convert_Init(state) { state = 0; }
SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding);
SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
#endif

View File

@ -0,0 +1,24 @@
/* BwtSort.h -- BWT block sorting
2008-03-26
Igor Pavlov
Public domain */
#ifndef __BWTSORT_H
#define __BWTSORT_H
#include "Types.h"
/* use BLOCK_SORT_EXTERNAL_FLAGS if blockSize can be > 1M */
/* #define BLOCK_SORT_EXTERNAL_FLAGS */
#ifdef BLOCK_SORT_EXTERNAL_FLAGS
#define BLOCK_SORT_EXTERNAL_SIZE(blockSize) ((((blockSize) + 31) >> 5))
#else
#define BLOCK_SORT_EXTERNAL_SIZE(blockSize) 0
#endif
#define BLOCK_SORT_BUF_SIZE(blockSize) ((blockSize) * 2 + BLOCK_SORT_EXTERNAL_SIZE(blockSize) + (1 << 16))
UInt32 BlockSort(UInt32 *indices, const Byte *data, UInt32 blockSize);
#endif

View File

@ -0,0 +1,69 @@
/* CpuArch.h
2008-08-05
Igor Pavlov
Public domain */
#ifndef __CPUARCH_H
#define __CPUARCH_H
/*
LITTLE_ENDIAN_UNALIGN means:
1) CPU is LITTLE_ENDIAN
2) it's allowed to make unaligned memory accesses
if LITTLE_ENDIAN_UNALIGN is not defined, it means that we don't know
about these properties of platform.
*/
#if defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || defined(__i386__) || defined(__x86_64__)
#define LITTLE_ENDIAN_UNALIGN
#endif
#ifdef LITTLE_ENDIAN_UNALIGN
#define GetUi16(p) (*(const UInt16 *)(p))
#define GetUi32(p) (*(const UInt32 *)(p))
#define GetUi64(p) (*(const UInt64 *)(p))
#define SetUi32(p, d) *(UInt32 *)(p) = (d);
#else
#define GetUi16(p) (((const Byte *)(p))[0] | ((UInt16)((const Byte *)(p))[1] << 8))
#define GetUi32(p) ( \
((const Byte *)(p))[0] | \
((UInt32)((const Byte *)(p))[1] << 8) | \
((UInt32)((const Byte *)(p))[2] << 16) | \
((UInt32)((const Byte *)(p))[3] << 24))
#define GetUi64(p) (GetUi32(p) | ((UInt64)GetUi32(((const Byte *)(p)) + 4) << 32))
#define SetUi32(p, d) { UInt32 _x_ = (d); \
((Byte *)(p))[0] = (Byte)_x_; \
((Byte *)(p))[1] = (Byte)(_x_ >> 8); \
((Byte *)(p))[2] = (Byte)(_x_ >> 16); \
((Byte *)(p))[3] = (Byte)(_x_ >> 24); }
#endif
#if defined(LITTLE_ENDIAN_UNALIGN) && defined(_WIN64) && (_MSC_VER >= 1300)
#pragma intrinsic(_byteswap_ulong)
#pragma intrinsic(_byteswap_uint64)
#define GetBe32(p) _byteswap_ulong(*(const UInt32 *)(const Byte *)(p))
#define GetBe64(p) _byteswap_uint64(*(const UInt64 *)(const Byte *)(p))
#else
#define GetBe32(p) ( \
((UInt32)((const Byte *)(p))[0] << 24) | \
((UInt32)((const Byte *)(p))[1] << 16) | \
((UInt32)((const Byte *)(p))[2] << 8) | \
((const Byte *)(p))[3] )
#define GetBe64(p) (((UInt64)GetBe32(p) << 32) | GetBe32(((const Byte *)(p)) + 4))
#endif
#define GetBe16(p) (((UInt16)((const Byte *)(p))[0] << 8) | ((const Byte *)(p))[1])
#endif

View File

@ -0,0 +1,21 @@
/* HuffEnc.h -- functions for Huffman encoding
2008-03-26
Igor Pavlov
Public domain */
#ifndef __HUFFENC_H
#define __HUFFENC_H
#include "Types.h"
/*
Conditions:
num <= 1024 = 2 ^ NUM_BITS
Sum(freqs) < 4M = 2 ^ (32 - NUM_BITS)
maxLen <= 16 = kMaxLen
Num_Items(p) >= HUFFMAN_TEMP_SIZE(num)
*/
void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 num, UInt32 maxLen);
#endif

View File

@ -0,0 +1,107 @@
/* LzFind.h -- Match finder for LZ algorithms
2008-10-04 : Igor Pavlov : Public domain */
#ifndef __LZFIND_H
#define __LZFIND_H
#include "Types.h"
typedef UInt32 CLzRef;
typedef struct _CMatchFinder
{
Byte *buffer;
UInt32 pos;
UInt32 posLimit;
UInt32 streamPos;
UInt32 lenLimit;
UInt32 cyclicBufferPos;
UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */
UInt32 matchMaxLen;
CLzRef *hash;
CLzRef *son;
UInt32 hashMask;
UInt32 cutValue;
Byte *bufferBase;
ISeqInStream *stream;
int streamEndWasReached;
UInt32 blockSize;
UInt32 keepSizeBefore;
UInt32 keepSizeAfter;
UInt32 numHashBytes;
int directInput;
int btMode;
/* int skipModeBits; */
int bigHash;
UInt32 historySize;
UInt32 fixedHashSize;
UInt32 hashSizeSum;
UInt32 numSons;
SRes result;
UInt32 crc[256];
} CMatchFinder;
#define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)
#define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(Int32)(index)])
#define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)
int MatchFinder_NeedMove(CMatchFinder *p);
Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);
void MatchFinder_MoveBlock(CMatchFinder *p);
void MatchFinder_ReadIfRequired(CMatchFinder *p);
void MatchFinder_Construct(CMatchFinder *p);
/* Conditions:
historySize <= 3 GB
keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB
*/
int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
ISzAlloc *alloc);
void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc);
void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems);
void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);
UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,
UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
UInt32 *distances, UInt32 maxLen);
/*
Conditions:
Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.
Mf_GetPointerToCurrentPos_Func's result must be used only before any other function
*/
typedef void (*Mf_Init_Func)(void *object);
typedef Byte (*Mf_GetIndexByte_Func)(void *object, Int32 index);
typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object);
typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object);
typedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances);
typedef void (*Mf_Skip_Func)(void *object, UInt32);
typedef struct _IMatchFinder
{
Mf_Init_Func Init;
Mf_GetIndexByte_Func GetIndexByte;
Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;
Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;
Mf_GetMatches_Func GetMatches;
Mf_Skip_Func Skip;
} IMatchFinder;
void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);
void MatchFinder_Init(CMatchFinder *p);
UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
#endif

View File

@ -0,0 +1,97 @@
/* LzFindMt.h -- multithreaded Match finder for LZ algorithms
2008-10-04 : Igor Pavlov : Public domain */
#ifndef __LZFINDMT_H
#define __LZFINDMT_H
#include "Threads.h"
#include "LzFind.h"
#define kMtHashBlockSize (1 << 13)
#define kMtHashNumBlocks (1 << 3)
#define kMtHashNumBlocksMask (kMtHashNumBlocks - 1)
#define kMtBtBlockSize (1 << 14)
#define kMtBtNumBlocks (1 << 6)
#define kMtBtNumBlocksMask (kMtBtNumBlocks - 1)
typedef struct _CMtSync
{
Bool wasCreated;
Bool needStart;
Bool exit;
Bool stopWriting;
CThread thread;
CAutoResetEvent canStart;
CAutoResetEvent wasStarted;
CAutoResetEvent wasStopped;
CSemaphore freeSemaphore;
CSemaphore filledSemaphore;
Bool csWasInitialized;
Bool csWasEntered;
CCriticalSection cs;
UInt32 numProcessedBlocks;
} CMtSync;
typedef UInt32 * (*Mf_Mix_Matches)(void *p, UInt32 matchMinPos, UInt32 *distances);
/* kMtCacheLineDummy must be >= size_of_CPU_cache_line */
#define kMtCacheLineDummy 128
typedef void (*Mf_GetHeads)(const Byte *buffer, UInt32 pos,
UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc);
typedef struct _CMatchFinderMt
{
/* LZ */
const Byte *pointerToCurPos;
UInt32 *btBuf;
UInt32 btBufPos;
UInt32 btBufPosLimit;
UInt32 lzPos;
UInt32 btNumAvailBytes;
UInt32 *hash;
UInt32 fixedHashSize;
UInt32 historySize;
const UInt32 *crc;
Mf_Mix_Matches MixMatchesFunc;
/* LZ + BT */
CMtSync btSync;
Byte btDummy[kMtCacheLineDummy];
/* BT */
UInt32 *hashBuf;
UInt32 hashBufPos;
UInt32 hashBufPosLimit;
UInt32 hashNumAvail;
CLzRef *son;
UInt32 matchMaxLen;
UInt32 numHashBytes;
UInt32 pos;
Byte *buffer;
UInt32 cyclicBufferPos;
UInt32 cyclicBufferSize; /* it must be historySize + 1 */
UInt32 cutValue;
/* BT + Hash */
CMtSync hashSync;
/* Byte hashDummy[kMtCacheLineDummy]; */
/* Hash */
Mf_GetHeads GetHeadsFunc;
CMatchFinder *MatchFinder;
} CMatchFinderMt;
void MatchFinderMt_Construct(CMatchFinderMt *p);
void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc);
SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,
UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc);
void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable);
void MatchFinderMt_ReleaseStream(CMatchFinderMt *p);
#endif

View File

@ -0,0 +1,54 @@
/* LzHash.h -- HASH functions for LZ algorithms
2008-10-04 : Igor Pavlov : Public domain */
#ifndef __LZHASH_H
#define __LZHASH_H
#define kHash2Size (1 << 10)
#define kHash3Size (1 << 16)
#define kHash4Size (1 << 20)
#define kFix3HashSize (kHash2Size)
#define kFix4HashSize (kHash2Size + kHash3Size)
#define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)
#define HASH2_CALC hashValue = cur[0] | ((UInt32)cur[1] << 8);
#define HASH3_CALC { \
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
hash2Value = temp & (kHash2Size - 1); \
hashValue = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; }
#define HASH4_CALC { \
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
hash2Value = temp & (kHash2Size - 1); \
hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
hashValue = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & p->hashMask; }
#define HASH5_CALC { \
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
hash2Value = temp & (kHash2Size - 1); \
hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)); \
hashValue = (hash4Value ^ (p->crc[cur[4]] << 3)) & p->hashMask; \
hash4Value &= (kHash4Size - 1); }
/* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */
#define HASH_ZIP_CALC hashValue = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;
#define MT_HASH2_CALC \
hash2Value = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1);
#define MT_HASH3_CALC { \
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
hash2Value = temp & (kHash2Size - 1); \
hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }
#define MT_HASH4_CALC { \
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
hash2Value = temp & (kHash2Size - 1); \
hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); }
#endif

View File

@ -0,0 +1,223 @@
/* LzmaDec.h -- LZMA Decoder
2008-10-04 : Igor Pavlov : Public domain */
#ifndef __LZMADEC_H
#define __LZMADEC_H
#include "Types.h"
/* #define _LZMA_PROB32 */
/* _LZMA_PROB32 can increase the speed on some CPUs,
but memory usage for CLzmaDec::probs will be doubled in that case */
#ifdef _LZMA_PROB32
#define CLzmaProb UInt32
#else
#define CLzmaProb UInt16
#endif
/* ---------- LZMA Properties ---------- */
#define LZMA_PROPS_SIZE 5
typedef struct _CLzmaProps
{
unsigned lc, lp, pb;
UInt32 dicSize;
} CLzmaProps;
/* LzmaProps_Decode - decodes properties
Returns:
SZ_OK
SZ_ERROR_UNSUPPORTED - Unsupported properties
*/
SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);
/* ---------- LZMA Decoder state ---------- */
/* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case.
Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */
#define LZMA_REQUIRED_INPUT_MAX 20
typedef struct
{
CLzmaProps prop;
CLzmaProb *probs;
Byte *dic;
const Byte *buf;
UInt32 range, code;
SizeT dicPos;
SizeT dicBufSize;
UInt32 processedPos;
UInt32 checkDicSize;
unsigned state;
UInt32 reps[4];
unsigned remainLen;
int needFlush;
int needInitState;
UInt32 numProbs;
unsigned tempBufSize;
Byte tempBuf[LZMA_REQUIRED_INPUT_MAX];
} CLzmaDec;
#define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; }
void LzmaDec_Init(CLzmaDec *p);
/* There are two types of LZMA streams:
0) Stream with end mark. That end mark adds about 6 bytes to compressed size.
1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */
typedef enum
{
LZMA_FINISH_ANY, /* finish at any point */
LZMA_FINISH_END /* block must be finished at the end */
} ELzmaFinishMode;
/* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!
You must use LZMA_FINISH_END, when you know that current output buffer
covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.
If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,
and output value of destLen will be less than output buffer size limit.
You can check status result also.
You can use multiple checks to test data integrity after full decompression:
1) Check Result and "status" variable.
2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.
3) Check that output(srcLen) = compressedSize, if you know real compressedSize.
You must use correct finish mode in that case. */
typedef enum
{
LZMA_STATUS_NOT_SPECIFIED, /* use main error code instead */
LZMA_STATUS_FINISHED_WITH_MARK, /* stream was finished with end mark. */
LZMA_STATUS_NOT_FINISHED, /* stream was not finished */
LZMA_STATUS_NEEDS_MORE_INPUT, /* you must provide more input bytes */
LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK /* there is probability that stream was finished without end mark */
} ELzmaStatus;
/* ELzmaStatus is used only as output value for function call */
/* ---------- Interfaces ---------- */
/* There are 3 levels of interfaces:
1) Dictionary Interface
2) Buffer Interface
3) One Call Interface
You can select any of these interfaces, but don't mix functions from different
groups for same object. */
/* There are two variants to allocate state for Dictionary Interface:
1) LzmaDec_Allocate / LzmaDec_Free
2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs
You can use variant 2, if you set dictionary buffer manually.
For Buffer Interface you must always use variant 1.
LzmaDec_Allocate* can return:
SZ_OK
SZ_ERROR_MEM - Memory allocation error
SZ_ERROR_UNSUPPORTED - Unsupported properties
*/
SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc);
void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc);
SRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc);
void LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc);
/* ---------- Dictionary Interface ---------- */
/* You can use it, if you want to eliminate the overhead for data copying from
dictionary to some other external buffer.
You must work with CLzmaDec variables directly in this interface.
STEPS:
LzmaDec_Constr()
LzmaDec_Allocate()
for (each new stream)
{
LzmaDec_Init()
while (it needs more decompression)
{
LzmaDec_DecodeToDic()
use data from CLzmaDec::dic and update CLzmaDec::dicPos
}
}
LzmaDec_Free()
*/
/* LzmaDec_DecodeToDic
The decoding to internal dictionary buffer (CLzmaDec::dic).
You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!
finishMode:
It has meaning only if the decoding reaches output limit (dicLimit).
LZMA_FINISH_ANY - Decode just dicLimit bytes.
LZMA_FINISH_END - Stream must be finished after dicLimit.
Returns:
SZ_OK
status:
LZMA_STATUS_FINISHED_WITH_MARK
LZMA_STATUS_NOT_FINISHED
LZMA_STATUS_NEEDS_MORE_INPUT
LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
SZ_ERROR_DATA - Data error
*/
SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,
const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
/* ---------- Buffer Interface ---------- */
/* It's zlib-like interface.
See LzmaDec_DecodeToDic description for information about STEPS and return results,
but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need
to work with CLzmaDec variables manually.
finishMode:
It has meaning only if the decoding reaches output limit (*destLen).
LZMA_FINISH_ANY - Decode just destLen bytes.
LZMA_FINISH_END - Stream must be finished after (*destLen).
*/
SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,
const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
/* ---------- One Call Interface ---------- */
/* LzmaDecode
finishMode:
It has meaning only if the decoding reaches output limit (*destLen).
LZMA_FINISH_ANY - Decode just destLen bytes.
LZMA_FINISH_END - Stream must be finished after (*destLen).
Returns:
SZ_OK
status:
LZMA_STATUS_FINISHED_WITH_MARK
LZMA_STATUS_NOT_FINISHED
LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
SZ_ERROR_DATA - Data error
SZ_ERROR_MEM - Memory allocation error
SZ_ERROR_UNSUPPORTED - Unsupported properties
SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
*/
SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
ELzmaStatus *status, ISzAlloc *alloc);
#endif

View File

@ -0,0 +1,72 @@
/* LzmaEnc.h -- LZMA Encoder
2008-10-04 : Igor Pavlov : Public domain */
#ifndef __LZMAENC_H
#define __LZMAENC_H
#include "Types.h"
#define LZMA_PROPS_SIZE 5
typedef struct _CLzmaEncProps
{
int level; /* 0 <= level <= 9 */
UInt32 dictSize; /* (1 << 12) <= dictSize <= (1 << 27) for 32-bit version
(1 << 12) <= dictSize <= (1 << 30) for 64-bit version
default = (1 << 24) */
int lc; /* 0 <= lc <= 8, default = 3 */
int lp; /* 0 <= lp <= 4, default = 0 */
int pb; /* 0 <= pb <= 4, default = 2 */
int algo; /* 0 - fast, 1 - normal, default = 1 */
int fb; /* 5 <= fb <= 273, default = 32 */
int btMode; /* 0 - hashChain Mode, 1 - binTree mode - normal, default = 1 */
int numHashBytes; /* 2, 3 or 4, default = 4 */
UInt32 mc; /* 1 <= mc <= (1 << 30), default = 32 */
unsigned writeEndMark; /* 0 - do not write EOPM, 1 - write EOPM, default = 0 */
int numThreads; /* 1 or 2, default = 2 */
} CLzmaEncProps;
void LzmaEncProps_Init(CLzmaEncProps *p);
void LzmaEncProps_Normalize(CLzmaEncProps *p);
UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2);
/* ---------- CLzmaEncHandle Interface ---------- */
/* LzmaEnc_* functions can return the following exit codes:
Returns:
SZ_OK - OK
SZ_ERROR_MEM - Memory allocation error
SZ_ERROR_PARAM - Incorrect paramater in props
SZ_ERROR_WRITE - Write callback error.
SZ_ERROR_PROGRESS - some break from progress callback
SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
*/
typedef void * CLzmaEncHandle;
CLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc);
void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig);
SRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props);
SRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size);
SRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream,
ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
SRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
/* ---------- One Call Interface ---------- */
/* LzmaEncode
Return code:
SZ_OK - OK
SZ_ERROR_MEM - Memory allocation error
SZ_ERROR_PARAM - Incorrect paramater
SZ_ERROR_OUTPUT_EOF - output buffer overflow
SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
*/
SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
#endif

View File

@ -0,0 +1,22 @@
/* RotateDefs.h -- Rotate functions
2008-08-05
Igor Pavlov
Public domain */
#ifndef __ROTATEDEFS_H
#define __ROTATEDEFS_H
#ifdef _MSC_VER
#include <stdlib.h>
#define rotlFixed(x, n) _rotl((x), (n))
#define rotrFixed(x, n) _rotr((x), (n))
#else
#define rotlFixed(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
#define rotrFixed(x, n) (((x) >> (n)) | ((x) << (32 - (n))))
#endif
#endif

View File

@ -0,0 +1,22 @@
/* Crypto/Sha256.h -- SHA-256 Hash function
2008-10-04 : Igor Pavlov : Public domain */
#ifndef __CRYPTO_SHA256_H
#define __CRYPTO_SHA256_H
#include "Types.h"
#define SHA256_DIGEST_SIZE 32
typedef struct
{
UInt32 state[8];
UInt64 count;
Byte buffer[64];
} CSha256;
void Sha256_Init(CSha256 *p);
void Sha256_Update(CSha256 *p, const Byte *data, size_t size);
void Sha256_Final(CSha256 *p, Byte *digest);
#endif

View File

@ -0,0 +1,14 @@
/* Sort.h -- Sort functions
2008-03-19
Igor Pavlov
Public domain */
#ifndef __7Z_SORT_H
#define __7Z_SORT_H
#include "Types.h"
void HeapSort(UInt32 *p, UInt32 size);
/* void HeapSortRef(UInt32 *p, UInt32 *vals, UInt32 size); */
#endif

View File

@ -0,0 +1,68 @@
/* Threads.h -- multithreading library
2008-11-22 : Igor Pavlov : Public domain */
#ifndef __7Z_THRESDS_H
#define __7Z_THRESDS_H
#include "Types.h"
typedef struct _CThread
{
HANDLE handle;
} CThread;
#define Thread_Construct(thread) (thread)->handle = NULL
#define Thread_WasCreated(thread) ((thread)->handle != NULL)
typedef unsigned THREAD_FUNC_RET_TYPE;
#define THREAD_FUNC_CALL_TYPE MY_STD_CALL
#define THREAD_FUNC_DECL THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE
WRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter);
WRes Thread_Wait(CThread *thread);
WRes Thread_Close(CThread *thread);
typedef struct _CEvent
{
HANDLE handle;
} CEvent;
typedef CEvent CAutoResetEvent;
typedef CEvent CManualResetEvent;
#define Event_Construct(event) (event)->handle = NULL
#define Event_IsCreated(event) ((event)->handle != NULL)
WRes ManualResetEvent_Create(CManualResetEvent *event, int initialSignaled);
WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *event);
WRes AutoResetEvent_Create(CAutoResetEvent *event, int initialSignaled);
WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *event);
WRes Event_Set(CEvent *event);
WRes Event_Reset(CEvent *event);
WRes Event_Wait(CEvent *event);
WRes Event_Close(CEvent *event);
typedef struct _CSemaphore
{
HANDLE handle;
} CSemaphore;
#define Semaphore_Construct(p) (p)->handle = NULL
WRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount);
WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num);
WRes Semaphore_Release1(CSemaphore *p);
WRes Semaphore_Wait(CSemaphore *p);
WRes Semaphore_Close(CSemaphore *p);
typedef CRITICAL_SECTION CCriticalSection;
WRes CriticalSection_Init(CCriticalSection *p);
#define CriticalSection_Delete(p) DeleteCriticalSection(p)
#define CriticalSection_Enter(p) EnterCriticalSection(p)
#define CriticalSection_Leave(p) LeaveCriticalSection(p)
#endif

View File

@ -0,0 +1,208 @@
/* Types.h -- Basic types
2008-11-23 : Igor Pavlov : Public domain */
#ifndef __7Z_TYPES_H
#define __7Z_TYPES_H
#include <stddef.h>
#ifdef _WIN32
#include <windows.h>
#endif
#define SZ_OK 0
#define SZ_ERROR_DATA 1
#define SZ_ERROR_MEM 2
#define SZ_ERROR_CRC 3
#define SZ_ERROR_UNSUPPORTED 4
#define SZ_ERROR_PARAM 5
#define SZ_ERROR_INPUT_EOF 6
#define SZ_ERROR_OUTPUT_EOF 7
#define SZ_ERROR_READ 8
#define SZ_ERROR_WRITE 9
#define SZ_ERROR_PROGRESS 10
#define SZ_ERROR_FAIL 11
#define SZ_ERROR_THREAD 12
#define SZ_ERROR_ARCHIVE 16
#define SZ_ERROR_NO_ARCHIVE 17
typedef int SRes;
#ifdef _WIN32
typedef DWORD WRes;
#else
typedef int WRes;
#endif
#ifndef RINOK
#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
#endif
typedef unsigned char Byte;
typedef short Int16;
typedef unsigned short UInt16;
#ifdef _LZMA_UINT32_IS_ULONG
typedef long Int32;
typedef unsigned long UInt32;
#else
typedef int Int32;
typedef unsigned int UInt32;
#endif
#ifdef _SZ_NO_INT_64
/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.
NOTES: Some code will work incorrectly in that case! */
typedef long Int64;
typedef unsigned long UInt64;
#else
#if defined(_MSC_VER) || defined(__BORLANDC__)
typedef __int64 Int64;
typedef unsigned __int64 UInt64;
#else
typedef long long int Int64;
typedef unsigned long long int UInt64;
#endif
#endif
#ifdef _LZMA_NO_SYSTEM_SIZE_T
typedef UInt32 SizeT;
#else
typedef size_t SizeT;
#endif
typedef int Bool;
#define True 1
#define False 0
#ifdef _MSC_VER
#if _MSC_VER >= 1300
#define MY_NO_INLINE __declspec(noinline)
#else
#define MY_NO_INLINE
#endif
#define MY_CDECL __cdecl
#define MY_STD_CALL __stdcall
#define MY_FAST_CALL MY_NO_INLINE __fastcall
#else
#define MY_CDECL
#define MY_STD_CALL
#define MY_FAST_CALL
#endif
/* The following interfaces use first parameter as pointer to structure */
typedef struct
{
SRes (*Read)(void *p, void *buf, size_t *size);
/* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
(output(*size) < input(*size)) is allowed */
} ISeqInStream;
/* it can return SZ_ERROR_INPUT_EOF */
SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);
SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);
SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf);
typedef struct
{
size_t (*Write)(void *p, const void *buf, size_t size);
/* Returns: result - the number of actually written bytes.
(result < size) means error */
} ISeqOutStream;
typedef enum
{
SZ_SEEK_SET = 0,
SZ_SEEK_CUR = 1,
SZ_SEEK_END = 2
} 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
{
SRes (*Look)(void *p, void **buf, size_t *size);
/* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
(output(*size) > input(*size)) is not allowed
(output(*size) < input(*size)) is allowed */
SRes (*Skip)(void *p, size_t offset);
/* offset must be <= output(*size) of Look */
SRes (*Read)(void *p, void *buf, size_t *size);
/* reads directly (without buffer). It's same as ISeqInStream::Read */
SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
} ILookInStream;
SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);
SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);
/* reads via ILookInStream::Read */
SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);
SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);
#define LookToRead_BUF_SIZE (1 << 14)
typedef struct
{
ILookInStream s;
ISeekInStream *realStream;
size_t pos;
size_t size;
Byte buf[LookToRead_BUF_SIZE];
} CLookToRead;
void LookToRead_CreateVTable(CLookToRead *p, int lookahead);
void LookToRead_Init(CLookToRead *p);
typedef struct
{
ISeqInStream s;
ILookInStream *realStream;
} CSecToLook;
void SecToLook_CreateVTable(CSecToLook *p);
typedef struct
{
ISeqInStream s;
ILookInStream *realStream;
} CSecToRead;
void SecToRead_CreateVTable(CSecToRead *p);
typedef struct
{
SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);
/* Returns: result. (result != SZ_OK) means break.
Value (UInt64)(Int64)-1 for size means unknown value. */
} ICompressProgress;
typedef struct
{
void *(*Alloc)(void *p, size_t size);
void (*Free)(void *p, void *address); /* address can be 0 */
} ISzAlloc;
#define IAlloc_Alloc(p, size) (p)->Alloc((p), size)
#define IAlloc_Free(p, a) (p)->Free((p), a)
#endif

View File

@ -0,0 +1,50 @@
// 7zCompressionMode.h
#ifndef __7Z_COMPRESSION_MODE_H
#define __7Z_COMPRESSION_MODE_H
#include "../../../Common/MyString.h"
#include "../../../Windows/PropVariant.h"
#include "../../Common/MethodProps.h"
namespace NArchive {
namespace N7z {
struct CMethodFull: public CMethod
{
UInt32 NumInStreams;
UInt32 NumOutStreams;
bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); }
};
struct CBind
{
UInt32 InCoder;
UInt32 InStream;
UInt32 OutCoder;
UInt32 OutStream;
};
struct CCompressionMethodMode
{
CObjectVector<CMethodFull> Methods;
CRecordVector<CBind> Binds;
#ifdef COMPRESS_MT
UInt32 NumThreads;
#endif
bool PasswordIsDefined;
UString Password;
bool IsEmpty() const { return (Methods.IsEmpty() && !PasswordIsDefined); }
CCompressionMethodMode(): PasswordIsDefined(false)
#ifdef COMPRESS_MT
, NumThreads(1)
#endif
{}
};
}}
#endif

View File

@ -0,0 +1,68 @@
// 7zDecode.h
#ifndef __7Z_DECODE_H
#define __7Z_DECODE_H
#include "../../IStream.h"
#include "../../IPassword.h"
#include "../Common/CoderMixer2.h"
#include "../Common/CoderMixer2MT.h"
#ifdef _ST_MODE
#include "../Common/CoderMixer2ST.h"
#endif
#include "../../Common/CreateCoder.h"
#include "7zItem.h"
namespace NArchive {
namespace N7z {
struct CBindInfoEx: public NCoderMixer::CBindInfo
{
CRecordVector<CMethodId> CoderMethodIDs;
void Clear()
{
CBindInfo::Clear();
CoderMethodIDs.Clear();
}
};
class CDecoder
{
bool _bindInfoExPrevIsDefined;
CBindInfoEx _bindInfoExPrev;
bool _multiThread;
#ifdef _ST_MODE
NCoderMixer::CCoderMixer2ST *_mixerCoderSTSpec;
#endif
NCoderMixer::CCoderMixer2MT *_mixerCoderMTSpec;
NCoderMixer::CCoderMixer2 *_mixerCoderCommon;
CMyComPtr<ICompressCoder2> _mixerCoder;
CObjectVector<CMyComPtr<IUnknown> > _decoders;
// CObjectVector<CMyComPtr<ICompressCoder2> > _decoders2;
public:
CDecoder(bool multiThread);
HRESULT Decode(
DECL_EXTERNAL_CODECS_LOC_VARS
IInStream *inStream,
UInt64 startPos,
const UInt64 *packSizes,
const CFolder &folder,
ISequentialOutStream *outStream,
ICompressProgressInfo *compressProgress
#ifndef _NO_CRYPTO
, ICryptoGetTextPassword *getTextPasswordSpec, bool &passwordIsDefined
#endif
#ifdef COMPRESS_MT
, bool mtMode, UInt32 numThreads
#endif
);
};
}}
#endif

View File

@ -0,0 +1,66 @@
// 7z/FolderInStream.h
#ifndef __7Z_FOLDERINSTREAM_H
#define __7Z_FOLDERINSTREAM_H
#include "7zItem.h"
#include "7zHeader.h"
#include "../IArchive.h"
#include "../Common/InStreamWithCRC.h"
#include "../../IStream.h"
#include "../../ICoder.h"
namespace NArchive {
namespace N7z {
class CFolderInStream:
public ISequentialInStream,
public ICompressGetSubStreamSize,
public CMyUnknownImp
{
public:
MY_UNKNOWN_IMP1(ICompressGetSubStreamSize)
CFolderInStream();
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value);
private:
CSequentialInStreamWithCRC *_inStreamWithHashSpec;
CMyComPtr<ISequentialInStream> _inStreamWithHash;
CMyComPtr<IArchiveUpdateCallback> _updateCallback;
bool _currentSizeIsDefined;
UInt64 _currentSize;
bool _fileIsOpen;
UInt64 _filePos;
const UInt32 *_fileIndices;
UInt32 _numFiles;
UInt32 _fileIndex;
HRESULT OpenStream();
HRESULT CloseStream();
void AddDigest();
public:
void Init(IArchiveUpdateCallback *updateCallback,
const UInt32 *fileIndices, UInt32 numFiles);
CRecordVector<bool> Processed;
CRecordVector<UInt32> CRCs;
CRecordVector<UInt64> Sizes;
UInt64 GetFullSize() const
{
UInt64 size = 0;
for (int i = 0; i < Sizes.Size(); i++)
size += Sizes[i];
return size;
}
};
}}
#endif

View File

@ -0,0 +1,60 @@
// 7zFolderOutStream.h
#ifndef __7Z_FOLDEROUTSTREAM_H
#define __7Z_FOLDEROUTSTREAM_H
#include "7zIn.h"
#include "../../IStream.h"
#include "../IArchive.h"
#include "../Common/OutStreamWithCRC.h"
namespace NArchive {
namespace N7z {
class CFolderOutStream:
public ISequentialOutStream,
public CMyUnknownImp
{
public:
MY_UNKNOWN_IMP
CFolderOutStream();
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
private:
COutStreamWithCRC *_outStreamWithHashSpec;
CMyComPtr<ISequentialOutStream> _outStreamWithHash;
const CArchiveDatabaseEx *_archiveDatabase;
const CBoolVector *_extractStatuses;
UInt32 _startIndex;
UInt32 _ref2Offset;
int _currentIndex;
// UInt64 _currentDataPos;
CMyComPtr<IArchiveExtractCallback> _extractCallback;
bool _testMode;
bool _fileIsOpen;
bool _checkCrc;
UInt64 _filePos;
HRESULT OpenFile();
HRESULT WriteEmptyFiles();
public:
HRESULT Init(
const CArchiveDatabaseEx *archiveDatabase,
UInt32 ref2Offset,
UInt32 startIndex,
const CBoolVector *extractStatuses,
IArchiveExtractCallback *extractCallback,
bool testMode,
bool checkCrc);
HRESULT FlushCorrupted(Int32 resultEOperationResult);
HRESULT WasWritingFinished();
};
}}
#endif

View File

@ -0,0 +1,121 @@
// 7z/Handler.h
#ifndef __7Z_HANDLER_H
#define __7Z_HANDLER_H
#include "../../ICoder.h"
#include "../IArchive.h"
#include "7zIn.h"
#include "7zCompressionMode.h"
#include "../../Common/CreateCoder.h"
#ifndef EXTRACT_ONLY
#include "../Common/HandlerOut.h"
#endif
namespace NArchive {
namespace N7z {
#ifndef __7Z_SET_PROPERTIES
#ifdef EXTRACT_ONLY
#ifdef COMPRESS_MT
#define __7Z_SET_PROPERTIES
#endif
#else
#define __7Z_SET_PROPERTIES
#endif
#endif
class CHandler:
#ifndef EXTRACT_ONLY
public NArchive::COutHandler,
#endif
public IInArchive,
#ifdef __7Z_SET_PROPERTIES
public ISetProperties,
#endif
#ifndef EXTRACT_ONLY
public IOutArchive,
#endif
PUBLIC_ISetCompressCodecsInfo
public CMyUnknownImp
{
public:
MY_QUERYINTERFACE_BEGIN2(IInArchive)
#ifdef __7Z_SET_PROPERTIES
MY_QUERYINTERFACE_ENTRY(ISetProperties)
#endif
#ifndef EXTRACT_ONLY
MY_QUERYINTERFACE_ENTRY(IOutArchive)
#endif
QUERY_ENTRY_ISetCompressCodecsInfo
MY_QUERYINTERFACE_END
MY_ADDREF_RELEASE
INTERFACE_IInArchive(;)
#ifdef __7Z_SET_PROPERTIES
STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties);
#endif
#ifndef EXTRACT_ONLY
INTERFACE_IOutArchive(;)
#endif
DECL_ISetCompressCodecsInfo
CHandler();
private:
CMyComPtr<IInStream> _inStream;
NArchive::N7z::CArchiveDatabaseEx _db;
#ifndef _NO_CRYPTO
bool _passwordIsDefined;
#endif
#ifdef EXTRACT_ONLY
#ifdef COMPRESS_MT
UInt32 _numThreads;
#endif
UInt32 _crcSize;
#else
CRecordVector<CBind> _binds;
HRESULT SetPassword(CCompressionMethodMode &methodMode, IArchiveUpdateCallback *updateCallback);
HRESULT SetCompressionMethod(CCompressionMethodMode &method,
CObjectVector<COneMethodInfo> &methodsInfo
#ifdef COMPRESS_MT
, UInt32 numThreads
#endif
);
HRESULT SetCompressionMethod(
CCompressionMethodMode &method,
CCompressionMethodMode &headerMethod);
#endif
bool IsEncrypted(UInt32 index2) const;
#ifndef _SFX
CRecordVector<UInt64> _fileInfoPopIDs;
void FillPopIDs();
#endif
DECL_EXTERNAL_CODECS_VARS
};
}}
#endif

View File

@ -0,0 +1,97 @@
// 7z/7zHeader.h
#ifndef __7Z_HEADER_H
#define __7Z_HEADER_H
#include "../../../Common/Types.h"
namespace NArchive {
namespace N7z {
const int kSignatureSize = 6;
extern Byte kSignature[kSignatureSize];
// #define _7Z_VOL
// 7z-MultiVolume is not finished yet.
// It can work already, but I still do not like some
// things of that new multivolume format.
// So please keep it commented.
#ifdef _7Z_VOL
extern Byte kFinishSignature[kSignatureSize];
#endif
struct CArchiveVersion
{
Byte Major;
Byte Minor;
};
const Byte kMajorVersion = 0;
struct CStartHeader
{
UInt64 NextHeaderOffset;
UInt64 NextHeaderSize;
UInt32 NextHeaderCRC;
};
const UInt32 kStartHeaderSize = 20;
#ifdef _7Z_VOL
struct CFinishHeader: public CStartHeader
{
UInt64 ArchiveStartOffset; // data offset from end if that struct
UInt64 AdditionalStartBlockSize; // start signature & start header size
};
const UInt32 kFinishHeaderSize = kStartHeaderSize + 16;
#endif
namespace NID
{
enum EEnum
{
kEnd,
kHeader,
kArchiveProperties,
kAdditionalStreamsInfo,
kMainStreamsInfo,
kFilesInfo,
kPackInfo,
kUnpackInfo,
kSubStreamsInfo,
kSize,
kCRC,
kFolder,
kCodersUnpackSize,
kNumUnpackStream,
kEmptyStream,
kEmptyFile,
kAnti,
kName,
kCTime,
kATime,
kMTime,
kWinAttributes,
kComment,
kEncodedHeader,
kStartPos,
kDummy
};
}
}}
#endif

View File

@ -0,0 +1,245 @@
// 7zIn.h
#ifndef __7Z_IN_H
#define __7Z_IN_H
#include "../../../Common/MyCom.h"
#include "../../IPassword.h"
#include "../../IStream.h"
#include "../../Common/CreateCoder.h"
#include "../../Common/InBuffer.h"
#include "7zItem.h"
namespace NArchive {
namespace N7z {
struct CInArchiveInfo
{
CArchiveVersion Version;
UInt64 StartPosition;
UInt64 StartPositionAfterHeader;
UInt64 DataStartPosition;
UInt64 DataStartPosition2;
CRecordVector<UInt64> FileInfoPopIDs;
void Clear()
{
FileInfoPopIDs.Clear();
}
};
struct CArchiveDatabaseEx: public CArchiveDatabase
{
CInArchiveInfo ArchiveInfo;
CRecordVector<UInt64> PackStreamStartPositions;
CRecordVector<CNum> FolderStartPackStreamIndex;
CRecordVector<CNum> FolderStartFileIndex;
CRecordVector<CNum> FileIndexToFolderIndexMap;
UInt64 HeadersSize;
UInt64 PhySize;
void Clear()
{
CArchiveDatabase::Clear();
ArchiveInfo.Clear();
PackStreamStartPositions.Clear();
FolderStartPackStreamIndex.Clear();
FolderStartFileIndex.Clear();
FileIndexToFolderIndexMap.Clear();
HeadersSize = 0;
PhySize = 0;
}
void FillFolderStartPackStream();
void FillStartPos();
void FillFolderStartFileIndex();
void Fill()
{
FillFolderStartPackStream();
FillStartPos();
FillFolderStartFileIndex();
}
UInt64 GetFolderStreamPos(int folderIndex, int indexInFolder) const
{
return ArchiveInfo.DataStartPosition +
PackStreamStartPositions[FolderStartPackStreamIndex[folderIndex] + indexInFolder];
}
UInt64 GetFolderFullPackSize(int folderIndex) const
{
CNum packStreamIndex = FolderStartPackStreamIndex[folderIndex];
const CFolder &folder = Folders[folderIndex];
UInt64 size = 0;
for (int i = 0; i < folder.PackStreams.Size(); i++)
size += PackSizes[packStreamIndex + i];
return size;
}
UInt64 GetFolderPackStreamSize(int folderIndex, int streamIndex) const
{
return PackSizes[FolderStartPackStreamIndex[folderIndex] + streamIndex];
}
UInt64 GetFilePackSize(CNum fileIndex) const
{
CNum folderIndex = FileIndexToFolderIndexMap[fileIndex];
if (folderIndex != kNumNoIndex)
if (FolderStartFileIndex[folderIndex] == fileIndex)
return GetFolderFullPackSize(folderIndex);
return 0;
}
};
class CInByte2
{
const Byte *_buffer;
size_t _size;
public:
size_t _pos;
void Init(const Byte *buffer, size_t size)
{
_buffer = buffer;
_size = size;
_pos = 0;
}
Byte ReadByte();
void ReadBytes(Byte *data, size_t size);
void SkeepData(UInt64 size);
void SkeepData();
UInt64 ReadNumber();
CNum ReadNum();
UInt32 ReadUInt32();
UInt64 ReadUInt64();
void ReadString(UString &s);
};
class CStreamSwitch;
const UInt32 kHeaderSize = 32;
class CInArchive
{
friend class CStreamSwitch;
CMyComPtr<IInStream> _stream;
CObjectVector<CInByte2> _inByteVector;
CInByte2 *_inByteBack;
UInt64 _arhiveBeginStreamPosition;
Byte _header[kHeaderSize];
UInt64 HeadersSize;
void AddByteStream(const Byte *buffer, size_t size)
{
_inByteVector.Add(CInByte2());
_inByteBack = &_inByteVector.Back();
_inByteBack->Init(buffer, size);
}
void DeleteByteStream()
{
_inByteVector.DeleteBack();
if (!_inByteVector.IsEmpty())
_inByteBack = &_inByteVector.Back();
}
private:
HRESULT FindAndReadSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit);
void ReadBytes(Byte *data, size_t size) { _inByteBack->ReadBytes(data, size); }
Byte ReadByte() { return _inByteBack->ReadByte(); }
UInt64 ReadNumber() { return _inByteBack->ReadNumber(); }
CNum ReadNum() { return _inByteBack->ReadNum(); }
UInt64 ReadID() { return _inByteBack->ReadNumber(); }
UInt32 ReadUInt32() { return _inByteBack->ReadUInt32(); }
UInt64 ReadUInt64() { return _inByteBack->ReadUInt64(); }
void SkeepData(UInt64 size) { _inByteBack->SkeepData(size); }
void SkeepData() { _inByteBack->SkeepData(); }
void WaitAttribute(UInt64 attribute);
void ReadArchiveProperties(CInArchiveInfo &archiveInfo);
void GetNextFolderItem(CFolder &itemInfo);
void ReadHashDigests(int numItems,
CBoolVector &digestsDefined, CRecordVector<UInt32> &digests);
void ReadPackInfo(
UInt64 &dataOffset,
CRecordVector<UInt64> &packSizes,
CBoolVector &packCRCsDefined,
CRecordVector<UInt32> &packCRCs);
void ReadUnpackInfo(
const CObjectVector<CByteBuffer> *dataVector,
CObjectVector<CFolder> &folders);
void ReadSubStreamsInfo(
const CObjectVector<CFolder> &folders,
CRecordVector<CNum> &numUnpackStreamsInFolders,
CRecordVector<UInt64> &unpackSizes,
CBoolVector &digestsDefined,
CRecordVector<UInt32> &digests);
void ReadStreamsInfo(
const CObjectVector<CByteBuffer> *dataVector,
UInt64 &dataOffset,
CRecordVector<UInt64> &packSizes,
CBoolVector &packCRCsDefined,
CRecordVector<UInt32> &packCRCs,
CObjectVector<CFolder> &folders,
CRecordVector<CNum> &numUnpackStreamsInFolders,
CRecordVector<UInt64> &unpackSizes,
CBoolVector &digestsDefined,
CRecordVector<UInt32> &digests);
void ReadBoolVector(int numItems, CBoolVector &v);
void ReadBoolVector2(int numItems, CBoolVector &v);
void ReadUInt64DefVector(const CObjectVector<CByteBuffer> &dataVector,
CUInt64DefVector &v, int numFiles);
HRESULT ReadAndDecodePackedStreams(
DECL_EXTERNAL_CODECS_LOC_VARS
UInt64 baseOffset, UInt64 &dataOffset,
CObjectVector<CByteBuffer> &dataVector
#ifndef _NO_CRYPTO
, ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
#endif
);
HRESULT ReadHeader(
DECL_EXTERNAL_CODECS_LOC_VARS
CArchiveDatabaseEx &db
#ifndef _NO_CRYPTO
,ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
#endif
);
HRESULT ReadDatabase2(
DECL_EXTERNAL_CODECS_LOC_VARS
CArchiveDatabaseEx &db
#ifndef _NO_CRYPTO
,ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
#endif
);
public:
HRESULT Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit); // S_FALSE means is not archive
void Close();
HRESULT ReadDatabase(
DECL_EXTERNAL_CODECS_LOC_VARS
CArchiveDatabaseEx &db
#ifndef _NO_CRYPTO
,ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
#endif
);
};
}}
#endif

View File

@ -0,0 +1,258 @@
// 7zItem.h
#ifndef __7Z_ITEM_H
#define __7Z_ITEM_H
#include "../../../Common/Buffer.h"
#include "../../../Common/MyString.h"
#include "../../Common/MethodId.h"
#include "7zHeader.h"
namespace NArchive {
namespace N7z {
typedef UInt32 CNum;
const CNum kNumMax = 0x7FFFFFFF;
const CNum kNumNoIndex = 0xFFFFFFFF;
struct CCoderInfo
{
CMethodId MethodID;
CByteBuffer Props;
CNum NumInStreams;
CNum NumOutStreams;
bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); }
};
struct CBindPair
{
CNum InIndex;
CNum OutIndex;
};
struct CFolder
{
CObjectVector<CCoderInfo> Coders;
CRecordVector<CBindPair> BindPairs;
CRecordVector<CNum> PackStreams;
CRecordVector<UInt64> UnpackSizes;
UInt32 UnpackCRC;
bool UnpackCRCDefined;
CFolder(): UnpackCRCDefined(false) {}
UInt64 GetUnpackSize() const // test it
{
if (UnpackSizes.IsEmpty())
return 0;
for (int i = UnpackSizes.Size() - 1; i >= 0; i--)
if (FindBindPairForOutStream(i) < 0)
return UnpackSizes[i];
throw 1;
}
CNum GetNumOutStreams() const
{
CNum result = 0;
for (int i = 0; i < Coders.Size(); i++)
result += Coders[i].NumOutStreams;
return result;
}
int FindBindPairForInStream(CNum inStreamIndex) const
{
for(int i = 0; i < BindPairs.Size(); i++)
if (BindPairs[i].InIndex == inStreamIndex)
return i;
return -1;
}
int FindBindPairForOutStream(CNum outStreamIndex) const
{
for(int i = 0; i < BindPairs.Size(); i++)
if (BindPairs[i].OutIndex == outStreamIndex)
return i;
return -1;
}
int FindPackStreamArrayIndex(CNum inStreamIndex) const
{
for(int i = 0; i < PackStreams.Size(); i++)
if (PackStreams[i] == inStreamIndex)
return i;
return -1;
}
bool CheckStructure() const;
};
struct CUInt64DefVector
{
CRecordVector<UInt64> Values;
CRecordVector<bool> Defined;
void Clear()
{
Values.Clear();
Defined.Clear();
}
void ReserveDown()
{
Values.ReserveDown();
Values.ReserveDown();
}
bool GetItem(int index, UInt64 &value) const
{
if (index < Defined.Size() && Defined[index])
{
value = Values[index];
return true;
}
value = 0;
return false;
}
void SetItem(int index, bool defined, UInt64 value)
{
while (index >= Defined.Size())
Defined.Add(false);
Defined[index] = defined;
if (!defined)
return;
while (index >= Values.Size())
Values.Add(0);
Values[index] = value;
}
bool CheckSize(int size) const { return Defined.Size() == size || Defined.Size() == 0; }
};
struct CFileItem
{
UInt64 Size;
UInt32 Attrib;
UInt32 Crc;
UString Name;
bool HasStream; // Test it !!! it means that there is
// stream in some folder. It can be empty stream
bool IsDir;
bool CrcDefined;
bool AttribDefined;
CFileItem():
HasStream(true),
IsDir(false),
CrcDefined(false),
AttribDefined(false)
{}
void SetAttrib(UInt32 attrib)
{
AttribDefined = true;
Attrib = attrib;
}
};
struct CFileItem2
{
UInt64 CTime;
UInt64 ATime;
UInt64 MTime;
UInt64 StartPos;
bool CTimeDefined;
bool ATimeDefined;
bool MTimeDefined;
bool StartPosDefined;
bool IsAnti;
};
struct CArchiveDatabase
{
CRecordVector<UInt64> PackSizes;
CRecordVector<bool> PackCRCsDefined;
CRecordVector<UInt32> PackCRCs;
CObjectVector<CFolder> Folders;
CRecordVector<CNum> NumUnpackStreamsVector;
CObjectVector<CFileItem> Files;
CUInt64DefVector CTime;
CUInt64DefVector ATime;
CUInt64DefVector MTime;
CUInt64DefVector StartPos;
CRecordVector<bool> IsAnti;
void Clear()
{
PackSizes.Clear();
PackCRCsDefined.Clear();
PackCRCs.Clear();
Folders.Clear();
NumUnpackStreamsVector.Clear();
Files.Clear();
CTime.Clear();
ATime.Clear();
MTime.Clear();
StartPos.Clear();
IsAnti.Clear();
}
void ReserveDown()
{
PackSizes.ReserveDown();
PackCRCsDefined.ReserveDown();
PackCRCs.ReserveDown();
Folders.ReserveDown();
NumUnpackStreamsVector.ReserveDown();
Files.ReserveDown();
CTime.ReserveDown();
ATime.ReserveDown();
MTime.ReserveDown();
StartPos.ReserveDown();
IsAnti.ReserveDown();
}
bool IsEmpty() const
{
return (PackSizes.IsEmpty() &&
PackCRCsDefined.IsEmpty() &&
PackCRCs.IsEmpty() &&
Folders.IsEmpty() &&
NumUnpackStreamsVector.IsEmpty() &&
Files.IsEmpty());
}
bool CheckNumFiles() const
{
int size = Files.Size();
return (
CTime.CheckSize(size) &&
ATime.CheckSize(size) &&
MTime.CheckSize(size) &&
StartPos.CheckSize(size) &&
(size == IsAnti.Size() || IsAnti.Size() == 0));
}
bool IsSolid() const
{
for (int i = 0; i < NumUnpackStreamsVector.Size(); i++)
if (NumUnpackStreamsVector[i] > 1)
return true;
return false;
}
bool IsItemAnti(int index) const { return (index < IsAnti.Size() && IsAnti[index]); }
void SetItemAnti(int index, bool isAnti)
{
while (index >= IsAnti.Size())
IsAnti.Add(false);
IsAnti[index] = isAnti;
}
void GetFile(int index, CFileItem &file, CFileItem2 &file2) const;
void AddFile(const CFileItem &file, const CFileItem2 &file2);
};
}}
#endif

View File

@ -0,0 +1,22 @@
// 7zProperties.h
#ifndef __7Z_PROPERTIES_H
#define __7Z_PROPERTIES_H
#include "../../PropID.h"
namespace NArchive {
namespace N7z {
enum
{
kpidPackedSize0 = kpidUserDefined,
kpidPackedSize1,
kpidPackedSize2,
kpidPackedSize3,
kpidPackedSize4
};
}}
#endif

View File

@ -0,0 +1,35 @@
// 7zSpecStream.h
#ifndef __7Z_SPEC_STREAM_H
#define __7Z_SPEC_STREAM_H
#include "../../IStream.h"
#include "../../ICoder.h"
#include "../../../Common/MyCom.h"
class CSequentialInStreamSizeCount2:
public ISequentialInStream,
public ICompressGetSubStreamSize,
public CMyUnknownImp
{
CMyComPtr<ISequentialInStream> _stream;
CMyComPtr<ICompressGetSubStreamSize> _getSubStreamSize;
UInt64 _size;
public:
void Init(ISequentialInStream *stream)
{
_stream = stream;
_getSubStreamSize = 0;
_stream.QueryInterface(IID_ICompressGetSubStreamSize, &_getSubStreamSize);
_size = 0;
}
UInt64 GetSize() const { return _size; }
MY_UNKNOWN_IMP1(ICompressGetSubStreamSize)
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value);
};
#endif

View File

@ -0,0 +1,9 @@
// StdAfx.h
#ifndef __STDAFX_H
#define __STDAFX_H
#include "../../../Common/MyWindows.h"
#include "../../../Common/NewHandler.h"
#endif

View File

@ -0,0 +1,70 @@
// BZip2/Handler.h
#ifndef __BZIP2_HANDLER_H
#define __BZIP2_HANDLER_H
#include "Common/MyCom.h"
#include "../IArchive.h"
#include "../../Common/CreateCoder.h"
#include "BZip2Item.h"
#ifdef COMPRESS_MT
#include "../../../Windows/System.h"
#endif
namespace NArchive {
namespace NBZip2 {
class CHandler:
public IInArchive,
public IOutArchive,
public ISetProperties,
PUBLIC_ISetCompressCodecsInfo
public CMyUnknownImp
{
CMyComPtr<IInStream> _stream;
NArchive::NBZip2::CItem _item;
UInt64 _streamStartPosition;
UInt32 _level;
UInt32 _dicSize;
UInt32 _numPasses;
#ifdef COMPRESS_MT
UInt32 _numThreads;
#endif
DECL_EXTERNAL_CODECS_VARS
void InitMethodProperties()
{
_level = 5;
_dicSize =
_numPasses = 0xFFFFFFFF;
#ifdef COMPRESS_MT
_numThreads = NWindows::NSystem::GetNumberOfProcessors();;
#endif
}
public:
MY_QUERYINTERFACE_BEGIN2(IInArchive)
MY_QUERYINTERFACE_ENTRY(IOutArchive)
MY_QUERYINTERFACE_ENTRY(ISetProperties)
QUERY_ENTRY_ISetCompressCodecsInfo
MY_QUERYINTERFACE_END
MY_ADDREF_RELEASE
INTERFACE_IInArchive(;)
#ifndef EXTRACT_ONLY
INTERFACE_IOutArchive(;)
STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties);
#endif
DECL_ISetCompressCodecsInfo
CHandler() { InitMethodProperties(); }
};
}}
#endif

View File

@ -0,0 +1,20 @@
// Archive/BZip2Item.h
#ifndef __ARCHIVE_BZIP2_ITEM_H
#define __ARCHIVE_BZIP2_ITEM_H
namespace NArchive {
namespace NBZip2 {
struct CItem
{
UInt64 PackSize;
UInt64 UnPackSize;
};
}}
#endif

View File

@ -0,0 +1,8 @@
// StdAfx.h
#ifndef __STDAFX_H
#define __STDAFX_H
#include "../../../Common/MyWindows.h"
#endif

View File

@ -0,0 +1,174 @@
// CoderMixer2.h
#ifndef __CODER_MIXER2_H
#define __CODER_MIXER2_H
#include "../../../Common/MyVector.h"
#include "../../../Common/Types.h"
#include "../../../Common/MyCom.h"
#include "../../ICoder.h"
namespace NCoderMixer {
struct CBindPair
{
UInt32 InIndex;
UInt32 OutIndex;
};
struct CCoderStreamsInfo
{
UInt32 NumInStreams;
UInt32 NumOutStreams;
};
struct CBindInfo
{
CRecordVector<CCoderStreamsInfo> Coders;
CRecordVector<CBindPair> BindPairs;
CRecordVector<UInt32> InStreams;
CRecordVector<UInt32> OutStreams;
void Clear()
{
Coders.Clear();
BindPairs.Clear();
InStreams.Clear();
OutStreams.Clear();
}
/*
UInt32 GetCoderStartOutStream(UInt32 coderIndex) const
{
UInt32 numOutStreams = 0;
for (UInt32 i = 0; i < coderIndex; i++)
numOutStreams += Coders[i].NumOutStreams;
return numOutStreams;
}
*/
void GetNumStreams(UInt32 &numInStreams, UInt32 &numOutStreams) const
{
numInStreams = 0;
numOutStreams = 0;
for (int i = 0; i < Coders.Size(); i++)
{
const CCoderStreamsInfo &coderStreamsInfo = Coders[i];
numInStreams += coderStreamsInfo.NumInStreams;
numOutStreams += coderStreamsInfo.NumOutStreams;
}
}
int FindBinderForInStream(UInt32 inStream) const
{
for (int i = 0; i < BindPairs.Size(); i++)
if (BindPairs[i].InIndex == inStream)
return i;
return -1;
}
int FindBinderForOutStream(UInt32 outStream) const
{
for (int i = 0; i < BindPairs.Size(); i++)
if (BindPairs[i].OutIndex == outStream)
return i;
return -1;
}
UInt32 GetCoderInStreamIndex(UInt32 coderIndex) const
{
UInt32 streamIndex = 0;
for (UInt32 i = 0; i < coderIndex; i++)
streamIndex += Coders[i].NumInStreams;
return streamIndex;
}
UInt32 GetCoderOutStreamIndex(UInt32 coderIndex) const
{
UInt32 streamIndex = 0;
for (UInt32 i = 0; i < coderIndex; i++)
streamIndex += Coders[i].NumOutStreams;
return streamIndex;
}
void FindInStream(UInt32 streamIndex, UInt32 &coderIndex,
UInt32 &coderStreamIndex) const
{
for (coderIndex = 0; coderIndex < (UInt32)Coders.Size(); coderIndex++)
{
UInt32 curSize = Coders[coderIndex].NumInStreams;
if (streamIndex < curSize)
{
coderStreamIndex = streamIndex;
return;
}
streamIndex -= curSize;
}
throw 1;
}
void FindOutStream(UInt32 streamIndex, UInt32 &coderIndex,
UInt32 &coderStreamIndex) const
{
for (coderIndex = 0; coderIndex < (UInt32)Coders.Size(); coderIndex++)
{
UInt32 curSize = Coders[coderIndex].NumOutStreams;
if (streamIndex < curSize)
{
coderStreamIndex = streamIndex;
return;
}
streamIndex -= curSize;
}
throw 1;
}
};
class CBindReverseConverter
{
UInt32 _numSrcOutStreams;
NCoderMixer::CBindInfo _srcBindInfo;
CRecordVector<UInt32> _srcInToDestOutMap;
CRecordVector<UInt32> _srcOutToDestInMap;
CRecordVector<UInt32> _destInToSrcOutMap;
public:
UInt32 NumSrcInStreams;
CRecordVector<UInt32> DestOutToSrcInMap;
CBindReverseConverter(const NCoderMixer::CBindInfo &srcBindInfo);
void CreateReverseBindInfo(NCoderMixer::CBindInfo &destBindInfo);
};
struct CCoderInfo2
{
CMyComPtr<ICompressCoder> Coder;
CMyComPtr<ICompressCoder2> Coder2;
UInt32 NumInStreams;
UInt32 NumOutStreams;
CRecordVector<UInt64> InSizes;
CRecordVector<UInt64> OutSizes;
CRecordVector<const UInt64 *> InSizePointers;
CRecordVector<const UInt64 *> OutSizePointers;
CCoderInfo2(UInt32 numInStreams, UInt32 numOutStreams);
void SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes);
HRESULT QueryInterface(REFGUID iid, void** pp) const
{
IUnknown *p = Coder ? (IUnknown *)Coder : (IUnknown *)Coder2;
return p->QueryInterface(iid, pp);
}
};
class CCoderMixer2
{
public:
virtual HRESULT SetBindInfo(const CBindInfo &bindInfo) = 0;
virtual void ReInit() = 0;
virtual void SetCoderInfo(UInt32 coderIndex, const UInt64 **inSizes, const UInt64 **outSizes) = 0;
};
}
#endif

View File

@ -0,0 +1,80 @@
// CoderMixer2MT.h
#ifndef __CODER_MIXER2_MT_H
#define __CODER_MIXER2_MT_H
#include "CoderMixer2.h"
#include "../../../Common/MyCom.h"
#include "../../Common/StreamBinder.h"
#include "../../Common/VirtThread.h"
namespace NCoderMixer {
struct CCoder2: public CCoderInfo2, public CVirtThread
{
HRESULT Result;
CObjectVector< CMyComPtr<ISequentialInStream> > InStreams;
CObjectVector< CMyComPtr<ISequentialOutStream> > OutStreams;
CRecordVector<ISequentialInStream*> InStreamPointers;
CRecordVector<ISequentialOutStream*> OutStreamPointers;
CCoder2(UInt32 numInStreams, UInt32 numOutStreams);
void SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes);
virtual void Execute();
void Code(ICompressProgressInfo *progress);
};
/*
SetBindInfo()
for each coder
AddCoder[2]()
SetProgressIndex(UInt32 coderIndex);
for each file
{
ReInit()
for each coder
SetCoderInfo
Code
}
*/
class CCoderMixer2MT:
public ICompressCoder2,
public CCoderMixer2,
public CMyUnknownImp
{
CBindInfo _bindInfo;
CObjectVector<CStreamBinder> _streamBinders;
int _progressCoderIndex;
void AddCoderCommon();
HRESULT Init(ISequentialInStream **inStreams, ISequentialOutStream **outStreams);
HRESULT ReturnIfError(HRESULT code);
public:
CObjectVector<CCoder2> _coders;
MY_UNKNOWN_IMP
STDMETHOD(Code)(ISequentialInStream **inStreams,
const UInt64 **inSizes,
UInt32 numInStreams,
ISequentialOutStream **outStreams,
const UInt64 **outSizes,
UInt32 numOutStreams,
ICompressProgressInfo *progress);
HRESULT SetBindInfo(const CBindInfo &bindInfo);
void AddCoder(ICompressCoder *coder);
void AddCoder2(ICompressCoder2 *coder);
void SetProgressCoderIndex(int coderIndex) { _progressCoderIndex = coderIndex; }
void ReInit();
void SetCoderInfo(UInt32 coderIndex, const UInt64 **inSizes, const UInt64 **outSizes)
{ _coders[coderIndex].SetCoderInfo(inSizes, outSizes); }
UInt64 GetWriteProcessedSize(UInt32 binderIndex) const
{ return _streamBinders[binderIndex].ProcessedSize; }
};
}
#endif

View File

@ -0,0 +1,24 @@
// DummyOutStream.h
#ifndef __DUMMYOUTSTREAM_H
#define __DUMMYOUTSTREAM_H
#include "../../IStream.h"
#include "Common/MyCom.h"
class CDummyOutStream:
public ISequentialOutStream,
public CMyUnknownImp
{
CMyComPtr<ISequentialOutStream> _stream;
UInt64 _size;
public:
void SetStream(ISequentialOutStream *outStream) { _stream = outStream; }
void ReleaseStream() { _stream.Release(); }
void Init() { _size = 0; }
MY_UNKNOWN_IMP
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
UInt64 GetSize() const { return _size; }
};
#endif

View File

@ -0,0 +1,12 @@
// FindSignature.h
#ifndef __FINDSIGNATURE_H
#define __FINDSIGNATURE_H
#include "../../IStream.h"
HRESULT FindSignatureInStream(ISequentialInStream *stream,
const Byte *signature, unsigned signatureSize,
const UInt64 *limit, UInt64 &resPos);
#endif

View File

@ -0,0 +1,69 @@
// InStreamWithCRC.h
#ifndef __INSTREAMWITHCRC_H
#define __INSTREAMWITHCRC_H
#include "../../../Common/MyCom.h"
#include "../../IStream.h"
extern "C"
{
#include "../../../../C/7zCrc.h"
}
class CSequentialInStreamWithCRC:
public ISequentialInStream,
public CMyUnknownImp
{
public:
MY_UNKNOWN_IMP
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
private:
CMyComPtr<ISequentialInStream> _stream;
UInt64 _size;
UInt32 _crc;
bool _wasFinished;
public:
void SetStream(ISequentialInStream *stream) { _stream = stream; }
void Init()
{
_size = 0;
_wasFinished = false;
_crc = CRC_INIT_VAL;
}
void ReleaseStream() { _stream.Release(); }
UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }
UInt64 GetSize() const { return _size; }
bool WasFinished() const { return _wasFinished; }
};
class CInStreamWithCRC:
public IInStream,
public CMyUnknownImp
{
public:
MY_UNKNOWN_IMP1(IInStream)
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
private:
CMyComPtr<IInStream> _stream;
UInt64 _size;
UInt32 _crc;
bool _wasFinished;
public:
void SetStream(IInStream *stream) { _stream = stream; }
void Init()
{
_size = 0;
_wasFinished = false;
_crc = CRC_INIT_VAL;
}
void ReleaseStream() { _stream.Release(); }
UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }
UInt64 GetSize() const { return _size; }
bool WasFinished() const { return _wasFinished; }
};
#endif

View File

@ -0,0 +1,24 @@
// Archive/Common/ItemNameUtils.h
#ifndef __ARCHIVE_ITEMNAMEUTILS_H
#define __ARCHIVE_ITEMNAMEUTILS_H
#include "../../../Common/MyString.h"
namespace NArchive {
namespace NItemName {
UString MakeLegalName(const UString &name);
UString GetOSName(const UString &name);
UString GetOSName2(const UString &name);
bool HasTailSlash(const AString &name, UINT codePage);
#ifdef _WIN32
inline UString WinNameToOSName(const UString &name) { return name; }
#else
UString WinNameToOSName(const UString &name);
#endif
}}
#endif

View File

@ -0,0 +1,76 @@
// MultiStream.h
#ifndef __MULTISTREAM_H
#define __MULTISTREAM_H
#include "../../../Common/MyCom.h"
#include "../../../Common/MyVector.h"
#include "../../Archive/IArchive.h"
class CMultiStream:
public IInStream,
public CMyUnknownImp
{
int _streamIndex;
UInt64 _pos;
UInt64 _seekPos;
UInt64 _totalLength;
public:
struct CSubStreamInfo
{
CMyComPtr<IInStream> Stream;
UInt64 Pos;
UInt64 Size;
};
CObjectVector<CSubStreamInfo> Streams;
void Init()
{
_streamIndex = 0;
_pos = 0;
_seekPos = 0;
_totalLength = 0;
for (int i = 0; i < Streams.Size(); i++)
_totalLength += Streams[i].Size;
}
MY_UNKNOWN_IMP1(IInStream)
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
};
/*
class COutMultiStream:
public IOutStream,
public CMyUnknownImp
{
int _streamIndex; // required stream
UInt64 _offsetPos; // offset from start of _streamIndex index
UInt64 _absPos;
UInt64 _length;
struct CSubStreamInfo
{
CMyComPtr<ISequentialOutStream> Stream;
UInt64 Size;
UInt64 Pos;
};
CObjectVector<CSubStreamInfo> Streams;
public:
CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;
void Init()
{
_streamIndex = 0;
_offsetPos = 0;
_absPos = 0;
_length = 0;
}
MY_UNKNOWN_IMP1(IOutStream)
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
};
*/
#endif

View File

@ -0,0 +1,38 @@
// OutStreamWithCRC.h
#ifndef __OUT_STREAM_WITH_CRC_H
#define __OUT_STREAM_WITH_CRC_H
#include "../../../Common/MyCom.h"
#include "../../IStream.h"
extern "C"
{
#include "../../../../C/7zCrc.h"
}
class COutStreamWithCRC:
public ISequentialOutStream,
public CMyUnknownImp
{
CMyComPtr<ISequentialOutStream> _stream;
UInt64 _size;
UInt32 _crc;
bool _calculate;
public:
MY_UNKNOWN_IMP
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
void SetStream(ISequentialOutStream *stream) { _stream = stream; }
void ReleaseStream() { _stream.Release(); }
void Init(bool calculate = true)
{
_size = 0;
_calculate = calculate;
_crc = CRC_INIT_VAL;
}
void InitCRC() { _crc = CRC_INIT_VAL; }
UInt64 GetSize() const { return _size; }
UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }
};
#endif

View File

@ -0,0 +1,18 @@
// ParseProperties.h
#ifndef __PARSEPROPERTIES_H
#define __PARSEPROPERTIES_H
#include "Common/MyString.h"
#include "Common/Types.h"
HRESULT ParsePropValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue);
HRESULT ParsePropDictionaryValue(const UString &srcStringSpec, UInt32 &dicSize);
HRESULT ParsePropDictionaryValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue);
bool StringToBool(const UString &s, bool &res);
HRESULT SetBoolProperty(bool &dest, const PROPVARIANT &value);
int ParseStringToUInt32(const UString &srcString, UInt32 &number);
HRESULT ParseMtProp(const UString &name, const PROPVARIANT &prop, UInt32 defaultNumThreads, UInt32 &numThreads);
#endif

View File

@ -0,0 +1,9 @@
// StdAfx.h
#ifndef __STDAFX_H
#define __STDAFX_H
#include "../../../Common/MyWindows.h"
#include "../../../Common/NewHandler.h"
#endif

View File

@ -0,0 +1,65 @@
// GZip/Handler.h
#ifndef __GZIP_HANDLER_H
#define __GZIP_HANDLER_H
#include "Common/MyCom.h"
#include "../IArchive.h"
#include "../../Common/CreateCoder.h"
#include "GZipIn.h"
#include "GZipUpdate.h"
namespace NArchive {
namespace NGZip {
class CHandler:
public IInArchive,
public IOutArchive,
public ISetProperties,
PUBLIC_ISetCompressCodecsInfo
public CMyUnknownImp
{
public:
MY_QUERYINTERFACE_BEGIN2(IInArchive)
MY_QUERYINTERFACE_ENTRY(IOutArchive)
MY_QUERYINTERFACE_ENTRY(ISetProperties)
QUERY_ENTRY_ISetCompressCodecsInfo
MY_QUERYINTERFACE_END
MY_ADDREF_RELEASE
INTERFACE_IInArchive(;)
#ifndef EXTRACT_ONLY
INTERFACE_IOutArchive(;)
STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties);
#endif
DECL_ISetCompressCodecsInfo
CHandler() { InitMethodProperties(); }
private:
NArchive::NGZip::CItem m_Item;
UInt64 m_StreamStartPosition;
UInt64 m_DataOffset;
UInt64 m_PackSize;
CMyComPtr<IInStream> m_Stream;
CCompressionMethodMode m_Method;
UInt32 m_Level;
DECL_EXTERNAL_CODECS_VARS
void InitMethodProperties()
{
m_Method.NumMatchFinderCyclesDefined = false;
m_Level = m_Method.NumPasses = m_Method.NumFastBytes =
m_Method.NumMatchFinderCycles = m_Method.Algo = 0xFFFFFFFF;
}
};
}}
#endif

View File

@ -0,0 +1,85 @@
// Archive/GZip/Header.h
#ifndef __ARCHIVE_GZIP_HEADER_H
#define __ARCHIVE_GZIP_HEADER_H
#include "Common/Types.h"
namespace NArchive {
namespace NGZip {
extern UInt16 kSignature;
static const UInt32 kSignatureSize = 2;
namespace NFileHeader
{
/*
struct CBlock
{
UInt16 Id;
Byte CompressionMethod;
Byte Flags;
UInt32 Time;
Byte ExtraFlags;
Byte HostOS;
};
*/
namespace NFlags
{
const int kDataIsText = 1 << 0;
const int kHeaderCRCIsPresent = 1 << 1;
const int kExtraIsPresent = 1 << 2;
const int kNameIsPresent = 1 << 3;
const int kComentIsPresent = 1 << 4;
}
namespace NExtraFlags
{
enum EEnum
{
kMaximum = 2,
kFastest = 4
};
}
namespace NCompressionMethod
{
const Byte kDeflate = 8;
}
namespace NHostOS
{
enum EEnum
{
kFAT = 0, // filesystem used by MS-DOS, OS/2, Win32
// pkzip 2.50 (FAT / VFAT / FAT32 file systems)
kAMIGA = 1,
kVMS = 2, // VAX/VMS
kUnix = 3,
kVM_CMS = 4,
kAtari = 5, // what if it's a minix filesystem? [cjh]
kHPFS = 6, // filesystem used by OS/2 (and NT 3.x)
kMac = 7,
kZ_System = 8,
kCPM = 9,
kTOPS20 = 10, // pkzip 2.50 NTFS
kNTFS = 11, // filesystem used by Windows NT
kQDOS = 12, // SMS/QDOS
kAcorn = 13, // Archimedes Acorn RISC OS
kVFAT = 14, // filesystem used by Windows 95, NT
kMVS = 15,
kBeOS = 16, // hybrid POSIX/database filesystem
// BeBOX or PowerMac
kTandem = 17,
kTHEOS = 18,
kUnknown = 255
};
const int kNumHostSystems = 19;
}
}
}}
#endif

View File

@ -0,0 +1,30 @@
// Archive/GZipIn.h
#ifndef __ARCHIVE_GZIP_IN_H
#define __ARCHIVE_GZIP_IN_H
#include "GZipHeader.h"
#include "GZipItem.h"
#include "../../IStream.h"
namespace NArchive {
namespace NGZip {
class CInArchive
{
UInt64 m_Position;
HRESULT ReadBytes(ISequentialInStream *inStream, void *data, UInt32 size);
HRESULT ReadZeroTerminatedString(ISequentialInStream *inStream, AString &resString, UInt32 &crc);
HRESULT ReadByte(ISequentialInStream *inStream, Byte &value, UInt32 &crc);
HRESULT ReadUInt16(ISequentialInStream *inStream, UInt16 &value, UInt32 &crc);
HRESULT ReadUInt32(ISequentialInStream *inStream, UInt32 &value, UInt32 &crc);
public:
HRESULT ReadHeader(ISequentialInStream *inStream, CItem &item);
HRESULT ReadPostHeader(ISequentialInStream *inStream, CItem &item);
UInt64 GetOffset() const { return m_Position; }
};
}}
#endif

View File

@ -0,0 +1,59 @@
// Archive/GZipItem.h
#ifndef __ARCHIVE_GZIP_ITEM_H
#define __ARCHIVE_GZIP_ITEM_H
#include "Common/Types.h"
#include "Common/MyString.h"
#include "Common/Buffer.h"
namespace NArchive {
namespace NGZip {
class CItem
{
private:
bool TestFlag(Byte flag) const { return ((Flags & flag) != 0); }
public:
Byte CompressionMethod;
Byte Flags;
UInt32 Time;
Byte ExtraFlags;
Byte HostOS;
UInt32 FileCRC;
UInt32 UnPackSize32;
AString Name;
AString Comment;
CByteBuffer Extra;
bool IsText() const
{ return TestFlag(NFileHeader::NFlags::kDataIsText); }
bool HeaderCRCIsPresent() const
{ return TestFlag(NFileHeader::NFlags::kHeaderCRCIsPresent); }
bool ExtraFieldIsPresent() const
{ return TestFlag(NFileHeader::NFlags::kExtraIsPresent); }
bool NameIsPresent() const
{ return TestFlag(NFileHeader::NFlags::kNameIsPresent); }
bool CommentIsPresent() const
{ return TestFlag(NFileHeader::NFlags::kComentIsPresent); }
void SetNameIsPresentFlag(bool nameIsPresent)
{
if (nameIsPresent)
Flags |= NFileHeader::NFlags::kNameIsPresent;
else
Flags &= (~NFileHeader::NFlags::kNameIsPresent);
}
void Clear()
{
Name.Empty();
Comment.Empty();;
Extra.SetCapacity(0);
}
};
}}
#endif

View File

@ -0,0 +1,39 @@
// GZip/Update.h
#ifndef __GZIP_UPDATE_H
#define __GZIP_UPDATE_H
#include "../IArchive.h"
#include "../../Common/CreateCoder.h"
#ifndef EXTRACT_ONLY
#include "GZipOut.h"
#endif
#include "GZipItem.h"
namespace NArchive {
namespace NGZip {
struct CCompressionMethodMode
{
UInt32 NumPasses;
UInt32 NumFastBytes;
UInt32 Algo;
bool NumMatchFinderCyclesDefined;
UInt32 NumMatchFinderCycles;
};
HRESULT UpdateArchive(
DECL_EXTERNAL_CODECS_LOC_VARS
IInStream *inStream,
UInt64 unpackSize,
ISequentialOutStream *outStream,
const CItem &newItem,
const CCompressionMethodMode &compressionMethod,
int indexInClient,
IArchiveUpdateCallback *updateCallback);
}}
#endif

View File

@ -0,0 +1,8 @@
// StdAfx.h
#ifndef __STDAFX_H
#define __STDAFX_H
#include "../../../Common/MyWindows.h"
#endif

View File

@ -0,0 +1,237 @@
// IArchive.h
#ifndef __IARCHIVE_H
#define __IARCHIVE_H
#include "../IStream.h"
#include "../IProgress.h"
#include "../PropID.h"
#define ARCHIVE_INTERFACE_SUB(i, base, x) DECL_INTERFACE_SUB(i, base, 6, x)
#define ARCHIVE_INTERFACE(i, x) ARCHIVE_INTERFACE_SUB(i, IUnknown, x)
namespace NFileTimeType
{
enum EEnum
{
kWindows,
kUnix,
kDOS
};
}
namespace NArchive
{
enum
{
kName = 0,
kClassID,
kExtension,
kAddExtension,
kUpdate,
kKeepName,
kStartSignature,
kFinishSignature,
kAssociate
};
namespace NExtract
{
namespace NAskMode
{
enum
{
kExtract = 0,
kTest,
kSkip
};
}
namespace NOperationResult
{
enum
{
kOK = 0,
kUnSupportedMethod,
kDataError,
kCRCError
};
}
}
namespace NUpdate
{
namespace NOperationResult
{
enum
{
kOK = 0,
kError
};
}
}
}
#define INTERFACE_IArchiveOpenCallback(x) \
STDMETHOD(SetTotal)(const UInt64 *files, const UInt64 *bytes) x; \
STDMETHOD(SetCompleted)(const UInt64 *files, const UInt64 *bytes) x; \
ARCHIVE_INTERFACE(IArchiveOpenCallback, 0x10)
{
INTERFACE_IArchiveOpenCallback(PURE);
};
#define INTERFACE_IArchiveExtractCallback(x) \
INTERFACE_IProgress(x) \
/* GetStream OUT: S_OK - OK, S_FALSE - skeep this file */ \
STDMETHOD(GetStream)(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode) x; \
STDMETHOD(PrepareOperation)(Int32 askExtractMode) x; \
STDMETHOD(SetOperationResult)(Int32 resultEOperationResult) x; \
ARCHIVE_INTERFACE_SUB(IArchiveExtractCallback, IProgress, 0x20)
{
INTERFACE_IArchiveExtractCallback(PURE)
};
#define INTERFACE_IArchiveOpenVolumeCallback(x) \
STDMETHOD(GetProperty)(PROPID propID, PROPVARIANT *value) x; \
STDMETHOD(GetStream)(const wchar_t *name, IInStream **inStream) x; \
ARCHIVE_INTERFACE(IArchiveOpenVolumeCallback, 0x30)
{
INTERFACE_IArchiveOpenVolumeCallback(PURE);
};
ARCHIVE_INTERFACE(IInArchiveGetStream, 0x40)
{
STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream) PURE;
};
ARCHIVE_INTERFACE(IArchiveOpenSetSubArchiveName, 0x50)
{
STDMETHOD(SetSubArchiveName)(const wchar_t *name) PURE;
};
/*
IInArchive::Extract:
indices must be sorted
numItems = 0xFFFFFFFF means "all files"
testMode != 0 means "test files without writing to outStream"
*/
#define INTERFACE_IInArchive(x) \
STDMETHOD(Open)(IInStream *stream, const UInt64 *maxCheckStartPosition, IArchiveOpenCallback *openArchiveCallback) x; \
STDMETHOD(Close)() x; \
STDMETHOD(GetNumberOfItems)(UInt32 *numItems) x; \
STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) x; \
STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems, Int32 testMode, IArchiveExtractCallback *extractCallback) x; \
STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value) x; \
STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties) x; \
STDMETHOD(GetPropertyInfo)(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) x; \
STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties) x; \
STDMETHOD(GetArchivePropertyInfo)(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) x;
ARCHIVE_INTERFACE(IInArchive, 0x60)
{
INTERFACE_IInArchive(PURE)
virtual ~IInArchive() {}
};
#define INTERFACE_IArchiveUpdateCallback(x) \
INTERFACE_IProgress(x); \
STDMETHOD(GetUpdateItemInfo)(UInt32 index, \
Int32 *newData, /*1 - new data, 0 - old data */ \
Int32 *newProperties, /* 1 - new properties, 0 - old properties */ \
UInt32 *indexInArchive /* -1 if there is no in archive, or if doesn't matter */ \
) x; \
STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) x; \
STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **inStream) x; \
STDMETHOD(SetOperationResult)(Int32 operationResult) x; \
ARCHIVE_INTERFACE_SUB(IArchiveUpdateCallback, IProgress, 0x80)
{
INTERFACE_IArchiveUpdateCallback(PURE);
};
#define INTERFACE_IArchiveUpdateCallback2(x) \
INTERFACE_IArchiveUpdateCallback(x) \
STDMETHOD(GetVolumeSize)(UInt32 index, UInt64 *size) x; \
STDMETHOD(GetVolumeStream)(UInt32 index, ISequentialOutStream **volumeStream) x; \
ARCHIVE_INTERFACE_SUB(IArchiveUpdateCallback2, IArchiveUpdateCallback, 0x82)
{
INTERFACE_IArchiveUpdateCallback2(PURE);
};
#ifndef EXTRACT_ONLY
#define INTERFACE_IOutArchive(x) \
STDMETHOD(UpdateItems)(ISequentialOutStream *outStream, UInt32 numItems, IArchiveUpdateCallback *updateCallback) x; \
STDMETHOD(GetFileTimeType)(UInt32 *type) x;
#else
#define INTERFACE_IOutArchive(x)
#endif
ARCHIVE_INTERFACE(IOutArchive, 0xA0)
{
#ifndef EXTRACT_ONLY
INTERFACE_IOutArchive(PURE)
#endif
};
ARCHIVE_INTERFACE(ISetProperties, 0x03)
{
#ifndef EXTRACT_ONLY
STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties) PURE;
#endif
};
#define IMP_IInArchive_GetProp(k) \
(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) \
{ if(index >= sizeof(k) / sizeof(k[0])) return E_INVALIDARG; \
const STATPROPSTG &srcItem = k[index]; \
*propID = srcItem.propid; *varType = srcItem.vt; *name = 0; return S_OK; } \
#define IMP_IInArchive_GetProp_WITH_NAME(k) \
(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) \
{ if(index >= sizeof(k) / sizeof(k[0])) return E_INVALIDARG; \
const STATPROPSTG &srcItem = k[index]; \
*propID = srcItem.propid; *varType = srcItem.vt; \
if (srcItem.lpwstrName == 0) *name = 0; else *name = ::SysAllocString(srcItem.lpwstrName); return S_OK; } \
#define IMP_IInArchive_Props \
STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties) \
{ *numProperties = sizeof(kProps) / sizeof(kProps[0]); return S_OK; } \
STDMETHODIMP CHandler::GetPropertyInfo IMP_IInArchive_GetProp(kProps)
#define IMP_IInArchive_Props_WITH_NAME \
STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties) \
{ *numProperties = sizeof(kProps) / sizeof(kProps[0]); return S_OK; } \
STDMETHODIMP CHandler::GetPropertyInfo IMP_IInArchive_GetProp_WITH_NAME(kProps)
#define IMP_IInArchive_ArcProps \
STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) \
{ *numProperties = sizeof(kArcProps) / sizeof(kArcProps[0]); return S_OK; } \
STDMETHODIMP CHandler::GetArchivePropertyInfo IMP_IInArchive_GetProp(kArcProps)
#define IMP_IInArchive_ArcProps_WITH_NAME \
STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) \
{ *numProperties = sizeof(kArcProps) / sizeof(kArcProps[0]); return S_OK; } \
STDMETHODIMP CHandler::GetArchivePropertyInfo IMP_IInArchive_GetProp_WITH_NAME(kArcProps)
#define IMP_IInArchive_ArcProps_NO \
STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) \
{ *numProperties = 0; return S_OK; } \
STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32, BSTR *, PROPID *, VARTYPE *) \
{ return E_NOTIMPL; } \
STDMETHODIMP CHandler::GetArchiveProperty(PROPID, PROPVARIANT *value) \
{ value->vt = VT_EMPTY; return S_OK; }
#endif

View File

@ -0,0 +1,27 @@
// LzhCRC.h
#ifndef __LZH_CRC_H
#define __LZH_CRC_H
#include <stddef.h>
#include "Common/Types.h"
namespace NArchive {
namespace NLzh {
class CCRC
{
UInt16 _value;
public:
static UInt16 Table[256];
static void InitTable();
CCRC(): _value(0){};
void Init() { _value = 0; }
void Update(const void *data, size_t size);
UInt16 GetDigest() const { return _value; }
};
}}
#endif

View File

@ -0,0 +1,30 @@
// LzhHandler.h
#ifndef __LZH_HANDLER_H
#define __LZH_HANDLER_H
#include "Common/MyCom.h"
#include "../IArchive.h"
#include "LzhIn.h"
namespace NArchive {
namespace NLzh {
class CHandler:
public IInArchive,
public CMyUnknownImp
{
public:
MY_UNKNOWN_IMP1(IInArchive)
INTERFACE_IInArchive(;)
CHandler();
private:
CObjectVector<CItemEx> _items;
CMyComPtr<IInStream> _stream;
};
}}
#endif

View File

@ -0,0 +1,19 @@
// Archive/Lzh/Header.h
#ifndef __ARCHIVE_LZH_HEADER_H
#define __ARCHIVE_LZH_HEADER_H
#include "Common/Types.h"
namespace NArchive {
namespace NLzh {
const int kMethodIdSize = 5;
const Byte kExtIdFileName = 0x01;
const Byte kExtIdDirName = 0x02;
const Byte kExtIdUnixTime = 0x54;
}}
#endif

View File

@ -0,0 +1,29 @@
// Archive/LzhIn.h
#ifndef __ARCHIVE_LZHIN_H
#define __ARCHIVE_LZHIN_H
#include "Common/MyCom.h"
#include "../../IStream.h"
#include "LzhItem.h"
namespace NArchive {
namespace NLzh {
class CInArchive
{
CMyComPtr<IInStream> m_Stream;
UInt64 m_Position;
HRESULT ReadBytes(void *data, UInt32 size, UInt32 &processedSize);
HRESULT CheckReadBytes(void *data, UInt32 size);
public:
HRESULT Open(IInStream *inStream);
HRESULT GetNextItem(bool &filled, CItemEx &itemInfo);
HRESULT Skeep(UInt64 numBytes);
};
}}
#endif

View File

@ -0,0 +1,172 @@
// Archive/LzhItem.h
#ifndef __ARCHIVE_LZH_ITEM_H
#define __ARCHIVE_LZH_ITEM_H
#include "Common/Types.h"
#include "Common/MyString.h"
#include "Common/Buffer.h"
#include "LzhHeader.h"
namespace NArchive {
namespace NLzh {
struct CExtension
{
Byte Type;
CByteBuffer Data;
AString GetString() const
{
AString s;
for (size_t i = 0; i < Data.GetCapacity(); i++)
{
char c = (char)Data[i];
if (c == 0)
break;
s += c;
}
return s;
}
};
struct CItem
{
public:
AString Name;
Byte Method[kMethodIdSize];
UInt32 PackSize;
UInt32 Size;
UInt32 ModifiedTime;
Byte Attributes;
Byte Level;
UInt16 CRC;
Byte OsId;
CObjectVector<CExtension> Extensions;
bool IsValidMethod() const { return (Method[0] == '-' && Method[1] == 'l' && Method[4] == '-'); }
bool IsLhMethod() const {return (IsValidMethod() && Method[2] == 'h'); }
bool IsDir() const {return (IsLhMethod() && Method[3] == 'd'); }
bool IsCopyMethod() const
{
return (IsLhMethod() && Method[3] == '0') ||
(IsValidMethod() && Method[2] == 'z' && Method[3] == '4');
}
bool IsLh1GroupMethod() const
{
if (!IsLhMethod())
return false;
switch(Method[3])
{
case '1':
return true;
}
return false;
}
bool IsLh4GroupMethod() const
{
if (!IsLhMethod())
return false;
switch(Method[3])
{
case '4':
case '5':
case '6':
case '7':
return true;
}
return false;
}
int GetNumDictBits() const
{
if (!IsLhMethod())
return 0;
switch(Method[3])
{
case '1':
return 12;
case '2':
return 13;
case '3':
return 13;
case '4':
return 12;
case '5':
return 13;
case '6':
return 15;
case '7':
return 16;
}
return 0;
}
int FindExt(Byte type) const
{
for (int i = 0; i < Extensions.Size(); i++)
if (Extensions[i].Type == type)
return i;
return -1;
}
bool GetUnixTime(UInt32 &value) const
{
int index = FindExt(kExtIdUnixTime);
if (index < 0)
{
if (Level == 2)
{
value = ModifiedTime;
return true;
}
return false;
}
const Byte *data = (const Byte *)(Extensions[index].Data);
value = data[0] |
((UInt32)data[1] << 8) |
((UInt32)data[2] << 16) |
((UInt32)data[3] << 24);
return true;
}
AString GetDirName() const
{
int index = FindExt(kExtIdDirName);
if (index < 0)
return AString();
return Extensions[index].GetString();
}
AString GetFileName() const
{
int index = FindExt(kExtIdFileName);
if (index < 0)
return Name;
return Extensions[index].GetString();
}
AString GetName() const
{
AString dirName = GetDirName();
dirName.Replace((char)(unsigned char)0xFF, '\\');
if (!dirName.IsEmpty())
{
char c = dirName[dirName.Length() - 1];
if (c != '\\')
dirName += '\\';
}
return dirName + GetFileName();
}
};
class CItemEx: public CItem
{
public:
UInt64 DataPosition;
};
}}
#endif

View File

@ -0,0 +1,38 @@
// LzhOutStreamWithCRC.h
#ifndef __LZHOUTSTREAMWITHCRC_H
#define __LZHOUTSTREAMWITHCRC_H
#include "LzhCRC.h"
#include "../../../Common/MyCom.h"
#include "../../IStream.h"
namespace NArchive {
namespace NLzh {
class COutStreamWithCRC:
public ISequentialOutStream,
public CMyUnknownImp
{
public:
MY_UNKNOWN_IMP
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
private:
CCRC _crc;
CMyComPtr<ISequentialOutStream> _stream;
public:
void Init(ISequentialOutStream *stream)
{
_stream = stream;
_crc.Init();
}
void ReleaseStream() { _stream.Release(); }
UInt32 GetCRC() const { return _crc.GetDigest(); }
void InitCRC() { _crc.Init(); }
};
}}
#endif

View File

@ -0,0 +1,8 @@
// StdAfx.h
#ifndef __STDAFX_H
#define __STDAFX_H
#include "../../../Common/MyWindows.h"
#endif

View File

@ -0,0 +1,26 @@
// LzmaFiltersDecode.h
#ifndef __LZMA_FILTERS_DECODE_H
#define __LZMA_FILTERS_DECODE_H
#include "../../Common/CreateCoder.h"
#include "LzmaItem.h"
namespace NArchive {
namespace NLzma {
class CDecoder
{
CMyComPtr<ICompressCoder> _lzmaDecoder;
CMyComPtr<ISequentialOutStream> _bcjStream;
public:
HRESULT Code(DECL_EXTERNAL_CODECS_LOC_VARS
const CHeader &block,
ISequentialInStream *inStream, ISequentialOutStream *outStream,
UInt64 *inProcessedSize, ICompressProgressInfo *progress);
};
}}
#endif

View File

@ -0,0 +1,69 @@
// Lzma/Handler.h
#ifndef __GZIP_HANDLER_H
#define __GZIP_HANDLER_H
#include "Common/MyCom.h"
#include "../IArchive.h"
#include "../../Common/CreateCoder.h"
#include "LzmaIn.h"
namespace NArchive {
namespace NLzma {
// const UInt64 k_LZMA = 0x030101;
class CHandler:
public IInArchive,
PUBLIC_ISetCompressCodecsInfo
public CMyUnknownImp
{
public:
MY_QUERYINTERFACE_BEGIN
MY_QUERYINTERFACE_ENTRY(IInArchive)
QUERY_ENTRY_ISetCompressCodecsInfo
MY_QUERYINTERFACE_END
MY_ADDREF_RELEASE
STDMETHOD(Open)(IInStream *inStream,
const UInt64 *maxCheckStartPosition,
IArchiveOpenCallback *openArchiveCallback);
STDMETHOD(Close)();
STDMETHOD(GetNumberOfItems)(UInt32 *numItems);
STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value);
STDMETHOD(Extract)(const UInt32* indices, UInt32 numItems,
Int32 testMode, IArchiveExtractCallback *extractCallback);
STDMETHOD(GetArchiveProperty)(PROPID propID, PROPVARIANT *value);
STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties);
STDMETHOD(GetPropertyInfo)(UInt32 index,
BSTR *name, PROPID *propID, VARTYPE *varType);
STDMETHOD(GetNumberOfArchiveProperties)(UInt32 *numProperties);
STDMETHOD(GetArchivePropertyInfo)(UInt32 index,
BSTR *name, PROPID *propID, VARTYPE *varType);
UString GetMethodString();
public:
CHandler() { }
private:
CHeader m_StreamInfo;
UInt64 m_StreamStartPosition;
UInt64 m_PackSize;
CMyComPtr<IInStream> m_Stream;
DECL_EXTERNAL_CODECS_VARS
DECL_ISetCompressCodecsInfo
};
}}
#endif

View File

@ -0,0 +1,16 @@
// Archive/LzmaIn.h
#ifndef __ARCHIVE_LZMA_IN_H
#define __ARCHIVE_LZMA_IN_H
#include "LzmaItem.h"
#include "../../IStream.h"
namespace NArchive {
namespace NLzma {
HRESULT ReadStreamHeader(ISequentialInStream *inStream, CHeader &st);
}}
#endif

View File

@ -0,0 +1,27 @@
// Archive/LzmaItem.h
#ifndef __ARCHIVE_LZMA_ITEM_H
#define __ARCHIVE_LZMA_ITEM_H
#include "Common/Types.h"
#include "../../../../C/CpuArch.h"
namespace NArchive {
namespace NLzma {
struct CHeader
{
UInt64 UnpackSize;
bool IsThereFilter;
Byte FilterMethod;
Byte LzmaProps[5];
UInt32 GetDicSize() const { return GetUi32(LzmaProps + 1); }
bool HasUnpackSize() const { return (UnpackSize != (UInt64)(Int64)-1); }
unsigned GetHeaderSize() const { return 5 + 8 + (IsThereFilter ? 1 : 0); }
};
}}
#endif

View File

@ -0,0 +1,8 @@
// StdAfx.h
#ifndef __STDAFX_H
#define __STDAFX_H
#include "../../../Common/MyWindows.h"
#endif

View File

@ -0,0 +1,60 @@
// Rar/Handler.h
#ifndef __RAR_HANDLER_H
#define __RAR_HANDLER_H
#include "../IArchive.h"
#include "RarIn.h"
#include "RarVolumeInStream.h"
#include "../../Common/CreateCoder.h"
namespace NArchive {
namespace NRar {
class CHandler:
public IInArchive,
PUBLIC_ISetCompressCodecsInfo
public CMyUnknownImp
{
public:
MY_QUERYINTERFACE_BEGIN2(IInArchive)
QUERY_ENTRY_ISetCompressCodecsInfo
MY_QUERYINTERFACE_END
MY_ADDREF_RELEASE
INTERFACE_IInArchive(;)
DECL_ISetCompressCodecsInfo
private:
CRecordVector<CRefItem> _refItems;
CObjectVector<CItemEx> _items;
CObjectVector<CInArchive> _archives;
NArchive::NRar::CInArchiveInfo _archiveInfo;
DECL_EXTERNAL_CODECS_VARS
UInt64 GetPackSize(int refIndex) const;
// NArchive::NRar::CInArchive _archive;
bool IsSolid(int refIndex)
{
const CItemEx &item = _items[_refItems[refIndex].ItemIndex];
if (item.UnPackVersion < 20)
{
if (_archiveInfo.IsSolid())
return (refIndex > 0);
return false;
}
return item.IsSolid();
}
HRESULT Open2(IInStream *stream,
const UInt64 *maxCheckStartPosition,
IArchiveOpenCallback *openArchiveCallback);
};
}}
#endif

View File

@ -0,0 +1,224 @@
// Archive/RarHeader.h
#ifndef __ARCHIVE_RAR_HEADER_H
#define __ARCHIVE_RAR_HEADER_H
#include "Common/Types.h"
namespace NArchive{
namespace NRar{
namespace NHeader{
const int kMarkerSize = 7;
extern Byte kMarker[kMarkerSize];
const int kArchiveSolid = 0x1;
namespace NBlockType
{
enum EBlockType
{
kMarker = 0x72,
kArchiveHeader = 0x73,
kFileHeader = 0x74,
kCommentHeader = 0x75,
kOldAuthenticity = 0x76,
kSubBlock = 0x77,
kRecoveryRecord = 0x78,
kAuthenticity = 0x79,
kEndOfArchive = 0x7B // Is not safe
};
}
namespace NArchive
{
const UInt16 kVolume = 1;
const UInt16 kComment = 2;
const UInt16 kLock = 4;
const UInt16 kSolid = 8;
const UInt16 kNewVolName = 0x10; // ('volname.partN.rar')
const UInt16 kAuthenticity = 0x20;
const UInt16 kRecovery = 0x40;
const UInt16 kBlockEncryption = 0x80;
const UInt16 kFirstVolume = 0x100; // (set only by RAR 3.0 and later)
const UInt16 kEncryptVer = 0x200; // RAR 3.6 there is EncryptVer Byte in End of MainHeader
const int kHeaderSizeMin = 7;
struct CBlock
{
UInt16 CRC;
Byte Type;
UInt16 Flags;
UInt16 Size;
UInt16 Reserved1;
UInt32 Reserved2;
// UInt16 GetRealCRC() const;
};
const int kArchiveHeaderSize = 13;
const int kBlockHeadersAreEncrypted = 0x80;
struct CHeader360: public CBlock
{
Byte EncryptVersion;
bool IsEncrypted() const { return (Flags & NHeader::NArchive::kBlockEncryption) != 0; }
bool IsThereEncryptVer() const { return (Flags & NHeader::NArchive::kEncryptVer) != 0; }
bool IsEncryptOld() const { return (!IsThereEncryptVer() || EncryptVersion < 36); }
UInt32 GetBaseSize() const { return kArchiveHeaderSize + (IsEncryptOld() ? 0 : 1); }
};
}
namespace NFile
{
const int kSplitBefore = 1 << 0;
const int kSplitAfter = 1 << 1;
const int kEncrypted = 1 << 2;
const int kComment = 1 << 3;
const int kSolid = 1 << 4;
const int kDictBitStart = 5;
const int kNumDictBits = 3;
const int kDictMask = (1 << kNumDictBits) - 1;
const int kDictDirectoryValue = 0x7;
const int kSize64Bits = 1 << 8;
const int kUnicodeName = 1 << 9;
const int kSalt = 1 << 10;
const int kOldVersion = 1 << 11;
const int kExtTime = 1 << 12;
// const int kExtFlags = 1 << 13;
// const int kSkipIfUnknown = 1 << 14;
const int kLongBlock = 1 << 15;
/*
struct CBlock
{
// UInt16 HeadCRC;
// Byte Type;
// UInt16 Flags;
// UInt16 HeadSize;
UInt32 PackSize;
UInt32 UnPackSize;
Byte HostOS;
UInt32 FileCRC;
UInt32 Time;
Byte UnPackVersion;
Byte Method;
UInt16 NameSize;
UInt32 Attributes;
};
*/
/*
struct CBlock32
{
UInt16 HeadCRC;
Byte Type;
UInt16 Flags;
UInt16 HeadSize;
UInt32 PackSize;
UInt32 UnPackSize;
Byte HostOS;
UInt32 FileCRC;
UInt32 Time;
Byte UnPackVersion;
Byte Method;
UInt16 NameSize;
UInt32 Attributes;
UInt16 GetRealCRC(const void *aName, UInt32 aNameSize,
bool anExtraDataDefined = false, Byte *anExtraData = 0) const;
};
struct CBlock64
{
UInt16 HeadCRC;
Byte Type;
UInt16 Flags;
UInt16 HeadSize;
UInt32 PackSizeLow;
UInt32 UnPackSizeLow;
Byte HostOS;
UInt32 FileCRC;
UInt32 Time;
Byte UnPackVersion;
Byte Method;
UInt16 NameSize;
UInt32 Attributes;
UInt32 PackSizeHigh;
UInt32 UnPackSizeHigh;
UInt16 GetRealCRC(const void *aName, UInt32 aNameSize) const;
};
*/
const int kLabelFileAttribute = 0x08;
const int kWinFileDirectoryAttributeMask = 0x10;
enum CHostOS
{
kHostMSDOS = 0,
kHostOS2 = 1,
kHostWin32 = 2,
kHostUnix = 3,
kHostMacOS = 4,
kHostBeOS = 5
};
}
namespace NBlock
{
const UInt16 kLongBlock = 1 << 15;
struct CBlock
{
UInt16 CRC;
Byte Type;
UInt16 Flags;
UInt16 HeadSize;
// UInt32 DataSize;
};
}
/*
struct CSubBlock
{
UInt16 HeadCRC;
Byte HeadType;
UInt16 Flags;
UInt16 HeadSize;
UInt32 DataSize;
UInt16 SubType;
Byte Level; // Reserved : Must be 0
};
struct CCommentBlock
{
UInt16 HeadCRC;
Byte HeadType;
UInt16 Flags;
UInt16 HeadSize;
UInt16 UnpSize;
Byte UnpVer;
Byte Method;
UInt16 CommCRC;
};
struct CProtectHeader
{
UInt16 HeadCRC;
Byte HeadType;
UInt16 Flags;
UInt16 HeadSize;
UInt32 DataSize;
Byte Version;
UInt16 RecSectors;
UInt32 TotalBlocks;
Byte Mark[8];
};
*/
}}}
#endif

View File

@ -0,0 +1,126 @@
// RarIn.h
#ifndef __ARCHIVE_RAR_IN_H
#define __ARCHIVE_RAR_IN_H
#include "Common/DynamicBuffer.h"
#include "Common/MyCom.h"
#include "../../ICoder.h"
#include "../../IStream.h"
#include "../../Common/StreamObjects.h"
#include "../../Crypto/RarAes.h"
#include "RarHeader.h"
#include "RarItem.h"
namespace NArchive {
namespace NRar {
class CInArchiveException
{
public:
enum CCauseType
{
kUnexpectedEndOfArchive = 0,
kArchiveHeaderCRCError,
kFileHeaderCRCError,
kIncorrectArchive
}
Cause;
CInArchiveException(CCauseType cause) : Cause(cause) {}
};
class CInArchiveInfo
{
public:
UInt64 StartPosition;
UInt16 Flags;
UInt64 CommentPosition;
UInt16 CommentSize;
bool IsSolid() const { return (Flags & NHeader::NArchive::kSolid) != 0; }
bool IsCommented() const { return (Flags & NHeader::NArchive::kComment) != 0; }
bool IsVolume() const { return (Flags & NHeader::NArchive::kVolume) != 0; }
bool HaveNewVolumeName() const { return (Flags & NHeader::NArchive::kNewVolName) != 0; }
bool IsEncrypted() const { return (Flags & NHeader::NArchive::kBlockEncryption) != 0; }
};
class CInArchive
{
CMyComPtr<IInStream> m_Stream;
UInt64 m_StreamStartPosition;
UInt64 m_Position;
UInt64 m_ArchiveStartPosition;
NHeader::NArchive::CHeader360 m_ArchiveHeader;
CDynamicBuffer<char> m_NameBuffer;
CDynamicBuffer<wchar_t> _unicodeNameBuffer;
bool m_SeekOnArchiveComment;
UInt64 m_ArchiveCommentPosition;
void ReadName(CItemEx &item, int nameSize);
void ReadHeaderReal(CItemEx &item);
HRESULT ReadBytes(void *data, UInt32 size, UInt32 *aProcessedSize);
bool ReadBytesAndTestSize(void *data, UInt32 size);
void ReadBytesAndTestResult(void *data, UInt32 size);
HRESULT FindAndReadMarker(IInStream *stream, const UInt64 *searchHeaderSizeLimit);
HRESULT Open2(IInStream *stream, const UInt64 *searchHeaderSizeLimit);
void ThrowExceptionWithCode(CInArchiveException::CCauseType cause);
void ThrowUnexpectedEndOfArchiveException();
void AddToSeekValue(UInt64 addValue);
protected:
CDynamicBuffer<Byte> m_FileHeaderData;
NHeader::NBlock::CBlock m_BlockHeader;
NCrypto::NRar29::CDecoder *m_RarAESSpec;
CMyComPtr<ICompressFilter> m_RarAES;
Byte *m_CurData; // it must point to start of Rar::Block
UInt32 m_CurPos;
UInt32 m_PosLimit;
Byte ReadByte();
UInt16 ReadUInt16();
UInt32 ReadUInt32();
void ReadTime(Byte mask, CRarTime &rarTime);
CBuffer<Byte> m_DecryptedData;
UInt32 m_DecryptedDataSize;
bool m_CryptoMode;
UInt32 m_CryptoPos;
void FinishCryptoBlock()
{
if (m_CryptoMode)
while ((m_CryptoPos & 0xF) != 0)
{
m_CryptoPos++;
m_Position++;
}
}
public:
HRESULT Open(IInStream *inStream, const UInt64 *searchHeaderSizeLimit);
void Close();
HRESULT GetNextItem(CItemEx &item, ICryptoGetTextPassword *getTextPassword);
void SkipArchiveComment();
void GetArchiveInfo(CInArchiveInfo &archiveInfo) const;
bool SeekInArchive(UInt64 position);
ISequentialInStream *CreateLimitedStream(UInt64 position, UInt64 size);
};
}}
#endif

View File

@ -0,0 +1,79 @@
// RarItem.h
#ifndef __ARCHIVE_RAR_ITEM_H
#define __ARCHIVE_RAR_ITEM_H
#include "Common/Types.h"
#include "Common/MyString.h"
#include "RarHeader.h"
namespace NArchive{
namespace NRar{
struct CRarTime
{
UInt32 DosTime;
Byte LowSecond;
Byte SubTime[3];
};
struct CItem
{
UInt64 Size;
UInt64 PackSize;
CRarTime CTime;
CRarTime ATime;
CRarTime MTime;
UInt32 FileCRC;
UInt32 Attrib;
UInt16 Flags;
Byte HostOS;
Byte UnPackVersion;
Byte Method;
bool CTimeDefined;
bool ATimeDefined;
AString Name;
UString UnicodeName;
Byte Salt[8];
bool IsEncrypted() const { return (Flags & NHeader::NFile::kEncrypted) != 0; }
bool IsSolid() const { return (Flags & NHeader::NFile::kSolid) != 0; }
bool IsCommented() const { return (Flags & NHeader::NFile::kComment) != 0; }
bool IsSplitBefore() const { return (Flags & NHeader::NFile::kSplitBefore) != 0; }
bool IsSplitAfter() const { return (Flags & NHeader::NFile::kSplitAfter) != 0; }
bool HasSalt() const { return (Flags & NHeader::NFile::kSalt) != 0; }
bool HasExtTime() const { return (Flags & NHeader::NFile::kExtTime) != 0; }
bool HasUnicodeName()const { return (Flags & NHeader::NFile::kUnicodeName) != 0; }
bool IsOldVersion() const { return (Flags & NHeader::NFile::kOldVersion) != 0; }
UInt32 GetDictSize() const { return (Flags >> NHeader::NFile::kDictBitStart) & NHeader::NFile::kDictMask; }
bool IsDir() const;
bool IgnoreItem() const;
UInt32 GetWinAttributes() const;
CItem(): CTimeDefined(false), ATimeDefined(false) {}
};
class CItemEx: public CItem
{
public:
UInt64 Position;
UInt16 MainPartSize;
UInt16 CommentSize;
UInt16 AlignSize;
UInt64 GetFullSize() const { return MainPartSize + CommentSize + AlignSize + PackSize; };
// DWORD GetHeaderWithCommentSize() const { return MainPartSize + CommentSize; };
UInt64 GetCommentPosition() const { return Position + MainPartSize; };
UInt64 GetDataPosition() const { return GetCommentPosition() + CommentSize + AlignSize; };
};
}}
#endif

View File

@ -0,0 +1,49 @@
// RarVolumeInStream.h
#ifndef __RAR_VOLUME_IN_STREAM_H
#define __RAR_VOLUME_IN_STREAM_H
#include "../../IStream.h"
#include "RarIn.h"
namespace NArchive {
namespace NRar {
struct CRefItem
{
int VolumeIndex;
int ItemIndex;
int NumItems;
};
class CFolderInStream:
public ISequentialInStream,
public CMyUnknownImp
{
public:
MY_UNKNOWN_IMP
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
private:
CObjectVector<CInArchive> *_archives;
const CObjectVector<CItemEx> *_items;
CRefItem _refItem;
int _curIndex;
UInt32 _crc;
bool _fileIsOpen;
CMyComPtr<ISequentialInStream> _stream;
HRESULT OpenStream();
HRESULT CloseStream();
public:
void Init(CObjectVector<CInArchive> *archives,
const CObjectVector<CItemEx> *items,
const CRefItem &refItem);
CRecordVector<UInt32> CRCs;
};
}}
#endif

View File

@ -0,0 +1,8 @@
// StdAfx.h
#ifndef __STDAFX_H
#define __STDAFX_H
#include "../../../Common/MyWindows.h"
#endif

View File

@ -0,0 +1,37 @@
// Split/Handler.h
#ifndef __SPLIT_HANDLER_H
#define __SPLIT_HANDLER_H
#include "Common/MyCom.h"
#include "Common/MyString.h"
#include "../IArchive.h"
namespace NArchive {
namespace NSplit {
class CHandler:
public IInArchive,
public IInArchiveGetStream,
// public IOutArchive,
public CMyUnknownImp
{
public:
MY_UNKNOWN_IMP2(IInArchive, IInArchiveGetStream)
INTERFACE_IInArchive(;)
STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);
private:
UString _subName;
UString _name;
CObjectVector<CMyComPtr<IInStream> > _streams;
CRecordVector<UInt64> _sizes;
UInt64 _totalSize;
};
}}
#endif

View File

@ -0,0 +1,8 @@
// StdAfx.h
#ifndef __STDAFX_H
#define __STDAFX_H
#include "../../../Common/MyWindows.h"
#endif

View File

@ -0,0 +1,9 @@
// StdAfx.h
#ifndef __STDAFX_H
#define __STDAFX_H
#include "../../Common/MyWindows.h"
#include "../../Common/NewHandler.h"
#endif

View File

@ -0,0 +1,9 @@
// StdAfx.h
#ifndef __STDAFX_H
#define __STDAFX_H
#include "../../../Common/MyWindows.h"
#include "../../../Common/NewHandler.h"
#endif

View File

@ -0,0 +1,37 @@
// Tar/Handler.h
#ifndef __TAR_HANDLER_H
#define __TAR_HANDLER_H
#include "Common/MyCom.h"
#include "../IArchive.h"
#include "TarItem.h"
namespace NArchive {
namespace NTar {
class CHandler:
public IInArchive,
public IOutArchive,
public CMyUnknownImp
{
public:
MY_UNKNOWN_IMP2(
IInArchive,
IOutArchive
)
INTERFACE_IInArchive(;)
INTERFACE_IOutArchive(;)
HRESULT Open2(IInStream *stream, IArchiveOpenCallback *callback);
private:
CObjectVector<CItemEx> _items;
CMyComPtr<IInStream> _inStream;
};
}}
#endif

View File

@ -0,0 +1,108 @@
// Archive/Tar/Header.h
#ifndef __ARCHIVE_TAR_HEADER_H
#define __ARCHIVE_TAR_HEADER_H
#include "Common/Types.h"
namespace NArchive {
namespace NTar {
namespace NFileHeader
{
const int kRecordSize = 512;
const int kNameSize = 100;
const int kUserNameSize = 32;
const int kGroupNameSize = 32;
const int kPrefixSize = 155;
/*
struct CHeader
{
char Name[kNameSize];
char Mode[8];
char UID[8];
char GID[8];
char Size[12];
char ModificationTime[12];
char CheckSum[8];
char LinkFlag;
char LinkName[kNameSize];
char Magic[8];
char UserName[kUserNameSize];
char GroupName[kGroupNameSize];
char DeviceMajor[8];
char DeviceMinor[8];
char Prefix[155];
};
union CRecord
{
CHeader Header;
Byte Padding[kRecordSize];
};
*/
namespace NMode
{
const int kSetUID = 04000; // Set UID on execution
const int kSetGID = 02000; // Set GID on execution
const int kSaveText = 01000; // Save text (sticky bit)
}
namespace NFilePermissions
{
const int kUserRead = 00400; // read by owner
const int kUserWrite = 00200; // write by owner
const int kUserExecute = 00100; // execute/search by owner
const int kGroupRead = 00040; // read by group
const int kGroupWrite = 00020; // write by group
const int kGroupExecute = 00010; // execute/search by group
const int kOtherRead = 00004; // read by other
const int kOtherWrite = 00002; // write by other
const int kOtherExecute = 00001; // execute/search by other
}
// The linkflag defines the type of file
namespace NLinkFlag
{
const char kOldNormal = '\0'; // Normal disk file, Unix compatible
const char kNormal = '0'; // Normal disk file
const char kLink = '1'; // Link to previously dumped file
const char kSymbolicLink = '2'; // Symbolic link
const char kCharacter = '3'; // Character special file
const char kBlock = '4'; // Block special file
const char kDirectory = '5'; // Directory
const char kFIFO = '6'; // FIFO special file
const char kContiguous = '7'; // Contiguous file
const char kDumpDir = 'D'; /* GNUTYPE_DUMPDIR.
data: list of files created by the --incremental (-G) option
Each file name is preceded by either
- 'Y' (file should be in this archive)
- 'N' (file is a directory, or is not stored in the archive.)
Each file name is terminated by a null + an additional null after
the last file name. */
}
// Further link types may be defined later.
// The checksum field is filled with this while the checksum is computed.
extern const char *kCheckSumBlanks;// = " "; // 8 blanks, no null
extern const char *kLongLink; // = "././@LongLink";
extern const char *kLongLink2; // = "@LongLink";
// The magic field is filled with this if uname and gname are valid.
namespace NMagic
{
extern const char *kUsTar; // = "ustar"; // 5 chars
extern const char *kGNUTar; // = "GNUtar "; // 7 chars and a null
extern const char *kEmpty; // = "GNUtar "; // 7 chars and a null
}
}
}}
#endif

View File

@ -0,0 +1,18 @@
// Archive/TarIn.h
#ifndef __ARCHIVE_TAR_IN_H
#define __ARCHIVE_TAR_IN_H
#include "Common/MyCom.h"
#include "../../IStream.h"
#include "TarItem.h"
namespace NArchive {
namespace NTar {
HRESULT ReadItem(ISequentialInStream *stream, bool &filled, CItemEx &itemInfo);
}}
#endif

View File

@ -0,0 +1,71 @@
// Archive/Tar/Item.h
#ifndef __ARCHIVE_TAR_ITEM_H
#define __ARCHIVE_TAR_ITEM_H
#include "Common/Types.h"
#include "Common/MyString.h"
#include "../Common/ItemNameUtils.h"
#include "TarHeader.h"
namespace NArchive {
namespace NTar {
struct CItem
{
AString Name;
UInt64 Size;
UInt32 Mode;
UInt32 UID;
UInt32 GID;
UInt32 MTime;
UInt32 DeviceMajor;
UInt32 DeviceMinor;
AString LinkName;
AString UserName;
AString GroupName;
char Magic[8];
char LinkFlag;
bool DeviceMajorDefined;
bool DeviceMinorDefined;
bool IsDir() const
{
switch(LinkFlag)
{
case NFileHeader::NLinkFlag::kDirectory:
case NFileHeader::NLinkFlag::kDumpDir:
return true;
case NFileHeader::NLinkFlag::kOldNormal:
case NFileHeader::NLinkFlag::kNormal:
return NItemName::HasTailSlash(Name, CP_OEMCP);
}
return false;
}
bool IsMagic() const
{
for (int i = 0; i < 5; i++)
if (Magic[i] != NFileHeader::NMagic::kUsTar[i])
return false;
return true;
}
UInt64 GetPackSize() const { return (Size + 0x1FF) & (~((UInt64)0x1FF)); }
};
struct CItemEx: public CItem
{
UInt64 HeaderPosition;
unsigned LongLinkSize;
UInt64 GetDataPosition() const { return HeaderPosition + LongLinkSize + NFileHeader::kRecordSize; }
UInt64 GetFullSize() const { return LongLinkSize + NFileHeader::kRecordSize + Size; }
};
}}
#endif

View File

@ -0,0 +1,8 @@
// StdAfx.h
#ifndef __STDAFX_H
#define __STDAFX_H
#include "../../../Common/MyWindows.h"
#endif

View File

@ -0,0 +1,39 @@
// CompressionMode.h
#ifndef __ZIP_COMPRESSIONMETHOD_H
#define __ZIP_COMPRESSIONMETHOD_H
#include "../../../Common/MyString.h"
namespace NArchive {
namespace NZip {
struct CCompressionMethodMode
{
CRecordVector<Byte> MethodSequence;
UString MatchFinder;
UInt32 Algo;
UInt32 NumPasses;
UInt32 NumFastBytes;
bool NumMatchFinderCyclesDefined;
UInt32 NumMatchFinderCycles;
UInt32 DicSize;
#ifdef COMPRESS_MT
UInt32 NumThreads;
#endif
bool PasswordIsDefined;
AString Password;
bool IsAesMode;
Byte AesKeyMode;
CCompressionMethodMode():
NumMatchFinderCyclesDefined(false),
PasswordIsDefined(false),
IsAesMode(false),
AesKeyMode(3)
{}
};
}}
#endif

View File

@ -0,0 +1,100 @@
// Zip/Handler.h
#ifndef __ZIP_HANDLER_H
#define __ZIP_HANDLER_H
#include "../../../Common/DynamicBuffer.h"
#include "../../ICoder.h"
#include "../IArchive.h"
#include "../../Common/CreateCoder.h"
#include "ZipIn.h"
#include "ZipCompressionMode.h"
#ifdef COMPRESS_MT
#include "../../../Windows/System.h"
#endif
namespace NArchive {
namespace NZip {
class CHandler:
public IInArchive,
#ifndef EXTRACT_ONLY
public IOutArchive,
public ISetProperties,
PUBLIC_ISetCompressCodecsInfo
#endif
public CMyUnknownImp
{
public:
MY_QUERYINTERFACE_BEGIN2(IInArchive)
#ifndef EXTRACT_ONLY
MY_QUERYINTERFACE_ENTRY(IOutArchive)
MY_QUERYINTERFACE_ENTRY(ISetProperties)
QUERY_ENTRY_ISetCompressCodecsInfo
#endif
MY_QUERYINTERFACE_END
MY_ADDREF_RELEASE
INTERFACE_IInArchive(;)
#ifndef EXTRACT_ONLY
INTERFACE_IOutArchive(;)
STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties);
DECL_ISetCompressCodecsInfo
#endif
CHandler();
private:
CObjectVector<CItemEx> m_Items;
CInArchive m_Archive;
int m_Level;
int m_MainMethod;
UInt32 m_DicSize;
UInt32 m_Algo;
UInt32 m_NumPasses;
UInt32 m_NumFastBytes;
UInt32 m_NumMatchFinderCycles;
bool m_NumMatchFinderCyclesDefined;
bool m_IsAesMode;
Byte m_AesKeyMode;
bool m_WriteNtfsTimeExtra;
bool m_ForseLocal;
bool m_ForseUtf8;
#ifdef COMPRESS_MT
UInt32 _numThreads;
#endif
DECL_EXTERNAL_CODECS_VARS
void InitMethodProperties()
{
m_Level = -1;
m_MainMethod = -1;
m_Algo =
m_DicSize =
m_NumPasses =
m_NumFastBytes =
m_NumMatchFinderCycles = 0xFFFFFFFF;
m_NumMatchFinderCyclesDefined = false;
m_IsAesMode = false;
m_AesKeyMode = 3; // aes-256
m_WriteNtfsTimeExtra = false;
m_ForseLocal = false;
m_ForseUtf8 = false;
#ifdef COMPRESS_MT
_numThreads = NWindows::NSystem::GetNumberOfProcessors();;
#endif
}
};
}}
#endif

View File

@ -0,0 +1,265 @@
// Archive/Zip/Header.h
#ifndef __ARCHIVE_ZIP_HEADER_H
#define __ARCHIVE_ZIP_HEADER_H
#include "../../../Common/Types.h"
namespace NArchive {
namespace NZip {
namespace NSignature
{
extern UInt32 kLocalFileHeader;
extern UInt32 kDataDescriptor;
extern UInt32 kCentralFileHeader;
extern UInt32 kEndOfCentralDir;
extern UInt32 kZip64EndOfCentralDir;
extern UInt32 kZip64EndOfCentralDirLocator;
static const UInt32 kMarkerSize = 4;
}
const UInt32 kEcdSize = 22;
const UInt32 kZip64EcdSize = 44;
const UInt32 kZip64EcdLocatorSize = 20;
/*
struct CEndOfCentralDirectoryRecord
{
UInt16 ThisDiskNumber;
UInt16 StartCentralDirectoryDiskNumber;
UInt16 NumEntriesInCentaralDirectoryOnThisDisk;
UInt16 NumEntriesInCentaralDirectory;
UInt32 CentralDirectorySize;
UInt32 CentralDirectoryStartOffset;
UInt16 CommentSize;
};
struct CEndOfCentralDirectoryRecordFull
{
UInt32 Signature;
CEndOfCentralDirectoryRecord Header;
};
*/
namespace NFileHeader
{
/*
struct CVersion
{
Byte Version;
Byte HostOS;
};
*/
namespace NCompressionMethod
{
enum EType
{
kStored = 0,
kShrunk = 1,
kReduced1 = 2,
kReduced2 = 3,
kReduced3 = 4,
kReduced4 = 5,
kImploded = 6,
kReservedTokenizing = 7, // reserved for tokenizing
kDeflated = 8,
kDeflated64 = 9,
kPKImploding = 10,
kBZip2 = 12,
kLZMA = 14,
kTerse = 18,
kLz77 = 19,
kJpeg = 0x60,
kWavPack = 0x61,
kPPMd = 0x62,
kWzAES = 0x63
};
const int kNumCompressionMethods = 11;
const Byte kMadeByProgramVersion = 20;
const Byte kDeflateExtractVersion = 20;
const Byte kStoreExtractVersion = 10;
const Byte kSupportedVersion = 20;
}
namespace NExtraID
{
enum
{
kZip64 = 0x01,
kNTFS = 0x0A,
kStrongEncrypt = 0x17,
kWzAES = 0x9901
};
}
namespace NNtfsExtra
{
const UInt16 kTagTime = 1;
enum
{
kMTime = 0,
kATime = 1,
kCTime = 2
};
}
const UInt32 kLocalBlockSize = 26;
/*
struct CLocalBlock
{
CVersion ExtractVersion;
UInt16 Flags;
UInt16 CompressionMethod;
UInt32 Time;
UInt32 FileCRC;
UInt32 PackSize;
UInt32 UnPackSize;
UInt16 NameSize;
UInt16 ExtraSize;
};
*/
const UInt32 kDataDescriptorSize = 16;
// const UInt32 kDataDescriptor64Size = 16 + 8;
/*
struct CDataDescriptor
{
UInt32 Signature;
UInt32 FileCRC;
UInt32 PackSize;
UInt32 UnPackSize;
};
struct CLocalBlockFull
{
UInt32 Signature;
CLocalBlock Header;
};
*/
const UInt32 kCentralBlockSize = 42;
/*
struct CBlock
{
CVersion MadeByVersion;
CVersion ExtractVersion;
UInt16 Flags;
UInt16 CompressionMethod;
UInt32 Time;
UInt32 FileCRC;
UInt32 PackSize;
UInt32 UnPackSize;
UInt16 NameSize;
UInt16 ExtraSize;
UInt16 CommentSize;
UInt16 DiskNumberStart;
UInt16 InternalAttributes;
UInt32 ExternalAttributes;
UInt32 LocalHeaderOffset;
};
struct CBlockFull
{
UInt32 Signature;
CBlock Header;
};
*/
namespace NFlags
{
const int kEncrypted = 1 << 0;
const int kLzmaEOS = 1 << 1;
const int kDescriptorUsedMask = 1 << 3;
const int kStrongEncrypted = 1 << 6;
const int kUtf8 = 1 << 11;
const int kImplodeDictionarySizeMask = 1 << 1;
const int kImplodeLiteralsOnMask = 1 << 2;
const int kDeflateTypeBitStart = 1;
const int kNumDeflateTypeBits = 2;
const int kNumDeflateTypes = (1 << kNumDeflateTypeBits);
const int kDeflateTypeMask = (1 << kNumDeflateTypeBits) - 1;
}
namespace NHostOS
{
enum EEnum
{
kFAT = 0,
kAMIGA = 1,
kVMS = 2, // VAX/VMS
kUnix = 3,
kVM_CMS = 4,
kAtari = 5, // what if it's a minix filesystem? [cjh]
kHPFS = 6, // filesystem used by OS/2 (and NT 3.x)
kMac = 7,
kZ_System = 8,
kCPM = 9,
kTOPS20 = 10, // pkzip 2.50 NTFS
kNTFS = 11, // filesystem used by Windows NT
kQDOS = 12, // SMS/QDOS
kAcorn = 13, // Archimedes Acorn RISC OS
kVFAT = 14, // filesystem used by Windows 95, NT
kMVS = 15,
kBeOS = 16, // hybrid POSIX/database filesystem
kTandem = 17,
kOS400 = 18,
kOSX = 19
};
}
namespace NUnixAttribute
{
const UInt32 kIFMT = 0170000; /* Unix file type mask */
const UInt32 kIFDIR = 0040000; /* Unix directory */
const UInt32 kIFREG = 0100000; /* Unix regular file */
const UInt32 kIFSOCK = 0140000; /* Unix socket (BSD, not SysV or Amiga) */
const UInt32 kIFLNK = 0120000; /* Unix symbolic link (not SysV, Amiga) */
const UInt32 kIFBLK = 0060000; /* Unix block special (not Amiga) */
const UInt32 kIFCHR = 0020000; /* Unix character special (not Amiga) */
const UInt32 kIFIFO = 0010000; /* Unix fifo (BCC, not MSC or Amiga) */
const UInt32 kISUID = 04000; /* Unix set user id on execution */
const UInt32 kISGID = 02000; /* Unix set group id on execution */
const UInt32 kISVTX = 01000; /* Unix directory permissions control */
const UInt32 kENFMT = kISGID; /* Unix record locking enforcement flag */
const UInt32 kIRWXU = 00700; /* Unix read, write, execute: owner */
const UInt32 kIRUSR = 00400; /* Unix read permission: owner */
const UInt32 kIWUSR = 00200; /* Unix write permission: owner */
const UInt32 kIXUSR = 00100; /* Unix execute permission: owner */
const UInt32 kIRWXG = 00070; /* Unix read, write, execute: group */
const UInt32 kIRGRP = 00040; /* Unix read permission: group */
const UInt32 kIWGRP = 00020; /* Unix write permission: group */
const UInt32 kIXGRP = 00010; /* Unix execute permission: group */
const UInt32 kIRWXO = 00007; /* Unix read, write, execute: other */
const UInt32 kIROTH = 00004; /* Unix read permission: other */
const UInt32 kIWOTH = 00002; /* Unix write permission: other */
const UInt32 kIXOTH = 00001; /* Unix execute permission: other */
}
namespace NAmigaAttribute
{
const UInt32 kIFMT = 06000; /* Amiga file type mask */
const UInt32 kIFDIR = 04000; /* Amiga directory */
const UInt32 kIFREG = 02000; /* Amiga regular file */
const UInt32 kIHIDDEN = 00200; /* to be supported in AmigaDOS 3.x */
const UInt32 kISCRIPT = 00100; /* executable script (text command file) */
const UInt32 kIPURE = 00040; /* allow loading into resident memory */
const UInt32 kIARCHIVE = 00020; /* not modified since bit was last set */
const UInt32 kIREAD = 00010; /* can be opened for reading */
const UInt32 kIWRITE = 00004; /* can be opened for writing */
const UInt32 kIEXECUTE = 00002; /* executable image, a loadable runfile */
const UInt32 kIDELETE = 00001; /* can be deleted */
}
}
}}
#endif

View File

@ -0,0 +1,116 @@
// Archive/ZipIn.h
#ifndef __ZIP_IN_H
#define __ZIP_IN_H
#include "../../../Common/MyCom.h"
#include "../../IStream.h"
#include "ZipHeader.h"
#include "ZipItemEx.h"
namespace NArchive {
namespace NZip {
class CInArchiveException
{
public:
enum ECauseType
{
kUnexpectedEndOfArchive = 0,
kArchiceHeaderCRCError,
kFileHeaderCRCError,
kIncorrectArchive,
kDataDescroptorsAreNotSupported,
kMultiVolumeArchiveAreNotSupported,
kReadStreamError,
kSeekStreamError
}
Cause;
CInArchiveException(ECauseType cause): Cause(cause) {}
};
class CInArchiveInfo
{
public:
UInt64 Base;
UInt64 StartPosition;
CByteBuffer Comment;
CInArchiveInfo(): Base(0), StartPosition(0) {}
void Clear()
{
Base = 0;
StartPosition = 0;
Comment.SetCapacity(0);
}
};
class CProgressVirt
{
public:
STDMETHOD(SetTotal)(UInt64 numFiles) PURE;
STDMETHOD(SetCompleted)(UInt64 numFiles) PURE;
};
struct CCdInfo
{
// UInt64 NumEntries;
UInt64 Size;
UInt64 Offset;
};
class CInArchive
{
CMyComPtr<IInStream> m_Stream;
UInt32 m_Signature;
UInt64 m_StreamStartPosition;
UInt64 m_Position;
AString m_NameBuffer;
HRESULT Seek(UInt64 offset);
HRESULT FindAndReadMarker(IInStream *stream, const UInt64 *searchHeaderSizeLimit);
bool ReadUInt32(UInt32 &signature);
AString ReadFileName(UInt32 nameSize);
HRESULT ReadBytes(void *data, UInt32 size, UInt32 *processedSize);
bool ReadBytesAndTestSize(void *data, UInt32 size);
void SafeReadBytes(void *data, UInt32 size);
void ReadBuffer(CByteBuffer &buffer, UInt32 size);
Byte ReadByte();
UInt16 ReadUInt16();
UInt32 ReadUInt32();
UInt64 ReadUInt64();
void IncreaseRealPosition(UInt64 addValue);
void ReadExtra(UInt32 extraSize, CExtraBlock &extraBlock,
UInt64 &unpackSize, UInt64 &packSize, UInt64 &localHeaderOffset, UInt32 &diskStartNumber);
HRESULT ReadLocalItem(CItemEx &item);
HRESULT ReadLocalItemDescriptor(CItemEx &item);
HRESULT ReadCdItem(CItemEx &item);
HRESULT TryEcd64(UInt64 offset, CCdInfo &cdInfo);
HRESULT FindCd(CCdInfo &cdInfo);
HRESULT TryReadCd(CObjectVector<CItemEx> &items, UInt64 cdOffset, UInt64 cdSize, CProgressVirt *progress);
HRESULT ReadCd(CObjectVector<CItemEx> &items, UInt64 &cdOffset, UInt64 &cdSize, CProgressVirt *progress);
HRESULT ReadLocalsAndCd(CObjectVector<CItemEx> &items, CProgressVirt *progress, UInt64 &cdOffset);
public:
CInArchiveInfo m_ArchiveInfo;
bool IsZip64;
HRESULT ReadHeaders(CObjectVector<CItemEx> &items, CProgressVirt *progress);
HRESULT ReadLocalItemAfterCdItem(CItemEx &item);
HRESULT ReadLocalItemAfterCdItemFull(CItemEx &item);
HRESULT Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit);
void Close();
void GetArchiveInfo(CInArchiveInfo &archiveInfo) const;
bool SeekInArchive(UInt64 position);
ISequentialInStream *CreateLimitedStream(UInt64 position, UInt64 size);
IInStream* CreateStream();
bool IsOpen() const { return m_Stream != NULL; }
};
}}
#endif

View File

@ -0,0 +1,268 @@
// Archive/ZipItem.h
#ifndef __ARCHIVE_ZIP_ITEM_H
#define __ARCHIVE_ZIP_ITEM_H
#include "../../../Common/Types.h"
#include "../../../Common/MyString.h"
#include "../../../Common/Buffer.h"
#include "../../../Common/UTFConvert.h"
#include "../../../Common/StringConvert.h"
#include "ZipHeader.h"
namespace NArchive {
namespace NZip {
struct CVersion
{
Byte Version;
Byte HostOS;
};
bool operator==(const CVersion &v1, const CVersion &v2);
bool operator!=(const CVersion &v1, const CVersion &v2);
struct CExtraSubBlock
{
UInt16 ID;
CByteBuffer Data;
bool ExtractNtfsTime(int index, FILETIME &ft) const;
};
struct CWzAesExtraField
{
UInt16 VendorVersion; // 0x0001 - AE-1, 0x0002 - AE-2,
// UInt16 VendorId; // "AE"
Byte Strength; // 1 - 128-bit , 2 - 192-bit , 3 - 256-bit
UInt16 Method;
CWzAesExtraField(): VendorVersion(2), Strength(3), Method(0) {}
bool NeedCrc() const { return (VendorVersion == 1); }
bool ParseFromSubBlock(const CExtraSubBlock &sb)
{
if (sb.ID != NFileHeader::NExtraID::kWzAES)
return false;
if (sb.Data.GetCapacity() < 7)
return false;
const Byte *p = (const Byte *)sb.Data;
VendorVersion = (((UInt16)p[1]) << 8) | p[0];
if (p[2] != 'A' || p[3] != 'E')
return false;
Strength = p[4];
Method = (((UInt16)p[6]) << 16) | p[5];
return true;
}
void SetSubBlock(CExtraSubBlock &sb) const
{
sb.Data.SetCapacity(7);
sb.ID = NFileHeader::NExtraID::kWzAES;
Byte *p = (Byte *)sb.Data;
p[0] = (Byte)VendorVersion;
p[1] = (Byte)(VendorVersion >> 8);
p[2] = 'A';
p[3] = 'E';
p[4] = Strength;
p[5] = (Byte)Method;
p[6] = (Byte)(Method >> 8);
}
};
namespace NStrongCryptoFlags
{
const UInt16 kDES = 0x6601;
const UInt16 kRC2old = 0x6602;
const UInt16 k3DES168 = 0x6603;
const UInt16 k3DES112 = 0x6609;
const UInt16 kAES128 = 0x660E;
const UInt16 kAES192 = 0x660F;
const UInt16 kAES256 = 0x6610;
const UInt16 kRC2 = 0x6702;
const UInt16 kBlowfish = 0x6720;
const UInt16 kTwofish = 0x6721;
const UInt16 kRC4 = 0x6801;
}
struct CStrongCryptoField
{
UInt16 Format;
UInt16 AlgId;
UInt16 BitLen;
UInt16 Flags;
bool ParseFromSubBlock(const CExtraSubBlock &sb)
{
if (sb.ID != NFileHeader::NExtraID::kStrongEncrypt)
return false;
const Byte *p = (const Byte *)sb.Data;
if (sb.Data.GetCapacity() < 8)
return false;
Format = (((UInt16)p[1]) << 8) | p[0];
AlgId = (((UInt16)p[3]) << 8) | p[2];
BitLen = (((UInt16)p[5]) << 8) | p[4];
Flags = (((UInt16)p[7]) << 8) | p[6];
return (Format == 2);
}
};
struct CExtraBlock
{
CObjectVector<CExtraSubBlock> SubBlocks;
void Clear() { SubBlocks.Clear(); }
size_t GetSize() const
{
size_t res = 0;
for (int i = 0; i < SubBlocks.Size(); i++)
res += SubBlocks[i].Data.GetCapacity() + 2 + 2;
return res;
}
bool GetWzAesField(CWzAesExtraField &aesField) const
{
for (int i = 0; i < SubBlocks.Size(); i++)
if (aesField.ParseFromSubBlock(SubBlocks[i]))
return true;
return false;
}
bool GetStrongCryptoField(CStrongCryptoField &f) const
{
for (int i = 0; i < SubBlocks.Size(); i++)
if (f.ParseFromSubBlock(SubBlocks[i]))
return true;
return false;
}
bool HasWzAesField() const
{
CWzAesExtraField aesField;
return GetWzAesField(aesField);
}
bool GetNtfsTime(int index, FILETIME &ft) const
{
for (int i = 0; i < SubBlocks.Size(); i++)
{
const CExtraSubBlock &sb = SubBlocks[i];
if (sb.ID == NFileHeader::NExtraID::kNTFS)
return sb.ExtractNtfsTime(index, ft);
}
return false;
}
/*
bool HasStrongCryptoField() const
{
CStrongCryptoField f;
return GetStrongCryptoField(f);
}
*/
void RemoveUnknownSubBlocks()
{
for (int i = SubBlocks.Size() - 1; i >= 0; i--)
if (SubBlocks[i].ID != NFileHeader::NExtraID::kWzAES)
SubBlocks.Delete(i);
}
};
class CLocalItem
{
public:
CVersion ExtractVersion;
UInt16 Flags;
UInt16 CompressionMethod;
UInt32 Time;
UInt32 FileCRC;
UInt64 PackSize;
UInt64 UnPackSize;
AString Name;
CExtraBlock LocalExtra;
bool IsUtf8() const { return (Flags & NFileHeader::NFlags::kUtf8) != 0; }
bool IsEncrypted() const { return (Flags & NFileHeader::NFlags::kEncrypted) != 0; }
bool IsStrongEncrypted() const { return IsEncrypted() && (Flags & NFileHeader::NFlags::kStrongEncrypted) != 0; };
bool IsLzmaEOS() const { return (Flags & NFileHeader::NFlags::kLzmaEOS) != 0; }
bool IsDir() const;
bool IgnoreItem() const { return false; }
UInt32 GetWinAttributes() const;
bool HasDescriptor() const { return (Flags & NFileHeader::NFlags::kDescriptorUsedMask) != 0; }
UString GetUnicodeString(const AString &s) const
{
UString res;
if (IsUtf8())
if (!ConvertUTF8ToUnicode(s, res))
res.Empty();
if (res.IsEmpty())
res = MultiByteToUnicodeString(s, GetCodePage());
return res;
}
private:
void SetFlagBits(int startBitNumber, int numBits, int value);
void SetBitMask(int bitMask, bool enable);
public:
void ClearFlags() { Flags = 0; }
void SetEncrypted(bool encrypted);
void SetUtf8(bool isUtf8);
WORD GetCodePage() const { return CP_OEMCP; }
};
class CItem: public CLocalItem
{
public:
CVersion MadeByVersion;
UInt16 InternalAttributes;
UInt32 ExternalAttributes;
UInt64 LocalHeaderPosition;
FILETIME NtfsMTime;
FILETIME NtfsATime;
FILETIME NtfsCTime;
CExtraBlock CentralExtra;
CByteBuffer Comment;
bool FromLocal;
bool FromCentral;
bool NtfsTimeIsDefined;
bool IsDir() const;
UInt32 GetWinAttributes() const;
bool IsThereCrc() const
{
if (CompressionMethod == NFileHeader::NCompressionMethod::kWzAES)
{
CWzAesExtraField aesField;
if (CentralExtra.GetWzAesField(aesField))
return aesField.NeedCrc();
}
return (FileCRC != 0 || !IsDir());
}
WORD GetCodePage() const
{
return (WORD)((MadeByVersion.HostOS == NFileHeader::NHostOS::kFAT
|| MadeByVersion.HostOS == NFileHeader::NHostOS::kNTFS
) ? CP_OEMCP : CP_ACP);
}
CItem() : FromLocal(false), FromCentral(false), NtfsTimeIsDefined(false) {}
};
}}
#endif

View File

@ -0,0 +1,34 @@
// Archive/ZipItemEx.h
#ifndef __ARCHIVE_ZIP_ITEMEX_H
#define __ARCHIVE_ZIP_ITEMEX_H
#include "ZipHeader.h"
#include "ZipItem.h"
namespace NArchive {
namespace NZip {
class CItemEx: public CItem
{
public:
UInt32 FileHeaderWithNameSize;
UInt16 LocalExtraSize;
UInt64 GetLocalFullSize() const
{ return FileHeaderWithNameSize + LocalExtraSize + PackSize +
(HasDescriptor() ? NFileHeader::kDataDescriptorSize : 0); };
/*
UInt64 GetLocalFullSize(bool isZip64) const
{ return FileHeaderWithNameSize + LocalExtraSize + PackSize +
(HasDescriptor() ? (isZip64 ? NFileHeader::kDataDescriptor64Size : NFileHeader::kDataDescriptorSize) : 0); };
*/
UInt64 GetLocalExtraPosition() const
{ return LocalHeaderPosition + FileHeaderWithNameSize; };
UInt64 GetDataPosition() const
{ return GetLocalExtraPosition() + LocalExtraSize; };
};
}}
#endif

View File

@ -0,0 +1,98 @@
// CreateCoder.h
#ifndef __CREATECODER_H
#define __CREATECODER_H
#include "../../Common/MyCom.h"
#include "../../Common/MyString.h"
#include "../ICoder.h"
#include "MethodId.h"
#ifdef EXTERNAL_CODECS
struct CCodecInfoEx
{
UString Name;
CMethodId Id;
UInt32 NumInStreams;
UInt32 NumOutStreams;
bool EncoderIsAssigned;
bool DecoderIsAssigned;
bool IsSimpleCodec() const { return NumOutStreams == 1 && NumInStreams == 1; }
CCodecInfoEx(): EncoderIsAssigned(false), DecoderIsAssigned(false) {}
};
HRESULT LoadExternalCodecs(ICompressCodecsInfo *codecsInfo, CObjectVector<CCodecInfoEx> &externalCodecs);
#define PUBLIC_ISetCompressCodecsInfo public ISetCompressCodecsInfo,
#define QUERY_ENTRY_ISetCompressCodecsInfo MY_QUERYINTERFACE_ENTRY(ISetCompressCodecsInfo)
#define DECL_ISetCompressCodecsInfo STDMETHOD(SetCompressCodecsInfo)(ICompressCodecsInfo *compressCodecsInfo);
#define IMPL_ISetCompressCodecsInfo2(x) \
STDMETHODIMP x::SetCompressCodecsInfo(ICompressCodecsInfo *compressCodecsInfo) { \
COM_TRY_BEGIN _codecsInfo = compressCodecsInfo; return LoadExternalCodecs(_codecsInfo, _externalCodecs); COM_TRY_END }
#define IMPL_ISetCompressCodecsInfo IMPL_ISetCompressCodecsInfo2(CHandler)
#define EXTERNAL_CODECS_VARS2 _codecsInfo, &_externalCodecs
#define DECL_EXTERNAL_CODECS_VARS CMyComPtr<ICompressCodecsInfo> _codecsInfo; CObjectVector<CCodecInfoEx> _externalCodecs;
#define EXTERNAL_CODECS_VARS EXTERNAL_CODECS_VARS2,
#define DECL_EXTERNAL_CODECS_LOC_VARS2 ICompressCodecsInfo *codecsInfo, const CObjectVector<CCodecInfoEx> *externalCodecs
#define EXTERNAL_CODECS_LOC_VARS2 codecsInfo, externalCodecs
#define DECL_EXTERNAL_CODECS_LOC_VARS DECL_EXTERNAL_CODECS_LOC_VARS2,
#define EXTERNAL_CODECS_LOC_VARS EXTERNAL_CODECS_LOC_VARS2,
#else
#define PUBLIC_ISetCompressCodecsInfo
#define QUERY_ENTRY_ISetCompressCodecsInfo
#define DECL_ISetCompressCodecsInfo
#define IMPL_ISetCompressCodecsInfo
#define EXTERNAL_CODECS_VARS2
#define DECL_EXTERNAL_CODECS_VARS
#define EXTERNAL_CODECS_VARS EXTERNAL_CODECS_VARS2
#define DECL_EXTERNAL_CODECS_LOC_VARS2
#define EXTERNAL_CODECS_LOC_VARS2
#define DECL_EXTERNAL_CODECS_LOC_VARS
#define EXTERNAL_CODECS_LOC_VARS
#endif
bool FindMethod(
DECL_EXTERNAL_CODECS_LOC_VARS
const UString &name, CMethodId &methodId, UInt32 &numInStreams, UInt32 &numOutStreams);
bool FindMethod(
DECL_EXTERNAL_CODECS_LOC_VARS
CMethodId methodId, UString &name);
HRESULT CreateCoder(
DECL_EXTERNAL_CODECS_LOC_VARS
CMethodId methodId,
CMyComPtr<ICompressFilter> &filter,
CMyComPtr<ICompressCoder> &coder,
CMyComPtr<ICompressCoder2> &coder2,
bool encode, bool onlyCoder);
HRESULT CreateCoder(
DECL_EXTERNAL_CODECS_LOC_VARS
CMethodId methodId,
CMyComPtr<ICompressCoder> &coder,
CMyComPtr<ICompressCoder2> &coder2,
bool encode);
HRESULT CreateCoder(
DECL_EXTERNAL_CODECS_LOC_VARS
CMethodId methodId,
CMyComPtr<ICompressCoder> &coder, bool encode);
HRESULT CreateFilter(
DECL_EXTERNAL_CODECS_LOC_VARS
CMethodId methodId,
CMyComPtr<ICompressFilter> &filter,
bool encode);
#endif

View File

@ -0,0 +1,28 @@
// DeclareArcs.h
#ifndef __DECLAREARCS_H
#define __DECLAREARCS_H
#define DECLARE_ARC(x) struct CRegister##x { CRegister##x(); }; \
FORCE_REF(CRegister##x, g_RegisterArc##x)
#define DECLARE_ARCN(x,n) struct CRegister##x##n { CRegister##x##n(); }; \
FORCE_REF(CRegister##x##n, g_RegisterArc##n##x)
#ifndef FORCE_REF
#define FORCE_REF(...)
#endif
DECLARE_ARC(7z)
DECLARE_ARC(BZip2)
DECLARE_ARC(GZip)
DECLARE_ARC(Lzh)
DECLARE_ARC(Lzma)
DECLARE_ARC(Rar)
DECLARE_ARC(Split)
DECLARE_ARC(Tar)
DECLARE_ARC(Zip)
DECLARE_ARCN(Zip,2)
DECLARE_ARCN(Zip,3)
#endif

View File

@ -0,0 +1,31 @@
// DeclareCodecs.h
#ifndef __DECLARECODECS_H
#define __DECLARECODECS_H
#define DECLARE_CODEC(x) struct CRegisterCodec##x { CRegisterCodec##x(); }; \
FORCE_REF(CRegisterCodec##x, g_RegisterCodec##x)
#define DECLARE_CODECS(x) struct CRegisterCodecs##x { CRegisterCodecs##x(); }; \
FORCE_REF(CRegisterCodecs##x, g_RegisterCodecs##x)
#ifndef FORCE_REF
#define FORCE_REF(...)
#endif
DECLARE_CODEC(7zAES)
DECLARE_CODEC(BCJ2)
DECLARE_CODEC(BCJ)
DECLARE_CODEC(BZip2)
DECLARE_CODEC(Copy)
DECLARE_CODEC(Deflate64)
DECLARE_CODEC(DeflateNsis)
DECLARE_CODEC(Deflate)
DECLARE_CODEC(LZMA)
DECLARE_CODEC(PPMD)
DECLARE_CODECS(Branch)
DECLARE_CODECS(ByteSwap)
DECLARE_CODECS(Rar)
#endif

View File

@ -0,0 +1,143 @@
// FilterCoder.h
#ifndef __FILTERCODER_H
#define __FILTERCODER_H
#include "../../Common/MyCom.h"
#include "../ICoder.h"
#include "../IPassword.h"
#define MY_QUERYINTERFACE_ENTRY_AG(i, sub0, sub) if (iid == IID_ ## i) \
{ if (!sub) RINOK(sub0->QueryInterface(IID_ ## i, (void **)&sub)) \
*outObject = (void *)(i *)this; AddRef(); return S_OK; }
class CFilterCoder:
public ICompressCoder,
// #ifdef _ST_MODE
public ICompressSetInStream,
public ISequentialInStream,
public ICompressSetOutStream,
public ISequentialOutStream,
public IOutStreamFlush,
// #endif
#ifndef _NO_CRYPTO
public ICryptoSetPassword,
#endif
#ifndef EXTRACT_ONLY
public ICompressSetCoderProperties,
public ICompressWriteCoderProperties,
// public ICryptoResetSalt,
public ICryptoResetInitVector,
#endif
public ICompressSetDecoderProperties2,
public CMyUnknownImp
{
protected:
Byte *_buffer;
// #ifdef _ST_MODE
CMyComPtr<ISequentialInStream> _inStream;
CMyComPtr<ISequentialOutStream> _outStream;
UInt32 _bufferPos;
UInt32 _convertedPosBegin;
UInt32 _convertedPosEnd;
// #endif
bool _outSizeIsDefined;
UInt64 _outSize;
UInt64 _nowPos64;
HRESULT Init()
{
_nowPos64 = 0;
_outSizeIsDefined = false;
return Filter->Init();
}
CMyComPtr<ICryptoSetPassword> _setPassword;
#ifndef EXTRACT_ONLY
CMyComPtr<ICompressSetCoderProperties> _SetCoderProperties;
CMyComPtr<ICompressWriteCoderProperties> _writeCoderProperties;
// CMyComPtr<ICryptoResetSalt> _CryptoResetSalt;
CMyComPtr<ICryptoResetInitVector> _CryptoResetInitVector;
#endif
CMyComPtr<ICompressSetDecoderProperties2> _setDecoderProperties;
public:
CMyComPtr<ICompressFilter> Filter;
CFilterCoder();
~CFilterCoder();
HRESULT WriteWithLimit(ISequentialOutStream *outStream, UInt32 size);
bool NeedMore() const
{ return (!_outSizeIsDefined || (_nowPos64 < _outSize)); }
public:
MY_QUERYINTERFACE_BEGIN
MY_QUERYINTERFACE_ENTRY(ICompressCoder)
// #ifdef _ST_MODE
MY_QUERYINTERFACE_ENTRY(ICompressSetInStream)
MY_QUERYINTERFACE_ENTRY(ISequentialInStream)
MY_QUERYINTERFACE_ENTRY(ICompressSetOutStream)
MY_QUERYINTERFACE_ENTRY(ISequentialOutStream)
MY_QUERYINTERFACE_ENTRY(IOutStreamFlush)
// #endif
#ifndef _NO_CRYPTO
MY_QUERYINTERFACE_ENTRY_AG(ICryptoSetPassword, Filter, _setPassword)
#endif
#ifndef EXTRACT_ONLY
MY_QUERYINTERFACE_ENTRY_AG(ICompressSetCoderProperties, Filter, _SetCoderProperties)
MY_QUERYINTERFACE_ENTRY_AG(ICompressWriteCoderProperties, Filter, _writeCoderProperties)
// MY_QUERYINTERFACE_ENTRY_AG(ICryptoResetSalt, Filter, _CryptoResetSalt)
MY_QUERYINTERFACE_ENTRY_AG(ICryptoResetInitVector, Filter, _CryptoResetInitVector)
#endif
MY_QUERYINTERFACE_ENTRY_AG(ICompressSetDecoderProperties2, Filter, _setDecoderProperties)
MY_QUERYINTERFACE_END
MY_ADDREF_RELEASE
STDMETHOD(Code)(ISequentialInStream *inStream,
ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
ICompressProgressInfo *progress);
// #ifdef _ST_MODE
STDMETHOD(ReleaseInStream)();
STDMETHOD(SetInStream)(ISequentialInStream *inStream);
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); \
STDMETHOD(SetOutStream)(ISequentialOutStream *outStream);
STDMETHOD(ReleaseOutStream)();
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
STDMETHOD(Flush)();
// #endif
#ifndef _NO_CRYPTO
STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size);
#endif
#ifndef EXTRACT_ONLY
STDMETHOD(SetCoderProperties)(const PROPID *propIDs,
const PROPVARIANT *properties, UInt32 numProperties);
STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);
// STDMETHOD(ResetSalt)();
STDMETHOD(ResetInitVector)();
#endif
STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
};
// #ifdef _ST_MODE
class CInStreamReleaser
{
public:
CFilterCoder *FilterCoder;
CInStreamReleaser(): FilterCoder(0) {}
~CInStreamReleaser() { if (FilterCoder) FilterCoder->ReleaseInStream(); }
};
class COutStreamReleaser
{
public:
CFilterCoder *FilterCoder;
COutStreamReleaser(): FilterCoder(0) {}
~COutStreamReleaser() { if (FilterCoder) FilterCoder->ReleaseOutStream(); }
};
// #endif
#endif

View File

@ -0,0 +1,81 @@
// InBuffer.h
#ifndef __INBUFFER_H
#define __INBUFFER_H
#include "../IStream.h"
#include "../../Common/MyCom.h"
#include "../../Common/MyException.h"
#ifndef _NO_EXCEPTIONS
struct CInBufferException: public CSystemException
{
CInBufferException(HRESULT errorCode): CSystemException(errorCode) {}
};
#endif
class CInBuffer
{
Byte *_buffer;
Byte *_bufferLimit;
Byte *_bufferBase;
CMyComPtr<ISequentialInStream> _stream;
UInt64 _processedSize;
UInt32 _bufferSize;
bool _wasFinished;
bool ReadBlock();
Byte ReadBlock2();
public:
#ifdef _NO_EXCEPTIONS
HRESULT ErrorCode;
#endif
CInBuffer();
~CInBuffer() { Free(); }
bool Create(UInt32 bufferSize);
void Free();
void SetStream(ISequentialInStream *stream);
void Init();
void ReleaseStream() { _stream.Release(); }
bool ReadByte(Byte &b)
{
if (_buffer >= _bufferLimit)
if (!ReadBlock())
return false;
b = *_buffer++;
return true;
}
Byte ReadByte()
{
if (_buffer >= _bufferLimit)
return ReadBlock2();
return *_buffer++;
}
UInt32 ReadBytes(Byte *buf, UInt32 size)
{
if ((UInt32)(_bufferLimit - _buffer) >= size)
{
for (UInt32 i = 0; i < size; i++)
buf[i] = _buffer[i];
_buffer += size;
return size;
}
for (UInt32 i = 0; i < size; i++)
{
if (_buffer >= _bufferLimit)
if (!ReadBlock())
return i;
buf[i] = *_buffer++;
}
return size;
}
UInt64 GetProcessedSize() const { return _processedSize + (_buffer - _bufferBase); }
bool WasFinished() const { return _wasFinished; }
};
#endif

View File

@ -0,0 +1,55 @@
// Util/InOutTempBuffer.h
#ifndef __IN_OUT_TEMP_BUFFER_H
#define __IN_OUT_TEMP_BUFFER_H
#include "../../Windows/FileIO.h"
#include "../../Windows/FileDir.h"
#include "../../Common/MyCom.h"
#include "../IStream.h"
class CInOutTempBuffer
{
NWindows::NFile::NDirectory::CTempFile _tempFile;
NWindows::NFile::NIO::COutFile _outFile;
NWindows::NFile::NIO::CInFile _inFile;
Byte *_buffer;
UInt32 _bufferPosition;
UInt32 _currentPositionInBuffer;
CSysString _tmpFileName;
bool _tmpFileCreated;
UInt64 _fileSize;
bool WriteToFile(const void *data, UInt32 size);
public:
CInOutTempBuffer();
~CInOutTempBuffer();
void Create();
void InitWriting();
bool Write(const void *data, UInt32 size);
UInt64 GetDataSize() const { return _fileSize; }
bool FlushWrite();
bool InitReading();
HRESULT WriteToStream(ISequentialOutStream *stream);
};
class CSequentialOutTempBufferImp:
public ISequentialOutStream,
public CMyUnknownImp
{
CInOutTempBuffer *_buffer;
public:
// CSequentialOutStreamImp(): _size(0) {}
// UInt32 _size;
void Init(CInOutTempBuffer *buffer) { _buffer = buffer; }
// UInt32 GetSize() const { return _size; }
MY_UNKNOWN_IMP
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
};
#endif

View File

@ -0,0 +1,54 @@
// LimitedStreams.h
#ifndef __LIMITEDSTREAMS_H
#define __LIMITEDSTREAMS_H
#include "../../Common/MyCom.h"
#include "../IStream.h"
class CLimitedSequentialInStream:
public ISequentialInStream,
public CMyUnknownImp
{
CMyComPtr<ISequentialInStream> _stream;
UInt64 _size;
UInt64 _pos;
bool _wasFinished;
public:
void SetStream(ISequentialInStream *stream) { _stream = stream; }
void Init(UInt64 streamSize)
{
_size = streamSize;
_pos = 0;
_wasFinished = false;
}
MY_UNKNOWN_IMP
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
UInt64 GetSize() const { return _pos; }
bool WasFinished() const { return _wasFinished; }
};
class CLimitedSequentialOutStream:
public ISequentialOutStream,
public CMyUnknownImp
{
CMyComPtr<ISequentialOutStream> _stream;
UInt64 _size;
bool _overflow;
public:
MY_UNKNOWN_IMP
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
void SetStream(ISequentialOutStream *stream) { _stream = stream; }
void ReleaseStream() { _stream.Release(); }
void Init(UInt64 size)
{
_size = size;
_overflow = false;
}
bool IsFinishedOK() const { return (_size == 0 && !_overflow); }
UInt64 GetRem() const { return _size; }
};
#endif

View File

@ -0,0 +1,38 @@
// LockedStream.h
#ifndef __LOCKEDSTREAM_H
#define __LOCKEDSTREAM_H
#include "../../Windows/Synchronization.h"
#include "../../Common/MyCom.h"
#include "../IStream.h"
class CLockedInStream
{
CMyComPtr<IInStream> _stream;
NWindows::NSynchronization::CCriticalSection _criticalSection;
public:
void Init(IInStream *stream)
{ _stream = stream; }
HRESULT Read(UInt64 startPos, void *data, UInt32 size, UInt32 *processedSize);
};
class CLockedSequentialInStreamImp:
public ISequentialInStream,
public CMyUnknownImp
{
CLockedInStream *_lockedInStream;
UInt64 _pos;
public:
void Init(CLockedInStream *lockedInStream, UInt64 startPos)
{
_lockedInStream = lockedInStream;
_pos = startPos;
}
MY_UNKNOWN_IMP
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
};
#endif

View File

@ -0,0 +1,77 @@
// MemBlocks.h
#ifndef __MEMBLOCKS_H
#define __MEMBLOCKS_H
extern "C"
{
#include "../../../C/Alloc.h"
}
#include "Common/Types.h"
#include "Common/MyVector.h"
#include "Windows/Synchronization.h"
#include "../IStream.h"
class CMemBlockManager
{
void *_data;
size_t _blockSize;
void *_headFree;
public:
CMemBlockManager(size_t blockSize = (1 << 20)): _data(0), _blockSize(blockSize), _headFree(0) {}
~CMemBlockManager() { FreeSpace(); }
bool AllocateSpace(size_t numBlocks);
void FreeSpace();
size_t GetBlockSize() const { return _blockSize; }
void *AllocateBlock();
void FreeBlock(void *p);
};
class CMemBlockManagerMt: public CMemBlockManager
{
NWindows::NSynchronization::CCriticalSection _criticalSection;
public:
NWindows::NSynchronization::CSemaphore Semaphore;
CMemBlockManagerMt(size_t blockSize = (1 << 20)): CMemBlockManager(blockSize) {}
~CMemBlockManagerMt() { FreeSpace(); }
HRes AllocateSpace(size_t numBlocks, size_t numNoLockBlocks = 0);
HRes AllocateSpaceAlways(size_t desiredNumberOfBlocks, size_t numNoLockBlocks = 0);
void FreeSpace();
void *AllocateBlock();
void FreeBlock(void *p, bool lockMode = true);
HRes ReleaseLockedBlocks(int number) { return Semaphore.Release(number); }
};
class CMemBlocks
{
void Free(CMemBlockManagerMt *manager);
public:
CRecordVector<void *> Blocks;
UInt64 TotalSize;
CMemBlocks(): TotalSize(0) {}
void FreeOpt(CMemBlockManagerMt *manager);
HRESULT WriteToStream(size_t blockSize, ISequentialOutStream *outStream) const;
};
struct CMemLockBlocks: public CMemBlocks
{
bool LockMode;
CMemLockBlocks(): LockMode(true) {};
void Free(CMemBlockManagerMt *memManager);
void FreeBlock(int index, CMemBlockManagerMt *memManager);
HRes SwitchToNoLockMode(CMemBlockManagerMt *memManager);
void Detach(CMemLockBlocks &blocks, CMemBlockManagerMt *memManager);
};
#endif

View File

@ -0,0 +1,10 @@
// MethodId.h
#ifndef __7Z_METHOD_ID_H
#define __7Z_METHOD_ID_H
#include "../../Common/Types.h"
typedef UInt64 CMethodId;
#endif

View File

@ -0,0 +1,41 @@
// MethodProps.h
#ifndef __7Z_METHOD_PROPS_H
#define __7Z_METHOD_PROPS_H
#include "../../Common/MyVector.h"
#include "../../Windows/PropVariant.h"
#include "MethodId.h"
struct CProp
{
PROPID Id;
NWindows::NCOM::CPropVariant Value;
};
struct CMethod
{
CMethodId Id;
CObjectVector<CProp> Props;
};
struct CMethodsMode
{
CObjectVector<CMethod> Methods;
#ifdef COMPRESS_MT
UInt32 NumThreads;
#endif
CMethodsMode()
#ifdef COMPRESS_MT
: NumThreads(1)
#endif
{}
bool IsEmpty() const { return Methods.IsEmpty() ; }
};
HRESULT SetMethodProperties(const CMethod &method, const UInt64 *inSizeForReduce, IUnknown *coder);
#endif

View File

@ -0,0 +1,25 @@
// OffsetStream.h
#ifndef __OFFSETSTREAM_H
#define __OFFSETSTREAM_H
#include "Common/MyCom.h"
#include "../IStream.h"
class COffsetOutStream:
public IOutStream,
public CMyUnknownImp
{
UInt64 _offset;
CMyComPtr<IOutStream> _stream;
public:
HRESULT Init(IOutStream *stream, UInt64 offset);
MY_UNKNOWN_IMP
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
STDMETHOD(SetSize)(Int64 newSize);
};
#endif

View File

@ -0,0 +1,64 @@
// OutBuffer.h
#ifndef __OUTBUFFER_H
#define __OUTBUFFER_H
#include "../IStream.h"
#include "../../Common/MyCom.h"
#include "../../Common/MyException.h"
#ifndef _NO_EXCEPTIONS
struct COutBufferException: public CSystemException
{
COutBufferException(HRESULT errorCode): CSystemException(errorCode) {}
};
#endif
class COutBuffer
{
protected:
Byte *_buffer;
UInt32 _pos;
UInt32 _limitPos;
UInt32 _streamPos;
UInt32 _bufferSize;
CMyComPtr<ISequentialOutStream> _stream;
UInt64 _processedSize;
Byte *_buffer2;
bool _overDict;
HRESULT FlushPart();
public:
#ifdef _NO_EXCEPTIONS
HRESULT ErrorCode;
#endif
COutBuffer(): _buffer(0), _pos(0), _stream(0), _buffer2(0) {}
~COutBuffer() { Free(); }
bool Create(UInt32 bufferSize);
void Free();
void SetMemStream(Byte *buffer) { _buffer2 = buffer; }
void SetStream(ISequentialOutStream *stream);
void Init();
HRESULT Flush();
void FlushWithCheck();
void ReleaseStream() { _stream.Release(); }
void WriteByte(Byte b)
{
_buffer[_pos++] = b;
if(_pos == _limitPos)
FlushWithCheck();
}
void WriteBytes(const void *data, size_t size)
{
for (size_t i = 0; i < size; i++)
WriteByte(((const Byte *)data)[i]);
}
UInt64 GetProcessedSize() const;
};
#endif

View File

@ -0,0 +1,96 @@
// OutMemStream.h
#ifndef __OUTMEMSTREAM_H
#define __OUTMEMSTREAM_H
#include "Common/MyCom.h"
#include "MemBlocks.h"
class COutMemStream:
public IOutStream,
public CMyUnknownImp
{
CMemBlockManagerMt *_memManager;
size_t _curBlockIndex;
size_t _curBlockPos;
bool _realStreamMode;
bool _unlockEventWasSent;
NWindows::NSynchronization::CAutoResetEvent StopWritingEvent;
NWindows::NSynchronization::CAutoResetEvent WriteToRealStreamEvent;
// NWindows::NSynchronization::CAutoResetEvent NoLockEvent;
HRESULT StopWriteResult;
CMemLockBlocks Blocks;
UInt64 GetPos() const { return (UInt64)_curBlockIndex * _memManager->GetBlockSize() + _curBlockPos; }
CMyComPtr<ISequentialOutStream> OutSeqStream;
CMyComPtr<IOutStream> OutStream;
public:
HRes CreateEvents()
{
RINOK(StopWritingEvent.CreateIfNotCreated());
return WriteToRealStreamEvent.CreateIfNotCreated();
}
void SetOutStream(IOutStream *outStream)
{
OutStream = outStream;
OutSeqStream = outStream;
}
void SetSeqOutStream(ISequentialOutStream *outStream)
{
OutStream = NULL;
OutSeqStream = outStream;
}
void ReleaseOutStream()
{
OutStream.Release();
OutSeqStream.Release();
}
COutMemStream(CMemBlockManagerMt *memManager): _memManager(memManager) { }
~COutMemStream() { Free(); }
void Free();
void Init();
HRESULT WriteToRealStream();
void DetachData(CMemLockBlocks &blocks);
bool WasUnlockEventSent() const { return _unlockEventWasSent; }
void SetRealStreamMode()
{
_unlockEventWasSent = true;
WriteToRealStreamEvent.Set();
}
/*
void SetNoLockMode()
{
_unlockEventWasSent = true;
NoLockEvent.Set();
}
*/
void StopWriting(HRESULT res)
{
StopWriteResult = res;
StopWritingEvent.Set();
}
MY_UNKNOWN_IMP
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
STDMETHOD(SetSize)(Int64 newSize);
};
#endif

View File

@ -0,0 +1,46 @@
// ProgressMt.h
#ifndef __PROGRESSMT_H
#define __PROGRESSMT_H
#include "../../Common/MyCom.h"
#include "../../Common/MyVector.h"
#include "../../Windows/Synchronization.h"
#include "../ICoder.h"
#include "../IProgress.h"
class CMtCompressProgressMixer
{
CMyComPtr<ICompressProgressInfo> _progress;
CRecordVector<UInt64> InSizes;
CRecordVector<UInt64> OutSizes;
UInt64 TotalInSize;
UInt64 TotalOutSize;
public:
NWindows::NSynchronization::CCriticalSection CriticalSection;
void Init(int numItems, ICompressProgressInfo *progress);
void Reinit(int index);
HRESULT SetRatioInfo(int index, const UInt64 *inSize, const UInt64 *outSize);
};
class CMtCompressProgress:
public ICompressProgressInfo,
public CMyUnknownImp
{
CMtCompressProgressMixer *_progress;
int _index;
public:
void Init(CMtCompressProgressMixer *progress, int index)
{
_progress = progress;
_index = index;
}
void Reinit() { _progress->Reinit(_index); }
MY_UNKNOWN_IMP
STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);
};
#endif

View File

@ -0,0 +1,34 @@
// ProgressUtils.h
#ifndef __PROGRESSUTILS_H
#define __PROGRESSUTILS_H
#include "../../Common/MyCom.h"
#include "../ICoder.h"
#include "../IProgress.h"
class CLocalProgress:
public ICompressProgressInfo,
public CMyUnknownImp
{
CMyComPtr<IProgress> _progress;
CMyComPtr<ICompressProgressInfo> _ratioProgress;
bool _inSizeIsMain;
public:
UInt64 ProgressOffset;
UInt64 InSize;
UInt64 OutSize;
bool SendRatio;
bool SendProgress;
CLocalProgress();
void Init(IProgress *progress, bool inSizeIsMain);
HRESULT SetCur();
MY_UNKNOWN_IMP
STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);
};
#endif

View File

@ -0,0 +1,33 @@
// RegisterArc.h
#ifndef __REGISTERARC_H
#define __REGISTERARC_H
#include "../Archive/IArchive.h"
#include "DeclareArcs.h"
typedef IInArchive * (*CreateInArchiveP)();
typedef IOutArchive * (*CreateOutArchiveP)();
struct CArcInfo
{
const wchar_t *Name;
const wchar_t *Ext;
const wchar_t *AddExt;
Byte ClassId;
Byte Signature[16];
int SignatureSize;
bool KeepName;
CreateInArchiveP CreateInArchive;
CreateOutArchiveP CreateOutArchive;
};
void RegisterArc(const CArcInfo *arcInfo);
#define REGISTER_ARC(x) CRegister##x::CRegister##x() { RegisterArc(&g_ArcInfo); } \
CRegister##x g_RegisterArc##x;
#define REGISTER_ARCN(x,n) CRegister##x##n::CRegister##x##n() { RegisterArc(&g_ArcInfo##n); } \
CRegister##x##n g_RegisterArc##n##x;
#endif

View File

@ -0,0 +1,30 @@
// RegisterCodec.h
#ifndef __REGISTERCODEC_H
#define __REGISTERCODEC_H
#include "../Common/MethodId.h"
#include "DeclareCodecs.h"
typedef void * (*CreateCodecP)();
struct CCodecInfo
{
CreateCodecP CreateDecoder;
CreateCodecP CreateEncoder;
CMethodId Id;
const wchar_t *Name;
UInt32 NumInStreams;
bool IsFilter;
};
void RegisterCodec(const CCodecInfo *codecInfo);
#define REGISTER_CODEC(x) CRegisterCodec##x::CRegisterCodec##x() { RegisterCodec(&g_CodecInfo); } \
CRegisterCodec##x g_RegisterCodec##x;
#define REGISTER_CODECS(x) CRegisterCodecs##x::CRegisterCodecs##x() { \
for(int i=0;i<sizeof(g_CodecsInfo)/sizeof(*g_CodecsInfo);i++) \
RegisterCodec(&g_CodecsInfo[i]); } \
CRegisterCodecs##x g_RegisterCodecs##x;
#endif

View File

@ -0,0 +1,9 @@
// StdAfx.h
#ifndef __STDAFX_H
#define __STDAFX_H
#include "../../Common/MyWindows.h"
#include "../../Common/NewHandler.h"
#endif

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