Skip to content

Commit cccb6fa

Browse files
author
Oleh Kulykov
committed
1721299233
1 parent 91a6655 commit cccb6fa

File tree

9 files changed

+210
-105
lines changed

9 files changed

+210
-105
lines changed

src/CPP/7zip/Archive/ArchiveExports.cpp

100755100644
File mode changed.

src/CPP/7zip/Archive/DllExports2.cpp

100755100644
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,65 @@
2121

2222
#include "IArchive.h"
2323

24+
25+
#ifdef _WIN32
26+
27+
#if defined(_UNICODE) && !defined(_WIN64) && !defined(UNDER_CE)
28+
#define NT_CHECK_FAIL_ACTION return FALSE;
29+
#endif
30+
31+
static
32+
HINSTANCE g_hInstance;
33+
34+
extern "C"
35+
BOOL WINAPI DllMain(
36+
#ifdef UNDER_CE
37+
HANDLE
38+
#else
39+
HINSTANCE
40+
#endif
41+
hInstance, DWORD dwReason, LPVOID /*lpReserved*/);
42+
43+
extern "C"
44+
BOOL WINAPI DllMain(
45+
#ifdef UNDER_CE
46+
HANDLE
47+
#else
48+
HINSTANCE
49+
#endif
50+
hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
51+
{
52+
if (dwReason == DLL_PROCESS_ATTACH)
53+
{
54+
// OutputDebugStringA("7z.dll DLL_PROCESS_ATTACH");
55+
g_hInstance = (HINSTANCE)hInstance;
56+
NT_CHECK
57+
}
58+
/*
59+
if (dwReason == DLL_PROCESS_DETACH)
60+
{
61+
OutputDebugStringA("7z.dll DLL_PROCESS_DETACH");
62+
}
63+
*/
64+
return TRUE;
65+
}
66+
67+
#else // _WIN32
68+
69+
#include "../../Common/StringConvert.h"
70+
// #include <stdio.h>
71+
72+
// STDAPI LibStartup();
73+
static __attribute__((constructor)) void Init_ForceToUTF8();
74+
static __attribute__((constructor)) void Init_ForceToUTF8()
75+
{
76+
g_ForceToUTF8 = IsNativeUTF8();
77+
// printf("\nDLLExports2.cpp::Init_ForceToUTF8 =%d\n", g_ForceToUTF8 ? 1 : 0);
78+
}
79+
80+
#endif // _WIN32
81+
82+
2483
Z7_DEFINE_GUID(CLSID_CArchiveHandler,
2584
k_7zip_GUID_Data1,
2685
k_7zip_GUID_Data2,

src/CPP/7zip/Archive/DllExports2.h

100755100644
File mode changed.

src/CPP/7zip/Archive/IArchive.h

100755100644
Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ namespace NArchive
175175
}
176176

177177
#define Z7_IFACEM_IArchiveOpenCallback(x) \
178-
x(SetTotal(const UInt64 *files, const UInt64 *bytes)); \
179-
x(SetCompleted(const UInt64 *files, const UInt64 *bytes)); \
178+
x(SetTotal(const UInt64 *files, const UInt64 *bytes)) \
179+
x(SetCompleted(const UInt64 *files, const UInt64 *bytes)) \
180180

181181
Z7_IFACE_CONSTR_ARCHIVE(IArchiveOpenCallback, 0x10)
182182

@@ -232,9 +232,9 @@ SetOperationResult()
232232
// INTERFACE_IProgress(x)
233233

234234
#define Z7_IFACEM_IArchiveExtractCallback(x) \
235-
x(GetStream(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode)) \
236-
x(PrepareOperation(Int32 askExtractMode)) \
237-
x(SetOperationResult(Int32 opRes)) \
235+
x(GetStream(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode)) \
236+
x(PrepareOperation(Int32 askExtractMode)) \
237+
x(SetOperationResult(Int32 opRes)) \
238238

239239
Z7_IFACE_CONSTR_ARCHIVE_SUB(IArchiveExtractCallback, IProgress, 0x20)
240240

@@ -565,6 +565,56 @@ Z7_IFACE_CONSTR_ARCHIVE(IArchiveKeepModeForNextOpen, 0x04)
565565
Z7_IFACE_CONSTR_ARCHIVE(IArchiveAllowTail, 0x05)
566566

567567

568+
namespace NRequestMemoryUseFlags
569+
{
570+
const UInt32 k_AllowedSize_WasForced = 1 << 0; // (*allowedSize) was forced by -mmemx or -smemx
571+
const UInt32 k_DefaultLimit_Exceeded = 1 << 1; // default limit of archive format was exceeded
572+
const UInt32 k_MLimit_Exceeded = 1 << 2; // -mmemx value was exceeded
573+
const UInt32 k_SLimit_Exceeded = 1 << 3; // -smemx value was exceeded
574+
575+
const UInt32 k_NoErrorMessage = 1 << 10; // do not show error message, and show only request
576+
const UInt32 k_IsReport = 1 << 11; // only report is required, without user request
577+
578+
const UInt32 k_SkipArc_IsExpected = 1 << 12; // NRequestMemoryAnswerFlags::k_SkipArc flag answer is expected
579+
const UInt32 k_Report_SkipArc = 1 << 13; // report about SkipArc operation
580+
581+
// const UInt32 k_SkipBigFile_IsExpected = 1 << 14; // NRequestMemoryAnswerFlags::k_SkipBigFiles flag answer is expected (unused)
582+
// const UInt32 k_Report_SkipBigFile = 1 << 15; // report about SkipFile operation (unused)
583+
584+
// const UInt32 k_SkipBigFiles_IsExpected = 1 << 16; // NRequestMemoryAnswerFlags::k_SkipBigFiles flag answer is expected (unused)
585+
// const UInt32 k_Report_SkipBigFiles = 1 << 17; // report that all big files will be skipped (unused)
586+
}
587+
588+
namespace NRequestMemoryAnswerFlags
589+
{
590+
const UInt32 k_Allow = 1 << 0; // allow further archive extraction
591+
const UInt32 k_Stop = 1 << 1; // for exit (and return_code == E_ABORT is used)
592+
const UInt32 k_SkipArc = 1 << 2; // skip current archive extraction
593+
// const UInt32 k_SkipBigFile = 1 << 4; // skip extracting of files that exceed limit (unused)
594+
// const UInt32 k_SkipBigFiles = 1 << 5; // skip extracting of files that exceed limit (unused)
595+
const UInt32 k_Limit_Exceeded = 1 << 10; // limit was exceeded
596+
}
597+
598+
/*
599+
*allowedSize is in/out:
600+
in : default allowed memory usage size or forced size, if it was changed by switch -mmemx.
601+
out : value specified by user or unchanged value.
602+
603+
*answerFlags is in/out:
604+
*answerFlags must be set by caller before calling for default action,
605+
606+
indexType : must be set with NEventIndexType::* constant
607+
(indexType == kNoIndex), if request for whole archive.
608+
index : must be set for some (indexType) types (if
609+
fileIndex , if (indexType == NEventIndexType::kInArcIndex)
610+
0, if if (indexType == kNoIndex)
611+
path : NULL can be used for any indexType.
612+
*/
613+
#define Z7_IFACEM_IArchiveRequestMemoryUseCallback(x) \
614+
x(RequestMemoryUse(UInt32 flags, UInt32 indexType, UInt32 index, const wchar_t *path, \
615+
UInt64 requiredSize, UInt64 *allowedSize, UInt32 *answerFlags))
616+
Z7_IFACE_CONSTR_ARCHIVE(IArchiveRequestMemoryUseCallback, 0x09)
617+
568618

569619
struct CStatProp
570620
{

src/CPP/7zip/Archive/LzmaHandler.cpp

100755100644
Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -80,31 +80,26 @@ class CDecoder Z7_final
8080
{
8181
CMyComPtr<ISequentialOutStream> _bcjStream;
8282
CFilterCoder *_filterCoder;
83-
CMyComPtr<ICompressCoder> _lzmaDecoder;
8483
public:
85-
NCompress::NLzma::CDecoder *_lzmaDecoderSpec;
84+
CMyComPtr2<ICompressCoder, NCompress::NLzma::CDecoder> _lzmaDecoder;
8685

8786
~CDecoder();
8887
HRESULT Create(bool filtered, ISequentialInStream *inStream);
8988

9089
HRESULT Code(const CHeader &header, ISequentialOutStream *outStream, ICompressProgressInfo *progress);
9190

92-
UInt64 GetInputProcessedSize() const { return _lzmaDecoderSpec->GetInputProcessedSize(); }
91+
UInt64 GetInputProcessedSize() const { return _lzmaDecoder->GetInputProcessedSize(); }
9392

94-
void ReleaseInStream() { if (_lzmaDecoder) _lzmaDecoderSpec->ReleaseInStream(); }
93+
void ReleaseInStream() { if (_lzmaDecoder) _lzmaDecoder->ReleaseInStream(); }
9594

9695
HRESULT ReadInput(Byte *data, UInt32 size, UInt32 *processedSize)
97-
{ return _lzmaDecoderSpec->ReadFromInputStream(data, size, processedSize); }
96+
{ return _lzmaDecoder->ReadFromInputStream(data, size, processedSize); }
9897
};
9998

10099
HRESULT CDecoder::Create(bool filteredMode, ISequentialInStream *inStream)
101100
{
102-
if (!_lzmaDecoder)
103-
{
104-
_lzmaDecoderSpec = new NCompress::NLzma::CDecoder;
105-
_lzmaDecoderSpec->FinishStream = true;
106-
_lzmaDecoder = _lzmaDecoderSpec;
107-
}
101+
_lzmaDecoder.Create_if_Empty();
102+
_lzmaDecoder->FinishStream = true;
108103

109104
if (filteredMode)
110105
{
@@ -117,7 +112,7 @@ HRESULT CDecoder::Create(bool filteredMode, ISequentialInStream *inStream)
117112
}
118113
}
119114

120-
return _lzmaDecoderSpec->SetInStream(inStream);
115+
return _lzmaDecoder->SetInStream(inStream);
121116
}
122117

123118
CDecoder::~CDecoder()
@@ -131,7 +126,7 @@ HRESULT CDecoder::Code(const CHeader &header, ISequentialOutStream *outStream,
131126
if (header.FilterID > 1)
132127
return E_NOTIMPL;
133128

134-
RINOK(_lzmaDecoderSpec->SetDecoderProperties2(header.LzmaProps, 5))
129+
RINOK(_lzmaDecoder->SetDecoderProperties2(header.LzmaProps, 5))
135130

136131
bool filteredMode = (header.FilterID == 1);
137132

@@ -143,7 +138,7 @@ HRESULT CDecoder::Code(const CHeader &header, ISequentialOutStream *outStream,
143138
}
144139

145140
const UInt64 *Size = header.HasSize() ? &header.Size : NULL;
146-
HRESULT res = _lzmaDecoderSpec->CodeResume(outStream, Size, progress);
141+
HRESULT res = _lzmaDecoder->CodeResume(outStream, Size, progress);
147142

148143
if (filteredMode)
149144
{
@@ -160,7 +155,7 @@ HRESULT CDecoder::Code(const CHeader &header, ISequentialOutStream *outStream,
160155
RINOK(res)
161156

162157
if (header.HasSize())
163-
if (_lzmaDecoderSpec->GetOutputProcessedSize() != header.Size)
158+
if (_lzmaDecoder->GetOutputProcessedSize() != header.Size)
164159
return S_FALSE;
165160

166161
return S_OK;
@@ -170,11 +165,7 @@ HRESULT CDecoder::Code(const CHeader &header, ISequentialOutStream *outStream,
170165
Z7_CLASS_IMP_CHandler_IInArchive_1(
171166
IArchiveOpenSeq
172167
)
173-
CHeader _header;
174168
bool _lzma86;
175-
CMyComPtr<IInStream> _stream;
176-
CMyComPtr<ISequentialInStream> _seqStream;
177-
178169
bool _isArc;
179170
bool _needSeekToStart;
180171
bool _dataAfterEnd;
@@ -186,6 +177,10 @@ Z7_CLASS_IMP_CHandler_IInArchive_1(
186177
bool _unpackSize_Defined;
187178
bool _numStreams_Defined;
188179

180+
CHeader _header;
181+
CMyComPtr<IInStream> _stream;
182+
CMyComPtr<ISequentialInStream> _seqStream;
183+
189184
UInt64 _packSize;
190185
UInt64 _unpackSize;
191186
UInt64 _numStreams;
@@ -220,6 +215,7 @@ Z7_COM7F_IMF(CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value))
220215
prop = v;
221216
break;
222217
}
218+
default: break;
223219
}
224220
prop.Detach(value);
225221
return S_OK;
@@ -288,6 +284,7 @@ Z7_COM7F_IMF(CHandler::GetProperty(UInt32 /* index */, PROPID propID, PROPVARIAN
288284
case kpidSize: if (_stream && _header.HasSize()) prop = _header.Size; break;
289285
case kpidPackSize: if (_packSize_Defined) prop = _packSize; break;
290286
case kpidMethod: GetMethod(prop); break;
287+
default: break;
291288
}
292289
prop.Detach(value);
293290
return S_OK;
@@ -366,7 +363,6 @@ Z7_COM7F_IMF(CHandler::Open(IInStream *inStream, const UInt64 *, IArchiveOpenCal
366363
)
367364
return S_FALSE;
368365

369-
CDecoder state;
370366
const UInt32 outLimit = 1 << 11;
371367
Byte outBuf[outLimit];
372368

@@ -452,9 +448,10 @@ Z7_COM7F_IMF(CHandler::Extract(const UInt32 *indices, UInt32 numItems,
452448
return E_INVALIDARG;
453449

454450
if (_packSize_Defined)
455-
extractCallback->SetTotal(_packSize);
451+
RINOK(extractCallback->SetTotal(_packSize))
456452

457-
453+
Int32 opResult;
454+
{
458455
CMyComPtr<ISequentialOutStream> realOutStream;
459456
const Int32 askMode = testMode ?
460457
NExtract::NAskMode::kTest :
@@ -463,16 +460,14 @@ Z7_COM7F_IMF(CHandler::Extract(const UInt32 *indices, UInt32 numItems,
463460
if (!testMode && !realOutStream)
464461
return S_OK;
465462

466-
extractCallback->PrepareOperation(askMode);
463+
RINOK(extractCallback->PrepareOperation(askMode))
467464

468-
CDummyOutStream *outStreamSpec = new CDummyOutStream;
469-
CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);
470-
outStreamSpec->SetStream(realOutStream);
471-
outStreamSpec->Init();
465+
CMyComPtr2_Create<ISequentialOutStream, CDummyOutStream> outStream;
466+
outStream->SetStream(realOutStream);
467+
outStream->Init();
472468
realOutStream.Release();
473469

474-
CLocalProgress *lps = new CLocalProgress;
475-
CMyComPtr<ICompressProgressInfo> progress = lps;
470+
CMyComPtr2_Create<ICompressProgressInfo, CLocalProgress> lps;
476471
lps->Init(extractCallback, true);
477472

478473
if (_needSeekToStart)
@@ -485,8 +480,7 @@ Z7_COM7F_IMF(CHandler::Extract(const UInt32 *indices, UInt32 numItems,
485480
_needSeekToStart = true;
486481

487482
CDecoder decoder;
488-
HRESULT result = decoder.Create(_lzma86, _seqStream);
489-
RINOK(result)
483+
RINOK(decoder.Create(_lzma86, _seqStream))
490484

491485
bool firstItem = true;
492486

@@ -496,6 +490,8 @@ Z7_COM7F_IMF(CHandler::Extract(const UInt32 *indices, UInt32 numItems,
496490

497491
bool dataAfterEnd = false;
498492

493+
HRESULT hres = S_OK;
494+
499495
for (;;)
500496
{
501497
lps->InSize = packSize;
@@ -523,32 +519,32 @@ Z7_COM7F_IMF(CHandler::Extract(const UInt32 *indices, UInt32 numItems,
523519
numStreams++;
524520
firstItem = false;
525521

526-
result = decoder.Code(st, outStream, progress);
522+
hres = decoder.Code(st, outStream, lps);
527523

528524
packSize = decoder.GetInputProcessedSize();
529-
unpackSize = outStreamSpec->GetSize();
525+
unpackSize = outStream->GetSize();
530526

531-
if (result == E_NOTIMPL)
527+
if (hres == E_NOTIMPL)
532528
{
533529
_unsupported = true;
534-
result = S_FALSE;
530+
hres = S_FALSE;
535531
break;
536532
}
537-
if (result == S_FALSE)
533+
if (hres == S_FALSE)
538534
break;
539-
RINOK(result)
535+
RINOK(hres)
540536
}
541537

542538
if (firstItem)
543539
{
544540
_isArc = false;
545-
result = S_FALSE;
541+
hres = S_FALSE;
546542
}
547-
else if (result == S_OK || result == S_FALSE)
543+
else if (hres == S_OK || hres == S_FALSE)
548544
{
549545
if (dataAfterEnd)
550546
_dataAfterEnd = true;
551-
else if (decoder._lzmaDecoderSpec->NeedsMoreInput())
547+
else if (decoder._lzmaDecoder->NeedsMoreInput())
552548
_needMoreInput = true;
553549

554550
_packSize = packSize;
@@ -560,7 +556,7 @@ Z7_COM7F_IMF(CHandler::Extract(const UInt32 *indices, UInt32 numItems,
560556
_numStreams_Defined = true;
561557
}
562558

563-
Int32 opResult = NExtract::NOperationResult::kOK;
559+
opResult = NExtract::NOperationResult::kOK;
564560

565561
if (!_isArc)
566562
opResult = NExtract::NOperationResult::kIsNotArc;
@@ -570,14 +566,15 @@ Z7_COM7F_IMF(CHandler::Extract(const UInt32 *indices, UInt32 numItems,
570566
opResult = NExtract::NOperationResult::kUnsupportedMethod;
571567
else if (_dataAfterEnd)
572568
opResult = NExtract::NOperationResult::kDataAfterEnd;
573-
else if (result == S_FALSE)
569+
else if (hres == S_FALSE)
574570
opResult = NExtract::NOperationResult::kDataError;
575-
else if (result == S_OK)
571+
else if (hres == S_OK)
576572
opResult = NExtract::NOperationResult::kOK;
577573
else
578-
return result;
574+
return hres;
579575

580-
outStream.Release();
576+
// outStream.Release();
577+
}
581578
return extractCallback->SetOperationResult(opResult);
582579

583580
COM_TRY_END

0 commit comments

Comments
 (0)