dissect.cstruct.compiler

Module Contents

Classes

Compiler

Compiler for cstruct structures. Creates somewhat optimized parsing code.

class dissect.cstruct.compiler.Compiler(cstruct: Compiler.__init__.cstruct)

Compiler for cstruct structures. Creates somewhat optimized parsing code.

TYPES = ()
COMPILE_TEMPLATE = Multiline-String
Show Value
"""
class {name}(Structure):
    def __init__(self, cstruct, structure, source=None):
        self.structure = structure
        self.source = source
        super().__init__(cstruct, structure.name, structure.fields, anonymous=structure.anonymous)

    def _read(self, stream, context=None):
        r = OrderedDict()
        sizes = {{}}
        bitreader = BitBuffer(stream, self.cstruct.endian)

{read_code}

        return Instance(self, r, sizes)

    def add_field(self, name, type_, offset=None):
        raise NotImplementedError("Can't add fields to a compiled structure")

    def __repr__(self):
        return '<Structure {name} +compiled>'
"""
compile(structure: dissect.cstruct.types.Structure) dissect.cstruct.types.Structure
gen_struct_class(name: str, structure: dissect.cstruct.types.Structure) str
gen_read_block(size: int, block: List[str]) str
gen_dynamic_block(field: dissect.cstruct.types.Field) str