summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2017-03-31 17:50:08 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2017-03-31 17:50:08 (GMT)
commitebe248fe406de9565c8c7787187a1d439e68cd84 (patch)
tree8126ea63a5b753f549a90a107d6428db2b299ff2 /src
parent24096140aaa73db9e982db4437bc42a013812658 (diff)
Extracted strings from some extra ELF sections.
Diffstat (limited to 'src')
-rw-r--r--src/format/elf/elf.c5
-rw-r--r--src/format/elf/section.c60
-rw-r--r--src/format/elf/section.h6
-rw-r--r--src/format/elf/strings.c4
4 files changed, 71 insertions, 4 deletions
diff --git a/src/format/elf/elf.c b/src/format/elf/elf.c
index 0ad90ff..bc48eb5 100644
--- a/src/format/elf/elf.c
+++ b/src/format/elf/elf.c
@@ -411,6 +411,7 @@ static void g_elf_format_refine_portions(GElfFormat *format)
bool has_strings; /* Section trouvée ? */
elf_shdr shdr; /* En-tête de section ELF */
uint64_t sh_flags; /* Droits associés à une partie*/
+ mrange_t range; /* Emplacement d'une section */
const char *name; /* Nom trouvé ou NULL */
exe_format = G_EXE_FORMAT(format);
@@ -494,9 +495,9 @@ static void g_elf_format_refine_portions(GElfFormat *format)
else if (sh_flags & SHF_WRITE) background = BPC_DATA;
else background = BPC_DATA_RO;
- init_vmpa(&addr, ELF_SHDR(format, shdr, sh_offset), ELF_SHDR(format, shdr, sh_addr));
+ get_elf_section_range(format, &shdr, &range);
- new = g_binary_portion_new(background, &addr, ELF_SHDR(format, shdr, sh_size));
+ new = g_binary_portion_new(background, get_mrange_addr(&range), get_mrange_length(&range));
if (has_strings)
name = extract_name_from_elf_string_section(format, &strings,
diff --git a/src/format/elf/section.c b/src/format/elf/section.c
index 9583927..556c0ed 100644
--- a/src/format/elf/section.c
+++ b/src/format/elf/section.c
@@ -207,6 +207,37 @@ void get_elf_section_content(const GElfFormat *format, const elf_shdr *section,
/******************************************************************************
* *
* Paramètres : format = description de l'exécutable à consulter. *
+* section = section à consulter. *
+* range = emplacement de la fonction à renseigner. [OUT] *
+* *
+* Description : Fournit la localisation d'une section. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void get_elf_section_range(const GElfFormat *format, const elf_shdr *section, mrange_t *range)
+{
+ virt_t virt; /* Emplacement virtuel */
+ vmpa2t tmp; /* Enregistrement intermédiaire*/
+
+ virt = ELF_SHDR(format, *section, sh_addr);
+
+ if (virt == 0)
+ virt = VMPA_NO_VIRTUAL;
+
+ init_vmpa(&tmp, ELF_SHDR(format, *section, sh_offset), virt);
+
+ init_mrange(range, &tmp, ELF_SHDR(format, *section, sh_size));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = description de l'exécutable à consulter. *
* name = nom de la section recherchée. *
* offset = position de la section trouvée. [OUT] *
* size = taille de la section trouvée. [OUT] *
@@ -237,6 +268,35 @@ bool find_elf_section_content_by_name(const GElfFormat *format, const char *name
/******************************************************************************
* *
+* Paramètres : format = description de l'exécutable à consulter. *
+* name = nom de la section recherchée. *
+* range = emplacement de la fonction à renseigner. [OUT] *
+* *
+* Description : Recherche une zone donnée au sein de binaire par nom. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool find_elf_section_range_by_name(const GElfFormat *format, const char *name, mrange_t *range)
+{
+ bool result; /* Bilan à retourner */
+ elf_shdr section; /* Section trouvée ou non */
+
+ result = find_elf_section_by_name(format, name, &section);
+
+ if (result)
+ get_elf_section_range(format, &section, range);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : format = description de l'exécutable à consulter. *
* section = section contenant des chaînes terminées par '\0'. *
* index = indice du premier caractères à cerner. *
diff --git a/src/format/elf/section.h b/src/format/elf/section.h
index aed6f9e..f3be0f4 100644
--- a/src/format/elf/section.h
+++ b/src/format/elf/section.h
@@ -45,9 +45,15 @@ bool find_elf_sections_by_type(const GElfFormat *, uint32_t, elf_shdr **, size_t
/* Fournit les adresses et taille contenues dans une section. */
void get_elf_section_content(const GElfFormat *, const elf_shdr *, phys_t *, phys_t *, virt_t *);
+/* Fournit la localisation d'une section. */
+void get_elf_section_range(const GElfFormat *, const elf_shdr *, mrange_t *);
+
/* Recherche une zone donnée au sein de binaire par nom. */
bool find_elf_section_content_by_name(const GElfFormat *, const char *, phys_t *, phys_t *, virt_t *);
+/* Recherche une zone donnée au sein de binaire par nom. */
+bool find_elf_section_range_by_name(const GElfFormat *, const char *, mrange_t *);
+
/* Identifie une chaîne de caractères dans une section adéquate. */
const char *extract_name_from_elf_string_section(const GElfFormat *, const elf_shdr *, off_t);
diff --git a/src/format/elf/strings.c b/src/format/elf/strings.c
index 9bcb87f..8901db9 100644
--- a/src/format/elf/strings.c
+++ b/src/format/elf/strings.c
@@ -155,8 +155,8 @@ bool parse_elf_string_data(GElfFormat *format, phys_t start, phys_t size, virt_t
const bin_t *data; /* Contenu complet et original */
vmpa2t pos; /* Tête de lecture */
bool cut; /* Séparation nette ? */
- off_t i; /* Boucle de parcours */
- off_t end; /* Position de fin de chaîne */
+ phys_t i; /* Boucle de parcours */
+ phys_t end; /* Position de fin de chaîne */
GArchInstruction *instr; /* Instruction décodée */
GBinSymbol *symbol; /* Symbole à intégrer */
char *label; /* Désignation de la chaîne */