How to use the hachoir.core.text_handler.textHandler 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 / program / exe_res.py View on Github external
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 / video / mpeg_video.py View on Github external
if next == 0xff:
                padding += 1
                position += 8
            elif padding:
                yield PaddingBytes(self, "pad[]", padding)
                padding = None
                position = 0
            elif 0x40 <= next <= 0x7f:
                yield Bits(self, "scale_marker", 2)  # 1
                yield Bit(self, "scale")
                scale = self['scale'].value
                if scale:
                    scaleval = 1024
                else:
                    scaleval = 128
                yield textHandler(Bits(self, "size", 13), lambda field: str(field.value * scaleval))
            elif 0x00 <= next <= 0x3f:
                yield Bits(self, "ts_marker", 2)  # 0
                yield Bit(self, "has_pts")
                yield Bit(self, "has_dts")
                if self['has_pts'].value:
                    yield Timestamp(self, "pts")
                if self['has_dts'].value:
                    yield PaddingBits(self, "pad[]", 4)
                    yield Timestamp(self, "dts")
                if self.current_size % 8 == 4:
                    yield PaddingBits(self, "pad[]", 4)
                break
            elif 0x80 <= next <= 0xbf:
                # MPEG-2 extension
                yield PacketElement(self, "pkt")
                break
github vstinner / hachoir / hachoir / parser / audio / midi.py View on Github external
def createFields(self):
        yield Integer(self, "time", "Delta time in ticks")
        next = self.stream.readBits(
            self.absolute_address + self.current_size, 8, self.root.endian)
        if next & 0x80 == 0:
            # "Running Status" command
            if self.prev_command is None:
                raise ParserError(
                    "Running Status command not preceded by another command.")
            self.command = self.prev_command.command
        else:
            yield Enum(textHandler(UInt8(self, "command"), hexadecimal), self.COMMAND_DESC)
            self.command = self["command"].value
        if self.command == 0xFF:
            yield Enum(textHandler(UInt8(self, "meta_command"), hexadecimal), self.META_COMMAND_DESC)
            yield UInt8(self, "data_len")
            size = self["data_len"].value
            if size:
                command = self["meta_command"].value
                if command in self.META_COMMAND_PARSER:
                    parser = self.META_COMMAND_PARSER[command]
                else:
                    parser = None
                if parser is not None:
                    yield from parser(self, size)
                else:
                    yield RawBytes(self, "data", size)
        else:
github vstinner / hachoir / hachoir / parser / program / nds.py View on Github external
def createFields(self):
        yield textHandler(UInt64(self, "id"), hexadecimal)
        if self["id"].value == 0xe7ffdeffe7ffdeff:  # indicates that secure area is decrypted
            yield Bytes(self, "fixed[]", 6)  # always \xff\xde\xff\xe7\xff\xde
            yield Crc16(self, "header_crc16", self.stream.readBytes(self.absolute_address + (16 * 8), 2048 - 16))
            yield RawBytes(self, "unknown[]", 2048 - 16 - 2)
            yield Bytes(self, "fixed[]", 2)  # always \0\0
        else:
            yield RawBytes(self, "encrypted[]", 2048 - 8)
github vstinner / hachoir / hachoir / parser / archive / bzip2_parser.py View on Github external
def createFields(self):
        end = False
        while not end:
            marker = self.stream.readBits(
                self.absolute_address + self.current_size, 48, self.endian)
            if marker == self.START_BLOCK:
                yield Bzip2Block(self, "block[]")
            elif marker == self.END_STREAM:
                yield textHandler(Bits(self, "stream_end", 48, "End-of-stream marker"), hexadecimal)
                yield textHandler(UInt32(self, "crc32", "CRC32 for entire stream"), hexadecimal)
                padding = paddingSize(self.current_size, 8)
                if padding:
                    yield PaddingBits(self, "padding[]", padding)
                end = True
            else:
                raise ParserError("Invalid marker 0x%02X!" % marker)
