summaryrefslogtreecommitdiff
path: root/plugins/python/apkfiles/apkfiles.py
blob: b85b0c8ba496b00ccc1aa56342510dd39c0d8da4 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/python
# -*- coding: utf-8 -*-

from pychrysalide import PluginModule
import zipfile


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


    def get_interface(self):
        """Provide the full plugin description."""

        desc = {

            'name' : 'Welcome',
            'desc' : 'Add suppport for the APK file format',
            'version' : '0.1',

            'actions' : [ PluginModule.PGA_PLUGIN_INIT ]

        }

        return desc


    def init(self, ref):
        """Initialise l'extension."""

        return True


    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