diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2018-12-07 20:33:21 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2018-12-07 20:33:21 (GMT) |
commit | c0af4cc392a246b05d41b7b7c05bbcd8b0cfb39e (patch) | |
tree | 0d645c71c40fc4b625271d0ab1ef8e7ebab04075 /plugins/pychrysalide/analysis | |
parent | a13d12c758184449bf3305785ef33273802a761c (diff) |
Relied on GObject introspection and dynamic gtypes to inherit in Python.
Diffstat (limited to 'plugins/pychrysalide/analysis')
-rw-r--r-- | plugins/pychrysalide/analysis/content.c | 45 | ||||
-rw-r--r-- | plugins/pychrysalide/analysis/content.h | 3 |
2 files changed, 48 insertions, 0 deletions
diff --git a/plugins/pychrysalide/analysis/content.c b/plugins/pychrysalide/analysis/content.c index f590f82..26e7654 100644 --- a/plugins/pychrysalide/analysis/content.c +++ b/plugins/pychrysalide/analysis/content.c @@ -583,3 +583,48 @@ bool ensure_python_binary_content_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 contenu binaire. * +* * +* Retour : Bilan de l'opération, voire indications supplémentaires. * +* * +* Remarques : - * +* * +******************************************************************************/ + +int convert_to_binary_content(PyObject *arg, void *dst) +{ + int result; /* Bilan à retourner */ + + result = PyObject_IsInstance(arg, (PyObject *)get_python_binary_content_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 binary content"); + break; + + case 1: + *((GBinContent **)dst) = G_BIN_CONTENT(pygobject_get(arg)); + break; + + default: + assert(false); + break; + + } + + return result; + +} diff --git a/plugins/pychrysalide/analysis/content.h b/plugins/pychrysalide/analysis/content.h index b433828..61b82b3 100644 --- a/plugins/pychrysalide/analysis/content.h +++ b/plugins/pychrysalide/analysis/content.h @@ -37,6 +37,9 @@ PyTypeObject *get_python_binary_content_type(void); /* Prend en charge l'objet 'pychrysalide.analysis.BinContent'. */ bool ensure_python_binary_content_is_registered(void); +/* Tente de convertir en contenu binaire. */ +int convert_to_binary_content(PyObject *, void *); + #endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_CONTENT_H */ |