Example #1
0
 def createFields(self):
     yield displayHandler(
         Bits(self,
              "offset",
              27,
              description="Offset into file divided by 32"),
         lambda x: hex(x * 32).strip('L'))
     yield displayHandler(
         Bits(self, "size", 5, description="Power-of-2 size of the block"),
         lambda x: hex(1 << x).strip('L'))
Example #2
0
    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")
Example #3
0
 def createFields(self):
     yield GUID(self, "guid")
     yield filesizeHandler(UInt64(self, "file_size"))
     yield TimestampWin64(self, "creation_date")
     yield UInt64(self, "pckt_count")
     yield TimedeltaWin64(self, "play_duration")
     yield TimedeltaWin64(self, "send_duration")
     yield TimedeltaMillisWin64(self, "preroll")
     yield Bit(self, "broadcast", "Is broadcast?")
     yield Bit(self, "seekable", "Seekable stream?")
     yield PaddingBits(self, "reserved[]", 30)
     yield filesizeHandler(UInt32(self, "min_pckt_size"))
     yield filesizeHandler(UInt32(self, "max_pckt_size"))
     yield displayHandler(UInt32(self, "max_bitrate"), humanBitRate)
Example #4
0
def parseGraphicControl(parent):
    yield UInt8(parent, "size", "Block size (4)")

    yield Bit(parent, "has_transp", "Has transparency")
    yield Bit(parent, "user_input", "User input")
    yield Enum(Bits(parent, "disposal_method", 3), DISPOSAL_METHOD)
    yield NullBits(parent, "reserved[]", 3)

    if parent["size"].value != 4:
        raise ParserError("Invalid graphic control size")
    yield displayHandler(UInt16(parent, "delay", "Delay time in millisecond"),
                         humanDuration)
    yield UInt8(parent, "transp", "Transparent color index")
    yield NullBytes(parent, "terminator", 1, "Terminator (0)")
Example #5
0
    def createFields(self):
        yield displayHandler(UInt32(self, "res_space", "Reserved space"),
                             humanFilesize)
        yield displayHandler(UInt32(self, "used_space", "Used space"),
                             humanFilesize)
        yield Bits(self, "file_flags", 8, "(=4)")

        yield textHandler(UInt16(self, "magic"), hexadecimal)
        yield Bits(self, "flags", 16)
        yield displayHandler(UInt16(self, "page_size", "Page size in bytes"),
                             humanFilesize)
        yield String(self, "structure", 16, strip="\0", charset="ASCII")
        yield NullBytes(self, "zero", 2)
        yield UInt16(self, "nb_page_splits",
                     "Number of page splits B+ tree has suffered")
        yield UInt16(self, "root_page", "Page number of B+ tree root page")
        yield PaddingBytes(self, "one", 2, pattern="\xFF")
        yield UInt16(self, "nb_page", "Number of B+ tree pages")
        yield UInt16(self, "nb_level", "Number of levels of B+ tree")
        yield UInt16(self, "nb_entry", "Number of entries in B+ tree")

        size = (self.size - self.current_size) // 8
        if size:
            yield PaddingBytes(self, "reserved_space", size)
Example #6
0
 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")
         audio_size = (self["filesize"].value +
                       40) - (self["headersize"].value + 16)
     if 0 < audio_size:
         yield RawBytes(self, "audio_data", audio_size)
Example #7
0
 def createFields(self):
     yield Bits(self, "stream_index", 7)
     yield PaddingBits(self, "reserved", 9)
     yield displayHandler(UInt32(self, "avg_bitrate"), humanBitRate)
