diff options
| author | Cyrille Bagard <nocbos@gmail.com> | 2015-07-17 16:36:21 (GMT) | 
|---|---|---|
| committer | Cyrille Bagard <nocbos@gmail.com> | 2015-07-17 16:36:21 (GMT) | 
| commit | 24d3836fcf8d443eb654b981f65478cd9923b8f1 (patch) | |
| tree | 7672a28b864127e8958c3c6cce751dcf646d2fbe /plugins/pychrysa/analysis/block.c | |
| parent | a61f089babe336b012da31a494b0f7470b6e1a9a (diff) | |
Updated the Python bindings.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@552 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'plugins/pychrysa/analysis/block.c')
| -rw-r--r-- | plugins/pychrysa/analysis/block.c | 99 | 
1 files changed, 61 insertions, 38 deletions
diff --git a/plugins/pychrysa/analysis/block.c b/plugins/pychrysa/analysis/block.c index bd8684d..4cbc353 100644 --- a/plugins/pychrysa/analysis/block.c +++ b/plugins/pychrysa/analysis/block.c @@ -54,7 +54,7 @@ static PyObject *py_instructions_block_visit(PyObject *, PyObject *);  static PyObject *py_instructions_block_get_links_block(PyObject *, PyObject *);  /* Définit les constantes pour les blocs basiques. */ -static bool py_instructions_block_define_constants(PyObject *); +static bool py_instructions_block_define_constants(PyTypeObject *); @@ -82,7 +82,7 @@ static bool py_block_visitor_glue(GInstrBlock *block, BlockVisitOrder order, py_      args = PyTuple_New(3);      PyTuple_SetItem(args, 0, pygobject_new(G_OBJECT(block))); -    PyTuple_SetItem(args, 1, PyInt_FromLong(order)); +    PyTuple_SetItem(args, 1, PyLong_FromLong(order));      PyTuple_SetItem(args, 2, data->user);      value = _run_python_method(data->func, args); @@ -96,6 +96,7 @@ static bool py_block_visitor_glue(GInstrBlock *block, BlockVisitOrder order, py_  } +  /******************************************************************************  *                                                                             *  *  Paramètres  : self = classe représentant un binaire.                       * @@ -120,6 +121,8 @@ static PyObject *py_instructions_block_visit(PyObject *self, PyObject *args)      ret = PyArg_ParseTuple(args, "OO", &data.func, &data.user);      if (!ret) Py_RETURN_NONE; +    if (PyCallable_Check(data.func) != 1) return NULL; +      block = G_INSTR_BLOCK(pygobject_get(self));      status = g_instr_block_visit(block, (instr_block_visitor_cb)py_block_visitor_glue, &data); @@ -162,7 +165,7 @@ static PyObject *py_instructions_block_get_links_block(PyObject *self, PyObject  /******************************************************************************  *                                                                             * -*  Paramètres  : dict = dictionnaire à compléter.                             * +*  Paramètres  : obj_type = type dont le dictionnaire est à compléter.        *  *                                                                             *  *  Description : Définit les constantes pour les blocs basiques.              *  *                                                                             * @@ -172,90 +175,110 @@ static PyObject *py_instructions_block_get_links_block(PyObject *self, PyObject  *                                                                             *  ******************************************************************************/ -static bool py_instructions_block_define_constants(PyObject *dict) +static bool py_instructions_block_define_constants(PyTypeObject *obj_type)  { -    int ret;                                /* Bilan d'un ajout            */ - -    ret = PyDict_SetItemString(dict, "BVO_IN", PyInt_FromLong(BVO_IN)); -    if (ret == -1) return false; +    bool result;                            /* Bilan à retourner           */ -    ret = PyDict_SetItemString(dict, "BVO_PENDING", PyInt_FromLong(BVO_PENDING)); -    if (ret == -1) return false; +    result = true; -    ret = PyDict_SetItemString(dict, "BVO_OUT", PyInt_FromLong(BVO_OUT)); -    if (ret == -1) return false; +    result &= PyDict_AddIntMacro(obj_type, BVO_IN); +    result &= PyDict_AddIntMacro(obj_type, BVO_PENDING); +    result &= PyDict_AddIntMacro(obj_type, BVO_OUT); -    return true; +    return result;  }  /******************************************************************************  *                                                                             * -*  Paramètres  : module = module dont la définition est à compléter.          * +*  Paramètres  : -                                                            *  *                                                                             * -*  Description : Prend en charge l'objet 'pychrysalide.analysis.InstrBlock'.  * +*  Description : Fournit un accès à une définition de type à diffuser.        *  *                                                                             * -*  Retour      : Bilan de l'opération.                                        * +*  Retour      : Définition d'objet pour Python.                              *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -bool register_python_instructions_block(PyObject *module) +PyTypeObject *get_python_instr_block_type(void)  { -    PyObject *parent_mod;                   /* Module de la classe parente */ -    int ret;                                /* Bilan d'un appel            */ - -    static PyMethodDef py_instructions_block_methods[] = { +    static PyMethodDef py_instr_block_methods[] = {          {              "visit", (PyCFunction)py_instructions_block_visit,              METH_VARARGS, -            "Visit all the basic blocks, starting at the provided one." +            "visit($self, cb, data, /)\n--\n\nVisit all the basic blocks, starting at the provided one."          },          {              "get_links_block", (PyCFunction)py_instructions_block_get_links_block,              METH_VARARGS, -            "Get the block containing all blocks linked to the caller." +            "get_links_block($self, /)\n--\n\nGet the block containing all blocks linked to the caller."          },          { NULL }      }; -    static PyGetSetDef py_instructions_block_getseters[] = { +    static PyGetSetDef py_instr_block_getseters[] = {          { NULL }      }; -    static PyTypeObject py_instructions_block_type = { +    static PyTypeObject py_instr_block_type = { -        PyObject_HEAD_INIT(NULL) +        PyVarObject_HEAD_INIT(NULL, 0)          .tp_name        = "pychrysalide.analysis.InstrBlock", -        .tp_basicsize   = sizeof(PyGObject),          .tp_flags       = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,          .tp_doc         = "PyChrysalide basic block", -        .tp_methods     = py_instructions_block_methods, -        .tp_getset      = py_instructions_block_getseters +        .tp_methods     = py_instr_block_methods, +        .tp_getset      = py_instr_block_getseters,      }; -    parent_mod = PyImport_ImportModule("gobject"); -    if (parent_mod == NULL) return false; +    return &py_instr_block_type; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : module = module dont la définition est à compléter.          * +*                                                                             * +*  Description : Prend en charge l'objet 'pychrysalide.analysis.InstrBlock'.  * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +bool register_python_instr_block(PyObject *module) +{ +    PyTypeObject *py_instr_block_type;      /* Type Python 'InstrBlock'    */ +    int ret;                                /* Bilan d'un appel            */ +    PyObject *dict;                         /* Dictionnaire du module      */ + +    py_instr_block_type = get_python_instr_block_type(); -    py_instructions_block_type.tp_base = (PyTypeObject *)PyObject_GetAttrString(parent_mod, "GObject"); -    Py_DECREF(parent_mod); +    py_instr_block_type->tp_base = &PyGObject_Type; +    py_instr_block_type->tp_basicsize = py_instr_block_type->tp_base->tp_basicsize; -    if (PyType_Ready(&py_instructions_block_type) < 0) +    if (PyType_Ready(py_instr_block_type) != 0)          return false; -    if (!py_instructions_block_define_constants(py_instructions_block_type.tp_dict)) +    if (!py_instructions_block_define_constants(py_instr_block_type))          return false; -    Py_INCREF(&py_instructions_block_type); -    ret = PyModule_AddObject(module, "InstrBlock", (PyObject *)&py_instructions_block_type); +    Py_INCREF(py_instr_block_type); +    ret = PyModule_AddObject(module, "InstrBlock", (PyObject *)py_instr_block_type); +    if (ret != 0) return false; -    return (ret == 0); +    dict = PyModule_GetDict(module); +    pygobject_register_class(dict, "InstrBlock", G_TYPE_INSTR_BLOCK, py_instr_block_type, +                             Py_BuildValue("(O)", py_instr_block_type->tp_base)); + +    return true;  }  | 
