Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from xml.dom import minidom
- import os
- apktool_path = '/home/res/Android/apktool1.5.2/apktool.jar'
- apkfile = 'app-release.apk'
- command = 'java -jar ' + apktool_path + ' d -f ' + '/home/res/Android/apktool1.5.2/'+apkfile
- def decompile_apk(appname):
- """ Decompile the apk and return result and the folder name"""
- print command
- status = os.system(command)
- if status == 0:
- return os.path.join(os.curdir, os.path.splitext(apkfile)[0])
- return -1
- def create_xml_tree(manifestfile):
- """Create a minidom xml tree from the manifest file"""
- if os.path.exists(manifestfile):
- return minidom.parse(manifestfile)
- return -1
- def get_application_details(xmldoc):
- """Get the application details from the manifest"""
- manifest = xmldoc.getElementsByTagName('manifest')[0]
- application = xmldoc.getElementsByTagName('application')[0]
- app = {'name': manifest.attributes['package'].value, 'appname': application.attributes['android:name'].value}
- return app
- def get_activity_details(xmldoc):
- """Get the activity details from the manifest"""
- activity_list = xmldoc.getElementsByTagName('activity')
- activities = []
- for activity in activity_list:
- activities.append(activity.attributes['android:name'].value)
- return activities
- def get_service_details(xmldoc):
- """Get the service details from the manifest"""
- service_list = xmldoc.getElementsByTagName('service')
- services = []
- for service in service_list:
- services.append(activity.attributes['android:name'].value)
- return services
- def get_declared_permission_details(xmldoc):
- """Get the declared permissions detail from the manifest"""
- decl_permissions_list = xmldoc.getElementsByTagName('service')
- decl_permissions = []
- for permission in decl_permissions_list:
- decl_permissions.append(permission.attributes['android:name'].value)
- return decl_permissions
- def get_permission_details(xmldoc):
- """Get the permissions declared in the app"""
- permissions_list = xmldoc.getElementsByTagName('uses-permission')
- permissions = []
- for permission in permissions_list:
- permissions.append(permission.attributes['android:name'].value)
- return permissions
- def get_feature_details(xmldoc):
- """Get the features declared in the app"""
- featuress_list = xmldoc.getElementsByTagName('uses-feature')
- features = []
- for feature in features_list:
- features.append(feature.attributes['android:name'].value)
- return features
- def main():
- """Start the process"""
- status = decompile_apk(apkfile)
- if status != -1:
- xmldoc = create_xml_tree(status+'/AndroidManifest.xml')
- if xmldoc!= -1:
- application = get_application_details(xmldoc)
- activities = get_activity_details(xmldoc)
- permissions = get_permission_details(xmldoc)
- features = get_feature_details(xmldoc)
- print '------------------------------------------------------------------'
- print '------------------------------------------------------------------'
- print application['name'],'<>', application['appname']
- print '------------------------------------------------------------------'
- for activity in activities:
- print activity + '\n'
- print '------------------------------------------------------------------'
- for permission in permissions:
- print permission + '\n'
- print '------------------------------------------------------------------'
- print '------------------------------------------------------------------'
- for feature in features:
- print feature + '\n'
- print '------------------------------------------------------------------'
- else:
- print 'Unable to parse manifest'
- else:
- print 'There seems to be some error decompiling file'
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement