Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/kornelski/7z.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/C/Archive
diff options
context:
space:
mode:
authorIgor Pavlov <ipavlov@users.sourceforge.net>2009-06-02 04:00:00 +0400
committerKornel LesiƄski <kornel@geekhood.net>2016-05-28 02:15:59 +0300
commit829409452d85cd6dd9dfc9151f109d6e13a2bb1c (patch)
treee0acaea47044d167f35fa197584dee1bde41c329 /C/Archive
parent8874e4fbc9faabdcff719b9b2ac8ebad4f282bbe (diff)
9.04 beta
Diffstat (limited to 'C/Archive')
-rwxr-xr-xC/Archive/7z/7z.dsp8
-rwxr-xr-xC/Archive/7z/7zAlloc.h10
-rwxr-xr-xC/Archive/7z/7zDecode.c64
-rwxr-xr-xC/Archive/7z/7zDecode.h10
-rwxr-xr-xC/Archive/7z/7zExtract.h10
-rwxr-xr-xC/Archive/7z/7zHeader.h10
-rwxr-xr-xC/Archive/7z/7zIn.h12
-rwxr-xr-xC/Archive/7z/7zItem.h10
-rwxr-xr-xC/Archive/7z/7zMain.c122
-rwxr-xr-xC/Archive/7z/makefile1
-rwxr-xr-xC/Archive/7z/makefile.gcc5
11 files changed, 220 insertions, 42 deletions
diff --git a/C/Archive/7z/7z.dsp b/C/Archive/7z/7z.dsp
index 9626b03e..6d6b8d93 100755
--- a/C/Archive/7z/7z.dsp
+++ b/C/Archive/7z/7z.dsp
@@ -132,6 +132,14 @@ SOURCE=..\..\Bra86.c
# End Source File
# Begin Source File
+SOURCE=..\..\Lzma2Dec.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\Lzma2Dec.h
+# End Source File
+# Begin Source File
+
SOURCE=..\..\LzmaDec.c
# End Source File
# Begin Source File
diff --git a/C/Archive/7z/7zAlloc.h b/C/Archive/7z/7zAlloc.h
index e752ef18..a5e88e47 100755
--- a/C/Archive/7z/7zAlloc.h
+++ b/C/Archive/7z/7zAlloc.h
@@ -1,15 +1,23 @@
/* 7zAlloc.h -- Allocation functions
-2008-10-04 : Igor Pavlov : Public domain */
+2009-02-07 : Igor Pavlov : Public domain */
#ifndef __7Z_ALLOC_H
#define __7Z_ALLOC_H
#include <stddef.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
void *SzAlloc(void *p, size_t size);
void SzFree(void *p, void *address);
void *SzAllocTemp(void *p, size_t size);
void SzFreeTemp(void *p, void *address);
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/C/Archive/7z/7zDecode.c b/C/Archive/7z/7zDecode.c
index 02526f0e..0d310a48 100755
--- a/C/Archive/7z/7zDecode.c
+++ b/C/Archive/7z/7zDecode.c
@@ -1,14 +1,17 @@
/* 7zDecode.c -- Decoding from 7z folder
-2008-11-23 : Igor Pavlov : Public domain */
+2009-05-03 : Igor Pavlov : Public domain */
#include <string.h>
#include "../../Bcj2.h"
#include "../../Bra.h"
#include "../../LzmaDec.h"
+#include "../../Lzma2Dec.h"
+
#include "7zDecode.h"
#define k_Copy 0
+#define k_LZMA2 0x21
#define k_LZMA 0x30101
#define k_BCJ 0x03030103
#define k_BCJ2 0x0303011B
@@ -61,6 +64,55 @@ static SRes SzDecodeLzma(CSzCoderInfo *coder, UInt64 inSize, ILookInStream *inSt
return res;
}
+static SRes SzDecodeLzma2(CSzCoderInfo *coder, UInt64 inSize, ILookInStream *inStream,
+ Byte *outBuffer, SizeT outSize, ISzAlloc *allocMain)
+{
+ CLzma2Dec state;
+ SRes res = SZ_OK;
+
+ Lzma2Dec_Construct(&state);
+ if (coder->Props.size != 1)
+ return SZ_ERROR_DATA;
+ RINOK(Lzma2Dec_AllocateProbs(&state, coder->Props.data[0], allocMain));
+ state.decoder.dic = outBuffer;
+ state.decoder.dicBufSize = outSize;
+ Lzma2Dec_Init(&state);
+
+ for (;;)
+ {
+ 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 = (SizeT)lookahead, dicPos = state.decoder.dicPos;
+ ELzmaStatus status;
+ res = Lzma2Dec_DecodeToDic(&state, outSize, inBuf, &inProcessed, LZMA_FINISH_END, &status);
+ lookahead -= inProcessed;
+ inSize -= inProcessed;
+ if (res != SZ_OK)
+ break;
+ if (state.decoder.dicPos == state.decoder.dicBufSize || (inProcessed == 0 && dicPos == state.decoder.dicPos))
+ {
+ if (state.decoder.dicBufSize != outSize || lookahead != 0 ||
+ (status != LZMA_STATUS_FINISHED_WITH_MARK))
+ res = SZ_ERROR_DATA;
+ break;
+ }
+ res = inStream->Skip((void *)inStream, inProcessed);
+ if (res != SZ_OK)
+ break;
+ }
+ }
+
+ Lzma2Dec_FreeProbs(&state, allocMain);
+ return res;
+}
+
static SRes SzDecodeCopy(UInt64 inSize, ILookInStream *inStream, Byte *outBuffer)
{
while (inSize > 0)
@@ -80,7 +132,7 @@ static SRes SzDecodeCopy(UInt64 inSize, ILookInStream *inStream, Byte *outBuffer
return SZ_OK;
}
-#define IS_UNSUPPORTED_METHOD(m) ((m) != k_Copy && (m) != k_LZMA)
+#define IS_UNSUPPORTED_METHOD(m) ((m) != k_Copy && (m) != k_LZMA && (m) != k_LZMA2)
#define IS_UNSUPPORTED_CODER(c) (IS_UNSUPPORTED_METHOD(c.MethodID) || c.NumInStreams != 1 || c.NumOutStreams != 1)
#define IS_NO_BCJ(c) (c.MethodID != k_BCJ || c.NumInStreams != 1 || c.NumOutStreams != 1)
#define IS_NO_BCJ2(c) (c.MethodID != k_BCJ2 || c.NumInStreams != 4 || c.NumOutStreams != 1)
@@ -152,7 +204,7 @@ SRes SzDecode2(const UInt64 *packSizes, const CSzFolder *folder,
{
CSzCoderInfo *coder = &folder->Coders[ci];
- if (coder->MethodID == k_Copy || coder->MethodID == k_LZMA)
+ if (coder->MethodID == k_Copy || coder->MethodID == k_LZMA || coder->MethodID == k_LZMA2)
{
UInt32 si = 0;
UInt64 offset;
@@ -196,10 +248,14 @@ SRes SzDecode2(const UInt64 *packSizes, const CSzFolder *folder,
return SZ_ERROR_DATA;
RINOK(SzDecodeCopy(inSize, inStream, outBufCur));
}
- else
+ else if (coder->MethodID == k_LZMA)
{
RINOK(SzDecodeLzma(coder, inSize, inStream, outBufCur, outSizeCur, allocMain));
}
+ else
+ {
+ RINOK(SzDecodeLzma2(coder, inSize, inStream, outBufCur, outSizeCur, allocMain));
+ }
}
else if (coder->MethodID == k_BCJ)
{
diff --git a/C/Archive/7z/7zDecode.h b/C/Archive/7z/7zDecode.h
index e19fe387..0d77970d 100755
--- a/C/Archive/7z/7zDecode.h
+++ b/C/Archive/7z/7zDecode.h
@@ -1,13 +1,21 @@
/* 7zDecode.h -- Decoding from 7z folder
-2008-11-23 : Igor Pavlov : Public domain */
+2009-02-07 : Igor Pavlov : Public domain */
#ifndef __7Z_DECODE_H
#define __7Z_DECODE_H
#include "7zItem.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
SRes SzDecode(const UInt64 *packSizes, const CSzFolder *folder,
ILookInStream *stream, UInt64 startPos,
Byte *outBuffer, size_t outSize, ISzAlloc *allocMain);
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/C/Archive/7z/7zExtract.h b/C/Archive/7z/7zExtract.h
index 5f78415f..6f46bfa6 100755
--- a/C/Archive/7z/7zExtract.h
+++ b/C/Archive/7z/7zExtract.h
@@ -1,11 +1,15 @@
/* 7zExtract.h -- Extracting from 7z archive
-2008-11-23 : Igor Pavlov : Public domain */
+2009-02-07 : Igor Pavlov : Public domain */
#ifndef __7Z_EXTRACT_H
#define __7Z_EXTRACT_H
#include "7zIn.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/*
SzExtract extracts file from archive
@@ -38,4 +42,8 @@ SRes SzAr_Extract(
ISzAlloc *allocMain,
ISzAlloc *allocTemp);
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/C/Archive/7z/7zHeader.h b/C/Archive/7z/7zHeader.h
index 9941b6f7..bc117d2e 100755
--- a/C/Archive/7z/7zHeader.h
+++ b/C/Archive/7z/7zHeader.h
@@ -1,11 +1,15 @@
/* 7zHeader.h -- 7z Headers
-2008-10-04 : Igor Pavlov : Public domain */
+2009-02-07 : Igor Pavlov : Public domain */
#ifndef __7Z_HEADER_H
#define __7Z_HEADER_H
#include "../../Types.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#define k7zSignatureSize 6
extern Byte k7zSignature[k7zSignatureSize];
@@ -54,4 +58,8 @@ enum EIdEnum
k7zIdDummy
};
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/C/Archive/7z/7zIn.h b/C/Archive/7z/7zIn.h
index c8430a7b..50db4d38 100755
--- a/C/Archive/7z/7zIn.h
+++ b/C/Archive/7z/7zIn.h
@@ -1,5 +1,5 @@
-/* 7zIn.h -- 7z Input functions
-2008-11-23 : Igor Pavlov : Public domain */
+/* 7zIn.h -- 7z Input
+2009-02-07 : Igor Pavlov : Public domain */
#ifndef __7Z_IN_H
#define __7Z_IN_H
@@ -7,6 +7,10 @@
#include "7zHeader.h"
#include "7zItem.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
typedef struct
{
CSzAr db;
@@ -38,4 +42,8 @@ SZ_ERROR_FAIL
SRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream, ISzAlloc *allocMain, ISzAlloc *allocTemp);
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/C/Archive/7z/7zItem.h b/C/Archive/7z/7zItem.h
index 9f1366cd..ce7288c2 100755
--- a/C/Archive/7z/7zItem.h
+++ b/C/Archive/7z/7zItem.h
@@ -1,11 +1,15 @@
/* 7zItem.h -- 7z Items
-2008-10-04 : Igor Pavlov : Public domain */
+2009-02-07 : Igor Pavlov : Public domain */
#ifndef __7Z_ITEM_H
#define __7Z_ITEM_H
#include "../../7zBuf.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
typedef struct
{
UInt32 NumInStreams;
@@ -81,4 +85,8 @@ typedef struct
void SzAr_Init(CSzAr *p);
void SzAr_Free(CSzAr *p, ISzAlloc *alloc);
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/C/Archive/7z/7zMain.c b/C/Archive/7z/7zMain.c
index 0c20e8c3..ae65125f 100755
--- a/C/Archive/7z/7zMain.c
+++ b/C/Archive/7z/7zMain.c
@@ -1,5 +1,5 @@
/* 7zMain.c - Test application for 7z Decoder
-2008-11-23 : Igor Pavlov : Public domain */
+2009-04-04 : Igor Pavlov : Public domain */
#include <stdlib.h>
#include <stdio.h>
@@ -13,6 +13,37 @@
#include "7zExtract.h"
#include "7zIn.h"
+#ifndef USE_WINDOWS_FILE
+/* for mkdir */
+#ifdef _WIN32
+#include <direct.h>
+#else
+#include <sys/stat.h>
+#include <errno.h>
+#endif
+#endif
+
+#ifdef _WIN32
+#define CHAR_PATH_SEPARATOR '\\'
+#else
+#define CHAR_PATH_SEPARATOR '/'
+#endif
+
+static WRes MyCreateDir(const char *name)
+{
+ #ifdef USE_WINDOWS_FILE
+ return CreateDirectoryA(name, NULL) ? 0 : GetLastError();
+ #else
+ #ifdef _WIN32
+ return _mkdir(name)
+ #else
+ return mkdir(name, 0777)
+ #endif
+ == 0 ? 0 : errno;
+ #endif
+}
+
+
static void ConvertNumberToString(UInt64 value, char *s)
{
char temp[32];
@@ -33,7 +64,7 @@ static void ConvertNumberToString(UInt64 value, char *s)
#define PERIOD_100 (PERIOD_4 * 25 - 1)
#define PERIOD_400 (PERIOD_100 * 4 + 1)
-static void ConvertFileTimeToString(CNtfsFileTime *ft, char *s)
+static void ConvertFileTimeToString(const CNtfsFileTime *ft, char *s)
{
unsigned year, mon, day, hour, min, sec;
UInt64 v64 = ft->Low | ((UInt64)ft->High << 32);
@@ -97,16 +128,19 @@ int MY_CDECL main(int numargs, char *args[])
SRes res;
ISzAlloc allocImp;
ISzAlloc allocTempImp;
+ char *temp = NULL;
+ size_t tempSize = 0;
- printf("\n7z ANSI-C Decoder " MY_VERSION_COPYRIGHT_DATE "\n");
+ printf("\n7z ANSI-C Decoder " MY_VERSION_COPYRIGHT_DATE "\n\n");
if (numargs == 1)
{
printf(
- "\nUsage: 7zDec <command> <archive_name>\n\n"
+ "Usage: 7zDec <command> <archive_name>\n\n"
"<Commands>\n"
- " e: Extract files from archive\n"
+ " e: Extract files from archive (without using directory names)\n"
" l: List contents of archive\n"
- " t: Test integrity of archive\n");
+ " t: Test integrity of archive\n"
+ " x: eXtract files with full paths\n");
return 0;
}
if (numargs < 3)
@@ -141,17 +175,18 @@ int MY_CDECL main(int numargs, char *args[])
if (res == SZ_OK)
{
char *command = args[1];
- int listCommand = 0, testCommand = 0, extractCommand = 0;
+ int listCommand = 0, testCommand = 0, extractCommand = 0, fullPaths = 0;
if (strcmp(command, "l") == 0) listCommand = 1;
else if (strcmp(command, "t") == 0) testCommand = 1;
else if (strcmp(command, "e") == 0) extractCommand = 1;
+ else if (strcmp(command, "x") == 0) { extractCommand = 1; fullPaths = 1; }
if (listCommand)
{
UInt32 i;
for (i = 0; i < db.db.NumFiles; i++)
{
- CSzFileItem *f = db.db.Files + i;
+ const CSzFileItem *f = db.db.Files + i;
char s[32], t[32];
ConvertNumberToString(f->Size, s);
if (f->MTimeDefined)
@@ -159,7 +194,10 @@ int MY_CDECL main(int numargs, char *args[])
else
strcpy(t, " ");
- printf("%s %10s %s\n", t, s, f->Name);
+ printf("%s %10s %s", t, s, f->Name);
+ if (f->IsDir)
+ printf("/");
+ printf("\n");
}
}
else if (testCommand || extractCommand)
@@ -174,44 +212,67 @@ int MY_CDECL main(int numargs, char *args[])
Byte *outBuffer = 0; /* it must be 0 before first call for each new archive. */
size_t outBufferSize = 0; /* it can have any value before first call (if outBuffer = 0) */
- printf("\n");
for (i = 0; i < db.db.NumFiles; i++)
{
size_t offset;
size_t outSizeProcessed;
- CSzFileItem *f = db.db.Files + i;
- if (f->IsDir)
- printf("Directory ");
- else
- printf(testCommand ?
+ const CSzFileItem *f = db.db.Files + i;
+ if (f->IsDir && !fullPaths)
+ continue;
+ printf(testCommand ?
"Testing ":
"Extracting");
printf(" %s", f->Name);
if (f->IsDir)
+ printf("/");
+ else
{
- printf("\n");
- continue;
+ res = SzAr_Extract(&db, &lookStream.s, i,
+ &blockIndex, &outBuffer, &outBufferSize,
+ &offset, &outSizeProcessed,
+ &allocImp, &allocTempImp);
+ if (res != SZ_OK)
+ break;
}
- res = SzAr_Extract(&db, &lookStream.s, i,
- &blockIndex, &outBuffer, &outBufferSize,
- &offset, &outSizeProcessed,
- &allocImp, &allocTempImp);
- if (res != SZ_OK)
- break;
if (!testCommand)
{
CSzFile outFile;
size_t processedSize;
- char *fileName = f->Name;
- size_t nameLen = strlen(f->Name);
- for (; nameLen > 0; nameLen--)
- if (f->Name[nameLen - 1] == '/')
+ size_t j, nameLen = strlen(f->Name);
+ const char *destPath;
+ if (nameLen + 1 > tempSize)
+ {
+ SzFree(NULL, temp);
+ tempSize = nameLen + 1;
+ temp = (char *)SzAlloc(NULL, tempSize);
+ if (temp == 0)
{
- fileName = f->Name + nameLen;
+ res = SZ_ERROR_MEM;
break;
}
-
- if (OutFile_Open(&outFile, fileName))
+ }
+ destPath = temp;
+ strcpy(temp, f->Name);
+ for (j = 0; j < nameLen; j++)
+ if (temp[j] == '/')
+ {
+ if (fullPaths)
+ {
+ temp[j] = 0;
+ MyCreateDir(temp);
+ temp[j] = CHAR_PATH_SEPARATOR;
+ }
+ else
+ destPath = temp + j + 1;
+ }
+
+ if (f->IsDir)
+ {
+ MyCreateDir(destPath);
+ printf("\n");
+ continue;
+ }
+ else if (OutFile_Open(&outFile, destPath))
{
PrintError("can not open output file");
res = SZ_ERROR_FAIL;
@@ -243,6 +304,7 @@ int MY_CDECL main(int numargs, char *args[])
}
}
SzArEx_Free(&db, &allocImp);
+ SzFree(NULL, temp);
File_Close(&archiveStream.file);
if (res == SZ_OK)
diff --git a/C/Archive/7z/makefile b/C/Archive/7z/makefile
index c7bb05bd..cf06c860 100755
--- a/C/Archive/7z/makefile
+++ b/C/Archive/7z/makefile
@@ -7,6 +7,7 @@ C_OBJS = \
$O\7zBuf2.obj \
$O\7zCrc.obj \
$O\LzmaDec.obj \
+ $O\Lzma2Dec.obj \
$O\Bra86.obj \
$O\Bcj2.obj \
$O\7zFile.obj \
diff --git a/C/Archive/7z/makefile.gcc b/C/Archive/7z/makefile.gcc
index 2203dfc1..29d2aa02 100755
--- a/C/Archive/7z/makefile.gcc
+++ b/C/Archive/7z/makefile.gcc
@@ -4,7 +4,7 @@ LIB =
RM = rm -f
CFLAGS = -c -O2 -Wall
-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
+OBJS = 7zAlloc.o 7zBuf.o 7zBuf2.o 7zCrc.o 7zDecode.o 7zExtract.o 7zHeader.o 7zIn.o 7zItem.o 7zMain.o LzmaDec.o Lzma2Dec.o Bra86.o Bcj2.o 7zFile.o 7zStream.o
all: $(PROG)
@@ -44,6 +44,9 @@ $(PROG): $(OBJS)
LzmaDec.o: ../../LzmaDec.c
$(CXX) $(CFLAGS) ../../LzmaDec.c
+Lzma2Dec.o: ../../Lzma2Dec.c
+ $(CXX) $(CFLAGS) ../../Lzma2Dec.c
+
Bra86.o: ../../Bra86.c
$(CXX) $(CFLAGS) ../../Bra86.c