summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/analysis
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2018-04-21 22:00:00 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2018-04-21 22:00:00 (GMT)
commit8eb95d316f7b6fbad0ff798abfe7f70f89e812d2 (patch)
tree4f310c7ffdb94d48fff236e63c7e6f0ed9f1dee1 /plugins/pychrysalide/analysis
parent315146a49b5570294ca20beca720c4e3f74a86bd (diff)
Improved the way file formats are detected and loaded.
Diffstat (limited to 'plugins/pychrysalide/analysis')
-rw-r--r--plugins/pychrysalide/analysis/Makefile.am1
-rw-r--r--plugins/pychrysalide/analysis/binary.c91
-rw-r--r--plugins/pychrysalide/analysis/loaded.c77
-rw-r--r--plugins/pychrysalide/analysis/loading.c196
-rw-r--r--plugins/pychrysalide/analysis/loading.h56
-rw-r--r--plugins/pychrysalide/analysis/module.c3
-rw-r--r--plugins/pychrysalide/analysis/project.c93
7 files changed, 431 insertions, 86 deletions
diff --git a/plugins/pychrysalide/analysis/Makefile.am b/plugins/pychrysalide/analysis/Makefile.am
index 5c3c46c..61d2c94 100644
--- a/plugins/pychrysalide/analysis/Makefile.am
+++ b/plugins/pychrysalide/analysis/Makefile.am
@@ -6,6 +6,7 @@ libpychrysaanalysis_la_SOURCES = \
block.h block.c \
content.h content.c \
loaded.h loaded.c \
+ loading.h loading.c \
module.h module.c \
project.h project.c \
routine.h routine.c \
diff --git a/plugins/pychrysalide/analysis/binary.c b/plugins/pychrysalide/analysis/binary.c
index 6be767c..1ca5b3c 100644
--- a/plugins/pychrysalide/analysis/binary.c
+++ b/plugins/pychrysalide/analysis/binary.c
@@ -34,8 +34,8 @@
#include <analysis/binary.h>
-#include "content.h"
#include "../helpers.h"
+#include "../format/executable.h"
@@ -45,12 +45,6 @@ static PyObject *py_loaded_binary_new(PyTypeObject *, PyObject *, PyObject *);
/* Fournit le nom associé à l'élément binaire. */
static PyObject *py_loaded_binary_get_name(PyObject *, void *);
-/* Lance l'analyse d'un élément binaire chargé. */
-static PyObject *py_loaded_binary_analyse(PyObject *, PyObject *);
-
-/* Lance l'analyse d'un binaire chargé et attend sa conclusion. */
-static PyObject *py_loaded_binary_analyse_and_wait(PyObject *, PyObject *);
-
/* Fournit le format de fichier reconnu dans le contenu binaire. */
static PyObject *py_loaded_binary_get_format(PyObject *, void *);
@@ -79,23 +73,18 @@ static PyObject *py_loaded_binary_get_disassembled_cache(PyObject *, void *);
static PyObject *py_loaded_binary_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyObject *result; /* Instance à retourner */
- PyObject *content_obj; /* Objet pour le contenu */
+ PyObject *format_obj; /* Objet pour le contenu */
int ret; /* Bilan de lecture des args. */
- GBinContent *content; /* Instance GLib correspondante*/
- GLoadedBinary *binary; /* Version GLib du format */
+ GExeFormat *format; /* Instance GLib correspondante*/
+ GLoadedContent *binary; /* Version GLib du binaire */
- ret = PyArg_ParseTuple(args, "O", &content_obj);
+ ret = PyArg_ParseTuple(args, "O!", get_python_executable_format_type(), &format_obj);
if (!ret) return NULL;
- ret = PyObject_IsInstance(content_obj, (PyObject *)get_python_binary_content_type());
- if (ret == 0)
- {
- PyErr_SetString(PyExc_TypeError, _("Expected a BinContent as argument"));
- return NULL;
- }
+ format = G_EXE_FORMAT(pygobject_get(format_obj));
- content = G_BIN_CONTENT(pygobject_get(content_obj));
- binary = g_loaded_binary_new(content);
+ g_object_ref(G_OBJECT(format));
+ binary = g_loaded_binary_new(format);
result = pygobject_new(G_OBJECT(binary));
@@ -138,58 +127,6 @@ static PyObject *py_loaded_binary_get_name(PyObject *self, void *closure)
/******************************************************************************
* *
-* Paramètres : self = contenu binaire à manipuler. *
-* args = non utilisé ici. *
-* *
-* Description : Lance l'analyse d'un élément binaire chargé. *
-* *
-* Retour : Rien (None). *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static PyObject *py_loaded_binary_analyse(PyObject *self, PyObject *args)
-{
- GLoadedBinary *binary; /* Version GLib du format */
-
- binary = G_LOADED_BINARY(pygobject_get(self));
-
- g_loaded_binary_analyse(binary);
-
- Py_RETURN_NONE;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : self = contenu binaire à manipuler. *
-* args = non utilisé ici. *
-* *
-* Description : Lance l'analyse d'un binaire chargé et attend sa conclusion. *
-* *
-* Retour : Rien (None). *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static PyObject *py_loaded_binary_analyse_and_wait(PyObject *self, PyObject *args)
-{
- GLoadedBinary *binary; /* Version GLib du format */
-
- binary = G_LOADED_BINARY(pygobject_get(self));
-
- g_loaded_binary_analyse_and_wait(binary);
-
- Py_RETURN_NONE;
-
-}
-
-
-/******************************************************************************
-* *
* Paramètres : self = objet Python concerné par l'appel. *
* closure = non utilisé ici. *
* *
@@ -296,18 +233,6 @@ static PyObject *py_loaded_binary_get_disassembled_cache(PyObject *self, void *c
PyTypeObject *get_python_loaded_binary_type(void)
{
static PyMethodDef py_loaded_binary_methods[] = {
- {
- "analyse", py_loaded_binary_analyse,
- METH_NOARGS,
- "analyse(/)\n--\n\nStart the analysis of the loaded binary and " \
- "send a \"disassembly-done\" signal when done."
- },
- {
- "analyse_and_wait", py_loaded_binary_analyse_and_wait,
- METH_NOARGS,
- "analyse_and_wait(/)\n--\n\nRun the analysis of the loaded binary and " \
- "wait for its completion."
- },
{ NULL }
};
diff --git a/plugins/pychrysalide/analysis/loaded.c b/plugins/pychrysalide/analysis/loaded.c
index b38025a..328bf7b 100644
--- a/plugins/pychrysalide/analysis/loaded.c
+++ b/plugins/pychrysalide/analysis/loaded.c
@@ -36,6 +36,12 @@
+/* Lance l'analyse propre à l'élément chargé. */
+static PyObject *py_loaded_content_analyze(PyObject *, PyObject *);
+
+/* Lance l'analyse de l'élément chargé et attend sa conclusion. */
+static PyObject *py_loaded_content_analyze_and_wait(PyObject *, PyObject *);
+
/* Détermine le nombre de vues disponibles pour un contenu. */
static PyObject *py_loaded_content_count_views(PyObject *, PyObject *);
@@ -43,6 +49,63 @@ static PyObject *py_loaded_content_count_views(PyObject *, PyObject *);
/******************************************************************************
* *
+* Paramètres : self = contenu binaire à manipuler. *
+* args = non utilisé ici. *
+* *
+* Description : Lance l'analyse propre à l'élément chargé. *
+* *
+* Retour : Rien (None). *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_loaded_content_analyze(PyObject *self, PyObject *args)
+{
+ GLoadedContent *content; /* Version GLib de l'élément */
+
+ content = G_LOADED_CONTENT(pygobject_get(self));
+
+ g_loaded_content_analyze(content);
+
+ Py_RETURN_NONE;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = contenu binaire à manipuler. *
+* args = non utilisé ici. *
+* *
+* Description : Lance l'analyse de l'élément chargé et attend sa conclusion. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_loaded_content_analyze_and_wait(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Bilan à retourner */
+ GLoadedContent *content; /* Version GLib de l'élément */
+ bool status; /* Bilan de l'opération */
+
+ content = G_LOADED_CONTENT(pygobject_get(self));
+
+ status = g_loaded_content_analyze_and_wait(content);
+
+ result = status ? Py_True : Py_False;
+ Py_INCREF(result);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : self = contenu chargé à manipuler. *
* args = non utilisé ici. *
* *
@@ -57,7 +120,7 @@ static PyObject *py_loaded_content_count_views(PyObject *, PyObject *);
static PyObject *py_loaded_content_count_views(PyObject *self, PyObject *args)
{
PyObject *result; /* Instance à retourner */
- GLoadedContent *content; /* Version GLib du format */
+ GLoadedContent *content; /* Version GLib de l'élément */
size_t count; /* Quantité à retourner */
content = G_LOADED_CONTENT(pygobject_get(self));
@@ -87,6 +150,18 @@ PyTypeObject *get_python_loaded_content_type(void)
{
static PyMethodDef py_loaded_content_methods[] = {
{
+ "analyze", py_loaded_content_analyze,
+ METH_NOARGS,
+ "analyze($self, /)\n--\n\nStart the analysis of the loaded binary and " \
+ "send a \"disassembly-done\" signal when done."
+ },
+ {
+ "analyze_and_wait", py_loaded_content_analyze_and_wait,
+ METH_NOARGS,
+ "analyze_and_wait($self, /)\n--\n\nRun the analysis of the loaded binary and " \
+ "wait for its completion."
+ },
+ {
"count_views", py_loaded_content_count_views,
METH_NOARGS,
"count_views($self, /)\n--\n\nCompute the quantity of available views."
diff --git a/plugins/pychrysalide/analysis/loading.c b/plugins/pychrysalide/analysis/loading.c
new file mode 100644
index 0000000..fca9929
--- /dev/null
+++ b/plugins/pychrysalide/analysis/loading.c
@@ -0,0 +1,196 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * loading.c - équivalent Python du fichier "analysis/loading.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 "loading.h"
+
+
+#include <pygobject.h>
+
+
+#include <analysis/loading.h>
+
+
+#include "../helpers.h"
+
+
+
+/* --------------------- EXPLORATION NON BLOQUANTE DES CONTENUS --------------------- */
+
+
+
+/* ------------------- RESOLUTION DE CONTENUS BINAIRES EN CHARGES ------------------- */
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* EXPLORATION NON BLOQUANTE DES CONTENUS */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Fournit un accès à une définition de type à diffuser. *
+* *
+* Retour : Définition d'objet pour Python. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+PyTypeObject *get_python_content_explorer_type(void)
+{
+ static PyMethodDef py_content_explorer_methods[] = {
+ { NULL }
+ };
+
+ static PyGetSetDef py_content_explorer_getseters[] = {
+ { NULL }
+ };
+
+ static PyTypeObject py_content_explorer_type = {
+
+ PyVarObject_HEAD_INIT(NULL, 0)
+
+ .tp_name = "pychrysalide.analysis.ContentExplorer",
+
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+
+ .tp_doc = "PyChrysalide content explorer",
+
+ .tp_methods = py_content_explorer_methods,
+ .tp_getset = py_content_explorer_getseters
+
+ };
+
+ return &py_content_explorer_type;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Prend en charge l'objet 'pychrysalide...ContentExplorer'. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool register_python_content_explorer(PyObject *module)
+{
+ PyTypeObject *py_content_explorer_type; /* Type 'ContentExplorer' */
+ PyObject *dict; /* Dictionnaire du module */
+
+ py_content_explorer_type = get_python_content_explorer_type();
+
+ dict = PyModule_GetDict(module);
+
+ if (!register_class_for_pygobject(dict, G_TYPE_CONTENT_EXPLORER, py_content_explorer_type, &PyGObject_Type))
+ return false;
+
+ return true;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* RESOLUTION DE CONTENUS BINAIRES EN CHARGES */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Fournit un accès à une définition de type à diffuser. *
+* *
+* Retour : Définition d'objet pour Python. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+PyTypeObject *get_python_content_resolver_type(void)
+{
+ static PyMethodDef py_content_resolver_methods[] = {
+ { NULL }
+ };
+
+ static PyGetSetDef py_content_resolver_getseters[] = {
+ { NULL }
+ };
+
+ static PyTypeObject py_content_resolver_type = {
+
+ PyVarObject_HEAD_INIT(NULL, 0)
+
+ .tp_name = "pychrysalide.analysis.ContentResolver",
+
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+
+ .tp_doc = "PyChrysalide content resolver",
+
+ .tp_methods = py_content_resolver_methods,
+ .tp_getset = py_content_resolver_getseters
+
+ };
+
+ return &py_content_resolver_type;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Prend en charge l'objet 'pychrysalide...ContentResolver'. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool register_python_content_resolver(PyObject *module)
+{
+ PyTypeObject *py_content_resolver_type; /* Type 'ContentResolver' */
+ PyObject *dict; /* Dictionnaire du module */
+
+ py_content_resolver_type = get_python_content_resolver_type();
+
+ dict = PyModule_GetDict(module);
+
+ if (!register_class_for_pygobject(dict, G_TYPE_CONTENT_RESOLVER, py_content_resolver_type, &PyGObject_Type))
+ return false;
+
+ return true;
+
+}
diff --git a/plugins/pychrysalide/analysis/loading.h b/plugins/pychrysalide/analysis/loading.h
new file mode 100644
index 0000000..56cdd21
--- /dev/null
+++ b/plugins/pychrysalide/analysis/loading.h
@@ -0,0 +1,56 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * loading.h - prototypes pour l'équivalent Python du fichier "analysis/loading.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_LOADING_H
+#define _PLUGINS_PYCHRYSALIDE_ANALYSIS_LOADING_H
+
+
+#include <Python.h>
+#include <stdbool.h>
+
+
+
+/* --------------------- EXPLORATION NON BLOQUANTE DES CONTENUS --------------------- */
+
+
+/* Fournit un accès à une définition de type à diffuser. */
+PyTypeObject *get_python_content_explorer_type(void);
+
+/* Prend en charge l'objet 'pychrysalide.analysis.ContentExplorer'. */
+bool register_python_content_explorer(PyObject *);
+
+
+
+/* ------------------- RESOLUTION DE CONTENUS BINAIRES EN CHARGES ------------------- */
+
+
+/* Fournit un accès à une définition de type à diffuser. */
+PyTypeObject *get_python_content_resolver_type(void);
+
+/* Prend en charge l'objet 'pychrysalide.analysis.ContentResolver'. */
+bool register_python_content_resolver(PyObject *);
+
+
+
+#endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_LOADING_H */
diff --git a/plugins/pychrysalide/analysis/module.c b/plugins/pychrysalide/analysis/module.c
index a77121b..c9ab1e5 100644
--- a/plugins/pychrysalide/analysis/module.c
+++ b/plugins/pychrysalide/analysis/module.c
@@ -32,6 +32,7 @@
#include "block.h"
#include "content.h"
#include "loaded.h"
+#include "loading.h"
#include "project.h"
#include "routine.h"
#include "type.h"
@@ -90,6 +91,8 @@ bool add_analysis_module_to_python_module(PyObject *super)
result &= register_python_binary_content(module);
result &= register_python_loaded_content(module);
+ result &= register_python_content_explorer(module);
+ result &= register_python_content_resolver(module);
result &= register_python_loaded_binary(module);
result &= register_python_instr_block(module);
result &= register_python_binary_routine(module);
diff --git a/plugins/pychrysalide/analysis/project.c b/plugins/pychrysalide/analysis/project.c
index cd7578d..fa7de72 100644
--- a/plugins/pychrysalide/analysis/project.c
+++ b/plugins/pychrysalide/analysis/project.c
@@ -32,18 +32,66 @@
#include <analysis/project.h>
+#include "loaded.h"
#include "../helpers.h"
+/* Crée un nouvel objet Python de type 'StudyProject'. */
+static PyObject *py_study_project_new(PyTypeObject *, PyObject *, PyObject *);
+
/* Procède à l'enregistrement d'un projet donné. */
static PyObject *py_study_project_save(PyObject *, PyObject *);
+/* Attache un contenu donné à un projet donné. */
+static PyObject *py_study_project_attach_content(PyObject *, PyObject *);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type de l'objet à instancier. *
+* args = arguments fournis à l'appel. *
+* kwds = arguments de type key=val fournis. *
+* *
+* Description : Crée un nouvel objet Python de type 'StudyProject'. *
+* *
+* Retour : Instance Python mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_study_project_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ PyObject *result; /* Instance à retourner */
+ const char *filename; /* Destination de la sauvegarde*/
+ int ret; /* Bilan de lecture des args. */
+ GStudyProject *project; /* Version GLib du projet */
+
+ filename = NULL;
+
+ ret = PyArg_ParseTuple(args, "|s", &filename);
+ if (!ret) return NULL;
+
+ if (filename != NULL)
+ project = g_study_project_open(filename);
+ else
+ project = g_study_project_new();
+
+ result = pygobject_new(G_OBJECT(project));
+
+ if (project != NULL)
+ g_object_unref(project);
+
+ return result;
+
+}
/******************************************************************************
* *
-* Paramètres : self = contenu binaire à manipuler. *
+* Paramètres : self = projet d'étude à manipuler. *
* args = arguments accompagnant l'appel. *
* *
* Description : Procède à l'enregistrement d'un projet donné. *
@@ -80,6 +128,41 @@ static PyObject *py_study_project_save(PyObject *self, PyObject *args)
/******************************************************************************
* *
+* Paramètres : self = projet d'étude à manipuler. *
+* args = arguments accompagnant l'appel. *
+* *
+* Description : Attache un contenu donné à un projet donné. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_study_project_attach_content(PyObject *self, PyObject *args)
+{
+ GStudyProject *project; /* Version GLib du format */
+ PyObject *content_obj; /* Objet pour le contenu */
+ int ret; /* Bilan de lecture des args. */
+ GLoadedContent *content; /* Instance GLib correspondante*/
+
+ project = G_STUDY_PROJECT(pygobject_get(self));
+ assert(project != NULL);
+
+ ret = PyArg_ParseTuple(args, "O!", get_python_loaded_content_type(), &content_obj);
+ if (!ret) return NULL;
+
+ content = G_LOADED_CONTENT(pygobject_get(content_obj));
+
+ g_study_project_attach_content(project, content);
+
+ Py_RETURN_NONE;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : - *
* *
* Description : Fournit un accès à une définition de type à diffuser. *
@@ -98,6 +181,11 @@ PyTypeObject *get_python_study_project_type(void)
METH_VARARGS,
"save($self, filename, /)\n--\n\nSave the project into a given file."
},
+ {
+ "attach", py_study_project_attach_content,
+ METH_VARARGS,
+ "attach($self, loaded, /)\n--\n\nAdd a loaded content to the project."
+ },
{ NULL }
};
@@ -116,7 +204,8 @@ PyTypeObject *get_python_study_project_type(void)
.tp_doc = "PyChrysalide study project",
.tp_methods = py_study_project_methods,
- .tp_getset = py_study_project_getseters
+ .tp_getset = py_study_project_getseters,
+ .tp_new = py_study_project_new
};