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:
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.
- magic = <Bytes: offset=0x0, length=5>¶
- records = <BlockField: 0x00007f0c83472350>¶
- property 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:
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)>>¶
- property offset¶
- offset_maj = <UInt8: offset=0x0>¶
- offset_min = <UInt16_BE: offset=0x1>¶
- property repr¶
Plaintext summary of the Block.
- size = <UInt16_BE: offset=0x3>¶
- class mrcrowbar.lib.containers.patch.UIntVLV(offset, default=0, **kwargs)[source]¶
Bases:
Field
Base class for Fields.
- default
Default value to emit in the case of e.g. creating an empty Block.
- 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.
- class mrcrowbar.lib.containers.patch.UPS(source_data=None, parent=None, preload_attrs=None, endian=None, cache_bytes=False, path_hint=None)[source]¶
Bases:
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: 0x00007f0c83472c10>¶
- input_crc32 = <UInt32_LE: offset=<EndOffset: blocks (rw)>>¶
- input_size = <UIntVLV: 0x00007f0c833e1310>¶
- magic = <Bytes: offset=0x0, length=4>¶
- output_crc32 = <UInt32_LE: offset=<EndOffset: input_crc32 (rw)>>¶
- output_size = <UIntVLV: 0x00007f0c833e1450>¶
- 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:
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: 0x00007f0c834ae660>¶
- property 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:
Bytes
Field class for string data.
- offset
Position of data, relative to the start of the parent block. Defaults to the end offset of the previous field.
- default
Default value to emit in the case of e.g. creating an empty block.
- count
Load multiple strings. None implies a single value, non-negative numbers will return a Python list.
- length
Maximum size of the buffer to read in.
- stream
Read strings continuously until a stop condition is met. Defaults to False.
- alignment
Number of bytes to align the start of the next element to.
- stream_end
Byte string to indicate the end of the data.
- stop_check
A function that takes a data buffer and an offset; should return True if the end of the data stream has been reached and False otherwise.
- transform
Transform class to use for preprocessing the data before importing or exporting each string.
- encoding
Python string encoding to use for output, as accepted by bytes.decode().
- length_field
Field class used to parse the string length. For use when a string is preceded by the size.
- fill
Exact byte sequence that denotes an empty entry in a list.
- element_length
Length of each string element to load.
- element_end
Byte string to indicate the end of a single string element.
- zero_pad
Pad each element with zeros to match the length. Only for use with fixed length elements. The data size must be up to or equal to the length. Defaults to False.