Exemple #1
0
    def parse(blob,snr, loader_context):
        buf = SeqBuffer(blob)
        [type,common_length,v2] = buf.unpack('>3i')
        common_blob = buf.readBytes(common_length)
        buf2 = SeqBuffer(common_blob)
        [v3,v4,v5,v6,cast_id,nElems] = buf2.unpack('>5iH')
        offsets = []
        for i in range(nElems+1):
            [tmp] = buf2.unpack('>i')
            offsets.append(tmp)

        blob_after_table=buf2.peek_bytes_left()
        attrs = []
        for i in range(len(offsets)-1):
            attr = blob_after_table[offsets[i]:offsets[i+1]]
            print "DB|   Cast member attr #%d: <%s>" % (i, attr)
            attrs.append(attr)

        if len(attrs)>=2 and len(attrs[1])>0:
            name = SeqBuffer(attrs[1]).unpackString8()
        else:
            name = None

        print "DB| Cast-member common: name=\"%s\"  attrs=%s  misc=%s" % (
            name, attrs, [v2,v3,v4,v5,v6, cast_id])
        noncommon = buf.peek_bytes_left()

        castdata = CastMember.parse_castdata(type, cast_id, SeqBuffer(noncommon), attrs)
        res = CastMember(snr,type, name, attrs, castdata)
        return res
Exemple #2
0
 def parse(buf, *args):
     [type_length] = buf.unpack('>I')
     med_type = buf.readBytes(type_length)
     [rest_length] = buf.unpack('>I')
     info = buf.readBytes(rest_length)
     buf = SeqBuffer(info)
     if rest_length >= 4 and buf.readTag(
     ) == b'FLSH' and med_type == 'vectorShape':
         [sz2] = buf.unpack('>I')
         half_expect(sz2, rest_length, "XmedCastType.sz2")
         misc = buf.unpack('>24i')
         [npoints] = buf.unpack('>I')
         misc2 = buf.unpack('>35i')
         [proplen] = buf.unpack('>I')
         propname = buf.readBytes(proplen)
         points = []
         for i in range(npoints):
             if i:
                 [vx] = buf.unpack('>i')
                 half_expect(vx, -0x80000000, 'XmedCastType.vx')
             pdesc = buf.unpack('>6i')
             points.append(pdesc)
         [proplen] = buf.unpack('>I')
         propname = buf.readBytes(proplen)
         half_expect(buf.peek_bytes_left(), b'', 'XmedCastType.trailer')
         print(
             "DB| XmedCastType.parse: misc=%r npoints=%r misc2=%r, points=%r"
             % (misc, npoints, misc2, points))
         info = (misc, misc2, points)
     return XmedCastType(med_type, info, *args)
Exemple #3
0
def parse_dir_config(blob, loader_context):
    buf = SeqBuffer(blob, loader_context)
    misc1 = buf.unpack('>32h')
    misc2 = buf.unpack('>3i')
    [palette] = buf.unpack('>i')
    misc3 = buf.peek_bytes_left()
    config = {'palette': palette, 'misc': [misc1, misc2, bytes(misc3)]}
    print("DB| parse_dir_config: %r" % (config, ))
    return config
Exemple #4
0
    def parse(blob, snr, loader_context):
        buf = SeqBuffer(blob)
        [type, common_length, v2] = buf.unpack('>3i')
        common_blob = buf.readBytes(common_length)
        buf2 = SeqBuffer(common_blob)
        [v3, v4, v5, v6, cast_id, nElems] = buf2.unpack('>5iH')
        offsets = []
        for i in range(nElems + 1):
            [tmp] = buf2.unpack('>i')
            offsets.append(tmp)

        blob_after_table = buf2.peek_bytes_left()
        attrs = []
        for i in range(len(offsets) - 1):
            attr = blob_after_table[offsets[i]:offsets[i + 1]]
            print("DB|   Cast member attr #%d: <%r>" % (i, attr))
            attrs.append(attr)

        if len(attrs) >= 2 and len(attrs[1]) > 0:
            name = SeqBuffer(attrs[1]).unpackString8()
            attrs[1] = None
        else:
            name = None
        if len(attrs) >= 18 and len(attrs[17]) == 4:
            [ctime] = struct.unpack('>I', attrs[17])
            attrs[17] = None
        else:
            ctime = None
        if len(attrs) >= 19 and len(attrs[18]) == 4:
            [mtime] = struct.unpack('>I', attrs[18])
            attrs[18] = None
        else:
            mtime = None

        print(
            "DB| Cast-member common: name=\"%s\" ctime=%s mtime=%s  attrs=%s  misc=%s"
            % (name, ctime and time.ctime(ctime), mtime
               and time.ctime(mtime), attrs, [v2, v3, v4, v5, v6, cast_id]))
        noncommon = buf.peek_bytes_left()

        castdata = CastMember.parse_castdata(type, cast_id,
                                             SeqBuffer(noncommon), attrs)
        res = CastMember(snr, type, name, ctime, mtime, attrs, castdata)
        return res
