dissect.cstruct.types.structure

Module Contents

Classes

Field

Structure field.

StructureMetaType

Base metaclass for cstruct structure type classes.

Structure

Base class for cstruct structure type classes.

StructureValuesProxy

A proxy for the values of fields of a Structure.

UnionMetaType

Base metaclass for cstruct union type classes.

Union

Base class for cstruct union type classes.

UnionProxy

Functions

attrsetter

_make_structure__init__

Generates an __init__ method for a structure with the specified fields.

_make_union__init__

Generates an __init__ method for a class with the specified fields using setattr.

_make__eq__

Generates an __eq__ method for a class with the specified fields.

_make__bool__

Generates a __bool__ method for a class with the specified fields.

_make__hash__

Generates a __hash__ method for a class with the specified fields.

_generate_structure__init__

Generates an __init__ method for a structure with the specified fields.

_generate_union__init__

Generates an __init__ method for a union with the specified fields.

_generate__eq__

Generates an __eq__ method for a class with the specified fields.

_generate__bool__

Generates a __bool__ method for a class with the specified fields.

_generate__hash__

Generates a __hash__ method for a class with the specified fields.

class dissect.cstruct.types.structure.Field(name: str | None, type_: type[dissect.cstruct.types.base.BaseType], bits: int | None = None, offset: int | None = None)

Structure field.

name
type
bits = None
offset = None
alignment
__repr__() str
class dissect.cstruct.types.structure.StructureMetaType

Bases: dissect.cstruct.types.base.MetaType

Base metaclass for cstruct structure type classes.

fields: dict[str, Field]

Mapping of field names to Field objects, including “folded” fields from anonymous structures.

lookup: dict[str, Field]

Mapping of “raw” field names to Field objects. E.g. holds the anonymous struct and not its fields.

__fields__: list[Field]

List of Field objects for this structure. This is the structures’ Single Source Of Truth.

__align__: bool
__anonymous__: bool
__updating__ = False
__compiled__ = False
__static_sizes__: dict[str, int]
__call__(*args, **kwargs) typing_extensions.Self

Adds support for TypeClass(bytes | file-like object) parsing syntax.

add_field(name: str, type_: type[dissect.cstruct.types.base.BaseType], bits: int | None = None, offset: int | None = None) None
start_update() collections.abc.Iterator[None]
commit() None
class dissect.cstruct.types.structure.Structure

Bases: dissect.cstruct.types.base.BaseType

Base class for cstruct structure type classes.

Note that setting attributes which do not correspond to a field in the structure results in undefined behavior. For performance reasons, the structure does not check if the field exists when writing to an attribute.

__dynamic_sizes__: dict[str, int]
__len__() int

Return the byte size of the type.

__bytes__() bytes
__getitem__(item: str) Any
__repr__() str
property __values__: collections.abc.MutableMapping[str, Any]
property __sizes__: collections.abc.Mapping[str, int | None]
class dissect.cstruct.types.structure.StructureValuesProxy(struct: Structure)

Bases: collections.abc.MutableMapping

A proxy for the values of fields of a Structure.

__getitem__(key: str) Any
__setitem__(key: str, value: Any) None
__contains__(key: str) bool
__iter__() collections.abc.Iterator[str]
__len__() int
__repr__() str
abstract __delitem__(_: str)
class dissect.cstruct.types.structure.UnionMetaType

Bases: StructureMetaType

Base metaclass for cstruct union type classes.

__call__(*args, **kwargs) typing_extensions.Self

Adds support for TypeClass(bytes | file-like object) parsing syntax.

class dissect.cstruct.types.structure.Union

Bases: Structure

Base class for cstruct union type classes.

__eq__(other: object) bool
__setattr__(attr: str, value: Any) None
class dissect.cstruct.types.structure.UnionProxy(union: Union, attr: str, target: Structure)
__union__: Union
__attr__: str
__target__: Structure
__len__() int
__bytes__() bytes
__getitem__(item: str) Any
__repr__() str
__getattr__(attr: str) Any
__setattr__(attr: str, value: Any) None
dissect.cstruct.types.structure.attrsetter(path: str) collections.abc.Callable[[Any], Any]
dissect.cstruct.types.structure._make_structure__init__(fields: list[str]) str

Generates an __init__ method for a structure with the specified fields.

Parameters:

fields – List of field names.

dissect.cstruct.types.structure._make_union__init__(fields: list[str]) str

Generates an __init__ method for a class with the specified fields using setattr.

Parameters:

fields – List of field names.

dissect.cstruct.types.structure._make__eq__(fields: list[str]) str

Generates an __eq__ method for a class with the specified fields.

Parameters:

fields – List of field names.

dissect.cstruct.types.structure._make__bool__(fields: list[str]) str

Generates a __bool__ method for a class with the specified fields.

Parameters:

fields – List of field names.

dissect.cstruct.types.structure._make__hash__(fields: list[str]) str

Generates a __hash__ method for a class with the specified fields.

Parameters:

fields – List of field names.

dissect.cstruct.types.structure._generate_structure__init__(fields: list[Field]) types.FunctionType

Generates an __init__ method for a structure with the specified fields.

Parameters:

fields – List of field names.

dissect.cstruct.types.structure._generate_union__init__(fields: list[Field]) types.FunctionType

Generates an __init__ method for a union with the specified fields.

Parameters:

fields – List of field names.

dissect.cstruct.types.structure._generate__eq__(fields: list[str]) types.FunctionType

Generates an __eq__ method for a class with the specified fields.

Parameters:

fields – List of field names.

dissect.cstruct.types.structure._generate__bool__(fields: list[str]) types.FunctionType

Generates a __bool__ method for a class with the specified fields.

Parameters:

fields – List of field names.

dissect.cstruct.types.structure._generate__hash__(fields: list[str]) types.FunctionType

Generates a __hash__ method for a class with the specified fields.

Parameters:

fields – List of field names.