mrcrowbar.blocks module

Definition classes for data blocks.

class mrcrowbar.blocks.Block(source_data=None, parent=None, preload_attrs=None, endian=None, cache_bytes=False)[source]

Bases: object

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.
clone_data(source)[source]

Clone data from another Block.

source
Block instance to copy from.
export_data()[source]

Export data to a byte array.

get_field_end_offset(field_name, index=None)[source]
get_field_names()[source]
get_field_obj(field_name)[source]
get_field_size(field_name, index=None)[source]
get_field_start_offset(field_name, index=None)[source]
get_size()[source]

Get the projected size (in bytes) of the exported data from this Block instance.

import_data(raw_buffer)[source]

Import data from a byte array.

raw_buffer
Byte array to import from.
repr

Plaintext summary of the Block.

scrub_field(field_name)[source]
serialised

Tuple containing the contents of the Block.

update_data(source)[source]

Update data from a dictionary.

source
Dictionary of attribute: value pairs.
update_deps()[source]

Update dependencies on all the fields on this Block instance.

update_deps_on_field(field_name)[source]
validate()[source]

Validate all the fields on this Block instance.

validate_field(field_name)[source]
class mrcrowbar.blocks.BlockMeta[source]

Bases: type

Metaclass for Block which detects and wraps attributes from the class definition.

checks
fields
refs
class mrcrowbar.blocks.FieldDescriptor(name)[source]

Bases: object

Attribute wrapper class for Fields.

name
Name of the Field.
class mrcrowbar.blocks.RefDescriptor(name)[source]

Bases: object

Attribute wrapper class for Refs.

name
Name of the Ref.
class mrcrowbar.blocks.Unknown(source_data=None, parent=None, preload_attrs=None, endian=None, cache_bytes=False)[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.
data = <Bytes: offset=0x0>

Raw data.