How to use the hachoir.field.UInt16 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 / misc / msoffice.py View on Github external
def createFields(self):
            yield Bits(self, "version", 4)
            yield Bits(self, "instance", 12)
            yield Enum(UInt16(self, "type"), PowerPointDocument.OBJ_TYPES)
            yield UInt32(self, "length")
            self._size = self["length"].value * 8 + 64
            obj_type = self["type"].display
            obj_len = self["length"].value
            # type 1064 (RoundTripCustomTableStyles12) may appear to be a
            # container, but it is not.
            if self["version"].value == 0xF and self["type"].value != 1064:
                while (self.current_size) // 8 < obj_len + 8:
                    yield PowerPointDocument.PowerPointObject(self, "object[]")
            elif obj_len:
                if obj_type == "FontEntityAtom":
                    yield String(self, "data", obj_len, charset="UTF-16-LE", truncate="\0", strip="\0")
                elif obj_type == "TextCharsAtom":
                    yield String(self, "data", obj_len, charset="UTF-16-LE")
                elif obj_type == "TextBytesAtom":
                    yield String(self, "data", obj_len, charset="ASCII")
github vstinner / hachoir / hachoir / parser / image / gif.py View on Github external
def createFields(self):
        yield UInt16(self, "left", "Left")
        yield UInt16(self, "top", "Top")
        yield UInt16(self, "width", "Width")
        yield UInt16(self, "height", "Height")

        yield Bits(self, "size_local_map", 3, "log2(size of local map) minus one")
        yield NullBits(self, "reserved", 2)
        yield Bit(self, "sort_flag", "Is the local map sorted by decreasing importance?")
        yield Bit(self, "interlaced", "Interlaced?")
        yield Bit(self, "has_local_map", "Use local color map?")

        if self["has_local_map"].value:
            nb_color = 1 << (1 + self["size_local_map"].value)
            yield PaletteRGB(self, "local_map", nb_color, "Local color map")

        yield UInt8(self, "lzw_min_code_size", "LZW Minimum Code Size")
        group = None
        while True:
            size = UInt8(self, "image_block_size[]")
            if size.value == 0:
github vstinner / hachoir / hachoir / parser / program / java.py View on Github external
yield NullBits(self, "reserved[]", 1)
        yield Bit(self, "synthetic", description='Declared synthetic; not present in the source code.')
        yield NullBits(self, "reserved[]", 4)
        yield Bit(self, "transient", description='Declared transient; not written or read by a persistent object manager.')
        yield Bit(self, "volatile", description='Declared volatile; cannot be cached.')
        yield NullBits(self, "reserved[]", 1)
        yield Bit(self, "final", description='Declared final; never directly assigned to after object construction.')
        yield Bit(self, "static", description='Declared static.')
        yield Bit(self, "protected", description='Declared protected; may be accessed within subclasses.')
        yield Bit(self, "private", description='Declared private; accessible only within the defining class.')
        yield Bit(self, "public", description='Declared public; may be accessed from outside its package.')

        yield CPIndex(self, "name_index", "Field name", target_types="Utf8")
        yield CPIndex(self, "descriptor_index", "Field descriptor", target_types="Utf8",
                      target_text_handler=parse_field_descriptor)
        yield UInt16(self, "attributes_count", "Number of field attributes")
        if self["attributes_count"].value > 0:
            yield FieldArray(self, "attributes", AttributeInfo,
                             self["attributes_count"].value)
github vstinner / hachoir / hachoir / parser / program / java.py View on Github external
def createFields(self):
        yield textHandler(UInt32(self, "magic", "Java compiled class signature"),
                          hexadecimal)
        yield UInt16(self, "minor_version", "Class format minor version")
        yield UInt16(self, "major_version", "Class format major version")
        yield UInt16(self, "constant_pool_count", "Size of the constant pool")
        if self["constant_pool_count"].value > 1:
            # yield FieldArray(self, "constant_pool", CPInfo,
            #        (self["constant_pool_count"].value - 1), first_index=1)
            # Mmmh... can't use FieldArray actually, because ConstantPool
            # requires some specific hacks (skipping some indexes after Long
            # and Double entries).
            yield ConstantPool(self, "constant_pool",
                               (self["constant_pool_count"].value))

        # Class access and property modifiers (16 bits)
        yield NullBits(self, "reserved[]", 1)
        yield Bit(self, "enum", description="Declared as an enum type.")
        yield Bit(self, "annotation", description="Declared as an annotation type.")
        yield Bit(self, "synthetic", description="Declared synthetic; not present in the source code.")
        yield NullBits(self, "reserved[]", 1)
        yield Bit(self, "abstract", description="Declared abstract; must not be instantiated.")
github vstinner / hachoir / hachoir / parser / network / tcpdump.py View on Github external
def createFields(self):
        yield UInt16(self, "hw_type")
        yield UInt16(self, "proto_type")
        yield UInt8(self, "hw_size")
        yield UInt8(self, "proto_size")
        yield Enum(UInt16(self, "opcode"), ARP.opcode_name)
        yield MAC48_Address(self, "src_mac")
        yield IPv4_Address(self, "src_ip")
        yield MAC48_Address(self, "dst_mac")
        yield IPv4_Address(self, "dst_ip")
