diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2020-02-17 09:59:45 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2020-02-17 09:59:45 (GMT) |
commit | 838ed83634c445e4ba1b15998f4ad50d1e7503c9 (patch) | |
tree | dfd7a6b5be9217723d69742da868df8404da1ff1 /plugins | |
parent | 5108aad8eb7b20a14c1e7d9e084af2272035192d (diff) |
Relocated the undefined instructions.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/arm/v7/arm.c | 26 | ||||
-rw-r--r-- | plugins/arm/v7/thumb_32.c | 16 | ||||
-rw-r--r-- | plugins/pychrysalide/arch/Makefile.am | 4 | ||||
-rw-r--r-- | plugins/pychrysalide/arch/instructions/Makefile.am | 24 | ||||
-rw-r--r-- | plugins/pychrysalide/arch/instructions/constants.c | 71 | ||||
-rw-r--r-- | plugins/pychrysalide/arch/instructions/constants.h | 39 | ||||
-rw-r--r-- | plugins/pychrysalide/arch/instructions/module.c | 104 | ||||
-rw-r--r-- | plugins/pychrysalide/arch/instructions/module.h | 42 | ||||
-rw-r--r-- | plugins/pychrysalide/arch/instructions/undefined.c (renamed from plugins/pychrysalide/arch/undefined.c) | 109 | ||||
-rw-r--r-- | plugins/pychrysalide/arch/instructions/undefined.h (renamed from plugins/pychrysalide/arch/undefined.h) | 8 | ||||
-rw-r--r-- | plugins/pychrysalide/arch/module.c | 5 | ||||
-rw-r--r-- | plugins/pychrysalide/arch/operands/module.c | 10 |
12 files changed, 362 insertions, 96 deletions
diff --git a/plugins/arm/v7/arm.c b/plugins/arm/v7/arm.c index 3081f89..6cd40bb 100644 --- a/plugins/arm/v7/arm.c +++ b/plugins/arm/v7/arm.c @@ -27,7 +27,7 @@ #include <stdint.h> -#include <arch/undefined.h> +#include <arch/instructions/undefined.h> #include <common/bconst.h> @@ -2060,7 +2060,7 @@ static GArchInstruction *process_armv7_arm_coprocessor_instructions_and_supervis op = (raw >> 4) & 0x1; if ((op1 & b111110) == b000000) - result = g_undef_instruction_new(IBS_UNDEFINED); + result = g_undef_instruction_new(IEB_UNDEFINED); else if ((op1 & b110000) == b110000) result = armv7_read_arm_instr_a8_svc_previously_swi(raw); @@ -2246,20 +2246,20 @@ static GArchInstruction *process_armv7_arm_memory_hints_advanced_simd_instructio result = process_armv7_arm_advanced_simd_element_or_structure_load_store_instructions(raw); else if ((op1 & b1110111) == b1000001) - result = g_undef_instruction_new(IBS_NOP); + result = g_undef_instruction_new(IEB_NOP); else if ((op1 & b1110111) == b1000101) result = armv7_read_arm_instr_a8_pli_immediate_literal(raw); else if ((op1 & b1110011) == b1000011) - result = g_undef_instruction_new(IBS_UNPREDICTABLE); + result = g_undef_instruction_new(IEB_UNPREDICTABLE); else if ((op1 & b1110111) == b1010101) { if (rn != b1111) result = armv7_read_arm_instr_a8_pld_pldw_immediate(raw); else - result = g_undef_instruction_new(IBS_UNPREDICTABLE); + result = g_undef_instruction_new(IEB_UNPREDICTABLE); } @@ -2273,18 +2273,18 @@ static GArchInstruction *process_armv7_arm_memory_hints_advanced_simd_instructio } else if (op1 == b1010011) - result = g_undef_instruction_new(IBS_UNPREDICTABLE); + result = g_undef_instruction_new(IEB_UNPREDICTABLE); else if (op1 == b1010111) { if (op2 == b0000) - result = g_undef_instruction_new(IBS_UNPREDICTABLE); + result = g_undef_instruction_new(IEB_UNPREDICTABLE); else if (op2 == b0001) result = armv7_read_arm_instr_a8_clrex(raw); else if ((op2 & b1110) == b0010) - result = g_undef_instruction_new(IBS_UNPREDICTABLE); + result = g_undef_instruction_new(IEB_UNPREDICTABLE); else if (op2 == b0100) result = armv7_read_arm_instr_a8_dsb(raw); @@ -2296,18 +2296,18 @@ static GArchInstruction *process_armv7_arm_memory_hints_advanced_simd_instructio result = armv7_read_arm_instr_a8_isb(raw); else if (op2 == b0111) - result = g_undef_instruction_new(IBS_UNPREDICTABLE); + result = g_undef_instruction_new(IEB_UNPREDICTABLE); else if ((op2 & b1000) == b1000) - result = g_undef_instruction_new(IBS_UNPREDICTABLE); + result = g_undef_instruction_new(IEB_UNPREDICTABLE); } else if ((op1 & b1111011) == b1011011) - result = g_undef_instruction_new(IBS_UNPREDICTABLE); + result = g_undef_instruction_new(IEB_UNPREDICTABLE); else if ((op1 & b1110111) == b1100001 && (op2 & b0001) == b0000) - result = g_undef_instruction_new(IBS_NOP); + result = g_undef_instruction_new(IEB_NOP); else if ((op1 & b1110111) == b1100101 && (op2 & b0001) == b0000) result = armv7_read_arm_instr_a8_pli_register(raw); @@ -3157,7 +3157,7 @@ static GArchInstruction *process_armv7_arm_one_register_and_a_modified_immediate result = armv7_read_arm_instr_a8_vmov_immediate(raw); else if (cmode == b1111) - result = g_undef_instruction_new(IBS_UNDEFINED); + result = g_undef_instruction_new(IEB_UNDEFINED); } diff --git a/plugins/arm/v7/thumb_32.c b/plugins/arm/v7/thumb_32.c index 74c2a84..ae5f1fb 100644 --- a/plugins/arm/v7/thumb_32.c +++ b/plugins/arm/v7/thumb_32.c @@ -27,7 +27,7 @@ #include <stdint.h> -#include <arch/undefined.h> +#include <arch/instructions/undefined.h> #include <common/bconst.h> @@ -216,7 +216,7 @@ GArchInstruction *process_armv7_thumb_32_instruction_set_encoding(uint32_t raw) result = process_armv7_thumb_32_load_word(raw); else if ((op2 & b1100111) == b0000111) - result = g_undef_instruction_new(IBS_UNDEFINED); + result = g_undef_instruction_new(IEB_UNDEFINED); else if ((op2 & b1110001) == b0010000) result = process_armv7_thumb_32_advanced_simd_element_or_structure_load_store_instructions(raw); @@ -1023,7 +1023,7 @@ static GArchInstruction *process_armv7_thumb_32_load_halfword_memory_hints(uint3 result = armv7_read_thumb_32_instr_a8_ldrsh_literal(raw); else/* if (rt == b1111)*/ - result = g_undef_instruction_new(IBS_NOP); + result = g_undef_instruction_new(IEB_NOP); } @@ -1078,10 +1078,10 @@ static GArchInstruction *process_armv7_thumb_32_load_halfword_memory_hints(uint3 result = armv7_read_thumb_32_instr_a8_ldrsht(raw); else if (op2 == b000000 && rt == b1111) - result = g_undef_instruction_new(IBS_NOP); + result = g_undef_instruction_new(IEB_NOP); else if ((op2 & b111100) == b110000 && rt == b1111) - result = g_undef_instruction_new(IBS_NOP); + result = g_undef_instruction_new(IEB_NOP); } @@ -1091,7 +1091,7 @@ static GArchInstruction *process_armv7_thumb_32_load_halfword_memory_hints(uint3 result = armv7_read_thumb_32_instr_a8_ldrsh_immediate(raw); else/* if (rt == b1111)*/ - result = g_undef_instruction_new(IBS_NOP); + result = g_undef_instruction_new(IEB_NOP); } @@ -2243,7 +2243,7 @@ static GArchInstruction *process_armv7_thumb_32_coprocessor_advanced_simd_and_fl op = (raw >> 4) & 0x1; if ((op1 & b111110) == b000000) - result = g_undef_instruction_new(IBS_UNDEFINED); + result = g_undef_instruction_new(IEB_UNDEFINED); else if ((op1 & b110000) == b110000) result = process_armv7_thumb_32_advanced_simd_data_processing_instructions(raw); @@ -3142,7 +3142,7 @@ static GArchInstruction *process_armv7_thumb_32_one_register_and_a_modified_imme result = armv7_read_thumb_32_instr_a8_vmov_immediate(raw); else if (cmode == b1111) - result = g_undef_instruction_new(IBS_UNDEFINED); + result = g_undef_instruction_new(IEB_UNDEFINED); } diff --git a/plugins/pychrysalide/arch/Makefile.am b/plugins/pychrysalide/arch/Makefile.am index e167459..da78572 100644 --- a/plugins/pychrysalide/arch/Makefile.am +++ b/plugins/pychrysalide/arch/Makefile.am @@ -12,10 +12,10 @@ libpychrysaarch_la_SOURCES = \ processor.h processor.c \ raw.h raw.c \ register.h register.c \ - undefined.h undefined.c \ vmpa.h vmpa.c libpychrysaarch_la_LIBADD = \ + instructions/libpychrysaarchinstructions.la \ operands/libpychrysaarchoperands.la libpychrysaarch_la_LDFLAGS = @@ -31,4 +31,4 @@ AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJE AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) -SUBDIRS = operands +SUBDIRS = instructions operands diff --git a/plugins/pychrysalide/arch/instructions/Makefile.am b/plugins/pychrysalide/arch/instructions/Makefile.am new file mode 100644 index 0000000..885f96e --- /dev/null +++ b/plugins/pychrysalide/arch/instructions/Makefile.am @@ -0,0 +1,24 @@ + +noinst_LTLIBRARIES = libpychrysaarchinstructions.la + +libpychrysaarchinstructions_la_SOURCES = \ + constants.h constants.c \ + module.h module.c \ + undefined.h undefined.c + +libpychrysaarchinstructions_la_LIBADD = + +libpychrysaarchinstructions_la_LDFLAGS = + + +devdir = $(includedir)/chrysalide-$(subdir) + +dev_HEADERS = $(libpychrysaarchinstructions_la_SOURCES:%c=) + + +AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ + -I$(top_srcdir)/src + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) + +SUBDIRS = diff --git a/plugins/pychrysalide/arch/instructions/constants.c b/plugins/pychrysalide/arch/instructions/constants.c new file mode 100644 index 0000000..1f6a1d2 --- /dev/null +++ b/plugins/pychrysalide/arch/instructions/constants.c @@ -0,0 +1,71 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * constants.c - ajout des constantes de base pour les instructions + * + * Copyright (C) 2020 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 "constants.h" + + +#include <arch/instructions/undefined.h> + + +#include "../../helpers.h" + + + +/****************************************************************************** +* * +* Paramètres : type = type dont le dictionnaire est à compléter. * +* * +* Description : Définit les constantes liées aux comportements erratiques. * +* * +* Retour : true en cas de succès de l'opération, false sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool define_undefined_instruction_constants(PyTypeObject *type) +{ + bool result; /* Bilan à retourner */ + PyObject *values; /* Groupe de valeurs à établir */ + + values = PyDict_New(); + + result = add_const_to_group(values, "NOP", IEB_NOP); + if (result) result = add_const_to_group(values, "UNDEFINED", IEB_UNDEFINED); + if (result) result = add_const_to_group(values, "UNPREDICTABLE", IEB_UNPREDICTABLE); + + if (!result) + { + Py_DECREF(values); + goto exit; + } + + result = attach_constants_group_to_type(type, false, "InstrExpectedBehavior", values, + "List of possible behaviors of undefined instructions."); + + exit: + + return result; + +} diff --git a/plugins/pychrysalide/arch/instructions/constants.h b/plugins/pychrysalide/arch/instructions/constants.h new file mode 100644 index 0000000..c25f3f8 --- /dev/null +++ b/plugins/pychrysalide/arch/instructions/constants.h @@ -0,0 +1,39 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * constants.h - prototypes pour l'ajout des constantes de base pour les instructions + * + * Copyright (C) 2020 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_ARCH_INSTRUCTIONS_CONSTANTS_H +#define _PLUGINS_PYCHRYSALIDE_ARCH_INSTRUCTIONS_CONSTANTS_H + + +#include <Python.h> +#include <stdbool.h> + + + +/* Définit les constantes liées aux comportements erratiques. */ +bool define_undefined_instruction_constants(PyTypeObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_ARCH_INSTRUCTIONS_CONSTANTS_H */ diff --git a/plugins/pychrysalide/arch/instructions/module.c b/plugins/pychrysalide/arch/instructions/module.c new file mode 100644 index 0000000..13a9c8e --- /dev/null +++ b/plugins/pychrysalide/arch/instructions/module.c @@ -0,0 +1,104 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.c - intégration du répertoire instructions en tant que module + * + * Copyright (C) 2019-2020 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 <assert.h> + + +#include "undefined.h" +#include "../../helpers.h" + + + +/****************************************************************************** +* * +* Paramètres : super = module dont la définition est à compléter. * +* * +* Description : Ajoute le module 'arch.instructions' à un module Python. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool add_arch_instructions_module(PyObject *super) +{ + bool result; /* Bilan à retourner */ + PyObject *module; /* Sous-module mis en place */ + +#define PYCHRYSALIDE_ARCH_INSTRUCTIONS_DOC \ + "This module contains implementations for most basic instructions.\n" \ + "\n" \ + "Basic instructions include non executable instructions such as" \ + " pychrysalide.arch.RawInstruction, used for managing raw bytes in a" \ + " binary content." + + static PyModuleDef py_chrysalide_arch_instructions_module = { + + .m_base = PyModuleDef_HEAD_INIT, + + .m_name = "pychrysalide.arch.instructions", + .m_doc = PYCHRYSALIDE_ARCH_INSTRUCTIONS_DOC, + + .m_size = -1, + + }; + + module = build_python_module(super, &py_chrysalide_arch_instructions_module); + + result = (module != NULL); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Intègre les objets du module 'arch.instructions'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool populate_arch_instructions_module(void) +{ + bool result; /* Bilan à retourner */ + + result = true; + + if (result) result = ensure_python_undefined_instruction_is_registered(); + + assert(result); + + return result; + +} diff --git a/plugins/pychrysalide/arch/instructions/module.h b/plugins/pychrysalide/arch/instructions/module.h new file mode 100644 index 0000000..42d6423 --- /dev/null +++ b/plugins/pychrysalide/arch/instructions/module.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.h - prototypes pour l'intégration du répertoire instructions 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_PYCHRYSALIDE_ARCH_INSTRUCTIONS_MODULE_H +#define _PLUGINS_PYCHRYSALIDE_ARCH_INSTRUCTIONS_MODULE_H + + +#include <Python.h> +#include <stdbool.h> + + + +/* Ajoute le module 'arch.instructions' à un module Python. */ +bool add_arch_instructions_module(PyObject *); + +/* Intègre les objets du module 'arch.instructions'. */ +bool populate_arch_instructions_module(void); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_ARCH_INSTRUCTIONS_MODULE_H */ diff --git a/plugins/pychrysalide/arch/undefined.c b/plugins/pychrysalide/arch/instructions/undefined.c index 1be5ccc..a2c989e 100644 --- a/plugins/pychrysalide/arch/undefined.c +++ b/plugins/pychrysalide/arch/instructions/undefined.c @@ -1,6 +1,6 @@ /* Chrysalide - Outil d'analyse de fichiers binaires - * undefined.c - équivalent Python du fichier "arch/undefined.h" + * undefined.c - équivalent Python du fichier "arch/instructions/undefined.h" * * Copyright (C) 2019 Cyrille Bagard * @@ -29,13 +29,14 @@ #include <i18n.h> -#include <arch/undefined-int.h> +#include <arch/instructions/undefined-int.h> #include <plugins/dt.h> -#include "instruction.h" -#include "../access.h" -#include "../helpers.h" +#include "constants.h" +#include "../instruction.h" +#include "../../access.h" +#include "../../helpers.h" @@ -46,10 +47,7 @@ static PyObject *py_undef_instruction_new(PyTypeObject *, PyObject *, PyObject * static int py_undef_instruction_init(PyObject *, PyObject *, PyObject *); /* Indique le type de conséquences réél de l'instruction. */ -static PyObject *py_undef_instruction_get_status(PyObject *, void *); - -/* Définit les constantes pour les instructions non définies. */ -static bool py_undefined_instruction_define_constants(PyTypeObject *); +static PyObject *py_undef_instruction_get_behavior(PyObject *, void *); @@ -129,17 +127,30 @@ static PyObject *py_undef_instruction_new(PyTypeObject *type, PyObject *args, Py static int py_undef_instruction_init(PyObject *self, PyObject *args, PyObject *kwds) { - unsigned long status; /* Conséquence pour l'instruct°*/ + unsigned long behavior; /* Conséquence pour l'instruct°*/ int ret; /* Bilan de lecture des args. */ PyObject *new_args; /* Nouveaux arguments épurés */ PyObject *new_kwds; /* Nouveau dictionnaire épuré */ GUndefInstruction *instr; /* Instruction à manipuler */ - - static char *kwlist[] = { "status", NULL }; + undef_obj_extra *extra; /* Données insérées à modifier */ + + static char *kwlist[] = { "behavior", NULL }; + +#define UNDEF_INSTRUCTION_DOC \ + "UndefInstruction represents all kinds of instructions which are" \ + " officially not part of a runnable instruction set.\n" \ + "\n" \ + "Instances can be created using the following constructor:\n" \ + "\n" \ + " UndefInstruction(behavior)" \ + "\n" \ + "Where behavior is a" \ + " pychrysalide.arch.instructions.UndefInstruction.InstrExpectedBehavior" \ + " constant describing the state of the CPU once the instruction is run." /* Récupération des paramètres */ - ret = PyArg_ParseTupleAndKeywords(args, kwds, "k", kwlist, &status); + ret = PyArg_ParseTupleAndKeywords(args, kwds, "k", kwlist, &behavior); if (!ret) return -1; /* Initialisation d'un objet GLib */ @@ -158,7 +169,9 @@ static int py_undef_instruction_init(PyObject *self, PyObject *args, PyObject *k instr = G_UNDEF_INSTRUCTION(pygobject_get(self)); - instr->status = status; + extra = GET_UNDEF_INSTR_EXTRA(instr); + + extra->behavior = behavior; return 0; @@ -178,52 +191,27 @@ static int py_undef_instruction_init(PyObject *self, PyObject *args, PyObject *k * * ******************************************************************************/ -static PyObject *py_undef_instruction_get_status(PyObject *self, void *closure) +static PyObject *py_undef_instruction_get_behavior(PyObject *self, void *closure) { PyObject *result; /* Conversion à retourner */ GUndefInstruction *instr; /* Version native */ - InstrBehaviorStatus status; /* Etat de la définition */ + InstrExpectedBehavior behavior; /* Comportement attendu */ + +#define UNDEF_INSTRUCTION_BEHAVIOR_ATTRIB PYTHON_GET_DEF_FULL \ +( \ + behavior, py_undef_instruction, \ + "Consequence carried by the undefined instruction.\n" \ + "\n" \ + "The result is provided as a" \ + " pychrysalide.arch.instructions.UndefInstruction.InstrExpectedBehavior" \ + " constant." \ +) instr = G_UNDEF_INSTRUCTION(pygobject_get(self)); + behavior = g_undef_instruction_get_behavior(instr); - status = g_undef_instruction_get_status(instr); - - result = PyLong_FromLong(status); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : obj_type = type dont le dictionnaire est à compléter. * -* * -* Description : Définit les constantes pour les instructions non définies. * -* * -* Retour : true en cas de succès de l'opération, false sinon. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool py_undefined_instruction_define_constants(PyTypeObject *obj_type) -{ - bool result; /* Bilan à retourner */ - - result = true; - - if (result) result = PyDict_AddStringMacro(obj_type, BPC_RAW); - if (result) result = PyDict_AddStringMacro(obj_type, BPC_CODE); - if (result) result = PyDict_AddStringMacro(obj_type, BPC_DATA); - if (result) result = PyDict_AddStringMacro(obj_type, BPC_DATA_RO); - if (result) result = PyDict_AddStringMacro(obj_type, BPC_DISASS_ERROR); - - if (result) result = PyDict_AddULongMacro(obj_type, PAC_NONE); - if (result) result = PyDict_AddULongMacro(obj_type, PAC_READ); - if (result) result = PyDict_AddULongMacro(obj_type, PAC_WRITE); - if (result) result = PyDict_AddULongMacro(obj_type, PAC_EXEC); - if (result) result = PyDict_AddULongMacro(obj_type, PAC_ALL); + result = cast_with_constants_group_from_type(get_python_undefined_instruction_type(), + "InstrExpectedBehavior", behavior); return result; @@ -249,10 +237,7 @@ PyTypeObject *get_python_undefined_instruction_type(void) }; static PyGetSetDef py_undefined_instruction_getseters[] = { - { - "status", py_undef_instruction_get_status, NULL, - "Consequence carried by the undefined instruction.", NULL - }, + UNDEF_INSTRUCTION_BEHAVIOR_ATTRIB, { NULL } }; @@ -260,12 +245,12 @@ PyTypeObject *get_python_undefined_instruction_type(void) PyVarObject_HEAD_INIT(NULL, 0) - .tp_name = "pychrysalide.arch.UndefInstruction", + .tp_name = "pychrysalide.arch.instructions.UndefInstruction", .tp_basicsize = sizeof(PyGObject), .tp_flags = Py_TPFLAGS_DEFAULT, - .tp_doc = "PyChrysalide undefined instruction for a all architectures.", + .tp_doc = UNDEF_INSTRUCTION_DOC, .tp_methods = py_undefined_instruction_methods, .tp_getset = py_undefined_instruction_getseters, @@ -302,7 +287,7 @@ bool ensure_python_undefined_instruction_is_registered(void) if (!PyType_HasFeature(type, Py_TPFLAGS_READY)) { - module = get_access_to_python_module("pychrysalide.arch"); + module = get_access_to_python_module("pychrysalide.arch.instructions"); dict = PyModule_GetDict(module); @@ -312,7 +297,7 @@ bool ensure_python_undefined_instruction_is_registered(void) if (!register_class_for_pygobject(dict, G_TYPE_UNDEF_INSTRUCTION, type, get_python_arch_instruction_type())) return false; - if (!py_undefined_instruction_define_constants(type)) + if (!define_undefined_instruction_constants(type)) return false; } diff --git a/plugins/pychrysalide/arch/undefined.h b/plugins/pychrysalide/arch/instructions/undefined.h index 57b3839..4e9090c 100644 --- a/plugins/pychrysalide/arch/undefined.h +++ b/plugins/pychrysalide/arch/instructions/undefined.h @@ -1,6 +1,6 @@ /* Chrysalide - Outil d'analyse de fichiers binaires - * undefined.h - prototypes pour l'équivalent Python du fichier "arch/undefined.h" + * undefined.h - prototypes pour l'équivalent Python du fichier "arch/instructions/undefined.h" * * Copyright (C) 2019 Cyrille Bagard * @@ -22,8 +22,8 @@ */ -#ifndef _PLUGINS_PYCHRYSALIDE_ARCH_UNDEFINED_H -#define _PLUGINS_PYCHRYSALIDE_ARCH_UNDEFINED_H +#ifndef _PLUGINS_PYCHRYSALIDE_ARCH_INSTRUCTIONS_UNDEFINED_H +#define _PLUGINS_PYCHRYSALIDE_ARCH_INSTRUCTIONS_UNDEFINED_H #include <Python.h> @@ -42,4 +42,4 @@ int convert_to_undefined_instruction(PyObject *, void *); -#endif /* _PLUGINS_PYCHRYSALIDE_ARCH_UNDEFINED_H */ +#endif /* _PLUGINS_PYCHRYSALIDE_ARCH_INSTRUCTIONS_UNDEFINED_H */ diff --git a/plugins/pychrysalide/arch/module.c b/plugins/pychrysalide/arch/module.c index 093efe2..05942a5 100644 --- a/plugins/pychrysalide/arch/module.c +++ b/plugins/pychrysalide/arch/module.c @@ -40,8 +40,8 @@ #include "processor.h" #include "raw.h" #include "register.h" -#include "undefined.h" #include "vmpa.h" +#include "instructions/module.h" #include "operands/module.h" #include "../helpers.h" @@ -140,6 +140,7 @@ bool add_arch_module(PyObject *super) result = (module != NULL); + if (result) result = add_arch_instructions_module(module); if (result) result = add_arch_operands_module(module); if (result) result = py_base_define_constants(Py_TYPE(module)); @@ -175,10 +176,10 @@ bool populate_arch_module(void) if (result) result = ensure_python_arch_processor_is_registered(); if (result) result = ensure_python_raw_instruction_is_registered(); if (result) result = ensure_python_arch_register_is_registered(); - if (result) result = ensure_python_undefined_instruction_is_registered(); if (result) result = ensure_python_vmpa_is_registered(); if (result) result = ensure_python_mrange_is_registered(); + if (result) result = populate_arch_instructions_module(); if (result) result = populate_arch_operands_module(); assert(result); diff --git a/plugins/pychrysalide/arch/operands/module.c b/plugins/pychrysalide/arch/operands/module.c index 10477ed..cbd0bde 100644 --- a/plugins/pychrysalide/arch/operands/module.c +++ b/plugins/pychrysalide/arch/operands/module.c @@ -1,6 +1,6 @@ /* Chrysalide - Outil d'analyse de fichiers binaires - * module.c - intégration du répertoire arch en tant que module + * module.c - intégration du répertoire operands en tant que module * * Copyright (C) 2019-2020 Cyrille Bagard * @@ -53,10 +53,10 @@ bool add_arch_operands_module(PyObject *super) bool result; /* Bilan à retourner */ PyObject *module; /* Sous-module mis en place */ -#define PYCHRYSALIDE_ARCH_OPERANDS_DOC \ - "This module contains implementations for most common operand usages." \ - "\n" \ - "These operands are usually added to objects such as" \ +#define PYCHRYSALIDE_ARCH_OPERANDS_DOC \ + "This module contains implementations for most common operand usages.\n" \ + "\n" \ + "These operands are usually added to objects such as" \ " pychrysalide.arch.ArchInstruction when disassembling a binary." static PyModuleDef py_chrysalide_arch_operands_module = { |