How to use the hachoir.field.NullBits 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 Bits(self, "version", 4, "Version")
        yield Bits(self, "hdr_size", 4, "Header size divided by 5")

        # Type of service
        yield Enum(Bits(self, "precedence", 3, "Precedence"), self.precedence_name)
        yield Bit(self, "low_delay", "If set, low delay, else normal delay")
        yield Bit(self, "high_throu", "If set, high throughput, else normal throughput")
        yield Bit(self, "high_rel", "If set, high relibility, else normal")
        yield NullBits(self, "reserved[]", 2, "(reserved for future use)")

        yield UInt16(self, "length")
        yield UInt16(self, "id")

        yield NullBits(self, "reserved[]", 1)
        yield Bit(self, "df", "Don't fragment")
        yield Bit(self, "more_frag", "There are more fragments? if not set, it's the last one")
        yield Bits(self, "frag_ofst_lo", 5)
        yield UInt8(self, "frag_ofst_hi")
        yield UInt8(self, "ttl", "Type to live")
        yield Enum(UInt8(self, "protocol"), self.PROTOCOL_NAME)
        yield textHandler(UInt16(self, "checksum"), hexadecimal)
        yield IPv4_Address(self, "src")
        yield IPv4_Address(self, "dst")

        size = (self.size - self.current_size) // 8
github vstinner / hachoir / hachoir / parser / container / riff.py View on Github external
def parseAviHeader(self):
    yield UInt32(self, "microsec_per_frame", "Microsecond per frame")
    yield UInt32(self, "max_byte_per_sec", "Maximum byte per second")
    yield NullBytes(self, "reserved", 4)

    # Flags
    yield NullBits(self, "reserved[]", 4)
    yield Bit(self, "has_index")
    yield Bit(self, "must_use_index")
    yield NullBits(self, "reserved[]", 2)
    yield Bit(self, "is_interleaved")
    yield NullBits(self, "reserved[]", 2)
    yield Bit(self, "trust_cktype")
    yield NullBits(self, "reserved[]", 4)
    yield Bit(self, "was_capture_file")
    yield Bit(self, "is_copyrighted")
    yield NullBits(self, "reserved[]", 14)

    yield UInt32(self, "total_frame", "Total number of frames in the video")
    yield UInt32(self, "init_frame", "Initial frame (used in interleaved video)")
    yield UInt32(self, "nb_stream", "Number of streams")
    yield UInt32(self, "sug_buf_size", "Suggested buffer size")
    yield UInt32(self, "width", "Width in pixel")
github vstinner / hachoir / hachoir / parser / container / mp4.py View on Github external
def createFields(self):
        yield UInt8(self, "version", "Version")
        yield NullBits(self, "flags", 23)
        yield Bit(self, "is_same_file", "Is the reference to this file?")
        if not self['is_same_file'].value:
            yield CString(self, "location")
github vstinner / hachoir / hachoir / parser / program / elf.py View on Github external
def createFields(self):
        if self.root.endian == BIG_ENDIAN:
            yield NullBits(self, "padding[]", 29)
            for fld, desc in self.FLAGS:
                yield Bit(self, fld, "Segment is " + desc)
        else:
            for fld, desc in reversed(self.FLAGS):
                yield Bit(self, fld, "Segment is " + desc)
            yield NullBits(self, "padding[]", 29)
github vstinner / hachoir / hachoir / parser / misc / gnome_keyring.py View on Github external
def createFields(self):
        yield String(self, "magic", len(self.MAGIC), 'Magic string (%r)' % self.MAGIC, charset="ASCII")
        yield UInt8(self, "major_version")
        yield UInt8(self, "minor_version")
        yield Enum(UInt8(self, "crypto"), self.CRYPTO_NAMES)
        yield Enum(UInt8(self, "hash"), self.HASH_NAMES)
        yield KeyringString(self, "keyring_name")
        yield TimestampUnix64(self, "mtime")
        yield TimestampUnix64(self, "ctime")
        yield Bit(self, "lock_on_idle")
        yield NullBits(self, "reserved[]", 31, "Reserved for future flags")
        yield UInt32(self, "lock_timeout")
        yield UInt32(self, "hash_iterations")
        yield RawBytes(self, "salt", 8)
        yield NullBytes(self, "reserved[]", 16)
        yield Items(self, "items")
        yield UInt32(self, "encrypted_size")
        yield Deflate(SubFile(self, "encrypted", self["encrypted_size"].value, "AES128 CBC", parser_class=EncryptedData))
