summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2017-01-08 20:03:20 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2017-01-08 20:03:20 (GMT)
commit746a7cfb0b5f2db859618d2e490eafeb9047958b (patch)
treec82c0f0bcdfda0cb6c913b707f25a38d8fac1179
parent991445be8992c9aad1d86f1ce28300c3421e8f2c (diff)
Fixed the behavior of the instruction iterator.
-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);