summaryrefslogtreecommitdiff
path: root/src/format
diff options
context:
space:
mode:
Diffstat (limited to 'src/format')
-rw-r--r--src/format/elf/Makefile.am3
-rw-r--r--src/format/elf/e_elf.c28
-rw-r--r--src/format/elf/elf-int.h1
-rw-r--r--src/format/elf/helper_mips.c85
-rw-r--r--src/format/elf/helper_mips.h41
-rw-r--r--src/format/elf/section.c5
-rw-r--r--src/format/elf/symbol.c65
7 files changed, 215 insertions, 13 deletions
diff --git a/src/format/elf/Makefile.am b/src/format/elf/Makefile.am
index ce23fb4..fa481ca 100644
--- a/src/format/elf/Makefile.am
+++ b/src/format/elf/Makefile.am
@@ -1,9 +1,10 @@
noinst_LTLIBRARIES = libformatelf.la
-libformatelf_la_SOURCES = \
+libformatelf_la_SOURCES = \
e_elf.h e_elf.c \
elf-int.h \
+ helper_mips.h helper_mips.c \
section.h section.c \
strings.h strings.c \
symbol.h symbol.c
diff --git a/src/format/elf/e_elf.c b/src/format/elf/e_elf.c
index 373df2b..1de4ac0 100644
--- a/src/format/elf/e_elf.c
+++ b/src/format/elf/e_elf.c
@@ -204,15 +204,15 @@ elf_format *load_elf(const uint8_t *content, off_t length)
test = read_elf_section_names(result);
- printf("ok ? %d\n", test);
+ printf("section names ok ? %d\n", test);
test = find_all_elf_strings(result);
- printf("ok ? %d\n", test);
+ printf("strings ok ? %d\n", test);
test = load_elf_symbols(result);
- printf("ok ? %d\n", test);
+ printf("symbols ok ? %d\n", test);
@@ -326,6 +326,18 @@ bin_part **get_elf_default_code_parts(const elf_format *format, size_t *count)
}
+ if (find_elf_section_content_by_name(format, ".MIPS.stubs", &offset, &size, &voffset))
+ {
+ part = create_bin_part();
+
+ set_bin_part_name(part, ".MIPS.stubs");
+ set_bin_part_values(part, offset, size, voffset);
+
+ result = (bin_part **)realloc(result, ++(*count) * sizeof(bin_part *));
+ result[*count - 1] = part;
+
+ }
+
if (find_elf_section_content_by_name(format, ".init", &offset, &size, &voffset))
{
part = create_bin_part();
@@ -583,16 +595,16 @@ GBinRoutine **get_all_elf_routines(const elf_format *format, size_t *count)
result = (GBinRoutine **)calloc(format->sym_count, sizeof(GBinRoutine *));
*count = format->sym_count;
- /*
+
for (i = 0; i < format->sym_count; i++)
{
- result[i] = create_binary_routine();
+ result[i] = g_binary_routine_new();
- set_binary_routine_offset(result[i], format->symbols[i].address);
- set_binary_routine_name(result[i], strdup(format->symbols[i].name));
+ g_binary_routine_set_address(result[i], format->symbols[i].address);
+ g_binary_routine_set_name(result[i], strdup(format->symbols[i].name));
}
- */
+
return result;
}
diff --git a/src/format/elf/elf-int.h b/src/format/elf/elf-int.h
index 4ee3a08..dd8909d 100644
--- a/src/format/elf/elf-int.h
+++ b/src/format/elf/elf-int.h
@@ -117,6 +117,7 @@ typedef union _Elf_Sym
#define ELF_SYM(fmt, sb, fld) (fmt->is_32b ? sb.sym32.fld : sb.sym64.fld)
+#define ELF_ST_TYPE ELF32_ST_TYPE
diff --git a/src/format/elf/helper_mips.c b/src/format/elf/helper_mips.c
new file mode 100644
index 0000000..b56db5d
--- /dev/null
+++ b/src/format/elf/helper_mips.c
@@ -0,0 +1,85 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * helper_mips.c - gestion auxiliaire de l'architecture MIPS
+ *
+ * Copyright (C) 2009 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 "helper_mips.h"
+
+
+#include <string.h>
+
+
+#include "elf-int.h"
+
+
+
+/******************************************************************************
+* *
+* Paramètres : format = description de l'exécutable à compléter. *
+* dyn_start = début des informations dynamiques associées. *
+* dyn_size = taille de la zone associée. *
+* str_start = début de la zone de chaîne de caractères. *
+* str_size = taille de la zone de chaînes de caractères. *
+* *
+* Description : Déduit les adresses effectives des appels externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_elf_format_find_mips_dynamic_symbols(elf_format *format, off_t dyn_start, off_t dyn_size, off_t str_start, off_t str_size)
+{
+ off_t iter; /* Boucle de parcours */
+ Elf_Sym symbol; /* Symbole ELF lu */
+ off_t name_pos; /* Localisation du nom */
+
+ if (dyn_size % ELF_SIZEOF_SYM(format) != 0) return false;
+
+ for (iter = dyn_start; iter < (dyn_start + dyn_size); iter += ELF_SIZEOF_SYM(format))
+ {
+ memcpy(&symbol, &EXE_FORMAT(format)->content[iter], ELF_SIZEOF_SYM(format));
+
+ if (ELF_ST_TYPE(ELF_SYM(format, symbol, st_info)) != STT_FUNC) continue;
+
+ if (ELF_SYM(format, symbol, st_value) == 0) continue;
+
+ name_pos = ELF_SYM(format, symbol, st_name);
+
+ /* Sécurité anti-débordements */
+ if (name_pos >= str_size) continue;
+
+ /* Si le symbole possède un nom... */
+ if (strlen(&EXE_FORMAT(format)->content[str_start + name_pos]) > 0)
+ {
+ format->symbols = (elf_symbol *)realloc(format->symbols, ++format->sym_count * sizeof(elf_symbol));
+
+ format->symbols[format->sym_count - 1].name = &EXE_FORMAT(format)->content[str_start + name_pos];
+ format->symbols[format->sym_count - 1].address = ELF_SYM(format, symbol, st_value);
+
+ }
+
+ }
+
+ return true;
+
+}
diff --git a/src/format/elf/helper_mips.h b/src/format/elf/helper_mips.h
new file mode 100644
index 0000000..6a26e03
--- /dev/null
+++ b/src/format/elf/helper_mips.h
@@ -0,0 +1,41 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * helper_mips.h - prototypes pour la gestion auxiliaire de l'architecture MIPS
+ *
+ * Copyright (C) 2009 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/>.
+ */
+
+
+#ifndef _FORMAT_ELF_HELPER_MIPS_H
+#define _FORMAT_ELF_HELPER_MIPS_H
+
+
+#include <stdbool.h>
+#include <sys/types.h>
+
+
+#include "e_elf.h"
+
+
+
+/* Déduit les adresses effectives des appels externes. */
+bool g_elf_format_find_mips_dynamic_symbols(elf_format *, off_t, off_t, off_t, off_t);
+
+
+
+#endif /* _FORMAT_ELF_HELPER_MIPS_H */
diff --git a/src/format/elf/section.c b/src/format/elf/section.c
index 7ad8363..c619293 100644
--- a/src/format/elf/section.c
+++ b/src/format/elf/section.c
@@ -50,11 +50,12 @@ bool read_elf_section_names(elf_format *format)
Elf32_Shdr section; /* Section visée */
offset = format->header.e_shoff + format->header.e_shentsize * format->header.e_shstrndx;
- if ((offset + sizeof(Elf32_Shdr)) >= EXE_FORMAT(format)->length) return false;
+
+ if ((offset + sizeof(Elf32_Shdr)) > EXE_FORMAT(format)->length) return false;
memcpy(&section, &EXE_FORMAT(format)->content[offset], sizeof(Elf32_Shdr));
- if ((section.sh_offset + section.sh_size) >= EXE_FORMAT(format)->length) return false;
+ if ((section.sh_offset + section.sh_size) > EXE_FORMAT(format)->length) return false;
format->sec_names = (char *)calloc(section.sh_size + 1, sizeof(char));
format->sec_size = section.sh_size;
diff --git a/src/format/elf/symbol.c b/src/format/elf/symbol.c
index fbb6fd8..eaf11a4 100644
--- a/src/format/elf/symbol.c
+++ b/src/format/elf/symbol.c
@@ -94,6 +94,10 @@ bool load_elf_symbols(elf_format *format)
off_t str_size; /* Taille de section */
off_t rel_start; /* Début de section */
off_t rel_size; /* Taille de section */
+
+
+ bool test; /* Bilan d'une recherche */
+
off_t dyn_start; /* Début de section */
off_t dyn_size; /* Taille de section */
@@ -133,7 +137,56 @@ bool load_elf_symbols(elf_format *format)
}
- /* Relocalisations dynamiques */
+ /* Liaison dynamique (si elle existe) */
+
+ test = find_elf_section_by_name(format, ".dynsym", &section);
+
+ if (!test)
+ {
+ test = find_elf_section_by_type(format, SHT_HASH, &sections, &count);
+
+ if (test)
+ test = find_elf_section_by_index(format, ELF_SHDR(format, &sections[0], sh_link), &section);
+
+ }
+
+ if (test)
+ {
+ get_elf_section_content(format, &section, &dyn_start, &dyn_size, NULL);
+
+ result &= find_elf_section_by_index(format, ELF_SHDR(format, &section, sh_link), &section);
+
+ }
+
+ if (result)
+ {
+ get_elf_section_content(format, &section, &str_start, &str_size, NULL);
+
+ switch (get_elf_target_machine(format))
+ {
+ case FTM_MIPS:
+ result = g_elf_format_find_mips_dynamic_symbols(format, dyn_start, dyn_size, str_start, str_size);
+ break;
+
+ default:
+ break;
+
+ }
+
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+#if 0
find_elf_section_by_type(format, SHT_REL, &sections, &count);
@@ -171,6 +224,14 @@ bool load_elf_symbols(elf_format *format)
/* Récupération (seconde partie) */
+
+ /* switch ... */
+
+ g_elf_format_translate_mips_external_calls(format);
+ exit(0);
+
+
+
if (result)
{
#if 0
@@ -182,7 +243,7 @@ bool load_elf_symbols(elf_format *format)
#endif
}
-
+#endif
return result;