github vstinner / hachoir / hachoir / parser / audio / real_audio.py View on Github external
def createFields(self):
        yield Bytes(self, "signature", 4, r"RealAudio identifier ('.ra\xFD')")
        yield UInt16(self, "version", "Version")
        if self["version"].value == 3:
            yield UInt16(self, "header_size", "Header size")
            yield RawBytes(self, "Unknown1", 10)
            yield UInt32(self, "data_size", "Data size")
            yield Metadata(self, "metadata")
            yield UInt8(self, "Unknown2")
            yield PascalString8(self, "FourCC")
            audio_size = self["data_size"].value
        else:  # version = 4
            yield UInt16(self, "reserved1", "Reserved, should be 0")
            yield String(self, "ra4sig", 4, "'.ra4' signature")
            yield UInt32(self, "filesize", "File size (minus 40 bytes)")
            yield UInt16(self, "version2", "Version 2 (always equal to version)")
            yield UInt32(self, "headersize", "Header size (minus 16)")
            yield UInt16(self, "codec_flavor", "Codec flavor")
            yield UInt32(self, "coded_frame_size", "Coded frame size")
            yield RawBytes(self, "unknown1", 12)
            yield UInt16(self, "subpacketh", "Subpacket h (?)")
            yield UInt16(self, "frame_size", "Frame size")
            yield UInt16(self, "sub_packet_size", "Subpacket size")
            yield UInt16(self, "unknown2", "Unknown")
            yield displayHandler(UInt16(self, "sample_rate", "Sample rate"), humanFrequency)
            yield UInt16(self, "unknown3", "Unknown")
            yield UInt16(self, "sample_size", "Sample size")
            yield UInt16(self, "channels", "Channels")
            yield PascalString8(self, "Interleaving ID String")
            yield PascalString8(self, "FourCC")
            yield RawBytes(self, "unknown4", 3)
            yield Metadata(self, "metadata")
github vstinner / hachoir / hachoir / parser / container / mp4.py View on Github external
def createFields(self):
        yield UInt8(self, "version", "Version")
        yield Bits(self, "flags", 24, "Flags (=1)")
        graphics = UInt16(self, "graphicsmode")
        graphics.createDisplay = lambda: self.graphicsDisplay(graphics)
        graphics.createDescription = lambda: self.graphicsDescription(graphics)
        yield graphics
        yield UInt16(self, "op_red", "Red value for graphics mode")
        yield UInt16(self, "op_green", "Green value for graphics mode")
        yield UInt16(self, "op_blue", "Blue value for graphics mode")
github vstinner / hachoir / hachoir / parser / container / mp4.py View on Github external
def VisualSampleEntry(self):
    yield UInt16(self, "version")
    yield UInt16(self, "revision_level")
    yield RawBytes(self, "vendor_id", 4)
    yield UInt32(self, "temporal_quality")
    yield UInt32(self, "spatial_quality")
    yield UInt16(self, "width", "Width (pixels)")
    yield UInt16(self, "height", "Height (pixels)")
    yield QTFloat32(self, "horizontal_resolution", "Horizontal resolution in DPI")
    yield QTFloat32(self, "vertical resolution", "Vertical resolution in DPI")
    yield UInt32(self, "data_size")
    yield UInt16(self, "frame_count")
    yield UInt8(self, "compressor_name_length")
    yield String(self, "compressor_name", 31, strip='\0')
    yield UInt16(self, "depth", "Bit depth of image")
    yield Int16(self, "unknown")
github vstinner / hachoir / hachoir / parser / archive / zip.py View on Github external
def ZipStartCommonFields(self):
    yield ZipVersion(self, "version_needed", "Version needed")
    yield ZipGeneralFlags(self, "flags", "General purpose flag")
    yield Enum(UInt16(self, "compression", "Compression method"),
               COMPRESSION_METHOD)
    yield TimeDateMSDOS32(self, "last_mod", "Last modification file time")
    yield textHandler(UInt32(self, "crc32", "CRC-32"), hexadecimal)
    yield UInt32(self, "compressed_size", "Compressed size")
    yield UInt32(self, "uncompressed_size", "Uncompressed size")
    yield UInt16(self, "filename_length", "Filename length")
    yield UInt16(self, "extra_length", "Extra fields length")
github vstinner / hachoir / hachoir / parser / image / photoshop_metadata.py View on Github external
def createFields(self):
        yield FixedFloat32(self, "horiz_res")
        yield Enum(UInt16(self, "horiz_res_unit"), {1: 'px/in', 2: 'px/cm'})
        yield Enum(UInt16(self, "width_unit"), {1: 'inches', 2: 'cm', 3: 'points', 4: 'picas', 5: 'columns'})
        yield FixedFloat32(self, "vert_res")
        yield Enum(UInt16(self, "vert_res_unit"), {1: 'px/in', 2: 'px/cm'})
        yield Enum(UInt16(self, "height_unit"), {1: 'inches', 2: 'cm', 3: 'points', 4: 'picas', 5: 'columns'})