Пример #1
0
char *
symbol_name(struct elf_file *file, Elf32_Sym *symbol)
{
        char *name = string_entry(file, file->string_table, symbol->st_name);
        if (symbol->st_shndx == SHN_COMMON) {
                return name;
        }
        if (*name == '\0') {
                Elf32_Shdr *section = section_header(file, symbol->st_shndx);
                name = string_entry(file, file->sh_string_table, section->sh_name);
        }

        return name;
}
Пример #2
0
void
dump_relocations(struct elf_file *file, Elf32_Shdr *header)
{
        char *name = string_entry(file, file->sh_string_table, header->sh_name);
        if (header->sh_type != SHT_REL) {
                fprintf(stderr, "%s is not a relocation section\n", name);
                return;
        }
        char *type_name = "unknown";
        if (header->sh_type == SHT_REL) type_name = "SHT_REL";
        if (header->sh_type == SHT_RELA) type_name = "SHT_RELA";

        printf("\nRelocation section: %s [%s]\n", name, type_name);

        if (header->sh_entsize != sizeof(Elf32_Rel)) {
                fprintf(stderr, "table entry size (%d) is not sizeof(Elf32_Rel) [%zu]\n",
                        header->sh_entsize, sizeof(Elf32_Rel));
                return;
        }
        if (header->sh_size % header->sh_entsize) {
                fprintf(stderr, "section size is not a multiple of entrysize (%d/%d)\n",
                        header->sh_size, header->sh_entsize);
                return;
        }

        size_t entry_count = header->sh_size / header->sh_entsize;
        Elf32_Sym *symbols = (Elf32_Sym *)(file->file_data + file->symbol_table->sh_offset);
        Elf32_Rel *relocations = (Elf32_Rel *)(file->file_data + header->sh_offset);
        size_t idx;
        printf("Idx   Name                     value    size offset   section          type\n");
        for (idx = 0; idx < entry_count; idx++) {
                Elf32_Rel *entry = relocations + idx;
                Elf32_Sym *symbol = symbols + ELF32_R_SYM(entry->r_info);

                printf("%4.4zu: %-24s %8.8X %4.4X %6X   %-16s %s\n", idx,
                       symbol_name(file, symbol), symbol->st_value,
                       symbol->st_size, entry->r_offset,
                       section_name(file, section_header(file, symbol->st_shndx)),
                       relocation_type(ELF32_R_TYPE(entry->r_info)));
        }
}
 /** method to add valid string entries - can be called for
  *  OT_String */
 void AddValidStringSetting(const std::string value,
                            const std::string description)
 {
   DBG_ASSERT(type_ == OT_String);
   valid_strings_.push_back(string_entry(value, description));
 }
Пример #4
0
char *
section_name(struct elf_file *file, Elf32_Shdr *header)
{
        return string_entry(file, file->sh_string_table, header->sh_name);
}