Pro.CAB
— API for parsing Microsoft Cabinet files¶
File Extraction¶
The following code example shows how to extract files from a CAB object.
from Pro.Core import *
from Pro.CAB import *
def parseCAB(fname):
c = createContainerFromFile(fname)
obj = CABObject()
if not obj.Load(c):
return
files = obj.GetCFFiles()
it = CFFStructIt(files)
while it.HasNext():
file = it.Next()
# get the file name
name = file.Str("szName")
print(name)
# extract the file
file_data = obj.Extract(file)
Module API¶
Pro.CAB module API.
Classes:
This class contains information about the certificate of a cabinet file.
This class represents a Microsoft Cabinet object.
Attributes:
Flag for the ‘attribs’ field in the cabinet file header.
Flag for the ‘attribs’ field in the cabinet file header.
Flag for the ‘attribs’ field in the cabinet file header.
Flag for the ‘attribs’ field in the cabinet file header.
Flag for the ‘attribs’ field in the cabinet file header.
Flag for the ‘attribs’ field in the cabinet file header.
Flag for the ‘flags’ field in the cabinet header.
Flag for the ‘flags’ field in the cabinet header.
Flag for the ‘flags’ field in the cabinet header.
Option for the ‘iFolder’ field in the cabinet file header.
Option for the ‘iFolder’ field in the cabinet file header.
Option for the ‘iFolder’ field in the cabinet file header.
Mask for the ‘typeCompress’ field in the cabinet folder header.
LZX compression option for the ‘typeCompress’ field in the cabinet folder header.
MSZip compression option for the ‘typeCompress’ field in the cabinet folder header.
None compression option for the ‘typeCompress’ field in the cabinet folder header.
Quantum compression option for the ‘typeCompress’ field in the cabinet folder header.
- class CABCertificateInfo¶
This class contains information about the certificate of a cabinet file.
See also
CABObject.GetCertificateInfo()
.Methods:
IsNull
()Returns
True
if invalid; otherwise returnsFalse
.
IsValid
()Returns
True
if valid; otherwise returnsFalse
.Attributes:
The offset of the certificate.
The size of the certificate.
The version number of the certificate.
- IsNull() → bool¶
- Returns
Returns
True
if invalid; otherwise returnsFalse
.- Return type
bool
See also
IsValid()
.
- IsValid() → bool¶
- Returns
Returns
True
if valid; otherwise returnsFalse
.- Return type
bool
See also
IsNull()
.
- version¶
The version number of the certificate.
- class CABObject¶
Bases:
Pro.Core.CFFObject
This class represents a Microsoft Cabinet object.
Methods:
ComputeChecksum
(cfdata_or_data[, seed])This class computes the checksum for a file in the cabinet.
Decompress
(folder)Decompressed a cabinet folder.
Extract
(file)Extracts a file from the cabinet.
GetCFData
(coffCabStart_or_folder[, cCfData])Retrieves cabinet file data structures.
GetCFDataCompressedData
(cfdata)Retrieves the compressed data for a cabinet file data structure.
Returns the array of file structures in the cabinet file.
Returns the array of folder structures in the cabinet file.
Returns the main header of the cabinet file.
Returns information about the certificate of the cabinet file if available; otherwise returns an invalid
CABCertificateInfo
instance.
GetCompressionName
(compression_type)Returns the name for the compression algorithm specified by the ‘typeCompress’ field in the cabinet folder structure.
- ComputeChecksum(cfdata_or_data: Union[Pro.Core.CFFStruct, Pro.Core.NTContainer], seed: int = 0) → int¶
This class computes the checksum for a file in the cabinet.
- Parameters
cfdata_or_data (Union[CFFStruct, NTContainer]) – Either the data to checksum or the cabinet file data.
seed (int) – The checksum seed.
- Returns
Returns the computed checksum.
- Return type
int
See also
GetCFData()
andGetCFDataCompressedData()
.
- Decompress(folder: Pro.Core.CFFStruct) → Pro.Core.NTContainer¶
Decompressed a cabinet folder.
- Parameters
folder (CFFStruct) – The folder to decompress.
- Returns
Returns the decompressed folder if successful; otherwise returns an invalid
Pro.Core.NTContainer
instance.- Return type
See also
GetCFFolders()
.
- Extract(file: Pro.Core.CFFStruct) → Pro.Core.NTContainer¶
Extracts a file from the cabinet.
- Parameters
file (CFFStruct) – The file to extract.
- Returns
Returns the extracted file if successful; otherwise returns an invalid
Pro.Core.NTContainer
instance.- Return type
See also
GetCFFiles()
.
- GetCFData(coffCabStart_or_folder: Union[Pro.Core.CFFStruct, int], cCfData: Optional[int] = None) → Pro.Core.CFFStruct¶
Retrieves cabinet file data structures.
- Parameters
coffCabStart_or_folder (Union[CFFStruct, int]) – Either the folder structure or the offset of the array.
cCfData (Optional[int]) – The size of the array if the previous field was the offset of the array.
- Returns
Returns the array if successful; otherwise returns an invalid
Pro.Core.CFFStruct
instance.- Return type
See also
GetCFFolders()
andGetCFDataCompressedData()
.
- GetCFDataCompressedData(cfdata: Pro.Core.CFFStruct) → Pro.Core.NTContainer¶
Retrieves the compressed data for a cabinet file data structure.
- Parameters
cfdata (CFFStruct) – The cabinet file data structure.
- Returns
Returns the compressed data if successful; otherwise returns an invalid
Pro.Core.NTContainer
instance.- Return type
- GetCFFiles() → Pro.Core.CFFStruct¶
- Returns
Returns the array of file structures in the cabinet file.
- Return type
See also
Extract()
.
- GetCFFolders() → Pro.Core.CFFStruct¶
- Returns
Returns the array of folder structures in the cabinet file.
- Return type
See also
Decompress()
.
- GetCFHeader() → Pro.Core.CFFStruct¶
- Returns
Returns the main header of the cabinet file.
- Return type
- GetCertificateInfo() → Pro.CAB.CABCertificateInfo¶
- Returns
Returns information about the certificate of the cabinet file if available; otherwise returns an invalid
CABCertificateInfo
instance.- Return type
See also
CABCertificateInfo
.
- GetCompressionName(compression_type: int) → str¶
Returns the name for the compression algorithm specified by the ‘typeCompress’ field in the cabinet folder structure.
- Parameters
compression_type (int) – The compression type.
- Returns
Returns the name of the compression algorithm if known; otherwise returns
'UNKNOWN'
.- Return type
str
See also
GetCFFolders()
.
- cfflattrib_A_ARCH: Final[int]¶
Flag for the ‘attribs’ field in the cabinet file header.
This flag is set if the file has been modified since the last backup.
See also
CABObject.GetCFFiles()
.
- cfflattrib_A_EXEC: Final[int]¶
Flag for the ‘attribs’ field in the cabinet file header.
This flag is set if the file will be run after extraction.
See also
CABObject.GetCFFiles()
.
- cfflattrib_A_HIDDEN: Final[int]¶
Flag for the ‘attribs’ field in the cabinet file header.
This flag is set if the file is hidden.
See also
CABObject.GetCFFiles()
.
- cfflattrib_A_NAME_IS_UTF: Final[int]¶
Flag for the ‘attribs’ field in the cabinet file header.
This flag is set if the ‘szName’ field contains UTF.
See also
CABObject.GetCFFiles()
.
- cfflattrib_A_RDONLY: Final[int]¶
Flag for the ‘attribs’ field in the cabinet file header.
This flag is set if the file is read-only.
See also
CABObject.GetCFFiles()
.
- cfflattrib_A_SYSTEM: Final[int]¶
Flag for the ‘attribs’ field in the cabinet file header.
This flag is set if the file is a system file.
See also
CABObject.GetCFFiles()
.
- cfhdrNEXT_CABINET: Final[int]¶
Flag for the ‘flags’ field in the cabinet header.
This flag is set if the cabinet file is not the last in a set of cabinet files.
See also
CABObject.GetCFHeader()
.
- cfhdrPREV_CABINET: Final[int]¶
Flag for the ‘flags’ field in the cabinet header.
The flag is set if the cabinet file is not the first in a set of cabinet files.
See also
CABObject.GetCFHeader()
.
- cfhdrRESERVE_PRESENT: Final[int]¶
Flag for the ‘flags’ field in the cabinet header.
This flag is set if the cabinet file contains reserved fields.
See also
CABObject.GetCFHeader()
.
- ifoldCONTINUED_FROM_PREV: Final[int]¶
Option for the ‘iFolder’ field in the cabinet file header.
See also
CABObject.GetCFFiles()
.
- ifoldCONTINUED_PREV_AND_NEXT: Final[int]¶
Option for the ‘iFolder’ field in the cabinet file header.
See also
CABObject.GetCFFiles()
.
- ifoldCONTINUED_TO_NEXT: Final[int]¶
Option for the ‘iFolder’ field in the cabinet file header.
See also
CABObject.GetCFFiles()
.
- tcompMASK_TYPE: Final[int]¶
Mask for the ‘typeCompress’ field in the cabinet folder header.
See also
CABObject.GetCFFolders()
.
- tcompTYPE_LZX: Final[int]¶
LZX compression option for the ‘typeCompress’ field in the cabinet folder header.
See also
CABObject.GetCFFolders()
.
- tcompTYPE_MSZIP: Final[int]¶
MSZip compression option for the ‘typeCompress’ field in the cabinet folder header.
See also
CABObject.GetCFFolders()
.
- tcompTYPE_NONE: Final[int]¶
None compression option for the ‘typeCompress’ field in the cabinet folder header.
See also
CABObject.GetCFFolders()
.
- tcompTYPE_QUANTUM: Final[int]¶
Quantum compression option for the ‘typeCompress’ field in the cabinet folder header.
See also
CABObject.GetCFFolders()
.