From 2769384a97478f4901157b71e67ec33496dd75cf Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Fri, 19 Apr 2019 22:29:34 +0200 Subject: Given access to Dalvik architecture from the Python bindings --- configure.ac | 2 + plugins/dalvik/Makefile.am | 27 +++++++- plugins/dalvik/core.c | 8 +++ plugins/dalvik/python/Makefile.am | 25 ++++++++ plugins/dalvik/python/instruction.c | 110 ++++++++++++++++++++++++++++++++ plugins/dalvik/python/instruction.h | 42 ++++++++++++ plugins/dalvik/python/module.c | 87 +++++++++++++++++++++++++ plugins/dalvik/python/module.h | 38 +++++++++++ plugins/dalvik/python/processor.c | 108 +++++++++++++++++++++++++++++++ plugins/dalvik/python/processor.h | 42 ++++++++++++ plugins/dalvik/python/v35/Makefile.am | 20 ++++++ plugins/dalvik/python/v35/instruction.c | 109 +++++++++++++++++++++++++++++++ plugins/dalvik/python/v35/instruction.h | 42 ++++++++++++ plugins/dalvik/python/v35/module.c | 76 ++++++++++++++++++++++ plugins/dalvik/python/v35/module.h | 39 +++++++++++ plugins/dalvik/python/v35/processor.c | 109 +++++++++++++++++++++++++++++++ plugins/dalvik/python/v35/processor.h | 42 ++++++++++++ 17 files changed, 924 insertions(+), 2 deletions(-) create mode 100644 plugins/dalvik/python/Makefile.am create mode 100644 plugins/dalvik/python/instruction.c create mode 100644 plugins/dalvik/python/instruction.h create mode 100644 plugins/dalvik/python/module.c create mode 100644 plugins/dalvik/python/module.h create mode 100644 plugins/dalvik/python/processor.c create mode 100644 plugins/dalvik/python/processor.h create mode 100644 plugins/dalvik/python/v35/Makefile.am create mode 100644 plugins/dalvik/python/v35/instruction.c create mode 100644 plugins/dalvik/python/v35/instruction.h create mode 100644 plugins/dalvik/python/v35/module.c create mode 100644 plugins/dalvik/python/v35/module.h create mode 100644 plugins/dalvik/python/v35/processor.c create mode 100644 plugins/dalvik/python/v35/processor.h diff --git a/configure.ac b/configure.ac index e4af946..338f7d4 100644 --- a/configure.ac +++ b/configure.ac @@ -409,6 +409,8 @@ AC_CONFIG_FILES([Makefile plugins/dalvik/Makefile plugins/dalvik/operands/Makefile plugins/dalvik/pseudo/Makefile + plugins/dalvik/python/Makefile + plugins/dalvik/python/v35/Makefile plugins/dalvik/v35/Makefile plugins/dalvik/v35/opcodes/Makefile plugins/dalvik/v35/opdefs/Makefile diff --git a/plugins/dalvik/Makefile.am b/plugins/dalvik/Makefile.am index c3dd774..76ce098 100644 --- a/plugins/dalvik/Makefile.am +++ b/plugins/dalvik/Makefile.am @@ -4,6 +4,27 @@ lib_LTLIBRARIES = libdalvik.la libdir = $(pluginslibdir) +if BUILD_PYTHON3_BINDINGS + +PYTHON3_LIBADD = python/libdalvikpython.la + +if BUILD_DISCARD_LOCAL + +PYTHON3_LDFLAGS = -Wl,-rpath,$(pluginslibdir) \ + -L$(top_srcdir)/plugins/pychrysalide/.libs -l:pychrysalide.so + +else + +PYTHON3_LDFLAGS = -Wl,-rpath,$(abs_top_srcdir)/plugins/pychrysalide/.libs \ + -L$(top_srcdir)/plugins/pychrysalide/.libs -l:pychrysalide.so + +endif + +PYTHON3_SUBDIRS = python + +endif + + libdalvik_la_SOURCES = \ context.h context.c \ core.h core.c \ @@ -21,11 +42,13 @@ libdalvik_la_SOURCES = \ libdalvik_la_LIBADD = \ operands/libdalvikoperands.la \ pseudo/libdalvikpseudo.la \ + $(PYTHON3_LIBADD) \ v35/libdalvik35.la libdalvik_la_LDFLAGS = \ -L$(top_srcdir)/src/.libs -lchrysacore \ - -L$(top_srcdir)/plugins/dex/.libs -ldex + -L$(top_srcdir)/plugins/dex/.libs -ldex \ + $(PYTHON3_LDFLAGS) devdir = $(includedir)/chrysalide-$(subdir) @@ -38,4 +61,4 @@ AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) -I$(top_srcdir)/src AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) -SUBDIRS = operands pseudo v35 +SUBDIRS = operands pseudo $(PYTHON3_SUBDIRS) v35 diff --git a/plugins/dalvik/core.c b/plugins/dalvik/core.c index 3220e2d..feb54ab 100644 --- a/plugins/dalvik/core.c +++ b/plugins/dalvik/core.c @@ -32,6 +32,9 @@ #include "operands/args.h" #include "operands/pool.h" #include "operands/register.h" +#ifdef HAVE_PYTHON3_BINDINGS +# include "python/module.h" +#endif #include "v35/core.h" @@ -96,6 +99,11 @@ G_MODULE_EXPORT bool chrysalide_plugin_init(GPluginModule *plugin) result = init_dalvik35_core(); +#ifdef HAVE_PYTHON3_BINDINGS + if (result) + result = add_arch_dalvik_module_to_python_module(); +#endif + return result; } diff --git a/plugins/dalvik/python/Makefile.am b/plugins/dalvik/python/Makefile.am new file mode 100644 index 0000000..8156b92 --- /dev/null +++ b/plugins/dalvik/python/Makefile.am @@ -0,0 +1,25 @@ + +noinst_LTLIBRARIES = libdalvikpython.la + +libdalvikpython_la_SOURCES = \ + instruction.h instruction.c \ + module.h module.c \ + processor.h processor.c + +libdalvikpython_la_LIBADD = \ + v35/libdalvikpythonv35.la + +libdalvikpython_la_LDFLAGS = + + +devdir = $(includedir)/chrysalide-$(subdir) + +dev_HEADERS = $(libdalvikpython_la_SOURCES:%c=) + + +AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ + -I$(top_srcdir)/src -DNO_IMPORT_PYGOBJECT + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) + +SUBDIRS = v35 diff --git a/plugins/dalvik/python/instruction.c b/plugins/dalvik/python/instruction.c new file mode 100644 index 0000000..c9d039f --- /dev/null +++ b/plugins/dalvik/python/instruction.c @@ -0,0 +1,110 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * instruction.c - équivalent Python du fichier "arch/dalvik/instruction.c" + * + * Copyright (C) 2019 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 "instruction.h" + + +#include + + +#include +#include + + +#include "../instruction.h" + + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *get_python_dalvik_instruction_type(void) +{ + static PyMethodDef py_dalvik_instruction_methods[] = { + { NULL } + }; + + static PyGetSetDef py_dalvik_instruction_getseters[] = { + { NULL } + }; + + static PyTypeObject py_dalvik_instruction_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.arch.dalvik.DalvikInstruction", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + + .tp_doc = "PyChrysalide instruction for an Dalvik architecture.", + + .tp_methods = py_dalvik_instruction_methods, + .tp_getset = py_dalvik_instruction_getseters, + + }; + + return &py_dalvik_instruction_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.....DalvikInstruction'.* +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_dalvik_instruction(PyObject *module) +{ + PyTypeObject *type; /* Type Python '...Instruction'*/ + PyObject *dict; /* Dictionnaire du module */ + + type = get_python_dalvik_instruction_type(); + + APPLY_ABSTRACT_FLAG(type); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_DALVIK_INSTRUCTION, type, get_python_arch_instruction_type())) + return false; + + return true; + +} diff --git a/plugins/dalvik/python/instruction.h b/plugins/dalvik/python/instruction.h new file mode 100644 index 0000000..b5050cf --- /dev/null +++ b/plugins/dalvik/python/instruction.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * instruction.h - prototypes pour l'équivalent Python du fichier "arch/dalvik/instruction.h" + * + * Copyright (C) 2019 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_DALVIK_PYTHON_INSTRUCTION_H +#define _PLUGINS_DALVIK_PYTHON_INSTRUCTION_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_dalvik_instruction_type(void); + +/* Prend en charge l'objet 'pychrysalide.arch.dalvik.DalvikInstruction'. */ +bool register_python_dalvik_instruction(PyObject *); + + + +#endif /* _PLUGINS_DALVIK_PYTHON_INSTRUCTION_H */ diff --git a/plugins/dalvik/python/module.c b/plugins/dalvik/python/module.c new file mode 100644 index 0000000..38f4b4f --- /dev/null +++ b/plugins/dalvik/python/module.c @@ -0,0 +1,87 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.c - intégration du répertoire dalvik en tant que module + * + * Copyright (C) 2015-2017 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 "module.h" + + +#include + + +#include +#include + + +#include "instruction.h" +#include "processor.h" +#include "v35/module.h" + + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Ajoute le module 'dalvik' au module Python. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool add_arch_dalvik_module_to_python_module(void) +{ + bool result; /* Bilan à retourner */ + PyObject *super; /* Module à compléter */ + PyObject *module; /* Sous-module mis en place */ + + static PyModuleDef py_chrysalide_dalvik_module = { + + .m_base = PyModuleDef_HEAD_INIT, + + .m_name = "pychrysalide.arch.dalvik", + .m_doc = "Python module for Chrysalide.arch.dalvik", + + .m_size = -1, + + }; + + result = false; + + super = get_access_to_python_module("pychrysalide.arch"); + + module = build_python_module(super, &py_chrysalide_dalvik_module); + + result = (module != NULL); + + if (result) result = register_python_dalvik_instruction(module); + if (result) result = register_python_dalvik_processor(module); + + if (result) result = add_arch_dalvik_v35_module_to_python_module(module); + + assert(result); + + return result; + +} diff --git a/plugins/dalvik/python/module.h b/plugins/dalvik/python/module.h new file mode 100644 index 0000000..5551bf7 --- /dev/null +++ b/plugins/dalvik/python/module.h @@ -0,0 +1,38 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.h - prototypes pour l'intégration du répertoire dalvik en tant que module + * + * Copyright (C) 2019 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_DALVIK_PYTHON_MODULE_H +#define _PLUGINS_DALVIK_PYTHON_MODULE_H + + +#include + + + +/* Ajoute le module 'dalvik' au module Python. */ +bool add_arch_dalvik_module_to_python_module(void); + + + +#endif /* _PLUGINS_DALVIK_PYTHON_MODULE_H */ diff --git a/plugins/dalvik/python/processor.c b/plugins/dalvik/python/processor.c new file mode 100644 index 0000000..26fd8b7 --- /dev/null +++ b/plugins/dalvik/python/processor.c @@ -0,0 +1,108 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * processor.c - équivalent Python du fichier "arch/dalvik/processor.c" + * + * Copyright (C) 2019 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 "processor.h" + + +#include + + +#include +#include + + +#include "../processor.h" + + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *get_python_dalvik_processor_type(void) +{ + static PyMethodDef py_dalvik_processor_methods[] = { + { NULL } + }; + + static PyGetSetDef py_dalvik_processor_getseters[] = { + { NULL } + }; + + static PyTypeObject py_dalvik_processor_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.arch.dalvik.DalvikProcessor", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + + .tp_doc = "PyChrysalide processor for an Dalvik architecture.", + + .tp_methods = py_dalvik_processor_methods, + .tp_getset = py_dalvik_processor_getseters, + + }; + + return &py_dalvik_processor_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.....DalvikProcessor'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_dalvik_processor(PyObject *module) +{ + PyTypeObject *type; /* Type Python '...Processor' */ + PyObject *dict; /* Dictionnaire du module */ + + type = get_python_dalvik_processor_type(); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_DALVIK_PROCESSOR, type, get_python_arch_processor_type())) + return false; + + return true; + +} diff --git a/plugins/dalvik/python/processor.h b/plugins/dalvik/python/processor.h new file mode 100644 index 0000000..ed2a672 --- /dev/null +++ b/plugins/dalvik/python/processor.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * processor.h - prototypes pour l'équivalent Python du fichier "arch/dalvik/processor.h" + * + * Copyright (C) 2019 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_DALVIK_PYTHON_PROCESSOR_H +#define _PLUGINS_DALVIK_PYTHON_PROCESSOR_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_dalvik_processor_type(void); + +/* Prend en charge l'objet 'pychrysalide.arch.dalvik.DalvikProcessor'. */ +bool register_python_dalvik_processor(PyObject *); + + + +#endif /* _PLUGINS_DALVIK_PYTHON_PROCESSOR_H */ diff --git a/plugins/dalvik/python/v35/Makefile.am b/plugins/dalvik/python/v35/Makefile.am new file mode 100644 index 0000000..0a31db7 --- /dev/null +++ b/plugins/dalvik/python/v35/Makefile.am @@ -0,0 +1,20 @@ + +noinst_LTLIBRARIES = libdalvikpythonv35.la + +libdalvikpythonv35_la_SOURCES = \ + instruction.h instruction.c \ + module.h module.c \ + processor.h processor.c + +libdalvikpythonv35_la_LDFLAGS = + + +devdir = $(includedir)/chrysalide-$(subdir) + +dev_HEADERS = $(libdalvikpythonv35_la_SOURCES:%c=) + + +AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ + -I$(top_srcdir)/src -DNO_IMPORT_PYGOBJECT + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) diff --git a/plugins/dalvik/python/v35/instruction.c b/plugins/dalvik/python/v35/instruction.c new file mode 100644 index 0000000..f5ccc2c --- /dev/null +++ b/plugins/dalvik/python/v35/instruction.c @@ -0,0 +1,109 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * instruction.c - équivalent Python du fichier "arch/dalvik/35/instruction.c" + * + * Copyright (C) 2019 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 "instruction.h" + + +#include + + +#include + + +#include "../instruction.h" +#include "../../v35/instruction.h" + + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *get_python_dalvik35_instruction_type(void) +{ + static PyMethodDef py_dalvik35_instruction_methods[] = { + { NULL } + }; + + static PyGetSetDef py_dalvik35_instruction_getseters[] = { + { NULL } + }; + + static PyTypeObject py_dalvik35_instruction_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.arch.dalvik.v35.Dalvik35Instruction", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT, + + .tp_doc = "PyChrysalide instruction for an Dalvik 35 architecture.", + + .tp_methods = py_dalvik35_instruction_methods, + .tp_getset = py_dalvik35_instruction_getseters, + + }; + + return &py_dalvik35_instruction_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide...Dalvik35Instruction'.* +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_dalvik35_instruction(PyObject *module) +{ + PyTypeObject *type; /* Type Python '...Instruction'*/ + PyObject *dict; /* Dictionnaire du module */ + + type = get_python_dalvik35_instruction_type(); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_DALVIK35_INSTRUCTION, + type, get_python_dalvik_instruction_type())) + return false; + + return true; + +} diff --git a/plugins/dalvik/python/v35/instruction.h b/plugins/dalvik/python/v35/instruction.h new file mode 100644 index 0000000..e38dfbe --- /dev/null +++ b/plugins/dalvik/python/v35/instruction.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * instruction.h - prototypes pour l'équivalent Python du fichier "arch/dalvik/v35/instruction.h" + * + * Copyright (C) 2019 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_DALVIK_PYTHON_V35_INSTRUCTION_H +#define _PLUGINS_DALVIK_PYTHON_V35_INSTRUCTION_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_dalvik35_instruction_type(void); + +/* Prend en charge l'objet 'pychrysalide.arch.dalvik.v35.Dalvik35Instruction'. */ +bool register_python_dalvik35_instruction(PyObject *); + + + +#endif /* _PLUGINS_DALVIK_PYTHON_V35_INSTRUCTION_H */ diff --git a/plugins/dalvik/python/v35/module.c b/plugins/dalvik/python/v35/module.c new file mode 100644 index 0000000..91ed216 --- /dev/null +++ b/plugins/dalvik/python/v35/module.c @@ -0,0 +1,76 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.c - intégration du répertoire v35 en tant que module + * + * Copyright (C) 2019 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 "module.h" + + +#include +#include + + +#include "instruction.h" +#include "processor.h" + + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Ajoute le module 'dalvik' au module Python. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool add_arch_dalvik_v35_module_to_python_module(PyObject *super) +{ + bool result; /* Bilan à retourner */ + PyObject *module; /* Sous-module mis en place */ + + static PyModuleDef py_chrysalide_v35_module = { + + .m_base = PyModuleDef_HEAD_INIT, + + .m_name = "pychrysalide.arch.dalvik.v35", + .m_doc = "Python module for Chrysalide.arch.dalvik.v35", + + .m_size = -1, + + }; + + module = build_python_module(super, &py_chrysalide_v35_module); + + result = (module != NULL); + + if (result) result = register_python_dalvik35_instruction(module); + if (result) result = register_python_dalvik35_processor(module); + + assert(result); + + return result; + +} diff --git a/plugins/dalvik/python/v35/module.h b/plugins/dalvik/python/v35/module.h new file mode 100644 index 0000000..a8de928 --- /dev/null +++ b/plugins/dalvik/python/v35/module.h @@ -0,0 +1,39 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.h - prototypes pour l'intégration du répertoire v35 en tant que module + * + * Copyright (C) 2019 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_DALVIK_PYTHON_V35_MODULE_H +#define _PLUGINS_DALVIK_PYTHON_V35_MODULE_H + + +#include +#include + + + +/* Ajoute le module 'dalvik' au module Python. */ +bool add_arch_dalvik_v35_module_to_python_module(PyObject *); + + + +#endif /* _PLUGINS_DALVIK_PYTHON_V35_MODULE_H */ diff --git a/plugins/dalvik/python/v35/processor.c b/plugins/dalvik/python/v35/processor.c new file mode 100644 index 0000000..fea342b --- /dev/null +++ b/plugins/dalvik/python/v35/processor.c @@ -0,0 +1,109 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * processor.c - équivalent Python du fichier "arch/dalvik/v35/processor.c" + * + * Copyright (C) 2019 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 "processor.h" + + +#include + + +#include + + +#include "../processor.h" +#include "../../v35/processor.h" + + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *get_python_dalvik35_processor_type(void) +{ + static PyMethodDef py_dalvik35_processor_methods[] = { + { NULL } + }; + + static PyGetSetDef py_dalvik35_processor_getseters[] = { + { NULL } + }; + + static PyTypeObject py_dalvik35_processor_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.arch.dalvik.v35.Dalvik35Processor", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT, + + .tp_doc = "PyChrysalide processor for an Dalvik 35 architecture.", + + .tp_methods = py_dalvik35_processor_methods, + .tp_getset = py_dalvik35_processor_getseters, + + }; + + return &py_dalvik35_processor_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.....Dalvik35Processor'.* +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_dalvik35_processor(PyObject *module) +{ + PyTypeObject *type; /* Type Python '...Processor' */ + PyObject *dict; /* Dictionnaire du module */ + + type = get_python_dalvik35_processor_type(); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_DALVIK35_PROCESSOR, + type, get_python_dalvik_processor_type())) + return false; + + return true; + +} diff --git a/plugins/dalvik/python/v35/processor.h b/plugins/dalvik/python/v35/processor.h new file mode 100644 index 0000000..ff80f08 --- /dev/null +++ b/plugins/dalvik/python/v35/processor.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * processor.h - prototypes pour l'équivalent Python du fichier "arch/dalvik/v35/processor.h" + * + * Copyright (C) 2019 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_DALVIK_PYTHON_V35_PROCESSOR_H +#define _PLUGINS_DALVIK_PYTHON_V35_PROCESSOR_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_dalvik35_processor_type(void); + +/* Prend en charge l'objet 'pychrysalide.arch.dalvik.v35.Dalvik35Processor'. */ +bool register_python_dalvik35_processor(PyObject *); + + + +#endif /* _PLUGINS_DALVIK_PYTHON_V35_PROCESSOR_H */ -- cgit v0.11.2-87-g4458