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

@@ -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)