4.61 beta

This commit is contained in:
Igor Pavlov
2008-11-23 00:00:00 +00:00
committed by Kornel Lesiński
parent c10e6b16f6
commit b717a4dbfe
80 changed files with 1605 additions and 1312 deletions

View File

@@ -1,7 +1,5 @@
/* 7zBuf.h -- Byte Buffer
2008-05-01
Igor Pavlov
Public domain */
2008-10-04 : Igor Pavlov : Public domain */
#ifndef __7Z_BUF_H
#define __7Z_BUF_H
@@ -18,4 +16,16 @@ void Buf_Init(CBuf *p);
int Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc);
void Buf_Free(CBuf *p, ISzAlloc *alloc);
typedef struct
{
Byte *data;
size_t size;
size_t pos;
} CDynBuf;
void DynBuf_Construct(CDynBuf *p);
void DynBuf_SeekToBeg(CDynBuf *p);
int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc);
void DynBuf_Free(CDynBuf *p, ISzAlloc *alloc);
#endif

45
C/7zBuf2.c Executable file
View File

@@ -0,0 +1,45 @@
/* 7zBuf2.c -- Byte Buffer
2008-10-04 : Igor Pavlov : Public domain */
#include <string.h>
#include "7zBuf.h"
void DynBuf_Construct(CDynBuf *p)
{
p->data = 0;
p->size = 0;
p->pos = 0;
}
void DynBuf_SeekToBeg(CDynBuf *p)
{
p->pos = 0;
}
int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc)
{
if (size > p->size - p->pos)
{
size_t newSize = p->pos + size;
Byte *data;
newSize += newSize / 4;
data = (Byte *)alloc->Alloc(alloc, newSize);
if (data == 0)
return 0;
p->size = newSize;
memcpy(data, p->data, p->pos);
alloc->Free(alloc, p->data);
p->data = data;
}
memcpy(p->data + p->pos, buf, size);
p->pos += size;
return 1;
}
void DynBuf_Free(CDynBuf *p, ISzAlloc *alloc)
{
alloc->Free(alloc, p->data);
p->data = 0;
p->size = 0;
p->pos = 0;
}

263
C/7zFile.c Executable file
View File

@@ -0,0 +1,263 @@
/* 7zFile.c -- File IO
2008-11-22 : Igor Pavlov : Public domain */
#include "7zFile.h"
#ifndef USE_WINDOWS_FILE
#include <errno.h>
#endif
#ifdef USE_WINDOWS_FILE
/*
ReadFile and WriteFile functions in Windows have BUG:
If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1)
from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES
(Insufficient system resources exist to complete the requested service).
Probably in some version of Windows there are problems with other sizes:
for 32 MB (maybe also for 16 MB).
And message can be "Network connection was lost"
*/
#define kChunkSizeMax (1 << 22)
#endif
void File_Construct(CSzFile *p)
{
#ifdef USE_WINDOWS_FILE
p->handle = INVALID_HANDLE_VALUE;
#else
p->file = NULL;
#endif
}
static WRes File_Open(CSzFile *p, const char *name, int writeMode)
{
#ifdef USE_WINDOWS_FILE
p->handle = CreateFileA(name,
writeMode ? GENERIC_WRITE : GENERIC_READ,
FILE_SHARE_READ, NULL,
writeMode ? CREATE_ALWAYS : OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);
return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError();
#else
p->file = fopen(name, writeMode ? "wb+" : "rb");
return (p->file != 0) ? 0 : errno;
#endif
}
WRes InFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 0); }
WRes OutFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 1); }
WRes File_Close(CSzFile *p)
{
#ifdef USE_WINDOWS_FILE
if (p->handle != INVALID_HANDLE_VALUE)
{
if (!CloseHandle(p->handle))
return GetLastError();
p->handle = INVALID_HANDLE_VALUE;
}
#else
if (p->file != NULL)
{
int res = fclose(p->file);
if (res != 0)
return res;
p->file = NULL;
}
#endif
return 0;
}
WRes File_Read(CSzFile *p, void *data, size_t *size)
{
size_t originalSize = *size;
if (originalSize == 0)
return 0;
#ifdef USE_WINDOWS_FILE
*size = 0;
do
{
DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;
DWORD processed = 0;
BOOL res = ReadFile(p->handle, data, curSize, &processed, NULL);
data = (void *)((Byte *)data + processed);
originalSize -= processed;
*size += processed;
if (!res)
return GetLastError();
if (processed == 0)
break;
}
while (originalSize > 0);
return 0;
#else
*size = fread(data, 1, originalSize, p->file);
if (*size == originalSize)
return 0;
return ferror(p->file);
#endif
}
WRes File_Write(CSzFile *p, const void *data, size_t *size)
{
size_t originalSize = *size;
if (originalSize == 0)
return 0;
#ifdef USE_WINDOWS_FILE
*size = 0;
do
{
DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;
DWORD processed = 0;
BOOL res = WriteFile(p->handle, data, curSize, &processed, NULL);
data = (void *)((Byte *)data + processed);
originalSize -= processed;
*size += processed;
if (!res)
return GetLastError();
if (processed == 0)
break;
}
while (originalSize > 0);
return 0;
#else
*size = fwrite(data, 1, originalSize, p->file);
if (*size == originalSize)
return 0;
return ferror(p->file);
#endif
}
WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin)
{
#ifdef USE_WINDOWS_FILE
LARGE_INTEGER value;
DWORD moveMethod;
value.LowPart = (DWORD)*pos;
value.HighPart = (LONG)((UInt64)*pos >> 16 >> 16); /* for case when UInt64 is 32-bit only */
switch (origin)
{
case SZ_SEEK_SET: moveMethod = FILE_BEGIN; break;
case SZ_SEEK_CUR: moveMethod = FILE_CURRENT; break;
case SZ_SEEK_END: moveMethod = FILE_END; break;
default: return ERROR_INVALID_PARAMETER;
}
value.LowPart = SetFilePointer(p->handle, value.LowPart, &value.HighPart, moveMethod);
if (value.LowPart == 0xFFFFFFFF)
{
WRes res = GetLastError();
if (res != NO_ERROR)
return res;
}
*pos = ((Int64)value.HighPart << 32) | value.LowPart;
return 0;
#else
int moveMethod;
int res;
switch (origin)
{
case SZ_SEEK_SET: moveMethod = SEEK_SET; break;
case SZ_SEEK_CUR: moveMethod = SEEK_CUR; break;
case SZ_SEEK_END: moveMethod = SEEK_END; break;
default: return 1;
}
res = fseek(p->file, (long)*pos, moveMethod);
*pos = ftell(p->file);
return res;
#endif
}
WRes File_GetLength(CSzFile *p, UInt64 *length)
{
#ifdef USE_WINDOWS_FILE
DWORD sizeHigh;
DWORD sizeLow = GetFileSize(p->handle, &sizeHigh);
if (sizeLow == 0xFFFFFFFF)
{
DWORD res = GetLastError();
if (res != NO_ERROR)
return res;
}
*length = (((UInt64)sizeHigh) << 32) + sizeLow;
return 0;
#else
long pos = ftell(p->file);
int res = fseek(p->file, 0, SEEK_END);
*length = ftell(p->file);
fseek(p->file, pos, SEEK_SET);
return res;
#endif
}
/* ---------- FileSeqInStream ---------- */
static SRes FileSeqInStream_Read(void *pp, void *buf, size_t *size)
{
CFileSeqInStream *p = (CFileSeqInStream *)pp;
return File_Read(&p->file, buf, size) == 0 ? SZ_OK : SZ_ERROR_READ;
}
void FileSeqInStream_CreateVTable(CFileSeqInStream *p)
{
p->s.Read = FileSeqInStream_Read;
}
/* ---------- FileInStream ---------- */
static SRes FileInStream_Read(void *pp, void *buf, size_t *size)
{
CFileInStream *p = (CFileInStream *)pp;
return (File_Read(&p->file, buf, size) == 0) ? SZ_OK : SZ_ERROR_READ;
}
static SRes FileInStream_Seek(void *pp, Int64 *pos, ESzSeek origin)
{
CFileInStream *p = (CFileInStream *)pp;
return File_Seek(&p->file, pos, origin);
}
void FileInStream_CreateVTable(CFileInStream *p)
{
p->s.Read = FileInStream_Read;
p->s.Seek = FileInStream_Seek;
}
/* ---------- FileOutStream ---------- */
static size_t FileOutStream_Write(void *pp, const void *data, size_t size)
{
CFileOutStream *p = (CFileOutStream *)pp;
File_Write(&p->file, data, &size);
return size;
}
void FileOutStream_CreateVTable(CFileOutStream *p)
{
p->s.Write = FileOutStream_Write;
}

74
C/7zFile.h Executable file
View File

@@ -0,0 +1,74 @@
/* 7zFile.h -- File IO
2008-11-22 : Igor Pavlov : Public domain */
#ifndef __7Z_FILE_H
#define __7Z_FILE_H
#ifdef _WIN32
#define USE_WINDOWS_FILE
#endif
#ifdef USE_WINDOWS_FILE
#include <windows.h>
#else
#include <stdio.h>
#endif
#include "Types.h"
/* ---------- File ---------- */
typedef struct
{
#ifdef USE_WINDOWS_FILE
HANDLE handle;
#else
FILE *file;
#endif
} CSzFile;
void File_Construct(CSzFile *p);
WRes InFile_Open(CSzFile *p, const char *name);
WRes OutFile_Open(CSzFile *p, const char *name);
WRes File_Close(CSzFile *p);
/* reads max(*size, remain file's size) bytes */
WRes File_Read(CSzFile *p, void *data, size_t *size);
/* writes *size bytes */
WRes File_Write(CSzFile *p, const void *data, size_t *size);
WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin);
WRes File_GetLength(CSzFile *p, UInt64 *length);
/* ---------- FileInStream ---------- */
typedef struct
{
ISeqInStream s;
CSzFile file;
} CFileSeqInStream;
void FileSeqInStream_CreateVTable(CFileSeqInStream *p);
typedef struct
{
ISeekInStream s;
CSzFile file;
} CFileInStream;
void FileInStream_CreateVTable(CFileInStream *p);
typedef struct
{
ISeqOutStream s;
CSzFile file;
} CFileOutStream;
void FileOutStream_CreateVTable(CFileOutStream *p);
#endif

169
C/7zStream.c Executable file
View File

@@ -0,0 +1,169 @@
/* 7zStream.c -- 7z Stream functions
2008-11-23 : Igor Pavlov : Public domain */
#include <string.h>
#include "Types.h"
SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType)
{
while (size != 0)
{
size_t processed = size;
RINOK(stream->Read(stream, buf, &processed));
if (processed == 0)
return errorType;
buf = (void *)((Byte *)buf + processed);
size -= processed;
}
return SZ_OK;
}
SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size)
{
return SeqInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);
}
SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf)
{
size_t processed = 1;
RINOK(stream->Read(stream, buf, &processed));
return (processed == 1) ? SZ_OK : SZ_ERROR_INPUT_EOF;
}
SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset)
{
Int64 t = offset;
return stream->Seek(stream, &t, SZ_SEEK_SET);
}
SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size)
{
void *lookBuf;
if (*size == 0)
return SZ_OK;
RINOK(stream->Look(stream, &lookBuf, size));
memcpy(buf, lookBuf, *size);
return stream->Skip(stream, *size);
}
SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType)
{
while (size != 0)
{
size_t processed = size;
RINOK(stream->Read(stream, buf, &processed));
if (processed == 0)
return errorType;
buf = (void *)((Byte *)buf + processed);
size -= processed;
}
return SZ_OK;
}
SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size)
{
return LookInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);
}
static SRes LookToRead_Look_Lookahead(void *pp, void **buf, size_t *size)
{
SRes res = SZ_OK;
CLookToRead *p = (CLookToRead *)pp;
size_t size2 = p->size - p->pos;
if (size2 == 0 && *size > 0)
{
p->pos = 0;
size2 = LookToRead_BUF_SIZE;
res = p->realStream->Read(p->realStream, p->buf, &size2);
p->size = size2;
}
if (size2 < *size)
*size = size2;
*buf = p->buf + p->pos;
return res;
}
static SRes LookToRead_Look_Exact(void *pp, void **buf, size_t *size)
{
SRes res = SZ_OK;
CLookToRead *p = (CLookToRead *)pp;
size_t size2 = p->size - p->pos;
if (size2 == 0 && *size > 0)
{
p->pos = 0;
if (*size > LookToRead_BUF_SIZE)
*size = LookToRead_BUF_SIZE;
res = p->realStream->Read(p->realStream, p->buf, size);
size2 = p->size = *size;
}
if (size2 < *size)
*size = size2;
*buf = p->buf + p->pos;
return res;
}
static SRes LookToRead_Skip(void *pp, size_t offset)
{
CLookToRead *p = (CLookToRead *)pp;
p->pos += offset;
return SZ_OK;
}
static SRes LookToRead_Read(void *pp, void *buf, size_t *size)
{
CLookToRead *p = (CLookToRead *)pp;
size_t rem = p->size - p->pos;
if (rem == 0)
return p->realStream->Read(p->realStream, buf, size);
if (rem > *size)
rem = *size;
memcpy(buf, p->buf + p->pos, rem);
p->pos += rem;
*size = rem;
return SZ_OK;
}
static SRes LookToRead_Seek(void *pp, Int64 *pos, ESzSeek origin)
{
CLookToRead *p = (CLookToRead *)pp;
p->pos = p->size = 0;
return p->realStream->Seek(p->realStream, pos, origin);
}
void LookToRead_CreateVTable(CLookToRead *p, int lookahead)
{
p->s.Look = lookahead ?
LookToRead_Look_Lookahead :
LookToRead_Look_Exact;
p->s.Skip = LookToRead_Skip;
p->s.Read = LookToRead_Read;
p->s.Seek = LookToRead_Seek;
}
void LookToRead_Init(CLookToRead *p)
{
p->pos = p->size = 0;
}
static SRes SecToLook_Read(void *pp, void *buf, size_t *size)
{
CSecToLook *p = (CSecToLook *)pp;
return LookInStream_LookRead(p->realStream, buf, size);
}
void SecToLook_CreateVTable(CSecToLook *p)
{
p->s.Read = SecToLook_Read;
}
static SRes SecToRead_Read(void *pp, void *buf, size_t *size)
{
CSecToRead *p = (CSecToRead *)pp;
return p->realStream->Read(p->realStream, buf, size);
}
void SecToRead_CreateVTable(CSecToRead *p)
{
p->s.Read = SecToRead_Read;
}

7
C/7zVersion.h Executable file
View File

@@ -0,0 +1,7 @@
#define MY_VER_MAJOR 4
#define MY_VER_MINOR 61
#define MY_VER_BUILD 0
#define MY_VERSION "4.61 beta"
#define MY_DATE "2008-10-28"
#define MY_COPYRIGHT ": Igor Pavlov : Public domain"
#define MY_VERSION_COPYRIGHT_DATE MY_VERSION " " MY_COPYRIGHT " : " MY_DATE

View File

@@ -1,5 +1,5 @@
/* Alloc.c -- Memory allocation functions
2008-08-05
2008-09-24
Igor Pavlov
Public domain */
@@ -25,16 +25,21 @@ void *MyAlloc(size_t size)
if (size == 0)
return 0;
#ifdef _SZ_ALLOC_DEBUG
fprintf(stderr, "\nAlloc %10d bytes; count = %10d", size, g_allocCount++);
#endif
{
void *p = malloc(size);
fprintf(stderr, "\nAlloc %10d bytes, count = %10d, addr = %8X", size, g_allocCount++, (unsigned)p);
return p;
}
#else
return malloc(size);
#endif
}
void MyFree(void *address)
{
#ifdef _SZ_ALLOC_DEBUG
if (address != 0)
fprintf(stderr, "\nFree; count = %10d", --g_allocCount);
fprintf(stderr, "\nFree; count = %10d, addr = %8X", --g_allocCount, (unsigned)address);
#endif
free(address);
}

View File

@@ -42,7 +42,7 @@ RSC=rc.exe
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MD /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MD /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FAs /YX /FD /c
# ADD BASE RSC /l 0x419 /d "NDEBUG"
# ADD RSC /l 0x419 /d "NDEBUG"
BSC32=bscmake.exe
@@ -67,7 +67,7 @@ LINK32=link.exe
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /W4 /Gm /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /W4 /Gm /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_SZ_ALLOC_DEBUG2" /D "_SZ_NO_INT_64_A" /YX /FD /GZ /c
# ADD BASE RSC /l 0x419 /d "_DEBUG"
# ADD RSC /l 0x419 /d "_DEBUG"
BSC32=bscmake.exe
@@ -104,6 +104,18 @@ SOURCE=..\..\7zCrc.h
# End Source File
# Begin Source File
SOURCE=..\..\7zFile.c
# End Source File
# Begin Source File
SOURCE=..\..\7zFile.h
# End Source File
# Begin Source File
SOURCE=..\..\7zStream.c
# End Source File
# Begin Source File
SOURCE=..\..\Bcj2.c
# End Source File
# Begin Source File

View File

@@ -1,7 +1,5 @@
/* 7zAlloc.c -- Allocation functions
2008-03-28
Igor Pavlov
Public domain */
2008-10-04 : Igor Pavlov : Public domain */
#include <stdlib.h>
#include "7zAlloc.h"

View File

@@ -1,7 +1,5 @@
/* 7zAlloc.h -- Allocation functions
2008-03-28
Igor Pavlov
Public domain */
2008-10-04 : Igor Pavlov : Public domain */
#ifndef __7Z_ALLOC_H
#define __7Z_ALLOC_H

View File

