How to use the hachoir.field.RawBytes function in hachoir

To help you get started, we’ve selected a few hachoir 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 vstinner / hachoir / hachoir / parser / network / tcpdump.py View on Github external
def createFields(self):
        yield TimestampUnix32(self, "ts_epoch", "Timestamp (Epoch)")
        yield UInt32(self, "ts_nanosec", "Timestamp (nano second)")
        yield UInt32(self, "caplen", "length of portion present")
        yield UInt32(self, "len", "length this packet (off wire)")

        # Read different layers
        field = self._first_parser(self, self._first_name)
        while field:
            yield field
            field = field.parseNext(self)

        # Read data if any
        size = (self.size - self.current_size) // 8
        if size:
            yield RawBytes(self, "data", size)
github vstinner / hachoir / hachoir / parser / audio / modplug.py View on Github external
def ParseModplugMetadata(parser):
    while not parser.eof:
        block = ModplugBlock(parser, "block[]")
        yield block
        if block["block_type"].value == "STPM":
            break

    # More undocumented stuff: date ?
    size = (parser._size - parser.absolute_address - parser.current_size) // 8
    if size > 0:
        yield RawBytes(parser, "info", size)
github vstinner / hachoir / hachoir / parser / program / prc.py View on Github external
yield PRCHeader(self, "header", "Header")
        lens = []
        firstOne = True
        poff = 0
        for index in range(self["header/num_records"].value):
            r = ResourceHeader(self, "res_header[]")
            if firstOne:
                firstOne = False
            else:
                lens.append(r["offset"].value - poff)
            poff = r["offset"].value
            yield r
        lens.append(self.size // 8 - poff)
        yield UInt16(self, "placeholder", "Place holder bytes")
        for i in range(len(lens)):
            yield RawBytes(self, "res[]", lens[i], '"' + self["res_header[" + str(i) + "]/name"].value + "\" Resource")
github vstinner / hachoir / hachoir / parser / container / mp4.py View on Github external
else:
                size = (self.size - self.current_size) // 8
        else:
            size = size - 8
        if self['tag'].value == 'uuid':
            yield GUID(self, "usertag")
            tag = self["usertag"].value
            size -= 16
        else:
            tag = self["tag"].value
        if size > 0:
            if tag in self.tag_info:
                handler, name, desc = self.tag_info[tag]
                yield handler(self, name, desc, size=size * 8)
            else:
                yield RawBytes(self, "data", size)
github vstinner / hachoir / hachoir / parser / audio / mpeg_audio.py View on Github external
def createFields(self):
        # Find synchronisation bytes
        padding = self.synchronize()
        if padding:
            yield padding

        while self.current_size < self.size:
            yield Frame(self, "frame[]")
#            padding = self.synchronize()
#            if padding:
#                yield padding

        # Read raw bytes at the end (if any)
        size = (self.size - self.current_size) // 8
        if size:
            yield RawBytes(self, "raw", size)
github vstinner / hachoir / hachoir / parser / container / mkv.py View on Github external
def parseFixed(self):
        n = self.n_frames + 1
        size = self._size // 8 // n
        for i in range(n):
            yield RawBytes(self, 'frame[]', size)
github vstinner / hachoir / hachoir / parser / video / mpeg_video.py View on Github external
def createFields(self):
        yield Bit(self, "sync[]")  # =True
        yield Bits(self, "ext_length", 7)
        yield NullBits(self, "reserved[]", 8)
        size = self["ext_length"].value
        if size:
            yield RawBytes(self, "ext_bytes", size)
github vstinner / hachoir / hachoir / parser / archive / cab.py View on Github external
def createFields(self):
        yield UInt32(self, "offset", "Offset to data (from file start)")
        yield UInt16(self, "data_blocks", "Number of data blocks which are in this cabinet")
        yield Enum(Bits(self, "compr_method", 4, "Compression method"), COMPRESSION_NAME)
        if self["compr_method"].value in [2, 3]:  # Quantum or LZX use compression level
            yield PaddingBits(self, "padding[]", 4)
            yield Bits(self, "compr_level", 5, "Compression level")
            yield PaddingBits(self, "padding[]", 3)
        else:
            yield PaddingBits(self, "padding[]", 12)
        if self["../flags/has_reserved"].value and self["../reserved_folder_size"].value:
            yield RawBytes(self, "reserved_folder", self["../reserved_folder_size"].value, "Per-folder reserved area")
github vstinner / hachoir / hachoir / parser / misc / chm.py View on Github external
yield UInt64(self, "%s_spaninfo" % sectname, "Size of uncompressed data in the %s section" % sectname)
                    elif name.endswith('/ControlData'):
                        yield ControlData(self, "%s_controldata" % sectname, "Data about the compression scheme", size=entry["length"].value * 8)
                    elif name.endswith('/Transform/List'):
                        yield String(self, "%s_transform_list" % sectname, 38, description="Transform/List element", charset="UTF-16-LE")
                    elif name.endswith('/Transform/{7FC28940-9D31-11D0-9B27-00A0C91E9C7C}/InstanceData/ResetTable'):
                        yield ResetTable(self, "%s_reset_table" % sectname, "LZX Reset Table", size=entry["length"].value * 8)
                    elif name.endswith('/Content'):
                        # eventually, a LZX wrapper will appear here, we hope!
                        yield RawBytes(self, "%s_content" % sectname, entry["length"].value, "Content for the %s section" % sectname)
                    else:
                        yield RawBytes(self, "entry_data[]", entry["length"].value, name)
                elif name == "/#SYSTEM":
                    yield SystemFile(self, "system_file", size=entry["length"].value * 8)
                else:
                    yield RawBytes(self, "entry_data[]", entry["length"].value, name)
github vstinner / hachoir / hachoir / parser / archive / zip.py View on Github external
def createFields(self):
        yield UInt64(self, "zip64_end_size",
                     "Size of zip64 end of central directory record")
        yield ZipVersion(self, "version_made_by", "Version made by")
        yield ZipVersion(self, "version_needed", "Version needed to extract")
        yield UInt32(self, "number_disk", "Number of this disk")
        yield UInt32(self, "number_disk2",
                     "Number of the disk with the start of the central directory")
        yield UInt64(self, "number_entries",
                     "Total number of entries in the central directory on this disk")
        yield UInt64(self, "number_entries2",
                     "Total number of entries in the central directory")
        yield UInt64(self, "size", "Size of the central directory")
        yield UInt64(self, "offset", "Offset of start of central directory")
        if 0 < self["zip64_end_size"].value:
            yield RawBytes(self, "data_sector", self["zip64_end_size"].value,
                           "zip64 extensible data sector")