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.

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, type_: dissect.cstruct.types.base.MetaType, 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
__call__(*args, **kwargs) Structure

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

add_field(name: str, 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.

__len__() int

Return the byte size of the type.

__bytes__() bytes
__getitem__(item: str) Any
__repr__() str
class dissect.cstruct.types.structure.UnionMetaType

Bases: StructureMetaType

Base metaclass for cstruct union type classes.

__call__(*args, **kwargs) Union

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) 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.