From df6298b8f0f2144ad8e975ab0b0b30cc73ee9b5c Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Mon, 23 Jul 2018 11:24:34 +0200 Subject: Fix the Python scripts loading. --- configure.ac | 1 - plugins/pychrysalide/plugin.c | 37 ++++++++------- plugins/python/Makefile.am | 2 +- plugins/python/apkfiles/apkfiles.py | 6 +-- plugins/python/samples/Makefile.am | 9 ---- plugins/python/samples/__init__.py | 2 - plugins/python/samples/basic_blocks.py | 83 ---------------------------------- plugins/python/samples/demo.py | 30 ------------ 8 files changed, 24 insertions(+), 146 deletions(-) delete mode 100644 plugins/python/samples/Makefile.am delete mode 100644 plugins/python/samples/__init__.py delete mode 100644 plugins/python/samples/basic_blocks.py delete mode 100644 plugins/python/samples/demo.py diff --git a/configure.ac b/configure.ac index e2b9c97..3eebab2 100644 --- a/configure.ac +++ b/configure.ac @@ -377,7 +377,6 @@ AC_CONFIG_FILES([Makefile plugins/pychrysalide/mangling/Makefile plugins/python/Makefile plugins/python/apkfiles/Makefile - plugins/python/samples/Makefile plugins/readdex/Makefile plugins/readelf/Makefile plugins/readmc/Makefile diff --git a/plugins/pychrysalide/plugin.c b/plugins/pychrysalide/plugin.c index f8b4fc8..57891a6 100644 --- a/plugins/pychrysalide/plugin.c +++ b/plugins/pychrysalide/plugin.c @@ -80,7 +80,7 @@ static bool g_python_plugin_read_interface(GPythonPlugin *); static bool g_python_plugin_do_init(GPythonPlugin *); /* Procède à l'extinction du greffon. */ -static bool g_python_plugin_do_exit(GPythonPlugin *, GObject *); +static bool g_python_plugin_do_exit(GPythonPlugin *); /* Procède à une opération liée à un contenu binaire. */ static void g_python_plugin_handle_binary_content(const GPythonPlugin *, PluginAction, GBinContent *, wgroup_id_t, GtkStatusStack *); @@ -557,18 +557,20 @@ static bool g_python_plugin_read_interface(GPythonPlugin *plugin) static bool g_python_plugin_do_init(GPythonPlugin *plugin) { bool result; /* Bilan à retourner */ - PyObject *args; /* Arguments pour l'appel */ PyObject *value; /* Valeur obtenue */ - args = Py_None; - Py_INCREF(args); + if (!has_python_method(plugin->instance, "init")) + result = true; - value = run_python_method(plugin->instance, "init", args); + else + { + value = run_python_method(plugin->instance, "init", NULL); - result = (value != NULL && PyObject_IsTrue(value)); + result = (value != NULL && PyObject_IsTrue(value)); - Py_XDECREF(value); - Py_DECREF(args); + Py_XDECREF(value); + + } return result; @@ -578,7 +580,6 @@ static bool g_python_plugin_do_init(GPythonPlugin *plugin) /****************************************************************************** * * * Paramètres : plugin = greffon à initialiser. * -* ref = espace de référencement global. * * * * Description : Procède à l'extinction du greffon. * * * @@ -588,21 +589,23 @@ static bool g_python_plugin_do_init(GPythonPlugin *plugin) * * ******************************************************************************/ -static bool g_python_plugin_do_exit(GPythonPlugin *plugin, GObject *ref) +static bool g_python_plugin_do_exit(GPythonPlugin *plugin) { bool result; /* Bilan à retourner */ - PyObject *args; /* Arguments pour l'appel */ PyObject *value; /* Valeur obtenue */ - args = PyTuple_New(1); - PyTuple_SetItem(args, 0, pygobject_new(ref)); + if (!has_python_method(plugin->instance, "exit")) + result = true; - value = run_python_method(plugin->instance, "exit", args); + else + { + value = run_python_method(plugin->instance, "exit", NULL); - result = PyObject_IsTrue(value); + result = (value != NULL && PyObject_IsTrue(value)); - Py_XDECREF(value); - Py_DECREF(args); + Py_XDECREF(value); + + } return result; diff --git a/plugins/python/Makefile.am b/plugins/python/Makefile.am index 35f15eb..efbb704 100644 --- a/plugins/python/Makefile.am +++ b/plugins/python/Makefile.am @@ -1,2 +1,2 @@ -SUBDIRS = apkfiles samples +SUBDIRS = apkfiles diff --git a/plugins/python/apkfiles/apkfiles.py b/plugins/python/apkfiles/apkfiles.py index b85b0c8..c45f8c9 100644 --- a/plugins/python/apkfiles/apkfiles.py +++ b/plugins/python/apkfiles/apkfiles.py @@ -14,7 +14,7 @@ class ApkFiles(PluginModule): desc = { - 'name' : 'Welcome', + 'name' : 'ApkFiles', 'desc' : 'Add suppport for the APK file format', 'version' : '0.1', @@ -25,8 +25,8 @@ class ApkFiles(PluginModule): return desc - def init(self, ref): - """Initialise l'extension.""" + def init(self): + """Initialize the plugin.""" return True diff --git a/plugins/python/samples/Makefile.am b/plugins/python/samples/Makefile.am deleted file mode 100644 index 816868c..0000000 --- a/plugins/python/samples/Makefile.am +++ /dev/null @@ -1,9 +0,0 @@ - -samplesdir = $(pluginsdir)/python/apkfiles - -samples_DATA = \ - __init__.py \ - basic_blocks.py \ - demo.py - -EXTRA_DIST = $(samples_DATA) diff --git a/plugins/python/samples/__init__.py b/plugins/python/samples/__init__.py deleted file mode 100644 index 7186d48..0000000 --- a/plugins/python/samples/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ - -from demo import Demo as samples diff --git a/plugins/python/samples/basic_blocks.py b/plugins/python/samples/basic_blocks.py deleted file mode 100644 index 90f3a2c..0000000 --- a/plugins/python/samples/basic_blocks.py +++ /dev/null @@ -1,83 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -import re -from pychrysalide.analysis import InstrBlock -from pychrysalide.analysis.blocks import FlowBlock - - -class VisitIndent: - - def __init__(self): - self.offset = 0 - - def get_padding(self): - return ' ' * self.offset - - def inc_offset(self): - self.offset = self.offset + 1 - - def dec_offset(self): - self.offset = self.offset - 1 - - -def get_c_address_of_pygobject(obj): - """Parse the string representation of a given object and return its memory address.""" - - ret = re.match('.*(0x[0-9a-f]+)\)>', str(obj), re.I) - - if ret == None: - result = '???' - else: - result = ret.group(1) - - return result - - -def visit_block(block, order, indent): - """Describe each visited basic block.""" - - padding = indent.get_padding() - addr = get_c_address_of_pygobject(block) - - if isinstance(block, FlowBlock): - - start, end = block.boundary_addresses - rank = block.rank - links = block.get_links_block() - - if links != None: - laddr = get_c_address_of_pygobject(links) - print '%s- flow %s (rank=%d) : 0x%08lx -> 0x%08lx (links = %s)' \ - % (padding, addr, rank, start, end, laddr) - - else: - print '%s- flow %s (rank=%d) : 0x%08lx -> 0x%08lx' \ - % (padding, addr, rank, start, end) - - else: - - if order != InstrBlock.BVO_OUT: - - print '%s- virtual %s' % (padding, addr) - indent.inc_offset() - - else: - indent.dec_offset() - - return True - - -def show_basic_blocks(binary): - """Print the tree of all basic blocks for each routine of a given binary.""" - - fmt = binary.get_format() - indent = VisitIndent() - - for r in fmt.routines: - - print '==== %s ====' % str(r) - - r.basic_blocks.visit(visit_block, indent) - - print diff --git a/plugins/python/samples/demo.py b/plugins/python/samples/demo.py deleted file mode 100644 index c406231..0000000 --- a/plugins/python/samples/demo.py +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -from pychrysalide import Plugin -from pychrysalide.gui.panels import LogPanel - -from basic_blocks import show_basic_blocks - - -class Demo(Plugin): - """Demonstration plugin.""" - - def init(self, ref): - """Initialize the plugin.""" - - LogPanel.log_message(LogPanel.LMT_WARNING, 'Welcome to the demo Python plugin !') - - return True - - - def get_action(self): - """Register the plugin for given actions.""" - - return Plugin.PGA_BINARY_GROUPED - - - def execute_on_binary(self, binary, action): - """Process registered actions.""" - - show_basic_blocks(binary) -- cgit v0.11.2-87-g4458