示例#1
0
 def createFields(self):
     if self.has_all_byte:
         yield Enum(UInt8(self, "all_defined"), {0: 'False', 1: 'True'})
         if self['all_defined'].value:
             return
     nbytes = alignValue(self.num, 8) // 8
     ctr = 0
     for i in range(nbytes):
         for j in reversed(range(8)):
             yield Bit(self, "bit[%d]" % (ctr + j))
         ctr += 8
示例#2
0
文件: s3m.py 项目: valnar1/SickGear
 def getLastProperties(self):
     yield UInt8(self, "glob_vol", "Global volume")
     yield UInt8(self, "init_speed", "Initial speed (command A)")
     yield UInt8(self, "init_tempo", "Initial tempo (command T)")
     yield Bits(self, "volume", 7)
     yield Bit(self, "stereo")
     yield UInt8(self, "click_removal", "Number of GUS channels to run to prevent clicks")
     yield UInt8(self, "panning_info")
     yield RawBytes(self, "reserved[]", 8)
     yield UInt16(self, "custom_data_parapointer",
                  "Parapointer to special custom data (not used by ST3.01)")
示例#3
0
 def createFields(self):
     yield String(self, 'capture_pattern', 4, charset="ASCII")
     if self['capture_pattern'].value != "OggS":
         self.warning(
             'Invalid signature. An Ogg page must start with "OggS".')
     yield UInt8(self, 'stream_structure_version')
     yield Bit(self, 'continued_packet')
     yield Bit(self, 'first_page')
     yield Bit(self, 'last_page')
     yield NullBits(self, 'unused', 5)
     yield UInt64(self, 'abs_granule_pos')
     yield textHandler(UInt32(self, 'serial'), hexadecimal)
     yield UInt32(self, 'page')
     yield textHandler(UInt32(self, 'checksum'), hexadecimal)
     yield UInt8(self, 'lacing_size')
     if self.lacing_size:
         yield Lacing(self, "lacing", size=self.lacing_size * 8)
         yield Segments(self,
                        "segments",
                        size=self._size - self._current_size)
示例#4
0
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")
    yield UInt32(self, "height", "Height in pixel")
    yield UInt32(self, "scale")
    yield UInt32(self, "rate")
    yield UInt32(self, "start")
    yield UInt32(self, "length")
示例#5
0
    def createFields(self):
        yield SubTileBitmap(self, "sub_tile_bitmap")
        # yield Bits(self, "sub_tile_bitmap", 16)

        yield Bits(self, "layer", 4)
        yield Bits(self, "num_tags", 4)

        for i in range(self["num_tags"].value):
            yield UIntVbe(self, "tag_id[]")

        yield Bit(self, "have_name")
        yield Bit(self, "have_house_number")
        yield Bit(self, "have_ref")
        yield Bit(self, "have_label_position")
        yield Bit(self, "have_num_way_blocks")
        yield Enum(Bit(self, "coord_encoding"), CoordinateEncoding)
        yield PaddingBits(self, "pad[]", 2)

        if self["have_name"].value:
            yield VbeString(self, "name")
        if self["have_house_number"].value:
            yield VbeString(self, "house_number")
        if self["have_ref"].value:
            yield VbeString(self, "ref")
        if self["have_label_position"].value:
            yield IntVbe(self, "label_lat_diff")
            yield IntVbe(self, "label_lon_diff")
        numWayDataBlocks = 1
        if self["have_num_way_blocks"].value:
            yield UIntVbe(self, "num_way_blocks")
            numWayDataBlocks = self["num_way_blocks"].value

        for i in range(numWayDataBlocks):
            yield WayData(self, "way_data[]")
示例#6
0
    def createFields(self):
        yield textHandler(
            UInt32(self, "magic", "File information magic (0xFEEF04BD)"),
            hexadecimal)
        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")
示例#7
0
 def createFields(self):
     yield Bit(self, "debug", "Print debug info upon mount")
     yield Bit(self, "bsdgroups",
               "New files take the gid of the containing dir")
     yield Bit(self, "xattr_user", "Support userspace-provided xattrs")
     yield Bit(self, "acl", "Support POSIX access control lists")
     yield Bit(self, "uid16", "Do not support 32-bit UIDs")
     yield Enum(Bits(self, "jmode", 2, "Journaling mode"), {
         0: "none",
         1: "data",
         2: "ordered",
         3: "wback"
     })
     yield Bit(self, "reserved[]")
     yield Bit(self, "nobarrier", "Disable write flushes")
     yield Bit(
         self, "block_validity",
         "Track metadata blocks to avoid treating them as data blocks")
     yield Bit(self, "discard",
               "Tell the storage device when blocks become unused")
     yield Bit(self, "nodelalloc", "Disable delayed allocation")
     yield PaddingBits(self, "reserved[]", 20)
