parseapk/parse_apk.py
def parse_cd(data, offset):
    '''
    parses Central Directory header for ZIP file
    data = content of APK
    offset = offset to the beginning of CD
    '''
    print "\033[1;32;1m---------------- Central Directory ------------"
    print "Offset: %d (0x%08x)" % (offset, offset)
    cdir = data[offset:]

    # parsing the central directory header
    signature = cdir[0:4]
    #print "Tag: ", signature
    version_made_by = struct.unpack("<H", cdir[4:6])[0]
    print "Version made by: ", version_made_by
    version_needed = struct.unpack("<H", cdir[6:8])[0]
    print "Version needed : ", version_needed
    compressed_size = struct.unpack("<L", cdir[20:24])[0]
    print "Compressed size: ", compressed_size
    uncompressed_size = struct.unpack("<L", cdir[24:28])[0]
    print "Uncompressed size: ", uncompressed_size
    filename_length = struct.unpack("<H", cdir[28:30])[0]
    extrafield_length = struct.unpack("<H", cdir[30:32])[0]
    comment_length = struct.unpack("<H", cdir[32:34])[0] #file comment
    offset_local = struct.unpack("<L", cdir[42:46])[0]
    print "Relative offset to local header: ", offset_local

    #After the header:
    if filename_length > 0:
        filename = cdir[46:46+filename_length]
        print "File name (length=%d): %s" % (filename_length ,filename)

    if comment_length > 0:
        comment = cdir[46+filename_length+extrafield_length:46+filename_length+extrafield_length+comment_length]
        print "File comment (length=%d): %s" % (comment_length, comment)
    print "\033[0m"

    parses Central Directory header for ZIP file
    data = content of APK
    offset = offset to the beginning of CD
    
parses Central Directory header for ZIP file
data = content of APK
offset = offset to the beginning of CD
parses Central Directory header for ZIP file data = content of APK offset = offset to the beginning of CD
def parse_cd(data, offset):
    print "\033[1;32;1m---------------- Central Directory ------------"
    print "Offset: %d (0x%08x)" % (offset, offset)
    cdir = data[offset:]
    signature = cdir[0:4]
    version_made_by = struct.unpack("<H", cdir[4:6])[0]
    print "Version made by: ", version_made_by
    version_needed = struct.unpack("<H", cdir[6:8])[0]
    print "Version needed : ", version_needed
    compressed_size = struct.unpack("<L", cdir[20:24])[0]
    print "Compressed size: ", compressed_size
    uncompressed_size = struct.unpack("<L", cdir[24:28])[0]
    print "Uncompressed size: ", uncompressed_size
    filename_length = struct.unpack("<H", cdir[28:30])[0]
    extrafield_length = struct.unpack("<H", cdir[30:32])[0]
    comment_length = struct.unpack("<H", cdir[32:34])[0] 
    offset_local = struct.unpack("<L", cdir[42:46])[0]
    print "Relative offset to local header: ", offset_local
    if filename_length > 0:
        filename = cdir[46:46+filename_length]
        print "File name (length=%d): %s" % (filename_length ,filename)
    if comment_length > 0:
        comment = cdir[46+filename_length+extrafield_length:46+filename_length+extrafield_length+comment_length]
        print "File comment (length=%d): %s" % (comment_length, comment)
    print "\033[0m"
def parse_cd ( data , offset ) : print "\033[1;32;1m---------------- Central Directory ------------" print "Offset: %d (0x%08x)" % ( offset , offset ) cdir = data [ offset : ] signature = cdir [ 0 : 4 ] version_made_by = struct . unpack ( "<H" , cdir [ 4 : 6 ] ) [ 0 ] print "Version made by: " , version_made_by version_needed = struct . unpack ( "<H" , cdir [ 6 : 8 ] ) [ 0 ] print "Version needed : " , version_needed compressed_size = struct . unpack ( "<L" , cdir [ 20 : 24 ] ) [ 0 ] print "Compressed size: " , compressed_size uncompressed_size = struct . unpack ( "<L" , cdir [ 24 : 28 ] ) [ 0 ] print "Uncompressed size: " , uncompressed_size filename_length = struct . unpack ( "<H" , cdir [ 28 : 30 ] ) [ 0 ] extrafield_length = struct . unpack ( "<H" , cdir [ 30 : 32 ] ) [ 0 ] comment_length = struct . unpack ( "<H" , cdir [ 32 : 34 ] ) [ 0 ] offset_local = struct . unpack ( "<L" , cdir [ 42 : 46 ] ) [ 0 ] print "Relative offset to local header: " , offset_local if filename_length > 0 : filename = cdir [ 46 : 46 + filename_length ] print "File name (length=%d): %s" % ( filename_length , filename ) if comment_length > 0 : comment = cdir [ 46 + filename_length + extrafield_length : 46 + filename_length + extrafield_length + comment_length ] print "File comment (length=%d): %s" % ( comment_length , comment ) print "\033[0m"
parses Central Directory header for ZIP file
data = content of APK
offset = offset to the beginning of CD
parses Central Directory header for ZIP file data = content of APK offset = offset to the beginning of CD
'''
    parses Central Directory header for ZIP file
    data = content of APK
    offset = offset to the beginning of CD
    ''' # parsing the central directory header #print "Tag: ", signature #file comment #After the header:
data
offset