def parse_abmp_section(blob, file): buf = SeqBuffer(blob) v1 = buf.unpackVarint() v2 = buf.unpackVarint() section_count = buf.unpackVarint() print("ABMP header: %s" % [v1,v2, section_count]) #w1sum=0; w2sum=0; w3sum=0; w4sum=0 csum=0; usum=0 sections = [] for i in range(section_count): id = buf.unpackVarint() offset = buf.unpackVarint() # offset comp_size = buf.unpackVarint() # size in file decomp_size = buf.unpackVarint() # size, decompressed repr_mode = buf.unpackVarint() [tag] = buf.unpack('<4s') tag = rev(tag) print("ABMP entry: %s" % ([id, tag, offset, comp_size, decomp_size, repr_mode])) sections.append(ABMPEntry(id, tag, comp_size, offset, repr_mode)) print("Bytes left in ABMP section: %d" % buf.bytes_left()) # print "Sums: %s" % [csum, usum] return sections
def parse_abmp_section(blob, file): buf = SeqBuffer(blob) v1 = buf.unpackVarint() v2 = buf.unpackVarint() section_count = buf.unpackVarint() print("ABMP header: %s" % [v1,v2, section_count]) #w1sum=0; w2sum=0; w3sum=0; w4sum=0 csum=0; usum=0 sections = [] for i in range(section_count): id = buf.unpackVarint() offset = buf.unpackVarint() # offset comp_size = buf.unpackVarint() # size in file decomp_size = buf.unpackVarint() # size, decompressed repr_mode = buf.unpackVarint() [tag] = buf.unpack('<4s') tag = rev(tag) print("ABMP entry: %s" % ([id, tag, offset, comp_size, decomp_size, repr_mode])) sections.append(ABMPEntry(id, tag, comp_size, offset, repr_mode)) print "Bytes left in ABMP section: %d" % buf.bytes_left() # print "Sums: %s" % [csum, usum] return sections
def parse_cast_lib_section(blob, loader_context): # Read header: buf = SeqBuffer(blob) [v1, nElems, ofsPerElem, nOffsets, v5] = buf.unpack('>iiHii') print( "DB| Cast lib section header: nElems=%d, nOffsets=%d, ofsPerElem=%d, misc=%s" % (nElems, nOffsets, ofsPerElem, [v1, v5])) # Read offset table: offsets = [] for i in range(nOffsets): [offset] = buf.unpack('>i') offsets.append(offset) base = buf.tell() #print "DB| Cast lib section: offsets=%s" % offsets offnr = 0 table = [] for enr in range(nElems): entry = [] for i in range(ofsPerElem): subblob = buf.buf[base + offsets[offnr]:base + offsets[offnr + 1]] offnr += 1 #print "DB| i=%d subblob=<%s>" % (i,subblob) buf2 = SeqBuffer(subblob) if i == 0: item = buf2.unpackString8() elif i == 1: if buf2.bytes_left() > 0: item = buf2.unpackString8() else: item = None elif i == 2: [item] = buf2.unpack('>h') elif i == 3: [w1, w2, w3, w4] = buf2.unpack('>hhhh') item = (w1, w2, w3, w4) else: item = subblob entry.append(item) print("DB| Cast lib table entry #%d: %s" % (enr + 1, entry)) [name, path, _zero, (low_idx, high_idx, assoc_id, self_idx)] = entry table.append( CastLibrary(enr + 1, name, path, assoc_id, (low_idx, high_idx), self_idx)) return CastLibraryTable(table)
def parse_cast_lib_section(blob, loader_context): # Read header: buf = SeqBuffer(blob) [v1,nElems,ofsPerElem,nOffsets,v5] = buf.unpack('>iiHii') print "DB| Cast lib section header: nElems=%d, nOffsets=%d, ofsPerElem=%d, misc=%s" % (nElems, nOffsets, ofsPerElem, [v1,v5]) # Read offset table: offsets = [] for i in range(nOffsets): [offset] = buf.unpack('>i') offsets.append(offset) base = buf.tell() #print "DB| Cast lib section: offsets=%s" % offsets offnr = 0 table = [] for enr in range(nElems): entry = [] for i in range(ofsPerElem): subblob = buf.buf[base + offsets[offnr]:base + offsets[offnr+1]] offnr += 1 #print "DB| i=%d subblob=<%s>" % (i,subblob) buf2 = SeqBuffer(subblob) if i==0: item = buf2.unpackString8() elif i==1: if buf2.bytes_left()>0: item = buf2.unpackString8() else: item = None elif i==2: [item] = buf2.unpack('>h') elif i==3: [w1,w2,w3,w4] = buf2.unpack('>hhhh') item = (w1,w2,w3,w4) else: item = subblob entry.append(item) print "DB| Cast lib table entry #%d: %s" % (enr+1,entry) [name, path, _zero, (low_idx,high_idx, assoc_id, self_idx)] = entry table.append(CastLibrary(enr+1, name, path, assoc_id, (low_idx,high_idx), self_idx)) return CastLibraryTable(table)