diff options
Diffstat (limited to 'plugins/pychrysalide/analysis')
-rw-r--r-- | plugins/pychrysalide/analysis/block.c | 83 |
1 files changed, 57 insertions, 26 deletions
diff --git a/plugins/pychrysalide/analysis/block.c b/plugins/pychrysalide/analysis/block.c index 3d51676..0b09eb7 100644 --- a/plugins/pychrysalide/analysis/block.c +++ b/plugins/pychrysalide/analysis/block.c @@ -34,6 +34,7 @@ #include "../access.h" #include "../helpers.h" +#include "../arch/instruction.h" #include "../arch/vmpa.h" @@ -154,8 +155,22 @@ static PyObject *py_code_block_get_sources(PyObject *self, void *closure) size_t count; /* Quantité de blocs liés */ block_link_t *links; /* Liens à traiter */ size_t i; /* Boucle de parcours */ - block_link_t *link; /* Informations conservées */ - PyObject *info; /* Informations à transmettre */ + block_link_t *source; /* Origine des liens */ + PyObject *linked; /* Source de lien Python */ + PyObject *type; /* Nature du lien en Python */ +#ifndef NDEBUG + int ret; /* Bilan d'une écriture d'arg. */ +#endif + +#define CODE_BLOCK_SOURCES_ATTRIB PYTHON_GET_DEF_FULL \ +( \ + sources, py_code_block, \ + "List of source blocks.\n" \ + "\n" \ + "Each item of the resulting tuple is a pair of" \ + " pychrysalide.analysis.CodeBlock instance and" \ + " pychrysalide.arch.ArchInstruction.InstructionLinkType value." \ +) block = G_CODE_BLOCK(pygobject_get(self)); @@ -165,16 +180,20 @@ static PyObject *py_code_block_get_sources(PyObject *self, void *closure) for (i = 0; i < count; i++) { - link = &links[i]; + source = &links[i]; - info = PyTuple_New(2); + linked = pygobject_new(G_OBJECT(source->linked)); + type = cast_with_constants_group_from_type(get_python_arch_instruction_type(), + "InstructionLinkType", source->type); - PyTuple_SetItem(info, 0, pygobject_new(G_OBJECT(link->linked))); - PyTuple_SetItem(info, 1, PyLong_FromUnsignedLong(link->type)); +#ifndef NDEBUG + ret = PyTuple_SetItem(result, i, Py_BuildValue("(OO)", linked, type)); + assert(ret == 0); +#else + PyTuple_SetItem(result, i, Py_BuildValue("(OO)", linked, type)); +#endif - PyTuple_SetItem(result, i, info); - - unref_block_link(link); + unref_block_link(source); } @@ -206,8 +225,22 @@ static PyObject *py_code_block_get_destinations(PyObject *self, void *closure) size_t count; /* Quantité de blocs liés */ block_link_t *links; /* Liens à traiter */ size_t i; /* Boucle de parcours */ - block_link_t *link; /* Informations conservées */ - PyObject *info; /* Informations à transmettre */ + block_link_t *dest; /* Destination des liens */ + PyObject *linked; /* Destination de lien Python */ + PyObject *type; /* Nature du lien en Python */ +#ifndef NDEBUG + int ret; /* Bilan d'une écriture d'arg. */ +#endif + +#define CODE_BLOCK_DESTINATIONS_ATTRIB PYTHON_GET_DEF_FULL \ +( \ + destinations, py_code_block, \ + "List of destination blocks.\n" \ + "\n" \ + "Each item of the resulting tuple is a pair of" \ + " pychrysalide.analysis.CodeBlock instance and" \ + " pychrysalide.arch.ArchInstruction.InstructionLinkType value." \ +) block = G_CODE_BLOCK(pygobject_get(self)); @@ -217,16 +250,20 @@ static PyObject *py_code_block_get_destinations(PyObject *self, void *closure) for (i = 0; i < count; i++) { - link = &links[i]; - - info = PyTuple_New(2); + dest = &links[i]; - PyTuple_SetItem(info, 0, pygobject_new(G_OBJECT(link->linked))); - PyTuple_SetItem(info, 1, PyLong_FromUnsignedLong(link->type)); + linked = pygobject_new(G_OBJECT(dest->linked)); + type = cast_with_constants_group_from_type(get_python_arch_instruction_type(), + "InstructionLinkType", dest->type); - PyTuple_SetItem(result, i, info); +#ifndef NDEBUG + ret = PyTuple_SetItem(result, i, Py_BuildValue("(OO)", linked, type)); + assert(ret == 0); +#else + PyTuple_SetItem(result, i, Py_BuildValue("(OO)", linked, type)); +#endif - unref_block_link(link); + unref_block_link(dest); } @@ -265,14 +302,8 @@ PyTypeObject *get_python_code_block_type(void) "rank", py_code_block_get_rank, NULL, "Rang of the code block.", NULL }, - { - "sources", py_code_block_get_sources, NULL, - "List of source blocks.", NULL - }, - { - "destinations", py_code_block_get_destinations, NULL, - "List of destination blocks.", NULL - }, + CODE_BLOCK_SOURCES_ATTRIB, + CODE_BLOCK_DESTINATIONS_ATTRIB, { NULL } }; |