summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/analysis
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2018-05-07 14:24:16 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2018-05-07 14:24:16 (GMT)
commitc136e2c4c1ad02ea2e363fbe71ce54c6255793e2 (patch)
treeba19cc948ac23a3930d9943e94f8e37ec86991c1 /plugins/pychrysalide/analysis
parentb38035259b6e09c77d87950fe409fb72d09887d3 (diff)
Extended the Python bindings for the Dex format.
Diffstat (limited to 'plugins/pychrysalide/analysis')
-rw-r--r--plugins/pychrysalide/analysis/Makefile.am3
-rw-r--r--plugins/pychrysalide/analysis/module.c2
-rw-r--r--plugins/pychrysalide/analysis/type.c2
-rw-r--r--plugins/pychrysalide/analysis/variable.c268
-rw-r--r--plugins/pychrysalide/analysis/variable.h42
5 files changed, 315 insertions, 2 deletions
diff --git a/plugins/pychrysalide/analysis/Makefile.am b/plugins/pychrysalide/analysis/Makefile.am
index 570235d..edac3c0 100644
--- a/plugins/pychrysalide/analysis/Makefile.am
+++ b/plugins/pychrysalide/analysis/Makefile.am
@@ -10,7 +10,8 @@ libpychrysaanalysis_la_SOURCES = \
module.h module.c \
project.h project.c \
routine.h routine.c \
- type.h type.c
+ type.h type.c \
+ variable.h variable.c
libpychrysaanalysis_la_LIBADD = \
contents/libpychrysaanalysiscontents.la \
diff --git a/plugins/pychrysalide/analysis/module.c b/plugins/pychrysalide/analysis/module.c
index c9ab1e5..614adf0 100644
--- a/plugins/pychrysalide/analysis/module.c
+++ b/plugins/pychrysalide/analysis/module.c
@@ -36,6 +36,7 @@
#include "project.h"
#include "routine.h"
#include "type.h"
+#include "variable.h"
#include "contents/module.h"
#include "db/module.h"
#include "../access.h"
@@ -98,6 +99,7 @@ bool add_analysis_module_to_python_module(PyObject *super)
result &= register_python_binary_routine(module);
result &= register_python_data_type(module);
result &= register_python_study_project(module);
+ result &= register_python_binary_variable(module);
result &= add_analysis_contents_module_to_python_module(module);
result &= add_analysis_db_module_to_python_module(module);
diff --git a/plugins/pychrysalide/analysis/type.c b/plugins/pychrysalide/analysis/type.c
index eea9596..1d9e9f0 100644
--- a/plugins/pychrysalide/analysis/type.c
+++ b/plugins/pychrysalide/analysis/type.c
@@ -61,7 +61,7 @@ static PyObject *py_data_type_to_str(PyObject *self)
type = G_DATA_TYPE(pygobject_get(self));
- desc = g_data_type_to_string(type);
+ desc = _g_data_type_to_string(type, false);
result = PyUnicode_FromString(desc);
diff --git a/plugins/pychrysalide/analysis/variable.c b/plugins/pychrysalide/analysis/variable.c
new file mode 100644
index 0000000..7437e54
--- /dev/null
+++ b/plugins/pychrysalide/analysis/variable.c
@@ -0,0 +1,268 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * variable.c - équivalent Python du fichier "analysis/variable.c"
+ *
+ * Copyright (C) 2018 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * Chrysalide is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Chrysalide is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "variable.h"
+
+
+#include <string.h>
+#include <pygobject.h>
+
+
+#include <i18n.h>
+
+
+#include <analysis/variable.h>
+
+
+#include "../helpers.h"
+
+
+
+/* Décrit la variable donnée sous forme de caractères. */
+static PyObject *py_binary_variable_to_str(PyObject *);
+
+/* Fournit le type d'une variable donnée. */
+static PyObject *py_binary_variable_get_type(PyObject *, void *);
+
+/* Fournit le nom d'une variable donnée. */
+static PyObject *py_binary_variable_get_name(PyObject *, void *);
+
+/* Définit le nom d'une variable donnée. */
+static int py_binary_variable_set_name(PyObject *, PyObject *, void *);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : self = instance d'une variable version Python à traiter. *
+* *
+* Description : Décrit la variable donnée sous forme de caractères. *
+* *
+* Retour : Chaîne de caractère construite pour l'occasion. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_binary_variable_to_str(PyObject *self)
+{
+ PyObject *result; /* Représentation à retourner */
+ GBinVariable *variable; /* Version native de l'objet */
+ char *desc; /* Description du type */
+
+ variable = G_BIN_VARIABLE(pygobject_get(self));
+
+ desc = g_binary_variable_to_string(variable, true);
+
+ result = PyUnicode_FromString(desc);
+
+ free(desc);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = objet Python concerné par l'appel. *
+* closure = non utilisé ici. *
+* *
+* Description : Fournit le type d'une variable donnée. *
+* *
+* Retour : Type de la variable. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_binary_variable_get_type(PyObject *self, void *closure)
+{
+ PyObject *result; /* Valeur à retourner */
+ GBinVariable *variable; /* Elément à consulter */
+ GDataType *type; /* Type natif de la variable */
+
+ variable = G_BIN_VARIABLE(pygobject_get(self));
+
+ type = g_binary_variable_get_vtype(variable);
+
+ result = pygobject_new(G_OBJECT(type));
+
+ g_object_unref(G_OBJECT(type));
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = objet Python concerné par l'appel. *
+* closure = non utilisé ici. *
+* *
+* Description : Fournit le nom d'une variable donnée. *
+* *
+* Retour : Nom de la variable ou None si non précisé. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_binary_variable_get_name(PyObject *self, void *closure)
+{
+ PyObject *result; /* Valeur à retourner */
+ GBinVariable *variable; /* Elément à consulter */
+ const char *name; /* Désignation courante */
+
+ variable = G_BIN_VARIABLE(pygobject_get(self));
+ name = g_binary_variable_get_name(variable);
+
+ if (name != NULL)
+ result = PyUnicode_FromString(name);
+ else
+ {
+ result = Py_None;
+ Py_INCREF(result);
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = objet Python concerné par l'appel. *
+* value = valeur fournie à intégrer ou prendre en compte. *
+* closure = non utilisé ici. *
+* *
+* Description : Définit le nom d'une variable donnée. *
+* *
+* Retour : Bilan de l'opération pour Python. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static int py_binary_variable_set_name(PyObject *self, PyObject *value, void *closure)
+{
+ GBinVariable *variable; /* Elément à consulter */
+
+ if (!PyUnicode_Check(value) && value != Py_None)
+ {
+ PyErr_SetString(PyExc_TypeError, _("The attribute value must be a string."));
+ return -1;
+ }
+
+ variable = G_BIN_VARIABLE(pygobject_get(self));
+
+ if (!PyUnicode_Check(value))
+ g_binary_variable_set_name(variable, PyUnicode_DATA(value));
+ else
+ g_binary_variable_set_name(variable, NULL);
+
+ return 0;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Fournit un accès à une définition de type à diffuser. *
+* *
+* Retour : Définition d'objet pour Python. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+PyTypeObject *get_python_binary_variable_type(void)
+{
+ static PyMethodDef py_binary_variable_methods[] = {
+ { NULL }
+ };
+
+ static PyGetSetDef py_binary_variable_getseters[] = {
+ {
+ "type", py_binary_variable_get_type, NULL,
+ "Type of the current variable.", NULL
+ },
+ {
+ "name", py_binary_variable_get_name, py_binary_variable_set_name,
+ "Name of the current variable.", NULL
+ },
+ { NULL }
+ };
+
+ static PyTypeObject py_binary_variable_type = {
+
+ PyVarObject_HEAD_INIT(NULL, 0)
+
+ .tp_name = "pychrysalide.analysis.BinVariable",
+
+ .tp_str = py_binary_variable_to_str,
+
+ .tp_flags = Py_TPFLAGS_DEFAULT,
+
+ .tp_doc = "PyChrysalide binary variable",
+
+ .tp_methods = py_binary_variable_methods,
+ .tp_getset = py_binary_variable_getseters
+
+ };
+
+ return &py_binary_variable_type;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Prend en charge l'objet 'pychrysalide.analysis.BinVariable'. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool register_python_binary_variable(PyObject *module)
+{
+ PyTypeObject *py_binary_variable_type; /* Type Python 'BinVariable' */
+ PyObject *dict; /* Dictionnaire du module */
+
+ py_binary_variable_type = get_python_binary_variable_type();
+
+ dict = PyModule_GetDict(module);
+
+ if (!register_class_for_pygobject(dict, G_TYPE_BIN_VARIABLE, py_binary_variable_type, &PyGObject_Type))
+ return false;
+
+ return true;
+
+}
diff --git a/plugins/pychrysalide/analysis/variable.h b/plugins/pychrysalide/analysis/variable.h
new file mode 100644
index 0000000..dad56d6
--- /dev/null
+++ b/plugins/pychrysalide/analysis/variable.h
@@ -0,0 +1,42 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * variable.h - prototypes pour l'équivalent Python du fichier "analysis/variable.h"
+ *
+ * Copyright (C) 2018 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * Chrysalide is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Chrysalide is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#ifndef _PLUGINS_PYCHRYSALIDE_ANALYSIS_VARIABLE_H
+#define _PLUGINS_PYCHRYSALIDE_ANALYSIS_VARIABLE_H
+
+
+#include <Python.h>
+#include <stdbool.h>
+
+
+
+/* Fournit un accès à une définition de type à diffuser. */
+PyTypeObject *get_python_binary_variable_type(void);
+
+/* Prend en charge l'objet 'pychrysalide.analysis.BinVariable'. */
+bool register_python_binary_variable(PyObject *);
+
+
+
+#endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_VARIABLE_H */