How to use the construct.Bytes function in construct

To help you get started, we’ve selected a few construct examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dfirfpi / dpapilab / vaultstruct.py View on Github external
def GUID(name):
    return GuidAdapter(construct.Bytes(name, 16))
github ANSSI-FR / bootcode_parser / bootcode_parser.py View on Github external
def PascalUtf16(size_type=Int16ul):
    """Parse a length-defined string in UTF-16."""

    return _Utf16(Sequence(
        size_type,
        Bytes(this[0] * 2),
    ))
github libyal / assorted / scripts / cpio.py View on Github external
construct.ULInt16(u'file_size_upper'),
      construct.ULInt16(u'file_size_lower'))

  _CPIO_PORTABLE_ASCII_FILE_ENTRY_STRUCT = construct.Struct(
      u'cpio_portable_ascii_file_entry',
      construct.Bytes(u'signature', 6),
      construct.Bytes(u'device_number', 6),
      construct.Bytes(u'inode_number', 6),
      construct.Bytes(u'mode', 6),
      construct.Bytes(u'user_identifier', 6),
      construct.Bytes(u'group_identifier', 6),
      construct.Bytes(u'number_of_links', 6),
      construct.Bytes(u'special_device_number', 6),
      construct.Bytes(u'modification_time', 11),
      construct.Bytes(u'path_string_size', 6),
      construct.Bytes(u'file_size', 11))

  _CPIO_NEW_ASCII_FILE_ENTRY_STRUCT = construct.Struct(
      u'cpio_portable_ascii_file_entry',
      construct.Bytes(u'signature', 6),
      construct.Bytes(u'inode_number', 8),
      construct.Bytes(u'mode', 8),
      construct.Bytes(u'user_identifier', 8),
      construct.Bytes(u'group_identifier', 8),
      construct.Bytes(u'number_of_links', 8),
      construct.Bytes(u'modification_time', 8),
      construct.Bytes(u'file_size', 8),
      construct.Bytes(u'device_major_number', 8),
      construct.Bytes(u'device_minor_number', 8),
      construct.Bytes(u'special_device_major_number', 8),
      construct.Bytes(u'special_device_minor_number', 8),
      construct.Bytes(u'path_string_size', 8),
github SekoiaLab / Fastir_Collector / registry / reg.py View on Github external
)
    parse_res = itempos_struct.parse_stream(itempos_io)
    if itempos_io.pos % 2 == 1:
        itempos_io.read(1)
    ext_struct = construct.Struct("ext",
                                  construct.ULInt16("ext_size"),
                                  construct.ULInt16("ext_version")
                                  )
    parse_ext = ext_struct.parse_stream(itempos_io)
    if parse_ext["ext_version"] >= 0x3:
        itempos2_struct = construct.Struct("itempos2",
                                           construct.Padding(2),  # 0004
                                           construct.Padding(2),  # BEEF
                                           construct.Bytes("creation_dos_date", 2),
                                           construct.Bytes("creation_dos_time", 2),
                                           construct.Bytes("access_dos_date", 2),
                                           construct.Bytes("access_dos_time", 2),
                                           construct.Padding(4)
                                           )
        parse_res2 = itempos2_struct.parse_stream(itempos_io)
    unicode_filename = ""
    if parse_ext["ext_version"] >= 0x7:
        itempos3_struct = construct.Struct("itempos3",
                                           construct.ULInt64("file_ref"),
                                           construct.Padding(8),
                                           construct.Padding(2)
                                           )
        parse_res3 = itempos3_struct.parse_stream(itempos_io)
        if parse_ext["ext_version"] >= 0x8:
            itempos4_struct = construct.Struct("itempos4",
                                               construct.Padding(4)
                                               )
github PythEch / pymobiledevice / libs / python / construct / formats / filesystem / fat16.py View on Github external
ULInt16("sectorSize"),
            Byte("sectorsPerCluster"),
            ULInt16("reservedSectorCount"),
            Byte("fatCount"),
            ULInt16("rootdirEntryCount"),
            ULInt16("sectorCount_small"),
            Byte("mediaId"), 
            ULInt16("sectorsPerFat"),
            ULInt16("sectorsPerTrack"),
            ULInt16("sideCount"),
            ULInt32("hiddenSectorCount"),
            ULInt32("sectorCount_large"),
            Byte("physicalDriveNumber"),
            Byte("currentHead"),
            Byte("extendedBootSignature"),
            Bytes("volumeId", 4),
            Bytes("volumeLabel", 11),
            Const(Bytes("fsType", 8), "FAT16   "),
            Bytes("bootCode", 448),
            Const(Bytes("bootSectorSignature", 2), "\x55\xaa"))
