首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用androguard或aapt从.apk中提取过滤意图?

如何使用androguard或aapt从.apk中提取过滤意图?
EN

Stack Overflow用户
提问于 2019-04-28 17:27:06
回答 1查看 672关注 0票数 0

我需要从APK文件中提取过滤意图特征,我可以使用androguard提取权限和硬件组件,这是一个开源库,我使用它的APK类来提取特征,但是对于过滤意图,我得到了一个错误。

代码语言:javascript
复制
*************
    filter_intent_accepted = apk.get_intent_filters()
TypeError: get_intent_filters() missing 2 required positional arguments: 'itemtype' and 'name'

Process finished with exit code 1

我还检查了他们添加评论的函数。我尝试了所有可能的论点,但没有得到任何结果。

该函数为:

代码语言:javascript
复制
def get_intent_filters(self, itemtype, name):
        """
        Find intent filters for a given item and name.

        Intent filter are attached to activities, services or receivers.
        You can search for the intent filters of such items and get a dictionary of all
        attached actions and intent categories.

        :param itemtype: the type of parent item to look for, e.g. `activity`,  `service` or `receiver`
        :param name: the `android:name` of the parent item, e.g. activity name
        :return: a dictionary with the keys `action` and `category` containing the `android:name` of those items
        """
        d = {"action": [], "category": []}

        for i in self.xml:
            # TODO: this can probably be solved using a single xpath
            for item in self.xml[i].findall(".//" + itemtype):
                if self._format_value(item.get(NS_ANDROID + "name")) == name:
                    for sitem in item.findall(".//intent-filter"):
                        for ssitem in sitem.findall("action"):
                            if ssitem.get(NS_ANDROID + "name") not in d["action"]:
                                d["action"].append(ssitem.get(NS_ANDROID + "name"))
                        for ssitem in sitem.findall("category"):
                            if ssitem.get(NS_ANDROID + "name") not in d["category"]:
                                d["category"].append(ssitem.get(NS_ANDROID + "name"))

        if not d["action"]:
            del d["action"]

        if not d["category"]:
            del d["category"]

        return d

我应该向函数传递哪些参数?我试过它的定义示例,但是我不能理解它。提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2019-06-29 18:28:34

代码语言:javascript
复制
def printIntentFilters(itemtype, name):
    print ('\t' + name + ':')
    for action,intent_name in apk.get_intent_filters(itemtype, name).items():
                print ('\t\t' + action + ':')
                for intent in intent_name:
                        print ('\t\t\t' + intent)
    return

# Intent filters 
print('\nServices and their intent-filters:')
services = apk.get_services()
serviceString = 'service'
for service in services:
    printIntentFilters(serviceString, service)
print('\nReceivers and their intent-filters:')
receivers = apk.get_receivers()
receiverString = 'receiver'
for receiver in receivers:
    printIntentFilters(receiverString, receiver)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55888851

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档