summaryrefslogtreecommitdiff
path: root/src/format/elf/program.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2010-04-05 19:11:16 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2010-04-05 19:11:16 (GMT)
commitc853ed6c88a82e2859033c4111b0edb0372bc570 (patch)
treefba98d186b6e80539c1e5aad9910316c0cb3725c /src/format/elf/program.c
parentb6fd6dc823615aaee8661e8e2365181c1ea1775f (diff)
Reorganized the ELF header (32 or 64 bits).
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@148 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/format/elf/program.c')
-rw-r--r--src/format/elf/program.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/format/elf/program.c b/src/format/elf/program.c
new file mode 100644
index 0000000..f55b7c7
--- /dev/null
+++ b/src/format/elf/program.c
@@ -0,0 +1,96 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * program.c - gestion des en-têtes de programme d'un ELF
+ *
+ * Copyright (C) 2010 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "program.h"
+
+
+#include "elf-int.h"
+
+
+
+/******************************************************************************
+* *
+* Paramètres : format = description de l'exécutable à consulter. *
+* index = indice de la section recherchée. *
+* program = ensemble d'informations à faire remonter. [OUT] *
+* *
+* Description : Recherche un programme donné au sein de binaire par indice. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool find_elf_program_by_index(const GElfFormat *format, uint16_t index, elf_phdr *program)
+{
+ off_t offset; /* Emplacement à venir lire */
+
+ if (index >= ELF_HDR(format, format->header, e_phnum)) return false;
+
+ offset = ELF_HDR(format, format->header, e_phoff)
+ + ELF_HDR(format, format->header, e_phentsize) * index;
+
+ return read_elf_program_header(format, &offset, program);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = description de l'exécutable à consulter. *
+* addr = adresse virtuelle à retrouver. *
+* pos = position correspondante. [OUT] *
+* *
+* Description : Fournit la position correspondant à une adresse virtuelle. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool translate_address_into_offset_using_elf_programs(const GElfFormat *format, vmpa_t addr, off_t *pos)
+{
+ bool result; /* Bilan à retourner */
+ uint16_t i; /* Boucle de parcours */
+ elf_phdr program; /* Programme à analyser */
+
+ result = false;
+
+ for (i = 0; i < ELF_HDR(format, format->header, e_phnum) && !result; i++)
+ {
+ find_elf_program_by_index(format, i, &program);
+
+ if (ELF_PHDR(format, program, p_vaddr) <= addr
+ && addr < (ELF_PHDR(format, program, p_vaddr) + ELF_PHDR(format, program, p_filesz)))
+ {
+ *pos = ELF_PHDR(format, program, p_offset) + addr - ELF_PHDR(format, program, p_vaddr);
+ result = true;
+ }
+
+ }
+
+ return result;
+
+}