summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/analysis
diff options
context:
space:
mode:
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/routine.c36
-rw-r--r--plugins/pychrysalide/analysis/type.c145
-rw-r--r--plugins/pychrysalide/analysis/type.h42
5 files changed, 227 insertions, 1 deletions
diff --git a/plugins/pychrysalide/analysis/Makefile.am b/plugins/pychrysalide/analysis/Makefile.am
index c1639e7..2379b19 100644
--- a/plugins/pychrysalide/analysis/Makefile.am
+++ b/plugins/pychrysalide/analysis/Makefile.am
@@ -7,7 +7,8 @@ libpychrysaanalysis_la_SOURCES = \
content.h content.c \
loaded.h loaded.c \
module.h module.c \
- routine.h routine.c
+ routine.h routine.c \
+ type.h type.c
libpychrysaanalysis_la_LIBADD = \
contents/libpychrysaanalysiscontents.la \
diff --git a/plugins/pychrysalide/analysis/module.c b/plugins/pychrysalide/analysis/module.c
index f4a0f5b..c9a9276 100644
--- a/plugins/pychrysalide/analysis/module.c
+++ b/plugins/pychrysalide/analysis/module.c
@@ -33,6 +33,7 @@
#include "content.h"
#include "loaded.h"
#include "routine.h"
+#include "type.h"
#include "contents/module.h"
#include "db/module.h"
#include "../access.h"
@@ -91,6 +92,7 @@ bool add_analysis_module_to_python_module(PyObject *super)
result &= register_python_instr_block(module);
//result &= register_python_binary_content(module);
result &= register_python_binary_routine(module);
+ result &= register_python_data_type(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/routine.c b/plugins/pychrysalide/analysis/routine.c
index 37f36a7..d0abd72 100644
--- a/plugins/pychrysalide/analysis/routine.c
+++ b/plugins/pychrysalide/analysis/routine.c
@@ -42,6 +42,9 @@
+/* Décrit la routine fournie sous forme de caractères. */
+static PyObject *py_binary_routine_to_str(PyObject *);
+
/* Crée un nouvel objet Python de type 'BinRoutine'. */
static PyObject *py_binary_routine_new(PyTypeObject *, PyObject *, PyObject *);
@@ -58,6 +61,37 @@ static PyObject *py_binary_routine_get_basic_blocks(PyObject *, void *);
/******************************************************************************
* *
+* Paramètres : self = instance d'une routine version Python à traiter. *
+* *
+* Description : Décrit la routine fournie sous forme de caractères. *
+* *
+* Retour : Chaîne de caractère construite pour l'occasion. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_binary_routine_to_str(PyObject *self)
+{
+ PyObject *result; /* Représentation à retourner */
+ GBinRoutine *routine; /* Version native de l'objet */
+ char *desc; /* Description du type */
+
+ routine = G_BIN_ROUTINE(pygobject_get(self));
+
+ desc = g_binary_routine_to_string(routine);
+
+ result = PyUnicode_FromString(desc);
+
+ free(desc);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : type = type de l'objet à instancier. *
* args = arguments fournis à l'appel. *
* kwds = arguments de type key=val fournis. *
@@ -250,6 +284,8 @@ PyTypeObject *get_python_binary_routine_type(void)
.tp_name = "pychrysalide.analysis.BinRoutine",
+ .tp_str = py_binary_routine_to_str,
+
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_doc = "PyChrysalide binary routine",
diff --git a/plugins/pychrysalide/analysis/type.c b/plugins/pychrysalide/analysis/type.c
new file mode 100644
index 0000000..eea9596
--- /dev/null
+++ b/plugins/pychrysalide/analysis/type.c
@@ -0,0 +1,145 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * type.c - équivalent Python du fichier "analysis/type.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 "type.h"
+
+
+#include <malloc.h>
+#include <pygobject.h>
+
+
+#include <analysis/type.h>
+
+
+#include "../helpers.h"
+
+
+
+/* Décrit le type fourni sous forme de caractères. */
+static PyObject *py_data_type_to_str(PyObject *);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : self = instance d'un type version Python à traiter. *
+* *
+* Description : Décrit le type fourni sous forme de caractères. *
+* *
+* Retour : Chaîne de caractère construite pour l'occasion. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_data_type_to_str(PyObject *self)
+{
+ PyObject *result; /* Représentation à retourner */
+ GDataType *type; /* Version native de l'objet */
+ char *desc; /* Description du type */
+
+ type = G_DATA_TYPE(pygobject_get(self));
+
+ desc = g_data_type_to_string(type);
+
+ result = PyUnicode_FromString(desc);
+
+ free(desc);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Fournit un accès à une définition de type à diffuser. *
+* *
+* Retour : Définition d'objet pour Python. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+PyTypeObject *get_python_data_type_type(void)
+{
+ static PyMethodDef py_data_type_methods[] = {
+ { NULL }
+ };
+
+ static PyGetSetDef py_data_type_getseters[] = {
+ { NULL }
+ };
+
+ static PyTypeObject py_data_type_type = {
+
+ PyVarObject_HEAD_INIT(NULL, 0)
+
+ .tp_name = "pychrysalide.analysis.DataType",
+
+ .tp_str = py_data_type_to_str,
+
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+
+ .tp_doc = "PyChrysalide data type",
+
+ .tp_methods = py_data_type_methods,
+ .tp_getset = py_data_type_getseters
+
+ };
+
+ return &py_data_type_type;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Prend en charge l'objet 'pychrysalide.analysis.DataType'. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool register_python_data_type(PyObject *module)
+{
+ PyTypeObject *py_data_type_type; /* Type Python 'DataType' */
+ PyObject *dict; /* Dictionnaire du module */
+
+ py_data_type_type = get_python_data_type_type();
+
+ dict = PyModule_GetDict(module);
+
+ if (!register_class_for_pygobject(dict, G_TYPE_DATA_TYPE, py_data_type_type, &PyGObject_Type))
+ return false;
+
+ return true;
+
+}
diff --git a/plugins/pychrysalide/analysis/type.h b/plugins/pychrysalide/analysis/type.h
new file mode 100644
index 0000000..b6b8b95
--- /dev/null
+++ b/plugins/pychrysalide/analysis/type.h
@@ -0,0 +1,42 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * type.h - prototypes pour l'équivalent Python du fichier "analysis/type.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_PYOIDA_ANALYSIS_TYPE_H
+#define _PLUGINS_PYOIDA_ANALYSIS_TYPE_H
+
+
+#include <Python.h>
+#include <stdbool.h>
+
+
+
+/* Fournit un accès à une définition de type à diffuser. */
+PyTypeObject *get_python_data_type_type(void);
+
+/* Prend en charge l'objet 'pychrysalide.analysis.DataType'. */
+bool register_python_data_type(PyObject *);
+
+
+
+#endif /* _PLUGINS_PYOIDA_ANALYSIS_TYPE_H */