diff options
Diffstat (limited to 'src/format/elf/symbols.c')
-rw-r--r-- | src/format/elf/symbols.c | 81 |
1 files changed, 36 insertions, 45 deletions
diff --git a/src/format/elf/symbols.c b/src/format/elf/symbols.c index 1fa3d0e..04c584d 100644 --- a/src/format/elf/symbols.c +++ b/src/format/elf/symbols.c @@ -188,15 +188,11 @@ static void register_elf_entry_point(GElfFormat *format, virt_t vaddr, phys_t le routine = g_binary_symbol_get_routine(symbol); g_object_ref(G_OBJECT(routine)); - printf(" -- SYM CHANGE @ 0x%08x\n", vaddr); - _g_binary_symbol_attach_routine(symbol, routine, STP_ENTRY_POINT); } else { - printf(" -- SYM ENTRY @ 0x%08x\n", vaddr); - init_mrange(&range, &addr, len); g_binary_routine_set_range(routine, &range); @@ -229,10 +225,10 @@ static bool load_all_elf_basic_entry_points(GElfFormat *format) elf_phdr dynamic; /* En-tête de programme DYNAMIC*/ elf_dyn item_a; /* Premier élément DYNAMIC */ elf_dyn item_b; /* Second élément DYNAMIC */ - const bin_t *content; /* Contenu binaire à lire */ - off_t length; /* Taille totale du contenu */ + const GBinContent *content; /* Contenu binaire à lire */ + phys_t length; /* Taille totale du contenu */ bool status; /* Bilan d'une opération */ - off_t pos; /* Tête de lecture courante */ + vmpa2t pos; /* Tête de lecture courante */ uint32_t virt_32; /* Adresse virtuelle sur 32b */ uint64_t virt_64; /* Adresse virtuelle sur 64b */ @@ -285,26 +281,24 @@ static bool load_all_elf_basic_entry_points(GElfFormat *format) assert(sizeof(fullname) >= (strlen(prefix) + sizeof(XSTR(UINT64_MAX) + 1))); content = G_BIN_FORMAT(fmt)->content; - length = G_BIN_FORMAT(fmt)->length; - status = g_exe_format_translate_address_into_offset(G_EXE_FORMAT(format), - ELF_DYN(fmt, *ar, d_un.d_val), - &pos); + status = g_exe_format_translate_address_into_vmpa(G_EXE_FORMAT(format), + ELF_DYN(fmt, *ar, d_un.d_val), + &pos); if (!status) return; - if ((pos + ELF_DYN(fmt, *sz, d_un.d_val)) < length) - length = pos + ELF_DYN(fmt, *sz, d_un.d_val); + length = get_phy_addr(&pos) + ELF_DYN(fmt, *sz, d_un.d_val); - for (i = 0; pos < length; i++) + for (i = 0; get_phy_addr(&pos) < length; i++) { if (fmt->is_32b) { - status = read_u32(&virt_32, content, &pos, length, fmt->endian); + status = g_binary_content_read_u32(content, &pos, fmt->endian, &virt_32); ep = virt_32; } else { - status = read_u64(&virt_64, content, &pos, length, fmt->endian); + status = g_binary_content_read_u64(content, &pos, fmt->endian, &virt_64); ep = virt_64; } @@ -354,31 +348,30 @@ static bool load_all_elf_basic_entry_points(GElfFormat *format) if (find_elf_dynamic_item_from_pheader(format, &dynamic, DT_PLTGOT, &item_a)) { - status = g_exe_format_translate_address_into_offset(G_EXE_FORMAT(format), - ELF_DYN(format, item_a, d_un.d_val), - &pos); + status = g_exe_format_translate_address_into_vmpa(G_EXE_FORMAT(format), + ELF_DYN(format, item_a, d_un.d_val), + &pos); if (status) { content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; /* On saute le premier élément... */ if (format->is_32b) - status = read_u32(&virt_32, content, &pos, length, format->endian); + status = g_binary_content_read_u32(content, &pos, format->endian, &virt_32); else - status = read_u64(&virt_64, content, &pos, length, format->endian); + status = g_binary_content_read_u64(content, &pos, format->endian, &virt_64); while (1) { if (format->is_32b) { - status = read_u32(&virt_32, content, &pos, length, format->endian); + status = g_binary_content_read_u32(content, &pos, format->endian, &virt_32); ep = virt_32; } else { - status = read_u64(&virt_64, content, &pos, length, format->endian); + status = g_binary_content_read_u64(content, &pos, format->endian, &virt_64); ep = virt_64; } @@ -428,9 +421,9 @@ static bool load_all_elf_basic_entry_points(GElfFormat *format) bool get_elf_symbol_by_index(GElfFormat *format, const elf_shdr *sym, off_t index, elf_sym *symbol) { - off_t sym_start; /* Début de section */ - off_t sym_size; /* Taille de section */ - off_t offset; /* Emplacement à venir lire */ + phys_t sym_start; /* Début de section */ + phys_t sym_size; /* Taille de section */ + phys_t offset; /* Emplacement à venir lire */ get_elf_section_content(format, sym, &sym_start, &sym_size, NULL); @@ -505,9 +498,9 @@ static bool load_elf_internal_symbols(GElfFormat *format) { elf_shdr strtab; /* Section .strtab trouvée */ bool has_strtab; /* Présence de cette section */ - off_t start; /* Début de la zone à traiter */ - off_t size; /* Taille de cette même zone */ - off_t iter; /* Boucle de parcours */ + phys_t start; /* Début de la zone à traiter */ + phys_t size; /* Taille de cette même zone */ + phys_t iter; /* Boucle de parcours */ elf_sym sym; /* Symbole aux infos visées */ virt_t virt; /* Adresse virtuelle */ vmpa2t addr; /* Localisation d'une routine */ @@ -682,50 +675,48 @@ static bool load_elf_internal_symbols(GElfFormat *format) static bool find_elf_dynamic_item(const GElfFormat *format, const elf_shdr *section, int32_t type, elf_dyn *item) { bool result; /* Bilan à retourner */ - const bin_t *content; /* Contenu binaire à lire */ - off_t length; /* Taille totale du contenu */ - off_t pos; /* Position de lecture */ - off_t tmp; /* Position écrasable */ + const GBinContent *content; /* Contenu binaire à lire */ + phys_t pos; /* Position de lecture */ + vmpa2t tmp; /* Position écrasable */ int32_t tag32; /* Type de l'entrée (32 bits) */ int64_t tag64; /* Type de l'entrée (64 bits) */ result = true; content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; for (pos = ELF_SHDR(format, *section, sh_offset); - pos < length/* FIXME !! + xploit */ && result; + result; pos += ELF_SIZEOF_DYN(format)) { - tmp = pos; + init_vmpa(&tmp, pos, VMPA_NO_VIRTUAL); if (format->is_32b) { - result = read_s32(&tag32, content, &tmp, length, format->endian); + result = g_binary_content_read_s32(content, &tmp, format->endian, &tag32); if (tag32 == type) break; } else { - result = read_s64(&tag64, content, &tmp, length, format->endian); + result = g_binary_content_read_s64(content, &tmp, format->endian, &tag64); if (tag64 == type) break; } } - result &= (pos < length); - if (result) { + init_vmpa(&tmp, pos, VMPA_NO_VIRTUAL); + if (format->is_32b) { - result = read_s32(&item->dyn32.d_tag, content, &pos, length, format->endian); - result &= read_s32(&item->dyn32.d_un.d_val, content, &pos, length, format->endian); + result = g_binary_content_read_s32(content, &tmp, format->endian, &item->dyn32.d_tag); + result &= g_binary_content_read_s32(content, &tmp, format->endian, &item->dyn32.d_un.d_val); } else { - result = read_s64(&item->dyn64.d_tag, content, &pos, length, format->endian); - result &= read_s64(&item->dyn64.d_un.d_val, content, &pos, length, format->endian); + result = g_binary_content_read_s64(content, &tmp, format->endian, &item->dyn64.d_tag); + result &= g_binary_content_read_s64(content, &tmp, format->endian, &item->dyn64.d_un.d_val); } } |