summaryrefslogtreecommitdiff
path: root/src/format
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2015-09-19 22:28:42 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2015-09-19 22:28:42 (GMT)
commit0e3059731d9687027c913135b3b856596c49a689 (patch)
treed3c3754f95c90ae50168817e6248afee6873fbf3 /src/format
parent18648e4e8763a3bc005d6fae51eae3d1528d7d29 (diff)
Extended the prototype for matching formats in order to get it suitable for plugins.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@577 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/format')
-rw-r--r--src/format/dwarf/dwarf.c31
-rw-r--r--src/format/dwarf/dwarf.h4
-rw-r--r--src/format/elf/elf.c16
-rw-r--r--src/format/elf/elf.h5
-rw-r--r--src/format/executable-int.h3
-rw-r--r--src/format/executable.c78
-rw-r--r--src/format/executable.h9
7 files changed, 127 insertions, 19 deletions
diff --git a/src/format/dwarf/dwarf.c b/src/format/dwarf/dwarf.c
index db8335b..519aa49 100644
--- a/src/format/dwarf/dwarf.c
+++ b/src/format/dwarf/dwarf.c
@@ -47,18 +47,20 @@ static void g_dwarf_format_finalize(GDwarfFormat *);
* *
* 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 : Désignation du format reconnu ou NULL si aucun. *
+* Retour : Conclusion de haut niveau sur la reconnaissance effectuée. *
* *
* Remarques : - *
* *
******************************************************************************/
-const char *dwarf_is_matching(GBinContent *content, GExeFormat *parent)
+FormatMatchStatus dwarf_is_matching(GBinContent *content, GExeFormat *parent, void *unused, char **key)
{
- const char *result; /* Format détecté à renvoyer */
+ FormatMatchStatus result; /* Bilan à renvoyer */
size_t i; /* Boucle de parcours */
mrange_t range; /* Couverture d'une section */
dw_section_header header; /* En-tête DWARF de section */
@@ -114,10 +116,10 @@ const char *dwarf_is_matching(GBinContent *content, GExeFormat *parent)
0 /* .debug_types */
};
- result = NULL;
+ result = FMS_UNKNOWN;
if (parent == NULL)
- return NULL;
+ return FMS_UNKNOWN;
/* Lecture des indices présents */
@@ -159,23 +161,32 @@ const char *dwarf_is_matching(GBinContent *content, GExeFormat *parent)
found = check_dwarf_version(dwarf_v4_versions, current_versions, ARRAY_SIZE(section_names));
if (found)
- result = "dwarf_v4";
+ {
+ result = FMS_MATCHED;
+ *key = strdup("dwarf_v4");
+ }
- if (result == NULL)
+ if (result == FMS_UNKNOWN)
{
found = check_dwarf_version(dwarf_v3_versions, current_versions, ARRAY_SIZE(section_names));
if (found)
- result = "dwarf_v3";
+ {
+ result = FMS_MATCHED;
+ *key = strdup("dwarf_v3");
+ }
}
- if (result == NULL)
+ if (result == FMS_UNKNOWN)
{
found = check_dwarf_version(dwarf_v2_versions, current_versions, ARRAY_SIZE(section_names));
if (found)
- result = "dwarf_v2";
+ {
+ result = FMS_MATCHED;
+ *key = strdup("dwarf_v2");
+ }
}
diff --git a/src/format/dwarf/dwarf.h b/src/format/dwarf/dwarf.h
index a5e988b..da5b70a 100644
--- a/src/format/dwarf/dwarf.h
+++ b/src/format/dwarf/dwarf.h
@@ -25,7 +25,7 @@
#define _FORMAT_DWARF_DWARF_H
-#include "../executable.h"
+#include "../../core/formats.h"
@@ -45,7 +45,7 @@ typedef struct _GDwarfFormatClass GDwarfFormatClass;
/* Indique si le format peut être pris en charge ici. */
-const char *dwarf_is_matching(GBinContent *, GExeFormat *);
+FormatMatchStatus dwarf_is_matching(GBinContent *, GExeFormat *, void *, char **);
/* Indique le type défini pour un format de débogage DWARF. */
GType g_dwarf_format_get_type(void);
diff --git a/src/format/elf/elf.c b/src/format/elf/elf.c
index 5c81b2f..50df077 100644
--- a/src/format/elf/elf.c
+++ b/src/format/elf/elf.c
@@ -84,18 +84,20 @@ bool g_elf_format_get_section_range_by_name(const GElfFormat *, const char *, mr
* *
* 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 : Désignation du format reconnu ou NULL si aucun. *
+* Retour : Conclusion de haut niveau sur la reconnaissance effectuée. *
* *
* Remarques : - *
* *
******************************************************************************/
-const char *elf_is_matching(GBinContent *content, GExeFormat *parent)
+FormatMatchStatus elf_is_matching(GBinContent *content, GExeFormat *parent, void *unused, char **key)
{
- const char *result; /* Format détecté à renvoyer */
+ FormatMatchStatus result; /* Bilan à renvoyer */
vmpa2t addr; /* Tête de lecture initiale */
bool status; /* Bilan des accès mémoire */
char magic[4]; /* Idenfiant standard */
@@ -106,7 +108,13 @@ const char *elf_is_matching(GBinContent *content, GExeFormat *parent)
status &= (memcmp(magic, "\x7f\x45\x4c\x46" /* .ELF */, 4) == 0);
- result = status ? "elf" : NULL;
+ if (status)
+ {
+ result = FMS_MATCHED;
+ *key = strdup("elf");
+ }
+ else
+ result = FMS_UNKNOWN;
return result;
diff --git a/src/format/elf/elf.h b/src/format/elf/elf.h
index 8e9a2cc..a557927 100644
--- a/src/format/elf/elf.h
+++ b/src/format/elf/elf.h
@@ -31,8 +31,7 @@
#include "elf_def.h"
-#include "../executable.h"
-#include "../format.h"
+#include "../../core/formats.h"
@@ -51,7 +50,7 @@ typedef struct _GElfFormatClass GElfFormatClass;
/* Indique si le format peut être pris en charge ici. */
-const char *elf_is_matching(GBinContent *, GExeFormat *);
+FormatMatchStatus elf_is_matching(GBinContent *, GExeFormat *, void *, char **);
/* Indique le type défini pour un format d'exécutable ELF. */
GType g_elf_format_get_type(void);
diff --git a/src/format/executable-int.h b/src/format/executable-int.h
index 704466e..f5a25b5 100644
--- a/src/format/executable-int.h
+++ b/src/format/executable-int.h
@@ -62,6 +62,9 @@ struct _GExeFormat
{
GBinFormat parent; /* A laisser en premier */
+ GDbgFormat **debugs; /* Informations de débogage */
+ size_t debugs_count; /* Nombre de ces informations */
+
get_target_machine_fc get_machine; /* Architecture ciblée */
refine_portions_fc refine_portions; /* Décrit les portions binaires*/
diff --git a/src/format/executable.c b/src/format/executable.c
index aae182a..5ff773c 100644
--- a/src/format/executable.c
+++ b/src/format/executable.c
@@ -84,6 +84,84 @@ static void g_executable_format_init(GExeFormat *format)
+/******************************************************************************
+* *
+* Paramètres : format = informations chargées à compléter. *
+* info = informations de débogage à lier. *
+* *
+* Description : Rajoute des informations de débogage à un exécutable. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_exe_format_add_debug_info(GExeFormat *format, GDbgFormat *info)
+{
+ /* Ajout dans la liste */
+
+ format->debugs = (GDbgFormat **)realloc(format->debugs,
+ ++format->debugs_count * sizeof(GDbgFormat *));
+
+ format->debugs[format->debugs_count - 1] = info;
+
+ /* Intégration des symboles */
+
+ /* TODO */
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = informations chargées à consulter. *
+* *
+* Description : Compte le nombre de formats de débogage liés à l'exécutable. *
+* *
+* Retour : Nombre de formats de débogage attachés. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+size_t g_exe_format_count_debug_info(const GExeFormat *format)
+{
+ return format->debugs_count;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = informations chargées à consulter. *
+* index = indice des informations à transmettre. *
+* *
+* Description : Fournit un format de débogage attaché à l'exécutable. *
+* *
+* Retour : Informations de débogage attachées. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDbgFormat *g_exe_format_get_debug_info(const GExeFormat *format, size_t index)
+{
+ GDbgFormat *result; /* Format à retourner */
+
+ if (index >= format->debugs_count)
+ result = NULL;
+
+ else
+ {
+ result = format->debugs[index];
+ g_object_ref(G_OBJECT(result));
+ }
+
+ return result;
+
+}
+
diff --git a/src/format/executable.h b/src/format/executable.h
index 45c736b..48a8139 100644
--- a/src/format/executable.h
+++ b/src/format/executable.h
@@ -28,6 +28,7 @@
#include <glib-object.h>
+#include "debuggable.h"
#include "../glibext/gbinportion.h"
@@ -52,6 +53,14 @@ typedef struct _GExeFormatClass GExeFormatClass;
GType g_executable_format_get_type(void);
+/* Rajoute des informations de débogage à un exécutable. */
+void g_exe_format_add_debug_info(GExeFormat *, GDbgFormat *);
+
+/* Compte le nombre de formats de débogage liés à l'exécutable. */
+size_t g_exe_format_count_debug_info(const GExeFormat *);
+
+/* Fournit un format de débogage attaché à l'exécutable. */
+GDbgFormat *g_exe_format_get_debug_info(const GExeFormat *, size_t);
/* Indique le type d'architecture visée par le format. */