github vstinner / hachoir / hachoir / parser / image / bmp.py View on Github external
if self["header_size"].value < 40:
            return
        yield Enum(UInt32(self, "compression", "Compression method"), BmpFile.COMPRESSION_NAME)
        yield UInt32(self, "image_size", "Image size (bytes)")
        yield UInt32(self, "horizontal_dpi", "Horizontal DPI")
        yield UInt32(self, "vertical_dpi", "Vertical DPI")
        yield UInt32(self, "used_colors", "Number of color used")
        yield UInt32(self, "important_color", "Number of import colors")

        # Version 4 (108 bytes)
        if self["header_size"].value < 108:
            return
        yield textHandler(UInt32(self, "red_mask"), hexadecimal)
        yield textHandler(UInt32(self, "green_mask"), hexadecimal)
        yield textHandler(UInt32(self, "blue_mask"), hexadecimal)
        yield textHandler(UInt32(self, "alpha_mask"), hexadecimal)
        yield Enum(UInt32(self, "color_space"), self.color_space_name)
        yield CIEXYZ(self, "red_primary")
        yield CIEXYZ(self, "green_primary")
        yield CIEXYZ(self, "blue_primary")
        yield UInt32(self, "gamma_red")
        yield UInt32(self, "gamma_green")
        yield UInt32(self, "gamma_blue")
github vstinner / hachoir / hachoir / parser / container / riff.py View on Github external
def parseAnimationRate(self):
    while not self.eof:
        yield textHandler(UInt32(self, "rate[]"), formatJiffie)
github vstinner / hachoir / hachoir / parser / misc / lnk.py View on Github external
def createFields(self):
        yield UInt32(self, "length", "Length of this structure")
        if not self["length"].value:
            return

        yield Enum(textHandler(UInt32(self, "signature", "Signature determining the function of this structure"), hexadecimal), self.INFO_TYPE)

        if self["signature"].value == 0xA0000003:
            # Hostname and Other Stuff
            yield UInt32(self, "remaining_length")
            yield UInt32(self, "unknown[]")
            yield String(self, "hostname", 16, "Computer hostname on which shortcut was last modified", strip="\0")
            yield RawBytes(self, "unknown[]", 32)
            yield RawBytes(self, "unknown[]", 32)

        elif self["signature"].value == 0xA0000005:
            # Special Folder Info
            yield Enum(UInt32(self, "special_folder_id", "ID of the special folder"), self.SPECIAL_FOLDER)
            yield UInt32(self, "offset", "Offset to Item ID entry")

        elif self["signature"].value in (0xA0000001, 0xA0000006, 0xA0000007):
            if self["signature"].value == 0xA0000001:  # Link Target Information
github vstinner / hachoir / hachoir / parser / archive / cab.py View on Github external
def createFields(self):
        yield textHandler(UInt32(self, "crc32"), hexadecimal)
        yield UInt16(self, "size")
        yield UInt16(self, "uncompressed_size", "If this is 0, this block is continued in a subsequent cabinet")
        if self["/flags/has_reserved"].value and self["/reserved_data_size"].value:
            yield RawBytes(self, "reserved_data", self["/reserved_data_size"].value, "Per-datablock reserved area")
        compr_method = self.parent.folder["compr_method"].value
        if compr_method == 0:  # Uncompressed
            yield RawBytes(self, "data", self["size"].value, "Folder Data")
            self.parent.uncompressed_data += self["data"].value
        elif compr_method == 1:  # MSZIP
            yield String(self, "mszip_signature", 2, "MSZIP Signature (CK)")
            yield DeflateBlock(self, "deflate_block", self.parent.uncompressed_data)
            padding = paddingSize(self.current_size, 8)
            if padding:
                yield PaddingBits(self, "padding[]", padding)
            self.parent.uncompressed_data = self["deflate_block"].uncomp_data
        elif compr_method == 2:  # Quantum
github vstinner / hachoir / hachoir / parser / file_system / mbr.py View on Github external
def createFields(self):
        yield RawBytes(self, "program", 446, "Boot program (Intel x86 machine code)")
        yield PartitionHeader(self, "header[0]")
        yield PartitionHeader(self, "header[1]")
        yield PartitionHeader(self, "header[2]")
        yield PartitionHeader(self, "header[3]")
        yield textHandler(UInt16(self, "signature", "Signature (0xAA55)"), hexadecimal)