Pro.CAB — API for parsing Microsoft Cabinet files

Overview

The Pro.CAB module contains the 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:

CABCertificateInfo()

This class contains information about the certificate of a cabinet file.

CABObject()

This class represents a Microsoft Cabinet object.

Attributes:

cfflattrib_A_ARCH

Flag for the ‘attribs’ field in the cabinet file header.

cfflattrib_A_EXEC

Flag for the ‘attribs’ field in the cabinet file header.

cfflattrib_A_HIDDEN

Flag for the ‘attribs’ field in the cabinet file header.

cfflattrib_A_NAME_IS_UTF

Flag for the ‘attribs’ field in the cabinet file header.

cfflattrib_A_RDONLY

Flag for the ‘attribs’ field in the cabinet file header.

cfflattrib_A_SYSTEM

Flag for the ‘attribs’ field in the cabinet file header.

cfhdrNEXT_CABINET

Flag for the ‘flags’ field in the cabinet header.

cfhdrPREV_CABINET

Flag for the ‘flags’ field in the cabinet header.

cfhdrRESERVE_PRESENT

Flag for the ‘flags’ field in the cabinet header.

ifoldCONTINUED_FROM_PREV

Option for the ‘iFolder’ field in the cabinet file header.

ifoldCONTINUED_PREV_AND_NEXT

Option for the ‘iFolder’ field in the cabinet file header.

ifoldCONTINUED_TO_NEXT

Option for the ‘iFolder’ field in the cabinet file header.

tcompMASK_TYPE

Mask for the ‘typeCompress’ field in the cabinet folder header.

tcompTYPE_LZX

LZX compression option for the ‘typeCompress’ field in the cabinet folder header.

tcompTYPE_MSZIP

MSZip compression option for the ‘typeCompress’ field in the cabinet folder header.

tcompTYPE_NONE

None compression option for the ‘typeCompress’ field in the cabinet folder header.

tcompTYPE_QUANTUM

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 returns False.

IsValid()

Returns True if valid; otherwise returns False.

Attributes:

offset

The offset of the certificate.

size

The size of the certificate.

version

The version number of the certificate.

IsNull()bool
Returns

Returns True if invalid; otherwise returns False.

Return type

bool

See also IsValid().

IsValid()bool
Returns

Returns True if valid; otherwise returns False.

Return type

bool

See also IsNull().

offset

The offset of the certificate.

See also size.

size

The size of the certificate.

See also offset.

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.

GetCFFiles()

Returns the array of file structures in the cabinet file.

GetCFFolders()

Returns the array of folder structures in the cabinet file.

GetCFHeader()

Returns the main header of the cabinet file.

GetCertificateInfo()

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() and GetCFDataCompressedData().

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

NTContainer

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

NTContainer

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

CFFStruct

See also GetCFFolders() and GetCFDataCompressedData().

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

NTContainer

GetCFFiles()Pro.Core.CFFStruct
Returns

Returns the array of file structures in the cabinet file.

Return type

CFFStruct

See also Extract().

GetCFFolders()Pro.Core.CFFStruct
Returns

Returns the array of folder structures in the cabinet file.

Return type

CFFStruct

See also Decompress().

GetCFHeader()Pro.Core.CFFStruct
Returns

Returns the main header of the cabinet file.

Return type

CFFStruct

GetCertificateInfo()Pro.CAB.CABCertificateInfo
Returns

Returns information about the certificate of the cabinet file if available; otherwise returns an invalid CABCertificateInfo instance.

Return type

CABCertificateInfo

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().