summaryrefslogtreecommitdiff
path: root/plugins/pychrysa/analysis
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysa/analysis')
-rw-r--r--plugins/pychrysa/analysis/Makefile.am19
-rw-r--r--plugins/pychrysa/analysis/binaries/file.c116
-rw-r--r--plugins/pychrysa/analysis/binaries/file.h7
-rw-r--r--plugins/pychrysa/analysis/binaries/module.c43
-rw-r--r--plugins/pychrysa/analysis/binaries/module.h2
-rw-r--r--plugins/pychrysa/analysis/binary.c102
-rw-r--r--plugins/pychrysa/analysis/binary.h3
-rw-r--r--plugins/pychrysa/analysis/module.c92
-rw-r--r--plugins/pychrysa/analysis/module.h6
9 files changed, 335 insertions, 55 deletions
diff --git a/plugins/pychrysa/analysis/Makefile.am b/plugins/pychrysa/analysis/Makefile.am
index f970d94..9b9ac18 100644
--- a/plugins/pychrysa/analysis/Makefile.am
+++ b/plugins/pychrysa/analysis/Makefile.am
@@ -3,14 +3,21 @@ noinst_LTLIBRARIES = libpychrysaanalysis.la
libpychrysaanalysis_la_SOURCES = \
binary.h binary.c \
- block.h block.c \
- module.h module.c \
- roptions.h roptions.c \
- routine.h routine.c
+ module.h module.c
libpychrysaanalysis_la_LIBADD = \
- binaries/libpychrysaanalysisbinaries.la \
- blocks/libpychrysaanalysisblocks.la
+ binaries/libpychrysaanalysisbinaries.la
+
+# libpychrysaanalysis_la_SOURCES = \
+# binary.h binary.c \
+# block.h block.c \
+# module.h module.c \
+# roptions.h roptions.c \
+# routine.h routine.c
+
+# libpychrysaanalysis_la_LIBADD = \
+# binaries/libpychrysaanalysisbinaries.la \
+# blocks/libpychrysaanalysisblocks.la
libpychrysaanalysis_la_LDFLAGS =
diff --git a/plugins/pychrysa/analysis/binaries/file.c b/plugins/pychrysa/analysis/binaries/file.c
index 2b2a460..28bfecb 100644
--- a/plugins/pychrysa/analysis/binaries/file.c
+++ b/plugins/pychrysa/analysis/binaries/file.c
@@ -25,20 +25,21 @@
#include "file.h"
-
#include <pygobject.h>
#include <analysis/binaries/file.h>
+#include "../binary.h"
-/* Crée un nouvel objet Python de type 'FileBinary'. */
-static PyObject *py_file_binary_new(PyTypeObject *, PyObject *, PyObject *);
-
+/* Crée un nouvel objet Python de type 'BinaryFile'. */
+static PyObject *py_binary_file_new(PyTypeObject *, PyObject *, PyObject *);
+/* Fournit le chemin d'accès au binaire représenté. */
+static PyObject *py_binary_file_get_filename(PyObject *, void *);
@@ -48,7 +49,7 @@ static PyObject *py_file_binary_new(PyTypeObject *, PyObject *, PyObject *);
* args = arguments fournis à l'appel. *
* kwds = arguments de type key=val fournis. *
* *
-* Description : Crée un nouvel objet Python de type 'FileBinary'. *
+* Description : Crée un nouvel objet Python de type 'BinaryFile'. *
* *
* Retour : Instance Python mise en place. *
* *
@@ -56,7 +57,7 @@ static PyObject *py_file_binary_new(PyTypeObject *, PyObject *, PyObject *);
* *
******************************************************************************/
-static PyObject *py_file_binary_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+static PyObject *py_binary_file_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyObject *result; /* Instance à retourner */
char *filename; /* Nom du fichier à charger */
@@ -69,74 +70,121 @@ static PyObject *py_file_binary_new(PyTypeObject *type, PyObject *args, PyObject
binary = g_file_binary_new_from_file(filename);
result = pygobject_new(G_OBJECT(binary));
- //g_object_unref(binary);
+ g_object_unref(binary);
return result;
}
+/******************************************************************************
+* *
+* Paramètres : self = NULL car méthode statique. *
+* closure = non utilisé ici. *
+* *
+* Description : Fournit le chemin d'accès au binaire représenté. *
+* *
+* Retour : Chemin d'accès en Python. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+static PyObject *py_binary_file_get_filename(PyObject *self, void *closure)
+{
+ const GFileBinary *file; /* Fichier binaire concerné */
+ const char *filename; /* Chemin d'accès à diffuser */
+
+ file = G_FILE_BINARY(pygobject_get(self));
+ filename = g_file_binary_get_filename(file, true);
+ return PyUnicode_FromString(filename);
+
+}
/******************************************************************************
* *
-* Paramètres : module = module dont la définition est à compléter. *
+* Paramètres : - *
* *
-* Description : Prend en charge l'objet 'pychrysalide.analysis.LoadedBinary'.*
+* 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_file_binary(PyObject *module)
+PyTypeObject *get_python_binary_file_type(void)
{
- PyObject *parent_mod; /* Module Python-LoadedBinary */
- int ret; /* Bilan d'un appel */
-
- static PyMethodDef py_file_binary_methods[] = {
+ static PyMethodDef py_binary_file_methods[] = {
{ NULL }
};
- static PyGetSetDef py_file_binary_getseters[] = {
+ static PyGetSetDef py_binary_file_getseters[] = {
+ {
+ "filename", py_binary_file_get_filename, NULL,
+ "Show the filename of the loaded binary file.", NULL
+ },
{ NULL }
};
- static PyTypeObject py_file_binary_type = {
+ static PyTypeObject py_binary_file_type = {
- PyObject_HEAD_INIT(NULL)
+ PyVarObject_HEAD_INIT(NULL, 0)
- .tp_name = "pychrysalide.analysis.binaries.FileBinary",
+ .tp_name = "pychrysalide.analysis.binaries.BinaryFile",
.tp_basicsize = sizeof(PyGObject),
- .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+ .tp_flags = Py_TPFLAGS_DEFAULT,
- .tp_doc = "PyChrysalide file binary",
+ .tp_doc = "PyChrysalide binary file",
- .tp_methods = py_file_binary_methods,
- .tp_getset = py_file_binary_getseters,
- .tp_new = (newfunc)py_file_binary_new
+ .tp_methods = py_binary_file_methods,
+ .tp_getset = py_binary_file_getseters,
+ .tp_new = (newfunc)py_binary_file_new
};
- parent_mod = PyImport_ImportModule("pychrysalide.analysis");
- if (parent_mod == NULL) return false;
+ return &py_binary_file_type;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Prend en charge l'objet 'pychrysalide.analysis.LoadedBinary'.*
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool register_python_binary_file(PyObject *module)
+{
+ PyTypeObject *py_binary_file_type; /* Type Python 'LoadedBinary' */
+ int ret; /* Bilan d'un appel */
+ PyObject *dict; /* Dictionnaire du module */
+
+ py_binary_file_type = get_python_binary_file_type();
- py_file_binary_type.tp_base = (PyTypeObject *)PyObject_GetAttrString(parent_mod, "LoadedBinary");
- Py_DECREF(parent_mod);
+ py_binary_file_type->tp_base = get_python_loaded_binary_type();
+ py_binary_file_type->tp_basicsize = py_binary_file_type->tp_base->tp_basicsize;
- if (PyType_Ready(&py_file_binary_type) < 0)
+ if (PyType_Ready(py_binary_file_type) < 0)
return false;
- Py_INCREF(&py_file_binary_type);
- ret = PyModule_AddObject(module, "FileBinary", (PyObject *)&py_file_binary_type);
+ Py_INCREF(py_binary_file_type);
+ ret = PyModule_AddObject(module, "BinaryFile", (PyObject *)py_binary_file_type);
+ if (ret != 0) return false;
- pygobject_register_class(module, "GFileBinary", G_TYPE_FILE_BINARY, &py_file_binary_type,
- Py_BuildValue("(O)", py_file_binary_type.tp_base));
+ dict = PyModule_GetDict(module);
+ pygobject_register_class(dict, "BinaryFile", G_TYPE_FILE_BINARY, py_binary_file_type,
+ Py_BuildValue("(O)", py_binary_file_type->tp_base));
- return (ret == 0);
+ return true;
}
diff --git a/plugins/pychrysa/analysis/binaries/file.h b/plugins/pychrysa/analysis/binaries/file.h
index 2ba9ed0..b381379 100644
--- a/plugins/pychrysa/analysis/binaries/file.h
+++ b/plugins/pychrysa/analysis/binaries/file.h
@@ -31,8 +31,11 @@
-/* Prend en charge l'objet 'pychrysalide.analysis.binaries.FileBinary'. */
-bool register_python_file_binary(PyObject *);
+/* Fournit un accès à une définition de type à diffuser. */
+PyTypeObject *get_python_binary_file_type(void);
+
+/* Prend en charge l'objet 'pychrysalide.analysis.binaries.BinaryFile'. */
+bool register_python_binary_file(PyObject *);
diff --git a/plugins/pychrysa/analysis/binaries/module.c b/plugins/pychrysa/analysis/binaries/module.c
index aae0a33..c2adddf 100644
--- a/plugins/pychrysa/analysis/binaries/module.c
+++ b/plugins/pychrysa/analysis/binaries/module.c
@@ -41,25 +41,50 @@
* *
******************************************************************************/
-bool add_binaries_module_to_python_module(PyObject *super)
+bool add_analysis_binaries_module_to_python_module(PyObject *super)
{
- bool result;
- PyObject *module;
+ bool result; /* Bilan à retourner */
+ PyObject *module; /* Sous-module mis en place */
int ret; /* Bilan d'un appel */
- static PyMethodDef py_format_methods[] = {
- { NULL }
+ static PyModuleDef py_chrysalide_arch_module = {
+
+ .m_base = PyModuleDef_HEAD_INIT,
+
+ .m_name = "pychrysalide.analysis.binaries",
+ .m_doc = "Python module for Chrysalide.analysis.binaries",
+
+ .m_size = -1,
+
};
- module = Py_InitModule("pychrysalide.analysis.binaries", py_format_methods);
+ result = false;
+
+ module = PyModule_Create(&py_chrysalide_arch_module);
if (module == NULL) return false;
+ ret = PyState_AddModule(super, &py_chrysalide_arch_module);
+ if (ret != 0) goto aabmtpm_exit;
+
+ ret = _PyImport_FixupBuiltin(module, "pychrysalide.analysis.binaries");
+ if (ret != 0) goto aabmtpm_exit;
+
Py_INCREF(module);
- ret = PyModule_AddObject(super, "pychrysalide.analysis.binaries", module);
+ ret = PyModule_AddObject(super, "binaries", module);
+ if (ret != 0) goto aabmtpm_exit;
+
+ result = true;
+
+ result &= register_python_binary_file(module);
+
+ aabmtpm_exit:
- result = (ret == 0);
+ if (!result)
+ {
+ printf("something went wrong in %s...\n", __FUNCTION__);
+ /* ... */
- result &= register_python_file_binary(module);
+ }
return result;
diff --git a/plugins/pychrysa/analysis/binaries/module.h b/plugins/pychrysa/analysis/binaries/module.h
index 1fd62d0..653f7da 100644
--- a/plugins/pychrysa/analysis/binaries/module.h
+++ b/plugins/pychrysa/analysis/binaries/module.h
@@ -32,7 +32,7 @@
/* Ajoute le module 'binaries' au module Python. */
-bool add_binaries_module_to_python_module(PyObject *);
+bool add_analysis_binaries_module_to_python_module(PyObject *);
diff --git a/plugins/pychrysa/analysis/binary.c b/plugins/pychrysa/analysis/binary.c
index c570cf9..807df7e 100644
--- a/plugins/pychrysa/analysis/binary.c
+++ b/plugins/pychrysa/analysis/binary.c
@@ -28,6 +28,105 @@
#include <pygobject.h>
+
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Fournit un accès à une définition de type à diffuser. *
+* *
+* Retour : Définition d'objet pour Python. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+PyTypeObject *get_python_loaded_binary_type(void)
+{
+ static PyTypeObject py_loaded_binary_type = {
+
+ PyVarObject_HEAD_INIT(NULL, 0)
+
+ .tp_name = "pychrysalide.analysis.LoadedBinary",
+
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+
+ .tp_doc = "PyChrysalide loaded binary",
+
+ };
+
+ return &py_loaded_binary_type;
+
+}
+
+
+
+#include <analysis/binary.h>
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Prend en charge l'objet 'pychrysalide.arch.loaded_binary'. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool register_python_loaded_binary(PyObject *module)
+{
+ PyTypeObject *py_loaded_binary_type; /* Type Python 'LoadedBinary' */
+ int ret; /* Bilan d'un appel */
+ PyObject *dict; /* Dictionnaire du module */
+
+ py_loaded_binary_type = get_python_loaded_binary_type();
+
+ py_loaded_binary_type->tp_base = &PyGObject_Type;
+ py_loaded_binary_type->tp_basicsize = py_loaded_binary_type->tp_base->tp_basicsize;
+
+ if (PyType_Ready(py_loaded_binary_type) != 0)
+ return false;
+
+ Py_INCREF(py_loaded_binary_type);
+ ret = PyModule_AddObject(module, "LoadedBinary", (PyObject *)py_loaded_binary_type);
+ if (ret != 0) return false;
+
+ dict = PyModule_GetDict(module);
+ pygobject_register_class(dict, "LoadedBinary", G_TYPE_LOADED_BINARY, py_loaded_binary_type,
+ Py_BuildValue("(O)", py_loaded_binary_type->tp_base));
+
+ return true;
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+#if 0
+
+
+#include <pygobject.h>
+
+
#include <analysis/binary.h>
@@ -258,3 +357,6 @@ bool register_python_loaded_binary(PyObject *module)
return (ret == 0);
}
+
+#endif
+
diff --git a/plugins/pychrysa/analysis/binary.h b/plugins/pychrysa/analysis/binary.h
index cb78024..83ea7c7 100644
--- a/plugins/pychrysa/analysis/binary.h
+++ b/plugins/pychrysa/analysis/binary.h
@@ -31,6 +31,9 @@
+/* Fournit un accès à une définition de type à diffuser. */
+PyTypeObject *get_python_loaded_binary_type(void);
+
/* Prend en charge l'objet 'pychrysalide.analysis.LoadedBinary'. */
bool register_python_loaded_binary(PyObject *);
diff --git a/plugins/pychrysa/analysis/module.c b/plugins/pychrysa/analysis/module.c
index 54509a8..e13c8f8 100644
--- a/plugins/pychrysa/analysis/module.c
+++ b/plugins/pychrysa/analysis/module.c
@@ -26,6 +26,97 @@
#include "binary.h"
+#include "binaries/module.h"
+
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Ajoute le module 'analysis' au module Python. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool add_analysis_module_to_python_module(PyObject *super)
+{
+ bool result; /* Bilan à retourner */
+ PyObject *module; /* Sous-module mis en place */
+ int ret; /* Bilan d'un appel */
+
+ static PyModuleDef py_chrysalide_arch_module = {
+
+ .m_base = PyModuleDef_HEAD_INIT,
+
+ .m_name = "pychrysalide.analysis",
+ .m_doc = "Python module for Chrysalide.analysis",
+
+ .m_size = -1,
+
+ };
+
+ result = false;
+
+ module = PyModule_Create(&py_chrysalide_arch_module);
+ if (module == NULL) return false;
+
+ ret = PyState_AddModule(super, &py_chrysalide_arch_module);
+ if (ret != 0) goto aamtpm_exit;
+
+ ret = _PyImport_FixupBuiltin(module, "pychrysalide.analysis");
+ if (ret != 0) goto aamtpm_exit;
+
+ Py_INCREF(module);
+ ret = PyModule_AddObject(super, "analysis", module);
+ if (ret != 0) goto aamtpm_exit;
+
+ result = true;
+
+ result &= register_python_loaded_binary(module);
+
+ result &= add_analysis_binaries_module_to_python_module(module);
+
+ aamtpm_exit:
+
+ if (!result)
+ {
+ printf("something went wrong in %s...\n", __FUNCTION__);
+ /* ... */
+
+ }
+
+ return result;
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#if 0
+#include "binary.h"
#include "block.h"
#include "routine.h"
#include "binaries/module.h"
@@ -72,3 +163,4 @@ bool add_analysis_module_to_python_module(PyObject *super)
return result;
}
+#endif
diff --git a/plugins/pychrysa/analysis/module.h b/plugins/pychrysa/analysis/module.h
index 0ff1167..bc4a65e 100644
--- a/plugins/pychrysa/analysis/module.h
+++ b/plugins/pychrysa/analysis/module.h
@@ -22,8 +22,8 @@
*/
-#ifndef _PLUGINS_PYOIDA_ANALYSIS_MODULE_H
-#define _PLUGINS_PYOIDA_ANALYSIS_MODULE_H
+#ifndef _PLUGINS_PYCHRYSALIDE_ANALYSIS_MODULE_H
+#define _PLUGINS_PYCHRYSALIDE_ANALYSIS_MODULE_H
#include <Python.h>
@@ -36,4 +36,4 @@ bool add_analysis_module_to_python_module(PyObject *);
-#endif /* _PLUGINS_PYOIDA_ANALYSIS_MODULE_H */
+#endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_MODULE_H */