summaryrefslogtreecommitdiff
path: root/src/format/elf/elf.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/format/elf/elf.c')
-rw-r--r--src/format/elf/elf.c57
1 files changed, 51 insertions, 6 deletions
diff --git a/src/format/elf/elf.c b/src/format/elf/elf.c
index bf5a7a2..7f3af9f 100644
--- a/src/format/elf/elf.c
+++ b/src/format/elf/elf.c
@@ -75,31 +75,38 @@ static bool g_elf_format_translate_offset_into_vmpa(const GElfFormat *, phys_t,
/* Fournit l'emplacement correspondant à une position physique. */
static bool g_elf_format_translate_address_into_vmpa(const GElfFormat *, virt_t, vmpa2t *);
+/* Fournit l'emplacement d'une section donnée. */
+bool g_elf_format_get_section_range_by_name(const GElfFormat *, const char *, mrange_t *);
+
/******************************************************************************
* *
* Paramètres : content = contenu binaire à parcourir. *
+* parent = éventuel format exécutable déjà chargé. *
* *
* Description : Indique si le format peut être pris en charge ici. *
* *
-* Retour : true si la réponse est positive, false sinon. *
+* Retour : Désignation du format reconnu ou NULL si aucun. *
* *
* Remarques : - *
* *
******************************************************************************/
-bool elf_is_matching(GBinContent *content)
+const char *elf_is_matching(GBinContent *content, GExeFormat *parent)
{
- bool result; /* Bilan à faire connaître */
+ const char *result; /* Format détecté à renvoyer */
vmpa2t addr; /* Tête de lecture initiale */
+ bool status; /* Bilan des accès mémoire */
char magic[4]; /* Idenfiant standard */
init_vmpa(&addr, 0, VMPA_NO_VIRTUAL);
- result = g_binary_content_get_raw(content, &addr, 4, (bin_t *)magic);
+ status = g_binary_content_get_raw(content, &addr, 4, (bin_t *)magic);
+
+ status &= (memcmp(magic, "\x7f\x45\x4c\x46" /* .ELF */, 4) == 0);
- result &= (memcmp(magic, "\x7f\x45\x4c\x46" /* .ELF */, 4) == 0);
+ result = status ? "elf" : NULL;
return result;
@@ -137,6 +144,8 @@ static void g_elf_format_class_init(GElfFormatClass *klass)
exe->translate_phys = (translate_phys_fc)g_elf_format_translate_offset_into_vmpa;
exe->translate_virt = (translate_virt_fc)g_elf_format_translate_address_into_vmpa;
+ exe->get_range_by_name = (get_range_by_name_fc)g_elf_format_get_section_range_by_name;
+
}
@@ -205,6 +214,7 @@ static void g_elf_format_finalize(GElfFormat *format)
/******************************************************************************
* *
* Paramètres : content = contenu binaire à parcourir. *
+* parent = éventuel format exécutable déjà chargé. *
* *
* Description : Prend en charge un nouveau format ELF. *
* *
@@ -214,7 +224,7 @@ static void g_elf_format_finalize(GElfFormat *format)
* *
******************************************************************************/
-GBinFormat *g_elf_format_new(GBinContent *content)
+GBinFormat *g_elf_format_new(GBinContent *content, GExeFormat *parent)
{
GElfFormat *result; /* Structure à retourner */
@@ -502,6 +512,41 @@ static bool g_elf_format_translate_address_into_vmpa(const GElfFormat *format, v
/******************************************************************************
* *
+* Paramètres : format = description de l'exécutable à consulter. *
+* name = nom de la section recherchée. *
+* range = emplacement en mémoire à renseigner. [OUT] *
+* *
+* Description : Fournit l'emplacement d'une section donnée. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_elf_format_get_section_range_by_name(const GElfFormat *format, const char *name, mrange_t *range)
+{
+ bool result; /* Bilan à retourner */
+ phys_t offset; /* Position physique de section*/
+ phys_t size; /* Taille de la section trouvée*/
+ virt_t address; /* Adresse virtuelle de section*/
+ vmpa2t tmp; /* Adresse à initialiser */
+
+ result = find_elf_section_content_by_name(format, name, &offset, &size, &address);
+
+ if (result)
+ {
+ init_vmpa(&tmp, offset, address);
+ init_mrange(range, &tmp, size);
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : format = informations chargées à consulter. *
* *
* Description : Présente l'en-tête ELF du format chargé. *