summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--plugins/pychrysa/arch/instriter.c11
-rw-r--r--src/arch/instriter.c18
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 <nocbos@gmail.com>
+
+ * plugins/pychrysa/arch/instriter.c:
+ * src/arch/instriter.c:
+ Fix the behavior of the instruction iterator.
+
17-01-06 Cyrille Bagard <nocbos@gmail.com>
* 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);