@@ -1,32 +1,23 @@
/* 7zDecode.c Decoding from 7z folder
2008-08-05
Igor Pavlov
Copyright (c) 1999-2008 Igor Pavlov
Read 7zDecode.h for license options */
/* 7zDecode.c -- Decoding from 7z folder
2008-11-23 : Igor Pavlov : Public domain */
#include <string.h>
#include "7zDecode.h"
#include "../../LzmaDec.h"
#include "../../Bra.h"
#include "../../Bcj2.h"
#include "../../Bra.h"
#include "../../LzmaDec.h"
#include "7zDecode.h"
#define k_Copy 0
#define k_LZMA 0x30101
#define k_BCJ 0x03030103
#define k_BCJ2 0x0303011B
/*
#ifdef _LZMA_IN_CB
*/
static SRes SzDecodeLzma(CSzCoderInfo *coder, CFileSize inSize, ISzInStream *inStream,
Byte *outBuffer, size_t outSize, ISzAlloc *allocMain)
static SRes SzDecodeLzma(CSzCoderInfo *coder, UInt64 inSize, ILookInStream *inStream,
Byte *outBuffer, SizeT outSize, ISzAlloc *allocMain)
{
CLzmaDec state;
int res = SZ_OK;
size_t _inSize;
Byte *inBuf = NULL;
SRes res = SZ_OK;
LzmaDec_Construct(&state);
RINOK(LzmaDec_AllocateProbs(&state, coder->Props.data, (unsigned)coder->Props.size, allocMain));
@@ -34,65 +25,60 @@ static SRes SzDecodeLzma(CSzCoderInfo *coder, CFileSize inSize, ISzInStream *inS
state.dicBufSize = outSize;
LzmaDec_Init(&state);
_inSize = 0;
for (;;)
{
if (_inSize == 0)
{
_inSize = (1 << 18);
if (_inSize > inSize)
_inSize = (size_t)(inSize);
res = inStream->Read((void *)inStream, (void **)&inBuf, &_inSize);
if (res != SZ_OK)
break;
inSize -= _inSize;
}
Byte *inBuf = NULL;
size_t lookahead = (1 << 18);
if (lookahead > inSize)
lookahead = (size_t)inSize;
res = inStream->Look((void *)inStream, (void **)&inBuf, &lookahead);
if (res != SZ_OK)
break;
{
SizeT inProcessed = _inSize, dicPos = state.dicPos;
SizeT inProcessed = (SizeT)lookahead, dicPos = state.dicPos;
ELzmaStatus status;
res = LzmaDec_DecodeToDic(&state, outSize, inBuf, &inProcessed, LZMA_FINISH_END, &status);
_inSize -= inProcessed;
inBuf = (Byte *)inBuf + inProcessed;
lookahead -= inProcessed;
inSize -= inProcessed;
if (res != SZ_OK)
break;
if (state.dicPos == state.dicBufSize || (inProcessed == 0 && dicPos == state.dicPos))
{
if (state.dicBufSize != outSize || _inSize != 0 ||
if (state.dicBufSize != outSize || lookahead != 0 ||
(status != LZMA_STATUS_FINISHED_WITH_MARK &&
status != LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK))
res = SZ_ERROR_DATA;
break;
}
res = inStream->Skip((void *)inStream, inProcessed);
if (res != SZ_OK)
break;
}
}
LzmaDec_FreeProbs(&state, allocMain);
return res;
}
static SRes SzDecodeCopy(CFileSize inSize, ISzInStream *inStream, Byte *outBuffer)
static SRes SzDecodeCopy(UInt64 inSize, ILookInStream *inStream, Byte *outBuffer)
{
while (inSize > 0)
{
void *inBuffer;
void *inBuf;
size_t curSize = (1 << 18);
if (curSize > inSize)
curSize = (size_t)(inSize);
RINOK(inStream->Read((void *)inStream, (void **)&inBuffer, &curSize));
curSize = (size_t)inSize;
RINOK(inStream->Look((void *)inStream, (void **)&inBuf, &curSize));
if (curSize == 0)
return SZ_ERROR_INPUT_EOF;
memcpy(outBuffer, inBuffer, curSize);
memcpy(outBuffer, inBuf, curSize);
outBuffer += curSize;
inSize -= curSize;
RINOK(inStream->Skip((void *)inStream, curSize));
}
return SZ_OK;
}
/*
#endif
*/
#define IS_UNSUPPORTED_METHOD(m) ((m) != k_Copy && (m) != k_LZMA)
#define IS_UNSUPPORTED_CODER(c) (IS_UNSUPPORTED_METHOD(c.MethodID) || c.NumInStreams != 1 || c.NumOutStreams != 1)
@@ -141,31 +127,23 @@ SRes CheckSupportedFolder(const CSzFolder *f)
return SZ_ERROR_UNSUPPORTED;
}
CFileSize GetSum(const CFileSize *values, UInt32 index)
UInt64 GetSum(const UInt64 *values, UInt32 index)
{
CFileSize sum = 0;
UInt64 sum = 0;
UInt32 i;
for (i = 0; i < index; i++)
sum += values[i];
return sum;
}
SRes SzDecode2(const CFileSize *packSizes, const CSzFolder *folder,
/*
#ifdef _LZMA_IN_CB
*/
ISzInStream *inStream, CFileSize startPos,
/*
#else
const Byte *inBuffer,
#endif
*/
Byte *outBuffer, size_t outSize, ISzAlloc *allocMain,
SRes SzDecode2(const UInt64 *packSizes, const CSzFolder *folder,
ILookInStream *inStream, UInt64 startPos,
Byte *outBuffer, SizeT outSize, ISzAlloc *allocMain,
Byte *tempBuf[])
{
UInt32 ci;
size_t tempSizes[3] = { 0, 0, 0};
size_t tempSize3 = 0;
SizeT tempSizes[3] = { 0, 0, 0};
SizeT tempSize3 = 0;
Byte *tempBuf3 = 0;
RINOK(CheckSupportedFolder(folder));
@@ -177,19 +155,19 @@ SRes SzDecode2(const CFileSize *packSizes, const CSzFolder *folder,
if (coder->MethodID == k_Copy || coder->MethodID == k_LZMA)
{
UInt32 si = 0;
CFileSize offset;
CFileSize inSize;
UInt64 offset;
UInt64 inSize;
Byte *outBufCur = outBuffer;
size_t outSizeCur = outSize;
SizeT outSizeCur = outSize;
if (folder->NumCoders == 4)
{
UInt32 indices[] = { 3, 2, 0 };
CFileSize unpackSize = folder->UnpackSizes[ci];
UInt64 unpackSize = folder->UnpackSizes[ci];
si = indices[ci];
if (ci < 2)
{
Byte *temp;
outSizeCur = (size_t)unpackSize;
outSizeCur = (SizeT)unpackSize;
if (outSizeCur != unpackSize)
return SZ_ERROR_MEM;
temp = (Byte *)IAlloc_Alloc(allocMain, outSizeCur);
@@ -200,58 +178,27 @@ SRes SzDecode2(const CFileSize *packSizes, const CSzFolder *folder,
}
else if (ci == 2)
{
if (unpackSize > outSize) // check it
return SZ_ERROR_PARAM; // check it
if (unpackSize > outSize) /* check it */
return SZ_ERROR_PARAM;
tempBuf3 = outBufCur = outBuffer + (outSize - (size_t)unpackSize);
tempSize3 = outSizeCur = (size_t)unpackSize;
tempSize3 = outSizeCur = (SizeT)unpackSize;
}
else
return SZ_ERROR_UNSUPPORTED;
}
offset = GetSum(packSizes, si);
inSize = packSizes[si];
/*
#ifdef _LZMA_IN_CB
*/
RINOK(inStream->Seek(inStream, startPos + offset, SZ_SEEK_SET));
/*
#endif
*/
RINOK(LookInStream_SeekTo(inStream, startPos + offset));
if (coder->MethodID == k_Copy)
{
if (inSize != outSizeCur) // check it
if (inSize != outSizeCur) /* check it */
return SZ_ERROR_DATA;
/*
#ifdef _LZMA_IN_CB
*/
RINOK(SzDecodeCopy(inSize, inStream, outBufCur));
/*
#else
memcpy(outBufCur, inBuffer + (size_t)offset, (size_t)inSize);
#endif
*/
}
else
{
/*
#ifdef _LZMA_IN_CB
*/
SRes res = SzDecodeLzma(coder, inSize,
inStream,
outBufCur, outSizeCur, allocMain);
/*
#else
SizeT lzmaOutSizeT = outSizeCur;
SizeT lzmaInSizeT = (SizeT)inSize;
SRes res = LzmaDecode(outBufCur, &lzmaOutSizeT,
inBuffer + (size_t)offset, &lzmaInSizeT,
coder->Props.Items, (unsigned)coder->Props.size, LZMA_FINISH_BYTE, allocMain);
#endif
*/
RINOK(res);
RINOK(SzDecodeLzma(coder, inSize, inStream, outBufCur, outSizeCur, allocMain));
}
}
else if (coder->MethodID == k_BCJ)
@@ -264,17 +211,13 @@ SRes SzDecode2(const CFileSize *packSizes, const CSzFolder *folder,
}
else if (coder->MethodID == k_BCJ2)
{
CFileSize offset = GetSum(packSizes, 1);
CFileSize s3Size = packSizes[1];
UInt64 offset = GetSum(packSizes, 1);
UInt64 s3Size = packSizes[1];
SRes res;
if (ci != 3)
return SZ_ERROR_UNSUPPORTED;
/*
#ifdef _LZMA_IN_CB
*/
RINOK(inStream->Seek(inStream, startPos + offset, SZ_SEEK_SET));
tempSizes[2] = (size_t)s3Size;
RINOK(LookInStream_SeekTo(inStream, startPos + offset));
tempSizes[2] = (SizeT)s3Size;
if (tempSizes[2] != s3Size)
return SZ_ERROR_MEM;
tempBuf[2] = (Byte *)IAlloc_Alloc(allocMain, tempSizes[2]);
@@ -282,23 +225,12 @@ SRes SzDecode2(const CFileSize *packSizes, const CSzFolder *folder,
return SZ_ERROR_MEM;
res = SzDecodeCopy(s3Size, inStream, tempBuf[2]);
RINOK(res)
/*
#endif
*/
res = Bcj2_Decode(
tempBuf3, tempSize3,
tempBuf[0], tempSizes[0],
tempBuf[1], tempSizes[1],
/*
#ifdef _LZMA_IN_CB
*/
tempBuf[2], tempSizes[2],
/*
#else
inBuffer + (size_t)offset, (size_t)s3Size,
#endif
*/
outBuffer, outSize);
RINOK(res)
}
@@ -308,31 +240,14 @@ SRes SzDecode2(const CFileSize *packSizes, const CSzFolder *folder,
return SZ_OK;
}
SRes SzDecode(const CFileSize *packSizes, const CSzFolder *folder,
/*
#ifdef _LZMA_IN_CB
*/
ISzInStream *inStream, CFileSize startPos,
/*
#else
const Byte *inBuffer,
#endif
*/
SRes SzDecode(const UInt64 *packSizes, const CSzFolder *folder,
ILookInStream *inStream, UInt64 startPos,
Byte *outBuffer, size_t outSize, ISzAlloc *allocMain)
{
Byte *tempBuf[3] = { 0, 0, 0};
int i;
SRes res = SzDecode2(packSizes, folder,
/*
#ifdef _LZMA_IN_CB
*/
inStream, startPos,
/*
#else
inBuffer,
#endif
*/
outBuffer, outSize, allocMain, tempBuf);
SRes res = SzDecode2(packSizes, folder, inStream, startPos,
outBuffer, (SizeT)outSize, allocMain, tempBuf);
for (i = 0; i < 3; i++)
IAlloc_Free(allocMain, tempBuf[i]);
return res;

View File

@@ -1,26 +1,13 @@
/* 7zDecode.h -- Decoding from 7z folder
2008-04-09
Igor Pavlov
Copyright (c) 1999-2008 Igor Pavlov
Read 7zItem.h for license options */
2008-11-23 : Igor Pavlov : Public domain */
#ifndef __7Z_DECODE_H
#define __7Z_DECODE_H
#include "7zItem.h"
#include "7zIn.h"
SRes SzDecode(const CFileSize *packSizes, const CSzFolder *folder,
/*
#ifdef _LZMA_IN_CB
*/
ISzInStream *stream, CFileSize startPos,
/*
#else
const Byte *inBuffer,
#endif
*/
SRes SzDecode(const UInt64 *packSizes, const CSzFolder *folder,
ILookInStream *stream, UInt64 startPos,
Byte *outBuffer, size_t outSize, ISzAlloc *allocMain);
#endif

View File

@@ -1,16 +1,13 @@
/* 7zExtract.c -- Extracting from 7z archive
2008-08-17
Igor Pavlov
Copyright (c) 1999-2008 Igor Pavlov
Read 7zExtract.h for license options */
2008-11-23 : Igor Pavlov : Public domain */
#include "7zExtract.h"
#include "7zDecode.h"
#include "../../7zCrc.h"
#include "7zDecode.h"
#include "7zExtract.h"
SRes SzAr_Extract(
const CSzArEx *p,
ISzInStream *inStream,
ILookInStream *inStream,
UInt32 fileIndex,
UInt32 *blockIndex,
Byte **outBuffer,
@@ -36,9 +33,9 @@ SRes SzAr_Extract(
if (*outBuffer == 0 || *blockIndex != folderIndex)
{
CSzFolder *folder = p->db.Folders + folderIndex;
CFileSize unpackSizeSpec = SzFolder_GetUnpackSize(folder);
UInt64 unpackSizeSpec = SzFolder_GetUnpackSize(folder);
size_t unpackSize = (size_t)unpackSizeSpec;
CFileSize startOffset = SzArEx_GetFolderStreamPos(p, folderIndex, 0);
UInt64 startOffset = SzArEx_GetFolderStreamPos(p, folderIndex, 0);
if (unpackSize != unpackSizeSpec)
return SZ_ERROR_MEM;
@@ -46,7 +43,7 @@ SRes SzAr_Extract(
IAlloc_Free(allocMain, *outBuffer);
*outBuffer = 0;
RINOK(inStream->Seek(inStream, startOffset, SZ_SEEK_SET));
RINOK(LookInStream_SeekTo(inStream, startOffset));
if (res == SZ_OK)
{

View File

@@ -1,8 +1,5 @@
/* 7zExtract.h -- Extracting from 7z archive
2008-08-05
Igor Pavlov
Copyright (c) 1999-2008 Igor Pavlov
Read 7zItem.h for license options */
2008-11-23 : Igor Pavlov : Public domain */
#ifndef __7Z_EXTRACT_H
#define __7Z_EXTRACT_H
@@ -31,7 +28,7 @@ Read 7zItem.h for license options */
SRes SzAr_Extract(
const CSzArEx *db,
ISzInStream *inStream,
ILookInStream *inStream,
UInt32 fileIndex, /* index of file */
UInt32 *blockIndex, /* index of solid block */
Byte **outBuffer, /* pointer to pointer to output buffer (allocated with allocMain) */

View File

@@ -1,8 +1,5 @@
/* 7zHeader.c -- 7z Headers
2008-04-09
Igor Pavlov
Copyright (c) 1999-2008 Igor Pavlov
Read 7zHeader.h for license options */
2008-10-04 : Igor Pavlov : Public domain */
#include "7zHeader.h"

View File

@@ -1,7 +1,5 @@
/* 7zHeader.h -- 7z Headers
2008-07-14
Copyright (c) 1999-2008 Igor Pavlov
Read LzmaDec.h for license options */
2008-10-04 : Igor Pavlov : Public domain */
#ifndef __7Z_HEADER_H
#define __7Z_HEADER_H

View File

@@ -1,12 +1,11 @@
/* 7zIn.c -- 7z Input functions
2008-08-17
Igor Pavlov
Copyright (c) 1999-2008 Igor Pavlov
Read 7zIn.h for license options */
2008-11-23 : Igor Pavlov : Public domain */
#include "7zIn.h"
#include "7zDecode.h"
#include "../../7zCrc.h"
#include "../../CpuArch.h"
#include "7zDecode.h"
#include "7zIn.h"
#define RINOM(x) { if ((x) == 0) return SZ_ERROR_MEM; }
@@ -30,12 +29,12 @@ void SzArEx_Free(CSzArEx *p, ISzAlloc *alloc)
}
/*
CFileSize GetFolderPackStreamSize(int folderIndex, int streamIndex) const
UInt64 GetFolderPackStreamSize(int folderIndex, int streamIndex) const
{
return PackSizes[FolderStartPackStreamIndex[folderIndex] + streamIndex];
}
CFileSize GetFilePackSize(int fileIndex) const
UInt64 GetFilePackSize(int fileIndex) const
{
int folderIndex = FileIndexToFolderIndexMap[fileIndex];
if (folderIndex >= 0)
@@ -54,7 +53,7 @@ CFileSize GetFilePackSize(int fileIndex) const
static SRes SzArEx_Fill(CSzArEx *p, ISzAlloc *alloc)
{
UInt32 startPos = 0;
CFileSize startPosSize = 0;
UInt64 startPosSize = 0;
UInt32 i;
UInt32 folderIndex = 0;
UInt32 indexInFolder = 0;
@@ -65,7 +64,7 @@ static SRes SzArEx_Fill(CSzArEx *p, ISzAlloc *alloc)
startPos += p->db.Folders[i].NumPackStreams;
}
MY_ALLOC(CFileSize, p->PackStreamStartPositions, p->db.NumPackStreams, alloc);
MY_ALLOC(UInt64, p->PackStreamStartPositions, p->db.NumPackStreams, alloc);
for (i = 0; i < p->db.NumPackStreams; i++)
{
@@ -115,22 +114,22 @@ static SRes SzArEx_Fill(CSzArEx *p, ISzAlloc *alloc)
}
CFileSize SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder)
UInt64 SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder)
{
return p->ArchiveInfo.DataStartPosition +
return p->dataPos +
p->PackStreamStartPositions[p->FolderStartPackStreamIndex[folderIndex] + indexInFolder];
}
int SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, CFileSize *resSize)
int SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, UInt64 *resSize)
{
UInt32 packStreamIndex = p->FolderStartPackStreamIndex[folderIndex];
CSzFolder *folder = p->db.Folders + folderIndex;
CFileSize size = 0;
UInt64 size = 0;
UInt32 i;
for (i = 0; i < folder->NumPackStreams; i++)
{
CFileSize t = size + p->db.PackSizes[packStreamIndex + i];
if (t < size) // check it
UInt64 t = size + p->db.PackSizes[packStreamIndex + i];
if (t < size) /* check it */
return SZ_ERROR_FAIL;
size = t;
}
@@ -173,58 +172,6 @@ SRes SzReadTime(const CObjectVector<CBuf> &dataVector,
}
*/
static SRes SafeReadDirect(ISzInStream *inStream, Byte *data, size_t size)
{
while (size > 0)
{
void *inBufferSpec;
size_t processedSize = size;
const Byte *inBuffer;
RINOK(inStream->Read(inStream, (void **)&inBufferSpec, &processedSize));
inBuffer = (const Byte *)inBufferSpec;
if (processedSize == 0)
return SZ_ERROR_INPUT_EOF;
size -= processedSize;
do
*data++ = *inBuffer++;
while (--processedSize != 0);
}
return SZ_OK;
}
static SRes SafeReadDirectByte(ISzInStream *inStream, Byte *data)
{
return SafeReadDirect(inStream, data, 1);
}
static SRes SafeReadDirectUInt32(ISzInStream *inStream, UInt32 *value, UInt32 *crc)
{
int i;
*value = 0;
for (i = 0; i < 4; i++)
{
Byte b;
RINOK(SafeReadDirectByte(inStream, &b));
*value |= ((UInt32)b << (8 * i));
*crc = CRC_UPDATE_BYTE(*crc, b);
}
return SZ_OK;
}
static SRes SafeReadDirectUInt64(ISzInStream *inStream, UInt64 *value, UInt32 *crc)
{
int i;
*value = 0;
for (i = 0; i < 8; i++)
{
Byte b;
RINOK(SafeReadDirectByte(inStream, &b));
*value |= ((UInt64)b << (8 * i));
*crc = CRC_UPDATE_BYTE(*crc, b);
}
return SZ_OK;
}
static int TestSignatureCandidate(Byte *testBytes)
{
size_t i;
@@ -295,14 +242,6 @@ static SRes SzReadNumber(CSzData *sd, UInt64 *value)
return SZ_OK;
}
static SRes SzReadSize(CSzData *sd, CFileSize *value)
{
UInt64 value64;
RINOK(SzReadNumber(sd, &value64));
*value = (CFileSize)value64;
return SZ_OK;
}
static SRes SzReadNumber32(CSzData *sd, UInt32 *value)
{
UInt64 value64;
@@ -415,24 +354,24 @@ static SRes SzReadHashDigests(
static SRes SzReadPackInfo(
CSzData *sd,
CFileSize *dataOffset,
UInt64 *dataOffset,
UInt32 *numPackStreams,
CFileSize **packSizes,
UInt64 **packSizes,
Byte **packCRCsDefined,
UInt32 **packCRCs,
ISzAlloc *alloc)
{
UInt32 i;
RINOK(SzReadSize(sd, dataOffset));
RINOK(SzReadNumber(sd, dataOffset));
RINOK(SzReadNumber32(sd, numPackStreams));
RINOK(SzWaitAttribute(sd, k7zIdSize));
MY_ALLOC(CFileSize, *packSizes, (size_t)*numPackStreams, alloc);
MY_ALLOC(UInt64, *packSizes, (size_t)*numPackStreams, alloc);
for (i = 0; i < *numPackStreams; i++)
{
RINOK(SzReadSize(sd, (*packSizes) + i));
RINOK(SzReadNumber(sd, (*packSizes) + i));
}
for (;;)
@@ -498,7 +437,7 @@ static SRes SzGetNextFolderItem(CSzData *sd, CSzFolder *folder, ISzAlloc *alloc)
return SZ_ERROR_UNSUPPORTED;
coder->MethodID = 0;
for (j = 0; j < idSize; j++)
coder->MethodID |= (CMethodID)longID[idSize - 1 - j] << (8 * j);
coder->MethodID |= (UInt64)longID[idSize - 1 - j] << (8 * j);
if ((mainByte & 0x10) != 0)
{
@@ -548,7 +487,7 @@ static SRes SzGetNextFolderItem(CSzData *sd, CSzFolder *folder, ISzAlloc *alloc)
for (i = 0; i < numBindPairs; i++)
{
CBindPair *bindPair = folder->BindPairs + i;;
CBindPair *bindPair = folder->BindPairs + i;
RINOK(SzReadNumber32(sd, &bindPair->InIndex));
RINOK(SzReadNumber32(sd, &bindPair->OutIndex));
}
@@ -609,11 +548,11 @@ static SRes SzReadUnpackInfo(
CSzFolder *folder = (*folders) + i;
UInt32 numOutStreams = SzFolder_GetNumOutStreams(folder);
MY_ALLOC(CFileSize, folder->UnpackSizes, (size_t)numOutStreams, alloc);
MY_ALLOC(UInt64, folder->UnpackSizes, (size_t)numOutStreams, alloc);
for (j = 0; j < numOutStreams; j++)
{
RINOK(SzReadSize(sd, folder->UnpackSizes + j));
RINOK(SzReadNumber(sd, folder->UnpackSizes + j));
}
}
@@ -652,7 +591,7 @@ static SRes SzReadSubStreamsInfo(
UInt32 numFolders,
CSzFolder *folders,
UInt32 *numUnpackStreams,
CFileSize **unpackSizes,
UInt64 **unpackSizes,
Byte **digestsDefined,
UInt32 **digests,
ISzAlloc *allocTemp)
@@ -696,7 +635,7 @@ static SRes SzReadSubStreamsInfo(
}
else
{
*unpackSizes = (CFileSize *)IAlloc_Alloc(allocTemp, (size_t)*numUnpackStreams * sizeof(CFileSize));
*unpackSizes = (UInt64 *)IAlloc_Alloc(allocTemp, (size_t)*numUnpackStreams * sizeof(UInt64));
RINOM(*unpackSizes);
*digestsDefined = (Byte *)IAlloc_Alloc(allocTemp, (size_t)*numUnpackStreams * sizeof(Byte));
RINOM(*digestsDefined);
@@ -710,7 +649,7 @@ static SRes SzReadSubStreamsInfo(
v3.13 incorrectly worked with empty folders
v4.07: we check that folder is empty
*/
CFileSize sum = 0;
UInt64 sum = 0;
UInt32 j;
UInt32 numSubstreams = folders[i].NumUnpackStreams;
if (numSubstreams == 0)
@@ -718,8 +657,8 @@ static SRes SzReadSubStreamsInfo(
if (type == k7zIdSize)
for (j = 1; j < numSubstreams; j++)
{
CFileSize size;
RINOK(SzReadSize(sd, &size));
UInt64 size;
RINOK(SzReadNumber(sd, &size));
(*unpackSizes)[si++] = size;
sum += size;
}
@@ -795,10 +734,10 @@ static SRes SzReadSubStreamsInfo(
static SRes SzReadStreamsInfo(
CSzData *sd,
CFileSize *dataOffset,
UInt64 *dataOffset,
CSzAr *p,
UInt32 *numUnpackStreams,
CFileSize **unpackSizes, /* allocTemp */
UInt64 **unpackSizes, /* allocTemp */
Byte **digestsDefined, /* allocTemp */
UInt32 **digests, /* allocTemp */
ISzAlloc *alloc,
@@ -917,7 +856,7 @@ static SRes SzReadFileNames(CSzData *sd, UInt32 numFiles, CSzFileItem *files, IS
static SRes SzReadHeader2(
CSzArEx *p, /* allocMain */
CSzData *sd,
CFileSize **unpackSizes, /* allocTemp */
UInt64 **unpackSizes, /* allocTemp */
Byte **digestsDefined, /* allocTemp */
UInt32 **digests, /* allocTemp */
Byte **emptyStreamVector, /* allocTemp */
@@ -945,13 +884,13 @@ static SRes SzReadHeader2(
if (type == k7zIdMainStreamsInfo)
{
RINOK(SzReadStreamsInfo(sd,
&p->ArchiveInfo.DataStartPosition,
&p->dataPos,
&p->db,
&numUnpackStreams,
unpackSizes,
digestsDefined,
digests, allocMain, allocTemp));
p->ArchiveInfo.DataStartPosition += p->ArchiveInfo.StartPositionAfterHeader;
p->dataPos += p->startPosAfterHeader;
RINOK(SzReadID(sd, &type));
}
@@ -1070,7 +1009,7 @@ static SRes SzReadHeader(
ISzAlloc *allocMain,
ISzAlloc *allocTemp)
{
CFileSize *unpackSizes = 0;
UInt64 *unpackSizes = 0;
Byte *digestsDefined = 0;
UInt32 *digests = 0;
Byte *emptyStreamVector = 0;
@@ -1090,21 +1029,21 @@ static SRes SzReadHeader(
}
static SRes SzReadAndDecodePackedStreams2(
ISzInStream *inStream,
ILookInStream *inStream,
CSzData *sd,
CBuf *outBuffer,
CFileSize baseOffset,
UInt64 baseOffset,
CSzAr *p,
CFileSize **unpackSizes,
UInt64 **unpackSizes,
Byte **digestsDefined,
UInt32 **digests,
ISzAlloc *allocTemp)
{
UInt32 numUnpackStreams = 0;
CFileSize dataStartPos;
UInt64 dataStartPos;
CSzFolder *folder;
CFileSize unpackSize;
UInt64 unpackSize;
SRes res;
RINOK(SzReadStreamsInfo(sd, &dataStartPos, p,
@@ -1118,7 +1057,7 @@ static SRes SzReadAndDecodePackedStreams2(
folder = p->Folders;
unpackSize = SzFolder_GetUnpackSize(folder);
RINOK(inStream->Seek(inStream, dataStartPos, SZ_SEEK_SET));
RINOK(LookInStream_SeekTo(inStream, dataStartPos));
if (!Buf_Create(outBuffer, (size_t)unpackSize, allocTemp))
return SZ_ERROR_MEM;
@@ -1134,14 +1073,14 @@ static SRes SzReadAndDecodePackedStreams2(
}
static SRes SzReadAndDecodePackedStreams(
ISzInStream *inStream,
ILookInStream *inStream,
CSzData *sd,
CBuf *outBuffer,
CFileSize baseOffset,
UInt64 baseOffset,
ISzAlloc *allocTemp)
{
CSzAr p;
CFileSize *unpackSizes = 0;
UInt64 *unpackSizes = 0;
Byte *digestsDefined = 0;
UInt32 *digests = 0;
SRes res;
@@ -1158,105 +1097,101 @@ static SRes SzReadAndDecodePackedStreams(
static SRes SzArEx_Open2(
CSzArEx *p,
ISzInStream *inStream,
ILookInStream *inStream,
ISzAlloc *allocMain,
ISzAlloc *allocTemp)
{
Byte signature[k7zSignatureSize];
Byte version;
UInt32 crcFromArchive;
UInt64 nextHeaderOffset;
UInt64 nextHeaderSize;
Byte header[k7zStartHeaderSize];
UInt64 nextHeaderOffset, nextHeaderSize;
size_t nextHeaderSizeT;
UInt32 nextHeaderCRC;
UInt32 crc = 0;
CFileSize pos = 0;
CBuf buffer;
CSzData sd;
SRes res;
if (SafeReadDirect(inStream, signature, k7zSignatureSize) != SZ_OK)
return SZ_ERROR_NO_ARCHIVE;
RINOK(LookInStream_Read2(inStream, header, k7zStartHeaderSize, SZ_ERROR_NO_ARCHIVE));
if (!TestSignatureCandidate(signature))
if (!TestSignatureCandidate(header))
return SZ_ERROR_NO_ARCHIVE;
/*
p.Clear();
p.ArchiveInfo.StartPosition = _arhiveBeginStreamPosition;
*/
RINOK(SafeReadDirectByte(inStream, &version));
if (version != k7zMajorVersion)
if (header[6] != k7zMajorVersion)
return SZ_ERROR_UNSUPPORTED;
RINOK(SafeReadDirectByte(inStream, &version));
RINOK(SafeReadDirectUInt32(inStream, &crcFromArchive, &crc));
nextHeaderOffset = GetUi64(header + 12);
nextHeaderSize = GetUi64(header + 20);
nextHeaderCRC = GetUi32(header + 28);
crc = CRC_INIT_VAL;
RINOK(SafeReadDirectUInt64(inStream, &nextHeaderOffset, &crc));
RINOK(SafeReadDirectUInt64(inStream, &nextHeaderSize, &crc));
RINOK(SafeReadDirectUInt32(inStream, &nextHeaderCRC, &crc));
pos = k7zStartHeaderSize;
p->ArchiveInfo.StartPositionAfterHeader = pos;
p->startPosAfterHeader = k7zStartHeaderSize;
if (CRC_GET_DIGEST(crc) != crcFromArchive)
if (CrcCalc(header + 12, 20) != GetUi32(header + 8))
return SZ_ERROR_CRC;
if (nextHeaderSize == 0)
nextHeaderSizeT = (size_t)nextHeaderSize;
if (nextHeaderSizeT != nextHeaderSize)
return SZ_ERROR_MEM;
if (nextHeaderSizeT == 0)
return SZ_OK;
if (nextHeaderOffset > nextHeaderOffset + nextHeaderSize ||
nextHeaderOffset > nextHeaderOffset + nextHeaderSize + k7zStartHeaderSize)
return SZ_ERROR_NO_ARCHIVE;
RINOK(inStream->Seek(inStream, (CFileSize)(pos + nextHeaderOffset), SZ_SEEK_SET));
{
Int64 pos = 0;
RINOK(inStream->Seek(inStream, &pos, SZ_SEEK_END));
if ((UInt64)pos < nextHeaderOffset ||
(UInt64)pos < k7zStartHeaderSize + nextHeaderOffset ||
(UInt64)pos < k7zStartHeaderSize + nextHeaderOffset + nextHeaderSize)
return SZ_ERROR_INPUT_EOF;
}
if (!Buf_Create(&buffer, (size_t)nextHeaderSize, allocTemp))
RINOK(LookInStream_SeekTo(inStream, k7zStartHeaderSize + nextHeaderOffset));
if (!Buf_Create(&buffer, nextHeaderSizeT, allocTemp))
return SZ_ERROR_MEM;
res = SafeReadDirect(inStream, buffer.data, (size_t)nextHeaderSize);
res = LookInStream_Read(inStream, buffer.data, nextHeaderSizeT);
if (res == SZ_OK)
{
res = SZ_ERROR_ARCHIVE;
if (CrcCalc(buffer.data, (size_t)nextHeaderSize) == nextHeaderCRC)
if (CrcCalc(buffer.data, nextHeaderSizeT) == nextHeaderCRC)
{
for (;;)
CSzData sd;
UInt64 type;
sd.Data = buffer.data;
sd.Size = buffer.size;
res = SzReadID(&sd, &type);
if (res == SZ_OK)
{
UInt64 type;
sd.Data = buffer.data;
sd.Size = buffer.size;
res = SzReadID(&sd, &type);
if (res != SZ_OK)
break;
if (type == k7zIdHeader)
{
res = SzReadHeader(p, &sd, allocMain, allocTemp);
break;
}
if (type != k7zIdEncodedHeader)
{
res = SZ_ERROR_UNSUPPORTED;
break;
}
if (type == k7zIdEncodedHeader)
{
CBuf outBuffer;
Buf_Init(&outBuffer);
res = SzReadAndDecodePackedStreams(inStream, &sd, &outBuffer,
p->ArchiveInfo.StartPositionAfterHeader,
allocTemp);
res = SzReadAndDecodePackedStreams(inStream, &sd, &outBuffer, p->startPosAfterHeader, allocTemp);
if (res != SZ_OK)
{
Buf_Free(&outBuffer, allocTemp);
break;
else
{
Buf_Free(&buffer, allocTemp);
buffer.data = outBuffer.data;
buffer.size = outBuffer.size;
sd.Data = buffer.data;
sd.Size = buffer.size;
res = SzReadID(&sd, &type);
}
Buf_Free(&buffer, allocTemp);
buffer.data = outBuffer.data;
buffer.size = outBuffer.size;
}
}
if (res == SZ_OK)
{
if (type == k7zIdHeader)
res = SzReadHeader(p, &sd, allocMain, allocTemp);
else
res = SZ_ERROR_UNSUPPORTED;
}
}
}
Buf_Free(&buffer, allocTemp);
return res;
}
SRes SzArEx_Open(CSzArEx *p, ISzInStream *inStream, ISzAlloc *allocMain, ISzAlloc *allocTemp)
SRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream, ISzAlloc *allocMain, ISzAlloc *allocTemp)
{
SRes res = SzArEx_Open2(p, inStream, allocMain, allocTemp);
if (res != SZ_OK)

View File

@@ -1,8 +1,5 @@
/* 7zIn.h -- 7z Input functions
2008-08-05
Igor Pavlov
Copyright (c) 1999-2008 Igor Pavlov
Read 7zItem.h for license options */
2008-11-23 : Igor Pavlov : Public domain */
#ifndef __7Z_IN_H
#define __7Z_IN_H
@@ -10,43 +7,24 @@ Read 7zItem.h for license options */
#include "7zHeader.h"
#include "7zItem.h"
typedef struct
{
CFileSize StartPositionAfterHeader;
CFileSize DataStartPosition;
} CInArchiveInfo;
typedef struct
{
CSzAr db;
CInArchiveInfo ArchiveInfo;
UInt64 startPosAfterHeader;
UInt64 dataPos;
UInt32 *FolderStartPackStreamIndex;
CFileSize *PackStreamStartPositions;
UInt64 *PackStreamStartPositions;
UInt32 *FolderStartFileIndex;
UInt32 *FileIndexToFolderIndexMap;
} CSzArEx;
void SzArEx_Init(CSzArEx *p);
void SzArEx_Free(CSzArEx *p, ISzAlloc *alloc);
CFileSize SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder);
int SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, CFileSize *resSize);
UInt64 SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder);
int SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, UInt64 *resSize);
typedef enum
{
SZ_SEEK_SET = 0,
SZ_SEEK_CUR = 1,
SZ_SEEK_END = 2
} ESzSeek;
typedef struct
{
SRes (*Read)(void *object, void **buf, size_t *size);
/* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
(output(*size) < input(*size)) is allowed */
SRes (*Seek)(void *object, CFileSize pos, ESzSeek origin);
} ISzInStream;
/*
Errors:
SZ_ERROR_NO_ARCHIVE
@@ -58,6 +36,6 @@ SZ_ERROR_INPUT_EOF
SZ_ERROR_FAIL
*/
SRes SzArEx_Open(CSzArEx *p, ISzInStream *inStream, ISzAlloc *allocMain, ISzAlloc *allocTemp);
SRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream, ISzAlloc *allocMain, ISzAlloc *allocTemp);
#endif

View File

@@ -1,8 +1,5 @@
/* 7zItem.c -- 7z Items
2008-08-05
Igor Pavlov
Copyright (c) 1999-2008 Igor Pavlov
Read 7zItem.h for license options */
2008-10-04 : Igor Pavlov : Public domain */
#include "7zItem.h"
@@ -72,7 +69,7 @@ int SzFolder_FindBindPairForOutStream(CSzFolder *p, UInt32 outStreamIndex)
return -1;
}
CFileSize SzFolder_GetUnpackSize(CSzFolder *p)
UInt64 SzFolder_GetUnpackSize(CSzFolder *p)
{
int i = (int)SzFolder_GetNumOutStreams(p);
if (i == 0)

View File

@@ -1,30 +1,16 @@
/* 7zItem.h -- 7z Items
2008-07-09
Igor Pavlov
Copyright (c) 1999-2008 Igor Pavlov
Read LzmaDec.h for license options */
2008-10-04 : Igor Pavlov : Public domain */
#ifndef __7Z_ITEM_H
#define __7Z_ITEM_H
#include "../../7zBuf.h"
/* #define _SZ_FILE_SIZE_32 */
/* You can define _SZ_FILE_SIZE_32, if you don't need support for files larger than 4 GB*/
#ifdef _SZ_FILE_SIZE_32
typedef UInt32 CFileSize;
#else
typedef UInt64 CFileSize;
#endif
typedef UInt64 CMethodID;
typedef struct
{
UInt32 NumInStreams;
UInt32 NumOutStreams;
CMethodID MethodID;
UInt64 MethodID;
CBuf Props;
} CSzCoderInfo;
@@ -42,7 +28,7 @@ typedef struct
CSzCoderInfo *Coders;
CBindPair *BindPairs;
UInt32 *PackStreams;
CFileSize *UnpackSizes;
UInt64 *UnpackSizes;
UInt32 NumCoders;
UInt32 NumBindPairs;
UInt32 NumPackStreams;
@@ -53,10 +39,10 @@ typedef struct
} CSzFolder;
void SzFolder_Init(CSzFolder *p);
CFileSize SzFolder_GetUnpackSize(CSzFolder *p);
UInt64 SzFolder_GetUnpackSize(CSzFolder *p);
int SzFolder_FindBindPairForInStream(CSzFolder *p, UInt32 inStreamIndex);
UInt32 SzFolder_GetNumOutStreams(CSzFolder *p);
CFileSize SzFolder_GetUnpackSize(CSzFolder *p);
UInt64 SzFolder_GetUnpackSize(CSzFolder *p);
typedef struct
{
@@ -67,7 +53,7 @@ typedef struct
typedef struct
{
CNtfsFileTime MTime;
CFileSize Size;
UInt64 Size;
char *Name;
UInt32 FileCRC;
@@ -82,7 +68,7 @@ void SzFile_Init(CSzFileItem *p);
typedef struct
{
CFileSize *PackSizes;
UInt64 *PackSizes;
Byte *PackCRCsDefined;
UInt32 *PackCRCs;
CSzFolder *Folders;

View File

@@ -1,34 +1,19 @@
/* 7zMain.c - Test application for 7z Decoder
2008-08-17
Igor Pavlov
Public domain */
2008-11-23 : Igor Pavlov : Public domain */
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifdef _WIN32
#define USE_WINDOWS_FUNCTIONS
#endif
#ifdef USE_WINDOWS_FUNCTIONS
#include <windows.h>
#endif
#include "7zIn.h"
#include "7zExtract.h"
#include "7zAlloc.h"
#include "../../7zCrc.h"
#include "../../7zFile.h"
#include "../../7zVersion.h"
#include "7zAlloc.h"
#include "7zExtract.h"
#include "7zIn.h"
#ifdef USE_WINDOWS_FUNCTIONS
typedef HANDLE MY_FILE_HANDLE;
#else
typedef FILE *MY_FILE_HANDLE;
#endif
void ConvertNumberToString(CFileSize value, char *s)
static void ConvertNumberToString(UInt64 value, char *s)
{
char temp[32];
int pos = 0;
@@ -48,7 +33,7 @@ void ConvertNumberToString(CFileSize value, char *s)
#define PERIOD_100 (PERIOD_4 * 25 - 1)
#define PERIOD_400 (PERIOD_100 * 4 + 1)
void ConvertFileTimeToString(CNtfsFileTime *ft, char *s)
static void ConvertFileTimeToString(CNtfsFileTime *ft, char *s)
{
unsigned year, mon, day, hour, min, sec;
UInt64 v64 = ft->Low | ((UInt64)ft->High << 32);
@@ -99,140 +84,6 @@ void ConvertFileTimeToString(CNtfsFileTime *ft, char *s)
sprintf(s, "%04d-%02d-%02d %02d:%02d:%02d", year, mon, day, hour, min, sec);
}
#ifdef USE_WINDOWS_FUNCTIONS
/*
ReadFile and WriteFile functions in Windows have BUG:
If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1)
from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES
(Insufficient system resources exist to complete the requested service).
*/
#define kChunkSizeMax (1 << 24)
#endif
size_t MyReadFile(MY_FILE_HANDLE file, void *data, size_t size)
{
if (size == 0)
return 0;
#ifdef USE_WINDOWS_FUNCTIONS
{
size_t processedSize = 0;
do
{
DWORD curSize = (size > kChunkSizeMax) ? kChunkSizeMax : (DWORD)size;
DWORD processedLoc = 0;
BOOL res = ReadFile(file, data, curSize, &processedLoc, NULL);
data = (void *)((unsigned char *)data + processedLoc);
size -= processedLoc;
processedSize += processedLoc;
if (!res || processedLoc == 0)
break;
}
while (size > 0);
return processedSize;
}
#else
return fread(data, 1, size, file);
#endif
}
size_t MyWriteFile(MY_FILE_HANDLE file, void *data, size_t size)
{
if (size == 0)
return 0;
#ifdef USE_WINDOWS_FUNCTIONS
{
size_t processedSize = 0;
do
{
DWORD curSize = (size > kChunkSizeMax) ? kChunkSizeMax : (DWORD)size;
DWORD processedLoc = 0;
BOOL res = WriteFile(file, data, curSize, &processedLoc, NULL);
data = (void *)((unsigned char *)data + processedLoc);
size -= processedLoc;
processedSize += processedLoc;
if (!res)
break;
}
while (size > 0);
return processedSize;
}
#else
return fwrite(data, 1, size, file);
#endif
}
int MyCloseFile(MY_FILE_HANDLE file)
{
#ifdef USE_WINDOWS_FUNCTIONS
return (CloseHandle(file) != FALSE) ? 0 : 1;
#else
return fclose(file);
#endif
}
typedef struct _CFileInStream
{
ISzInStream InStream;
MY_FILE_HANDLE File;
} CFileInStream;
#define kBufferSize (1 << 12)
Byte g_Buffer[kBufferSize];
SRes SzFileReadImp(void *object, void **buffer, size_t *size)
{
CFileInStream *s = (CFileInStream *)object;
if (*size > kBufferSize)
*size = kBufferSize;
*size = MyReadFile(s->File, g_Buffer, *size);
*buffer = g_Buffer;
return SZ_OK;
}
SRes SzFileSeekImp(void *object, CFileSize pos, ESzSeek origin)
{
CFileInStream *s = (CFileInStream *)object;
#ifdef USE_WINDOWS_FUNCTIONS
{
LARGE_INTEGER value;
DWORD moveMethod;
value.LowPart = (DWORD)pos;
value.HighPart = (LONG)((UInt64)pos >> 32);
#ifdef _SZ_FILE_SIZE_32
/* VC 6.0 has bug with >> 32 shifts. */
value.HighPart = 0;
#endif
switch (origin)
{
case SZ_SEEK_SET: moveMethod = FILE_BEGIN; break;
case SZ_SEEK_CUR: moveMethod = FILE_CURRENT; break;
case SZ_SEEK_END: moveMethod = FILE_END; break;
default: return SZ_ERROR_PARAM;
}
value.LowPart = SetFilePointer(s->File, value.LowPart, &value.HighPart, moveMethod);
if (value.LowPart == 0xFFFFFFFF)
if (GetLastError() != NO_ERROR)
return SZ_ERROR_FAIL;
return SZ_OK;
}
#else
int moveMethod;
int res;
switch (origin)
{
case SZ_SEEK_SET: moveMethod = SEEK_SET; break;
case SZ_SEEK_CUR: moveMethod = SEEK_CUR; break;
case SZ_SEEK_END: moveMethod = SEEK_END; break;
default: return SZ_ERROR_PARAM;
}
res = fseek(s->File, (long)pos, moveMethod );
return (res == 0) ? SZ_OK : SZ_ERROR_FAIL;
#endif
}
void PrintError(char *sz)
{
printf("\nERROR: %s\n", sz);
@@ -241,12 +92,13 @@ void PrintError(char *sz)
int MY_CDECL main(int numargs, char *args[])
{
CFileInStream archiveStream;
CLookToRead lookStream;
CSzArEx db;
SRes res;
ISzAlloc allocImp;
ISzAlloc allocTempImp;
printf("\n7z ANSI-C Decoder 4.59 Copyright (c) 1999-2008 Igor Pavlov 2008-07-09\n");
printf("\n7z ANSI-C Decoder " MY_VERSION_COPYRIGHT_DATE "\n");
if (numargs == 1)
{
printf(
@@ -263,22 +115,18 @@ int MY_CDECL main(int numargs, char *args[])
return 1;
}
archiveStream.File =
#ifdef USE_WINDOWS_FUNCTIONS
CreateFileA(args[2], GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (archiveStream.File == INVALID_HANDLE_VALUE)
#else
archiveStream.File = fopen(args[2], "rb");
if (archiveStream.File == 0)
#endif
if (InFile_Open(&archiveStream.file, args[2]))
{
PrintError("can not open input file");
return 1;
}
archiveStream.InStream.Read = SzFileReadImp;
archiveStream.InStream.Seek = SzFileSeekImp;
FileInStream_CreateVTable(&archiveStream);
LookToRead_CreateVTable(&lookStream, False);
lookStream.realStream = &archiveStream.s;
LookToRead_Init(&lookStream);
allocImp.Alloc = SzAlloc;
allocImp.Free = SzFree;
@@ -289,19 +137,14 @@ int MY_CDECL main(int numargs, char *args[])
CrcGenerateTable();
SzArEx_Init(&db);
res = SzArEx_Open(&db, &archiveStream.InStream, &allocImp, &allocTempImp);
res = SzArEx_Open(&db, &lookStream.s, &allocImp, &allocTempImp);
if (res == SZ_OK)
{
char *command = args[1];
int listCommand = 0;
int testCommand = 0;
int extractCommand = 0;
if (strcmp(command, "l") == 0)
listCommand = 1;
if (strcmp(command, "t") == 0)
testCommand = 1;
else if (strcmp(command, "e") == 0)
extractCommand = 1;
int listCommand = 0, testCommand = 0, extractCommand = 0;
if (strcmp(command, "l") == 0) listCommand = 1;
else if (strcmp(command, "t") == 0) testCommand = 1;
else if (strcmp(command, "e") == 0) extractCommand = 1;
if (listCommand)
{
@@ -316,7 +159,7 @@ int MY_CDECL main(int numargs, char *args[])
else
strcpy(t, " ");
printf("%10s %s %s\n", s, t, f->Name);
printf("%s %10s %s\n", t, s, f->Name);
}
}
else if (testCommand || extractCommand)
@@ -349,7 +192,7 @@ int MY_CDECL main(int numargs, char *args[])
printf("\n");
continue;
}
res = SzAr_Extract(&db, &archiveStream.InStream, i,
res = SzAr_Extract(&db, &lookStream.s, i,
&blockIndex, &outBuffer, &outBufferSize,
&offset, &outSizeProcessed,
&allocImp, &allocTempImp);
@@ -357,7 +200,7 @@ int MY_CDECL main(int numargs, char *args[])
break;
if (!testCommand)
{
MY_FILE_HANDLE outputHandle;
CSzFile outFile;
size_t processedSize;
char *fileName = f->Name;
size_t nameLen = strlen(f->Name);
@@ -368,28 +211,21 @@ int MY_CDECL main(int numargs, char *args[])
break;
}
outputHandle =
#ifdef USE_WINDOWS_FUNCTIONS
CreateFileA(fileName, GENERIC_WRITE, FILE_SHARE_READ,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (outputHandle == INVALID_HANDLE_VALUE)
#else
fopen(fileName, "wb+");
if (outputHandle == 0)
#endif
if (OutFile_Open(&outFile, fileName))
{
PrintError("can not open output file");
res = SZ_ERROR_FAIL;
break;
}
processedSize = MyWriteFile(outputHandle, outBuffer + offset, outSizeProcessed);
if (processedSize != outSizeProcessed)
processedSize = outSizeProcessed;
if (File_Write(&outFile, outBuffer + offset, &processedSize) != 0 ||
processedSize != outSizeProcessed)
{
PrintError("can not write output file");
res = SZ_ERROR_FAIL;
break;
}
if (MyCloseFile(outputHandle))
if (File_Close(&outFile))
{
PrintError("can not close output file");
res = SZ_ERROR_FAIL;
@@ -408,7 +244,7 @@ int MY_CDECL main(int numargs, char *args[])
}
SzArEx_Free(&db, &allocImp);
MyCloseFile(archiveStream.File);
File_Close(&archiveStream.file);
if (res == SZ_OK)
{
printf("\nEverything is Ok\n");

View File

@@ -4,10 +4,13 @@ PROG = 7zDec.exe
C_OBJS = \
$O\7zBuf.obj \
$O\7zBuf2.obj \
$O\7zCrc.obj \
$O\LzmaDec.obj \
$O\Bra86.obj \
$O\Bcj2.obj \
$O\7zFile.obj \
$O\7zStream.obj \
7Z_OBJS = \
$O\7zAlloc.obj \

View File

@@ -4,7 +4,7 @@ LIB =
RM = rm -f
CFLAGS = -c -O2 -Wall
OBJS = 7zAlloc.o 7zBuf.o 7zCrc.o 7zDecode.o 7zExtract.o 7zHeader.o 7zIn.o 7zItem.o 7zMain.o LzmaDec.o Bra86.o Bcj2.o
OBJS = 7zAlloc.o 7zBuf.o 7zBuf2.o 7zCrc.o 7zDecode.o 7zExtract.o 7zHeader.o 7zIn.o 7zItem.o 7zMain.o LzmaDec.o Bra86.o Bcj2.o 7zFile.o 7zStream.o
all: $(PROG)
@@ -17,6 +17,9 @@ $(PROG): $(OBJS)
7zBuf.o: ../../7zBuf.c
$(CXX) $(CFLAGS) ../../7zBuf.c
7zBuf2.o: ../../7zBuf2.c
$(CXX) $(CFLAGS) ../../7zBuf2.c
7zCrc.o: ../../7zCrc.c
$(CXX) $(CFLAGS) ../../7zCrc.c
@@ -47,6 +50,12 @@ Bra86.o: ../../Bra86.c
Bcj2.o: ../../Bcj2.c
$(CXX) $(CFLAGS) ../../Bcj2.c
7zFile.o: ../../7zFile.c
$(CXX) $(CFLAGS) ../../7zFile.c
7zStream.o: ../../7zStream.c
$(CXX) $(CFLAGS) ../../7zStream.c
clean:
-$(RM) $(PROG) $(OBJS)

View File

@@ -1,7 +1,5 @@
/* Bcj2.c -- Converter for x86 code (BCJ2)
2008-08-17
Copyright (c) 1999-2008 Igor Pavlov
Read Bra.h for license options */
2008-10-04 : Igor Pavlov : Public domain */
#include "Bcj2.h"

View File

@@ -1,7 +1,5 @@
/* Bcj2.h -- Converter for x86 code (BCJ2)
2008-08-05
Copyright (c) 1999-2008 Igor Pavlov
Read Bra.h for license options */
2008-10-04 : Igor Pavlov : Public domain */
#ifndef __BCJ2_H
#define __BCJ2_H

View File

@@ -1,7 +1,5 @@
/* Bra.c -- converters for RISC code
2008-08-05
Copyright (c) 1999-2008 Igor Pavlov
Read Bra.h for license options */
/* Bra.c -- Converters for RISC code
2008-10-04 : Igor Pavlov : Public domain */
#include "Bra.h"

View File

@@ -1,7 +1,5 @@
/* Bra.h -- Branch converters for executables
2008-08-17
Copyright (c) 1999-2008 Igor Pavlov
Read LzmaDec.h for license options */
2008-10-04 : Igor Pavlov : Public domain */
#ifndef __BRA_H
#define __BRA_H
@@ -43,7 +41,7 @@ in CALL instructions to increase the compression ratio.
UInt32 ip = 0;
for ()
{
// size must be >= Alignment + LookAhead, if it's not last block
; size must be >= Alignment + LookAhead, if it's not last block
SizeT processed = Convert(data, size, ip, 1);
data += processed;
size -= processed;

View File

@@ -1,7 +1,5 @@
/* Bra86.c -- converter for x86 code (BCJ)
2008-08-17
Copyright (c) 1999-2008 Igor Pavlov
Read Bra.h for license options */
/* Bra86.c -- Converter for x86 code (BCJ)
2008-10-04 : Igor Pavlov : Public domain */
#include "Bra.h"

View File

@@ -1,7 +1,5 @@
/* BraIA64.c -- converter for IA-64 code
2008-08-05
Copyright (c) 1999-2008 Igor Pavlov
Read Bra.h for license options */
/* BraIA64.c -- Converter for IA-64 code
2008-10-04 : Igor Pavlov : Public domain */
#include "Bra.h"

View File

@@ -1,7 +1,5 @@
/* LzFind.c -- Match finder for LZ algorithms
2008-08-17
Copyright (c) 1999-2008 Igor Pavlov
Read LzFind.h for license options */
/* LzFind.c -- Match finder for LZ algorithms
2008-10-04 : Igor Pavlov : Public domain */
#include <string.h>

View File

@@ -1,14 +1,5 @@
/* LzFind.h -- Match finder for LZ algorithms
2008-08-05
Copyright (c) 1999-2008 Igor Pavlov
You can use any of the following license options:
1) GNU Lesser General Public License (GNU LGPL)
2) Common Public License (CPL)
3) Common Development and Distribution License (CDDL) Version 1.0
4) Igor Pavlov, as the author of this code, expressly permits you to
statically or dynamically link your code (or bind by name) to this file,
while you keep this file unmodified.
*/
/* LzFind.h -- Match finder for LZ algorithms
2008-10-04 : Igor Pavlov : Public domain */
#ifndef __LZFIND_H
#define __LZFIND_H

View File

@@ -1,7 +1,5 @@
/* LzFindMt.c -- multithreaded Match finder for LZ algorithms
2008-08-17
Copyright (c) 1999-2008 Igor Pavlov
Read LzFind.h for license options */
2008-10-04 : Igor Pavlov : Public domain */
#include "LzHash.h"

View File

@@ -1,7 +1,5 @@
/* LzFindMt.h -- multithreaded Match finder for LZ algorithms
2008-08-05
Copyright (c) 1999-2008 Igor Pavlov
Read LzFind.h for license options */
/* LzFindMt.h -- multithreaded Match finder for LZ algorithms
2008-10-04 : Igor Pavlov : Public domain */
#ifndef __LZFINDMT_H
#define __LZFINDMT_H

View File

@@ -1,7 +1,5 @@
/* LzHash.h -- HASH functions for LZ algorithms
2008-03-26
Copyright (c) 1999-2008 Igor Pavlov
Read LzFind.h for license options */
/* LzHash.h -- HASH functions for LZ algorithms
2008-10-04 : Igor Pavlov : Public domain */
#ifndef __LZHASH_H
#define __LZHASH_H

View File

@@ -1,7 +1,5 @@
/* LzmaDec.c -- LZMA Decoder
2008-08-17
Copyright (c) 1999-2008 Igor Pavlov
Read LzmaDec.h for license options */
2008-11-06 : Igor Pavlov : Public domain */
#include "LzmaDec.h"
@@ -115,12 +113,7 @@ Read LzmaDec.h for license options */
StopCompilingDueBUG
#endif
/*
#define LZMA_STREAM_WAS_FINISHED_ID (-1)
#define LZMA_SPEC_LEN_OFFSET (-3)
*/
const Byte kLiteralNextStates[kNumStates * 2] =
static const Byte kLiteralNextStates[kNumStates * 2] =
{
0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5,
7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10
@@ -132,8 +125,8 @@ const Byte kLiteralNextStates[kNumStates * 2] =
And it decodes new LZMA-symbols while (buf < bufLimit), but "buf" is without last normalization
Out:
Result:
0 - OK
1 - Error
SZ_OK - OK
SZ_ERROR_DATA - Error
p->remainLen:
< kMatchSpecLenStart : normal remain
= kMatchSpecLenStart : finished
@@ -390,6 +383,8 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
len += kMatchMinLen;
if (limit == dicPos)
return SZ_ERROR_DATA;
{
SizeT rem = limit - dicPos;
unsigned curLen = ((rem < len) ? (unsigned)rem : len);
@@ -464,8 +459,6 @@ static void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)
}
}
/* LzmaDec_DecodeReal2 decodes LZMA-symbols and sets p->needFlush and p->needInit, if required. */
static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit)
{
do
@@ -811,7 +804,7 @@ SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *sr
p->buf = src;
if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0)
return SZ_ERROR_DATA;
processed = p->buf - src;
processed = (SizeT)(p->buf - src);
(*srcLen) += processed;
src += processed;
inSize -= processed;

View File

@@ -1,14 +1,5 @@
/* LzmaDec.h -- LZMA Decoder
2008-08-05
Copyright (c) 1999-2008 Igor Pavlov
You can use any of the following license options:
1) GNU Lesser General Public License (GNU LGPL)
2) Common Public License (CPL)
3) Common Development and Distribution License (CDDL) Version 1.0
4) Igor Pavlov, as the author of this code, expressly permits you to
statically or dynamically link your code (or bind by name) to this file,
while you keep this file unmodified.
*/
2008-10-04 : Igor Pavlov : Public domain */
#ifndef __LZMADEC_H
#define __LZMADEC_H

View File

@@ -1,7 +1,5 @@
/* LzmaEnc.c -- LZMA Encoder
2008-08-17
Copyright (c) 1999-2008 Igor Pavlov
Read LzmaEnc.h for license options */
2008-10-04 : Igor Pavlov : Public domain */
#include <string.h>
@@ -2092,6 +2090,8 @@ void LzmaEnc_Finish(CLzmaEncHandle pp)
CLzmaEnc *p = (CLzmaEnc *)pp;
if (p->mtMode)
MatchFinderMt_ReleaseStream(&p->matchFinderMt);
#else
pp = pp;
#endif
}
@@ -2154,7 +2154,7 @@ SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,
RangeEnc_Init(&p->rc);
p->rc.outStream = &outStream.funcTable;
res = LzmaEnc_CodeOneBlock(pp, True, desiredPackSize, *unpackSize);
res = LzmaEnc_CodeOneBlock(p, True, desiredPackSize, *unpackSize);
*unpackSize = (UInt32)(p->nowPos64 - nowPos64);
*destLen -= outStream.rem;
@@ -2181,7 +2181,7 @@ SRes LzmaEnc_Encode(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *i
for (;;)
{
res = LzmaEnc_CodeOneBlock(pp, False, 0, 0);
res = LzmaEnc_CodeOneBlock(p, False, 0, 0);
if (res != SZ_OK || p->finished != 0)
break;
if (progress != 0)

View File

@@ -1,7 +1,5 @@
/* LzmaEnc.h -- LZMA Encoder
2008-08-05
Copyright (c) 1999-2008 Igor Pavlov
Read LzFind.h for license options */
2008-10-04 : Igor Pavlov : Public domain */
#ifndef __LZMAENC_H
#define __LZMAENC_H

View File

@@ -1,7 +1,5 @@
/* LzmaLibExports.c -- LZMA library DLL Entry point
2008-03-26
Igor Pavlov
Public domain */
/* LzmaLibExports.c -- LZMA library DLL Entry point
2008-10-04 : Igor Pavlov : Public domain */
#include <windows.h>

View File

@@ -1,7 +1,5 @@
/* LzmaUtil.c -- Test application for LZMA compression
2008-08-05
Igor Pavlov
public domain */
2008-11-23 : Igor Pavlov : Public domain */
#define _CRT_SECURE_NO_WARNINGS
@@ -9,9 +7,11 @@ public domain */
#include <stdlib.h>
#include <string.h>
#include "../Alloc.h"
#include "../7zFile.h"
#include "../7zVersion.h"
#include "../LzmaDec.h"
#include "../LzmaEnc.h"
#include "../Alloc.h"
const char *kCantReadMessage = "Can not read input file";
const char *kCantWriteMessage = "Can not write output file";
@@ -19,43 +19,12 @@ const char *kCantAllocateMessage = "Can not allocate memory";
const char *kDataErrorMessage = "Data error";
static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }
static void SzFree(void *p, void *address) { p = p; MyFree(address); }
static void SzFree(void *p, void *address) { p = p; MyFree(address); }
static ISzAlloc g_Alloc = { SzAlloc, SzFree };
#define kInBufferSize (1 << 15)
#define kOutBufferSize (1 << 15)
unsigned char g_InBuffer[kInBufferSize];
unsigned char g_OutBuffer[kOutBufferSize];
size_t MyReadFile(FILE *file, void *data, size_t size)
{ return fread(data, 1, size, file); }
int MyReadFileAndCheck(FILE *file, void *data, size_t size)
{ return (MyReadFile(file, data, size) == size); }
size_t MyWriteFile(FILE *file, const void *data, size_t size)
{
if (size == 0)
return 0;
return fwrite(data, 1, size, file);
}
int MyWriteFileAndCheck(FILE *file, const void *data, size_t size)
{ return (MyWriteFile(file, data, size) == size); }
long MyGetFileLength(FILE *file)
{
long length;
fseek(file, 0, SEEK_END);
length = ftell(file);
fseek(file, 0, SEEK_SET);
return length;
}
void PrintHelp(char *buffer)
{
strcat(buffer, "\nLZMA Utility 4.58 Copyright (c) 1999-2008 Igor Pavlov 2008-04-11\n"
strcat(buffer, "\nLZMA Utility " MY_VERSION_COPYRIGHT_DATE "\n"
"\nUsage: lzma <e|d> inputFile outputFile\n"
" e: encode file\n"
" d: decode file\n");
@@ -83,13 +52,65 @@ int PrintUserError(char *buffer)
#define IN_BUF_SIZE (1 << 16)
#define OUT_BUF_SIZE (1 << 16)
static int Decode(FILE *inFile, FILE *outFile, char *rs)
static SRes Decode2(CLzmaDec *state, ISeqOutStream *outStream, ISeqInStream *inStream,
UInt64 unpackSize)
{
int thereIsSize = (unpackSize != (UInt64)(Int64)-1);
Byte inBuf[IN_BUF_SIZE];
Byte outBuf[OUT_BUF_SIZE];
size_t inPos = 0, inSize = 0, outPos = 0;
LzmaDec_Init(state);
for (;;)
{
if (inPos == inSize)
{
inSize = IN_BUF_SIZE;
RINOK(inStream->Read(inStream, inBuf, &inSize));
inPos = 0;
}
{
SRes res;
SizeT inProcessed = inSize - inPos;
SizeT outProcessed = OUT_BUF_SIZE - outPos;
ELzmaFinishMode finishMode = LZMA_FINISH_ANY;
ELzmaStatus status;
if (thereIsSize && outProcessed > unpackSize)
{
outProcessed = (SizeT)unpackSize;
finishMode = LZMA_FINISH_END;
}
res = LzmaDec_DecodeToBuf(state, outBuf + outPos, &outProcessed,
inBuf + inPos, &inProcessed, finishMode, &status);
inPos += inProcessed;
outPos += outProcessed;
unpackSize -= outProcessed;
if (outStream)
if (outStream->Write(outStream, outBuf, outPos) != outPos)
return SZ_ERROR_WRITE;
outPos = 0;
if (res != SZ_OK || thereIsSize && unpackSize == 0)
return res;
if (inProcessed == 0 && outProcessed == 0)
{
if (thereIsSize || status != LZMA_STATUS_FINISHED_WITH_MARK)
return SZ_ERROR_DATA;
return res;
}
}
}
}
static SRes Decode(ISeqOutStream *outStream, ISeqInStream *inStream)
{
UInt64 unpackSize;
int thereIsSize; /* = 1, if there is uncompressed size in headers */
int i;
int res = 0;
SRes res = 0;
CLzmaDec state;
/* header: 5 bytes of LZMA properties and 8 bytes of uncompressed size */
@@ -97,119 +118,31 @@ static int Decode(FILE *inFile, FILE *outFile, char *rs)
/* Read and parse header */
if (!MyReadFileAndCheck(inFile, header, sizeof(header)))
return PrintError(rs, kCantReadMessage);
RINOK(SeqInStream_Read(inStream, header, sizeof(header)));
unpackSize = 0;
thereIsSize = 0;
for (i = 0; i < 8; i++)
{
unsigned char b = header[LZMA_PROPS_SIZE + i];
if (b != 0xFF)
thereIsSize = 1;
unpackSize += (UInt64)b << (i * 8);
}
unpackSize += (UInt64)header[LZMA_PROPS_SIZE + i] << (i * 8);
LzmaDec_Construct(&state);
res = LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc);
if (res != SZ_OK)
return res;
{
Byte inBuf[IN_BUF_SIZE];
Byte outBuf[OUT_BUF_SIZE];
size_t inPos = 0, inSize = 0, outPos = 0;
LzmaDec_Init(&state);
for (;;)
{
if (inPos == inSize)
{
inSize = MyReadFile(inFile, inBuf, IN_BUF_SIZE);
inPos = 0;
}
{
SizeT inProcessed = inSize - inPos;
SizeT outProcessed = OUT_BUF_SIZE - outPos;
ELzmaFinishMode finishMode = LZMA_FINISH_ANY;
ELzmaStatus status;
if (thereIsSize && outProcessed > unpackSize)
{
outProcessed = (SizeT)unpackSize;
finishMode = LZMA_FINISH_END;
}
res = LzmaDec_DecodeToBuf(&state, outBuf + outPos, &outProcessed,
inBuf + inPos, &inProcessed, finishMode, &status);
inPos += (UInt32)inProcessed;
outPos += outProcessed;
unpackSize -= outProcessed;
if (outFile != 0)
MyWriteFile(outFile, outBuf, outPos);
outPos = 0;
if (res != SZ_OK || thereIsSize && unpackSize == 0)
break;
if (inProcessed == 0 && outProcessed == 0)
{
if (thereIsSize || status != LZMA_STATUS_FINISHED_WITH_MARK)
res = SZ_ERROR_DATA;
break;
}
}
}
}
RINOK(LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc));
res = Decode2(&state, outStream, inStream, unpackSize);
LzmaDec_Free(&state, &g_Alloc);
return res;
}
typedef struct _CFileSeqInStream
{
ISeqInStream funcTable;
FILE *file;
} CFileSeqInStream;
static SRes MyRead(void *p, void *buf, size_t *size)
{
if (*size == 0)
return SZ_OK;
*size = MyReadFile(((CFileSeqInStream*)p)->file, buf, *size);
/*
if (*size == 0)
return SZE_FAIL;
*/
return SZ_OK;
}
typedef struct _CFileSeqOutStream
{
ISeqOutStream funcTable;
FILE *file;
} CFileSeqOutStream;
static size_t MyWrite(void *pp, const void *buf, size_t size)
{
return MyWriteFile(((CFileSeqOutStream *)pp)->file, buf, size);
}
static SRes Encode(FILE *inFile, FILE *outFile, char *rs)
static SRes Encode(ISeqOutStream *outStream, ISeqInStream *inStream, UInt64 fileSize, char *rs)
{
CLzmaEncHandle enc;
SRes res;
CFileSeqInStream inStream;
CFileSeqOutStream outStream;
CLzmaEncProps props;
rs = rs;
enc = LzmaEnc_Create(&g_Alloc);
if (enc == 0)
return SZ_ERROR_MEM;
inStream.funcTable.Read = MyRead;
inStream.file = inFile;
outStream.funcTable.Write = MyWrite;
outStream.file = outFile;
LzmaEncProps_Init(&props);
res = LzmaEnc_SetProps(enc, &props);
@@ -217,19 +150,18 @@ static SRes Encode(FILE *inFile, FILE *outFile, char *rs)
{
Byte header[LZMA_PROPS_SIZE + 8];
size_t headerSize = LZMA_PROPS_SIZE;
UInt64 fileSize;
int i;
res = LzmaEnc_WriteProperties(enc, header, &headerSize);
fileSize = MyGetFileLength(inFile);
for (i = 0; i < 8; i++)
header[headerSize++] = (Byte)(fileSize >> (8 * i));
if (!MyWriteFileAndCheck(outFile, header, headerSize))
return PrintError(rs, "writing error");
if (res == SZ_OK)
res = LzmaEnc_Encode(enc, &outStream.funcTable, &inStream.funcTable,
NULL, &g_Alloc, &g_Alloc);
if (outStream->Write(outStream, header, headerSize) != headerSize)
res = SZ_ERROR_WRITE;
else
{
if (res == SZ_OK)
res = LzmaEnc_Encode(enc, outStream, inStream, NULL, &g_Alloc, &g_Alloc);
}
}
LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc);
return res;
@@ -237,11 +169,18 @@ static SRes Encode(FILE *inFile, FILE *outFile, char *rs)
int main2(int numArgs, const char *args[], char *rs)
{
FILE *inFile = 0;
FILE *outFile = 0;
CFileSeqInStream inStream;
CFileOutStream outStream;
char c;
int res;
int encodeMode;
Bool useOutFile = False;
FileSeqInStream_CreateVTable(&inStream);
File_Construct(&inStream.file);
FileOutStream_CreateVTable(&outStream);
File_Construct(&outStream.file);
if (numArgs == 1)
{
@@ -261,17 +200,16 @@ int main2(int numArgs, const char *args[], char *rs)
size_t t4 = sizeof(UInt32);
size_t t8 = sizeof(UInt64);
if (t4 != 4 || t8 != 8)
return PrintError(rs, "LZMA UTil needs correct UInt32 and UInt64");
return PrintError(rs, "Incorrect UInt32 or UInt64");
}
inFile = fopen(args[2], "rb");
if (inFile == 0)
if (InFile_Open(&inStream.file, args[2]) != 0)
return PrintError(rs, "Can not open input file");
if (numArgs > 3)
{
outFile = fopen(args[3], "wb+");
if (outFile == 0)
useOutFile = True;
if (OutFile_Open(&outStream.file, args[3]) != 0)
return PrintError(rs, "Can not open output file");
}
else if (encodeMode)
@@ -279,16 +217,18 @@ int main2(int numArgs, const char *args[], char *rs)
if (encodeMode)
{
res = Encode(inFile, outFile, rs);
UInt64 fileSize;
File_GetLength(&inStream.file, &fileSize);
res = Encode(&outStream.s, &inStream.s, fileSize, rs);
}
else
{
res = Decode(inFile, outFile, rs);
res = Decode(&outStream.s, useOutFile ? &inStream.s : NULL);
}
if (outFile != 0)
fclose(outFile);
fclose(inFile);
if (useOutFile)
File_Close(&outStream.file);
File_Close(&inStream.file);
if (res != SZ_OK)
{
@@ -296,8 +236,11 @@ int main2(int numArgs, const char *args[], char *rs)
return PrintError(rs, kCantAllocateMessage);
else if (res == SZ_ERROR_DATA)
return PrintError(rs, kDataErrorMessage);
else
return PrintErrorNumber(rs, res);
else if (res == SZ_ERROR_WRITE)
return PrintError(rs, kCantWriteMessage);
else if (res == SZ_ERROR_READ)
return PrintError(rs, kCantReadMessage);
return PrintErrorNumber(rs, res);
}
return 0;
}

View File

@@ -86,6 +86,22 @@ LINK32=link.exe
# Name "LzmaUtil - Win32 Debug"
# Begin Source File
SOURCE=..\7zFile.c
# End Source File
# Begin Source File
SOURCE=..\7zFile.h
# End Source File
# Begin Source File
SOURCE=..\7zStream.c
# End Source File
# Begin Source File
SOURCE=..\7zVersion.h
# End Source File
# Begin Source File
SOURCE=..\Alloc.c
# End Source File
# Begin Source File

View File

@@ -13,6 +13,8 @@ C_OBJS = \
$O\LzFindMt.obj \
$O\LzmaDec.obj \
$O\LzmaEnc.obj \
$O\7zFile.obj \
$O\7zStream.obj \
$O\Threads.obj \
OBJS = \

View File

@@ -10,6 +10,8 @@ OBJS = \
LzFind.o \
LzmaDec.o \
LzmaEnc.o \
7zFile.o \
7zStream.o \
all: $(PROG)
@@ -32,5 +34,11 @@ LzmaDec.o: ../LzmaDec.c
LzmaEnc.o: ../LzmaEnc.c
$(CXX) $(CFLAGS) ../LzmaEnc.c
7zFile.o: ../7zFile.c
$(CXX) $(CFLAGS) ../7zFile.c
7zStream.o: ../7zStream.c
$(CXX) $(CFLAGS) ../7zStream.c
clean:
-$(RM) $(PROG) $(OBJS)

View File

@@ -1,8 +1,6 @@
/* Crypto/Sha256.c -- SHA-256 Hash function
2008-08-05
This code is based on public domain code from Wei Dai's Crypto++ library.
Igor Pavlov
Public domain */
2008-11-06 : Igor Pavlov : Public domain
This code is based on public domain code from Wei Dai's Crypto++ library. */
#include "Sha256.h"
#include "RotateDefs.h"

View File

@@ -1,7 +1,5 @@
/* Crypto/Sha256.h -- SHA-256 Hash function
2008-08-05
Igor Pavlov
Public domain */
2008-10-04 : Igor Pavlov : Public domain */
#ifndef __CRYPTO_SHA256_H
#define __CRYPTO_SHA256_H

View File

@@ -1,13 +1,9 @@
/* Threads.h -- multithreading library
2008-04-11
Igor Pavlov
Public domain */
2008-11-22 : Igor Pavlov : Public domain */
#ifndef __7Z_THRESDS_H
#define __7Z_THRESDS_H
#include <windows.h>
#include "Types.h"
typedef struct _CThread
@@ -22,8 +18,6 @@ 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
typedef DWORD WRes;
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);

View File

@@ -1,11 +1,15 @@
/* Types.h -- Basic types
2008-08-05
Igor Pavlov
Public domain */
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
@@ -26,6 +30,12 @@ Public domain */
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
@@ -42,11 +52,11 @@ typedef int Int32;
typedef unsigned int UInt32;
#endif
/* #define _SZ_NO_INT_64 */
/* define it if your compiler doesn't support 64-bit integers */
#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;
@@ -65,7 +75,6 @@ typedef unsigned long long int UInt64;
#ifdef _LZMA_NO_SYSTEM_SIZE_T
typedef UInt32 SizeT;
#else
#include <stddef.h>
typedef size_t SizeT;
#endif
@@ -104,13 +113,82 @@ typedef struct
(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 */
(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);

View File

@@ -9,34 +9,6 @@
namespace NArchive {
namespace NCab {
/*
static HRESULT ReadBytes(IInStream *inStream, void *data, UInt32 size)
{
UInt32 realProcessedSize;
RINOK(ReadStream(inStream, data, size, &realProcessedSize));
if(realProcessedSize != size)
return S_FALSE;
return S_OK;
}
static HRESULT SafeRead(IInStream *inStream, void *data, UInt32 size)
{
UInt32 realProcessedSize;
RINOK(ReadStream(inStream, data, size, &realProcessedSize));
if(realProcessedSize != size)
throw CInArchiveException(CInArchiveException::kUnexpectedEndOfArchive);
return S_OK;
}
static void SafeInByteRead(::CInBuffer &inBuffer, void *data, UInt32 size)
{
UInt32 realProcessedSize;
inBuffer.ReadBytes(data, size, realProcessedSize);
if(realProcessedSize != size)
throw CInArchiveException(CInArchiveException::kUnexpectedEndOfArchive);
}
*/
Byte CInArchive::ReadByte()
{
Byte b;
@@ -107,43 +79,43 @@ HRESULT CInArchive::Open2(IInStream *stream,
inBuffer.SetStream(stream);
inBuffer.Init();
CInArchiveInfo &archiveInfo = database.ArchiveInfo;
CInArchiveInfo &ai = database.ArchiveInfo;
archiveInfo.Size = ReadUInt32(); // size of this cabinet file in bytes
ai.Size = ReadUInt32();
if (ReadUInt32() != 0)
return S_FALSE;
archiveInfo.FileHeadersOffset = ReadUInt32(); // offset of the first CFFILE entry
ai.FileHeadersOffset = ReadUInt32();
if (ReadUInt32() != 0)
return S_FALSE;
archiveInfo.VersionMinor = ReadByte(); // cabinet file format version, minor
archiveInfo.VersionMajor = ReadByte(); // cabinet file format version, major
archiveInfo.NumFolders = ReadUInt16(); // number of CFFOLDER entries in this cabinet
archiveInfo.NumFiles = ReadUInt16(); // number of CFFILE entries in this cabinet
archiveInfo.Flags = ReadUInt16();
if (archiveInfo.Flags > 7)
ai.VersionMinor = ReadByte();
ai.VersionMajor = ReadByte();
ai.NumFolders = ReadUInt16();
ai.NumFiles = ReadUInt16();
ai.Flags = ReadUInt16();
if (ai.Flags > 7)
return S_FALSE;
archiveInfo.SetID = ReadUInt16(); // must be the same for all cabinets in a set
archiveInfo.CabinetNumber = ReadUInt16(); // number of this cabinet file in a set
ai.SetID = ReadUInt16();
ai.CabinetNumber = ReadUInt16();
if (archiveInfo.ReserveBlockPresent())
if (ai.ReserveBlockPresent())
{
archiveInfo.PerCabinetAreaSize = ReadUInt16(); // (optional) size of per-cabinet reserved area
archiveInfo.PerFolderAreaSize = ReadByte(); // (optional) size of per-folder reserved area
archiveInfo.PerDataBlockAreaSize = ReadByte(); // (optional) size of per-datablock reserved area
ai.PerCabinetAreaSize = ReadUInt16();
ai.PerFolderAreaSize = ReadByte();
ai.PerDataBlockAreaSize = ReadByte();
Skeep(archiveInfo.PerCabinetAreaSize);
Skeep(ai.PerCabinetAreaSize);
}
{
if (archiveInfo.IsTherePrev())
ReadOtherArchive(archiveInfo.PreviousArchive);
if (archiveInfo.IsThereNext())
ReadOtherArchive(archiveInfo.NextArchive);
if (ai.IsTherePrev())
ReadOtherArchive(ai.PreviousArchive);
if (ai.IsThereNext())
ReadOtherArchive(ai.NextArchive);
}
int i;
for(i = 0; i < archiveInfo.NumFolders; i++)
for (i = 0; i < ai.NumFolders; i++)
{
CFolder folder;
@@ -152,15 +124,15 @@ HRESULT CInArchive::Open2(IInStream *stream,
folder.CompressionTypeMajor = ReadByte();
folder.CompressionTypeMinor = ReadByte();
Skeep(archiveInfo.PerFolderAreaSize);
Skeep(ai.PerFolderAreaSize);
database.Folders.Add(folder);
}
RINOK(stream->Seek(database.StartPosition + archiveInfo.FileHeadersOffset, STREAM_SEEK_SET, NULL));
RINOK(stream->Seek(database.StartPosition + ai.FileHeadersOffset, STREAM_SEEK_SET, NULL));
inBuffer.SetStream(stream);
inBuffer.Init();
for(i = 0; i < archiveInfo.NumFiles; i++)
for (i = 0; i < ai.NumFiles; i++)
{
CItem item;
item.Size = ReadUInt32();
@@ -224,16 +196,10 @@ bool CMvDatabaseEx::AreItemsEqual(int i1, int i2)
const CDatabaseEx &db2 = Volumes[p2->VolumeIndex];
const CItem &item1 = db1.Items[p1->ItemIndex];
const CItem &item2 = db2.Items[p2->ItemIndex];;
int f1 = GetFolderIndex(p1);
int f2 = GetFolderIndex(p2);
if (f1 != f2)
return false;
if (item1.Offset != item2.Offset)
return false;
if (item1.Size != item2.Size)
return false;
return true;
return GetFolderIndex(p1) == GetFolderIndex(p2) &&
item1.Offset == item2.Offset &&
item1.Size == item2.Size &&
item1.Name == item2.Name;
}
void CMvDatabaseEx::FillSortAndShrink()
@@ -296,7 +262,7 @@ bool CMvDatabaseEx::Check()
}
UInt64 maxPos = 0;
int prevFolder = -2;
for(int i = 0; i < Items.Size(); i++)
for (int i = 0; i < Items.Size(); i++)
{
const CMvItem &mvItem = Items[i];
int fIndex = GetFolderIndex(&mvItem);

View File

@@ -31,13 +31,13 @@ struct COtherArchive
struct CArchiveInfo
{
Byte VersionMinor; /* cabinet file format version, minor */
Byte VersionMajor; /* cabinet file format version, major */
UInt16 NumFolders; /* number of CFFOLDER entries in this cabinet */
UInt16 NumFiles; /* number of CFFILE entries in this cabinet */
UInt16 Flags; /* cabinet file option indicators */
UInt16 SetID; /* must be the same for all cabinets in a set */
UInt16 CabinetNumber; /* number of this cabinet file in a set */
Byte VersionMinor; /* cabinet file format version, minor */
Byte VersionMajor; /* cabinet file format version, major */
UInt16 NumFolders; /* number of CFFOLDER entries in this cabinet */
UInt16 NumFiles; /* number of CFFILE entries in this cabinet */
UInt16 Flags; /* cabinet file option indicators */
UInt16 SetID; /* must be the same for all cabinets in a set */
UInt16 CabinetNumber; /* number of this cabinet file in a set */
bool ReserveBlockPresent() const { return (Flags & NHeader::NArchive::NFlags::kReservePresent) != 0; }

View File

@@ -346,10 +346,8 @@ HRESULT CInArchive::Open2()
Clear();
RINOK(_stream->Seek(kStartPos, STREAM_SEEK_CUR, &_position));
bool primVolDescDefined = false;
m_BufferPos = 0;
BlockSize = kBlockSize;
VolDescs.Add(CVolumeDescriptor());
for (;;)
{
Byte sig[7];
@@ -396,42 +394,33 @@ HRESULT CInArchive::Open2()
break;
}
case NVolDescType::kPrimaryVol:
{
if (primVolDescDefined)
return S_FALSE;
primVolDescDefined = true;
CVolumeDescriptor &volDesc = VolDescs[0];
ReadVolumeDescriptor(volDesc);
// some burners write "Joliet" Escape Sequence to primary volume
memset(volDesc.EscapeSequence, 0, sizeof(volDesc.EscapeSequence));
break;
}
case NVolDescType::kSupplementaryVol:
{
CVolumeDescriptor sd;
ReadVolumeDescriptor(sd);
VolDescs.Add(sd);
// some ISOs have two PrimaryVols.
CVolumeDescriptor vd;
ReadVolumeDescriptor(vd);
if (sig[0] == NVolDescType::kPrimaryVol)
{
// some burners write "Joliet" Escape Sequence to primary volume
memset(vd.EscapeSequence, 0, sizeof(vd.EscapeSequence));
}
VolDescs.Add(vd);
break;
}
default:
break;
}
}
MainVolDescIndex = 0;
if (!primVolDescDefined)
if (VolDescs.IsEmpty())
return S_FALSE;
for (int i = VolDescs.Size() - 1; i >= 0; i--)
{
if (VolDescs[i].IsJoliet())
{
MainVolDescIndex = i;
for (MainVolDescIndex = VolDescs.Size() - 1; MainVolDescIndex > 0; MainVolDescIndex--)
if (VolDescs[MainVolDescIndex].IsJoliet())
break;
}
}
// MainVolDescIndex = 0; // to read primary volume
if (VolDescs[MainVolDescIndex].LogicalBlockSize != kBlockSize)
const CVolumeDescriptor &vd = VolDescs[MainVolDescIndex];
if (vd.LogicalBlockSize != kBlockSize)
return S_FALSE;
(CDirRecord &)_rootDir = VolDescs[MainVolDescIndex].RootDirRecord;
(CDirRecord &)_rootDir = vd.RootDirRecord;
ReadDir(_rootDir, 0);
CreateRefs(_rootDir);
ReadBootInfo();

View File

@@ -264,6 +264,9 @@ struct CSection
void Parse(const Byte *p);
};
static bool operator <(const CSection &a1, const CSection &a2) { return (a1.Pa < a2.Pa); }
static bool operator ==(const CSection &a1, const CSection &a2) { return (a1.Pa == a2.Pa); }
static AString GetName(const Byte *name)
{
const int kNameSize = 8;
@@ -726,6 +729,34 @@ HRESULT CHandler::Open2(IInStream *stream)
if (fileSize > _totalSize)
return S_FALSE;
_totalSizeLimited = (_totalSize < fileSize) ? _totalSize : (UInt32)fileSize;
{
CObjectVector<CSection> sections = _sections;
sections.Sort();
UInt32 limit = (1 << 12);
int num = 0;
for (int i = 0; i < sections.Size(); i++)
{
const CSection &s = sections[i];
if (s.Pa > limit)
{
CSection s2;
s2.Pa = s2.Va = limit;
s2.PSize = s2.VSize = s.Pa - limit;
char sz[32];
ConvertUInt64ToString(++num, sz);
s2.Name = "[data-";
s2.Name += sz;
s2.Name += "]";
_sections.Add(s2);
}
UInt32 next = s.Pa + s.PSize;
if (next < limit)
break;
limit = next;
}
}
return S_OK;
}

View File

@@ -9,9 +9,13 @@ extern "C"
#include "Windows/PropVariant.h"
#include "Windows/Defs.h"
#include "../../MyVersion.h"
#include "../../ICoder.h"
#include "../../IPassword.h"
#include "../../Common/CreateCoder.h"
#include "../../Common/StreamObjects.h"
#include "../../Common/StreamUtils.h"
#include "../../Compress/LZMA/LZMAEncoder.h"
#include "../Common/InStreamWithCRC.h"
#include "ZipAddCommon.h"
@@ -23,11 +27,59 @@ namespace NZip {
static const CMethodId kMethodId_ZipBase = 0x040100;
static const CMethodId kMethodId_BZip2 = 0x040202;
static const UInt32 kLzmaPropsSize = 5;
static const UInt32 kLzmaHeaderSize = 4 + kLzmaPropsSize;
class CLzmaEncoder:
public ICompressCoder,
public CMyUnknownImp
{
NCompress::NLZMA::CEncoder *EncoderSpec;
CMyComPtr<ICompressCoder> Encoder;
Byte Header[kLzmaHeaderSize];
public:
STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
HRESULT CLzmaEncoder::SetCoderProperties(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps);
MY_UNKNOWN_IMP
};
HRESULT CLzmaEncoder::SetCoderProperties(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps)
{
if (!Encoder)
{
EncoderSpec = new NCompress::NLZMA::CEncoder;
Encoder = EncoderSpec;
}
CSequentialOutStreamImp *outStreamSpec = new CSequentialOutStreamImp;
CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);
outStreamSpec->Init();
RINOK(EncoderSpec->SetCoderProperties(propIDs, props, numProps));
RINOK(EncoderSpec->WriteCoderProperties(outStream));
if (outStreamSpec->GetSize() != kLzmaPropsSize)
return E_FAIL;
Header[0] = MY_VER_MAJOR;
Header[1] = MY_VER_MINOR;
Header[2] = kLzmaPropsSize;
Header[3] = 0;
memcpy(Header + 4, outStreamSpec->GetBuffer(), kLzmaPropsSize);
return S_OK;
}
HRESULT CLzmaEncoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress)
{
RINOK(WriteStream(outStream, Header, kLzmaHeaderSize));
return Encoder->Code(inStream, outStream, inSize, outSize, progress);
}
CAddCommon::CAddCommon(const CCompressionMethodMode &options):
_options(options),
_copyCoderSpec(NULL),
_cryptoStreamSpec(0)
{}
{}
static HRESULT GetStreamCRC(ISequentialInStream *inStream, UInt32 &resultCRC)
{
@@ -38,7 +90,7 @@ static HRESULT GetStreamCRC(ISequentialInStream *inStream, UInt32 &resultCRC)
{
UInt32 realProcessedSize;
RINOK(inStream->Read(buffer, kBufferSize, &realProcessedSize));
if(realProcessedSize == 0)
if (realProcessedSize == 0)
{
resultCRC = CRC_GET_DIGEST(crc);
return S_OK;
@@ -87,7 +139,7 @@ HRESULT CAddCommon::Compress(
}
Byte method = 0;
COutStreamReleaser outStreamReleaser;
for(int i = 0; i < numTestMethods; i++)
for (int i = 0; i < numTestMethods; i++)
{
if (inCrcStreamSpec != 0)
RINOK(inCrcStreamSpec->Seek(0, STREAM_SEEK_SET, NULL));
@@ -127,7 +179,7 @@ HRESULT CAddCommon::Compress(
{
case NFileHeader::NCompressionMethod::kStored:
{
if(_copyCoderSpec == NULL)
if (_copyCoderSpec == NULL)
{
_copyCoderSpec = new NCompress::CCopyCoder;
_copyCoder = _copyCoderSpec;
@@ -143,8 +195,41 @@ HRESULT CAddCommon::Compress(
}
default:
{
if(!_compressEncoder)
if (!_compressEncoder)
{
if (method == NFileHeader::NCompressionMethod::kLZMA)
{
CLzmaEncoder *_lzmaEncoder = new CLzmaEncoder();
_compressEncoder = _lzmaEncoder;
NWindows::NCOM::CPropVariant props[] =
{
#ifdef COMPRESS_MT
_options.NumThreads,
#endif
_options.Algo,
_options.DicSize,
_options.NumFastBytes,
(BSTR)(const wchar_t *)_options.MatchFinder,
_options.NumMatchFinderCycles
};
PROPID propIDs[] =
{
#ifdef COMPRESS_MT
NCoderPropID::kNumThreads,
#endif
NCoderPropID::kAlgorithm,
NCoderPropID::kDictionarySize,
NCoderPropID::kNumFastBytes,
NCoderPropID::kMatchFinder,
NCoderPropID::kMatchFinderCycles
};
int numProps = sizeof(propIDs) / sizeof(propIDs[0]);
if (!_options.NumMatchFinderCyclesDefined)
numProps--;
RINOK(_lzmaEncoder->SetCoderProperties(propIDs, props, numProps));
}
else
{
CMethodId methodId;
switch(method)
{
@@ -164,7 +249,7 @@ HRESULT CAddCommon::Compress(
if (method == NFileHeader::NCompressionMethod::kDeflated ||
method == NFileHeader::NCompressionMethod::kDeflated64)
{
NWindows::NCOM::CPropVariant properties[] =
NWindows::NCOM::CPropVariant props[] =
{
_options.Algo,
_options.NumPasses,
@@ -185,12 +270,12 @@ HRESULT CAddCommon::Compress(
_compressEncoder.QueryInterface(IID_ICompressSetCoderProperties, &setCoderProperties);
if (setCoderProperties)
{
RINOK(setCoderProperties->SetCoderProperties(propIDs, properties, numProps));
RINOK(setCoderProperties->SetCoderProperties(propIDs, props, numProps));
}
}
else if (method == NFileHeader::NCompressionMethod::kBZip2)
{
NWindows::NCOM::CPropVariant properties[] =
NWindows::NCOM::CPropVariant props[] =
{
_options.DicSize,
_options.NumPasses
@@ -210,9 +295,10 @@ HRESULT CAddCommon::Compress(
_compressEncoder.QueryInterface(IID_ICompressSetCoderProperties, &setCoderProperties);
if (setCoderProperties)
{
RINOK(setCoderProperties->SetCoderProperties(propIDs, properties, sizeof(propIDs) / sizeof(propIDs[0])));
RINOK(setCoderProperties->SetCoderProperties(propIDs, props, sizeof(propIDs) / sizeof(propIDs[0])));
}
}
}
}
CMyComPtr<ISequentialOutStream> outStreamNew;
if (_options.PasswordIsDefined)

View File

@@ -11,7 +11,7 @@ namespace NZip {
struct CCompressionMethodMode
{
CRecordVector<Byte> MethodSequence;
// bool MaximizeRatio;
UString MatchFinder;
UInt32 Algo;
UInt32 NumPasses;
UInt32 NumFastBytes;

View File

@@ -16,10 +16,12 @@
#include "../../Common/ProgressUtils.h"
#include "../../Common/StreamObjects.h"
#include "../../Common/StreamUtils.h"
#include "../../Common/CreateCoder.h"
#include "../../Common/FilterCoder.h"
#include "../../Compress/Copy/CopyCoder.h"
#include "../../Compress/LZMA/LZMADecoder.h"
#include "../Common/ItemNameUtils.h"
#include "../Common/OutStreamWithCRC.h"
@@ -108,13 +110,13 @@ const wchar_t *kMethods[] =
L"Tokenizing",
L"Deflate",
L"Deflate64",
L"PKImploding",
L"Unknown",
L"BZip2"
L"PKImploding"
};
const int kNumMethods = sizeof(kMethods) / sizeof(kMethods[0]);
// const wchar_t *kUnknownMethod = L"Unknown";
const wchar_t *kBZip2Method = L"BZip2";
const wchar_t *kLZMAMethod = L"LZMA";
const wchar_t *kJpegMethod = L"Jpeg";
const wchar_t *kWavPackMethod = L"WavPack";
const wchar_t *kPPMdMethod = L"PPMd";
const wchar_t *kAESMethod = L"AES";
@@ -294,15 +296,23 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
}
if (methodId < kNumMethods)
method += kMethods[methodId];
else if (methodId == NFileHeader::NCompressionMethod::kPPMd)
method += kPPMdMethod;
else if (methodId == NFileHeader::NCompressionMethod::kWavPack)
method += kWavPackMethod;
else
else switch (methodId)
{
wchar_t s[32];
ConvertUInt64ToString(methodId, s);
method += s;
case NFileHeader::NCompressionMethod::kLZMA:
method += kLZMAMethod;
if (item.IsLzmaEOS())
method += L":EOS";
break;
case NFileHeader::NCompressionMethod::kBZip2: method += kBZip2Method; break;
case NFileHeader::NCompressionMethod::kJpeg: method += kJpegMethod; break;
case NFileHeader::NCompressionMethod::kWavPack: method += kWavPackMethod; break;
case NFileHeader::NCompressionMethod::kPPMd: method += kPPMdMethod; break;
default:
{
wchar_t s[32];
ConvertUInt64ToString(methodId, s);
method += s;
}
}
prop = method;
break;
@@ -367,6 +377,37 @@ STDMETHODIMP CHandler::Close()
//////////////////////////////////////
// CHandler::DecompressItems
class CLzmaDecoder:
public ICompressCoder,
public CMyUnknownImp
{
NCompress::NLZMA::CDecoder *DecoderSpec;
CMyComPtr<ICompressCoder> Decoder;
public:
CLzmaDecoder();
STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
MY_UNKNOWN_IMP
};
CLzmaDecoder::CLzmaDecoder()
{
DecoderSpec = new NCompress::NLZMA::CDecoder;
Decoder = DecoderSpec;
}
HRESULT CLzmaDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
const UInt64 * /* inSize */, const UInt64 *outSize, ICompressProgressInfo *progress)
{
Byte buf[9];
RINOK(ReadStream_FALSE(inStream, buf, 9));
if (buf[2] != 5 || buf[3] != 0)
return E_NOTIMPL;
RINOK(DecoderSpec->SetDecoderProperties2(buf + 4, 5));
return Decoder->Code(inStream, outStream, NULL, outSize, progress);
}
struct CMethodItem
{
UInt16 ZipMethod;
@@ -568,6 +609,8 @@ HRESULT CZipDecoder::Decode(
mi.Coder = new NCompress::NShrink::CDecoder;
else if (methodId == NFileHeader::NCompressionMethod::kImploded)
mi.Coder = new NCompress::NImplode::NDecoder::CCoder;
else if (methodId == NFileHeader::NCompressionMethod::kLZMA)
mi.Coder = new CLzmaDecoder;
else
{
CMethodId szMethodID;
@@ -656,6 +699,12 @@ HRESULT CZipDecoder::Decode(
result = coder->Code(inStreamNew, outStream, NULL, &item.UnPackSize, compressProgress);
if (result == S_FALSE)
return S_OK;
if (result == E_NOTIMPL)
{
res = NArchive::NExtract::NOperationResult::kUnSupportedMethod;
return S_OK;
}
RINOK(result);
}
bool crcOK = true;

View File

@@ -25,16 +25,28 @@ using namespace NTime;
namespace NArchive {
namespace NZip {
static const UInt32 kDeflateAlgoX1 = 0;
static const UInt32 kDeflateAlgoX5 = 1;
static const UInt32 kLzAlgoX1 = 0;
static const UInt32 kLzAlgoX5 = 1;
static const UInt32 kDeflateNumPassesX1 = 1;
static const UInt32 kDeflateNumPassesX7 = 3;
static const UInt32 kDeflateNumPassesX9 = 10;
static const UInt32 kNumFastBytesX1 = 32;
static const UInt32 kNumFastBytesX7 = 64;
static const UInt32 kNumFastBytesX9 = 128;
static const UInt32 kDeflateNumFastBytesX1 = 32;
static const UInt32 kDeflateNumFastBytesX7 = 64;
static const UInt32 kDeflateNumFastBytesX9 = 128;
static const wchar_t *kLzmaMatchFinderX1 = L"HC4";
static const wchar_t *kLzmaMatchFinderX5 = L"BT4";
static const UInt32 kLzmaNumFastBytesX1 = 32;
static const UInt32 kLzmaNumFastBytesX7 = 64;
static const UInt32 kLzmaDicSizeX1 = 1 << 16;
static const UInt32 kLzmaDicSizeX3 = 1 << 20;
static const UInt32 kLzmaDicSizeX5 = 1 << 24;
static const UInt32 kLzmaDicSizeX7 = 1 << 25;
static const UInt32 kLzmaDicSizeX9 = 1 << 26;
static const UInt32 kBZip2NumPassesX1 = 1;
static const UInt32 kBZip2NumPassesX7 = 2;
@@ -173,24 +185,20 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
{
bool defaultCharWasUsed;
ui.Name = UnicodeStringToMultiByte(name, CP_OEMCP, '_', defaultCharWasUsed);
tryUtf8 = (!m_ForseLocal && defaultCharWasUsed);
tryUtf8 = (!m_ForseLocal && (defaultCharWasUsed ||
MultiByteToUnicodeString(ui.Name, CP_OEMCP) != name));
}
if (tryUtf8)
{
bool needUtf = false;
for (int i = 0; i < name.Length(); i++)
if ((unsigned)name[i] >= 0x80)
{
needUtf = true;
break;
}
ui.IsUtf8 = needUtf;
int i;
for (i = 0; i < name.Length() && (unsigned)name[i] < 0x80; i++);
ui.IsUtf8 = (i != name.Length());
if (!ConvertUnicodeToUTF8(name, ui.Name))
return E_INVALIDARG;
}
if (ui.Name.Length() > 0xFFFF)
if (ui.Name.Length() >= (1 << 16))
return E_INVALIDARG;
ui.IndexInClient = i;
@@ -272,6 +280,8 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
options.MethodSequence.Add(NFileHeader::NCompressionMethod::kStored);
bool isDeflate = (mainMethod == NFileHeader::NCompressionMethod::kDeflated) ||
(mainMethod == NFileHeader::NCompressionMethod::kDeflated64);
bool isLZMA = (mainMethod == NFileHeader::NCompressionMethod::kLZMA);
bool isLz = (isLZMA || isDeflate);
bool isBZip2 = (mainMethod == NFileHeader::NCompressionMethod::kBZip2);
options.NumPasses = m_NumPasses;
options.DicSize = m_DicSize;
@@ -282,20 +292,41 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
#ifdef COMPRESS_MT
options.NumThreads = _numThreads;
#endif
if (isDeflate)
if (isLz)
{
if (options.NumPasses == 0xFFFFFFFF)
options.NumPasses = (level >= 9 ? kDeflateNumPassesX9 :
(level >= 7 ? kDeflateNumPassesX7 :
kDeflateNumPassesX1));
if (options.NumFastBytes == 0xFFFFFFFF)
options.NumFastBytes = (level >= 9 ? kNumFastBytesX9 :
(level >= 7 ? kNumFastBytesX7 :
kNumFastBytesX1));
if (isDeflate)
{
if (options.NumPasses == 0xFFFFFFFF)
options.NumPasses = (level >= 9 ? kDeflateNumPassesX9 :
(level >= 7 ? kDeflateNumPassesX7 :
kDeflateNumPassesX1));
if (options.NumFastBytes == 0xFFFFFFFF)
options.NumFastBytes = (level >= 9 ? kDeflateNumFastBytesX9 :
(level >= 7 ? kDeflateNumFastBytesX7 :
kDeflateNumFastBytesX1));
}
else if (isLZMA)
{
if (options.DicSize == 0xFFFFFFFF)
options.DicSize =
(level >= 9 ? kLzmaDicSizeX9 :
(level >= 7 ? kLzmaDicSizeX7 :
(level >= 5 ? kLzmaDicSizeX5 :
(level >= 3 ? kLzmaDicSizeX3 :
kLzmaDicSizeX1))));
if (options.NumFastBytes == 0xFFFFFFFF)
options.NumFastBytes = (level >= 7 ? kLzmaNumFastBytesX7 :
kLzmaNumFastBytesX1);
options.MatchFinder =
(level >= 5 ? kLzmaMatchFinderX5 :
kLzmaMatchFinderX1);
}
if (options.Algo == 0xFFFFFFFF)
options.Algo =
(level >= 5 ? kDeflateAlgoX5 :
kDeflateAlgoX1);
options.Algo = (level >= 5 ? kLzAlgoX5 :
kLzAlgoX1);
}
if (isBZip2)
{
@@ -343,18 +374,14 @@ STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *v
{
if (prop.vt == VT_BSTR)
{
UString valueString = prop.bstrVal;
valueString.MakeUpper();
if (valueString == L"COPY")
m_MainMethod = NFileHeader::NCompressionMethod::kStored;
else if (valueString == L"DEFLATE")
m_MainMethod = NFileHeader::NCompressionMethod::kDeflated;
else if (valueString == L"DEFLATE64")
m_MainMethod = NFileHeader::NCompressionMethod::kDeflated64;
else if (valueString == L"BZIP2")
m_MainMethod = NFileHeader::NCompressionMethod::kBZip2;
else
return E_INVALIDARG;
UString m = prop.bstrVal;
m.MakeUpper();
if (m == L"COPY") m_MainMethod = NFileHeader::NCompressionMethod::kStored;
else if (m == L"DEFLATE") m_MainMethod = NFileHeader::NCompressionMethod::kDeflated;
else if (m == L"DEFLATE64") m_MainMethod = NFileHeader::NCompressionMethod::kDeflated64;
else if (m == L"BZIP2") m_MainMethod = NFileHeader::NCompressionMethod::kBZip2;
else if (m == L"LZMA") m_MainMethod = NFileHeader::NCompressionMethod::kLZMA;
else return E_INVALIDARG;
}
else if (prop.vt == VT_UI4)
{
@@ -364,6 +391,7 @@ STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *v
case NFileHeader::NCompressionMethod::kDeflated:
case NFileHeader::NCompressionMethod::kDeflated64:
case NFileHeader::NCompressionMethod::kBZip2:
case NFileHeader::NCompressionMethod::kLZMA:
m_MainMethod = (Byte)prop.ulVal;
break;
default:
@@ -414,7 +442,7 @@ STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *v
}
else if (name.Left(2) == L"FB")
{
UInt32 num = kNumFastBytesX9;
UInt32 num = kDeflateNumFastBytesX9;
RINOK(ParsePropValue(name.Mid(2), prop, num));
m_NumFastBytes = num;
}
@@ -433,25 +461,25 @@ STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *v
}
else if (name.Left(1) == L"A")
{
UInt32 num = kDeflateAlgoX5;
UInt32 num = kLzAlgoX5;
RINOK(ParsePropValue(name.Mid(1), prop, num));
m_Algo = num;
}
else if (name.CompareNoCase(L"TC") == 0)
return SetBoolProperty(m_WriteNtfsTimeExtra, prop);
{
RINOK(SetBoolProperty(m_WriteNtfsTimeExtra, prop));
}
else if (name.CompareNoCase(L"CL") == 0)
{
RINOK(SetBoolProperty(m_ForseLocal, prop));
if (m_ForseLocal)
m_ForseUtf8 = false;
return S_OK;
}
else if (name.CompareNoCase(L"CU") == 0)
{
RINOK(SetBoolProperty(m_ForseUtf8, prop));
if (m_ForseUtf8)
m_ForseLocal = false;
return S_OK;
}
else
return E_INVALIDARG;

View File

@@ -69,6 +69,10 @@ namespace NFileHeader
kPKImploding = 10,
kBZip2 = 12,
kLZMA = 14,
kTerse = 18,
kLz77 = 19,
kJpeg = 0x60,
kWavPack = 0x61,
kPPMd = 0x62,
kWzAES = 0x63
@@ -170,6 +174,7 @@ namespace NFileHeader
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;

View File

@@ -51,20 +51,6 @@ bool CExtraSubBlock::ExtractNtfsTime(int index, FILETIME &ft) const
return false;
}
bool CLocalItem::IsImplodeBigDictionary() const
{
if (CompressionMethod != NFileHeader::NCompressionMethod::kImploded)
throw 12312212;
return (Flags & NFileHeader::NFlags::kImplodeDictionarySizeMask) != 0;
}
bool CLocalItem::IsImplodeLiteralsOn() const
{
if (CompressionMethod != NFileHeader::NCompressionMethod::kImploded)
throw 12312213;
return (Flags & NFileHeader::NFlags::kImplodeLiteralsOnMask) != 0;
}
bool CLocalItem::IsDir() const
{
return NItemName::HasTailSlash(Name, GetCodePage());

View File

@@ -188,8 +188,7 @@ public:
bool IsEncrypted() const { return (Flags & NFileHeader::NFlags::kEncrypted) != 0; }
bool IsStrongEncrypted() const { return IsEncrypted() && (Flags & NFileHeader::NFlags::kStrongEncrypted) != 0; };
bool IsImplodeBigDictionary() const;
bool IsImplodeLiteralsOn() const;
bool IsLzmaEOS() const { return (Flags & NFileHeader::NFlags::kLzmaEOS) != 0; }
bool IsDir() const;
bool IgnoreItem() const { return false; }

View File

@@ -1,4 +1,4 @@
// ZipUpdate.cpp
lzma// ZipUpdate.cpp
#include "StdAfx.h"
@@ -568,6 +568,14 @@ static HRESULT Update2(
if (numThreads <= 1)
mtMode = false;
}
if (method == NFileHeader::NCompressionMethod::kLZMA)
{
UInt32 numLZMAThreads = (options->Algo > 0 ? 2 : 1);
numThreads /= numLZMAThreads;
options2.NumThreads = numLZMAThreads;
if (numThreads <= 1)
mtMode = false;
}
}
if (!mtMode)

View File

@@ -5,27 +5,30 @@
#include "Common/MyInitGuid.h"
#include "Common/CommandLineParser.h"
#include "Common/StdOutStream.h"
#include "Common/Wildcard.h"
#include "Common/StringConvert.h"
#include "Common/MyCom.h"
#include "Common/MyException.h"
#include "Common/StdOutStream.h"
#include "Common/StringConvert.h"
#include "Common/Wildcard.h"
#include "Windows/FileDir.h"
#include "Windows/FileName.h"
#include "Windows/Defs.h"
#include "Windows/FileName.h"
#ifdef _WIN32
#include "Windows/DLL.h"
#include "Windows/FileDir.h"
#endif
#include "../../IPassword.h"
#include "../../ICoder.h"
#include "../../UI/Common/OpenArchive.h"
#include "../../UI/Common/DefaultName.h"
#include "../../UI/Common/ExitCode.h"
#include "../../UI/Common/Extract.h"
#include "../../UI/Common/OpenArchive.h"
#include "../../UI/Console/ExtractCallbackConsole.h"
#include "../../UI/Console/List.h"
#include "../../UI/Console/OpenCallbackConsole.h"
#include "../../UI/Console/ExtractCallbackConsole.h"
#include "../../MyVersion.h"
@@ -40,11 +43,6 @@ static const char *kCopyrightString =
static const int kNumSwitches = 6;
#ifdef _WIN32
static const wchar_t *kDefaultExt = L".exe";
static const int kDefaultExtLength = 4;
#endif
namespace NKey {
enum Enum
{
@@ -271,7 +269,25 @@ int Main2(
GetArguments(numArguments, arguments, commandStrings);
#endif
UString archiveName = commandStrings.Front();
#ifdef _WIN32
UString arcPath;
{
UString path;
NDLL::MyGetModuleFileName(NULL, path);
int fileNamePartStartIndex;
if (!NDirectory::MyGetFullPathName(path, arcPath, fileNamePartStartIndex))
{
g_StdOut << "GetFullPathName Error";
return NExitCode::kFatalError;
}
}
#else
UString arcPath = commandStrings.Front();
#endif
commandStrings.Delete(0);
@@ -318,11 +334,6 @@ int Main2(
bool yesToAll = parser[NKey::kYes].ThereIs;
#ifdef _WIN32
if (archiveName.Right(kDefaultExtLength).CompareNoCase(kDefaultExt) != 0)
archiveName += kDefaultExt;
#endif
// NExtractMode::EEnum extractMode;
// bool isExtractGroupCommand = command.IsFromExtractGroup(extractMode);
@@ -333,13 +344,13 @@ int Main2(
password = parser[NKey::kPassword].PostStrings[0];
NFind::CFileInfoW archiveFileInfo;
if (!NFind::FindFile(archiveName, archiveFileInfo))
if (!NFind::FindFile(arcPath, archiveFileInfo))
throw kCantFindSFX;
if (archiveFileInfo.IsDir())
throw kCantFindSFX;
UString outputDir;
if(parser[NKey::kOutputDir].ThereIs)
if (parser[NKey::kOutputDir].ThereIs)
{
outputDir = parser[NKey::kOutputDir].PostStrings[0];
NName::NormalizeDirPathPrefix(outputDir);
@@ -347,8 +358,8 @@ int Main2(
{
UStringVector v1, v2;
v1.Add(archiveName);
v2.Add(archiveName);
v1.Add(arcPath);
v2.Add(arcPath);
const NWildcard::CCensorNode &wildcardCensorHead =
wildcardCensor.Pairs.Front().Head;

View File

@@ -381,6 +381,14 @@ SOURCE=..\..\Crypto\Hash\RotateDefs.h
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\..\..\Windows\DLL.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\DLL.h
# End Source File
# Begin Source File
SOURCE=..\..\..\Windows\Error.cpp
# End Source File
# Begin Source File

View File

@@ -29,6 +29,7 @@ COMMON_OBJS = \
$O\Wildcard.obj \
WIN_OBJS = \
$O\DLL.obj \
$O\Error.obj \
$O\FileDir.obj \
$O\FileFind.obj \

View File

@@ -106,8 +106,6 @@ STDMETHODIMP CExtractCallbackImp::GetStream(UInt32 index,
}
_filePath = fullPath;
// m_CurrentFilePath = GetSystemString(fullPath, _codePage);
if (askExtractMode == NArchive::NExtract::NAskMode::kExtract)
{
NCOM::CPropVariant prop;
@@ -135,14 +133,9 @@ STDMETHODIMP CExtractCallbackImp::GetStream(UInt32 index,
RINOK(_archiveHandler->GetProperty(index, kpidMTime, &prop));
switch(prop.vt)
{
case VT_EMPTY:
_processedFileInfo.MTime = _defaultMTime;
break;
case VT_FILETIME:
_processedFileInfo.MTime = prop.filetime;
break;
default:
return E_FAIL;
case VT_EMPTY: _processedFileInfo.MTime = _defaultMTime; break;
case VT_FILETIME: _processedFileInfo.MTime = prop.filetime; break;
default: return E_FAIL;
}
UStringVector pathParts;
@@ -168,6 +161,8 @@ STDMETHODIMP CExtractCallbackImp::GetStream(UInt32 index,
if (isAnti)
NDirectory::MyRemoveDirectory(_diskFilePath);
else
NDirectory::SetDirTime(_diskFilePath, NULL, NULL, &_processedFileInfo.MTime);
return S_OK;
}
@@ -204,13 +199,7 @@ STDMETHODIMP CExtractCallbackImp::GetStream(UInt32 index,
STDMETHODIMP CExtractCallbackImp::PrepareOperation(Int32 askExtractMode)
{
_extractMode = false;
switch (askExtractMode)
{
case NArchive::NExtract::NAskMode::kExtract:
_extractMode = true;
break;
};
_extractMode = (askExtractMode == NArchive::NExtract::NAskMode::kExtract);
return S_OK;
}

View File

@@ -18,6 +18,7 @@ static HRESULT SResToHRESULT(SRes res)
case SZ_OK: return S_OK;
case SZ_ERROR_MEM: return E_OUTOFMEMORY;
case SZ_ERROR_PARAM: return E_INVALIDARG;
case SZ_ERROR_UNSUPPORTED: return E_NOTIMPL;
// case SZ_ERROR_PROGRESS: return E_ABORT;
case SZ_ERROR_DATA: return S_FALSE;
}
@@ -29,7 +30,7 @@ namespace NLZMA {
static const UInt32 kInBufSize = 1 << 20;
CDecoder::CDecoder(): _inBuf(0), _outSizeDefined(false)
CDecoder::CDecoder(): _inBuf(0), _outSizeDefined(false), FinishStream(false)
{
LzmaDec_Construct(&_state);
}
@@ -104,10 +105,8 @@ STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream,
if (rem < curSize)
{
curSize = (SizeT)rem;
/*
// finishMode = LZMA_FINISH_END;
we can't use LZMA_FINISH_END here to allow partial decoding
*/
if (FinishStream)
finishMode = LZMA_FINISH_END;
}
}

View File

@@ -65,6 +65,8 @@ public:
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
#endif
bool FinishStream;
CDecoder();
virtual ~CDecoder();

View File

@@ -179,42 +179,6 @@ SOURCE=..\LZMA\LZMAEncoder.cpp
SOURCE=..\LZMA\LZMAEncoder.h
# End Source File
# End Group
# Begin Group "RangeCoder"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\RangeCoder\RangeCoder.h
# End Source File
# Begin Source File
SOURCE=..\RangeCoder\RangeCoderBit.cpp
# End Source File
# Begin Source File
SOURCE=..\RangeCoder\RangeCoderBit.h
# End Source File
# Begin Source File
SOURCE=..\RangeCoder\RangeCoderBitTree.h
# End Source File
# Begin Source File
SOURCE=..\RangeCoder\RangeCoderOpt.h
# End Source File
# End Group
# Begin Group "LZ"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\LZ\LZOutWindow.cpp
# End Source File
# Begin Source File
SOURCE=..\LZ\LZOutWindow.h
# End Source File
# End Group
# End Group
# Begin Group "Windows"

View File

@@ -31,11 +31,9 @@
#include "../../../Windows/System.h"
#endif
#include "../../MyVersion.h"
extern "C"
{
#include "../../../../C/7zVersion.h"
#include "../../../../C/Alloc.h"
#include "../../../../C/LzmaUtil/Lzma86Dec.h"
#include "../../../../C/LzmaUtil/Lzma86Enc.h"
@@ -64,13 +62,13 @@ enum Enum
{
kHelp1 = 0,
kHelp2,
kMode,
kDictionary,
kFastBytes,
kMatchFinderCycles,
kLitContext,
kLitPos,
kPosBits,
kAlgo,
kDict,
kFb,
kMc,
kLc,
kLp,
kPb,
kMatchFinder,
kMultiThread,
kEOS,
@@ -109,7 +107,7 @@ static void PrintHelp()
" b: Benchmark\n"
"<Switches>\n"
" -a{N}: set compression mode - [0, 1], default: 1 (max)\n"
" -d{N}: set dictionary - [12, 30], default: 23 (8MB)\n"
" -d{N}: set dictionary size - [12, 30], default: 23 (8MB)\n"
" -fb{N}: set number of fast bytes - [5, 273], default: 128\n"
" -mc{N}: set number of cycles for match finder\n"
" -lc{N}: set number of literal context bits - [0, 8], default: 3\n"
@@ -157,6 +155,13 @@ static bool GetNumber(const wchar_t *s, UInt32 &value)
return true;
}
static void ParseUInt32(const CParser &parser, int index, UInt32 &res)
{
if (parser[index].ThereIs)
if (!GetNumber(parser[index].PostStrings[0], res))
IncorrectCommand();
}
int main2(int n, const char *args[])
{
#ifdef _WIN32
@@ -202,15 +207,15 @@ int main2(int n, const char *args[])
IncorrectCommand();
const UString &command = nonSwitchStrings[paramIndex++];
bool dictionaryIsDefined = false;
UInt32 dictionary = (UInt32)-1;
if(parser[NKey::kDictionary].ThereIs)
bool dictDefined = false;
UInt32 dict = (UInt32)-1;
if(parser[NKey::kDict].ThereIs)
{
UInt32 dicLog;
if (!GetNumber(parser[NKey::kDictionary].PostStrings[0], dicLog))
if (!GetNumber(parser[NKey::kDict].PostStrings[0], dicLog))
IncorrectCommand();
dictionary = 1 << dicLog;
dictionaryIsDefined = true;
dict = 1 << dicLog;
dictDefined = true;
}
UString mf = L"BT4";
if (parser[NKey::kMatchFinder].ThereIs)
@@ -240,7 +245,7 @@ int main2(int n, const char *args[])
if (!GetNumber(nonSwitchStrings[paramIndex++], numIterations))
numIterations = kNumDefaultItereations;
}
return LzmaBenchCon(stderr, numIterations, numThreads, dictionary);
return LzmaBenchCon(stderr, numIterations, numThreads, dict);
}
if (numThreads == (UInt32)-1)
@@ -334,10 +339,10 @@ int main2(int n, const char *args[])
if (outBuffer == 0)
throw kCantAllocate;
}
if (!dictionaryIsDefined)
dictionary = 1 << 23;
if (!dictDefined)
dict = 1 << 23;
int res = Lzma86_Encode(outBuffer, &outSize, inBuffer, inSize,
5, dictionary, parser[NKey::kFilter86].PostCharIndex == 0 ? SZ_FILTER_YES : SZ_FILTER_AUTO);
5, dict, parser[NKey::kFilter86].PostCharIndex == 0 ? SZ_FILTER_YES : SZ_FILTER_AUTO);
if (res != 0)
{
fprintf(stderr, "\nEncoder error = %d\n", (int)res);
@@ -378,42 +383,30 @@ int main2(int n, const char *args[])
NCompress::NLZMA::CEncoder *encoderSpec = new NCompress::NLZMA::CEncoder;
CMyComPtr<ICompressCoder> encoder = encoderSpec;
if (!dictionaryIsDefined)
dictionary = 1 << 23;
if (!dictDefined)
dict = 1 << 23;
UInt32 posStateBits = 2;
UInt32 litContextBits = 3; // for normal files
// UInt32 litContextBits = 0; // for 32-bit data
UInt32 litPosBits = 0;
// UInt32 litPosBits = 2; // for 32-bit data
UInt32 algorithm = 1;
UInt32 numFastBytes = 128;
UInt32 matchFinderCycles = 16 + numFastBytes / 2;
bool matchFinderCyclesDefined = false;
UInt32 pb = 2;
UInt32 lc = 3; // = 0; for 32-bit data
UInt32 lp = 0; // = 2; for 32-bit data
UInt32 algo = 1;
UInt32 fb = 128;
UInt32 mc = 16 + fb / 2;
bool mcDefined = false;
bool eos = parser[NKey::kEOS].ThereIs || stdInMode;
if(parser[NKey::kMode].ThereIs)
if (!GetNumber(parser[NKey::kMode].PostStrings[0], algorithm))
IncorrectCommand();
ParseUInt32(parser, NKey::kAlgo, algo);
ParseUInt32(parser, NKey::kFb, fb);
ParseUInt32(parser, NKey::kLc, lc);
ParseUInt32(parser, NKey::kLp, lp);
ParseUInt32(parser, NKey::kPb, pb);
if(parser[NKey::kFastBytes].ThereIs)
if (!GetNumber(parser[NKey::kFastBytes].PostStrings[0], numFastBytes))
mcDefined = parser[NKey::kMc].ThereIs;
if (mcDefined)
if (!GetNumber(parser[NKey::kMc].PostStrings[0], mc))
IncorrectCommand();
matchFinderCyclesDefined = parser[NKey::kMatchFinderCycles].ThereIs;
if (matchFinderCyclesDefined)
if (!GetNumber(parser[NKey::kMatchFinderCycles].PostStrings[0], matchFinderCycles))
IncorrectCommand();
if(parser[NKey::kLitContext].ThereIs)
if (!GetNumber(parser[NKey::kLitContext].PostStrings[0], litContextBits))
IncorrectCommand();
if(parser[NKey::kLitPos].ThereIs)
if (!GetNumber(parser[NKey::kLitPos].PostStrings[0], litPosBits))
IncorrectCommand();
if(parser[NKey::kPosBits].ThereIs)
if (!GetNumber(parser[NKey::kPosBits].PostStrings[0], posStateBits))
IncorrectCommand();
PROPID propIDs[] =
{
NCoderPropID::kDictionarySize,
@@ -429,35 +422,35 @@ int main2(int n, const char *args[])
};
const int kNumPropsMax = sizeof(propIDs) / sizeof(propIDs[0]);
PROPVARIANT properties[kNumPropsMax];
PROPVARIANT props[kNumPropsMax];
for (int p = 0; p < 6; p++)
properties[p].vt = VT_UI4;
props[p].vt = VT_UI4;
properties[0].ulVal = (UInt32)dictionary;
properties[1].ulVal = (UInt32)posStateBits;
properties[2].ulVal = (UInt32)litContextBits;
properties[3].ulVal = (UInt32)litPosBits;
properties[4].ulVal = (UInt32)algorithm;
properties[5].ulVal = (UInt32)numFastBytes;
props[0].ulVal = (UInt32)dict;
props[1].ulVal = (UInt32)pb;
props[2].ulVal = (UInt32)lc;
props[3].ulVal = (UInt32)lp;
props[4].ulVal = (UInt32)algo;
props[5].ulVal = (UInt32)fb;
properties[6].vt = VT_BSTR;
properties[6].bstrVal = (BSTR)(const wchar_t *)mf;
props[6].vt = VT_BSTR;
props[6].bstrVal = (BSTR)(const wchar_t *)mf;
properties[7].vt = VT_BOOL;
properties[7].boolVal = eos ? VARIANT_TRUE : VARIANT_FALSE;
props[7].vt = VT_BOOL;
props[7].boolVal = eos ? VARIANT_TRUE : VARIANT_FALSE;
properties[8].vt = VT_UI4;
properties[8].ulVal = (UInt32)numThreads;
props[8].vt = VT_UI4;
props[8].ulVal = (UInt32)numThreads;
// it must be last in property list
properties[9].vt = VT_UI4;
properties[9].ulVal = (UInt32)matchFinderCycles;
props[9].vt = VT_UI4;
props[9].ulVal = (UInt32)mc;
int numProps = kNumPropsMax;
if (!matchFinderCyclesDefined)
if (!mcDefined)
numProps--;
if (encoderSpec->SetCoderProperties(propIDs, properties, numProps) != S_OK)
if (encoderSpec->SetCoderProperties(propIDs, props, numProps) != S_OK)
IncorrectCommand();
encoderSpec->WriteCoderProperties(outStream);
@@ -491,6 +484,7 @@ int main2(int n, const char *args[])
{
NCompress::NLZMA::CDecoder *decoderSpec = new NCompress::NLZMA::CDecoder;
CMyComPtr<ICompressCoder> decoder = decoderSpec;
decoderSpec->FinishStream = true;
const UInt32 kPropertiesSize = 5;
Byte header[kPropertiesSize + 8];
if (ReadStream_FALSE(inStream, header, kPropertiesSize + 8) != S_OK)

View File

@@ -1,8 +1,8 @@
#define MY_VER_MAJOR 4
#define MY_VER_MINOR 60
#define MY_VER_MINOR 61
#define MY_VER_BUILD 0
#define MY_VERSION " 4.60 beta"
#define MY_7ZIP_VERSION "7-Zip 4.60 beta"
#define MY_DATE "2008-08-19"
#define MY_VERSION "4.61 beta"
#define MY_7ZIP_VERSION "7-Zip 4.61 beta"
#define MY_DATE "2008-11-23"
#define MY_COPYRIGHT "Copyright (c) 1999-2008 Igor Pavlov"
#define MY_VERSION_COPYRIGHT_DATE MY_VERSION " " MY_COPYRIGHT " " MY_DATE

View File

@@ -4,8 +4,6 @@
#include "DefaultName.h"
static const wchar_t *kEmptyFileAlias = L"[Content]";
static UString GetDefaultName3(const UString &fileName,
const UString &extension, const UString &addSubExtension)
{
@@ -21,7 +19,11 @@ static UString GetDefaultName3(const UString &fileName,
int dotPos = fileName.ReverseFind(L'.');
if (dotPos > 0)
return fileName.Left(dotPos) + addSubExtension;
return kEmptyFileAlias;
if (addSubExtension.IsEmpty())
return fileName + L"~";
else
return fileName + addSubExtension;
}
UString GetDefaultName2(const UString &fileName,

View File

@@ -39,25 +39,23 @@ static int MyCompareTime(NFileTimeType::EEnum fileTimeType, const FILETIME &time
}
static const wchar_t *kDuplicateFileNameMessage = L"Duplicate filename:";
static const wchar_t *kNotCensoredCollisionMessaged = L"Internal file name collision (file on disk, file in archive):";
/*
static const char *kNotCensoredCollisionMessaged = "Internal file name collision:\n";
static const char *kSameTimeChangedSizeCollisionMessaged =
"Collision between files with same date/time and different sizes:\n";
*/
static void ThrowError(const UString &message, const UString &s1, const UString &s2)
{
UString m = message;
m += L'\n';
m += s1;
m += L'\n';
m += s2;
throw m;
}
static void TestDuplicateString(const UStringVector &strings, const CIntVector &indices)
{
for(int i = 0; i + 1 < indices.Size(); i++)
if (CompareFileNames(strings[indices[i]], strings[indices[i + 1]]) == 0)
{
UString message = kDuplicateFileNameMessage;
message += L"\n";
message += strings[indices[i]];
message += L"\n";
message += strings[indices[i + 1]];
throw message;
}
ThrowError(kDuplicateFileNameMessage, strings[indices[i]], strings[indices[i + 1]]);
}
void GetUpdatePairInfoList(
@@ -116,7 +114,7 @@ void GetUpdatePairInfoList(
else
{
if (!ai.Censored)
throw 1082022;
ThrowError(kNotCensoredCollisionMessaged, dirNames[dirIndex2], ai.Name);
pair.DirIndex = dirIndex2;
pair.ArcIndex = arcIndex2;
switch (MyCompareTime(

View File

@@ -164,6 +164,8 @@ static const wchar_t *kStartExtensions[] =
L"docx", L"docm", L"dotx", L"dotm", L"xlsx", L"xlsm", L"xltx", L"xltm", L"xlsb",
L"xlam", L"pptx", L"pptm", L"potx", L"potm", L"ppam", L"ppsx", L"ppsm", L"xsn",
L"dwf",
L"odt", L"ods",
L"wb3",
L"pdf"

View File

@@ -81,17 +81,24 @@ STDMETHODIMP CRootFolder::GetProperty(UInt32 itemIndex, PROPID propID, PROPVARIA
return S_OK;
}
typedef BOOL (WINAPI *SHGetSpecialFolderPathWp)(HWND hwnd, LPWSTR pszPath, int csidl, BOOL fCreate);
typedef BOOL (WINAPI *SHGetSpecialFolderPathAp)(HWND hwnd, LPSTR pszPath, int csidl, BOOL fCreate);
UString GetMyDocsPath()
{
UString us;
WCHAR s[MAX_PATH + 1];
if (SHGetSpecialFolderPathW(0, s, CSIDL_PERSONAL, FALSE))
SHGetSpecialFolderPathWp getW = (SHGetSpecialFolderPathWp)
::GetProcAddress(::GetModuleHandleA("shell32.dll"), "SHGetSpecialFolderPathW");
if (getW && getW(0, s, CSIDL_PERSONAL, FALSE))
us = s;
#ifndef _UNICODE
else
{
SHGetSpecialFolderPathAp getA = (SHGetSpecialFolderPathAp)
::GetProcAddress(::GetModuleHandleA("shell32.dll"), "SHGetSpecialFolderPathA");
CHAR s2[MAX_PATH + 1];
if (SHGetSpecialFolderPathA(0, s2, CSIDL_PERSONAL, FALSE))
if (getA && getA(0, s2, CSIDL_PERSONAL, FALSE))
us = GetUnicodeString(s2);
}
#endif

View File

@@ -146,7 +146,8 @@ static EMethodID g_ZipMethods[] =
{
kDeflate,
kDeflate64,
kBZip2
kBZip2,
kLZMA
};
static EMethodID g_GZipMethods[] =
@@ -173,6 +174,8 @@ struct CFormatInfo
bool EncryptFileNames;
};
#define METHODS_PAIR(x) x, MY_SIZE_OF_ARRAY(x)
static const CFormatInfo g_Formats[] =
{
{
@@ -184,26 +187,25 @@ static const CFormatInfo g_Formats[] =
{
k7zFormat,
(1 << 0) | (1 << 1) | (1 << 3) | (1 << 5) | (1 << 7) | (1 << 9),
g_7zMethods, MY_SIZE_OF_ARRAY(g_7zMethods),
METHODS_PAIR(g_7zMethods),
true, true, true, true, true, true
},
{
L"Zip",
(1 << 0) | (1 << 1) | (1 << 3) | (1 << 5) | (1 << 7) | (1 << 9),
g_ZipMethods, MY_SIZE_OF_ARRAY(g_ZipMethods) ,
METHODS_PAIR(g_ZipMethods),
false, false, true, false, true, false
},
{
L"GZip",
(1 << 1) | (1 << 5) | (1 << 7) | (1 << 9),
g_GZipMethods, MY_SIZE_OF_ARRAY(g_GZipMethods),
METHODS_PAIR(g_GZipMethods),
false, false, false, false, false, false
},
{
L"BZip2",
(1 << 1) | (1 << 3) | (1 << 5) | (1 << 7) | (1 << 9),
g_BZip2Methods,
MY_SIZE_OF_ARRAY(g_BZip2Methods),
METHODS_PAIR(g_BZip2Methods),
false, false, true, false, false
},
{
@@ -1289,8 +1291,12 @@ UInt64 CCompressDialog::GetMemoryUsage(UInt32 dictionary, UInt64 &decompressMemo
UInt32 numThreads = GetNumThreads2();
if (IsZipFormat())
{
if (numThreads > 1)
size += (UInt64)numThreads << 25;
UInt32 numSubThreads = 1;
if (GetMethodID() == kLZMA && numThreads > 1 && level >= 5)
numSubThreads = 2;
UInt32 numMainThreads = numThreads / numSubThreads;
if (numMainThreads > 1)
size += (UInt64)numMainThreads << 25;
}
switch (GetMethodID())
{
@@ -1306,13 +1312,19 @@ UInt64 CCompressDialog::GetMemoryUsage(UInt32 dictionary, UInt64 &decompressMemo
if (hs > (1 << 24))
hs >>= 1;
hs++;
size += hs * 4;
size += (UInt64)dictionary * 11 / 2;
UInt64 size1 = (UInt64)hs * 4;
size1 += (UInt64)dictionary * 11 / 2;
if (level >= 5)
size += dictionary * 4;
size += (2 << 20);
size1 += dictionary * 4;
size1 += (2 << 20);
UInt32 numThreads1 = 1;
if (numThreads > 1 && level >= 5)
size += (2 << 20) + (4 << 20);
{
size1 += (2 << 20) + (4 << 20);
numThreads1 = 2;
}
size += size1 * numThreads / numThreads1;
decompressMemory = dictionary + (2 << 20);
return size;

View File

@@ -3,7 +3,10 @@
#ifndef __COMMON_TYPES_H
#define __COMMON_TYPES_H
extern "C"
{
#include "../../C/Types.h"
}
typedef int HRes;

View File

@@ -1,8 +1,6 @@
7z ANSI-C Decoder 4.58
7z ANSI-C Decoder 4.61
----------------------
7z ANSI-C Decoder 4.58 Copyright (C) 1999-2008 Igor Pavlov
7z ANSI-C provides 7z/LZMA decoding.
7z ANSI-C version is simplified version ported from C++ code.
@@ -95,7 +93,7 @@ Steps for using 7z decoder
Use code at 7zMain.c as example.
1) Declare variables:
inStream /* implements ISzInStream interface */
inStream /* implements ILookInStream interface */
CSzArEx db; /* 7z archive database structure */
ISzAlloc allocImp; /* memory functions for main pool */
ISzAlloc allocTempImp; /* memory functions for temporary pool */
@@ -128,7 +126,7 @@ SzArEx_Open function allocates and frees temporary structures by "allocTemp" fun
SZ_RESULT SzAr_Extract(
CArchiveDatabaseEx *db,
ISzInStream *inStream,
ILookInStream *inStream,
UInt32 fileIndex, /* index of file */
UInt32 *blockIndex, /* index of solid block */
Byte **outBuffer, /* pointer to pointer to output buffer (allocated with allocMain) */
@@ -192,4 +190,3 @@ _SZ_ALLOC_DEBUG - define it if you want to debug alloc/free operations to stde
---
http://www.7-zip.org
http://www.7-zip.org/support.html

View File

@@ -2,7 +2,7 @@
;Defines
!define VERSION_MAJOR 4
!define VERSION_MINOR 59
!define VERSION_MINOR 61
!define VERSION_POSTFIX_FULL " beta"
!ifdef WIN64
!ifdef IA64
@@ -240,6 +240,7 @@ Section
File pt-br.txt
File ro.txt
File ru.txt
File si.txt
File sk.txt
File sl.txt
File sq.txt
@@ -319,6 +320,8 @@ Section
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\7-Zip" "NoRepair" 1
WriteUninstaller $INSTDIR\Uninstall.exe
DeleteRegValue HKCR "CLSID\${CLSID_CONTEXT_MENU}\InprocServer32" "InprocServer32"
!ifdef WIN64
ExecWait 'regsvr32 /s "$INSTDIR\7-zip.dll"'
!endif
@@ -426,6 +429,7 @@ Section "Uninstall"
Delete $INSTDIR\Lang\pt-br.txt
Delete $INSTDIR\Lang\ro.txt
Delete $INSTDIR\Lang\ru.txt
Delete $INSTDIR\Lang\si.txt
Delete $INSTDIR\Lang\sk.txt
Delete $INSTDIR\Lang\sl.txt
Delete $INSTDIR\Lang\sq.txt

View File

@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<?define VerMajor = "4" ?>
<?define VerMinor = "60" ?>
<?define VerMinor = "61" ?>
<?define VerBuild = "00" ?>
<?define MmVer = "$(var.VerMajor).$(var.VerMinor)" ?>
<?define MmHex = "0$(var.VerMajor)$(var.VerMinor)" ?>
@@ -279,6 +279,7 @@
<File Id="pt_br.txt" Name="pt-br.txt" />
<File Id="ro.txt" Name="ro.txt" />
<File Id="ru.txt" Name="ru.txt" />
<File Id="si.txt" Name="si.txt" />
<File Id="sk.txt" Name="sk.txt" />
<File Id="sl.txt" Name="sl.txt" />
<File Id="sq.txt" Name="sq.txt" />

View File

@@ -1,4 +1,4 @@
7-Zip method IDs (4.58)
7-Zip method IDs (4.61)
-----------------------
Each compression or crypto method in 7z has unique binary value (ID).
@@ -8,9 +8,9 @@ If you want to add some new ID, you have two ways:
1) Write request for allocating IDs to 7-zip developers.
2) Generate 8-bytes ID:
7F ZZ ZZ ZZ ZZ ZZ MM MM
3F ZZ ZZ ZZ ZZ ZZ MM MM
7F - Prefix for random IDs (1 byte)
3F - Prefix for random IDs (1 byte)
ZZ ZZ ZZ ZZ ZZ - Developer ID (5 bytes). Use real random bytes.
MM MM - Method ID (2 bytes)

View File

@@ -1,6 +1,14 @@
Sources history of the 7-Zip
----------------------------
4.61 2008-11-23
-------------------------
- Bug in ver. 4.58+ was fixed:
7-Zip didn't use any -m* switch after -mtc, -mcl or -mcu for .zip archives.
- Bug in .CAB code was fixed. 7-Zip didn't show some empty files,
if .CAB archive contains more than one empty file.
4.59 2008-07-27
-------------------------
- Bug was fixed:

View File

@@ -1,8 +1,6 @@
LZMA SDK 4.60 beta
LZMA SDK 4.61 beta
------------------
LZMA SDK Copyright (C) 1999-2008 Igor Pavlov
LZMA SDK provides the documentation, samples, header files, libraries,
and tools you need to develop applications that use LZMA compression.
@@ -20,62 +18,7 @@ decompressing.
LICENSE
-------
LZMA SDK is available under any of the following licenses:
1) GNU Lesser General Public License (GNU LGPL)
2) Common Public License (CPL)
3) Common Development and Distribution License (CDDL) Version 1.0
4) Simplified license for unmodified code (read SPECIAL EXCEPTION)
It means that you can select one of these options and follow rules of that license.
1,2,3) GNU LGPL, CPL and CDDL licenses are classified as
- "Free software licenses" at http://www.gnu.org/
- "OSI-approved" at http://www.opensource.org/
4) Simplified license for unmodified code (read SPECIAL EXCEPTION)
Igor Pavlov, as the author of this code, expressly permits you
to statically or dynamically link your code (or bind by name)
to the files from LZMA SDK.
SPECIAL EXCEPTION allows you to use LZMA SDK in applications with closed code,
while you keep LZMA SDK code unmodified.
SPECIAL EXCEPTION #2: Igor Pavlov, as the author of this code, expressly permits
you to use this code under the same terms and conditions contained in the License
Agreement you have for any previous version of LZMA SDK developed by Igor Pavlov.
SPECIAL EXCEPTION #2 allows owners of proprietary licenses to use latest version
of LZMA SDK as update for previous versions.
Some files in LZMA SDK are placed in public domain.
Some of these "public domain" files:
C\Types.h,
C\LzmaLib.*
C\LzmaLibUtil.*
LzmaAlone.cpp,
LzmaAlone.cs,
LzmaAlone.java
So you can change them as you want and use "SPECIAL EXCEPTION"
for other unmodified files. For example, you can edit C\Types.h to solve some
compatibility problems with your compiler.
-----
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
You should have received a copy of the Common Public License
along with this library.
You should have received a copy of the Common Development and Distribution
License Version 1.0 along with this library.
LZMA SDK is written and placed in the public domain by Igor Pavlov.
LZMA SDK Contents
@@ -107,9 +50,6 @@ lzma.txt - LZMA SDK description (this file)
methods.txt - Compression method IDs for .7z
lzma.exe - Compiled file->file LZMA encoder/decoder for Windows
history.txt - history of the LZMA SDK
LGPL.txt - GNU Lesser General Public License
CPL.html - Common Public License
CDDL.html - Common Development and Distribution License (CDDL)
Source code structure