diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/pychrysalide/core/Makefile.am | 1 | ||||
-rw-r--r-- | plugins/pychrysalide/core/logs.c | 2 | ||||
-rw-r--r-- | plugins/pychrysalide/core/module.c | 2 | ||||
-rw-r--r-- | plugins/pychrysalide/core/processors.c | 248 | ||||
-rw-r--r-- | plugins/pychrysalide/core/processors.h | 39 | ||||
-rw-r--r-- | plugins/pychrysalide/format/executable.c | 2 | ||||
-rw-r--r-- | plugins/ropgadgets/finder.c | 2 |
7 files changed, 293 insertions, 3 deletions
diff --git a/plugins/pychrysalide/core/Makefile.am b/plugins/pychrysalide/core/Makefile.am index 4018012..131e1b9 100644 --- a/plugins/pychrysalide/core/Makefile.am +++ b/plugins/pychrysalide/core/Makefile.am @@ -7,6 +7,7 @@ libpychrysacore_la_SOURCES = \ logs.h logs.c \ module.h module.c \ params.h params.c \ + processors.h processors.c \ queue.h queue.c libpychrysacore_la_LDFLAGS = diff --git a/plugins/pychrysalide/core/logs.c b/plugins/pychrysalide/core/logs.c index be1f57a..afab7ab 100644 --- a/plugins/pychrysalide/core/logs.c +++ b/plugins/pychrysalide/core/logs.c @@ -1,6 +1,6 @@ /* Chrysalide - Outil d'analyse de fichiers binaires - * logs.c - équivalent Python du fichier "gui/panels/logs.c" + * logs.c - équivalent Python du fichier "core/logs.c" * * Copyright (C) 2017 Cyrille Bagard * diff --git a/plugins/pychrysalide/core/module.c b/plugins/pychrysalide/core/module.c index 3d117a5..d954821 100644 --- a/plugins/pychrysalide/core/module.c +++ b/plugins/pychrysalide/core/module.c @@ -32,6 +32,7 @@ #include "global.h" #include "logs.h" #include "params.h" +#include "processors.h" #include "queue.h" #include "../helpers.h" @@ -96,6 +97,7 @@ bool populate_core_module(void) if (result) result = populate_core_module_with_global(); if (result) result = populate_core_module_with_logs(); if (result) result = populate_core_module_with_params(); + if (result) result = populate_core_module_with_processors(); if (result) result = populate_core_module_with_queue(); assert(result); diff --git a/plugins/pychrysalide/core/processors.c b/plugins/pychrysalide/core/processors.c new file mode 100644 index 0000000..341c816 --- /dev/null +++ b/plugins/pychrysalide/core/processors.c @@ -0,0 +1,248 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * processors.c - équivalent Python du fichier "core/processors.c" + * + * Copyright (C) 2018 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "processors.h" + + +#include <pygobject.h> + + +#include <i18n.h> +#include <arch/processor.h> +#include <core/processors.h> + + +#include "../access.h" +#include "../helpers.h" +#include "../pychrysa.h" +#include "../arch/processor.h" + + + +/* Enregistre un processeur pour une architecture donnée. */ +static PyObject *py_processors_register_type(PyObject *, PyObject *); + +/* Fournit le nom humain de l'architecture visée. */ +static PyObject *py_processors_get_description(PyObject *, PyObject *); + +/* Fournit le processeur d'architecture correspondant à un nom. */ +static PyObject *py_processors_get_for_name(PyObject *, PyObject *); + + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* args = arguments fournis à l'appel. * +* * +* Description : Enregistre un processeur pour une architecture donnée. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_processors_register_type(PyObject *self, PyObject *args) +{ + PyObject *result; /* Bilan à retourner */ + const char *name; /* Nom technique de processeur */ + const char *desc; /* description humaine liée */ + PyObject *type; /* Type d'une instance future */ + int ret; /* Bilan de lecture des args. */ + PyObject *new_args; /* Nouveaux arguments épurés */ + PyObject *new_kwds; /* Nouveau dictionnaire épuré */ + PyObject *dummy; /* Coquille vide pour analyse */ + GType instance; /* Type pour futures instances */ + bool status; /* Bilan d'un enregistrement */ + + ret = PyArg_ParseTuple(args, "ssO!", &name, &desc, &PyType_Type, &type); + if (!ret) return NULL; + + ret = PyObject_IsSubclass(type, (PyObject *)get_python_arch_processor_type());; + if (ret == -1) return NULL; + + if (ret != 1) + { + PyErr_SetString(PyExc_TypeError, _("The new processor should be a subclass of the ArchProcessor type.")); + return NULL; + } + + /** + * Comme le type GLib n'est initié et enregistré qu'à la création d'une première instance, + * on force sa mise en place ici, afin de ne pas contraidre l'utilisateur à le faire + * lui même via un appel du style : + * + * register_processor('aaa', 'BBB CCC', type(AaaProcessor())) + */ + + new_args = PyTuple_New(0); + new_kwds = PyDict_New(); + + dummy = PyObject_Call(type, new_args, new_kwds); + + Py_DECREF(new_kwds); + Py_DECREF(new_args); + + if (dummy == NULL) return NULL; + + instance = pyg_type_from_object_strict((PyObject *)Py_TYPE(dummy), TRUE); + assert(instance != 0 && instance != G_TYPE_ARCH_PROCESSOR); + + Py_DECREF(dummy); + + status = register_processor_type(name, desc, instance); + + result = status ? Py_True : Py_False; + Py_INCREF(result); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* args = arguments fournis à l'appel. * +* * +* Description : Fournit le nom humain de l'architecture visée. * +* * +* Retour : Désignation humaine trouvée ou NULL. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_processors_get_description(PyObject *self, PyObject *args) +{ + PyObject *result; /* Bilan à retourner */ + const char *name; /* Nom technique de processeur */ + int ret; /* Bilan de lecture des args. */ + const char *desc; /* Description humaine obtenue */ + + ret = PyArg_ParseTuple(args, "s", &name); + if (!ret) return NULL; + + desc = get_arch_processor_description(name); + + if (desc != NULL) + result = PyUnicode_FromString(desc); + + else + { + result = Py_None; + Py_INCREF(result); + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* args = arguments fournis à l'appel. * +* * +* Description : Fournit le processeur d'architecture correspondant à un nom. * +* * +* Retour : Processeur d'architecture trouvé. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_processors_get_for_name(PyObject *self, PyObject *args) +{ + PyObject *result; /* Bilan à retourner */ + const char *name; /* Nom technique de processeur */ + int ret; /* Bilan de lecture des args. */ + GArchProcessor *proc; /* Instance mise en place */ + + ret = PyArg_ParseTuple(args, "s", &name); + if (!ret) return NULL; + + proc = get_arch_processor_for_name(name); + + if (proc != NULL) + { + result = pygobject_new(G_OBJECT(proc)); + g_object_unref(G_OBJECT(proc)); + } + else + { + result = Py_None; + Py_INCREF(result); + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Définit une extension du module 'core' à compléter. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool populate_core_module_with_processors(void) +{ + bool result; /* Bilan à retourner */ + PyObject *module; /* Module à recompléter */ + + static PyMethodDef py_processors_methods[] = { + { + "register_processor", py_processors_register_type, + METH_VARARGS, + "register_type(name, desc, cls, /)\n--\n\nRegister an an architecture processor by its name, description and class type." + }, + { + "get_processor_description", py_processors_get_description, + METH_VARARGS, + "get_processor_description(name, /)\n--\n\nProvide the description of a given architecture processor." + }, + { + "get_processor_for_name", py_processors_get_for_name, + METH_VARARGS, + "get_processor_for_name(name, /)\n--\n\nProvide an instance of an architecture processor for a given name." + }, + { NULL } + + }; + + module = get_access_to_python_module("pychrysalide.core"); + + result = register_python_module_methods(module, py_processors_methods); + + return result; + +} diff --git a/plugins/pychrysalide/core/processors.h b/plugins/pychrysalide/core/processors.h new file mode 100644 index 0000000..956c9e5 --- /dev/null +++ b/plugins/pychrysalide/core/processors.h @@ -0,0 +1,39 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * processors.h - prototypes pour l'équivalent Python du fichier "core/processors.h" + * + * Copyright (C) 2018 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _PLUGINS_PYCHRYSALIDE_CORE_PROCESSORS_H +#define _PLUGINS_PYCHRYSALIDE_CORE_PROCESSORS_H + + +#include <Python.h> +#include <stdbool.h> + + + +/* Définit une extension du module 'core' à compléter. */ +bool populate_core_module_with_processors(void); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_CORE_PROCESSORS_H */ diff --git a/plugins/pychrysalide/format/executable.c b/plugins/pychrysalide/format/executable.c index cc0dd33..906fae5 100644 --- a/plugins/pychrysalide/format/executable.c +++ b/plugins/pychrysalide/format/executable.c @@ -320,7 +320,7 @@ int convert_to_vmpa_using_executable(PyObject *obj, exe_cv_info_t *info) { arch = g_exe_format_get_target_machine(info->format); - conv.proc = get_arch_processor_for_type(arch); + conv.proc = get_arch_processor_for_name(arch); if (conv.proc != NULL) { diff --git a/plugins/ropgadgets/finder.c b/plugins/ropgadgets/finder.c index 3e7ed1a..b9a4500 100644 --- a/plugins/ropgadgets/finder.c +++ b/plugins/ropgadgets/finder.c @@ -387,7 +387,7 @@ found_rop_list *list_all_gadgets(GExeFormat *format, unsigned int max_depth, upd domain.content = g_binary_format_get_content(G_BIN_FORMAT(format)); target = g_exe_format_get_target_machine(format); - domain.proc = get_arch_processor_for_type(target); + domain.proc = get_arch_processor_for_name(target); bool collect_x_ranges(GBinPortion *portion, GBinPortion *parent, BinaryPortionVisit visit, void *unused) { |