示例#8
0
 def createFields(self):
     yield Enum(UInt8(self, "typecode"), TYPECODE_NAMES)
     yield PascalString16(self, "className", charset="UTF-8")
     yield Int64(self, "serialVersionUID")
     self.root.newHandle(self)
     yield NullBits(self, "classDescFlags_reserved", 3)
     yield Bit(self, "classDescFlags_enum", "Is the class an Enum?")
     yield Bit(
         self, "classDescFlags_block_data",
         "Was the externalizable's block data written using stream version 2?"
     )
     yield Bit(self, "classDescFlags_externalizable",
               "Does the class implement java.io.Externalizable?")
     yield Bit(self, "classDescFlags_serializable",
               "Does the class implement java.io.Serializable?")
     yield Bit(self, "classDescFlags_write_method",
               "Does the class have a writeObject method?")
     yield Int16(self, "fieldDesc_count")
     for i in range(self['fieldDesc_count'].value):
         yield FieldDesc(self, "fieldDesc[]")
     yield ClassAnnotation(self, "classAnnotation")
     yield SerializedContent(self, "superClassDesc")
示例#9
0
def parseDeclareFunctionV7(parent, size):
    yield CString(parent, "name")
    argCount = UInt16(parent, "arg_count")
    yield argCount
    yield UInt8(parent, "reg_count")
    yield Bits(parent, "reserved", 7)
    yield Bit(parent, "preload_global")
    yield Bit(parent, "preload_parent")
    yield Bit(parent, "preload_root")
    yield Bit(parent, "suppress_super")
    yield Bit(parent, "preload_super")
    yield Bit(parent, "suppress_arguments")
    yield Bit(parent, "preload_arguments")
    yield Bit(parent, "suppress_this")
    yield Bit(parent, "preload_this")
    for i in range(argCount.value):
        yield UInt8(parent, "register[]")
        yield CString(parent, "arg[]")
    yield UInt16(parent, "function_length")
示例#10
0
文件: asn1.py 项目: valnar1/SickGear
 def createFields(self):
     yield Enum(Bits(self, "class", 2), self.CLASS_DESC)
     yield Enum(Bit(self, "form"), self.FORM_DESC)
     if self['class'].value == 0:
         yield Enum(Bits(self, "type", 5), self.TYPE_DESC)
     else:
         yield Bits(self, "type", 5)
     yield ASNInteger(self, "size", "Size in bytes")
     size = self["size"].value
     if size:
         if self._handler:
             yield from self._handler(self, size)
         else:
             yield RawBytes(self, "raw", size)
示例#11
0
文件: cab.py 项目: valnar1/SickGear
 def createFields(self):
     yield Bit(self, "readonly")
     yield Bit(self, "hidden")
     yield Bit(self, "system")
     yield Bits(self, "reserved[]", 2)
     yield Bit(self, "archive", "Has the file been modified since the last backup?")
     yield Bit(self, "exec", "Run file after extraction?")
     yield Bit(self, "name_is_utf", "Is the filename using UTF-8?")
     yield Bits(self, "reserved[]", 8)
