parseapk/parse_apk.py
def parse_signed_data(data, offset):
    '''parses a length prefixed signed data (inside APK Signature Scheme v2 Block)
    '''
    length = struct.unpack("<L", data[offset: offset+4])[0]
    print "\t\t\tSigned data length=", length

    # sequence of digests
    total_digests_length = struct.unpack("<L", data[offset+4: offset+8])[0]
    print "\t\t\t\tTotal digests length: ", total_digests_length
    i = 0
    nb = 1
    while i < total_digests_length:
        print "\t\t\t\tDigest struct #%d" % (nb)
        increment = parse_digest(data, offset + i + 8)
        i = i + increment
    if  i != total_digests_length:
        print "WARNING: Bad total digest length"

    # sequence of certificates
    total_certificates_length = struct.unpack("<L", data[offset+8+total_digests_length:offset+12+total_digests_length])[0]
    print "\t\t\t\tTotal certificates length: ", total_certificates_length
    parse_certificates(data, offset+12+total_digests_length, total_certificates_length)

    # sequence of attributes
    total_attributes_length = struct.unpack("<L", data[offset+12+total_digests_length+total_certificates_length:offset+16+total_digests_length+total_certificates_length])[0]
    print "\t\t\t\tTotal attributes length: ", total_attributes_length
    # we are not showing the attributes

    return 16+total_digests_length+total_certificates_length
parses a length prefixed signed data (inside APK Signature Scheme v2 Block)
    
parses a length prefixed signed data (inside APK Signature Scheme v2 Block)
parses a length prefixed signed data ( inside APK Signature Scheme v2 Block )
def parse_signed_data(data, offset):
    length = struct.unpack("<L", data[offset: offset+4])[0]
    print "\t\t\tSigned data length=", length
    total_digests_length = struct.unpack("<L", data[offset+4: offset+8])[0]
    print "\t\t\t\tTotal digests length: ", total_digests_length
    i = 0
    nb = 1
    while i < total_digests_length:
        print "\t\t\t\tDigest struct #%d" % (nb)
        increment = parse_digest(data, offset + i + 8)
        i = i + increment
    if  i != total_digests_length:
        print "WARNING: Bad total digest length"
    total_certificates_length = struct.unpack("<L", data[offset+8+total_digests_length:offset+12+total_digests_length])[0]
    print "\t\t\t\tTotal certificates length: ", total_certificates_length
    parse_certificates(data, offset+12+total_digests_length, total_certificates_length)
    total_attributes_length = struct.unpack("<L", data[offset+12+total_digests_length+total_certificates_length:offset+16+total_digests_length+total_certificates_length])[0]
    print "\t\t\t\tTotal attributes length: ", total_attributes_length
    return 16+total_digests_length+total_certificates_length
def parse_signed_data ( data , offset ) : length = struct . unpack ( "<L" , data [ offset : offset + 4 ] ) [ 0 ] print "\t\t\tSigned data length=" , length total_digests_length = struct . unpack ( "<L" , data [ offset + 4 : offset + 8 ] ) [ 0 ] print "\t\t\t\tTotal digests length: " , total_digests_length i = 0 nb = 1 while i < total_digests_length : print "\t\t\t\tDigest struct #%d" % ( nb ) increment = parse_digest ( data , offset + i + 8 ) i = i + increment if i != total_digests_length : print "WARNING: Bad total digest length" total_certificates_length = struct . unpack ( "<L" , data [ offset + 8 + total_digests_length : offset + 12 + total_digests_length ] ) [ 0 ] print "\t\t\t\tTotal certificates length: " , total_certificates_length parse_certificates ( data , offset + 12 + total_digests_length , total_certificates_length ) total_attributes_length = struct . unpack ( "<L" , data [ offset + 12 + total_digests_length + total_certificates_length : offset + 16 + total_digests_length + total_certificates_length ] ) [ 0 ] print "\t\t\t\tTotal attributes length: " , total_attributes_length return 16 + total_digests_length + total_certificates_length
parses a length prefixed signed data (inside APK Signature Scheme v2 Block)
parses a length prefixed signed data ( inside APK Signature Scheme v2 Block )
'''parses a length prefixed signed data (inside APK Signature Scheme v2 Block)
    ''' # sequence of digests # sequence of certificates # sequence of attributes # we are not showing the attributes
data
offset