summaryrefslogtreecommitdiff
path: root/src/format/elf
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2015-04-26 10:34:20 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2015-04-26 10:34:20 (GMT)
commit60f7839e36d0eaf5bcc90ffe1369dae56ed53dbe (patch)
tree752ad498b9704951eb1912f77ab42c6b5ac9f475 /src/format/elf
parentee0ff01247738e847ae3faa44dcb5168d7b758ba (diff)
Loaded internal smybols ; created entry points only when needed.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@520 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/format/elf')
-rw-r--r--src/format/elf/symbols.c103
1 files changed, 57 insertions, 46 deletions
diff --git a/src/format/elf/symbols.c b/src/format/elf/symbols.c
index b57c601..4c1811f 100644
--- a/src/format/elf/symbols.c
+++ b/src/format/elf/symbols.c
@@ -93,7 +93,7 @@ static bool load_elf_external_symbols(GElfFormat *, const elf_shdr *);
-#include <stdlib.h>
+
/******************************************************************************
* *
@@ -116,18 +116,10 @@ bool load_elf_symbols(GElfFormat *format)
result = true;
+ /* Symboles internes */
+ result &= load_elf_internal_symbols(format);
- result &= load_all_elf_basic_entry_points(format);
-
-
-
-
-
- /* Symboles internes */
-#if 0
- result = load_elf_internal_symbols(format);
-#endif
@@ -149,34 +141,9 @@ bool load_elf_symbols(GElfFormat *format)
- qsort(G_BIN_FORMAT(format)->symbols, G_BIN_FORMAT(format)->symbols_count,
- sizeof(GBinSymbol *), (__compar_fn_t)g_binary_symbol_cmp);
+ /* Symboles d'entrée, si encore besoin */
-#if 0
-
- const vmpa2t *saddr; /* Adresse de symbole */
- size_t i; /* Boucle de parcours #2 */
- GBinSymbol **symbols; /* Symboles à représenter */
-
- symbols = G_BIN_FORMAT(format)->symbols;
-
- for (i = 0; i < G_BIN_FORMAT(format)->symbols_count; i++)
- {
- saddr = get_mrange_addr(g_binary_symbol_get_range(symbols[i]));
- if (saddr == NULL) continue;
-
- //if (g_binary_symbol_to_string(symbols[i]) == NULL) continue;
-
- printf(" <symbol % 2zu> '% 22s'-> 0x%08lx 0x%08lx\n",
- i,
- g_binary_symbol_to_string(symbols[i]),
- saddr->physical,
- saddr->virtual);
-
- }
-
- //exit(0);
-#endif
+ result &= load_all_elf_basic_entry_points(format);
return result;
@@ -220,13 +187,31 @@ static void register_elf_entry_point(GElfFormat *format, virt_t vaddr, phys_t le
init_vmpa(&addr, VMPA_NO_PHYSICAL, vaddr);
- init_mrange(&range, &addr, len);
+ if (g_binary_format_find_symbol_at(format, &addr, &symbol))
+ {
+ g_object_unref(G_OBJECT(routine));
+
+ routine = g_binary_symbol_get_routine(symbol);
+ g_object_ref(G_OBJECT(routine));
+
+ printf(" -- SYM CHANGE @ 0x%08x\n", vaddr);
- g_binary_routine_set_range(routine, &range);
+ _g_binary_symbol_attach_routine(symbol, routine, STP_ENTRY_POINT);
+
+ }
+ else
+ {
+ printf(" -- SYM ENTRY @ 0x%08x\n", vaddr);
- symbol = g_binary_symbol_new(STP_ENTRY_POINT, "XXX", ~0);
- g_binary_symbol_attach_routine(symbol, routine);
- g_binary_format_add_symbol(base, symbol);
+ init_mrange(&range, &addr, len);
+
+ g_binary_routine_set_range(routine, &range);
+
+ symbol = g_binary_symbol_new(STP_ENTRY_POINT, "XXX", ~0);
+ g_binary_symbol_attach_routine(symbol, routine);
+ g_binary_format_add_symbol(base, symbol);
+
+ }
}
@@ -530,6 +515,7 @@ static bool load_elf_internal_symbols(GElfFormat *format)
off_t size; /* Taille de cette même zone */
off_t iter; /* Boucle de parcours */
elf_sym sym; /* Symbole aux infos visées */
+ virt_t virt; /* Adresse virtuelle */
vmpa2t addr; /* Localisation d'une routine */
mrange_t range; /* Couverture mémoire associée */
const char *name; /* Nom du symbole trouvé */
@@ -546,6 +532,21 @@ static bool load_elf_internal_symbols(GElfFormat *format)
result = read_elf_symbol(format, &iter, &sym);
if (!result) break;
+ /* On rejette les symboles qui ne sont pas définis au sein du binaire */
+ if (ELF_SYM(format, sym, st_shndx) == 0) continue;
+
+#if 0
+
+ Elf64_Word st_name; /* Symbol name (string tbl index) */
+ unsigned char st_info; /* Symbol type and binding */
+ unsigned char st_other; /* Symbol visibility */
+ Elf64_Section st_shndx; /* Section index */
+ Elf64_Addr st_value; /* Symbol value */
+ Elf64_Xword st_size; /* Symbol size */
+
+#endif
+
+
if (ELF_SYM(format, sym, st_value) == 0) continue;
/* Résolution précise d'adresse */
@@ -553,10 +554,20 @@ static bool load_elf_internal_symbols(GElfFormat *format)
/* TODO */
- init_vmpa(&addr, ELF_SYM(format, sym, st_value), VMPA_NO_VIRTUAL);
+ //init_vmpa(&addr, VMPA_NO_PHYSICAL, ELF_SYM(format, sym, st_value));
+
+ virt = ELF_SYM(format, sym, st_value);
+
+ if (ELF_HDR(format, format->header, e_machine) == EM_ARM)
+ virt &= ~0x1;
+
+ if (!g_exe_format_translate_address_into_vmpa(G_EXE_FORMAT(format), virt, &addr))
+ continue;
+
- init_mrange(&range, &addr, ELF_SYM(format, sym, st_size));
+ //init_mrange(&range, &addr, ELF_SYM(format, sym, st_size));
+ init_mrange(&range, &addr, 0);
/* Première ébauche de nom */
@@ -609,7 +620,7 @@ static bool load_elf_internal_symbols(GElfFormat *format)
/* Routine */
- printf("ADDING>> '%s'\n", name);
+ printf("SYM ADDING>> '%s'\n", name);
routine = try_to_demangle_routine(name);