dissect.cstruct.types.base#

Module Contents#

Classes#

BaseType

Base class for cstruct type classes.

Array

Implements a fixed or dynamically sized array type.

RawType

Base class for raw types that have a name and size.

class dissect.cstruct.types.base.BaseType(cstruct: BaseType.__init__.cstruct)#

Base class for cstruct type classes.

__getitem__(count: int) Array#
__call__(*args, **kwargs) Any#
reads(data: bytes) Any#

Parse the given data according to the type that implements this class.

Parameters:

data – Byte string to parse.

Returns:

The parsed value of this type.

dumps(data: Any) bytes#

Dump the given data according to the type that implements this class.

Parameters:

data – Data to dump.

Returns:

The resulting bytes.

Raises:

ArraySizeError – Raised when len(data) does not match the size of a statically sized array field.

read(obj: BinaryIO, *args, **kwargs) Any#

Parse the given data according to the type that implements this class.

Parameters:

obj – Data to parse. Can be a (byte) string or a file-like object.

Returns:

The parsed value of this type.

write(stream: BinaryIO, data: Any) int#

Write the given data to a writable file-like object according to the type that implements this class.

Parameters:
  • stream – Writable file-like object to write to.

  • data – Data to write.

Returns:

The amount of bytes written.

Raises:

ArraySizeError – Raised when len(data) does not match the size of a statically sized array field.

abstract default() Any#

Return a default value of this type.

default_array(count: int) List[Any]#

Return a default array of this type.

class dissect.cstruct.types.base.Array(cstruct: Array.__init__.cstruct, type_: BaseType, count: int)#

Bases: BaseType

Implements a fixed or dynamically sized array type.

Example

When using the default C-style parser, the following syntax is supported:

x[3] -> 3 -> static length. x[] -> None -> null-terminated. x[expr] -> expr -> dynamic length.

__repr__() str#

Return repr(self).

__len__() int#
default() List[Any]#

Return a default value of this type.

class dissect.cstruct.types.base.RawType(cstruct: RawType.__init__.cstruct, name: str = None, size: int = 0, alignment: int = None)#

Bases: BaseType

Base class for raw types that have a name and size.

__len__() int#
__repr__() str#

Return repr(self).

abstract default() Any#

Return a default value of this type.