summaryrefslogtreecommitdiff
path: root/plugins/python/apkfiles/apkfiles.py
blob: fe7deb8259b49d6ffd533f561c520ecbdd0ce0bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/python
# -*- coding: utf-8 -*-

from pyoida import Plugin

import zipfile


class ApkFiles(Plugin):
    """Open and process APK files."""

    def get_action(self):
        """Register the plugin for given actions."""

        return Plugin.PGA_FORMAT_MATCHER

    def is_matching(self, filename, data):
        """Define if the given file can be handled."""

        if not zipfile.is_zipfile(filename):
            return Plugin.MFA_NONE, None, None

        zf = zipfile.ZipFile(filename)

        if zf.namelist().count('classes.dex') > 0:

            f = zf.open('classes.dex', 'r')
            data = f.read()
            f.closed

            return Plugin.MFA_RELOAD, None, bytearray(data)

        else:
            return Plugin.MFA_NONE, None, None