示例#12
0
文件: jpeg.py 项目: valnar1/SickGear
 def createFields(self):
     if self.stream.readBytes(self.absolute_address, 5) != b"Adobe":
         yield RawBytes(self, "raw", self.size // 8, "Raw data")
         return
     yield String(self, "adobe", 5, "\"Adobe\" string", charset="ASCII")
     yield UInt16(self, "version", "DCT encoder version")
     yield Enum(Bit(self, "flag00"), {
         False: "Chop down or subsampling",
         True: "Blend"
     })
     yield NullBits(self, "flags0_reserved", 15)
     yield NullBytes(self, "flags1", 2)
     yield Enum(
         UInt8(self, "color_transform", "Colorspace transformation code"),
         self.COLORSPACE_TRANSFORMATION)
示例#13
0
 def createFields(self):
     yield UInt8(self, "size", "Total length of this FFN in bytes, minus 1")
     self._size = self["size"].value * 8 + 8
     yield Bits(self, "prq", 2, "Pitch request")
     yield Bit(self, "fTrueType", "Is font a TrueType font?")
     yield Bits(self, "reserved[]", 1)
     yield Bits(self, "ff", 3, "Font Family ID")
     yield Bits(self, "reserved[]", 1)
     yield UInt16(self, "wWeight", "Base weight of font")
     yield UInt8(self, "chs", "Character set identifier")
     yield UInt8(self, "ixchSzAlt", "Index into name to the name of the alternate font")
     yield RawBytes(self, "panose", 10)
     yield RawBytes(self, "fs", 24, "Font Signature")
     yield CString(self, "name", charset="UTF-16-LE")
     if self["ixchSzAlt"].value != 0:
         yield CString(self, "nameAlt", charset="UTF-16-LE")
示例#14
0
文件: lzx.py 项目: valnar1/SickGear
 def createFields(self):
     self.uncompressed_data = ""
     self.r0 = 1
     self.r1 = 1
     self.r2 = 1
     yield Bit(self, "filesize_indicator")
     if self["filesize_indicator"].value:
         yield UInt32(self, "filesize")
     while self.current_size < self.size:
         block = LZXBlock(self, "block[]")
         yield block
         if self.size - self.current_size < 16:
             padding = paddingSize(self.address + self.current_size, 16)
             if padding:
                 yield PaddingBits(self, "padding[]", padding)
             break
示例#15
0
def parseAnimationHeader(self):
    yield UInt32(self, "hdr_size", "Size of header (36 bytes)")
    if self["hdr_size"].value != 36:
        self.warning("Animation header with unknown size (%s)" %
                     self["size"].value)
    yield UInt32(self, "nb_frame", "Number of unique Icons in this cursor")
    yield UInt32(self, "nb_step",
                 "Number of Blits before the animation cycles")
    yield UInt32(self, "cx")
    yield UInt32(self, "cy")
    yield UInt32(self, "bit_count")
    yield UInt32(self, "planes")
    yield UInt32(
        self, "jiffie_rate",
        "Default Jiffies (1/60th of a second) if rate chunk not present")
    yield Bit(self, "is_icon")
    yield NullBits(self, "padding", 31)
示例#16
0
 def createFields(self):
     yield FlashU30(self, "param_count")
     yield ABCMultinameIndex(self, "ret_type")
     for i in range(self["param_count"].value):
         yield ABCMultinameIndex(self, "param_type[]")
     yield ABCStringIndex(self, "name_index")
     yield Bit(self, "need_arguments")
     yield Bit(self, "need_activation")
     yield Bit(self, "need_rest")
     yield Bit(self, "has_optional")
     yield Bit(self, "ignore_rest")
     yield Bit(self, "explicit")
     yield Bit(self, "setsdxns")
     yield Bit(self, "has_paramnames")
     if self["has_optional"].value:
         yield ABCObjectArray(self, "optional", ABCValueKind)
     if self["has_paramnames"].value:
         for i in range(self["param_count"].value):
             yield FlashU30(self, "param_name[]")
示例#17
0
    def createFields(self):
        yield String(self, "file_magic", 20)
        yield UInt32(self, "header_size")
        yield UInt32(self, "file_version")
        yield UInt64(self, "file_size")
        yield UInt64(self, "creation_date")
        yield Int32(self, "min_lat")
        yield Int32(self, "min_lon")
        yield Int32(self, "max_lat")
        yield Int32(self, "max_lon")
        yield UInt16(self, "tile_size")
        yield VbeString(self, "projection")

        # flags
        yield Bit(self, "have_debug")
        yield Bit(self, "have_map_start")
        yield Bit(self, "have_start_zoom")
        yield Bit(self, "have_language_preference")
        yield Bit(self, "have_comment")
        yield Bit(self, "have_created_by")
        yield Bits(self, "reserved[]", 2)

        if self["have_map_start"].value:
            yield UInt32(self, "start_lat")
            yield UInt32(self, "start_lon")
        if self["have_start_zoom"].value:
            yield UInt8(self, "start_zoom")
        if self["have_language_preference"].value:
            yield VbeString(self, "language_preference")
        if self["have_comment"].value:
            yield VbeString(self, "comment")
        if self["have_created_by"].value:
            yield VbeString(self, "created_by")

        yield TagStringList(self, "poi_tags")
        yield TagStringList(self, "way_tags")

        yield UInt8(self, "num_zoom_intervals")
        for i in range(self["num_zoom_intervals"].value):
            yield ZoomIntervalCfg(self, "zoom_interval_cfg[]")

        for i in range(self["num_zoom_intervals"].value):
            zoomIntervalCfg = self["zoom_interval_cfg[%d]" % i]
            self.seekByte(zoomIntervalCfg["subfile_start"].value,
                          relative=False)
            yield ZoomSubFile(self,
                              "subfile[]",
                              size=zoomIntervalCfg["subfile_size"].value * 8,
                              zoomIntervalCfg=zoomIntervalCfg)
示例#18
0
文件: asf.py 项目: valnar1/SickGear
 def createFields(self):
     yield GUID(self, "type")
     yield GUID(self, "error_correction")
     yield UInt64(self, "time_offset")
     yield UInt32(self, "data_len")
     yield UInt32(self, "error_correct_len")
     yield Bits(self, "stream_index", 7)
     yield Bits(self, "reserved[]", 8)
     yield Bit(self, "encrypted", "Content is encrypted?")
     yield UInt32(self, "reserved[]")
     size = self["data_len"].value
     if size:
         tag = self["type"].value
         if tag in Object.TAG_INFO:
             name, parser = Object.TAG_INFO[tag][0:2]
             yield parser(self, name, size=size * 8)
         else:
             yield RawBytes(self, "data", size)
     size = self["error_correct_len"].value
     if size:
         yield RawBytes(self, "error_correct", size)
示例#19
0
 def createFields(self):
     self.osconfig = self.parent.osconfig
     if True:
         yield Enum(Bits(self, "type", 12), self.TYPE_NAME)
         yield Bit(self, "is_vector")
         yield NullBits(self, "padding", 32 - 12 - 1)
     else:
         yield Enum(Bits(self, "type", 32), self.TYPE_NAME)
     tag = self["type"].value
     kw = {}
     try:
         handler = self.TYPE_INFO[tag][1]
         if handler in (self.WidePascalString32, PascalString32):
             cur = self
             while not hasattr(cur, 'osconfig'):
                 cur = cur.parent
                 if cur is None:
                     raise LookupError('Cannot find osconfig')
             osconfig = cur.osconfig
             if tag == self.TYPE_LPSTR:
                 kw["charset"] = osconfig.charset
             else:
                 kw["charset"] = osconfig.utf16
         elif handler == TimestampWin64:
             if self.description == "TotalEditingTime":
                 handler = TimedeltaWin64
     except LookupError:
         handler = None
     if not handler:
         self.warning("OLE2: Unable to parse property of type %s" %
                      self["type"].display)
         # raise ParserError(
     elif self["is_vector"].value:
         yield UInt32(self, "count")
         for index in range(self["count"].value):
             yield handler(self, "item[]", **kw)
     else:
         yield handler(self, "value", **kw)
         self.createValue = lambda: self["value"].value
示例#20
0
文件: swf.py 项目: valnar1/SickGear
def parseStartSound(parent, size):
    yield UInt16(parent, "sound_id")
    yield Bit(parent, "has_in_point")
    yield Bit(parent, "has_out_point")
    yield Bit(parent, "has_loops")
    yield Bit(parent, "has_envelope")
    yield Bit(parent, "no_multiple")
    yield Bit(parent, "stop_playback")
    yield NullBits(parent, "reserved", 2)

    if parent["has_in_point"].value:
        yield UInt32(parent, "in_point")
    if parent["has_out_point"].value:
        yield UInt32(parent, "out_point")
    if parent["has_loops"].value:
        yield UInt16(parent, "loop_count")
    if parent["has_envelope"].value:
        yield SoundEnvelope(parent, "envelope")
示例#21
0
    def createFields(self):
        yield Bit(self, "last_metadata_block",
                  "True if this is the last metadata block")
        yield Enum(Bits(self, "block_type", 7, "Metadata block header type"),
                   self.BLOCK_TYPE_DESC)
        yield UInt24(
            self, "metadata_length",
            "Length of following metadata in bytes (doesn't include this header)"
        )

        block_type = self["block_type"].value
        size = self["metadata_length"].value
        if not size:
            return
        try:
            handler = self.BLOCK_TYPES[block_type][2]
        except KeyError:
            handler = None
        if handler:
            yield handler(self, "content", size=size * 8)
        elif self["block_type"].value == 1:
            yield NullBytes(self, "padding", size)
        else:
            yield RawBytes(self, "rawdata", size)
示例#22
0
文件: id3.py 项目: valnar1/SickGear
    def createFields(self):
        if 3 <= self["../ver_major"].value:
            # ID3 v2.3 and 2.4
            yield Enum(String(self, "tag", 4, "Tag", charset="ASCII", strip="\0"), ID3_Chunk.tag23_name)
            if 4 <= self["../ver_major"].value:
                yield ID3_Size(self, "size")   # ID3 v2.4
            else:
                yield UInt32(self, "size")   # ID3 v2.3

            yield Bit(self, "tag_alter", "Tag alter preservation")
            yield Bit(self, "file_alter", "Tag alter preservation")
            yield Bit(self, "rd_only", "Read only?")
            yield NullBits(self, "padding[]", 5)

            yield Bit(self, "compressed", "Frame is compressed?")
            yield Bit(self, "encrypted", "Frame is encrypted?")
            yield Bit(self, "group", "Grouping identity")
            yield NullBits(self, "padding[]", 5)
            size = self["size"].value
            is_compressed = self["compressed"].value
        else:
            # ID3 v2.2
            yield Enum(String(self, "tag", 3, "Tag", charset="ASCII", strip="\0"), ID3_Chunk.tag22_name)
            yield UInt24(self, "size")
            size = self["size"].value - self.current_size // 8 + 6
            is_compressed = False

        if size:
            cls = None
            if not(is_compressed):
                tag = self["tag"].value
                if tag in ID3_Chunk.handler:
                    cls = ID3_Chunk.handler[tag]
                elif tag[0] == "T":
                    cls = ID3_StringCharset
            if cls:
                yield cls(self, "content", "Content", size=size * 8)
            else:
                yield RawBytes(self, "content", size, "Raw data content")
示例#23
0
 def createFields(self):
     yield Bit(self, "final", "Is this the final block?")  # BFINAL
     yield Enum(
         Bits(self, "compression_type", 2),  # BTYPE
         {
             0: "None",
             1: "Fixed Huffman",
             2: "Dynamic Huffman",
             3: "Reserved"
         })
     if self["compression_type"].value == 0:  # no compression
         # align on byte boundary
         padding = paddingSize(self.current_size + self.absolute_address, 8)
         if padding:
             yield PaddingBits(self, "padding[]", padding)
         yield Int16(self, "len")
         yield Int16(self, "nlen", "One's complement of len")
         if self["len"].value != ~self["nlen"].value:
             raise ParserError(
                 "len must be equal to the one's complement of nlen!")
         # null stored blocks produced by some encoders (e.g. PIL)
         if self["len"].value:
             yield RawBytes(self, "data", self["len"].value,
                            "Uncompressed data")
         return
     elif self["compression_type"].value == 1:  # Fixed Huffman
         length_tree = {}  # (size, huffman code): value
         distance_tree = {}
         for i in range(144):
             length_tree[(8, i + 48)] = i
         for i in range(144, 256):
             length_tree[(9, i + 256)] = i
         for i in range(256, 280):
             length_tree[(7, i - 256)] = i
         for i in range(280, 288):
             length_tree[(8, i - 88)] = i
         for i in range(32):
             distance_tree[(5, i)] = i
     elif self["compression_type"].value == 2:  # Dynamic Huffman
         yield Bits(self, "huff_num_length_codes", 5,
                    "Number of Literal/Length Codes, minus 257")
         yield Bits(self, "huff_num_distance_codes", 5,
                    "Number of Distance Codes, minus 1")
         yield Bits(self, "huff_num_code_length_codes", 4,
                    "Number of Code Length Codes, minus 4")
         code_length_code_lengths = [0] * 19  # confusing variable name...
         for i in self.CODE_LENGTH_ORDER[:self["huff_num_code_length_codes"]
                                         .value + 4]:
             field = Bits(self, "huff_code_length_code[%i]" % i, 3,
                          "Code lengths for the code length alphabet")
             yield field
             code_length_code_lengths[i] = field.value
         code_length_tree = build_tree(code_length_code_lengths)
         length_code_lengths = []
         distance_code_lengths = []
         for numcodes, name, lengths in (
             (self["huff_num_length_codes"].value + 257, "length",
              length_code_lengths),
             (self["huff_num_distance_codes"].value + 1, "distance",
              distance_code_lengths)):
             while len(lengths) < numcodes:
                 field = HuffmanCode(self, "huff_%s_code[]" % name,
                                     code_length_tree)
                 value = field.realvalue
                 if value < 16:
                     prev_value = value
                     field._description = "Literal Code Length %i (Huffman Code %i)" % (
                         value, field.value)
                     yield field
                     lengths.append(value)
                 else:
                     info = {
                         16: (3, 6, 2),
                         17: (3, 10, 3),
                         18: (11, 138, 7)
                     }[value]
                     if value == 16:
                         repvalue = prev_value
                     else:
                         repvalue = 0
                     field._description = "Repeat Code %i, Repeating value (%i) %i to %i times (Huffman Code %i)" % (
                         value, repvalue, info[0], info[1], field.value)
                     yield field
                     extrafield = Bits(
                         self, "huff_%s_code_extra[%s" %
                         (name, field.name.split('[')[1]), info[2])
                     num_repeats = extrafield.value + info[0]
                     extrafield._description = "Repeat Extra Bits (%i), total repeats %i" % (
                         extrafield.value, num_repeats)
                     yield extrafield
                     lengths += [repvalue] * num_repeats
         length_tree = build_tree(length_code_lengths)
         distance_tree = build_tree(distance_code_lengths)
     else:
         raise ParserError("Unsupported compression type 3!")
     while True:
         field = HuffmanCode(self, "length_code[]", length_tree)
         value = field.realvalue
         if value < 256:
             field._description = "Literal Code %r (Huffman Code %i)" % (
                 chr(value), field.value)
             yield field
             self.uncomp_data += chr(value)
         if value == 256:
             field._description = "Block Terminator Code (256) (Huffman Code %i)" % field.value
             yield field
             break
         elif value > 256:
             info = self.LENGTH_SYMBOLS[value]
             if info[2] == 0:
                 field._description = "Length Code %i, Value %i (Huffman Code %i)" % (
                     value, info[0], field.value)
                 length = info[0]
                 yield field
             else:
                 field._description = "Length Code %i, Values %i to %i (Huffman Code %i)" % (
                     value, info[0], info[1], field.value)
                 yield field
                 extrafield = Bits(
                     self, "length_extra[%s" % field.name.split('[')[1],
                     info[2])
                 length = extrafield.value + info[0]
                 extrafield._description = "Length Extra Bits (%i), total length %i" % (
                     extrafield.value, length)
                 yield extrafield
             field = HuffmanCode(self, "distance_code[]", distance_tree)
             value = field.realvalue
             info = self.DISTANCE_SYMBOLS[value]
             if info[2] == 0:
                 field._description = "Distance Code %i, Value %i (Huffman Code %i)" % (
                     value, info[0], field.value)
                 distance = info[0]
                 yield field
             else:
                 field._description = "Distance Code %i, Values %i to %i (Huffman Code %i)" % (
                     value, info[0], info[1], field.value)
                 yield field
                 extrafield = Bits(
                     self, "distance_extra[%s" % field.name.split('[')[1],
                     info[2])
                 distance = extrafield.value + info[0]
                 extrafield._description = "Distance Extra Bits (%i), total length %i" % (
                     extrafield.value, distance)
                 yield extrafield
             self.uncomp_data = extend_data(self.uncomp_data, length,
                                            distance)
示例#24
0
def parseFontHeader(self):
    yield UInt16(self, "maj_ver", "Major version")
    yield UInt16(self, "min_ver", "Minor version")
    yield UInt16(self, "font_maj_ver", "Font major version")
    yield UInt16(self, "font_min_ver", "Font minor version")
    yield textHandler(UInt32(self, "checksum"), hexadecimal)
    yield Bytes(self, "magic", 4, r"Magic string (\x5F\x0F\x3C\xF5)")
    if self["magic"].value != b"\x5F\x0F\x3C\xF5":
        raise ParserError("TTF: invalid magic of font header")

    # Flags
    yield Bit(self, "y0", "Baseline at y=0")
    yield Bit(self, "x0", "Left sidebearing point at x=0")
    yield Bit(self, "instr_point", "Instructions may depend on point size")
    yield Bit(self, "ppem", "Force PPEM to integer values for all")
    yield Bit(self, "instr_width", "Instructions may alter advance width")
    yield Bit(self, "vertical", "e laid out vertically?")
    yield PaddingBits(self, "reserved[]", 1)
    yield Bit(self, "linguistic", "Requires layout for correct linguistic rendering?")
    yield Bit(self, "gx", "Metamorphosis effects?")
    yield Bit(self, "strong", "Contains strong right-to-left glyphs?")
    yield Bit(self, "indic", "contains Indic-style rearrangement effects?")
    yield Bit(self, "lossless", "Data is lossless (Agfa MicroType compression)")
    yield Bit(self, "converted", "Font converted (produce compatible metrics)")
    yield Bit(self, "cleartype", "Optimised for ClearType")
    yield Bits(self, "adobe", 2, "(used by Adobe)")

    yield UInt16(self, "unit_per_em", "Units per em")
    if not(16 <= self["unit_per_em"].value <= 16384):
        raise ParserError("TTF: Invalid unit/em value")
    yield UInt32(self, "created_high")
    yield TimestampMac32(self, "created")
    yield UInt32(self, "modified_high")
    yield TimestampMac32(self, "modified")
    yield UInt16(self, "xmin")
    yield UInt16(self, "ymin")
    yield UInt16(self, "xmax")
    yield UInt16(self, "ymax")

    # Mac style
    yield Bit(self, "bold")
    yield Bit(self, "italic")
    yield Bit(self, "underline")
    yield Bit(self, "outline")
    yield Bit(self, "shadow")
    yield Bit(self, "condensed", "(narrow)")
    yield Bit(self, "expanded")
    yield PaddingBits(self, "reserved[]", 9)

    yield UInt16(self, "lowest", "Smallest readable size in pixels")
    yield Enum(UInt16(self, "font_dir", "Font direction hint"), DIRECTION_NAME)
    yield Enum(UInt16(self, "ofst_format"), {0: "short offsets", 1: "long"})
    yield UInt16(self, "glyph_format", "(=0)")
示例#25
0
    def createFields(self):
        yield Bytes(self, "signature", 2, "New executable signature (NE)")
        yield UInt8(self, "link_ver", "Linker version number")
        yield UInt8(self, "link_rev", "Linker revision number")
        yield UInt16(self, "entry_table_ofst", "Offset to the entry table")
        yield UInt16(self, "entry_table_size",
                     "Length (in bytes) of the entry table")
        yield PaddingBytes(self, "reserved[]", 4)

        yield Bit(self, "is_dll", "Is a dynamic-link library (DLL)?")
        yield Bit(self, "is_win_app", "Is a Windows application?")
        yield PaddingBits(self, "reserved[]", 9)
        yield Bit(self, "first_seg_code",
                  "First segment contains code that loads the application?")
        yield NullBits(self, "reserved[]", 1)
        yield Bit(self, "link_error", "Load even if linker detects errors?")
        yield NullBits(self, "reserved[]", 1)
        yield Bit(self, "is_lib", "Is a library module?")

        yield UInt16(self, "auto_data_seg", "Automatic data segment number")
        yield filesizeHandler(
            UInt16(self, "local_heap_size",
                   "Initial size (in bytes) of the local heap"))
        yield filesizeHandler(
            UInt16(self, "stack_size", "Initial size (in bytes) of the stack"))
        yield textHandler(UInt32(self, "cs_ip", "Value of CS:IP"), hexadecimal)
        yield textHandler(UInt32(self, "ss_sp", "Value of SS:SP"), hexadecimal)

        yield UInt16(self, "nb_entry_seg_tab",
                     "Number of entries in the segment table")
        yield UInt16(self, "nb_entry_modref_tab",
                     "Number of entries in the module-reference table")
        yield filesizeHandler(
            UInt16(self, "size_nonres_name_tab",
                   "Number of bytes in the nonresident-name table"))
        yield UInt16(self, "seg_tab_ofs", "Segment table offset")
        yield UInt16(self, "rsrc_ofs", "Resource offset")

        yield UInt16(self, "res_name_tab_ofs", "Resident-name table offset")
        yield UInt16(self, "mod_ref_tab_ofs", "Module-reference table offset")
        yield UInt16(self, "import_tab_ofs", "Imported-name table offset")

        yield UInt32(self, "non_res_name_tab_ofs",
                     "Nonresident-name table offset")
        yield UInt16(self, "nb_mov_ent_pt", "Number of movable entry points")
        yield UInt16(self, "log2_sector_size",
                     "Log2 of the segment sector size")
        yield UInt16(self, "nb_rsrc_seg", "Number of resource segments")

        yield Bit(self, "unknown_os_format",
                  "Operating system format is unknown")
        yield PaddingBits(self, "reserved[]", 1)
        yield Bit(self, "os_windows", "Operating system is Microsoft Windows")
        yield NullBits(self, "reserved[]", 6)
        yield Bit(
            self, "is_win20_prot",
            "Is Windows 2.x application running in version 3.x protected mode")
        yield Bit(self, "is_win20_font",
                  "Is Windows 2.x application supporting proportional fonts")
        yield Bit(self, "fast_load", "Contains a fast-load area?")
        yield NullBits(self, "reserved[]", 4)

        yield UInt16(self, "fastload_ofs", "Fast-load area offset (in sector)")
        yield UInt16(self, "fastload_size",
                     "Fast-load area length (in sector)")

        yield NullBytes(self, "reserved[]", 2)
        yield textHandler(
            UInt16(self, "win_version", "Expected Windows version number"),
            hexadecimal)
示例#26
0
    def createFields(self):
        yield Enum(UInt16(self, "WindowsVersion"), self.PRODUCT_VERSION)
        yield UInt16(self, "FileVersion")
        yield GUID(self, "JobUUID")
        yield UInt16(self, "AppNameOffset", "App Name Length Offset")
        yield UInt16(
            self, "TriggerOffset",
            "Contains the offset in bytes within the .JOB file where the task triggers are located."
        )
        yield UInt16(
            self, "ErrorRetryCount",
            "Contains the number of execute attempts that are attempted for the task if the task fails to start."
        )
        yield UInt16(
            self, "ErrorRetryInterval",
            "Contains the interval, in minutes, between successive retries")
        yield UInt16(
            self, "IdleDeadline",
            "Contains a maximum time in minutes to wait for the machine to become idle for Idle Wait minutes."
        )
        yield UInt16(
            self, "IdleWait",
            "Contains a value in minutes. The machine remains idle for this many minutes before it runs the task"
        )
        yield UInt32(self, "Priority")
        yield UInt32(self, "MaxRunTime", "Maximum run time in milliseconds")
        yield UInt32(
            self, "ExitCode",
            "This contains the exit code of the executed task upon the completion of that task."
        )
        yield Enum(UInt32(self, "Status"), self.TASK_STATUS)
        yield Bit(self, "Interactive", "Can Task interact with user?")
        yield Bit(self, "DeleteWhenDone", "Remove the task file when done?")
        yield Bit(self, "Disabled", "Is Task disabled?")
        yield Bit(
            self, "StartOnlyIfIdle",
            "Task begins only if computer is not in use at the scheduled time")
        yield Bit(
            self, "KillOnIdleEnd",
            "Kill task if user input is detected, terminating idle state?")
        yield Bit(self, "DontStartIfOnBatteries")
        yield Bit(self, "KillIfGoingOnBatteries")
        yield Bit(self, "RunOnlyIfDocked")
        yield Bit(self, "HiddenTask")
        yield Bit(self, "RunIfConnectedToInternet")
        yield Bit(self, "RestartOnIdleResume")
        yield Bit(
            self, "SystemRequired",
            "Can task cause system to resume or awaken if system is sleeping?")
        yield Bit(self, "OnlyIfUserLoggedOn")
        yield Bit(self, "ApplicationNameExists",
                  "Does task have an application name defined?")
        yield Bit(self, "Unused[]")
        yield Bit(self, "Unused[]")
        yield RawBytes(self, "flags", 2)
        yield UInt16(self, "LastRunYear")
        yield UInt16(self, "LastRunMonth")
        yield UInt16(self, "LastRunWeekday", "Sunday=0,Saturday=6")
        yield UInt16(self, "LastRunDay")
        yield UInt16(self, "LastRunHour")
        yield UInt16(self, "LastRunMinute")
        yield UInt16(self, "LastRunSecond")
        yield UInt16(self, "LastRunMillisecond")
        yield UInt16(self, "RunningInstanceCount")
        yield PascalStringWin16(self, "AppNameLength", strip='\0')
        yield PascalStringWin16(self, "Parameters", strip='\0')
        yield PascalStringWin16(self, "WorkingDirectory", strip='\0')
        yield PascalStringWin16(self, "Author", strip='\0')
        yield PascalStringWin16(self, "Comment", strip='\0')

        yield UInt16(self, "UserDataSize")
        # todo: read optional userdata
        yield UInt16(self, "ReservedDataSize")
        if self["ReservedDataSize"].value == 8:
            yield Enum(
                UInt32(
                    self, "StartError",
                    "contains the HRESULT error from the most recent attempt to start the task"
                ), self.TASK_STATUS)
            yield UInt32(self, "TaskFlags")
        elif self["ReservedDataSize"].value:
            yield RawBytes(self, "Reserved", self["ReservedDataSize"].value)
        yield UInt16(self, "TriggerCount", "size of the array of triggers")
        for i in range(self["TriggerCount"].value):
            yield TaskTrigger(self, "Trigger[]")
示例#27
0
 def createFields(self):
     yield Bits(self, "name_offset", 31)
     yield Bit(self, "is_name")
     yield Bits(self, "offset", 31)
     yield Bit(self, "is_subdir")
示例#28
0
 def createFields(self):
     for y in range(4):
         for x in range(4):
             yield Bit(self, "is_used[%d,%d]" % (x, y))
示例#29
0
 def createFields(self):
     yield BytecodeChar(self, "bytecode", "Bytecode")
     yield Bit(self, "flag_ref", "Is a reference?")
     parser = self.code_info[1]
     if parser:
         yield from parser(self)
示例#30
0
 def createFields(self):
     yield Bit(self, "is_water_tile")
     yield Bits(self, "offset", 39)