Exemple #5
0
 def __init__(self, snr, tag, blob):
     Media.__init__(self, snr, tag, blob)
     if blob.startswith(b'\xff\xd8'):
         self.media_type = b"JPEG"
         self.hdr = None
     elif blob.startswith(b'\0\0\1@'):
         self.media_type = "MP3"
         buf = SeqBuffer(blob)
         [hdr_len] = buf.unpack('>I')
         self.hdr = buf.readBytes(hdr_len)
         self.music = buf.peek_bytes_left()
     else:
         self.media_type = repr(blob[:16])
         self.hdr = None
def create_section_map(f, loader_context):
    while True:
        xsectheader = f.read(4)
        if len(xsectheader) < 4: break
        [stag] = struct.unpack('<4s', xsectheader)
        stag = rev(stag)
        ssize = read_varint(f)
        print("stag=%s ssize=%d" % (stag, ssize))
        if ssize==0:
            break
        else:
            sect_data = f.read(ssize)
        if stag == "Fcdr" or stag == "FGEI":
            sect_data = zlib.decompress(sect_data)
            print("ssize decompressed=%d" % (len(sect_data)))
        elif stag == "ABMP":
            buf = SeqBuffer(sect_data)
            sect_data_null = buf.unpackVarint()
            sect_data_size = buf.unpackVarint()
            sect_data = zlib.decompress(buf.peek_bytes_left())
            del buf
            print("ssize decompressed=%d=%d" % (sect_data_size, len(sect_data)))
            abmp = parse_abmp_section(sect_data, f)
            print("DB| ABMP: %s" % abmp)
        if stag != "ABMP":
            print ("DB| %s -> %s" % (stag, sect_data))
    section_base_pos = f.tell()

    # entries_by_nr = {}
    # for e in abmp:
    #     entries_by_nr[e.nr] = e

    # Fetch the sections:
    sections = []
    sections_in_ils_by_nr = {}
    ils_section_bytes = None
    for e in abmp:
        snr = e.nr
        print("DB| section nr %s: %s" % (snr,e))
        if e.offset == -1:
            # Compressed, in ILS section.
            section = LateSectionImpl(snr,e.tag,e.size)
            sections_in_ils_by_nr[snr] = section
        elif e.repr_mode==0:
            section = ZSectionImpl(snr, e.tag, e.size,
                                   section_base_pos + e.offset, f)
        elif e.repr_mode==1:
            section = UncompSectionImpl(snr, e.tag, e.size, e.offset, f)
            # f.seek(section_base_pos + e.offset)
        
            # raw_sdata = f.read(e.size)
            # if e.repr_mode==0:
            #     sdata = zlib.decompress(raw_sdata)
            # elif e.repr_mode==1:
            #     sdata = raw_sdata
        else:
            raise "unknown repr_mode: %d" % e.repr_mode
            # entries_by_nr[snr] = (e.tag,sdata)
        sections.append(section)
        if e.tag=="ILS ":
            ils_section_bytes = section.bytes()

    if sections_in_ils_by_nr:
        read_ILS_section_into(ils_section_bytes,
                              sections_in_ils_by_nr,
                              sections)

    # print "Sections=%s" % (sections.keys())
    print("Sections:")
    for e in sections:
        print("  %d: %s" % (e.nr, e))

    # Debug:
    # for snr in sections:
    #     (tag,data) = sections[snr]
    #     if tag=="Lscr" or tag=="LctX":# or tag=="Lnam":
    #         print "DB| %d: %s->%s" % (snr, tag, data)
    #     if tag=="Lnam":
    #         print "DB| %d: %s->%s" % (snr, tag, LnamSection.parse(data))

    return SectionMapImpl(sections)