0

I need to extract filter intents features from APK files and I could extract permission and Hardware component with androguard which is open source library and I used its APK class for extracting features but for filter intent, I've got an error.

*************
    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

I also checked the function which they put the comment. I tried all the possible arguments but I didn't get any result.
the function is :

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

Which arguments I should pass to the function? I've tried its definition example but I couldn't figure it out. thanks in advance.

M_Salehi
  • 1
  • 4

1 Answers1

1
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)