:py:mod:`dissect.cstruct.utils` =============================== .. py:module:: dissect.cstruct.utils Module Contents --------------- Functions ~~~~~~~~~ .. autoapisummary:: :nosignatures: dissect.cstruct.utils.hexdump dissect.cstruct.utils.dumpstruct dissect.cstruct.utils.pack dissect.cstruct.utils.unpack dissect.cstruct.utils.p8 dissect.cstruct.utils.p16 dissect.cstruct.utils.p32 dissect.cstruct.utils.p64 dissect.cstruct.utils.u8 dissect.cstruct.utils.u16 dissect.cstruct.utils.u32 dissect.cstruct.utils.u64 dissect.cstruct.utils.swap dissect.cstruct.utils.swap16 dissect.cstruct.utils.swap32 dissect.cstruct.utils.swap64 Attributes ~~~~~~~~~~ .. autoapisummary:: dissect.cstruct.utils.COLOR_RED dissect.cstruct.utils.COLOR_GREEN dissect.cstruct.utils.COLOR_YELLOW dissect.cstruct.utils.COLOR_BLUE dissect.cstruct.utils.COLOR_PURPLE dissect.cstruct.utils.COLOR_CYAN dissect.cstruct.utils.COLOR_WHITE dissect.cstruct.utils.COLOR_NORMAL dissect.cstruct.utils.COLOR_BG_RED dissect.cstruct.utils.COLOR_BG_GREEN dissect.cstruct.utils.COLOR_BG_YELLOW dissect.cstruct.utils.COLOR_BG_BLUE dissect.cstruct.utils.COLOR_BG_PURPLE dissect.cstruct.utils.COLOR_BG_CYAN dissect.cstruct.utils.COLOR_BG_WHITE dissect.cstruct.utils.PRINTABLE dissect.cstruct.utils.ENDIANNESS_MAP dissect.cstruct.utils.Palette .. py:data:: COLOR_RED :value: '\x1b[1;31m' .. py:data:: COLOR_GREEN :value: '\x1b[1;32m' .. py:data:: COLOR_YELLOW :value: '\x1b[1;33m' .. py:data:: COLOR_BLUE :value: '\x1b[1;34m' .. py:data:: COLOR_PURPLE :value: '\x1b[1;35m' .. py:data:: COLOR_CYAN :value: '\x1b[1;36m' .. py:data:: COLOR_WHITE :value: '\x1b[1;37m' .. py:data:: COLOR_NORMAL :value: '\x1b[1;0m' .. py:data:: COLOR_BG_RED :value: '\x1b[1;41m\x1b[1;37m' .. py:data:: COLOR_BG_GREEN :value: '\x1b[1;42m\x1b[1;37m' .. py:data:: COLOR_BG_YELLOW :value: '\x1b[1;43m\x1b[1;37m' .. py:data:: COLOR_BG_BLUE :value: '\x1b[1;44m\x1b[1;37m' .. py:data:: COLOR_BG_PURPLE :value: '\x1b[1;45m\x1b[1;37m' .. py:data:: COLOR_BG_CYAN :value: '\x1b[1;46m\x1b[1;37m' .. py:data:: COLOR_BG_WHITE :value: '\x1b[1;47m\x1b[1;30m' .. py:data:: PRINTABLE :value: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ ' .. py:data:: ENDIANNESS_MAP .. py:data:: Palette .. py:function:: hexdump(data: bytes, palette: Palette | None = None, offset: int = 0, prefix: str = '', output: str = 'print') -> Iterator[str] | str | None Hexdump some data. :param data: Bytes to hexdump. :param palette: Colorize the hexdump using this color pattern. :param offset: Byte offset of the hexdump. :param prefix: Optional prefix. :param output: Output format, can be 'print', 'generator' or 'string'. .. py:function:: dumpstruct(obj: dissect.cstruct.types.structure.Structure | type[dissect.cstruct.types.structure.Structure], data: bytes | None = None, offset: int = 0, color: bool = True, output: str = 'print') -> str | None Dump a structure or parsed structure instance. Prints a colorized hexdump and parsed structure output. :param obj: Structure to dump. :param data: Bytes to parse the Structure on, if obj is not a parsed Structure already. :param offset: Byte offset of the hexdump. :param output: Output format, can be 'print' or 'string'. .. py:function:: pack(value: int, size: int = None, endian: str = 'little') -> bytes Pack an integer value to a given bit size, endianness. :param value: Value to pack. :param size: Integer size in bits. :param endian: Endianness to use (little, big, network, <, > or !) .. py:function:: unpack(value: bytes, size: int = None, endian: str = 'little', sign: bool = False) -> int Unpack an integer value from a given bit size, endianness and sign. :param value: Value to unpack. :param size: Integer size in bits. :param endian: Endianness to use (little, big, network, <, > or !) :param sign: Signedness of the integer. .. py:function:: p8(value: int, endian: str = 'little') -> bytes Pack an 8 bit integer. :param value: Value to pack. :param endian: Endianness to use (little, big, network, <, > or !) .. py:function:: p16(value: int, endian: str = 'little') -> bytes Pack a 16 bit integer. :param value: Value to pack. :param endian: Endianness to use (little, big, network, <, > or !) .. py:function:: p32(value: int, endian: str = 'little') -> bytes Pack a 32 bit integer. :param value: Value to pack. :param endian: Endianness to use (little, big, network, <, > or !) .. py:function:: p64(value: int, endian: str = 'little') -> bytes Pack a 64 bit integer. :param value: Value to pack. :param endian: Endianness to use (little, big, network, <, > or !) .. py:function:: u8(value: bytes, endian: str = 'little', sign: bool = False) -> int Unpack an 8 bit integer. :param value: Value to unpack. :param endian: Endianness to use (little, big, network, <, > or !) :param sign: Signedness of the integer. .. py:function:: u16(value: bytes, endian: str = 'little', sign: bool = False) -> int Unpack a 16 bit integer. :param value: Value to unpack. :param endian: Endianness to use (little, big, network, <, > or !) :param sign: Signedness of the integer. .. py:function:: u32(value: bytes, endian: str = 'little', sign: bool = False) -> int Unpack a 32 bit integer. :param value: Value to unpack. :param endian: Endianness to use (little, big, network, <, > or !) :param sign: Signedness of the integer. .. py:function:: u64(value: bytes, endian: str = 'little', sign: bool = False) -> int Unpack a 64 bit integer. :param value: Value to unpack. :param endian: Endianness to use (little, big, network, <, > or !) :param sign: Signedness of the integer. .. py:function:: swap(value: int, size: int) Swap the endianness of an integer with a given bit size. :param value: Integer to swap. :param size: Integer size in bits. .. py:function:: swap16(value: int) -> int Swap the endianness of a 16 bit integer. :param value: Integer to swap. .. py:function:: swap32(value: int) -> int Swap the endianness of a 32 bit integer. :param value: Integer to swap. .. py:function:: swap64(value: int) -> int Swap the endianness of a 64 bit integer. :param value: Integer to swap.