How to use the hachoir.field.String 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 / container / realmedia.py View on Github external
def createFields(self):
        yield String(self, "tag", 4, "Chunk FourCC", charset="ASCII")
        yield UInt32(self, "size", "Chunk Size")
        yield UInt16(self, "version", "Chunk Version")

        if self.parse_func:
            yield from self.parse_func(self)
        else:
            size = (self.size - self.current_size) // 8
            if size:
                yield RawBytes(self, "raw", size)
github vstinner / hachoir / hachoir / parser / misc / msoffice.py View on Github external
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")
                elif hasattr(PowerPointDocument, obj_type):
                    field = getattr(PowerPointDocument, obj_type)(self, "data")
                    field._size = obj_len * 8
                    yield field
                else:
                    yield RawBytes(self, "data", obj_len)
github vstinner / hachoir / hachoir / parser / archive / tar.py View on Github external
def createFields(self):
        yield String(self, "name", 100, "Name", strip="\0", charset="ISO-8859-1")
        yield String(self, "mode", 8, "Mode", strip=" \0", charset="ASCII")
        yield String(self, "uid", 8, "User ID", strip=" \0", charset="ASCII")
        yield String(self, "gid", 8, "Group ID", strip=" \0", charset="ASCII")
        yield String(self, "size", 12, "Size", strip=" \0", charset="ASCII")
        yield String(self, "mtime", 12, "Modification time", strip=" \0", charset="ASCII")
        yield String(self, "check_sum", 8, "Check sum", strip=" \0", charset="ASCII")
        yield Enum(UInt8(self, "type", "Type"), self.type_name)
        yield String(self, "lname", 100, "Link name", strip=" \0", charset="ISO-8859-1")
        yield String(self, "magic", 8, "Magic", strip=" \0", charset="ASCII")
        yield String(self, "uname", 32, "User name", strip=" \0", charset="ISO-8859-1")
        yield String(self, "gname", 32, "Group name", strip=" \0", charset="ISO-8859-1")
        yield String(self, "devmajor", 8, "Dev major", strip=" \0", charset="ASCII")
        yield String(self, "devminor", 8, "Dev minor", strip=" \0", charset="ASCII")
        yield String(self, "prefix", 155, "Prefix for filename", strip="\0", charset="ASCII")
        yield NullBytes(self, "padding", 12, "Padding (zero)")

        filesize = self.getOctal("size")
        if filesize:
            yield SubFile(self, "content", filesize, filename=self["name"].value)

        size = paddingSize(self.current_size // 8, 512)
        if size:
            yield NullBytes(self, "padding_end", size, "Padding (512 align)")
github vstinner / hachoir / hachoir / parser / audio / au.py View on Github external
def createFields(self):
        yield String(self, "signature", 4, 'Format signature (".snd")', charset="ASCII")
        yield UInt32(self, "data_ofs", "Data offset")
        yield filesizeHandler(UInt32(self, "data_size", "Data size"))
        yield Enum(UInt32(self, "codec", "Audio codec"), self.CODEC_NAME)
        yield displayHandler(UInt32(self, "sample_rate", "Number of samples/second"), humanFrequency)
        yield UInt32(self, "channels", "Number of interleaved channels")

        size = self["data_ofs"].value - self.current_size // 8
        if 0 < size:
            yield String(self, "info", size, "Information", strip=" \0", charset="ISO-8859-1")

        size = min(self["data_size"].value,
                   (self.size - self.current_size) // 8)
        yield RawBytes(self, "audio_data", size, "Audio data")
github vstinner / hachoir / hachoir / parser / file_system / fat.py View on Github external
def createFields(self):
        if not self.LFN:
            yield String(self, "name", 8, "DOS file name (padded with spaces)",
                         strip=' ', charset="ASCII")
            yield String(self, "ext", 3, "DOS file extension (padded with spaces)",
                         strip=' ', charset="ASCII")
            yield Bit(self, "read_only")
            yield Bit(self, "hidden")
            yield Bit(self, "system")
            yield Bit(self, "volume_label")
            yield Bit(self, "directory")
            yield Bit(self, "archive")
            yield Bit(self, "device")
            yield Bit(self, "unused")
            yield RawBytes(self, "reserved", 1, "Something about the case")
            yield Date(self, "create")
            yield Date(self, "access")
            if self.parent.parent.version > 16:
                yield UInt16(self, "cluster_hi")
            else:
                yield UInt16(self, "ea_index")
github vstinner / hachoir / hachoir / parser / container / mp4.py View on Github external
def createFields(self):
        yield UInt8(self, "version", "Version")
        yield NullBits(self, "flags", 24)
        yield String(self, "creator", 4)
        yield String(self, "subtype", 4)
        yield String(self, "manufacturer", 4)
        yield UInt32(self, "res_flags")
        yield UInt32(self, "res_flags_mask")
        if self.root.is_mpeg4:
            yield CString(self, "name", charset="UTF-8")
        else:
            yield PascalString8(self, "name")
github vstinner / hachoir / hachoir / parser / audio / itunesdb.py View on Github external
def createFields(self):
        yield String(self, "header_id", 4, "DataBase Header Markup (\"mhbd\")", charset="ISO-8859-1")
        yield UInt32(self, "header_length", "Header Length")
        yield UInt32(self, "entry_length", "Entry Length")
        yield UInt32(self, "unknown[]")
        yield UInt32(self, "version_number", "Version Number")
        yield UInt32(self, "child_number", "Number of Children")
        yield UInt64(self, "id", "ID for this database")
        yield UInt16(self, "unknown[]")
        yield UInt32(self, "unknown[]")
        yield UInt64(self, "unknown[]")
        yield UInt16(self, "unknown[]")
        yield UInt16(self, "hashing_scheme[]", "Algorithm used to calculate the database hash")
        yield NullBytes(self, "unknown[]", 20)
        yield String(self, "language_id", 2, "Language ID")
        yield UInt64(self, "persistent_id", "Library Persistent ID")
        yield UInt32(self, "unknown[]")
        yield UInt32(self, "unknown[]")
        yield RawBytes(self, "hash[]", 20)
        yield Int32(self, "timezone_offset[]", "Timezone offset in seconds")
        yield UInt16(self, "unknown[]")
        yield RawBytes(self, "iphone_hash[]", 45)
        size = self["header_length"].value - self.current_size / 8
        if size > 0:
            yield NullBytes(self, "padding", size)
        for i in range(self["child_number"].value):
            yield DataSet(self, "dataset[]")
        padding = self.seekByte(self["entry_length"].value, "entry padding")
        if padding:
            yield padding
github vstinner / hachoir / hachoir / parser / misc / mapsforge_map.py View on Github external
def createFields(self):
        if self["/have_debug"].value:
            yield String(self, "signature", 16)
            if self['signature'].value != "+++IndexStart+++":
                raise ValueError

        indexEntries = []
        numTiles = None
        i = 0
        while True:
            entry = TileIndexEntry(self, "tile_index_entry[]")
            indexEntries.append(entry)
            yield entry

            i += 1
            if numTiles is None:
                # calculate number of tiles (TODO: better calc this from map
                # bounding box)
                firstOffset = self["tile_index_entry[0]"]["offset"].value
github vstinner / hachoir / hachoir / parser / misc / file_3do.py View on Github external
def createFields(self):
        # Read file signature, and fix endian if needed
        yield String(self, "file_sig", 4, "File signature", charset="ASCII")
        if self["file_sig"].value == "MODL":
            self.endian = BIG_ENDIAN

        # Read file content
        yield Materials(self, "materials")
        yield String(self, "model_name", 32, "model file name", strip="\0")
        yield RawBytes(self, "unknown[]", 4)
        yield UInt32(self, "ngeosets")
        for index in range(self["ngeosets"].value):
            yield Geoset(self, "geoset[]")
        yield RawBytes(self, "unknown[]", 4)
        yield Nodes(self, "nodes")
        yield Float32(self, "model_radius")
        yield Vertex(self, "insertion_offset")

        # Read the end of the file
github vstinner / hachoir / hachoir / parser / archive / rar.py View on Github external
yield MSDOSFileAttr32(s, "file_attr", "File attributes")
    else:
        yield textHandler(UInt32(s, "file_attr", "File attributes"), hexadecimal)

    # Start additional field from unrar
    if s["flags/is_large"].value:
        yield filesizeHandler(UInt64(s, "large_size", "Extended 64bits filesize"))

    # End additional field
    size = s["filename_length"].value
    if size > 0:
        if s["flags/is_unicode"].value:
            charset = "UTF-8"
        else:
            charset = "ISO-8859-15"
        yield String(s, "filename", size, "Filename", charset=charset)
    # Start additional fields from unrar - file only
    if is_file:
        if s["flags/has_salt"].value:
            yield textHandler(UInt8(s, "salt", "Salt"), hexadecimal)
        if s["flags/has_ext_time"].value:
            yield ExtTime(s, "extra_time", "Extra time info")