示例#1
0
 def createFields(self):
     # CM
     yield Enum(Bits(self, "compression_method", 4), {
         8: "deflate",
         15: "reserved"
     })
     # CINFO
     yield Bits(self, "compression_info", 4,
                "base-2 log of the window size")
     yield Bits(self, "flag_check_bits", 5)  # FCHECK
     yield Bit(self, "flag_dictionary_present")  # FDICT
     yield Enum(
         Bits(self, "flag_compression_level", 2),  # FLEVEL
         {
             0: "Fastest",
             1: "Fast",
             2: "Default",
             3: "Maximum, Slowest"
         })
     if self["flag_dictionary_present"].value:
         yield textHandler(
             UInt32(self, "dict_checksum",
                    "ADLER32 checksum of dictionary information"),
             hexadecimal)
     yield DeflateData(self,
                       "data",
                       self.stream,
                       description="Compressed Data")
     yield textHandler(
         UInt32(self, "data_checksum",
                "ADLER32 checksum of compressed data"), hexadecimal)
示例#2
0
 def createFields(self):
     yield String(self, "name", 22, strip='\0')
     yield UInt16(self, "sample_count")
     yield textHandler(UInt8(self, "fine_tune"), getFineTune)
     yield textHandler(UInt8(self, "volume"), getVolume)
     yield UInt16(self, "loop_start", "Loop start offset in samples")
     yield UInt16(self, "loop_len", "Loop length in samples")
