summaryrefslogtreecommitdiff
path: root/plugins/python/apkfiles/apkfiles.py
blob: 7c05ca9738765ab995725be0705902010bc2d8c6 (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
35
36
37
#!/usr/bin/python
# -*- coding: utf-8 -*-

from pychrysalide 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 \
                and zf.namelist().count('AndroidManifest.xml') > 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