dissect.target.helpers.protobuf#

Module Contents#

Classes#

ProtobufVarint

Implements a protobuf integer type for dissect.cstruct that can span a variable amount of bytes.

Functions#

decode_varint

Reads a varint from the provided buffer stream.

encode_varint

Encode a decoded protobuf varint to its original bytes.

class dissect.target.helpers.protobuf.ProtobufVarint(cstruct: BytesInteger.__init__.cstruct, name: str, size: int, signed: bool, alignment: int = None)#

Bases: dissect.cstruct.types.bytesinteger.BytesInteger

Implements a protobuf integer type for dissect.cstruct that can span a variable amount of bytes.

Mainly follows the cstruct BytesInteger implementation with minor tweaks to support protobuf’s msb varint implementation.

Resources:
dissect.target.helpers.protobuf.decode_varint(stream: BinaryIO) int#

Reads a varint from the provided buffer stream.

If we have not reached the end of a varint, the msb will be 1. We read every byte from our current position until the msb is 0.

dissect.target.helpers.protobuf.encode_varint(number: int) bytes#

Encode a decoded protobuf varint to its original bytes.