示例#3
0
    def createFields(self):
        if self._m2ts:
            yield Bits(self, "c", 2)
            yield Bits(self, "ats", 32 - 2)
        yield textHandler(UInt8(self, "sync", 8), hexadecimal)
        if self["sync"].value != 0x47:
            raise ParserError("MPEG-2 TS: Invalid synchronization byte")
        yield Bit(self, "has_error")
        yield Bit(self, "payload_unit_start")
        yield Bit(self, "priority")
        yield Enum(
            textHandler(Bits(self, "pid", 13, "Program identifier"),
                        hexadecimal), self.PID)
        yield Bits(self, "scrambling_control", 2)
        yield Bit(self, "has_adaptation")
        yield Bit(self, "has_payload")
        yield Bits(self, "counter", 4)

        if self["has_adaptation"].value:
            yield AdaptationField(self, "adaptation_field")
        if self["has_payload"].value:
            size = 188
            if self._m2ts:
                size += 4
            size -= (self.current_size // 8)
            yield RawBytes(self, "payload", size)
        if self["has_error"].value:
            yield RawBytes(self, "error_correction", 16)
示例#4
0
 def createFields(self):
     yield String(self, "header", 2, "File header (MZ)", charset="ASCII")
     yield UInt16(self, "size_mod_512", "File size in bytes modulo 512")
     yield UInt16(self, "size_div_512", "File size in bytes divide by 512")
     yield UInt16(self, "reloc_entries", "Number of relocation entries")
     yield UInt16(self, "code_offset",
                  "Offset to the code in the file (divided by 16)")
     yield UInt16(self, "needed_memory",
                  "Memory needed to run (divided by 16)")
     yield UInt16(self, "max_memory",
                  "Maximum memory needed to run (divided by 16)")
     yield textHandler(
         UInt32(self, "init_ss_sp", "Initial value of SP:SS registers"),
         hexadecimal)
     yield UInt16(self, "checksum", "Checksum")
     yield textHandler(
         UInt32(self, "init_cs_ip", "Initial value of CS:IP registers"),
         hexadecimal)
     yield UInt16(self, "reloc_offset",
                  "Offset in file to relocation table")
     yield UInt16(self, "overlay_number", "Overlay number")
     yield PaddingBytes(self, "reserved[]", 8, "Reserved")
     yield UInt16(self, "oem_id", "OEM id")
     yield UInt16(self, "oem_info", "OEM info")
     yield PaddingBytes(self, "reserved[]", 20, "Reserved")
     yield UInt32(self, "next_offset", "Offset to next header (PE or NE)")
示例#5
0
文件: bmp.py 项目: valnar1/SickGear
    def createFields(self):
        # Version 2 (12 bytes)
        yield UInt32(self, "header_size", "Header size")
        yield UInt32(self, "width", "Width (pixels)")
        yield UInt32(self, "height", "Height (pixels)")
        yield UInt16(self, "nb_plan", "Number of plan (=1)")
        # may be zero for PNG/JPEG picture
        yield UInt16(self, "bpp", "Bits per pixel")

        # Version 3 (40 bytes)
        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")
示例#6
0
    def createFields(self):
        while self.stream.readBytes(self.absolute_address + self.current_size,
                                    1) == b'%':
            size = getLineEnd(self, 4)
            if size == 2:
                yield String(self, "crc32_comment", 1)
                yield textHandler(UInt16(self, "crc32"), hexadecimal)
            elif size == 4:
                yield String(self, "crc32_comment", 1)
                yield textHandler(UInt32(self, "crc32"), hexadecimal)
            elif self.stream.readBytes(
                    self.absolute_address + self.current_size, size).isalpha():
                yield String(self, "comment[]", size)
            else:
                RawBytes(self, "unknown_data[]", size)
            yield LineEnd(self, "line_end[]")

        # abs_offset = self.current_size//8
        # TODO: yield objects that read offsets and deduce size from
        # "/cross_ref_table/sub_section[]/entries/item[]"
        offsets = []
        for subsection in self.array("/cross_ref_table/sub_section"):
            for obj in subsection.array("entries/item"):
                if "byte_offset" in obj:
                    # Could be inserted already sorted
                    offsets.append(obj["byte_offset"].value)

        offsets.append(self["/cross_ref_table"].absolute_address // 8)
        offsets.sort()
        for index in range(len(offsets) - 1):
            yield Catalog(self,
                          "object[]",
                          size=offsets[index + 1] - offsets[index])
示例#7
0
文件: xm.py 项目: valnar1/SickGear
 def createFields(self):
     # This stupid shit gets the LSB, not the MSB...
     self.info(
         "Note info: 0x%02X" %
         self.stream.readBits(self.absolute_address, 8, LITTLE_ENDIAN))
     yield RealBit(self, "is_extended")
     if self["is_extended"].value:
         info = NoteInfo(self, "info")
         yield info
         if info["has_note"].value:
             yield Enum(UInt8(self, "note"), NOTE_NAME)
         if info["has_instrument"].value:
             yield UInt8(self, "instrument")
         if info["has_volume"].value:
             yield textHandler(UInt8(self, "volume"), parseVolume)
         if info["has_type"].value:
             yield Effect(self, "effect_type")
         if info["has_parameter"].value:
             yield textHandler(UInt8(self, "effect_parameter"), hexadecimal)
     else:
         yield Enum(Bits(self, "note", 7), NOTE_NAME)
         yield UInt8(self, "instrument")
         yield textHandler(UInt8(self, "volume"), parseVolume)
         yield Effect(self, "effect_type")
         yield textHandler(UInt8(self, "effect_parameter"), hexadecimal)
示例#8
0
    def createFields(self):
        yield Bytes(self, "jump", 3, "Intel x86 jump instruction")
        yield String(self, "name", 8)
        yield BiosParameterBlock(self, "bios", "BIOS parameters")

        yield textHandler(UInt8(self, "physical_drive", "(0x80)"), hexadecimal)
        yield NullBytes(self, "current_head", 1)
        yield textHandler(
            UInt8(self, "ext_boot_sig", "Extended boot signature (0x80)"),
            hexadecimal)
        yield NullBytes(self, "unused", 1)

        yield UInt64(self, "nb_sectors")
        yield UInt64(self, "mft_cluster", "Cluster location of MFT data")
        yield UInt64(self, "mftmirr_cluster",
                     "Cluster location of copy of MFT")
        yield UInt8(self, "cluster_per_mft", "MFT record size in clusters")
        yield NullBytes(self, "reserved[]", 3)
        yield UInt8(self, "cluster_per_index", "Index block size in clusters")
        yield NullBytes(self, "reserved[]", 3)
        yield textHandler(UInt64(self, "serial_number"), hexadecimal)
        yield textHandler(UInt32(self, "checksum", "Boot sector checksum"),
                          hexadecimal)
        yield Bytes(self, "boot_code", 426)
        yield Bytes(self, "mbr_magic", 2,
                    r"Master boot record magic number (\x55\xAA)")
示例#9
0
 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:
         if self.command not in self.COMMAND_PARSER:
             raise ParserError("Unknown command: %s" %
                               self["command"].display)
         parser = self.COMMAND_PARSER[self.command]
         yield from parser(self)
示例#10
0
def fileHeader(self):
    yield filesizeHandler(
        UInt32(self, "compressed_size", "Size of the compressed file"))
    yield filesizeHandler(
        UInt32(self, "uncompressed_size", "Uncompressed file size"))
    yield TimeDateMSDOS32(self, "ftime", "Date and time (MS DOS format)")
    if self["/header/host_os"].value in (OS_MSDOS, OS_WIN32):
        yield MSDOSFileAttr32(self, "file_attr", "File attributes")
    else:
        yield textHandler(UInt32(self, "file_attr", "File attributes"),
                          hexadecimal)
    yield textHandler(
        UInt32(self, "file_crc32", "CRC32 checksum over the compressed file)"),
        hexadecimal)
    yield Enum(UInt8(self, "compression_type", "Type of compression"),
               COMPRESSION_TYPE)
    yield Enum(UInt8(self, "compression_mode", "Quality of compression"),
               COMPRESSION_MODE)
    yield textHandler(UInt16(self, "parameters", "Compression parameters"),
                      hexadecimal)
    yield textHandler(UInt16(self, "reserved", "Reserved data"), hexadecimal)
    # Filename
    yield PascalString16(self, "filename", "Filename")
    # Comment
    if self["flags/has_comment"].value:
        yield filesizeHandler(
            UInt16(self, "comment_size", "Size of the compressed comment"))
        if self["comment_size"].value > 0:
            yield RawBytes(self, "comment_data", self["comment_size"].value,
                           "Comment data")
示例#11
0
    def createFields(self):
        # Gzip header
        yield Bytes(self, "signature", 2, r"GZip file signature (\x1F\x8B)")
        yield Enum(UInt8(self, "compression", "Compression method"),
                   self.COMPRESSION_NAME)

        # Flags
        yield Bit(self, "is_text", "File content is probably ASCII text")
        yield Bit(self, "has_crc16", "Header CRC16")
        yield Bit(self, "has_extra", "Extra informations (variable size)")
        yield Bit(self, "has_filename", "Contains filename?")
        yield Bit(self, "has_comment", "Contains comment?")
        yield NullBits(self, "reserved[]", 3)
        yield TimestampUnix32(self, "mtime", "Modification time")

        # Extra flags
        yield NullBits(self, "reserved[]", 1)
        yield Bit(self, "slowest",
                  "Compressor used maximum compression (slowest)")
        yield Bit(self, "fastest", "Compressor used the fastest compression")
        yield NullBits(self, "reserved[]", 5)
        yield Enum(UInt8(self, "os", "Operating system"), self.os_name)

        # Optional fields
        if self["has_extra"].value:
            yield UInt16(self, "extra_length", "Extra length")
            yield RawBytes(self, "extra", self["extra_length"].value, "Extra")
        if self["has_filename"].value:
            yield CString(self, "filename", "Filename", charset="ISO-8859-1")
        if self["has_comment"].value:
            yield CString(self, "comment", "Comment")
        if self["has_crc16"].value:
            yield textHandler(UInt16(self, "hdr_crc16", "CRC16 of the header"),
                              hexadecimal)

        if self._size is None:  # TODO: is it possible to handle piped input?
            raise NotImplementedError()

        # Read file
        size = (self._size - self.current_size) // 8 - 8  # -8: crc32+size
        if 0 < size:
            if self["has_filename"].value:
                filename = self["filename"].value
            else:
                for tag, filename in self.stream.tags:
                    if tag == "filename" and filename.endswith(".gz"):
                        filename = filename[:-3]
                        break
                else:
                    filename = None
            yield Deflate(SubFile(self, "file", size, filename=filename))

        # Footer
        yield textHandler(
            UInt32(self, "crc32", "Uncompressed data content CRC32"),
            hexadecimal)
        yield filesizeHandler(UInt32(self, "size", "Uncompressed size"))
示例#12
0
文件: nds.py 项目: valnar1/SickGear
 def createFields(self):
     yield UInt32(self, "id")
     yield textHandler(UInt32(self, "ram_address"), hexadecimal)
     yield UInt32(self, "ram_size")
     yield UInt32(self, "bss_size")
     yield textHandler(UInt32(self, "init_start_address"), hexadecimal)
     yield textHandler(UInt32(self, "init_end_address"), hexadecimal)
     yield UInt32(self, "file_id")
     yield RawBytes(self, "reserved[]", 4)
示例#13
0
文件: wmf.py 项目: valnar1/SickGear
 def createFields(self):
     yield textHandler(
         UInt32(self, "signature",
                "Placeable Metafiles signature (0x9AC6CDD7)"), hexadecimal)
     yield UInt16(self, "handle")
     yield RECT16(self, "rect")
     yield UInt16(self, "inch")
     yield NullBytes(self, "reserved", 4)
     yield textHandler(UInt16(self, "checksum"), hexadecimal)
示例#14
0
 def createFields(self):
     yield Enum(UInt32(self, "type", "Segment type"),
                ProgramHeader32.TYPE_NAME)
     yield ProgramFlags(self, "flags")
     yield UInt64(self, "offset", "Offset")
     yield textHandler(UInt64(self, "vaddr", "V. address"), hexadecimal)
     yield textHandler(UInt64(self, "paddr", "P. address"), hexadecimal)
     yield UInt64(self, "file_size", "File size")
     yield UInt64(self, "mem_size", "Memory size")
     yield UInt64(self, "align", "Alignment padding")
示例#15
0
 def createFields(self):
     yield textHandler(UInt32(self, "plugin_id1"), hexadecimal)
     yield textHandler(UInt32(self, "plugin_id2"), hexadecimal)
     yield UInt32(self, "input_routing")
     yield UInt32(self, "output_routing")
     yield GenericVector(self, "routing_info", 4, UInt32, "reserved")
     yield String(self, "name", 32, strip='\0')
     yield String(self,
                  "dll_name",
                  64,
                  desc="Original DLL name",
                  strip='\0')
示例#16
0
 def createFields(self):
     yield String(self, "segname", 16, strip="\0")
     yield textHandler(UInt64(self, "vmaddr"), hexadecimal)
     yield textHandler(UInt64(self, "vmsize"), hexadecimal)
     yield textHandler(UInt64(self, "fileoff"), hexadecimal)
     yield textHandler(UInt64(self, "filesize"), hexadecimal)
     yield UInt32(self, "maxprot")
     yield UInt32(self, "initprot")
     yield UInt32(self, "nsects")
     yield UInt32(self, "flags")
     for i in range(self['nsects'].value):
         yield MachoSection64(self, "section[]")
示例#17
0
 def createFields(self):
     yield String(self, "sectname", 16, strip="\0")
     yield String(self, "segname", 16, strip="\0")
     yield textHandler(UInt32(self, "addr"), hexadecimal)
     yield textHandler(UInt32(self, "size"), hexadecimal)
     yield textHandler(UInt32(self, "offset"), hexadecimal)
     yield textHandler(UInt32(self, "align"), hexadecimal)
     yield textHandler(UInt32(self, "reloff"), hexadecimal)
     yield UInt32(self, "nreloc")
     yield UInt32(self, "flags")
     yield UInt32(self, "reserved1")
     yield UInt32(self, "reserved2")
示例#18
0
文件: swf.py 项目: valnar1/SickGear
def parseSoundHeader(parent, size):
    yield Bit(parent, "playback_is_stereo")
    yield Bit(parent, "playback_is_16bit")
    yield textHandler(Bits(parent, "playback_rate", 2), bit2hertz)
    yield NullBits(parent, "reserved", 4)

    yield Bit(parent, "sound_is_stereo")
    yield Bit(parent, "sound_is_16bit")
    yield textHandler(Bits(parent, "sound_rate", 2), bit2hertz)
    yield Enum(Bits(parent, "codec", 4), SOUND_CODEC)

    yield UInt16(parent, "sample_count")

    if parent["codec"].value == 2:
        yield UInt16(parent, "latency_seek")
示例#19
0
def parseFileProperties(self):
    yield UInt32(self, "max_bit_rate", "Maximum bit rate")
    yield UInt32(self, "avg_bit_rate", "Average bit rate")
    yield UInt32(self, "max_pkt_size", "Size of largest data packet")
    yield UInt32(self, "avg_pkt_size", "Size of average data packet")
    yield UInt32(self, "num_pkts", "Number of data packets")
    yield UInt32(self, "duration", "File duration in milliseconds")
    yield UInt32(self, "preroll", "Suggested preroll in milliseconds")
    yield textHandler(UInt32(self, "index_offset", "Absolute offset of first index chunk"), hexadecimal)
    yield textHandler(UInt32(self, "data_offset", "Absolute offset of first data chunk"), hexadecimal)
    yield UInt16(self, "stream_count", "Number of streams in the file")
    yield RawBits(self, "reserved", 13)
    yield Bit(self, "is_live", "Whether file is a live broadcast")
    yield Bit(self, "is_perfect_play", "Whether PerfectPlay can be used")
    yield Bit(self, "is_saveable", "Whether file can be saved")
示例#20
0
    def createFields(self):
        # File data
        self.signature = None
        self.central_directory = []
        while not self.eof:
            skip = 0
            while True:
                try:
                    header = self.stream.readBits(self.absolute_address + self.current_size + skip, 32, self.endian)
                    if header in self.CHUNK_TYPES:
                        break
                    skipdelta = self.stream.searchBytes(b'PK', self.absolute_address + self.current_size + skip + 8)
                    if skipdelta is None:
                        if not self.current_size:
                            raise ParserError("Failed to find any zip headers")
                        return
                    skip = skipdelta - (self.absolute_address + self.current_size)
                except ReadStreamError:
                    if not self.current_size:
                        raise ParserError("Failed to read stream")
                    return
            if skip:
                yield RawBytes(self, "unparsed[]", skip // 8)

            yield textHandler(
                UInt32(self, "header[]", "Header"), hexadecimal)

            ftype, fname, fdesc = self.CHUNK_TYPES[header]
            yield ftype(self, fname, fdesc)
示例#21
0
文件: cab.py 项目: valnar1/SickGear
 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
         yield RawBytes(self, "compr_data", self["size"].value, "Compressed Folder Data")
     elif compr_method == 3:  # LZX
         group = getattr(self.parent.folder, "lzx_group", None)
         field = CustomFragment(
             self, "data", self["size"].value * 8, LZXStream, "LZX data fragment", group)
         if group is None:
             field.group.args["compr_level"] = self.parent.folder["compr_level"].value
         self.parent.folder.lzx_group = field.group
         yield field
示例#22
0
    def createFields(self):
        yield Enum(UInt16(self, "src"), self.port_name)
        yield Enum(UInt16(self, "dst"), self.port_name)
        yield UInt32(self, "seq_num")
        yield UInt32(self, "ack_num")

        yield Bits(self, "hdrlen", 6, "Header lenght")
        yield NullBits(self, "reserved", 2, "Reserved")

        yield Bit(self, "cgst", "Congestion Window Reduced")
        yield Bit(self, "ecn-echo", "ECN-echo")
        yield Bit(self, "urg", "Urgent")
        yield Bit(self, "ack", "Acknowledge")
        yield Bit(self, "psh", "Push mmode")
        yield Bit(self, "rst", "Reset connection")
        yield Bit(self, "syn", "Synchronize")
        yield Bit(self, "fin", "Stop the connection")

        yield UInt16(self, "winsize", "Windows size")
        yield textHandler(UInt16(self, "checksum"), hexadecimal)
        yield UInt16(self, "urgent")

        size = self["hdrlen"].value * 8 - self.current_size
        while 0 < size:
            option = TCP_Option(self, "option[]")
            yield option
            size -= option.size
示例#23
0
 def createFields(self):
     yield Bytes(self, "signature", 6, "Signature Header")
     yield UInt8(self, "major_ver", "Archive major version")
     yield UInt8(self, "minor_ver", "Archive minor version")
     yield textHandler(UInt32(self, "start_hdr_crc",
                              "Start header CRC"), hexadecimal)
     yield StartHeader(self, "start_hdr", "Start header")
示例#24
0
 def createFields(self):
     yield Enum(Int32(self, "cputype"), CPU_TYPE)
     yield Int32(self, "cpusubtype")
     yield textHandler(UInt32(self, "offset"), hexadecimal)
     yield UInt32(self, "size")
     yield UInt32(self, "align")
     self['align'].createDescription = lambda: str(1 << self['align'].value)
示例#25
0
文件: mkv.py 项目: swipswaps/SickGear
    def createFields(self):
        yield Unsigned(self, 'track')
        yield Int16(self, 'timecode')

        if self.parent._name == 'Block':
            yield NullBits(self, 'reserved[]', 4)
            yield Bit(self, 'invisible')
            yield self.lacing()
            yield NullBits(self, 'reserved[]', 1)
        elif self.parent._name.startswith('SimpleBlock'):
            yield Bit(self, 'keyframe')
            yield NullBits(self, 'reserved', 3)
            yield Bit(self, 'invisible')
            yield self.lacing()
            yield Bit(self, 'discardable')
        else:
            yield NullBits(self, 'reserved', 8)
            return

        size = (self._size - self.current_size) // 8
        lacing = self['lacing'].value
        if lacing:
            yield textHandler(GenericInteger(self, 'n_frames', False, 8),
                              lambda chunk: str(chunk.value + 1))
            yield Lace(self, lacing - 1, size - 1)
        else:
            yield RawBytes(self, 'frame', size)
示例#26
0
    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
        if size:
            yield RawBytes(self, "options", size)
示例#27
0
def newRecoveryHeader(self):
    """
    This header is described nowhere
    """
    if self["flags/extend"].value:
        yield filesizeHandler(
            UInt32(self, "body_size", "Size of the unknown body following"))
        self.body_size = self["body_size"].value
    yield textHandler(UInt32(self, "unknown[]", "Unknown field, probably 0"),
                      hexadecimal)
    yield String(self, "signature", 7, "Signature, normally '**ACE**'")
    yield textHandler(
        UInt32(self, "relative_start",
               "Offset (=crc16's) of this block in the file"), hexadecimal)
    yield textHandler(UInt32(self, "unknown[]", "Unknown field, probably 0"),
                      hexadecimal)
示例#28
0
    def createFields(self):
        yield Bytes(self, "signature", 4, r'ELF signature ("\x7fELF")')
        yield Enum(UInt8(self, "class", "Class"), self.CLASS_NAME)
        if self["class"].value == 1:
            ElfLongWord = UInt32
        else:
            ElfLongWord = UInt64
        yield Enum(UInt8(self, "endian", "Endian"), self.ENDIAN_NAME)
        yield UInt8(self, "file_version", "File version")
        yield Enum(UInt8(self, "osabi_ident", "OS/syscall ABI identification"),
                   self.OSABI_NAME)
        yield UInt8(self, "abi_version", "syscall ABI version")
        yield String(self, "pad", 7, "Pad")

        yield Enum(UInt16(self, "type", "File type"), self.TYPE_NAME)
        yield Enum(UInt16(self, "machine", "Machine type"), self.MACHINE_NAME)
        yield UInt32(self, "version", "ELF format version")
        yield textHandler(ElfLongWord(self, "entry", "Entry point"),
                          hexadecimal)
        yield ElfLongWord(self, "phoff", "Program header file offset")
        yield ElfLongWord(self, "shoff", "Section header file offset")
        yield UInt32(self, "flags", "Architecture-specific flags")
        yield UInt16(self, "ehsize", "Elf header size (this header)")
        yield UInt16(self, "phentsize", "Program header entry size")
        yield UInt16(self, "phnum", "Program header entry count")
        yield UInt16(self, "shentsize", "Section header entry size")
        yield UInt16(self, "shnum", "Section header entry count")
        yield UInt16(self, "shstrndx", "Section header string table index")
示例#29
0
 def createFields(self):
     yield textHandler(UInt32(self, "file_crc32",
                              "Checksum (CRC32)"), hexadecimal)
     yield filesizeHandler(UInt32(self, "file_compressed_size",
                                  "Compressed size (bytes)"))
     yield filesizeHandler(UInt32(self, "file_uncompressed_size",
                                  "Uncompressed size (bytes)"))
示例#30
0
    def createFields(self):
        yield Enum(UInt8(self, "type"), self.TYPE_DESC)
        yield UInt8(self, "code")
        yield textHandler(UInt16(self, "checksum"), hexadecimal)

        if self['type'].value in (self.ECHO_REQUEST, self.ECHO_REPLY):
            yield UInt16(self, "id")
            yield UInt16(self, "sequence")