Example #8
0
    def createFields(self):
        yield String(self,
                     "header_id",
                     4,
                     "Track Item Header Markup (\"mhit\")",
                     charset="ISO-8859-1")
        yield UInt32(self, "header_length", "Header Length")
        yield UInt32(self, "entry_length", "Entry Length")
        yield UInt32(self, "string_number", "Number of Strings")
        yield UInt32(self, "unique_id", "Unique ID")
        yield UInt32(self, "visible_tag", "Visible Tag")
        yield String(self, "file_type", 4, "File Type")
        yield Enum(UInt8(self, "x1_type", "Extended Type 1"),
                   self.x1_type_name)
        yield Enum(UInt8(self, "x2_type", "Extended type 2"),
                   self.x2_type_name)
        yield UInt8(self, "compilation_flag", "Compilation Flag")
        yield UInt8(self, "rating", "Rating")
        yield TimestampMac32(self, "last_modified",
                             "Time of the last modification of the track")
        yield filesizeHandler(UInt32(self, "size", "Track size in bytes"))
        yield displayHandler(
            UInt32(self, "length", "Track length in milliseconds"),
            humanDuration)
        yield UInt32(self, "track_number", "Number of this track")
        yield UInt32(self, "total_track", "Total number of tracks")
        yield UInt32(self, "year", "Year of the track")
        yield UInt32(self, "bitrate", "Bitrate")
        yield UInt32(self, "samplerate", "Sample Rate")
        yield UInt32(self, "volume", "volume")
        yield UInt32(self, "start_time", "Start playing at, in milliseconds")
        yield UInt32(self, "stop_time", "Stop playing at,  in milliseconds")
        yield UInt32(self, "soundcheck", "SoundCheck preamp")
        yield UInt32(self, "playcount_1", "Play count of the track")
        yield UInt32(self, "playcount_2",
                     "Play count of the track when last synced")
        yield TimestampMac32(self, "last_played_time",
                             "Time the song was last played")
        yield UInt32(self, "disc_number", "disc number in multi disc sets")
        yield UInt32(self, "total_discs",
                     "Total number of discs in the disc set")
        yield UInt32(self, "userid", "User ID in the DRM scheme")
        yield TimestampMac32(self, "added_date",
                             "Date when the item was added")
        yield UInt32(self, "bookmark_time", "Bookmark time for AudioBook")
        yield UInt64(
            self, "dbid",
            "Unique DataBase ID for the song (identical in mhit and in mhii)")
        yield UInt8(self, "checked", "song is checked")
        yield UInt8(self, "application_rating", "Last Rating before change")
        yield UInt16(self, "BPM", "BPM of the track")
        yield UInt16(self, "artwork_count", "number of artworks for this item")
        yield UInt16(self, "unknown[]")
        yield UInt32(self, "artwork_size", "Total size of artworks in bytes")
        yield UInt32(self, "unknown[]")
        yield Float32(self, "sample_rate_2", "Sample Rate express in float")
        yield UInt32(self, "released_date",
                     "Date of release in Music Store or in Podcast")
        yield UInt16(self, "unknown[]")
        yield UInt16(self, "explicit_flag[]", "Explicit flag")
        yield UInt32(self, "unknown[]")
        yield UInt32(self, "unknown[]")
        yield UInt32(self, "skip_count[]", "Skip Count")
        yield TimestampMac32(self, "last_skipped",
                             "Date when the item was last skipped")
        yield UInt8(self, "has_artwork",
                    "0x01 for track with artwork, 0x02 otherwise")
        yield UInt8(self, "skip_wen_shuffling",
                    "Skip that track when shuffling")
        yield UInt8(self, "remember_playback_position",
                    "Remember playback position")
        yield UInt8(self, "flag4", "Flag 4")
        yield UInt64(self, "dbid2",
                     "Unique DataBase ID for the song (identical as above)")
        yield UInt8(self, "lyrics_flag", "Lyrics Flag")
        yield UInt8(self, "movie_file_flag", "Movie File Flag")
        yield UInt8(self, "played_mark", "Track has been played")
        yield UInt8(self, "unknown[]")
        yield UInt32(self, "unknown[]")
        yield UInt32(self, "pregap[]",
                     "Number of samples of silence before the song starts")
        yield UInt64(
            self, "sample_count",
            "Number of samples in the song (only for WAV and AAC files)")
        yield UInt32(self, "unknown[]")
        yield UInt32(self, "postgap[]",
                     "Number of samples of silence at the end of the song")
        yield UInt32(self, "unknown[]")
        yield Enum(UInt32(self, "media_type", "Media Type for video iPod"),
                   self.media_type_name)
        yield UInt32(self, "season_number", "Season Number")
        yield UInt32(self, "episode_number", "Episode Number")
        yield UInt32(self, "unknown[]")
        yield UInt32(self, "unknown[]")
        yield UInt32(self, "unknown[]")
        yield UInt32(self, "unknown[]")
        yield UInt32(self, "unknown[]")
        yield UInt32(self, "unknown[]")
        yield UInt32(self, "unknown[]")
        yield UInt32(
            self, "gapless_data[]",
            "The size in bytes from first Sync Frame until the 8th before the last frame."
        )
        yield UInt32(self, "unknown[]")
        yield UInt16(self, "gaplessTrackFlag[]", "1 if track has gapless data")
        yield UInt16(self, "gaplessAlbumFlag[]",
                     "1 if track uses crossfading in iTunes")
        yield RawBytes(self, "unknown[]", 20)
        yield UInt32(self, "unknown[]")
        yield UInt32(self, "unknown[]")
        yield UInt32(self, "unknown[]")
        yield UInt32(self, "unknown[]")
        yield UInt16(self, "unknown[]")
        yield UInt16(self, "album_id[]",
                     "Album ID (used to link tracks with MHIAs)")
        yield RawBytes(self, "unknown[]", 52)
        yield UInt32(self, "mhii_link[]",
                     "Artwork ID (used to link tracks with MHIIs)")
        padding = self.seekByte(self["header_length"].value, "header padding")
        if padding:
            yield padding

        # while ((self.stream.readBytes(0, 4) == 'mhod') and  ((self.current_size/8) < self["entry_length"].value)):
        for i in xrange(self["string_number"].value):
            yield DataObject(self, "data[]")
        padding = self.seekBit(self._size, "entry padding")
        if padding:
            yield padding