github vstinner / hachoir / hachoir / parser / program / exe_res.py View on Github external
if self["magic"].value != 0xFEEF04BD:
            raise ParserError("EXE resource: invalid file info magic")
        yield Version(self, "struct_ver", "Structure version (1.0)")
        yield Version(self, "file_ver_ms", "File version MS")
        yield Version(self, "file_ver_ls", "File version LS")
        yield Version(self, "product_ver_ms", "Product version MS")
        yield Version(self, "product_ver_ls", "Product version LS")
        yield textHandler(UInt32(self, "file_flags_mask"), hexadecimal)

        yield Bit(self, "debug")
        yield Bit(self, "prerelease")
        yield Bit(self, "patched")
        yield Bit(self, "private_build")
        yield Bit(self, "info_inferred")
        yield Bit(self, "special_build")
        yield NullBits(self, "reserved", 26)

        yield Enum(textHandler(UInt16(self, "file_os_major"), hexadecimal), MAJOR_OS_NAME)
        yield Enum(textHandler(UInt16(self, "file_os_minor"), hexadecimal), MINOR_OS_NAME)
        yield Enum(textHandler(UInt32(self, "file_type"), hexadecimal), FILETYPE_NAME)
        field = textHandler(UInt32(self, "file_subfile"), hexadecimal)
        if field.value == FILETYPE_DRIVER:
            field = Enum(field, DRIVER_SUBTYPE_NAME)
        elif field.value == FILETYPE_FONT:
            field = Enum(field, FONT_SUBTYPE_NAME)
        yield field
        yield TimestampUnix32(self, "date_ms")
        yield TimestampUnix32(self, "date_ls")
github vstinner / hachoir / hachoir / parser / container / mp4.py View on Github external
def createFields(self):
        yield UInt8(self, "version")
        yield NullBits(self, "flags", 24)
        yield NullBits(self, "reserved", 8)
        if self["version"].value == 0:
            yield NullBits(self, "reserved2", 8)
        else:
            yield Bits(self, "default_crypt_byte_block", 4)
            yield Bits(self, "default_skip_byte_block", 4)
        yield UInt8(self, "default_isProtected")
        yield UInt8(self, "default_Per_sample_IV_Size")
        yield RawBytes(self, "default_KID", 16)
        if self["default_isProtected"].value == 1 and self["default_Per_sample_IV_Size"].value == 0:
            yield UInt8(self, "default_constant_IV_size")
            yield RawBytes(self, "default_constant_IV", self["default_constant_IV_size"].value)
github vstinner / hachoir / hachoir / parser / container / mp4.py View on Github external
def createFields(self):
        yield UInt8(self, "configurationVersion")
        yield UInt8(self, "AVCProfileIndication")
        yield UInt8(self, "profile_compatibility")
        yield UInt8(self, "AVCLevelIndication")
        yield NullBits(self, "reserved[]", 6)
        yield Bits(self, "lengthSizeMinusOne", 2)
        yield NullBits(self, "reserved[]", 3)

        yield Bits(self, "numOfSequenceParameterSets", 5)
        for i in range(self["numOfSequenceParameterSets"].value):
            yield PascalString16(self, "sequenceParameterSetNALUnit[]")

        yield UInt8(self, "numOfPictureParameterSets")
        for i in range(self["numOfPictureParameterSets"].value):
            yield PascalString16(self, "pictureParameterSetNALUnit[]")

        if self['AVCProfileIndication'].value in (100, 110, 122, 144) and not self.eof:
            yield NullBits(self, "reserved[]", 6)
            yield Bits(self, "chroma_format", 2)
            yield NullBits(self, "reserved[]", 5)
            yield Bits(self, "bit_depth_luma_minus8", 3)
github vstinner / hachoir / hachoir / parser / container / mp4.py View on Github external
def createFields(self):
        yield UInt8(self, "version")
        yield NullBits(self, "flags", 24)
        yield UInt32(self, "uniform_size", description="Uniform size of each sample (0 if non-uniform)")
        yield UInt32(self, "count", description="Number of samples")
        if self['uniform_size'].value == 0:
            for i in range(self['count'].value):
                yield UInt32(self, "sample_size[]")
github vstinner / hachoir / hachoir / parser / container / mp4.py View on Github external
def createFields(self):
        yield Bits(self, "fscod", 2)
        yield Bits(self, "bsid", 5)
        yield Bits(self, "bsmod", 5)
        yield Bits(self, "acmod", 3)
        yield Bits(self, "lfeon", 1)
        yield NullBits(self, "reserved", 3)
        yield Bits(self, "num_dep_sub", 4)
        if self["num_dep_sub"].value:
            yield Bits(self, "chan_loc", 9)
        else:
            yield NullBits(self, "reserved2", 1)