From 746a7cfb0b5f2db859618d2e490eafeb9047958b Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Sun, 8 Jan 2017 21:03:20 +0100 Subject: Fixed the behavior of the instruction iterator. --- ChangeLog | 6 ++++++ plugins/pychrysa/arch/instriter.c | 11 ++++++++++- src/arch/instriter.c | 18 ++++++++++-------- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index dbc9277..2e610cc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +17-01-08 Cyrille Bagard + + * plugins/pychrysa/arch/instriter.c: + * src/arch/instriter.c: + Fix the behavior of the instruction iterator. + 17-01-06 Cyrille Bagard * autogen.sh: diff --git a/plugins/pychrysa/arch/instriter.c b/plugins/pychrysa/arch/instriter.c index 6882cab..244a825 100644 --- a/plugins/pychrysa/arch/instriter.c +++ b/plugins/pychrysa/arch/instriter.c @@ -41,6 +41,7 @@ typedef struct _PyInstrIterator PyObject_HEAD; /* A laisser en premier */ instr_iter_t *native; /* Version native de l'objet */ + bool first_time; /* Premier élément retourné ? */ } PyInstrIterator; @@ -97,7 +98,14 @@ static PyObject *py_instr_iterator_next(PyInstrIterator *self) PyObject *result; /* Résultat à retourner */ GArchInstruction *next; /* Instruction suivante */ - next = get_instruction_iterator_next(self->native); + if (self->first_time) + { + next = get_instruction_iterator_current(self->native); + self->first_time = false; + } + + else + next = get_instruction_iterator_next(self->native); if (next != NULL) { @@ -149,6 +157,7 @@ static int py_instr_iterator_init(PyInstrIterator *self, PyObject *args, PyObjec proc = G_ARCH_PROCESSOR(pygobject_get(proc_obj)); self->native = create_instruction_iterator(proc, index); + self->first_time = true; result = 0; diff --git a/src/arch/instriter.c b/src/arch/instriter.c index ef1d865..2c922d8 100644 --- a/src/arch/instriter.c +++ b/src/arch/instriter.c @@ -155,14 +155,15 @@ GArchInstruction *get_instruction_iterator_prev(instr_iter_t *iter) else { - if (iter->index > 0) + if (iter->index > 1) + { + iter->index--; result = g_arch_processor_get_instruction(iter->proc, iter->index); + } + else result = NULL; - if (result != NULL) - iter->index--; - } g_arch_processor_unlock(iter->proc); @@ -195,14 +196,15 @@ GArchInstruction *get_instruction_iterator_next(instr_iter_t *iter) else { - if (iter->index < g_arch_processor_count_instructions(iter->proc)) + if ((iter->index + 1) < g_arch_processor_count_instructions(iter->proc)) + { + iter->index++; result = g_arch_processor_get_instruction(iter->proc, iter->index); + } + else result = NULL; - if (result != NULL) - iter->index++; - } g_arch_processor_unlock(iter->proc); -- cgit v0.11.2-87-g4458