github libyal / assorted / scripts / cpio.py View on Github external
construct.ULInt16(u'number_of_links'),
      construct.ULInt16(u'special_device_number'),
      construct.ULInt16(u'modification_time_upper'),
      construct.ULInt16(u'modification_time_lower'),
      construct.ULInt16(u'path_string_size'),
      construct.ULInt16(u'file_size_upper'),
      construct.ULInt16(u'file_size_lower'))

  _CPIO_PORTABLE_ASCII_FILE_ENTRY_STRUCT = construct.Struct(
      u'cpio_portable_ascii_file_entry',
      construct.Bytes(u'signature', 6),
      construct.Bytes(u'device_number', 6),
      construct.Bytes(u'inode_number', 6),
      construct.Bytes(u'mode', 6),
      construct.Bytes(u'user_identifier', 6),
      construct.Bytes(u'group_identifier', 6),
      construct.Bytes(u'number_of_links', 6),
      construct.Bytes(u'special_device_number', 6),
      construct.Bytes(u'modification_time', 11),
      construct.Bytes(u'path_string_size', 6),
      construct.Bytes(u'file_size', 11))

  _CPIO_NEW_ASCII_FILE_ENTRY_STRUCT = construct.Struct(
      u'cpio_portable_ascii_file_entry',
      construct.Bytes(u'signature', 6),
      construct.Bytes(u'inode_number', 8),
      construct.Bytes(u'mode', 8),
      construct.Bytes(u'user_identifier', 8),
      construct.Bytes(u'group_identifier', 8),
      construct.Bytes(u'number_of_links', 8),
      construct.Bytes(u'modification_time', 8),
      construct.Bytes(u'file_size', 8),
github PythEch / pymobiledevice / libs / python / construct / formats / filesystem / fat16.py View on Github external
Byte("fatCount"),
            ULInt16("rootdirEntryCount"),
            ULInt16("sectorCount_small"),
            Byte("mediaId"), 
            ULInt16("sectorsPerFat"),
            ULInt16("sectorsPerTrack"),
            ULInt16("sideCount"),
            ULInt32("hiddenSectorCount"),
            ULInt32("sectorCount_large"),
            Byte("physicalDriveNumber"),
            Byte("currentHead"),
            Byte("extendedBootSignature"),
            Bytes("volumeId", 4),
            Bytes("volumeLabel", 11),
            Const(Bytes("fsType", 8), "FAT16   "),
            Bytes("bootCode", 448),
            Const(Bytes("bootSectorSignature", 2), "\x55\xaa"))
github tdryer / gifprime / gifprime / parser.py View on Github external
def _get_data_subblocks(name):
    """Return Adapter to parse GIF data sub-blocks."""
    return construct.ExprAdapter(
        construct.Struct(
            name,
            construct.RepeatUntil(
                lambda obj, ctx: obj.block_size == 0x00,
                construct.Struct(
                    'blocks',
                    construct.ULInt8('block_size'),
                    construct.Bytes('data_values', lambda ctx: ctx.block_size),
                ),
            ),
        ),
        # from comment string, build Containers
        encoder=lambda obj, ctx: construct.Container(
            blocks = [
                construct.Container(
                    block_size = len(chunk),
                    data_values = chunk,
                ) for chunk in [obj[i:i+255] for i in xrange(0, len(obj), 255)]
            ] + [construct.Container(block_size = 0, data_values = '')],
        ),
        # from Containers, build comment string
        decoder=lambda obj, ctx: ''.join(dsb.data_values for dsb in obj.blocks),
    )
github stephen-bunn / bethesda-structs / bethesda_structs / plugin / fnv / _common.py View on Github external
"variable_count" / Int32ul,
                "type" / FlagsEnum(Int16ul, object=0x000, quest=0x001, effect=0x100),
                "flags" / FlagsEnum(Int16ul, enabled=0x0001),
            )
            * "Basic Script Data",
        ),
        Subrecord("SCDA", GreedyBytes * "Commpiled Script Source"),
        Subrecord("SCTX", GreedyString("utf8") * "Script Source"),
        SubrecordCollection(
            "ScriptVariables",
            [
                Subrecord(
                    "SLSD",
                    Struct(
                        "index" / Int32ul,
                        "_unknown_0" / Bytes(12),
                        "flags" / FlagsEnum(Int8ul, is_long_or_short=0x01),
                        "_unknown_1" / Bytes(7),
                    )
                    * "Local Variable Data",
                ),
                Subrecord("SCVR", CString("utf8") * "Local Variable Name"),
            ],
            optional=True,
            multiple=True,
        ),
        Subrecord(
            "SCRO",
            FNVFormID(
                [
                    "ACTI",
                    "DOOR",