diff options
| author | Cyrille Bagard <nocbos@gmail.com> | 2019-03-04 20:52:50 (GMT) | 
|---|---|---|
| committer | Cyrille Bagard <nocbos@gmail.com> | 2019-03-04 20:52:50 (GMT) | 
| commit | 27c21356d494824850005932f3dee5f38d7a8e82 (patch) | |
| tree | 6d7381f9cde78d28b4664f73ef03d0adb5b7b288 /plugins/pychrysalide/analysis | |
| parent | 72bebbd9dc7d59f69e23442b6c5b5526feb2a1a9 (diff) | |
Provided access to the graph layout from Python.
Diffstat (limited to 'plugins/pychrysalide/analysis')
| -rw-r--r-- | plugins/pychrysalide/analysis/binary.c | 45 | ||||
| -rw-r--r-- | plugins/pychrysalide/analysis/binary.h | 3 | ||||
| -rw-r--r-- | plugins/pychrysalide/analysis/block.c | 140 | ||||
| -rw-r--r-- | plugins/pychrysalide/analysis/block.h | 6 | 
4 files changed, 194 insertions, 0 deletions
| diff --git a/plugins/pychrysalide/analysis/binary.c b/plugins/pychrysalide/analysis/binary.c index f73684b..bc57ab4 100644 --- a/plugins/pychrysalide/analysis/binary.c +++ b/plugins/pychrysalide/analysis/binary.c @@ -330,3 +330,48 @@ bool ensure_python_loaded_binary_is_registered(void)      return true;  } + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : arg = argument quelconque à tenter de convertir.             * +*                dst = destination des valeurs récupérées en cas de succès.   * +*                                                                             * +*  Description : Tente de convertir en ensemble de binaire chargé.            * +*                                                                             * +*  Retour      : Bilan de l'opération, voire indications supplémentaires.     * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +int convert_to_loaded_binary(PyObject *arg, void *dst) +{ +    int result;                             /* Bilan à retourner           */ + +    result = PyObject_IsInstance(arg, (PyObject *)get_python_loaded_binary_type()); + +    switch (result) +    { +        case -1: +            /* L'exception est déjà fixée par Python */ +            result = 0; +            break; + +        case 0: +            PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to loaded binary"); +            break; + +        case 1: +            *((GLoadedBinary **)dst) = G_LOADED_BINARY(pygobject_get(arg)); +            break; + +        default: +            assert(false); +            break; + +    } + +    return result; + +} diff --git a/plugins/pychrysalide/analysis/binary.h b/plugins/pychrysalide/analysis/binary.h index 235e018..d4ab311 100644 --- a/plugins/pychrysalide/analysis/binary.h +++ b/plugins/pychrysalide/analysis/binary.h @@ -37,6 +37,9 @@ PyTypeObject *get_python_loaded_binary_type(void);  /* Prend en charge l'objet 'pychrysalide.analysis.LoadedBinary'. */  bool ensure_python_loaded_binary_is_registered(void); +/* Tente de convertir en ensemble de binaire chargé. */ +int convert_to_loaded_binary(PyObject *, void *); +  #endif  /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_BINARY_H */ diff --git a/plugins/pychrysalide/analysis/block.c b/plugins/pychrysalide/analysis/block.c index ca4ac09..e282d14 100644 --- a/plugins/pychrysalide/analysis/block.c +++ b/plugins/pychrysalide/analysis/block.c @@ -332,6 +332,51 @@ bool ensure_python_code_block_is_registered(void)  } +/****************************************************************************** +*                                                                             * +*  Paramètres  : arg = argument quelconque à tenter de convertir.             * +*                dst = destination des valeurs récupérées en cas de succès.   * +*                                                                             * +*  Description : Tente de convertir en bloc de code.                          * +*                                                                             * +*  Retour      : Bilan de l'opération, voire indications supplémentaires.     * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +int convert_to_code_block(PyObject *arg, void *dst) +{ +    int result;                             /* Bilan à retourner           */ + +    result = PyObject_IsInstance(arg, (PyObject *)get_python_code_block_type()); + +    switch (result) +    { +        case -1: +            /* L'exception est déjà fixée par Python */ +            result = 0; +            break; + +        case 0: +            PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to code block"); +            break; + +        case 1: +            *((GCodeBlock **)dst) = G_CODE_BLOCK(pygobject_get(arg)); +            break; + +        default: +            assert(false); +            break; + +    } + +    return result; + +} + +  /* ---------------------------------------------------------------------------------- */  /*                           REGROUPEMENT EN LISTE DE BLOCS                           */ @@ -542,3 +587,98 @@ bool ensure_python_block_list_is_registered(void)      return true;  } + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : arg = argument quelconque à tenter de convertir.             * +*                dst = destination des valeurs récupérées en cas de succès.   * +*                                                                             * +*  Description : Tente de convertir en liste de blocs de code.                * +*                                                                             * +*  Retour      : Bilan de l'opération, voire indications supplémentaires.     * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +int convert_to_block_list_with_ref(PyObject *arg, void *dst) +{ +    int result;                             /* Bilan à retourner           */ +    GBlockList *new;                        /* Nouvelle liste à constituer */ +    PyObject *item;                         /* Elément issu de l'itération */ +    int ret;                                /* Bilan d'une conversion      */ +    GCodeBlock *block;                      /* Bloc de code à intégrer     */ + +    if (arg == NULL) +    { +        g_clear_object((void **)dst); +        result = 1; +    } + +    else +    { +        result = PyObject_IsInstance(arg, (PyObject *)get_python_block_list_type()); + +        switch (result) +        { +            case -1: +                /* L'exception est déjà fixée par Python */ +                result = 0; +                break; + +            case 0: + +                if (PyIter_Check(arg)) +                { +                    new = g_block_list_new(0); + +                    result = Py_CLEANUP_SUPPORTED; + +                    for (item = PyIter_Next(arg); item != NULL; item = PyIter_Next(arg)) +                    { +                        ret = convert_to_code_block(item, &block); + +                        if (ret == 1) +                            g_object_ref(G_OBJECT(block)); + +                        Py_DECREF(item); + +                        if (ret != 1) +                        { +                            result = 0; +                            break; +                        } + +                        g_block_list_append_block(new, block); + +                    } + +                    if (result != Py_CLEANUP_SUPPORTED) +                        g_object_unref(G_OBJECT(new)); + +                    else +                        *((GBlockList **)dst) = new; + +                } + +                else +                    PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to graph cluster"); + +                break; + +            case 1: +                *((GBlockList **)dst) = G_BLOCK_LIST(pygobject_get(arg)); +                break; + +            default: +                assert(false); +                break; + +        } + +    } + +    return result; + +} diff --git a/plugins/pychrysalide/analysis/block.h b/plugins/pychrysalide/analysis/block.h index 8bae464..438157c 100644 --- a/plugins/pychrysalide/analysis/block.h +++ b/plugins/pychrysalide/analysis/block.h @@ -40,6 +40,9 @@ PyTypeObject *get_python_code_block_type(void);  /* Prend en charge l'objet 'pychrysalide.analysis.CodeBlock'. */  bool ensure_python_code_block_is_registered(void); +/* Tente de convertir en bloc de code. */ +int convert_to_code_block(PyObject *, void *); +  /* ------------------------- REGROUPEMENT EN LISTE DE BLOCS ------------------------- */ @@ -51,6 +54,9 @@ PyTypeObject *get_python_block_list_type(void);  /* Prend en charge l'objet 'pychrysalide.analysis.BlockList'. */  bool ensure_python_block_list_is_registered(void); +/* Tente de convertir en liste de blocs de code. */ +int convert_to_block_list_with_ref(PyObject *, void *); +  #endif  /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_BLOCK_H */ | 
