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=None, parent=None, preload_attrs=None, endian=None, cache_bytes=False, path_hint=None)[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.
create(source, target)[source]
magic = <Bytes: offset=0x0, length=5>
patch(source)[source]
records = <BlockField: 0x00007fb16c9725c0>
repr

Plaintext summary of the Block.

class mrcrowbar.lib.containers.patch.IPSRecord(source_data=None, parent=None, preload_attrs=None, endian=None, cache_bytes=False, path_hint=None)[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.
data = <Bytes: offset=0x5, length=<Ref: size (rw)>>
offset
offset_maj = <UInt8: offset=0x0>
offset_min = <UInt16_BE: offset=0x1>
repr

Plaintext summary of the Block.

size = <UInt16_BE: offset=0x3>
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=None, parent=None, preload_attrs=None, endian=None, cache_bytes=False, path_hint=None)[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.
STOP_CHECK(pointer)
blocks = <BlockField: 0x00007fb16c972b70>
input_crc32 = <UInt32_LE: offset=<EndOffset: blocks (rw)>>
input_size = <UIntVLV: 0x00007fb16c972a20>
magic = <Bytes: offset=0x0, length=4>
output_crc32 = <UInt32_LE: offset=<EndOffset: input_crc32 (rw)>>
output_size = <UIntVLV: 0x00007fb16c972ac8>
patch_crc32 = <UInt32_LE: offset=<EndOffset: output_crc32 (rw)>>
class mrcrowbar.lib.containers.patch.UPSBlock(source_data=None, parent=None, preload_attrs=None, endian=None, cache_bytes=False, path_hint=None)[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.
rel_offset = <UIntVLV: 0x00007fb16c9727f0>
repr

Plaintext summary of the Block.

xor_data = <XORData: offset=<EndOffset: rel_offset (rw)>>
class mrcrowbar.lib.containers.patch.XORData(offset, *args, **kwargs)[source]

Bases: mrcrowbar.fields.Bytes

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.