Python

The following Python interface is provided to facilitate exploitation of CBXP by Python callers.

 

The Python Interface for CBXP can be installed from PyPi using pip.


python3 -m pip install cbxp

The Python Interface for CBXP may also optionally be downloaded from GitHub.

cbxp.extract()

def extract(
    control_block: str,
    includes: list[str] = None,
    filters: list[CBXPFilter] = None,
    debug: bool = False,
) -> dict:

📄 Description

Extract and format Control Block Data from Live Memory.

📥 Parameters

  • control_block
    The name of the Control Block to extract.

  • includes
    A List of Include Patterns that describe Additional Control Blocks to include that are accessible from the Root Control Block being extracted.

  • filters
    A List of Filters that are used to filter the entries returned in Repeated control block data.

  • debug
    A Boolean that if set to True indicates that Debug Messages should be printed. If set to False, no Debug Messages will be printed.

📤 Returns

  • dict
    A Python Dictionary that contains Formatted Control Block Data.

❌ Raises

  • CBXPError
    Raises CBXPError when an error or condition that prevents the operation from completing successfully occurs.

💻 Examples

The following example extracts the PSA control block from Live Memory and prints Debug Messages.

Python Script
from cbxp import cbxp

cbdata = cbxp.extract("psa", debug=True)

 

The following example extracts the CVT control block from Live Memory, includes the ECVT and the ASVT, and includes all Known Control Blocks that are pointed to directly by the ASVT.

Python Script
from cbxp import cbxp

cbdata = cbxp.extract("cvt", includes=["ecvt", "asvt.*"])

 

The following example extracts all ASSB control blocks from Live Memory where the Control Block Field ASSBJBNI matches the Filter Value IBMUSER. The built-in Python library json is then used to convert the resulting Python dictionary into a JSON String.

Python Script
import json
from cbxp import CBXPFilter, CBXPFilterOperation, cbxp

cbdata = cbxp.extract(
    "assb",
    filters=[
        CBXPFilter(
            "assbjbni",
            CBXPFilterOperation.EQUAL,
            "IBMUSER"
        )
    ]
)

cbjson = json(cbdata, indent=2)

cbxp.format()

def format(
    control_block: str,
    data: bytes,
    debug: bool = False,
) -> dict:

📄 Description

Format Caller-Provided Control Block Data from Live Memory.

📥 Parameters

  • control_block
    The name of the Control Block to format.

  • data
    A Bytes Object containing the Raw Control Block Data to format.

  • debug
    A Boolean that if set to True indicates that Debug Messages should be printed. If set to False, no Debug Messages will be printed.

📤 Returns

  • dict
    A Python Dictionary that contains the Formatted Control Block Data.

❌ Raises

  • CBXPError
    Raises CBXPError when an error or condition that prevents the operation from completing successfully occurs.

💻 Examples

The following example formats Caller-Provided ASCB control block data.

Python Script
from cbxp import cbxp

with open("ascb.bin", "rb") as f:
    data = f.read()

cbdata = cbxp.format("ascb", data)