Example #9
0
    def createFields(self):
        yield Enum(
            Bits(self, "marker_type", 4), {
                0: "Simple",
                1: "Int",
                2: "Real",
                3: "Date",
                4: "Data",
                5: "ASCII String",
                6: "UTF-16-BE String",
                8: "UID",
                10: "Array",
                13: "Dict",
            })
        markertype = self['marker_type'].value
        if markertype == 0:
            # Simple (Null)
            yield Enum(Bits(self, "value", 4), {
                0: "Null",
                8: "False",
                9: "True",
                15: "Fill Byte",
            })
            if self['value'].display == "False":
                self.xml = lambda prefix: prefix + "<false/>"
            elif self['value'].display == "True":
                self.xml = lambda prefix: prefix + "<true/>"
            else:
                self.xml = lambda prefix: prefix + ""

        elif markertype == 1:
            # Int
            yield Bits(self, "size", 4, "log2 of number of bytes")
            size = self['size'].value
            # 8-bit (size=0), 16-bit (size=1) and 32-bit (size=2) numbers are unsigned
            # 64-bit (size=3) numbers are signed
            yield GenericInteger(self, "value", (size >= 3), (2**size) * 8)
            self.xml = lambda prefix: prefix + \
                "<integer>%s</integer>" % self['value'].value

        elif markertype == 2:
            # Real
            yield Bits(self, "size", 4, "log2 of number of bytes")
            if self['size'].value == 2:  # 2**2 = 4 byte float
                yield Float32(self, "value")
            elif self['size'].value == 3:  # 2**3 = 8 byte float
                yield Float64(self, "value")
            else:
                # FIXME: What is the format of the real?
                yield Bits(self, "value", (2**self['size'].value) * 8)
            self.xml = lambda prefix: prefix + \
                "<real>%s</real>" % self['value'].value

        elif markertype == 3:
            # Date
            yield Bits(self, "extra", 4, "Extra value, should be 3")

            # Use a heuristic to determine which epoch to use
            def cvt_time(v):
                v = timedelta(seconds=v)
                epoch2001 = datetime(2001, 1, 1)
                epoch1970 = datetime(1970, 1, 1)
                if (epoch2001 + v - datetime.today()).days > 5 * 365:
                    return epoch1970 + v
                return epoch2001 + v

            yield displayHandler(Float64(self, "value"),
                                 lambda x: humanDatetime(cvt_time(x)))
            self.xml = lambda prefix: prefix + "<date>%sZ</date>" % (cvt_time(
                self['value'].value).isoformat())

        elif markertype == 4:
            # Data
            yield BPListSize(self, "size")
            if self['size'].value:
                yield Bytes(self, "value", self['size'].value)
                self.xml = lambda prefix: prefix + \
                    "<data>\n%s\n%s</data>" % (
                        self['value'].value.encode('base64').strip(), prefix)
            else:
                self.xml = lambda prefix: prefix + '<data></data>'

        elif markertype == 5:
            # ASCII String
            yield BPListSize(self, "size")
            if self['size'].value:
                yield String(self,
                             "value",
                             self['size'].value,
                             charset="ASCII")
                self.xml = lambda prefix: prefix + \
                    "<string>%s</string>" % (
                        self['value'].value.replace('&', '&amp;').encode('iso-8859-1'))
            else:
                self.xml = lambda prefix: prefix + '<string></string>'

        elif markertype == 6:
            # UTF-16-BE String
            yield BPListSize(self, "size")
            if self['size'].value:
                yield String(self,
                             "value",
                             self['size'].value * 2,
                             charset="UTF-16-BE")
                self.xml = lambda prefix: prefix + \
                    "<string>%s</string>" % (
                        self['value'].value.replace('&', '&amp;').encode('utf-8'))
            else:
                self.xml = lambda prefix: prefix + '<string></string>'

        elif markertype == 8:
            # UID
            yield Bits(self, "size", 4, "Number of bytes minus 1")
            yield GenericInteger(self, "value", False,
                                 (self['size'].value + 1) * 8)
            self.xml = lambda prefix: prefix + ""  # no equivalent?

        elif markertype == 10:
            # Array
            yield BPListSize(self, "size")
            size = self['size'].value
            if size:
                yield BPListArray(self, "value", size)
                self.xml = lambda prefix: self['value'].createXML(prefix)

        elif markertype == 13:
            # Dict
            yield BPListSize(self, "size")
            yield BPListDict(self, "value", self['size'].value)
            self.xml = lambda prefix: self['value'].createXML(prefix)

        else:
            yield Bits(self, "value", 4)
            self.xml = lambda prefix: ''
Example #10
0
 def createFields(self):
     yield UInt32(self, "offset", "Offset in bytes relative to start of archive")
     yield filesizeHandler(UInt32(self, "length", "Length in bytes"))
     yield displayHandler(UInt32(self, "flags"), humanUnixAttributes)
     yield CString(self, "name", "Filename (byte array)")