diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2016-12-15 13:40:28 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2016-12-15 13:40:28 (GMT) |
commit | 124c8410dbfcad59d66b850c50c96ec73a607ab7 (patch) | |
tree | b7127c66abfccd11b9126741e2809a893ee44143 /plugins | |
parent | db1a6171007a6641a4659392c9bcc05670396643 (diff) |
Defined proper accesses to instructions loaded by a processor.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/androhelpers/params.c | 2 | ||||
-rw-r--r-- | plugins/androhelpers/switch.c | 2 | ||||
-rw-r--r-- | plugins/androhelpers/try_n_catch.c | 4 | ||||
-rw-r--r-- | plugins/libcsem/exit.c | 7 | ||||
-rw-r--r-- | plugins/pychrysa/arch/instriter.c | 4 | ||||
-rw-r--r-- | plugins/pychrysa/arch/processor.c | 109 |
6 files changed, 15 insertions, 113 deletions
diff --git a/plugins/androhelpers/params.c b/plugins/androhelpers/params.c index c9b1109..20e0da9 100644 --- a/plugins/androhelpers/params.c +++ b/plugins/androhelpers/params.c @@ -194,7 +194,7 @@ bool replace_parameters(GLoadedBinary *binary) format = G_DEX_FORMAT(g_loaded_binary_get_format(binary)); proc = g_loaded_binary_get_processor(binary); - instrs = g_arch_processor_get_disassembled_instructions(proc); + instrs = NULL;//g_arch_processor_get_disassembled_instructions(proc); cls_count = g_dex_format_count_classes(format); for (i = 0; i < cls_count; i++) diff --git a/plugins/androhelpers/switch.c b/plugins/androhelpers/switch.c index 43b6ae1..0700cc8 100644 --- a/plugins/androhelpers/switch.c +++ b/plugins/androhelpers/switch.c @@ -398,7 +398,7 @@ bool extract_switch_info(GLoadedBinary *binary, bool link) format = G_DEX_FORMAT(g_loaded_binary_get_format(binary)); proc = g_loaded_binary_get_processor(binary); - instrs = g_arch_processor_get_disassembled_instructions(proc); + instrs = NULL;//g_arch_processor_get_disassembled_instructions(proc); cls_count = g_dex_format_count_classes(format); for (i = 0; i < cls_count; i++) diff --git a/plugins/androhelpers/try_n_catch.c b/plugins/androhelpers/try_n_catch.c index 28f7061..dbe0ef4 100644 --- a/plugins/androhelpers/try_n_catch.c +++ b/plugins/androhelpers/try_n_catch.c @@ -125,7 +125,7 @@ static void attach_caught_code(const GLoadedBinary *binary, const GBinRoutine *r end = start + try->insn_count * sizeof(uint16_t); proc = g_loaded_binary_get_processor(binary); - instrs = g_arch_processor_get_disassembled_instructions(proc); + instrs = NULL;//g_arch_processor_get_disassembled_instructions(proc); first = g_arch_instruction_find_by_address(instrs, start, true); next = g_arch_instruction_find_by_address(instrs, end, true); @@ -253,7 +253,7 @@ static caught_exception **build_all_destinations_list(const GLoadedBinary *binar format = G_DEX_FORMAT(g_loaded_binary_get_format(binary)); proc = g_loaded_binary_get_processor(binary); - instrs = g_arch_processor_get_disassembled_instructions(proc); + instrs = NULL;//g_arch_processor_get_disassembled_instructions(proc); instrs = g_arch_instruction_find_by_address(instrs, start, true); /* Création d'un espace mémoire pour les listes */ diff --git a/plugins/libcsem/exit.c b/plugins/libcsem/exit.c index cbfec64..20511aa 100644 --- a/plugins/libcsem/exit.c +++ b/plugins/libcsem/exit.c @@ -70,6 +70,9 @@ static void mark_one_kind_of_exit_as_return(const GLoadedBinary *binary, const c instr = g_arch_processor_find_instr_by_address(proc, get_mrange_addr(range)); + if (instr == NULL) + goto mokoear_not_found; + g_arch_instruction_rlock_src(instr); count = g_arch_instruction_get_sources(instr, &sources); @@ -83,6 +86,10 @@ static void mark_one_kind_of_exit_as_return(const GLoadedBinary *binary, const c g_arch_instruction_runlock_src(instr); + g_object_unref(G_OBJECT(instr)); + + mokoear_not_found: + g_object_unref(G_OBJECT(proc)); mokoear_done_with_sym: diff --git a/plugins/pychrysa/arch/instriter.c b/plugins/pychrysa/arch/instriter.c index 1e5346e..0d65f26 100644 --- a/plugins/pychrysa/arch/instriter.c +++ b/plugins/pychrysa/arch/instriter.c @@ -28,7 +28,6 @@ #include <pygobject.h> -#include <arch/instriter.h> #include <arch/processor.h> @@ -101,7 +100,10 @@ static PyObject *py_instr_iterator_next(PyInstrIterator *self) next = get_instruction_iterator_next(self->native); if (next != NULL) + { result = pygobject_new(G_OBJECT(next)); + g_object_unref(G_OBJECT(next)); + } else { diff --git a/plugins/pychrysa/arch/processor.c b/plugins/pychrysa/arch/processor.c index 3ef56e4..e34bf1f 100644 --- a/plugins/pychrysa/arch/processor.c +++ b/plugins/pychrysa/arch/processor.c @@ -68,12 +68,6 @@ static PyObject *py_arch_processor_get_instrs(PyObject *, void *); /* Recherche une instruction d'après son adresse. */ static PyObject *py_arch_processor_find_instr_by_addr(PyObject *, PyObject *); -/* Fournit l'instruction qui en précède une autre. */ -static PyObject *py_arch_processor_get_prev_instr(PyObject *, PyObject *); - -/* Fournit l'instruction qui en suit une autre. */ -static PyObject *py_arch_processor_get_next_instr(PyObject *, PyObject *); - /* ---------------------------------------------------------------------------------- */ @@ -182,102 +176,11 @@ static PyObject *py_arch_processor_find_instr_by_addr(PyObject *self, PyObject * found = g_arch_processor_find_instr_by_address(proc, addr); if (found != NULL) - result = pygobject_new(G_OBJECT(found)); - - else { - result = Py_None; - Py_INCREF(result); - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = processeur d'architecture à manipuler. * -* args = instruction représentant le point de départ. * -* * -* Description : Fournit l'instruction qui en précède une autre. * -* * -* Retour : Instruction précédente trouvée, ou NULL. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_arch_processor_get_prev_instr(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - PyObject *instr_obj; /* Objet pour une instruction */ - int ret; /* Bilan de lecture des args. */ - GArchProcessor *proc; /* Processeur manipulé */ - GArchInstruction *instr; /* Instruction de référence */ - GArchInstruction *found; /* Instruction liée trouvée */ - - ret = PyArg_ParseTuple(args, "O", &instr_obj); - if (!ret) return NULL; - - ret = PyObject_IsInstance(instr_obj, (PyObject *)get_python_arch_instruction_type()); - if (!ret) return NULL; - - proc = G_ARCH_PROCESSOR(pygobject_get(self)); - instr = G_ARCH_INSTRUCTION(pygobject_get(instr_obj)); - - found = g_arch_processor_get_prev_instr(proc, instr); - - if (found != NULL) result = pygobject_new(G_OBJECT(found)); - - else - { - result = Py_None; - Py_INCREF(result); + g_object_unref(G_OBJECT(found)); } - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = processeur d'architecture à manipuler. * -* args = instruction représentant le point de départ. * -* * -* Description : Fournit l'instruction qui en suit une autre. * -* * -* Retour : Instruction suivante trouvée, ou NULL. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_arch_processor_get_next_instr(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - PyObject *instr_obj; /* Objet pour une instruction */ - int ret; /* Bilan de lecture des args. */ - GArchProcessor *proc; /* Processeur manipulé */ - GArchInstruction *instr; /* Instruction de référence */ - GArchInstruction *found; /* Instruction liée trouvée */ - - ret = PyArg_ParseTuple(args, "O", &instr_obj); - if (!ret) return NULL; - - ret = PyObject_IsInstance(instr_obj, (PyObject *)get_python_arch_instruction_type()); - if (!ret) return NULL; - - proc = G_ARCH_PROCESSOR(pygobject_get(self)); - instr = G_ARCH_INSTRUCTION(pygobject_get(instr_obj)); - - found = g_arch_processor_get_next_instr(proc, instr); - - if (found != NULL) - result = pygobject_new(G_OBJECT(found)); - else { result = Py_None; @@ -309,16 +212,6 @@ PyTypeObject *get_python_arch_processor_type(void) METH_VARARGS, "find_instr_by_addr($self, addr, /)\n--\n\nLook for an instruction located at a given address." }, - { - "get_prev_instr", py_arch_processor_get_prev_instr, - METH_VARARGS, - "get_prev_instr($self, instr, /)\n--\n\nProvide the instruction preceding a given instruction." - }, - { - "get_next_instr", py_arch_processor_get_next_instr, - METH_VARARGS, - "get_next_instr($self, instr, /)\n--\n\nProvide the instruction following a given instruction." - }, { NULL } }; |