-
Notifications
You must be signed in to change notification settings - Fork 12
/
sevenzip.pas
2730 lines (2421 loc) · 100 KB
/
sevenzip.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(********************************************************************************)
(* 7-ZIP DELPHI API *)
(* *)
(* The contents of this file are subject to the Mozilla Public License Version *)
(* 1.1 (the "License"); you may not use this file except in compliance with the *)
(* License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ *)
(* *)
(* Software distributed under the License is distributed on an "AS IS" basis, *)
(* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for *)
(* the specific language governing rights and limitations under the License. *)
(* *)
(* Unit owner : Henri Gourvest <[email protected]> *)
(* V1.2 *)
(********************************************************************************)
// Original code at https://code.google.com/archive/p/d7zip/
// Uploaded to GitHub at https://github.com/danielmarschall/d7zip
// Current version by Daniel Marschall, 15 May 2024 with the following changes:
// - Added format GUID: RAR5; https://github.com/geoffsmith82/d7zip/issues/7
// - Fix Range Check Exception in RINOK(); https://github.com/geoffsmith82/d7zip/pull/8
// - Avoid unhandled Delphi Exceptions crashing the DLL parent process; https://github.com/geoffsmith82/d7zip/pull/9
// - Implemented packing and unpacking of empty directories, folders which begin with a dot, and hidden files; https://github.com/geoffsmith82/d7zip/pull/10
// - Implemented restoring of the file attributes and modification times; https://github.com/geoffsmith82/d7zip/pull/11
// - Added ExtractItemToPath method, by ekot1; https://github.com/ekot1/d7zip/commit/a6e35cac4fe2306307372f7b4647a7a620d86cf8
// - Fixed wrong method name in README.md; https://github.com/r3code/d7zip/commit/b7f067436b1259177603cf0cc6e64a80bceaa68e
// - Show better error message when 7z.dll can not be loaded, by ekot1; https://github.com/ekot1/d7zip/commit/4facb0ef8b190c129d494c9237337918b3dbeece
// - Changes to match propids from 7z.dll v16.04, by ekot1 (this also adds new format GUIDs); https://github.com/ekot1/d7zip/commit/149de16032fe461796857e5eee22c70858cdb4b9
// - Readme: The source version was actually 1.2 from 2011, and not 1.1 from 2009; https://github.com/danielmarschall/d7zip/commit/18cd6d2e20e755f8a261a9195dd9aadb12ae59d0
// - Fixed: The method in IOutStreamFinish is called OutStreamFinish, not Flush!
// - Updated interface definitions (Cardinal=>UInt32, Int64 sometimes UInt32, etc.); partially added missing interfaces from the 7zip source headers
// - Extended own interfaces to support 64 bit file sizes: https://github.com/wang80919/d7zip/commit/b89d4d7a2bc26928a3e8a1de896feac1a79706ce
// and removed GUIDs because the signatures changed and we don't need COM interoperability for our interfaces
// - Added GetItemCompressedSize
// - Added LZMA2 to 7z methods (not tested)
// TODO: Possible changes to look closer at...
// - Add SetProgressCallbackEx method to allow use of anonymous methods as callbacks; https://github.com/ekot1/d7zip/commit/d850b85a05dd58ad6ded2823a635ab28b8cb62ca
// - Add SetProgressExceptCallback https://github.com/wang80919/d7zip/commit/626ad160001bb62671c959e43d052bea5047e950
// - Add packages and add namespace to unit; https://github.com/grandchef/d7zip/commit/b043af03cd22729be5c3515e27dfba402d0251f5#diff-3eea9649c6b570534a69a6f393cf9e7e7382bf9b8e6812a687d916d575237e02
// - Compatible with POSIX: https://github.com/zedalaye/d7zip/commit/7163f9f743c32c5b89e8f7f496ee960c46c4136d
// But this is complex, because we have things like FFileTime, TPropVariant, etc.!
unit sevenzip;
{$ALIGN ON}
{$MINENUMSIZE 4}
{$WARN SYMBOL_PLATFORM OFF}
interface
uses SysUtils, Windows, ActiveX, Classes, Contnrs, IOUtils, Math;
type
PInt32 = ^Int32;
PVarType = ^TVarType;
PCardArray = ^TCardArray;
TCardArray = array[0..MaxInt div SizeOf(Cardinal) - 1] of Cardinal;
{$IFNDEF UNICODE}
UnicodeString = WideString;
{$ENDIF}
{$REGION 'PropID.h'}
//******************************************************************************
// PropID.h
// (Last checked 14 May 2024; https://github.com/mcmilk/7-Zip/blob/master/CPP/7zip/PropID.h)
//******************************************************************************
const
kpidNoProperty = 0;
kpidMainSubfile = 1;
kpidHandlerItemIndex = 2;
kpidPath = 3; // VT_BSTR
kpidName = 4; // VT_BSTR
kpidExtension = 5; // VT_BSTR
kpidIsDir = 6; // VT_BOOL
kpidSize = 7; // VT_UI8
kpidPackSize = 8; // VT_UI8
kpidAttributes = 9; // VT_UI4
kpidCreationTime = 10; // VT_FILETIME
kpidLastAccessTime = 11; // VT_FILETIME
kpidLastWriteTime = 12; // VT_FILETIME
kpidSolid = 13; // VT_BOOL
kpidCommented = 14; // VT_BOOL
kpidEncrypted = 15; // VT_BOOL
kpidSplitBefore = 16; // VT_BOOL
kpidSplitAfter = 17; // VT_BOOL
kpidDictionarySize = 18; // VT_UI4
kpidCRC = 19; // VT_UI4
kpidType = 20; // VT_BSTR
kpidIsAnti = 21; // VT_BOOL
kpidMethod = 22; // VT_BSTR
kpidHostOS = 23; // VT_BSTR
kpidFileSystem = 24; // VT_BSTR
kpidUser = 25; // VT_BSTR
kpidGroup = 26; // VT_BSTR
kpidBlock = 27; // VT_UI4
kpidComment = 28; // VT_BSTR
kpidPosition = 29; // VT_UI4
kpidPrefix = 30; // VT_BSTR
kpidNumSubDirs = 31; // VT_UI4
kpidNumSubFiles = 32; // VT_UI4
kpidUnpackVer = 33; // VT_UI1
kpidVolume = 34; // VT_UI4
kpidIsVolume = 35; // VT_BOOL
kpidOffset = 36; // VT_UI8
kpidLinks = 37; // VT_UI4
kpidNumBlocks = 38; // VT_UI4
kpidNumVolumes = 39; // VT_UI4
kpidTimeType = 40; // VT_UI4
kpidBit64 = 41; // VT_BOOL
kpidBigEndian = 42; // VT_BOOL
kpidCpu = 43; // VT_BSTR
kpidPhySize = 44; // VT_UI8
kpidHeadersSize = 45; // VT_UI8
kpidChecksum = 46; // VT_UI4
kpidCharacts = 47; // VT_BSTR
kpidVa = 48; // VT_UI8
kpidId = 49;
kpidShortName = 50;
kpidCreatorApp = 51;
kpidSectorSize = 52;
kpidPosixAttrib = 53;
kpidSymLink = 54;
kpidError = 55;
kpidTotalSize = 56;
kpidFreeSpace = 57;
kpidClusterSize = 58;
kpidVolumeName = 59;
kpidLocalName = 60;
kpidProvider = 61;
kpidNtSecure = 62;
kpidIsAltStream = 63;
kpidIsAux = 64;
kpidIsDeleted = 65;
kpidIsTree = 66;
kpidSha1 = 67;
kpidSha256 = 68;
kpidErrorType = 69;
kpidNumErrors = 70;
kpidErrorFlags = 71;
kpidWarningFlags = 72;
kpidWarning = 73;
kpidNumStreams = 74;
kpidNumAltStreams = 75;
kpidAltStreamsSize = 76;
kpidVirtualSize = 77;
kpidUnpackSize = 78;
kpidTotalPhySize = 79;
kpidVolumeIndex = 80;
kpidSubType = 81;
kpidShortComment = 82;
kpidCodePage = 83;
kpidIsNotArcType = 84;
kpidPhySizeCantBeDetected = 85;
kpidZerosTailIsAllowed = 86;
kpidTailSize = 87;
kpidEmbeddedStubSize = 88;
kpidNtReparse = 89;
kpidHardLink = 90;
kpidINode = 91;
kpidStreamId = 92;
kpidReadOnly = 93;
kpidOutName = 94;
kpidCopyLink = 95;
kpidArcFileName = 96;
kpidIsHash = 97;
kpidChangeTime = 98;
kpidUserId = 99;
kpidGroupId =100;
kpidDeviceMajor =101;
kpidDeviceMinor =102;
kpidDevMajor =103;
kpidDevMinor =104;
kpidUserDefined = $10000;
{$ENDREGION}
{$REGION 'IProgress.h interfaces ("23170F69-40C1-278A-0000-000000xx0000")'}
//******************************************************************************
// IProgress.h
// (Last checked 14 May 2024; https://github.com/mcmilk/7-Zip/blob/master/CPP/7zip/IProgress.h)
//******************************************************************************
type
IProgress = interface(IUnknown)
['{23170F69-40C1-278A-0000-000000050000}']
function SetTotal(total: UInt64): HRESULT; stdcall;
function SetCompleted(completeValue: PUInt64): HRESULT; stdcall;
end;
{$ENDREGION}
{$REGION 'IFolderArchive.h interfaces ("23170F69-40C1-278A-0000-000100xx0000") - not implemented'}
// not implemented
// https://github.com/mcmilk/7-Zip/blob/master/CPP/7zip/UI/Agent/IFolderArchive.h
{$ENDREGION}
{$REGION 'IFolder.h interfaces ("23170F69-40C1-278A-0000-000800xx0000") - not implemented'}
// not implemented
// https://github.com/mcmilk/7-Zip/blob/master/CPP/7zip/UI/FileManager/IFolder.h
{$ENDREGION}
{$REGION 'IFolder.h FOLDER_MANAGER_INTERFACE ("23170F69-40C1-278A-0000-000900xx0000") - not implemented'}
// not implemented
// https://github.com/mcmilk/7-Zip/blob/master/CPP/7zip/UI/FileManager/IFolder.h
{$ENDREGION}
{$REGION 'PluginInterface.h interfaces ("23170F69-40C1-278A-0000-000A00xx0000") - not implemented'}
// not implemented
// https://github.com/mcmilk/7-Zip/blob/master/CPP/7zip/UI/FileManager/PluginInterface.h
{$ENDREGION}
{$REGION 'IPassword.h interfaces ("23170F69-40C1-278A-0000-000500xx0000")'}
//******************************************************************************
// IPassword.h
// (Last checked 14 May 2024; https://github.com/mcmilk/7-Zip/blob/master/CPP/7zip/IPassword.h)
//******************************************************************************
ICryptoGetTextPassword = interface(IUnknown)
['{23170F69-40C1-278A-0000-000500100000}']
function CryptoGetTextPassword(var password: TBStr): HRESULT; stdcall;
(*
How to use output parameter (BSTR *password):
in: The caller is required to set BSTR value as NULL (no string).
The callee (in 7-Zip code) ignores the input value stored in BSTR variable,
out: The callee rewrites BSTR variable (*password) with new allocated string pointer.
The caller must free BSTR string with function SysFreeString();
*)
end;
ICryptoGetTextPassword2 = interface(IUnknown)
['{23170F69-40C1-278A-0000-000500110000}']
function CryptoGetTextPassword2(passwordIsDefined: PInt32; var password: TBStr): HRESULT; stdcall;
(*
in:
The caller is required to set BSTR value as NULL (no string).
The caller is not required to set (*passwordIsDefined) value.
out:
Return code: != S_OK : error code
Return code: S_OK : success
if (*passwordIsDefined == 1), the variable (*password) contains password string
if (*passwordIsDefined == 0), the password is not defined,
but the callee still could set (*password) to some allocated string, for example, as empty string.
The caller must free BSTR string with function SysFreeString()
*)
end;
{$ENDREGION}
{$REGION 'IStream.h interfaces ("23170F69-40C1-278A-0000-000300xx0000")'}
//******************************************************************************
// IStream.h
// "23170F69-40C1-278A-0000-000300xx0000"
// (Last checked 14 May 2024; https://github.com/mcmilk/7-Zip/blob/master/CPP/7zip/IStream.h)
//******************************************************************************
ISequentialInStream = interface(IUnknown)
['{23170F69-40C1-278A-0000-000300010000}']
function Read(data: Pointer; size: UInt32; processedSize: PUInt32): HRESULT; stdcall;
(*
The requirement for caller: (processedSize != NULL).
The callee can allow (processedSize == NULL) for compatibility reasons.
if (size == 0), this function returns S_OK and (*processedSize) is set to 0.
if (size != 0)
{
Partial read is allowed: (*processedSize <= avail_size && *processedSize <= size),
where (avail_size) is the size of remaining bytes in stream.
If (avail_size != 0), this function must read at least 1 byte: (*processedSize > 0).
You must call Read() in loop, if you need to read exact amount of data.
}
If seek pointer before Read() call was changed to position past the end of stream:
if (seek_pointer >= stream_size), this function returns S_OK and (*processedSize) is set to 0.
ERROR CASES:
If the function returns error code, then (*processedSize) is size of
data written to (data) buffer (it can be data before error or data with errors).
The recommended way for callee to work with reading errors:
1) write part of data before error to (data) buffer and return S_OK.
2) return error code for further calls of Read().
*)
end;
ISequentialOutStream = interface(IUnknown)
['{23170F69-40C1-278A-0000-000300020000}']
function Write(data: Pointer; size: UInt32; processedSize: PUint32): HRESULT; stdcall;
(*
The requirement for caller: (processedSize != NULL).
The callee can allow (processedSize == NULL) for compatibility reasons.
if (size != 0)
{
Partial write is allowed: (*processedSize <= size),
but this function must write at least 1 byte: (*processedSize > 0).
You must call Write() in loop, if you need to write exact amount of data.
}
ERROR CASES:
If the function returns error code, then (*processedSize) is size of
data written from (data) buffer.
*)
end;
IInStream = interface(ISequentialInStream)
['{23170F69-40C1-278A-0000-000300030000}']
function Seek(offset: Int64; seekOrigin: UInt32; newPosition: PUInt64): HRESULT; stdcall;
(*
If you seek to position before the beginning of the stream,
Seek() function returns error code:
Recommended error code is __HRESULT_FROM_WIN32(ERROR_NEGATIVE_SEEK).
or STG_E_INVALIDFUNCTION
It is allowed to seek past the end of the stream.
if Seek() returns error, then the value of *newPosition is undefined.
*)
end;
IOutStream = interface(ISequentialOutStream)
['{23170F69-40C1-278A-0000-000300040000}']
function Seek(offset: Int64; seekOrigin: UInt32; newPosition: PUInt64): HRESULT; stdcall;
function SetSize(newSize: UInt64): HRESULT; stdcall;
end;
IStreamGetSize = interface(IUnknown)
['{23170F69-40C1-278A-0000-000300060000}']
function GetSize(size: PUInt64): HRESULT; stdcall;
end;
IOutStreamFinish = interface(IUnknown)
['{23170F69-40C1-278A-0000-000300070000}']
function OutStreamFinish: HRESULT; stdcall; // sic! This method is called OutStreamFinish and not Flush!
end;
IStreamGetProps = interface(IUnknown)
['{23170F69-40C1-278A-0000-000300080000}']
function GetProps(size: PUInt64; cTime: PFileTime; aTime: PFileTime;
mTime: PFileTime; attrib: PUInt32): HRESULT; stdcall;
end;
{$ENDREGION}
{$REGION 'IArchive.h interfaces ("23170F69-40C1-278A-0000-000600xx0000")'}
//******************************************************************************
// IArchive.h
// (Last checked 14 May 2024; https://github.com/mcmilk/7-Zip/blob/master/CPP/7zip/Archive/IArchive.h)
//******************************************************************************
// MIDL_INTERFACE("23170F69-40C1-278A-0000-000600xx0000")
//#define ARCHIVE_INTERFACE_SUB(i, base, x) \
//DEFINE_GUID(IID_ ## i, \
//0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x06, 0x00, x, 0x00, 0x00); \
//struct i: public base
//#define ARCHIVE_INTERFACE(i, x) ARCHIVE_INTERFACE_SUB(i, IUnknown, x)
type
// NFileTimeType
NFileTimeType = (
kWindows = 0,
kUnix,
kDOS
);
// NArcInfoFlags
NArcInfoFlags = (
aifKeepName = 1 shl 0, // keep name of file in archive name
aifAltStreams = 1 shl 1, // the handler supports alt streams
aifNtSecure = 1 shl 2, // the handler supports NT security
aifFindSignature = 1 shl 3, // the handler can find start of archive
aifMultiSignature = 1 shl 4, // there are several signatures
aifUseGlobalOffset = 1 shl 5, // the seek position of stream must be set as global offset
aifStartOpen = 1 shl 6, // call handler for each start position
aifPureStartOpen = 1 shl 7, // call handler only for start of file
aifBackwardOpen = 1 shl 8, // archive can be open backward
aifPreArc = 1 shl 9, // such archive can be stored before real archive (like SFX stub)
aifSymLinks = 1 shl 10, // the handler supports symbolic links
aifHardLinks = 1 shl 11 // the handler supports hard links
);
// NArchive::NHandlerPropID
NHandlerPropID = (
kName = 0, // VT_BSTR
kClassID, // binary GUID in VT_BSTR
kExtension, // VT_BSTR
kAddExtension, // VT_BSTR
kUpdate, // VT_BOOL
kKeepName, // VT_BOOL
kSignature, // binary in VT_BSTR
kMultiSignature, // binary in VT_BSTR
kSignatureOffset, // VT_UI4
kAltStreams, // VT_BOOL
kNtSecure, // VT_BOOL
kFlags, // VT_UI4
kTimeFlags // VT_UI4
// kVersion // VT_UI4 ((VER_MAJOR << 8) | VER_MINOR)
);
// NArchive::NExtract::NAskMode
NAskMode = (
kExtract = 0,
kTest,
kSkip,
kReadExternal
);
// NArchive::NExtract::NOperationResult
NExtOperationResult = (
kOK = 0,
kUnSupportedMethod,
kDataError,
kCRCError,
kUnavailable,
kUnexpectedEnd,
kDataAfterEnd,
kIsNotArc,
kHeadersError,
kWrongPassword
// , kMemError
);
// NArchive::NEventIndexType
NEventIndexType = (
kNoIndex = 0,
kInArcIndex,
kBlockIndex,
kOutArcIndex
);
// NArchive::NUpdate::NOperationResult
NUpdOperationResult = (
kOK_ = 0,
kError
//,kError_FileChanged
);
IArchiveOpenCallback = interface
['{23170F69-40C1-278A-0000-000600100000}']
function SetTotal(files, bytes: PUInt64): HRESULT; stdcall;
function SetCompleted(files, bytes: PUInt64): HRESULT; stdcall;
(*
IArchiveExtractCallback::
7-Zip doesn't call IArchiveExtractCallback functions
GetStream()
PrepareOperation()
SetOperationResult()
from different threads simultaneously.
But 7-Zip can call functions for IProgress or ICompressProgressInfo functions
from another threads simultaneously with calls for IArchiveExtractCallback interface.
IArchiveExtractCallback::GetStream()
UInt32 index - index of item in Archive
Int32 askExtractMode (Extract::NAskMode)
if (askMode != NExtract::NAskMode::kExtract)
{
then the callee can not real stream: (*inStream == NULL)
}
Out:
(*inStream == NULL) - for directories
(*inStream == NULL) - if link (hard link or symbolic link) was created
if (*inStream == NULL && askMode == NExtract::NAskMode::kExtract)
{
then the caller must skip extracting of that file.
}
returns:
S_OK : OK
S_FALSE : data error (for decoders)
if (IProgress::SetTotal() was called)
{
IProgress::SetCompleted(completeValue) uses
packSize - for some stream formats (xz, gz, bz2, lzma, z, ppmd).
unpackSize - for another formats.
}
else
{
IProgress::SetCompleted(completeValue) uses packSize.
}
SetOperationResult()
7-Zip calls SetOperationResult at the end of extracting,
so the callee can close the file, set attributes, timestamps and security information.
Int32 opRes (NExtract::NOperationResult)
*)
end;
IArchiveExtractCallback = interface(IProgress)
['{23170F69-40C1-278A-0000-000600200000}']
function GetStream(index: UInt32; var outStream: ISequentialOutStream;
askExtractMode: NAskMode): HRESULT; stdcall;
// GetStream OUT: S_OK - OK, S_FALSE - skeep this file
function PrepareOperation(askExtractMode: NAskMode): HRESULT; stdcall;
function SetOperationResult(resultEOperationResult: NExtOperationResult): HRESULT; stdcall;
(*
IArchiveExtractCallbackMessage can be requested from IArchiveExtractCallback object
by Extract() or UpdateItems() functions to report about extracting errors
ReportExtractResult()
UInt32 indexType (NEventIndexType)
UInt32 index
Int32 opRes (NExtract::NOperationResult)
*)
end;
// before v23:
IArchiveExtractCallbackMessage = interface
['{23170F69-40C1-278A-0000-000600210000}']
function ReportExtractResult(indexType: NEventIndexType; index: UInt32; opRes: Int32): HRESULT; stdcall;
end;
IArchiveExtractCallbackMessage2 = interface
['{23170F69-40C1-278A-0000-000600220000}']
// IArchiveExtractCallbackMessage2 can be requested from IArchiveExtractCallback object by Extract() or UpdateItems() functions to report about extracting errors
function ReportExtractResult(indexType: NEventIndexType; index: UInt32; opRes: Int32): HRESULT; stdcall;
end;
IArchiveOpenVolumeCallback = interface
['{23170F69-40C1-278A-0000-000600300000}']
function GetProperty(propID: PROPID; var value: OleVariant): HRESULT; stdcall;
function GetStream(const name: PWideChar; var inStream: IInStream): HRESULT; stdcall;
end;
IInArchiveGetStream = interface
['{23170F69-40C1-278A-0000-000600400000}']
function GetStream(index: UInt32; var stream: ISequentialInStream ): HRESULT; stdcall;
end;
IArchiveOpenSetSubArchiveName = interface
['{23170F69-40C1-278A-0000-000600500000}']
function SetSubArchiveName(name: PWideChar): HRESULT; stdcall;
end;
IInArchive = interface
['{23170F69-40C1-278A-0000-000600600000}']
function Open(stream: IInStream; const maxCheckStartPosition: PInt64;
openArchiveCallback: IArchiveOpenCallback): HRESULT; stdcall;
(*
IInArchive::Open
stream
if (kUseGlobalOffset), stream current position can be non 0.
if (!kUseGlobalOffset), stream current position is 0.
if (maxCheckStartPosition == NULL), the handler can try to search archive start in stream
if (*maxCheckStartPosition == 0), the handler must check only current position as archive start
IInArchive::Extract:
indices must be sorted
numItems = (UInt32)(Int32)-1 = 0xFFFFFFFF means "all files"
testMode != 0 means "test files without writing to outStream"
IInArchive::GetArchiveProperty:
kpidOffset - start offset of archive.
VT_EMPTY : means offset = 0.
VT_UI4, VT_UI8, VT_I8 : result offset; negative values is allowed
kpidPhySize - size of archive. VT_EMPTY means unknown size.
kpidPhySize is allowed to be larger than file size. In that case it must show
supposed size.
kpidIsDeleted:
kpidIsAltStream:
kpidIsAux:
kpidINode:
must return VARIANT_TRUE (VT_BOOL), if archive can support that property in GetProperty.
Notes:
Don't call IInArchive functions for same IInArchive object from different threads simultaneously.
Some IInArchive handlers will work incorrectly in that case.
*)
function Close: HRESULT; stdcall;
function GetNumberOfItems(var numItems: UInt32): HRESULT; stdcall;
function GetProperty(index: UInt32; propID: PROPID; var value: OleVariant): HRESULT; stdcall;
function Extract(indices: PCardArray; numItems: UInt32;
testMode: Integer; extractCallback: IArchiveExtractCallback): HRESULT; stdcall;
// indices must be sorted
// numItems = 0xFFFFFFFF means all files
// testMode != 0 means "test files operation"
function GetArchiveProperty(propID: PROPID; var value: OleVariant): HRESULT; stdcall;
function GetNumberOfProperties(numProps: PUInt32): HRESULT; stdcall;
function GetPropertyInfo(index: UInt32;
name: PBSTR; propID: PPropID; varType: PVarType): HRESULT; stdcall;
function GetNumberOfArchiveProperties(var numProps: UInt32): HRESULT; stdcall;
function GetArchivePropertyInfo(index: UInt32;
name: PBSTR; propID: PPropID; varType: PVARTYPE): HRESULT; stdcall;
end;
IArchiveOpenSeq = interface
['{23170F69-40C1-278A-0000-000600610000}']
function OpenSeq(var stream: ISequentialInStream): HRESULT; stdcall;
end;
(*
IArchiveOpen2 = interface
['{23170F69-40C1-278A-0000-000600620000}']
function ArcOpen2(ISequentialInStream *stream, UInt32 flags, IArchiveOpenCallback *openCallback): HRESULT; stdcall;
end;
*)
// NParentType::
NParentType = (
kDir = 0,
kAltStream
);
// NPropDataType::
NPropDataType = (
kMask_ZeroEnd = $10, // 1 shl 4,
// kMask_BigEndian = 1 shl 5,
kMask_Utf = $40, // 1 shl 6,
kMask_Utf8 = $40, // kMask_Utf or 0,
kMask_Utf16 = $41, // kMask_Utf or 1,
// kMask_Utf32 = $42, // kMask_Utf or 2,
kNotDefined = 0,
kRaw = 1,
kUtf8z = $50, // kMask_Utf8 or kMask_ZeroEnd,
kUtf16z = $51 // kMask_Utf16 or kMask_ZeroEnd
);
// NUpdateNotifyOp::
{
NUpdateNotifyOp = (
kAdd,
kUpdate,
kAnalyze,
kReplicate,
kRepack,
kSkip,
kDelete,
kHeader,
kHashRead,
kInFileChanged
// , kOpFinished
// , kNumDefined
);
}
IArchiveGetRawProps = interface
['{23170F69-40C1-278A-0000-000600700000}']
function GetParent(index: UInt32; var parent: UInt32; var parentType: UInt32): HRESULT; stdcall;
function GetRawProp(index: UInt32; propID: PROPID; var data: Pointer; var dataSize: UInt32; var propType: UInt32): HRESULT; stdcall;
function GetNumRawProps(var numProps: UInt32): HRESULT; stdcall;
function GetRawPropInfo(index: UInt32; name: PBSTR; var propID: PROPID): HRESULT; stdcall;
end;
IArchiveGetRootProps = interface
['{23170F69-40C1-278A-0000-000600710000}']
function GetRootProp(propID: PROPID; var value: PROPVARIANT): HRESULT; stdcall;
function GetRootRawProp(propID: PROPID; var data: Pointer; var dataSize: UINT32; var propType: UInt32): HRESULT; stdcall;
end;
IArchiveUpdateCallback = interface(IProgress)
['{23170F69-40C1-278A-0000-000600800000}']
function GetUpdateItemInfo(index: UInt32;
newData: PInt32; // 1 - new data, 0 - old data
newProps: PInt32; // 1 - new properties, 0 - old properties
indexInArchive: PUInt32 // -1 if there is no in archive, or if doesn't matter
): HRESULT; stdcall;
function GetProperty(index: UInt32; propID: PROPID; var value: OleVariant): HRESULT; stdcall;
function GetStream(index: UInt32; var inStream: ISequentialInStream): HRESULT; stdcall;
function SetOperationResult(operationResult: Int32): HRESULT; stdcall;
end;
IArchiveUpdateCallback2 = interface(IArchiveUpdateCallback)
['{23170F69-40C1-278A-0000-000600820000}']
function GetVolumeSize(index: UInt32; size: PUInt64): HRESULT; stdcall;
function GetVolumeStream(index: UInt32; var volumeStream: ISequentialOutStream): HRESULT; stdcall;
end;
(*
IArchiveUpdateCallbackFile = interface
['{23170F69-40C1-278A-0000-000600830000}']
function GetStream2(UInt32 index, ISequentialInStream **inStream, UInt32 notifyOp)): HRESULT; stdcall;
function ReportOperation(UInt32 indexType, UInt32 index, UInt32 notifyOp)): HRESULT; stdcall;
end;
IArchiveGetDiskProperty = interface
['{23170F69-40C1-278A-0000-000600840000}']
function GetDiskProperty(UInt32 index, PROPID propID, PROPVARIANT *value)): HRESULT; stdcall;
end;
IArchiveUpdateCallbackArcProp = interface
['{23170F69-40C1-278A-0000-000600850000}']
function ReportProp(UInt32 indexType, UInt32 index, PROPID propID, const PROPVARIANT *value)): HRESULT; stdcall;
function ReportRawProp(UInt32 indexType, UInt32 index, PROPID propID, const void *data, UInt32 dataSize, UInt32 propType)): HRESULT; stdcall;
function ReportFinished(UInt32 indexType, UInt32 index, Int32 opRes)): HRESULT; stdcall;
function DoNeedArcProp(PROPID propID, Int32 *answer)): HRESULT; stdcall;
end;
*)
IOutArchive = interface
['{23170F69-40C1-278A-0000-000600A00000}']
function UpdateItems(outStream: ISequentialOutStream; numItems: UInt32;
updateCallback: IArchiveUpdateCallback): HRESULT; stdcall;
function GetFileTimeType(type_: PUint32): HRESULT; stdcall;
end;
ISetProperties = interface
['{23170F69-40C1-278A-0000-000600030000}']
function SetProperties(names: PPWideChar; values: PPROPVARIANT; numProps: UInt32): HRESULT; stdcall;
end;
IArchiveKeepModeForNextOpen = interface
['{23170F69-40C1-278A-0000-000600040000}']
function KeepModeForNextOpen: HRESULT; stdcall;
end;
IArchiveAllowTail = interface
['{23170F69-40C1-278A-0000-000600050000}']
function AllowTail(allowTail: Int32): HRESULT; stdcall;
end;
{$ENDREGION}
{$REGION 'ICoder.h interfaces ("23170F69-40C1-278A-0000-000400xx0000")'}
//******************************************************************************
// ICoder.h
// "23170F69-40C1-278A-0000-000400xx0000"
// (Last checked 14 May 2024; https://github.com/mcmilk/7-Zip/blob/master/CPP/7zip/ICoder.h)
//******************************************************************************
ICompressProgressInfo = interface
['{23170F69-40C1-278A-0000-000400040000}']
function SetRatioInfo(inSize, outSize: PUInt64): HRESULT; stdcall;
end;
ICompressCoder = interface
['{23170F69-40C1-278A-0000-000400050000}']
function Code(inStream, outStream: ISequentialInStream;
inSize, outSize: PUInt64;
progress: ICompressProgressInfo): HRESULT; stdcall;
end;
ICompressCoder2 = interface
['{23170F69-40C1-278A-0000-000400180000}']
function Code(var inStreams: ISequentialInStream;
var inSizes: PUInt64;
numInStreams: UInt32;
var outStreams: ISequentialOutStream;
var outSizes: PUInt64;
numOutStreams: UInt32;
progress: ICompressProgressInfo): HRESULT; stdcall;
end;
//NCoderPropID::
NCoderPropID = (
kDefaultProp = 0,
kDictionarySize,
kUsedMemorySize,
kOrder,
kBlockSize,
kPosStateBits,
kLitContextBits,
kLitPosBits,
kNumFastBytes,
kMatchFinder,
kMatchFinderCycles,
kNumPasses,
kAlgorithm,
kNumThreads,
kEndMarker,
kLevel,
kReduceSize // estimated size of data that will be compressed. Encoder can use this value to reduce dictionary size.
);
type
ICompressSetCoderPropertiesOpt = interface
['{23170F69-40C1-278A-0000-0004001F0000}']
function SetCoderPropertiesOpt(propIDs: PPropID; props: PROPVARIANT; numProps: UInt32): HRESULT; stdcall;
end;
ICompressSetCoderProperties = interface
['{23170F69-40C1-278A-0000-000400200000}']
function SetCoderProperties(propIDs: PPropID; props: PROPVARIANT; numProps: UInt32): HRESULT; stdcall;
end;
// name conflict?! Is commented out in https://github.com/keithjjones/7z/blob/master/CPP/7zip/ICoder.h
(*
ICompressSetCoderProperties = interface
['{23170F69-40C1-278A-0000-000400210000}']
procedure SetDecoderProperties(inStream: ISequentialInStream);
end;
*)
ICompressSetDecoderProperties2 = interface
['{23170F69-40C1-278A-0000-000400220000}']
function SetDecoderProperties2(data: PByte; size: UInt32): HRESULT; stdcall;
(*
S_OK
E_NOTIMP : unsupported properties
E_INVALIDARG : incorrect (or unsupported) properties
E_OUTOFMEMORY : memory allocation error
*)
end;
ICompressWriteCoderProperties = interface
['{23170F69-40C1-278A-0000-000400230000}']
function WriteCoderProperties(outStreams: ISequentialOutStream): HRESULT; stdcall;
end;
ICompressGetInStreamProcessedSize = interface
['{23170F69-40C1-278A-0000-000400240000}']
function GetInStreamProcessedSize(value: PUInt64): HRESULT; stdcall;
end;
ICompressSetCoderMt = interface
['{23170F69-40C1-278A-0000-000400250000}']
function SetNumberOfThreads(numThreads: UInt32): HRESULT; stdcall;
end;
ICompressSetFinishMode = interface
['{23170F69-40C1-278A-0000-000400260000}']
function SetFinishMode(finishMode: UInt32): HRESULT; stdcall;
(* finishMode:
0 : partial decoding is allowed. It's default mode for ICompressCoder::Code(), if (outSize) is defined.
1 : full decoding. The stream must be finished at the end of decoding.
*)
end;
ICompressGetInStreamProcessedSize2 = interface
['{23170F69-40C1-278A-0000-000400270000}']
function GetInStreamProcessedSize2(streamIndex: UInt32; value: PUInt64): HRESULT; stdcall;
end;
ICompressSetMemLimit = interface
['{23170F69-40C1-278A-0000-000400280000}']
function SetMemLimit(memUsage: UInt64): HRESULT; stdcall;
end;
ICompressReadUnusedFromInBuf = interface
['{23170F69-40C1-278A-0000-000400290000}']
function ReadUnusedFromInBuf(data: Pointer; size: UInt32; processedSize: PUInt32): HRESULT; stdcall;
(*
ICompressReadUnusedFromInBuf is supported by ICoder object
call ReadUnusedFromInBuf() after ICoder::Code(inStream, ...).
ICoder::Code(inStream, ...) decodes data, and the ICoder object is allowed
to read from inStream to internal buffers more data than minimal data required for decoding.
So we can call ReadUnusedFromInBuf() from same ICoder object to read unused input
data from the internal buffer.
in ReadUnusedFromInBuf(): the Coder is not allowed to use (ISequentialInStream *inStream) object, that was sent to ICoder::Code().
*)
end;
ICompressGetSubStreamSize = interface
['{23170F69-40C1-278A-0000-000400300000}']
function GetSubStreamSize(subStream: UInt64; value: PUInt64): HRESULT; stdcall;
end;
ICompressSetInStream = interface
['{23170F69-40C1-278A-0000-000400310000}']
function SetInStream(inStream: ISequentialInStream): HRESULT; stdcall;
function ReleaseInStream: HRESULT; stdcall;
end;
ICompressSetOutStream = interface
['{23170F69-40C1-278A-0000-000400320000}']
function SetOutStream(outStream: ISequentialOutStream): HRESULT; stdcall;
function ReleaseOutStream: HRESULT; stdcall;
end;
ICompressSetInStreamSize = interface
['{23170F69-40C1-278A-0000-000400330000}']
function SetInStreamSize(inSize: PUInt64): HRESULT; stdcall;
end;
ICompressSetOutStreamSize = interface
['{23170F69-40C1-278A-0000-000400340000}']
function SetOutStreamSize(outSize: PUInt64): HRESULT; stdcall;
end;
ICompressSetBufSize = interface
['{23170F69-40C1-278A-0000-000400350000}']
function SetInBufSize(streamIndex: UInt32; size: UInt32): HRESULT; stdcall;
function SetOutBufSize(streamIndex: UInt32; size: UInt32): HRESULT; stdcall;
end;
ICompressInitEncoder = interface
['{23170F69-40C1-278A-0000-000400360000}']
function InitEncoder: HRESULT; stdcall;
(*
That function initializes encoder structures.
Call this function only for stream version of encoder.
*)
end;
ICompressSetInStream2 = interface
['{23170F69-40C1-278A-0000-000400370000}']
function SetInStream2(streamIndex: UInt32; inStream: ISequentialInStream): HRESULT; stdcall;
function ReleaseInStream2(streamIndex: UInt32): HRESULT; stdcall;
end;
ICompressSetOutStream2 = interface
['{23170F69-40C1-278A-0000-000400380000}']
function SetOutStream2(streamIndex: UInt32; outStream: ISequentialOutStream): HRESULT; stdcall;
function ReleaseOutStream2(streamIndex: UInt32): HRESULT; stdcall;
end;
ICompressSetInStreamSize2 = interface
['{23170F69-40C1-278A-0000-000400390000}']
function SetInStreamSize2(streamIndex: UInt32; inSize: PUInt64): HRESULT; stdcall;
end;
ICompressInSubStreams = interface
['{23170F69-40C1-278A-0000-0004003A0000}']
function GetNextInSubStream(streamIndexRes: PUInt64; var stream: ISequentialInStream): HRESULT; stdcall;
end;
ICompressOutSubStreams = interface
['{23170F69-40C1-278A-0000-0004003B0000}']
function GetNextOutSubStream(streamIndexRes: PUInt64; var stream: ISequentialOutStream): HRESULT; stdcall;
end;
(*
ICompressFilter
Filter(Byte *data, UInt32 size)
(size)
converts as most as possible bytes required for fast processing.
Some filters have (smallest_fast_block).
For example, (smallest_fast_block == 16) for AES CBC/CTR filters.
If data stream is not finished, caller must call Filter() for larger block:
where (size >= smallest_fast_block).
if (size >= smallest_fast_block)
{
The filter can leave some bytes at the end of data without conversion:
if there are data alignment reasons or speed reasons.
The caller can read additional data from stream and call Filter() again.
}
If data stream was finished, caller can call Filter() for (size < smallest_fast_block)
(data) parameter:
Some filters require alignment for any Filter() call:
1) (stream_offset % alignment_size) == (data % alignment_size)
2) (alignment_size == 2^N)
where (stream_offset) - is the number of bytes that were already filtered before.
The callers of Filter() are required to meet these requirements.
(alignment_size) can be different:
16 : for AES filters
4 or 2 : for some branch convert filters
1 : for another filters
(alignment_size >= 16) is enough for all current filters of 7-Zip.
But the caller can use larger (alignment_size).
Recommended alignment for (data) of Filter() call is (alignment_size == 64).
Also it's recommended to use aligned value for (size):
(size % alignment_size == 0),
if it's not last call of Filter() for current stream.
returns: (outSize):
if (outSize == 0) : Filter have not converted anything.
So the caller can stop processing, if data stream was finished.
if (outSize <= size) : Filter have converted outSize bytes
if (outSize > size) : Filter have not converted anything.
and it needs at least outSize bytes to convert one block
(it's for crypto block algorithms).
*/
*)
ICompressFilter = interface
['{23170F69-40C1-278A-0000-000400400000}']
function Init: HRESULT; stdcall;
function Filter(data: PByte; size: UInt32): UInt32; stdcall;
// Filter return outSize (UInt32)
// if (outSize <= size): Filter have converted outSize bytes
// if (outSize > size): Filter have not converted anything.
// and it needs at least outSize bytes to convert one block
// (it's for crypto block algorithms).
end;
ICompressCodecsInfo = interface
['{23170F69-40C1-278A-0000-000400600000}']
function GetNumMethods(numMethods: PUInt32): HRESULT; stdcall;
function GetProperty(index: UInt32; propID: PROPID; var value: PROPVARIANT): HRESULT; stdcall;
function CreateDecoder(index: UInt32; const iid: PGUID; var coder: Pointer): HRESULT; stdcall;
function CreateEncoder(index: UInt32; const iid: PGUID; var coder: Pointer): HRESULT; stdcall;
end;
ISetCompressCodecsInfo = interface
['{23170F69-40C1-278A-0000-000400610000}']
function SetCompressCodecsInfo(compressCodecsInfo: ICompressCodecsInfo): HRESULT; stdcall;
end;
ICryptoProperties = interface
['{23170F69-40C1-278A-0000-000400800000}']
function SetKey(Data: PByte; size: UInt32): HRESULT; stdcall;