diff options
Diffstat (limited to 'plugins/elf/dynamic.c')
-rw-r--r-- | plugins/elf/dynamic.c | 85 |
1 files changed, 79 insertions, 6 deletions
diff --git a/plugins/elf/dynamic.c b/plugins/elf/dynamic.c index f1d5e02..9d211e6 100644 --- a/plugins/elf/dynamic.c +++ b/plugins/elf/dynamic.c @@ -24,6 +24,9 @@ #include "dynamic.h" +#include <assert.h> + + #include "elf-int.h" #include "program.h" @@ -71,10 +74,80 @@ bool find_elf_dynamic_program_header(const GElfFormat *format, elf_phdr *dynamic * * * Paramètres : format = informations chargées à consulter. * * dynamic = programme de type PT_DYNAMIC. * +* index = indice de l'élément recherché. * +* item = élément retrouvé dans la section. [OUT] * +* * +* Description : Retrouve un élément dans la section dynamique par son indice.* +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool _find_elf_dynamic_item_by_index(const GElfFormat *format, const elf_phdr *dynamic, size_t index, elf_dyn *item) +{ + bool result; /* Bilan à retourner */ + size_t max; /* Nombre d'entités présentes */ + phys_t pos; /* Position de lecture */ + + max = ELF_PHDR(format, *dynamic, p_filesz) / ELF_SIZEOF_DYN(format); + + assert(index < max); + + if (index < max) + { + pos = ELF_PHDR(format, *dynamic, p_offset) + index * ELF_SIZEOF_DYN(format); + + result = read_elf_dynamic_entry(format, pos, item); + + } + + else + result = false; + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : format = informations chargées à consulter. * +* index = indice de l'élément recherché. * +* item = élément retrouvé dans la section. [OUT] * +* * +* Description : Retrouve un élément dans la section dynamique par son indice.* +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool find_elf_dynamic_item_by_index(const GElfFormat *format, size_t index, elf_dyn *item) +{ + bool result; /* Bilan à retourner */ + elf_phdr dynamic; /* En-tête de programme DYNAMIC*/ + + result = find_elf_dynamic_program_header(format, &dynamic); + + if (result) + result = _find_elf_dynamic_item_by_index(format, &dynamic, index, item); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : format = informations chargées à consulter. * +* dynamic = programme de type PT_DYNAMIC. * * type = sorte d'élément recherché. * * item = élément retrouvé dans la section. [OUT] * * * -* Description : Retrouve un élément donné dans la section dynamique. * +* Description : Retrouve un élément dans la section dynamique par son type. * * * * Retour : Bilan de l'opération. * * * @@ -82,7 +155,7 @@ bool find_elf_dynamic_program_header(const GElfFormat *format, elf_phdr *dynamic * * ******************************************************************************/ -bool find_elf_dynamic_item_from_pheader(const GElfFormat *format, const elf_phdr *dynamic, int64_t type, elf_dyn *item) +bool _find_elf_dynamic_item_by_type(const GElfFormat *format, const elf_phdr *dynamic, int64_t type, elf_dyn *item) { bool result; /* Bilan à retourner */ off_t max; /* Nombre d'entités présentes */ @@ -115,7 +188,7 @@ bool find_elf_dynamic_item_from_pheader(const GElfFormat *format, const elf_phdr * type = sorte d'élément recherché. * * item = élément retrouvé dans la section. [OUT] * * * -* Description : Retrouve rapidement un élément dans la section dynamique. * +* Description : Retrouve un élément dans la section dynamique par son type. * * * * Retour : Bilan de l'opération. * * * @@ -123,7 +196,7 @@ bool find_elf_dynamic_item_from_pheader(const GElfFormat *format, const elf_phdr * * ******************************************************************************/ -bool find_elf_dynamic_item(const GElfFormat *format, int64_t type, elf_dyn *item) +bool find_elf_dynamic_item_by_type(const GElfFormat *format, int64_t type, elf_dyn *item) { bool result; /* Bilan à retourner */ elf_phdr dynamic; /* En-tête de programme DYNAMIC*/ @@ -131,7 +204,7 @@ bool find_elf_dynamic_item(const GElfFormat *format, int64_t type, elf_dyn *item result = find_elf_dynamic_program_header(format, &dynamic); if (result) - result = find_elf_dynamic_item_from_pheader(format, &dynamic, type, item); + result = _find_elf_dynamic_item_by_type(format, &dynamic, type, item); return result; @@ -262,7 +335,7 @@ bool resolve_plt_using_got(GElfFormat *format, virt_t *virt) if (!find_elf_program_by_type(format, PT_DYNAMIC, &dynamic)) goto rpug_exit; - if (!find_elf_dynamic_item_from_pheader(format, &dynamic, DT_PLTGOT, &pltgot)) + if (!_find_elf_dynamic_item_by_type(format, &dynamic, DT_PLTGOT, &pltgot)) goto rpug_exit; got_virt = ELF_DYN(format, pltgot, d_un.d_ptr); |