Ejemplo n.º 1
0
    def ParseManifest(self, ManifestFile):
        ap = AXMLPrinter(open(ManifestFile, "rb").read())
        xml = minidom.parseString(ap.getBuff())
        package = xml.documentElement.getAttribute("package")

        classes = set()
        classnames = set()

        for tag_name in ["activity", "service", "receiver", "provider"]:
            for item in xml.getElementsByTagName(tag_name):
                value = item.getAttribute("android:name")

                if len(value) > 0:
                    if value[
                            0] == ".":  # Short form with implicit package name
                        classes.add(package + value)
                        classnames.add(value.split('.')[-1])
                    else:  # Fully-qualified name
                        classes.add(value)
                        classnames.add(value.split('.')[-1])
                        # Hack: Some apke does not follow this rule as set in the SDK
                        # As a workround treat them as short form as well
                        classes.add(package + '.' + value)

        return classes, classnames
Ejemplo n.º 2
0
    def __init__(self, file_name):

        APKParser.__init__(self, file_name)
        self.axml = {}
        self.xml = {}

        self.package = ''
        self.allow_backup = ''
        self.debuggable = ''
        self.androidversion = {}
        self.permissions = []
        self.parse_res = {}

        self.__comp_info = {}
        self.__components = []
        self.__providers = {}
        self.__activitys = {}
        self.__receivers = {}
        self.__services = {}
        self.__exported = {
            'activity': [],
            'service': [],
            'provider': [],
            'receiver': []
        }
        self.__exported_detail = {
            'activity': [],
            'service': [],
            'provider': [],
            'receiver': []
        }

        for i in self.zip.namelist():
            if i == 'AndroidManifest.xml':
                self.axml[i] = AXMLPrinter(self.zip.read(i))
                try:
                    self.xml[i] = minidom.parseString(self.axml[i].get_buff())
                except:
                    self.xml[i] = None

                if self.xml[i] != None:
                    self.package = self.xml[i].documentElement.getAttribute(
                        'package')
                    self.androidversion['Code'] = self.xml[
                        i].documentElement.getAttribute('android:versionCode')
                    self.androidversion['Name'] = self.xml[
                        i].documentElement.getAttribute('android:versionName')
                    self.share_user_id = self.xml[
                        i].documentElement.getAttribute('android:sharedUserId')

                    for item in self.xml[i].getElementsByTagName(
                            'uses-permission'):
                        self.permissions.append(
                            str(item.getAttribute('android:name')))

                    self.valid_apk = True
Ejemplo n.º 3
0
    def ParseManifest(self, ManifestFile):
        ap = AXMLPrinter(open(ManifestFile, "rb").read())
        xml = minidom.parseString(ap.getBuff())
        package = xml.documentElement.getAttribute( "package" )

        classes = set()
        classnames = set()

        for tag_name in ["activity", "service", "receiver", "provider"]:
            for item in xml.getElementsByTagName(tag_name) :
                value = item.getAttribute("android:name")
               
                if len(value) > 0 :
                    if value[0] == "." : # Short form with implicit package name
                        classes.add(package + value)
                        classnames.add(value.split('.')[-1])
                    else : # Fully-qualified name
                        classes.add(value)
                        classnames.add(value.split('.')[-1])
                        # Hack: Some apke does not follow this rule as set in the SDK
                        # As a workround treat them as short form as well
                        classes.add(package + '.' + value)
                        
        return classes, classnames
Ejemplo n.º 4
0
    def ParseManifest(self, ManifestFilename):
        mfile = open(ManifestFilename, "rb")
        xml = minidom.parseString(AXMLPrinter(mfile.read()).getBuff())
        mfile.close()
        
        package = xml.documentElement.getAttribute( "package" )

        ## Replace <application>:<android:name> with APIHook
        app = xml.getElementsByTagName("application")[0]
        self.AppClass = app.getAttribute("android:name")
        
        if self.AppClass:
            ## The APK already implements an Application class, we need to 
            ## do a bit of work later: modify the Application class so that it
            ## extends on top of our Application class. Here we just record the 
            ## full name of the original class.
            if self.AppClass.find('.') == -1:
                self.AppClass = package + '.' + self.AppClass
            elif self.AppClass[0] == '.':
                self.AppClass = package + self.AppClass
            elif self.AppClass[:2] == '/.':     
                self.AppClass = package + self.AppClass[1:]
        else:
            ## Otherwise just insert our Application definition into the manifest
            app.setAttribute("android:name", APIHook_Class)
        
        ## Add the dialog activity
        activity_element = xml.createElement("activity")
        activity_element.setAttribute("android:process", ":APIHookDialog")
        activity_element.setAttribute(  "android:theme", "@android:style/Theme.Translucent.NoTitleBar")
        activity_element.setAttribute(   "android:name", "com.rx201.apkmon.APIHookDialogActivity")
        app.appendChild(activity_element)
        
        ##DEBUG: Add permission to write to SD card.
	if 'AURASIUM_DEBUG_PAYLOAD' in os.environ:
            #  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
            manifest = xml.getElementsByTagName("manifest")[0]
            permission_element = xml.createElement("uses-permission")
            permission_element.setAttribute(   "android:name", "android.permission.WRITE_EXTERNAL_STORAGE")
            manifest.appendChild(permission_element)
        
        mfile = codecs.open(ManifestFilename, "wb", "utf-8")
        xml.writexml(mfile)
        mfile.close();
Ejemplo n.º 5
0
import re
import sys, os
import codecs
#http://androguard.blogspot.com/2011/03/androids-binary-xml.html
from apk import AXMLPrinter
from xml.dom import minidom

if sys.argv[1] != '-':
    ap = AXMLPrinter(open(sys.argv[1], "rb").read())
else:
    ap = AXMLPrinter(sys.stdin.read())
    
xml = minidom.parseString(ap.getBuff())

if sys.argv[2] != '-':
    xml.writexml(codecs.open(sys.argv[2], "wb", "utf-8"))
else:
    xml.writexml(codecs.getwriter('utf-8')(sys.stdout))