summaryrefslogtreecommitdiff
path: root/plugins
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
parent315146a49b5570294ca20beca720c4e3f74a86bd (diff)
Improved the way file formats are detected and loaded.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/dex/core.c55
-rw-r--r--plugins/dex/core.h3
-rwxr-xr-xplugins/dex/format.c150
-rwxr-xr-xplugins/dex/format.h5
-rw-r--r--plugins/dex/python/format.c59
-rw-r--r--plugins/elf/core.c50
-rw-r--r--plugins/elf/core.h3
-rw-r--r--plugins/elf/elf_def.h5
-rw-r--r--plugins/elf/format.c129
-rw-r--r--plugins/elf/format.h2
-rw-r--r--plugins/elf/python/format.c58
-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
-rw-r--r--plugins/pychrysalide/core/Makefile.am1
-rw-r--r--plugins/pychrysalide/core/global.c280
-rw-r--r--plugins/pychrysalide/core/global.h42
-rw-r--r--plugins/pychrysalide/core/module.c2
-rw-r--r--plugins/pychrysalide/format/executable.c2
-rw-r--r--plugins/pychrysalide/plugin.c66
24 files changed, 1106 insertions, 323 deletions
diff --git a/plugins/dex/core.c b/plugins/dex/core.c
index 05130a6..869ef4b 100644
--- a/plugins/dex/core.c
+++ b/plugins/dex/core.c
@@ -24,7 +24,7 @@
#include "core.h"
-#include <core/formats.h>
+#include <core/global.h>
#include <plugins/plugin-def.h>
@@ -34,7 +34,7 @@
DEFINE_CHRYSALIDE_PLUGIN("dex", "Add support for the DEX format", "0.1.0",
- RL("PyChrysalide", "dexbnf"), AL(PGA_PLUGIN_INIT));
+ RL("PyChrysalide", "dexbnf"), AL(PGA_PLUGIN_INIT, PGA_CONTENT_RESOLVER));
@@ -54,10 +54,7 @@ G_MODULE_EXPORT bool chrysalide_plugin_init(GPluginModule *plugin)
{
bool result; /* Bilan à retourner */
- result = register_format_matcher(dex_is_matching, NULL);
-
- if (result)
- result = register_format_loader("dex", "Dalvik Executable format", g_dex_format_new);
+ result = register_format_loader("dex", "Dalvik Executable format", g_dex_format_new);
if (result)
result = add_format_dex_module_to_python_module();
@@ -65,3 +62,49 @@ G_MODULE_EXPORT bool chrysalide_plugin_init(GPluginModule *plugin)
return result;
}
+
+
+/******************************************************************************
+* *
+* Paramètres : plugin = greffon à manipuler. *
+* action = type d'action attendue. *
+* content = contenu binaire à traiter. *
+* gid = identifiant du groupe de traitement. *
+* status = barre de statut à tenir informée. *
+* *
+* Description : Procède à une opération liée à un contenu binaire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+G_MODULE_EXPORT void chrysalide_plugin_handle_binary_content(const GPluginModule *plugin, PluginAction action, GBinContent *content, gid_t gid, GtkStatusStack *status)
+{
+ vmpa2t addr; /* Tête de lecture initiale */
+ bool test; /* Bilan des accès mémoire */
+ char magic[DEX_FILE_MAGIC_LEN]; /* Idenfiant standard */
+ GExeFormat *format; /* Format DEX reconnu */
+ GLoadedContent *loaded; /* Représentation chargée */
+ GContentResolver *resolver; /* Resolveur de contenus */
+
+ init_vmpa(&addr, 0, VMPA_NO_VIRTUAL);
+
+ test = g_binary_content_read_raw(content, &addr, DEX_FILE_MAGIC_LEN, (bin_t *)magic);
+
+ if (test)
+ test = (memcmp(magic, DEX_FILE_MAGIC, DEX_FILE_MAGIC_LEN) == 0);
+
+ if (test)
+ {
+ format = g_dex_format_new(content);
+ loaded = g_loaded_binary_new(format);
+
+ resolver = get_current_content_resolver();
+ g_content_resolver_add_detected(resolver, gid, loaded);
+ g_object_unref(G_OBJECT(resolver));
+
+ }
+
+}
diff --git a/plugins/dex/core.h b/plugins/dex/core.h
index bc1a444..8a07f84 100644
--- a/plugins/dex/core.h
+++ b/plugins/dex/core.h
@@ -33,6 +33,9 @@
/* Prend acte du chargement du greffon. */
G_MODULE_EXPORT bool chrysalide_plugin_init(GPluginModule *);
+/* Procède à une opération liée à un contenu binaire. */
+G_MODULE_EXPORT void chrysalide_plugin_handle_binary_content(const GPluginModule *, PluginAction, GBinContent *, gid_t, GtkStatusStack *);
+
#endif /* _PLUGINS_DEX_CORE_H */
diff --git a/plugins/dex/format.c b/plugins/dex/format.c
index f4cfdc9..d3e18da 100755
--- a/plugins/dex/format.c
+++ b/plugins/dex/format.c
@@ -51,6 +51,12 @@ static void g_dex_format_dispose(GDexFormat *);
/* Procède à la libération totale de la mémoire. */
static void g_dex_format_finalize(GDexFormat *);
+/* Indique la désignation interne du format. */
+static const char *g_dex_format_get_name(const GDexFormat *);
+
+/* Assure l'interprétation d'un format en différé. */
+static bool g_dex_format_analyze(GDexFormat *, wgroup_id_t, GtkStatusStack *);
+
/* Informe quant au boutisme utilisé. */
static SourceEndian g_dex_format_get_endianness(const GDexFormat *);
@@ -83,52 +89,6 @@ static void g_dex_format_decompile(const GDexFormat *, void/*GCodeBuffer*/ *, co
-/******************************************************************************
-* *
-* Paramètres : content = contenu binaire à parcourir. *
-* parent = éventuel format exécutable déjà chargé. *
-* unused = adresse non utilisée ici. *
-* key = identifiant de format trouvé ou NULL. [OUT] *
-* *
-* Description : Indique si le format peut être pris en charge ici. *
-* *
-* Retour : Conclusion de haut niveau sur la reconnaissance effectuée. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-FormatMatchStatus dex_is_matching(GBinContent *content, GExeFormat *parent, void *unused, char **key)
-{
- FormatMatchStatus result; /* Bilan à renvoyer */
- vmpa2t addr; /* Tête de lecture initiale */
- bool status; /* Bilan des accès mémoire */
- char magic[DEX_FILE_MAGIC_LEN]; /* Idenfiant standard */
-
-
- /* REMME */
- if (parent != NULL) return FMS_UNKNOWN;
-
-
- init_vmpa(&addr, 0, VMPA_NO_VIRTUAL);
-
- status = g_binary_content_read_raw(content, &addr, DEX_FILE_MAGIC_LEN, (bin_t *)magic);
-
- status &= (memcmp(magic, DEX_FILE_MAGIC, DEX_FILE_MAGIC_LEN) == 0);
-
- if (status)
- {
- result = FMS_MATCHED;
- *key = strdup(parent == NULL ? "dex" : "dexdbg");
- }
- else
- result = FMS_UNKNOWN;
-
- return result;
-
-}
-
-
/* Indique le type défini pour un format d'exécutable DEX. */
G_DEFINE_TYPE(GDexFormat, g_dex_format, G_TYPE_EXE_FORMAT);
@@ -158,6 +118,8 @@ static void g_dex_format_class_init(GDexFormatClass *klass)
fmt = G_BIN_FORMAT_CLASS(klass);
+ fmt->get_name = (format_get_name_fc)g_dex_format_get_name;
+ fmt->analyze = (format_analyze_fc)g_dex_format_analyze;
fmt->get_endian = (format_get_endian_fc)g_dex_format_get_endianness;
exe = G_EXE_FORMAT_CLASS(klass);
@@ -240,8 +202,6 @@ static void g_dex_format_finalize(GDexFormat *format)
/******************************************************************************
* *
* Paramètres : content = contenu binaire à parcourir. *
-* parent = éventuel format exécutable déjà chargé. *
- status = barre de statut à tenir informée. *
* *
* Description : Prend en charge un nouveau format Dex. *
* *
@@ -251,54 +211,96 @@ static void g_dex_format_finalize(GDexFormat *format)
* *
******************************************************************************/
-GBinFormat *g_dex_format_new(GBinContent *content, GExeFormat *parent, GtkStatusStack *status)
+GExeFormat *g_dex_format_new(GBinContent *content)
{
GDexFormat *result; /* Structure à retourner */
- GBinFormat *base; /* Version basique du format */
- GExeFormat *exe_format; /* Autre version du format */
- vmpa2t pos; /* Position de tête de lecture */
- wgroup_id_t gid; /* Identifiant pour les tâches */
result = g_object_new(G_TYPE_DEX_FORMAT, NULL);
- base = G_BIN_FORMAT(result);
- exe_format = G_EXE_FORMAT(result);
+ g_binary_format_set_content(G_BIN_FORMAT(result), content);
- g_binary_format_set_content(base, content);
+ return G_EXE_FORMAT(result);
- init_vmpa(&pos, 0, VMPA_NO_VIRTUAL);
+}
- if (!read_dex_header(result, &pos, &result->header))
- goto gdfn_error;
+/******************************************************************************
+* *
+* Paramètres : format = description de l'exécutable à consulter. *
+* *
+* Description : Indique la désignation interne du format. *
+* *
+* Retour : Description du format. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+static const char *g_dex_format_get_name(const GDexFormat *format)
+{
+ const char *result; /* Désignation à retourner */
- /* TODO : vérifier que les *_id ne se chevauchent pas */
+ result = "dex";
+ return result;
- gid = g_work_queue_define_work_group(get_work_queue());
+}
- if (!load_all_dex_types(result, gid, status))
- goto gdfn_error;
- if (!load_all_dex_fields(result, gid, status))
- goto gdfn_error;
+/******************************************************************************
+* *
+* Paramètres : format = format chargé dont l'analyse est lancée. *
+* gid = groupe de travail dédié. *
+* status = barre de statut à tenir informée. *
+* *
+* Description : Assure l'interprétation d'un format en différé. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
- if (!load_all_dex_classes(result, gid, status))
- goto gdfn_error;
+static bool g_dex_format_analyze(GDexFormat *format, wgroup_id_t gid, GtkStatusStack *status)
+{
+ bool result; /* Bilan à retourner */
+ GBinFormat *base; /* Version basique du format */
+ GExeFormat *exe; /* Autre version du format */
+ vmpa2t pos; /* Position de tête de lecture */
- preload_binary_format(PGA_FORMAT_PRELOAD, base, base->info, status);
+ result = false;
- if (!g_executable_format_complete_loading(exe_format, status))
- goto gdfn_error;
+ base = G_BIN_FORMAT(format);
+ exe = G_EXE_FORMAT(format);
- return base;
+ init_vmpa(&pos, 0, VMPA_NO_VIRTUAL);
- gdfn_error:
+ if (!read_dex_header(format, &pos, &format->header))
+ goto gdfa_error;
- g_object_unref(G_OBJECT(result));
- return NULL;
+ /* TODO : vérifier que les *_id ne se chevauchent pas */
+
+
+ if (!load_all_dex_types(format, gid, status))
+ goto gdfa_error;
+
+ if (!load_all_dex_fields(format, gid, status))
+ goto gdfa_error;
+
+ if (!load_all_dex_classes(format, gid, status))
+ goto gdfa_error;
+
+ preload_binary_format(PGA_FORMAT_PRELOAD, base, base->info, status);
+
+ if (!g_executable_format_complete_loading(exe, status))
+ goto gdfa_error;
+
+ result = true;
+
+ gdfa_error:
+
+ return result;
}
diff --git a/plugins/dex/format.h b/plugins/dex/format.h
index 81a4b0f..6850ed1 100755
--- a/plugins/dex/format.h
+++ b/plugins/dex/format.h
@@ -52,14 +52,11 @@ typedef struct _GDexFormat GDexFormat;
typedef struct _GDexFormatClass GDexFormatClass;
-/* Indique si le format peut être pris en charge ici. */
-FormatMatchStatus dex_is_matching(GBinContent *, GExeFormat *, void *, char **);
-
/* Indique le type défini pour un format d'exécutable DEX. */
GType g_dex_format_get_type(void);
/* Prend en charge un nouveau format DEX. */
-GBinFormat *g_dex_format_new(GBinContent *, GExeFormat *, GtkStatusStack *);
+GExeFormat *g_dex_format_new(GBinContent *);
/* Présente l'en-tête DEX du format chargé. */
const dex_header *g_dex_format_get_header(const GDexFormat *);
diff --git a/plugins/dex/python/format.c b/plugins/dex/python/format.c
index a406f62..a421549 100644
--- a/plugins/dex/python/format.c
+++ b/plugins/dex/python/format.c
@@ -25,6 +25,7 @@
#include "format.h"
+#include <assert.h>
#include <pygobject.h>
@@ -69,67 +70,17 @@ static PyObject *py_dex_format_new(PyTypeObject *type, PyObject *args, PyObject
{
PyObject *result; /* Instance à retourner */
PyObject *content_obj; /* Objet pour le contenu */
- PyObject *parent_obj; /* Objet pour le parent */
- PyObject *status_obj; /* Objet pour la progression */
int ret; /* Bilan de lecture des args. */
GBinContent *content; /* Instance GLib du contenu */
- GExeFormat *parent; /* Instance GLib du parent */
- GtkStatusStack *status; /* Instance GTK de suivi */
- GBinFormat *format; /* Création GLib à transmettre */
+ GExeFormat *format; /* Création GLib à transmettre */
- parent_obj = Py_None;
- status_obj = Py_None;
-
- ret = PyArg_ParseTuple(args, "O|OO", &content_obj, &parent_obj, &status_obj);
+ ret = PyArg_ParseTuple(args, "O!", get_python_binary_content_type(), &content_obj);
if (!ret) return NULL;
- ret = PyObject_IsInstance(content_obj, (PyObject *)get_python_binary_content_type());
- if (!ret)
- {
- PyErr_SetString(PyExc_TypeError, _("The first argument must be an instance of BinContent."));
- return NULL;
- }
-
content = G_BIN_CONTENT(pygobject_get(content_obj));
- if (parent_obj == Py_None)
- parent = NULL;
-
- else
- {
- ret = PyObject_IsInstance(parent_obj, (PyObject *)get_python_executable_format_type());
- if (!ret)
- {
- PyErr_SetString(PyExc_TypeError, _("The second argument must be a container format or None."));
- return NULL;
- }
-
- parent = G_EXE_FORMAT(pygobject_get(parent_obj));
-
- }
-
- if (status_obj == Py_None)
- status = NULL;
-
- else
- {
- ret = PyObject_IsInstance(status_obj, (PyObject *)get_python_binary_content_type());
- if (!ret)
- {
- PyErr_SetString(PyExc_TypeError, _("The third argument must be a status bar object or None."));
- return NULL;
- }
-
- status = GTK_STATUS_STACK(pygobject_get(status_obj));
-
- }
-
- format = g_dex_format_new(content, parent, status);
- if (format == NULL)
- {
- PyErr_SetString(PyExc_RuntimeError, _("Unable to load the DEX format."));
- return NULL;
- }
+ format = g_dex_format_new(content);
+ assert(format != NULL);
result = pygobject_new(G_OBJECT(format));
diff --git a/plugins/elf/core.c b/plugins/elf/core.c
index 0cfd49c..7486242 100644
--- a/plugins/elf/core.c
+++ b/plugins/elf/core.c
@@ -24,7 +24,7 @@
#include "core.h"
-#include <core/formats.h>
+#include <core/global.h>
#include <plugins/plugin-def.h>
@@ -34,7 +34,7 @@
DEFINE_CHRYSALIDE_PLUGIN("elf", "Add support for the ELF format", "0.1.0",
- RL("PyChrysalide"), AL(PGA_PLUGIN_INIT));
+ RL("PyChrysalide"), AL(PGA_PLUGIN_INIT, PGA_CONTENT_RESOLVER));
@@ -65,3 +65,49 @@ G_MODULE_EXPORT bool chrysalide_plugin_init(GPluginModule *plugin)
return result;
}
+
+
+/******************************************************************************
+* *
+* Paramètres : plugin = greffon à manipuler. *
+* action = type d'action attendue. *
+* content = contenu binaire à traiter. *
+* gid = identifiant du groupe de traitement. *
+* status = barre de statut à tenir informée. *
+* *
+* Description : Procède à une opération liée à un contenu binaire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+G_MODULE_EXPORT void chrysalide_plugin_handle_binary_content(const GPluginModule *plugin, PluginAction action, GBinContent *content, gid_t gid, GtkStatusStack *status)
+{
+ vmpa2t addr; /* Tête de lecture initiale */
+ bool test; /* Bilan des accès mémoire */
+ char magic[SELFMAG]; /* Idenfiant standard */
+ GExeFormat *format; /* Format ELF reconnu */
+ GLoadedContent *loaded; /* Représentation chargée */
+ GContentResolver *resolver; /* Resolveur de contenus */
+
+ init_vmpa(&addr, 0, VMPA_NO_VIRTUAL);
+
+ test = g_binary_content_read_raw(content, &addr, SELFMAG, (bin_t *)magic);
+
+ if (test)
+ test = (memcmp(magic, ELFMAG, SELFMAG) == 0);
+
+ if (test)
+ {
+ format = g_elf_format_new(content);
+ loaded = g_loaded_binary_new(format);
+
+ resolver = get_current_content_resolver();
+ g_content_resolver_add_detected(resolver, gid, loaded);
+ g_object_unref(G_OBJECT(resolver));
+
+ }
+
+}
diff --git a/plugins/elf/core.h b/plugins/elf/core.h
index 52ded90..ec9ed5c 100644
--- a/plugins/elf/core.h
+++ b/plugins/elf/core.h
@@ -33,6 +33,9 @@
/* Prend acte du chargement du greffon. */
G_MODULE_EXPORT bool chrysalide_plugin_init(GPluginModule *);
+/* Procède à une opération liée à un contenu binaire. */
+G_MODULE_EXPORT void chrysalide_plugin_handle_binary_content(const GPluginModule *, PluginAction, GBinContent *, gid_t, GtkStatusStack *);
+
#endif /* _PLUGINS_ELF_CORE_H */
diff --git a/plugins/elf/elf_def.h b/plugins/elf/elf_def.h
index bb33d6d..a820eac 100644
--- a/plugins/elf/elf_def.h
+++ b/plugins/elf/elf_def.h
@@ -111,6 +111,11 @@ typedef union _elf_header
#define EI_ABIVERSION 8 /* Version de l'ABI */
#define EI_PAD 9 /* Premier octet de bourrage */
+/* ... EI_MAG* */
+
+#define ELFMAG "\x7f\x45\x4c\x46" /* .ELF */
+#define SELFMAG 4
+
/* ... EI_CLASS */
#define ELFCLASSNONE 0 /* Objet invalide */
diff --git a/plugins/elf/format.c b/plugins/elf/format.c
index eb22059..0fb2d1e 100644
--- a/plugins/elf/format.c
+++ b/plugins/elf/format.c
@@ -60,6 +60,12 @@ static void g_elf_format_dispose(GElfFormat *);
/* Procède à la libération totale de la mémoire. */
static void g_elf_format_finalize(GElfFormat *);
+/* Indique la désignation interne du format. */
+static const char *g_elf_format_get_name(const GElfFormat *);
+
+/* Assure l'interprétation d'un format en différé. */
+static bool g_elf_format_analyze(GElfFormat *, wgroup_id_t, GtkStatusStack *);
+
/* Informe quant au boutisme utilisé. */
static SourceEndian g_elf_format_get_endianness(const GElfFormat *);
@@ -159,6 +165,8 @@ static void g_elf_format_class_init(GElfFormatClass *klass)
fmt = G_BIN_FORMAT_CLASS(klass);
+ fmt->get_name = (format_get_name_fc)g_elf_format_get_name;
+ fmt->analyze = (format_analyze_fc)g_elf_format_analyze;
fmt->get_endian = (format_get_endian_fc)g_elf_format_get_endianness;
fmt->complete = (format_complete_analysis_fc)g_elf_format_complete_analysis;
@@ -236,8 +244,6 @@ static void g_elf_format_finalize(GElfFormat *format)
/******************************************************************************
* *
* Paramètres : content = contenu binaire à parcourir. *
-* parent = éventuel format exécutable déjà chargé. *
- status = barre de statut à tenir informée. *
* *
* Description : Prend en charge un nouveau format ELF. *
* *
@@ -247,65 +253,113 @@ static void g_elf_format_finalize(GElfFormat *format)
* *
******************************************************************************/
-GBinFormat *g_elf_format_new(GBinContent *content, GExeFormat *parent, GtkStatusStack *status)
+GExeFormat *g_elf_format_new(GBinContent *content)
{
GElfFormat *result; /* Structure à retourner */
- GBinFormat *base; /* Version basique du format */
- GExeFormat *exe_format; /* Autre version du format */
result = g_object_new(G_TYPE_ELF_FORMAT, NULL);
- base = G_BIN_FORMAT(result);
- exe_format = G_EXE_FORMAT(result);
+ g_binary_format_set_content(G_BIN_FORMAT(result), content);
+
+ return G_EXE_FORMAT(result);
- g_binary_format_set_content(base, content);
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = description de l'exécutable à consulter. *
+* *
+* Description : Indique la désignation interne du format. *
+* *
+* Retour : Description du format. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static const char *g_elf_format_get_name(const GElfFormat *format)
+{
+ const char *result; /* Désignation à retourner */
+
+ result = "elf";
+
+ return result;
+
+}
- if (!read_elf_header(result, &result->header, &result->is_32b, &result->endian))
- goto gefn_error;
+
+/******************************************************************************
+* *
+* Paramètres : format = format chargé dont l'analyse est lancée. *
+* gid = groupe de travail dédié. *
+* status = barre de statut à tenir informée. *
+* *
+* Description : Assure l'interprétation d'un format en différé. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_elf_format_analyze(GElfFormat *format, wgroup_id_t gid, GtkStatusStack *status)
+{
+ bool result; /* Bilan à retourner */
+ GBinFormat *base; /* Version basique du format */
+ GExeFormat *exe; /* Autre version du format */
+
+ result = false;
+
+ base = G_BIN_FORMAT(format);
+ exe = G_EXE_FORMAT(format);
+
+ if (!read_elf_header(format, &format->header, &format->is_32b, &format->endian))
+ goto gefa_error;
/* Vérification des tailles d'entrée de table */
- if (ELF_HDR(result, result->header, e_phentsize) != ELF_SIZEOF_PHDR(result))
+ if (ELF_HDR(format, format->header, e_phentsize) != ELF_SIZEOF_PHDR(format))
{
log_variadic_message(LMT_BAD_BINARY,
_("Corrupted program header size (%hu); fixed!" \
" -- replacing 0x%04hx by 0x%04hx at offset 0x%x"),
- ELF_HDR(result, result->header, e_phentsize),
- ELF_HDR(result, result->header, e_phentsize),
- ELF_SIZEOF_PHDR(result),
- ELF_HDR_OFFSET_OF(result, e_phentsize));
+ ELF_HDR(format, format->header, e_phentsize),
+ ELF_HDR(format, format->header, e_phentsize),
+ ELF_SIZEOF_PHDR(format),
+ ELF_HDR_OFFSET_OF(format, e_phentsize));
- ELF_HDR_SET(result, result->header, e_phentsize, ELF_SIZEOF_PHDR(result));
+ ELF_HDR_SET(format, format->header, e_phentsize, ELF_SIZEOF_PHDR(format));
}
- if (ELF_HDR(result, result->header, e_shentsize) != ELF_SIZEOF_SHDR(result))
+ if (ELF_HDR(format, format->header, e_shentsize) != ELF_SIZEOF_SHDR(format))
{
log_variadic_message(LMT_BAD_BINARY,
_("Corrupted section header size (%hu); fixed!" \
" -- replacing 0x%04hx by 0x%04hx at offset 0x%x"),
- ELF_HDR(result, result->header, e_shentsize),
- ELF_HDR(result, result->header, e_shentsize),
- ELF_SIZEOF_SHDR(result),
- ELF_HDR_OFFSET_OF(result, e_shentsize));
+ ELF_HDR(format, format->header, e_shentsize),
+ ELF_HDR(format, format->header, e_shentsize),
+ ELF_SIZEOF_SHDR(format),
+ ELF_HDR_OFFSET_OF(format, e_shentsize));
- ELF_HDR_SET(result, result->header, e_shentsize, ELF_SIZEOF_SHDR(result));
+ ELF_HDR_SET(format, format->header, e_shentsize, ELF_SIZEOF_SHDR(format));
}
/* Opérations spécifiques à l'architecture */
- switch (ELF_HDR(result, result->header, e_machine))
+ switch (ELF_HDR(format, format->header, e_machine))
{
case EM_ARM:
- result->ops.get_type_desc = (get_elf_prgm_type_desc_cb)get_elf_program_arm_type_desc;
- result->ops.fix_virt = (fix_elf_virt_addr_cb)fix_elf_arm_virtual_address;
- result->ops.get_linkage_offset = (get_elf_linkage_offset_cb)retrieve_arm_linkage_offset;
+ format->ops.get_type_desc = (get_elf_prgm_type_desc_cb)get_elf_program_arm_type_desc;
+ format->ops.fix_virt = (fix_elf_virt_addr_cb)fix_elf_arm_virtual_address;
+ format->ops.get_linkage_offset = (get_elf_linkage_offset_cb)retrieve_arm_linkage_offset;
break;
default:
log_variadic_message(LMT_ERROR, "Architecture not supported for ELF binaries");
- goto gefn_error;
+ goto gefa_error;
break;
}
@@ -323,23 +377,20 @@ GBinFormat *g_elf_format_new(GBinContent *content, GExeFormat *parent, GtkStatus
preload_binary_format(PGA_FORMAT_PRELOAD, base, base->info, status);
+ if (!load_elf_symbols(format, status))
+ goto gefa_error;
- if (!load_elf_symbols(result, status))
- goto gefn_error;
+ if (!find_all_elf_strings(format))
+ goto gefa_error;
- if (!find_all_elf_strings(result))
- goto gefn_error;
+ if (!g_executable_format_complete_loading(exe, status))
+ goto gefa_error;
- if (!g_executable_format_complete_loading(exe_format, status))
- goto gefn_error;
+ result = true;
- return base;
+ gefa_error:
- gefn_error:
-
- g_object_unref(G_OBJECT(result));
-
- return NULL;
+ return result;
}
diff --git a/plugins/elf/format.h b/plugins/elf/format.h
index a822105..47b3171 100644
--- a/plugins/elf/format.h
+++ b/plugins/elf/format.h
@@ -59,7 +59,7 @@ FormatMatchStatus elf_is_matching(GBinContent *, GExeFormat *, void *, char **);
GType g_elf_format_get_type(void);
/* Prend en charge un nouveau format ELF. */
-GBinFormat *g_elf_format_new(GBinContent *, GExeFormat *, GtkStatusStack *);
+GExeFormat *g_elf_format_new(GBinContent *);
/* Présente l'en-tête ELF du format chargé. */
const elf_header *g_elf_format_get_header(const GElfFormat *);
diff --git a/plugins/elf/python/format.c b/plugins/elf/python/format.c
index a3d8758..2d5bfd8 100644
--- a/plugins/elf/python/format.c
+++ b/plugins/elf/python/format.c
@@ -72,67 +72,17 @@ static PyObject *py_elf_format_new(PyTypeObject *type, PyObject *args, PyObject
{
PyObject *result; /* Instance à retourner */
PyObject *content_obj; /* Objet pour le contenu */
- PyObject *parent_obj; /* Objet pour le parent */
- PyObject *status_obj; /* Objet pour la progression */
int ret; /* Bilan de lecture des args. */
GBinContent *content; /* Instance GLib du contenu */
- GExeFormat *parent; /* Instance GLib du parent */
- GtkStatusStack *status; /* Instance GTK de suivi */
- GBinFormat *format; /* Création GLib à transmettre */
+ GExeFormat *format; /* Création GLib à transmettre */
- parent_obj = Py_None;
- status_obj = Py_None;
-
- ret = PyArg_ParseTuple(args, "O|OO", &content_obj, &parent_obj, &status_obj);
+ ret = PyArg_ParseTuple(args, "O!", get_python_binary_content_type(), &content_obj);
if (!ret) return NULL;
- ret = PyObject_IsInstance(content_obj, (PyObject *)get_python_binary_content_type());
- if (!ret)
- {
- PyErr_SetString(PyExc_TypeError, _("The first argument must be an instance of BinContent."));
- return NULL;
- }
-
content = G_BIN_CONTENT(pygobject_get(content_obj));
- if (parent_obj == Py_None)
- parent = NULL;
-
- else
- {
- ret = PyObject_IsInstance(parent_obj, (PyObject *)get_python_executable_format_type());
- if (!ret)
- {
- PyErr_SetString(PyExc_TypeError, _("The second argument must be a container format or None."));
- return NULL;
- }
-
- parent = G_EXE_FORMAT(pygobject_get(parent_obj));
-
- }
-
- if (status_obj == Py_None)
- status = NULL;
-
- else
- {
- ret = PyObject_IsInstance(status_obj, (PyObject *)get_python_binary_content_type());
- if (!ret)
- {
- PyErr_SetString(PyExc_TypeError, _("The third argument must be a status bar object or None."));
- return NULL;
- }
-
- status = GTK_STATUS_STACK(pygobject_get(status_obj));
-
- }
-
- format = g_elf_format_new(content, parent, status);
- if (format == NULL)
- {
- PyErr_SetString(PyExc_RuntimeError, _("Unable to load the ELF format."));
- return NULL;
- }
+ format = g_elf_format_new(content);
+ assert(format != NULL);
result = pygobject_new(G_OBJECT(format));
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
};
diff --git a/plugins/pychrysalide/core/Makefile.am b/plugins/pychrysalide/core/Makefile.am
index bc21d77..999674d 100644
--- a/plugins/pychrysalide/core/Makefile.am
+++ b/plugins/pychrysalide/core/Makefile.am
@@ -4,6 +4,7 @@ noinst_LTLIBRARIES = libpychrysacore.la
libpychrysacore_la_SOURCES = \
demanglers.h demanglers.c \
formats.h formats.c \
+ global.h global.c \
logs.h logs.c \
module.h module.c \
params.h params.c
diff --git a/plugins/pychrysalide/core/global.c b/plugins/pychrysalide/core/global.c
new file mode 100644
index 0000000..0fe767f
--- /dev/null
+++ b/plugins/pychrysalide/core/global.c
@@ -0,0 +1,280 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * global.c - équivalent Python du fichier "core/global.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 "global.h"
+
+
+#include <pygobject.h>
+
+
+#include <core/global.h>
+
+
+#include "../helpers.h"
+#include "../analysis/project.h"
+
+
+
+/* Fournit l'adresse de l'explorateur de contenus courant. */
+static PyObject *py_global_get_content_explorer(PyObject *, void *);
+
+/* Fournit l'adresse du résolveur de contenus courant. */
+static PyObject *py_global_get_content_resolver(PyObject *, void *);
+
+/* Fournit l'adresse du projet courant. */
+static PyObject *py_global_get_current_project(PyObject *, void *);
+
+/* Définit l'adresse du projet courant. */
+static int py_global_set_current_project(PyObject *, PyObject *, void *);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : self = objet Python concerné par l'appel. *
+* closure = non utilisé ici. *
+* *
+* Description : Fournit l'adresse de l'explorateur de contenus courant. *
+* *
+* Retour : Adresse de l'explorateur global ou None si aucun (!). *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_global_get_content_explorer(PyObject *self, void *closure)
+{
+ PyObject *result; /* Instance Python à retourner */
+ GContentExplorer *explorer; /* Gestionnaire natif récupéré */
+
+ explorer = get_current_content_explorer();
+
+ if (explorer != NULL)
+ {
+ result = pygobject_new(G_OBJECT(explorer));
+ g_object_unref(G_OBJECT(explorer));
+ }
+ else
+ {
+ result = Py_None;
+ Py_INCREF(result);
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = objet Python concerné par l'appel. *
+* closure = non utilisé ici. *
+* *
+* Description : Fournit l'adresse du résolveur de contenus courant. *
+* *
+* Retour : Adresse du résolveur global ou None si aucun (!). *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_global_get_content_resolver(PyObject *self, void *closure)
+{
+ PyObject *result; /* Instance Python à retourner */
+ GContentResolver *resolver; /* Gestionnaire natif récupéré */
+
+ resolver = get_current_content_resolver();
+
+ if (resolver != NULL)
+ {
+ result = pygobject_new(G_OBJECT(resolver));
+ g_object_unref(G_OBJECT(resolver));
+ }
+ else
+ {
+ result = Py_None;
+ Py_INCREF(result);
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = objet Python concerné par l'appel. *
+* closure = non utilisé ici. *
+* *
+* Description : Fournit l'adresse du projet courant. *
+* *
+* Retour : Adresse du résolveur global ou None si aucun. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_global_get_current_project(PyObject *self, void *closure)
+{
+ PyObject *result; /* Instance Python à retourner */
+ GStudyProject *project; /* Projet courant récupéré */
+
+ project = get_current_project();
+
+ if (project != NULL)
+ {
+ result = pygobject_new(G_OBJECT(project));
+ g_object_unref(G_OBJECT(project));
+ }
+ else
+ {
+ result = Py_None;
+ Py_INCREF(result);
+ }
+
+ printf("result: %p (project=%p)\n", result, project);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = objet Python concerné par l'appel. *
+* value = valeur fournie à intégrer ou prendre en compte. *
+* closure = adresse non utilisée ici. *
+* *
+* Description : Définit l'adresse du projet courant. *
+* *
+* Retour : Bilan de l'opération pour Python. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static int py_global_set_current_project(PyObject *self, PyObject *value, void *closure)
+{
+ int ret; /* Bilan d'analyse */
+ GStudyProject *project; /* Version GLib du format */
+
+ ret = PyObject_IsInstance(value, (PyObject *)get_python_study_project_type());
+ if (!ret) return -1;
+
+ project = G_STUDY_PROJECT(pygobject_get(value));
+
+ g_object_ref(G_OBJECT(project));
+
+ set_current_project(project);
+
+ 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_global_type(void)
+{
+ static PyMethodDef py_global_methods[] = {
+ { NULL }
+ };
+
+ static PyGetSetDef py_global_getseters[] = {
+ {
+ "content_explorer", py_global_get_content_explorer, NULL,
+ "Get the global exploration manager discovering contents.", NULL
+ },
+ {
+ "content_resolver", py_global_get_content_resolver, NULL,
+ "Get the global resolution manager translating binary contents into loaded contents.", NULL
+ },
+ {
+ "current_project", py_global_get_current_project, py_global_set_current_project,
+ "Get or set the current global project.", NULL
+ },
+ { NULL }
+ };
+
+ static PyTypeObject py_global_type = {
+
+ PyVarObject_HEAD_INIT(NULL, 0)
+
+ .tp_name = "pychrysalide.core._global",
+ .tp_basicsize = sizeof(PyObject),
+
+ .tp_flags = Py_TPFLAGS_DEFAULT,
+
+ .tp_doc = "Access to the global properties",
+
+ .tp_methods = py_global_methods,
+ .tp_getset = py_global_getseters
+
+ };
+
+ return &py_global_type;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Prend en charge l'objet 'pychrysalide.core._global'. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool register_python_global(PyObject *module)
+{
+ PyTypeObject *py_global_type; /* Type Python de 'global' */
+ int ret; /* Bilan d'un appel */
+
+ py_global_type = get_python_global_type();
+
+ py_global_type->tp_new = PyType_GenericNew;
+
+ if (PyType_Ready(py_global_type) != 0)
+ return false;
+
+ Py_INCREF(py_global_type);
+ ret = PyModule_AddObject(module, "_global", (PyObject *)py_global_type);
+
+ return (ret == 0);
+
+}
diff --git a/plugins/pychrysalide/core/global.h b/plugins/pychrysalide/core/global.h
new file mode 100644
index 0000000..b136cdb
--- /dev/null
+++ b/plugins/pychrysalide/core/global.h
@@ -0,0 +1,42 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * global.h - prototypes pour l'équivalent Python du fichier "core/global.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_CORE_GLOBAL_H
+#define _PLUGINS_PYCHRYSALIDE_CORE_GLOBAL_H
+
+
+#include <Python.h>
+#include <stdbool.h>
+
+
+
+/* Fournit un accès à une définition de type à diffuser. */
+PyTypeObject *get_python_global_type(void);
+
+/* Prend en charge l'objet 'pychrysalide.core._global'. */
+bool register_python_global(PyObject *);
+
+
+
+#endif /* _PLUGINS_PYCHRYSALIDE_CORE_GLOBAL_H */
diff --git a/plugins/pychrysalide/core/module.c b/plugins/pychrysalide/core/module.c
index dd89ea0..22d9a48 100644
--- a/plugins/pychrysalide/core/module.c
+++ b/plugins/pychrysalide/core/module.c
@@ -30,6 +30,7 @@
#include "demanglers.h"
#include "formats.h"
+#include "global.h"
#include "logs.h"
#include "params.h"
#include "../access.h"
@@ -84,6 +85,7 @@ bool add_core_module_to_python_module(PyObject *super)
result &= register_python_demanglers(module);
result &= register_python_formats(module);
+ result &= register_python_global(module);
result &= register_python_logs(module);
result &= register_python_params(module);
diff --git a/plugins/pychrysalide/format/executable.c b/plugins/pychrysalide/format/executable.c
index 1b1bfe8..9ae45ff 100644
--- a/plugins/pychrysalide/format/executable.c
+++ b/plugins/pychrysalide/format/executable.c
@@ -28,7 +28,7 @@
#include <pygobject.h>
-#include <format/format.h>
+#include <format/executable.h>
#include "format.h"
diff --git a/plugins/pychrysalide/plugin.c b/plugins/pychrysalide/plugin.c
index fad0084..4689d0c 100644
--- a/plugins/pychrysalide/plugin.c
+++ b/plugins/pychrysalide/plugin.c
@@ -76,6 +76,9 @@ static bool g_python_plugin_do_init(GPythonPlugin *);
/* Procède à l'extinction du greffon. */
static bool g_python_plugin_do_exit(GPythonPlugin *, GObject *);
+/* Procède à une opération liée à un contenu binaire. */
+static void g_python_plugin_handle_binary_content(const GPythonPlugin *, PluginAction, GBinContent *, gid_t, GtkStatusStack *);
+
/* Indique si le format peut être pris en charge ici. */
FormatMatchStatus python_plugin_is_matching(GBinContent *, GExeFormat *, GPythonPlugin *, char **);
@@ -285,6 +288,27 @@ GPluginModule *g_python_plugin_new(const char *modname, const char *filename)
switch (sub)
{
+ case DPS_CONTENT:
+
+ switch (action)
+ {
+ case PGA_CONTENT_EXPLORER:
+ case PGA_CONTENT_RESOLVER:
+ if (!register_python_binding(instance, handle_content, \
+ (pg_handle_content)g_python_plugin_handle_binary_content))
+ goto gppn_bad_plugin;
+ break;
+
+ default:
+ log_variadic_message(LMT_WARNING,
+ _("Unknown action '0x%02x' in plugin '%s'..."),
+ action, filename);
+ break;
+
+ }
+
+ break;
+
case DPS_FORMAT:
switch (action)
@@ -439,7 +463,7 @@ static bool g_python_plugin_read_interface(GPythonPlugin *plugin)
{
action = PyList_GET_ITEM(tuple, i);
- interface.actions[i] = PyLong_AsLong(action);
+ interface.actions[i] = PyLong_AsUnsignedLong(action);
}
@@ -543,6 +567,42 @@ static bool g_python_plugin_do_exit(GPythonPlugin *plugin, GObject *ref)
/******************************************************************************
* *
+* Paramètres : plugin = greffon à manipuler. *
+* action = type d'action attendue. *
+* content = contenu binaire à traiter. *
+* gid = identifiant du groupe de traitement. *
+* status = barre de statut à tenir informée. *
+* *
+* Description : Procède à une opération liée à un contenu binaire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_python_plugin_handle_binary_content(const GPythonPlugin *plugin, PluginAction action, GBinContent *content, gid_t gid, GtkStatusStack *status)
+{
+ PyObject *args; /* Arguments pour l'appel */
+ PyObject *value; /* Valeurs obtenues */
+
+ args = PyTuple_New(4);
+
+ PyTuple_SetItem(args, 0, PyLong_FromUnsignedLong(action));
+ PyTuple_SetItem(args, 1, pygobject_new(G_OBJECT(content)));
+ PyTuple_SetItem(args, 2, PyLong_FromUnsignedLong(gid));
+ PyTuple_SetItem(args, 3, pygobject_new(G_OBJECT(status)));
+
+ value = run_python_method(plugin->instance, "handle_binary_content", args);
+
+ Py_XDECREF(value);
+ Py_DECREF(args);
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : content = contenu binaire à parcourir. *
* parent = éventuel format exécutable déjà chargé. *
* plugin = grefon C interne représentant le grefon Python. *
@@ -678,7 +738,7 @@ static void g_python_plugin_process_disass(const GPythonPlugin *plugin, PluginAc
args = PyTuple_New(2);
- PyTuple_SetItem(args, 0, PyLong_FromLong(action));
+ PyTuple_SetItem(args, 0, PyLong_FromUnsignedLong(action));
PyTuple_SetItem(args, 1, pygobject_new(G_OBJECT(binary)));
value = run_python_method(plugin->instance, "process_binary_disassembly", args);
@@ -716,6 +776,8 @@ static bool py_plugin_module_define_constants(PyTypeObject *obj_type)
result &= PyDict_AddIntMacro(obj_type, PGA_BASIC_NONE);
result &= PyDict_AddIntMacro(obj_type, PGA_PLUGIN_INIT);
result &= PyDict_AddIntMacro(obj_type, PGA_PLUGIN_EXIT);
+ result &= PyDict_AddIntMacro(obj_type, PGA_CONTENT_EXPLORER);
+ result &= PyDict_AddIntMacro(obj_type, PGA_CONTENT_RESOLVER);
result &= PyDict_AddIntMacro(obj_type, PGA_FORMAT_MATCHER);
result &= PyDict_AddIntMacro(obj_type, PGA_FORMAT_LOADER_LAST);
result &= PyDict_AddIntMacro(obj_type, PGA_DISASSEMBLY_STARTED);