📄 abziptyp.pas
字号:
(* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1 * * 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. * * The Original Code is TurboPower Abbrevia * * The Initial Developer of the Original Code is * TurboPower Software * * Portions created by the Initial Developer are Copyright (C) 1997-2002 * the Initial Developer. All Rights Reserved. * * Contributor(s): * * ***** END LICENSE BLOCK ***** *){*********************************************************}{* ABBREVIA: AbZipTyp.pas 3.05 *}{*********************************************************}{* ABBREVIA: PKZip types *}{* Based on information from Appnote.txt, shipped with *}{* PKWare's PKZip for Windows 2.5 *}{*********************************************************}{$I AbDefine.inc}unit AbZipTyp;interfaceuses typesarchive, //!! MVC for MMAX_PATH Classes, AbArcTyp, AbUtils, AbSpanSt;const { note #$50 = 'P', #$4B = 'K'} Ab_ZipVersion = 20; Ab_ZipLocalFileHeaderSignature : Longint = $04034B50; Ab_ZipCentralDirectoryFileHeaderSignature : Longint = $02014B50; Ab_ZipCentralDirectoryTailSignature : Longint = $06054B50; Ab_ZipSpannedSetSignature : Longint = $08074B50; Ab_ZipPossiblySpannedSignature : Longint = $30304B50; Ab_GeneralZipSignature : Word = $4B50; {!!.02} Ab_WindowsExeSignature : Word = $5A4D; {!!.02} Ab_LinuxExeSigWord1 : Word = $457F; {!!.02} Ab_LinuxExeSigWord2 : Word = $464C; {!!.02} Ab_iWindowSize = $8000; {Inflate window size} Ab_iMaxCodeLen = 16; {Maximum bit length of any code} Ab_iMaxCodes = 288; {Maximum number of codes in any set} Size32K = 32768; AbDefZipSpanningThreshold = 0; AbDefPasswordRetries = 3; AbFileIsEncryptedFlag = $0001; AbHasDataDescriptorFlag = $0008;var Ab_ZipEndCentralDirectorySignature : Longint = $06054B50;type PAbByteArray4K = ^TAbByteArray4K; TAbByteArray4K = array[1..4096] of Byte; PAbByteArray8K = ^TAbByteArray8K; TAbByteArray8K = array[0..8192] of Byte; PAbIntArray8K = ^TAbIntArray8K; TAbIntArray8K = array[0..8192] of SmallInt; PAbWordArray = ^TAbWordArray; TAbWordArray = array[0..65535 div SizeOf(Word)-1] of Word; PAbByteArray = ^TAbByteArray; TAbByteArray = array[0..65535-1] of Byte; PAbSmallIntArray = ^TAbSmallIntArray; TAbSmallIntArray = array[0..65535 div SizeOf(SmallInt)-1] of SmallInt; PAbIntegerArray = ^TAbIntegerArray; TAbIntegerArray = array[0..65535 div sizeof(integer)-1] of integer; PAbiSlide = ^TAbiSlide; TAbiSlide = array[0..Ab_iWindowSize] of Byte; PPAbHuft = ^PAbHuft; PAbHuft = ^TAbHuft; TAbHuft = packed record ExtraBits : Byte; {Number of extra bits} NumBits : Byte; {Number of bits in this code or subcode} Filler : Word; case Byte of 0: (N : Word); {Literal, length base, or distance base} 1: (NextLevel: PAbHuft); {Pointer to next level of table} end; TAbFollower = {used to expand reduced files} packed record Size : Byte; {size of follower set} FSet : array[0..31] of Byte; {follower set} end; PAbFollowerSets = ^TAbFollowerSets; TAbFollowerSets = array[0..255] of TAbFollower; PAbSfEntry = ^TAbSfEntry; TAbSfEntry = {entry in a Shannon-Fano tree} packed record case Byte of 0 : (Code : Word; Value, BitLength : Byte); 1 : (L : Longint); end; PAbSfTree = ^TAbSfTree; TAbSfTree = packed record {a Shannon-Fano tree} Entries : SmallInt; MaxLength : SmallInt; Entry : array[0..256] of TAbSfEntry; end; PAbWord = ^Word; TAbFCData = packed record case Byte of 0 : (Freq : Word); {frequency count} 1 : (Code : Word); {bit string} end; TAbDLData = packed record case Byte of 0 : (Dad : Word); {father node in Huffman tree} 1 : (Len : Word); {length of bit string} end; {Data structure describing a single value and its code string} TAbCTData = packed record FC : TAbFCData; Filler : word; DL : TAbDLData; end; PAbCTDataArray = ^TAbCTDataArray; TAbCTDataArray = array[0..65535 div SizeOf(TAbCTData) - 1] of TAbCTData; TAbTreeDescription = packed record DynamicTree : PAbCTDataArray; {the dynamic tree} StaticTree : PAbCTDataArray; {corresponding static tree or NULL} ExtraBits : PAbWordArray; {extra bits for each code or NULL} ExtraBase : SmallInt; {base index for ExtraBits} MaxElements : SmallInt; {max number of elements in the tree} MaxLength : SmallInt; {max bit length for the codes} MaxCode : SmallInt; {largest code with non zero frequency} end;type TAbFileType = (Binary, Ascii, Unknown); TAbZipCompressionMethod = (cmStored, cmShrunk, cmReduced1, cmReduced2, cmReduced3, cmReduced4, cmImploded, cmTokenized, cmDeflated, cmEnhancedDeflated, cmDCLImploded, cmBestMethod); TAbZipSupportedMethod = (smStored, smDeflated, smBestMethod); TAbZipHostOS = (hosDOS, hosAmiga, hosVAX, hosUnix, hosVMCMS, hosAtari, hosOS2, hosMacintosh, hosZSystem, hosCPM, hosNTFS); {for method 6 - imploding} TAbZipDictionarySize = (dsInvalid, ds4K, ds8K); {for method 8 - deflating} TAbZipDeflationOption = (doInvalid, doNormal, doMaximum, doFast, doSuperFast );type TAbNeedPasswordEvent = procedure(Sender : TObject; var NewPassword : string) of object;const AbDefCompressionMethodToUse = smBestMethod; AbDefDeflationOption = doNormal;type TAbZipDataDescriptor = class( TObject ) protected {private} FCRC32 : Longint; FCompressedSize : Longint; FUncompressedSize : Longint; public {methods} procedure LoadFromStream( Stream : TStream ); procedure SaveToStream( Stream : TStream ); public {properties} property CRC32 : Longint read FCRC32 write FCRC32; property CompressedSize : Longint read FCompressedSize write FCompressedSize; property UncompressedSize : Longint read FUncompressedSize write FUncompressedSize; end;type{ TAbZipFileHeader interface =============================================== } {ancestor class for ZipLocalFileHeader and DirectoryFileHeader} TAbZipFileHeader = class( TObject ) protected {private} FValidSignature : Longint; FSignature : Longint; FVersionNeededToExtract : Word; FGeneralPurposeBitFlag : Word; FCompressionMethod : Word; FLastModFileTime : Word; FLastModFileDate : Word; FCRC32 : Longint; FCompressedSize : Longint; FUncompressedSize : Longint; FFileNameLength : Word; FExtraFieldLength : Word; FFileName : PChar; FExtraField : PChar; FIsValid : Boolean; protected {methods} function GetCompressionMethod : TAbZipCompressionMethod; function GetCompressionRatio : Double; function GetDataDescriptor : Boolean; function GetDeflationOption : TAbZipDeflationOption; function GetDictionarySize : TAbZipDictionarySize; function GetEncrypted : Boolean; function GetShannonFanoTreeCount : Byte; function GetValid : Boolean; procedure SetCompressionMethod( Value : TAbZipCompressionMethod ); procedure SetExtraField( Value : PChar ); procedure SetFileName( Value : PChar ); public {methods} constructor Create; destructor Destroy; override; public {properties} property Signature : Longint read FSignature write FSignature; property VersionNeededToExtract : Word read FVersionNeededToExtract write FVersionNeededToExtract; property GeneralPurposeBitFlag : Word read FGeneralPurposeBitFlag write FGeneralPurposeBitFlag; property CompressionMethod : TAbZipCompressionMethod read GetCompressionMethod write SetCompressionMethod; property LastModFileTime : Word read FLastModFileTime write FLastModFileTime; property LastModFileDate : Word read FLastModFileDate write FLastModFileDate; property CRC32 : Longint read FCRC32 write FCRC32; property CompressedSize : Longint read FCompressedSize write FCompressedSize; property UncompressedSize : Longint read FUncompressedSize write FUncompressedSize; property FileNameLength : Word read FFileNameLength write FFileNameLength; property ExtraFieldLength : Word read FExtraFieldLength write FExtraFieldLength; property FileName : PChar read FFileName write SetFileName; property ExtraField : PChar read FExtraField write SetExtraField; property CompressionRatio : Double read GetCompressionRatio; property DeflationOption : TAbZipDeflationOption read GetDeflationOption; property DictionarySize : TAbZipDictionarySize read GetDictionarySize; property HasDataDescriptor : Boolean read GetDataDescriptor; property IsValid : Boolean read GetValid; property IsEncrypted : Boolean read GetEncrypted; property ShannonFanoTreeCount : Byte read GetShannonFanoTreeCount; end;{ TAbZipLocalFileHeader interface ========================================== } TAbZipLocalFileHeader = class( TAbZipFileHeader ) public {methods} constructor Create; destructor Destroy; override; procedure LoadFromStream( Stream : TStream ); procedure SaveToStream( Stream : TStream ); end;{ TAbZipDirectoryFileHeader interface ====================================== } TAbZipDirectoryFileHeader = class( TAbZipFileHeader ) protected {private} FVersionMadeBy : Word; FFileCommentLength : Word; FDiskNumberStart : Word; FInternalFileAttributes : Word; FExternalFileAttributes : Longint; FRelativeOffset : Longint; FFileComment : PChar; public {methods} constructor Create; destructor Destroy; override; procedure LoadFromStream( Stream : TStream ); procedure SaveToStream( Stream : TStream ); public {properties} property VersionMadeBy : Word read FVersionMadeBy write FVersionMadeBy; property FileCommentLength : Word read FFileCommentLength write FFileCommentLength; property DiskNumberStart : Word read FDiskNumberStart write FDiskNumberStart; property InternalFileAttributes : Word read FInternalFileAttributes write FInternalFileAttributes; property ExternalFileAttributes : Longint read FExternalFileAttributes write FExternalFileAttributes; property RelativeOffset : Longint read FRelativeOffset write FRelativeOffset; property FileComment : PChar read FFileComment write FFileComment; end;{ TAbZipDirectoryFileFooter interface ====================================== } TAbZipDirectoryFileFooter = class( TObject ) protected {private} FValidSignature : Longint; FSignature : Longint; FDiskNumber : Word; FStartDiskNumber : Word; FEntriesOnDisk : Word; FTotalEntries : Word; FDirectorySize : Longint; FDirectoryOffset : Longint; FZipfileCommentLength : Word; FZipFileComment : PChar; function GetValid : Boolean; public {methods} constructor Create; destructor Destroy; override; procedure LoadFromStream( Stream : TStream ); procedure SaveToStream( Stream : TStream ); public {properties} property Signature : Longint read FSignature write FSignature; property DiskNumber : Word read FDiskNumber write FDiskNumber; property EntriesOnDisk : Word read FEntriesOnDisk write FEntriesOnDisk; property TotalEntries : Word read FTotalEntries write FTotalEntries; property DirectorySize : Longint read FDirectorySize write FDirectorySize;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -