mrcrowbar.lib.containers.patch module

File format classes for binary patches.

Sources: IPS https://zerosoft.zophar.net/ips.php

UPS http://individual.utoronto.ca/dmeunier/ups-spec.pdf

class mrcrowbar.lib.containers.patch.IPS(source_data: common.BytesReadType | None = None, *, parent: Block | None = None, preload_attrs: dict[str, Any] | None = None, endian: EndianEncoding = None, cache_bytes: bool = False, path_hint: str | None = None, strict: bool = False, cache_refs: bool = True)[source]

Bases: mrcrowbar.blocks.Block

Base class for Blocks.

source_data
Source data to construct Block with. Can be a byte string, dictionary of attribute: value pairs, or another Block object.
parent
Parent Block object where this Block is defined. Used for e.g. evaluating Refs.
preload_attrs
Attributes on the Block to set before importing the data. Used for linking in dependencies before loading.
endian
Platform endianness to use when interpreting the Block data. Useful for Blocks which have the same data layout but different endianness for stored numbers. Has no effect on fields with an predefined endianness.
cache_bytes
Cache the bytes equivalent of the Block. Useful for debugging the loading procedure. Defaults to False.
path_hint
Cache a string containing the path of the current Block, relative to the root.
strict
Throw an exception if parsing a BlockField fails, instead of logging a warning and returning an Unknown. Defaults to False.
cache_refs
Pre-cache all the Refs. Defaults to True.
create(source, target)[source]
magic
patch(source)[source]
records
repr

Plaintext summary of the Block.

class mrcrowbar.lib.containers.patch.IPSRecord(source_data: common.BytesReadType | None = None, *, parent: Block | None = None, preload_attrs: dict[str, Any] | None = None, endian: EndianEncoding = None, cache_bytes: bool = False, path_hint: str | None = None, strict: bool = False, cache_refs: bool = True)[source]

Bases: mrcrowbar.blocks.Block

Base class for Blocks.

source_data
Source data to construct Block with. Can be a byte string, dictionary of attribute: value pairs, or another Block object.
parent
Parent Block object where this Block is defined. Used for e.g. evaluating Refs.
preload_attrs
Attributes on the Block to set before importing the data. Used for linking in dependencies before loading.
endian
Platform endianness to use when interpreting the Block data. Useful for Blocks which have the same data layout but different endianness for stored numbers. Has no effect on fields with an predefined endianness.
cache_bytes
Cache the bytes equivalent of the Block. Useful for debugging the loading procedure. Defaults to False.
path_hint
Cache a string containing the path of the current Block, relative to the root.
strict
Throw an exception if parsing a BlockField fails, instead of logging a warning and returning an Unknown. Defaults to False.
cache_refs
Pre-cache all the Refs. Defaults to True.
data
offset
offset_maj
offset_min
repr

Plaintext summary of the Block.

size
class mrcrowbar.lib.containers.patch.UIntVLV(offset, default=0, **kwargs)[source]

Bases: mrcrowbar.fields.Field

get_from_buffer(buffer, parent=None)[source]

Create a Python object from a byte string, using the field definition.

buffer
Input byte string to process.
parent
Parent block object where this Field is defined. Used for e.g. evaluating Refs.
get_size(value, parent=None, index=None)[source]

Return the size of the Field’s data (in bytes).

value
Input Python object to process.
parent
Parent block object where this Field is defined. Used for e.g. evaluating Refs.
index
Index of the Python object to measure from. Used if the Field takes a list of objects.
get_start_offset(value, parent=None, index=None)[source]

Return the start offset of where the Field’s data is to be stored in the Block.

value
Input Python object to process.
parent
Parent block object where this Field is defined. Used for e.g. evaluating Refs.
index
Index of the Python object to measure from. Used if the Field takes a list of objects.
update_buffer_with_value(value, buffer, parent=None)[source]

Write a Python object into a byte array, using the field definition.

value
Input Python object to process.
buffer
Output byte array to encode value into.
parent
Parent block object where this Field is defined. Used for e.g. evaluating Refs.
validate(value, parent=None)[source]

Validate that a correctly-typed Python object meets the constraints for the Field.

value
Input Python object to process.
parent
Parent block object where this Field is defined. Used for e.g. evaluating Refs.

Throws FieldValidationError if a constraint fails.

class mrcrowbar.lib.containers.patch.UPS(source_data: common.BytesReadType | None = None, *, parent: Block | None = None, preload_attrs: dict[str, Any] | None = None, endian: EndianEncoding = None, cache_bytes: bool = False, path_hint: str | None = None, strict: bool = False, cache_refs: bool = True)[source]

Bases: mrcrowbar.blocks.Block

Base class for Blocks.

source_data
Source data to construct Block with. Can be a byte string, dictionary of attribute: value pairs, or another Block object.
parent
Parent Block object where this Block is defined. Used for e.g. evaluating Refs.
preload_attrs
Attributes on the Block to set before importing the data. Used for linking in dependencies before loading.
endian
Platform endianness to use when interpreting the Block data. Useful for Blocks which have the same data layout but different endianness for stored numbers. Has no effect on fields with an predefined endianness.
cache_bytes
Cache the bytes equivalent of the Block. Useful for debugging the loading procedure. Defaults to False.
path_hint
Cache a string containing the path of the current Block, relative to the root.
strict
Throw an exception if parsing a BlockField fails, instead of logging a warning and returning an Unknown. Defaults to False.
cache_refs
Pre-cache all the Refs. Defaults to True.
STOP_CHECK(pointer)
blocks
input_crc32
input_size
magic
output_crc32
output_size
patch_crc32
class mrcrowbar.lib.containers.patch.UPSBlock(source_data: common.BytesReadType | None = None, *, parent: Block | None = None, preload_attrs: dict[str, Any] | None = None, endian: EndianEncoding = None, cache_bytes: bool = False, path_hint: str | None = None, strict: bool = False, cache_refs: bool = True)[source]

Bases: mrcrowbar.blocks.Block

Base class for Blocks.

source_data
Source data to construct Block with. Can be a byte string, dictionary of attribute: value pairs, or another Block object.
parent
Parent Block object where this Block is defined. Used for e.g. evaluating Refs.
preload_attrs
Attributes on the Block to set before importing the data. Used for linking in dependencies before loading.
endian
Platform endianness to use when interpreting the Block data. Useful for Blocks which have the same data layout but different endianness for stored numbers. Has no effect on fields with an predefined endianness.
cache_bytes
Cache the bytes equivalent of the Block. Useful for debugging the loading procedure. Defaults to False.
path_hint
Cache a string containing the path of the current Block, relative to the root.
strict
Throw an exception if parsing a BlockField fails, instead of logging a warning and returning an Unknown. Defaults to False.
cache_refs
Pre-cache all the Refs. Defaults to True.
rel_offset
repr

Plaintext summary of the Block.

xor_data
class mrcrowbar.lib.containers.patch.XORData(offset, *args, **kwargs)[source]

Bases: mrcrowbar.fields.StringField

validate(value, parent=None)[source]

Validate that a correctly-typed Python object meets the constraints for the Field.

value
Input Python object to process.
parent
Parent block object where this Field is defined. Used for e.g. evaluating Refs.

Throws FieldValidationError if a constraint fails.