Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.67 KB | None | 0 0
  1. from xml.dom import minidom
  2. import os
  3.  
  4. apktool_path = '/home/res/Android/apktool1.5.2/apktool.jar'
  5. apkfile = 'app-release.apk'
  6. command = 'java -jar ' + apktool_path + ' d -f ' + '/home/res/Android/apktool1.5.2/'+apkfile
  7.  
  8.  
  9. def decompile_apk(appname):
  10.     """  Decompile the apk and return result and the folder name"""
  11.     print command
  12.     status = os.system(command)
  13.     if status == 0:
  14.         return os.path.join(os.curdir, os.path.splitext(apkfile)[0])
  15.     return -1
  16.  
  17.  
  18. def create_xml_tree(manifestfile):
  19.     """Create a minidom xml tree from the manifest file"""
  20.     if os.path.exists(manifestfile):
  21.         return minidom.parse(manifestfile)
  22.     return -1
  23.  
  24. def get_application_details(xmldoc):
  25.     """Get the application details from the manifest"""
  26.     manifest = xmldoc.getElementsByTagName('manifest')[0]
  27.     application = xmldoc.getElementsByTagName('application')[0]
  28.     app = {'name': manifest.attributes['package'].value,  'appname': application.attributes['android:name'].value}
  29.     return app
  30.  
  31. def get_activity_details(xmldoc):
  32.     """Get the activity details from the manifest"""
  33.     activity_list = xmldoc.getElementsByTagName('activity')
  34.     activities = []
  35.     for activity in activity_list:
  36.         activities.append(activity.attributes['android:name'].value)
  37.     return activities
  38.  
  39. def get_service_details(xmldoc):
  40.     """Get the service details from the manifest"""
  41.     service_list = xmldoc.getElementsByTagName('service')
  42.     services = []
  43.     for service in service_list:
  44.         services.append(activity.attributes['android:name'].value)
  45.     return services
  46.  
  47. def get_declared_permission_details(xmldoc):
  48.     """Get the declared permissions detail from the manifest"""
  49.     decl_permissions_list = xmldoc.getElementsByTagName('service')
  50.     decl_permissions = []
  51.     for permission in decl_permissions_list:
  52.         decl_permissions.append(permission.attributes['android:name'].value)
  53.     return decl_permissions
  54.  
  55.  
  56.  
  57. def get_permission_details(xmldoc):
  58.     """Get the permissions declared in the app"""
  59.     permissions_list = xmldoc.getElementsByTagName('uses-permission')
  60.     permissions = []
  61.     for permission in permissions_list:
  62.         permissions.append(permission.attributes['android:name'].value)
  63.     return permissions
  64.  
  65. def get_feature_details(xmldoc):
  66.     """Get the features declared in the app"""
  67.     featuress_list = xmldoc.getElementsByTagName('uses-feature')
  68.     features = []
  69.     for feature in features_list:
  70.         features.append(feature.attributes['android:name'].value)
  71.     return features
  72.  
  73.  
  74. def main():
  75.     """Start the process"""
  76.     status = decompile_apk(apkfile)
  77.     if status != -1:
  78.         xmldoc = create_xml_tree(status+'/AndroidManifest.xml')
  79.         if xmldoc!= -1:
  80.             application = get_application_details(xmldoc)
  81.             activities  = get_activity_details(xmldoc)
  82.             permissions = get_permission_details(xmldoc)
  83.             features    = get_feature_details(xmldoc)
  84.             print '------------------------------------------------------------------'
  85.             print '------------------------------------------------------------------'
  86.             print application['name'],'<>', application['appname']
  87.             print '------------------------------------------------------------------'
  88.             for activity in activities:
  89.                 print activity + '\n'
  90.             print '------------------------------------------------------------------'
  91.             for permission in permissions:
  92.                 print permission + '\n'
  93.             print '------------------------------------------------------------------'
  94.             print '------------------------------------------------------------------'
  95.             for feature in features:
  96.                 print feature + '\n'
  97.             print '------------------------------------------------------------------'
  98.  
  99.         else:
  100.             print 'Unable to parse manifest'
  101.     else:
  102.         print 'There seems to be some error decompiling file'
  103.  
  104.  
  105. if __name__ == '__main__':
  106.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement