summaryrefslogtreecommitdiff
path: root/plugins/elf
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2018-05-07 15:00:14 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2018-05-07 15:00:14 (GMT)
commit83da8ea946dc50941838ec8b3951108f5e16642e (patch)
tree06d30655b95e856f2def3da0fab24067271de8b0 /plugins/elf
parentc136e2c4c1ad02ea2e363fbe71ce54c6255793e2 (diff)
Described binary formats and improved their loading.
Diffstat (limited to 'plugins/elf')
-rw-r--r--plugins/elf/core.c17
-rw-r--r--plugins/elf/format.c60
-rw-r--r--plugins/elf/format.h4
-rw-r--r--plugins/elf/python/format.c15
4 files changed, 53 insertions, 43 deletions
diff --git a/plugins/elf/core.c b/plugins/elf/core.c
index 7486242..03d5964 100644
--- a/plugins/elf/core.c
+++ b/plugins/elf/core.c
@@ -54,13 +54,7 @@ G_MODULE_EXPORT bool chrysalide_plugin_init(GPluginModule *plugin)
{
bool result; /* Bilan à retourner */
- result = register_format_matcher(elf_is_matching, NULL);
-
- if (result)
- result = register_format_loader("elf", "Executable and Linkable Format", g_elf_format_new);
-
- if (result)
- result = add_format_elf_module_to_python_module();
+ result = add_format_elf_module_to_python_module();
return result;
@@ -85,19 +79,12 @@ G_MODULE_EXPORT bool chrysalide_plugin_init(GPluginModule *plugin)
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);
+ test = check_elf_format(content);
if (test)
{
diff --git a/plugins/elf/format.c b/plugins/elf/format.c
index 86682a2..9e29a11 100644
--- a/plugins/elf/format.c
+++ b/plugins/elf/format.c
@@ -63,6 +63,9 @@ static void g_elf_format_finalize(GElfFormat *);
/* Indique la désignation interne du format. */
static const char *g_elf_format_get_name(const GElfFormat *);
+/* Fournit une description humaine du format. */
+static const char *g_elf_format_get_description(const GElfFormat *);
+
/* Assure l'interprétation d'un format en différé. */
static bool g_elf_format_analyze(GElfFormat *, wgroup_id_t, GtkStatusStack *);
@@ -94,42 +97,28 @@ static bool g_elf_format_get_section_range_by_name(const GElfFormat *, const cha
/******************************************************************************
* *
-* 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] *
+* Paramètres : content = contenu binaire à traiter. *
* *
-* Description : Indique si le format peut être pris en charge ici. *
+* Description : Valide un contenu comme étant un format Elf. *
* *
-* Retour : Conclusion de haut niveau sur la reconnaissance effectuée. *
+* Retour : - *
* *
* Remarques : - *
* *
******************************************************************************/
-FormatMatchStatus elf_is_matching(GBinContent *content, GExeFormat *parent, void *unused, char **key)
+bool check_elf_format(const GBinContent *content)
{
- FormatMatchStatus result; /* Bilan à renvoyer */
+ bool result; /* Bilan à faire remonter */
vmpa2t addr; /* Tête de lecture initiale */
- bool status; /* Bilan des accès mémoire */
char magic[4]; /* Idenfiant standard */
- if (parent != NULL)
- return FMS_UNKNOWN;
-
init_vmpa(&addr, 0, VMPA_NO_VIRTUAL);
- status = g_binary_content_read_raw(content, &addr, 4, (bin_t *)magic);
+ result = g_binary_content_read_raw(content, &addr, 4, (bin_t *)magic);
- status &= (memcmp(magic, "\x7f\x45\x4c\x46" /* .ELF */, 4) == 0);
-
- if (status)
- {
- result = FMS_MATCHED;
- *key = strdup("elf");
- }
- else
- result = FMS_UNKNOWN;
+ if (result)
+ result = (memcmp(magic, "\x7f\x45\x4c\x46" /* .ELF */, 4) == 0);
return result;
@@ -166,6 +155,7 @@ 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->get_desc = (format_get_desc_fc)g_elf_format_get_description;
fmt->analyze = (format_analyze_fc)g_elf_format_analyze;
fmt->get_endian = (format_get_endian_fc)g_elf_format_get_endianness;
@@ -257,6 +247,9 @@ GExeFormat *g_elf_format_new(GBinContent *content)
{
GElfFormat *result; /* Structure à retourner */
+ if (!check_elf_format(content))
+ return NULL;
+
result = g_object_new(G_TYPE_ELF_FORMAT, NULL);
g_binary_format_set_content(G_BIN_FORMAT(result), content);
@@ -291,6 +284,29 @@ static const char *g_elf_format_get_name(const GElfFormat *format)
/******************************************************************************
* *
+* Paramètres : format = description de l'exécutable à consulter. *
+* *
+* Description : Fournit une description humaine du format. *
+* *
+* Retour : Description du format. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static const char *g_elf_format_get_description(const GElfFormat *format)
+{
+ const char *result; /* Désignation à retourner */
+
+ result = "Executable and Linkable Format";
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : format = format chargé dont l'analyse est lancée. *
* gid = groupe de travail dédié. *
* status = barre de statut à tenir informée. *
diff --git a/plugins/elf/format.h b/plugins/elf/format.h
index 47b3171..c97ed67 100644
--- a/plugins/elf/format.h
+++ b/plugins/elf/format.h
@@ -52,8 +52,8 @@ typedef struct _GElfFormat GElfFormat;
typedef struct _GElfFormatClass GElfFormatClass;
-/* Indique si le format peut être pris en charge ici. */
-FormatMatchStatus elf_is_matching(GBinContent *, GExeFormat *, void *, char **);
+/* Valide un contenu comme étant un format Elf. */
+bool check_elf_format(const GBinContent *);
/* Indique le type défini pour un format d'exécutable ELF. */
GType g_elf_format_get_type(void);
diff --git a/plugins/elf/python/format.c b/plugins/elf/python/format.c
index 0319ba9..87b590b 100644
--- a/plugins/elf/python/format.c
+++ b/plugins/elf/python/format.c
@@ -82,13 +82,20 @@ static PyObject *py_elf_format_new(PyTypeObject *type, PyObject *args, PyObject
content = G_BIN_CONTENT(pygobject_get(content_obj));
format = g_elf_format_new(content);
- assert(format != NULL);
- result = pygobject_new(G_OBJECT(format));
+ if (format == NULL)
+ {
+ result = Py_None;
+ Py_INCREF(result);
+ }
- g_object_unref(format);
+ else
+ {
+ result = pygobject_new(G_OBJECT(format));
+ g_object_unref(format);
+ }
- return (PyObject *)result;
+ return result;
}