示例#1
0
    def processAPK(self):
        xml = {}
        error = True
        try:
            zip = zipfile.ZipFile(self.filename)

            for i in zip.namelist():
                if i == "AndroidManifest.xml":
                    try:
                        xml[i] = minidom.parseString(zip.read(i))
                    except:
                        xml[i] = minidom.parseString(
                            AXMLPrinter(zip.read(i)).getBuff())

                    for item in xml[i].getElementsByTagName('manifest'):
                        self.packageNames.append(
                            str(item.getAttribute("package")))

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

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

                    for item in xml[i].getElementsByTagName('receiver'):
                        self.recvs.append(
                            str(item.getAttribute("android:name")))
                        for child in item.getElementsByTagName('action'):
                            self.recvsaction[str(
                                item.getAttribute("android:name"))] = (str(
                                    child.getAttribute("android:name")))

                    for item in xml[i].getElementsByTagName('activity') + xml[
                            i].getElementsByTagName('activity-alias'):
                        activity = str(item.getAttribute("android:name"))
                        self.activities[activity] = {}
                        self.activities[activity]["actions"] = list()

                        for child in item.getElementsByTagName('action'):
                            self.activities[activity]["actions"].append(
                                str(child.getAttribute("android:name")))

                    for activity in self.activities:
                        for action in self.activities[activity]["actions"]:
                            if action == 'android.intent.action.MAIN':
                                self.mainActivity = activity
                    error = False

                    break

            if (error == False):
                return 1
            else:
                return 0

        except:
            return 0
示例#2
0
    try:
        duration = int(sys.argv[2])
    except:
        print "Usage: ./droidbox.sh filename.apk <duration in seconds> (optional)"
        sys.exit(1)

apkName = sys.argv[1]
raw = fd.read()
fd.close()
zip = zipfile.ZipFile(StringIO.StringIO(raw))
for i in zip.namelist():
    if i == "AndroidManifest.xml":
        try:
            xml[i] = minidom.parseString(zip.read(i))
        except:
            xml[i] = minidom.parseString(AXMLPrinter(zip.read(i)).getBuff())
            for item in xml[i].getElementsByTagName('manifest'):
                packageNames.append(str(item.getAttribute("package")))
            for item in xml[i].getElementsByTagName('permission'):
                enfperm.append(str(item.getAttribute("android:name")))
            for item in xml[i].getElementsByTagName('uses-permission'):
                permissions.append(str(item.getAttribute("android:name")))
            for item in xml[i].getElementsByTagName('receiver'):
                recvs.append(str(item.getAttribute("android:name")))
                for child in item.getElementsByTagName('action'):
                    recvsaction[str(item.getAttribute("android:name"))] = (str(
                        child.getAttribute("android:name")))
            for item in xml[i].getElementsByTagName('activity'):
                activities.append(str(item.getAttribute("android:name")))
                for child in item.getElementsByTagName('action'):
                    activityaction[str(