diff options
Diffstat (limited to 'plugins/pychrysalide/arch/instriter.c')
-rw-r--r-- | plugins/pychrysalide/arch/instriter.c | 96 |
1 files changed, 84 insertions, 12 deletions
diff --git a/plugins/pychrysalide/arch/instriter.c b/plugins/pychrysalide/arch/instriter.c index bb1e1a3..381f967 100644 --- a/plugins/pychrysalide/arch/instriter.c +++ b/plugins/pychrysalide/arch/instriter.c @@ -28,10 +28,12 @@ #include <pygobject.h> +#include <i18n.h> #include <arch/processor.h> #include "processor.h" +#include "vmpa.h" #include "../access.h" #include "../helpers.h" @@ -54,6 +56,9 @@ static void py_instr_iterator_dealloc(PyInstrIterator *); /* Fournit l'instruction qui en suit une autre. */ static PyObject *py_instr_iterator_next(PyInstrIterator *); +/* Limite le parcours des instructions à une zone donnée. */ +static PyObject *py_instr_iterator_restrict(PyObject *, PyObject *); + /* Initialise un nouvel itérateur. */ static int py_instr_iterator_init(PyInstrIterator *, PyObject *, PyObject *); @@ -140,27 +145,51 @@ static PyObject *py_instr_iterator_next(PyInstrIterator *self) static int py_instr_iterator_init(PyInstrIterator *self, PyObject *args, PyObject *kwds) { int result; /* Bilan à retourner */ - PyObject *proc_obj; /* Processeur version Python */ - unsigned long index; /* Indice de première instruc. */ - int ret; /* Bilan de lecture des args. */ GArchProcessor *proc; /* Version native du processeur*/ + PyObject *start; /* Position de départ */ + int ret; /* Bilan de lecture des args. */ + PyTypeObject *py_vmpa_type; /* Type Python pour 'vmpa' */ + PY_LONG_LONG index; /* Indice de première instruc. */ + int overflow; /* Détection d'une grosse val. */ result = -1; - ret = PyArg_ParseTuple(args, "Ok", &proc_obj, &index); - if (ret == 0) goto piii_exit; + ret = PyArg_ParseTuple(args, "O&O", convert_to_arch_processor, &proc, &start); + if (!ret) goto exit; - ret = PyObject_IsInstance(proc_obj, (PyObject *)get_python_arch_processor_type()); - if (!ret) goto piii_exit; + py_vmpa_type = get_python_vmpa_type(); - proc = G_ARCH_PROCESSOR(pygobject_get(proc_obj)); + ret = PyObject_IsInstance(start, (PyObject *)py_vmpa_type); - self->native = create_instruction_iterator(proc, index); - self->first_time = true; + /* Si l'argument est une adresse... */ + if (ret == 1) + { + self->native = g_arch_processor_get_iter_from_address(proc, get_internal_vmpa(start)); + result = 0; + } + + /* Si l'argument est un indice... */ + else + { + index = PyLong_AsLongLongAndOverflow(start, &overflow); - result = 0; + if (index == -1 && (overflow == 1 || PyErr_Occurred())) + { + PyErr_Clear(); + PyErr_SetString(PyExc_TypeError, _("Unable to cast object as index.")); + } - piii_exit: + else + { + self->native = create_instruction_iterator(proc, index); + result = 0; + } + + } + + self->first_time = true; + + exit: return result; @@ -169,6 +198,39 @@ static int py_instr_iterator_init(PyInstrIterator *self, PyObject *args, PyObjec /****************************************************************************** * * +* Paramètres : self = itérateur d'instructions à manipuler. * +* args = bornes de l'espace de parcours. * +* * +* Description : Limite le parcours des instructions à une zone donnée. * +* * +* Retour : Itérateur mis à jour. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_instr_iterator_restrict(PyObject *self, PyObject *args) +{ + mrange_t range; /* Espace mémoire fourni */ + int ret; /* Bilan de lecture des args. */ + PyInstrIterator *iter; /* Autre version d'objet */ + + ret = PyArg_ParseTuple(args, "O&", convert_any_to_mrange, &range); + if (!ret) return NULL; + + iter = (PyInstrIterator *)self; + + restrict_instruction_iterator(iter->native, &range); + + Py_INCREF(self); + + return self; + +} + + +/****************************************************************************** +* * * Paramètres : - * * * * Description : Fournit un accès à une définition de type à diffuser. * @@ -181,6 +243,15 @@ static int py_instr_iterator_init(PyInstrIterator *self, PyObject *args, PyObjec PyTypeObject *get_python_instr_iterator_type(void) { + static PyMethodDef py_instr_iterator_methods[] = { + { + "restrict", py_instr_iterator_restrict, + METH_VARARGS, + "restrict($self, range, /)\n--\n\nLimit the instruction iterator to a memory range." + }, + { NULL } + }; + static PyTypeObject py_instr_iterator_type = { PyVarObject_HEAD_INIT(NULL, 0) @@ -197,6 +268,7 @@ PyTypeObject *get_python_instr_iterator_type(void) .tp_iter = PyObject_SelfIter, .tp_iternext = (iternextfunc)py_instr_iterator_next, + .tp_methods = py_instr_iterator_methods, .tp_init = (initproc)py_instr_iterator_init, .tp_new = PyType_GenericNew, |