From f76219d3d4ede4045263adc20c9922ad09b469e5 Mon Sep 17 00:00:00 2001 From: Gregory Date: Wed, 5 Jun 2019 00:18:10 +0300 Subject: [PATCH] partially print section table names --- src/main.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/main.c b/src/main.c index f671a75..c44f357 100644 --- a/src/main.c +++ b/src/main.c @@ -2,6 +2,7 @@ #include #include #include +#include int main(int argc, char **argv) { @@ -23,20 +24,38 @@ int main(int argc, char **argv) ft_putstr("not a regular file\n"); return (1); } - Elf64_Ehdr elf_header; - read(fd, &elf_header, sizeof(Elf64_Ehdr)); - if (elf_header.e_ident[EI_MAG0] != ELFMAG0 || - elf_header.e_ident[EI_MAG1] != ELFMAG1 || - elf_header.e_ident[EI_MAG2] != ELFMAG2) + char *file; + file = malloc(stat_buff.st_size); + read(fd, file, stat_buff.st_size); + Elf64_Ehdr *elf_header; + + elf_header = (Elf64_Ehdr *)file; + if (elf_header->e_ident[EI_MAG0] != ELFMAG0 || + elf_header->e_ident[EI_MAG1] != ELFMAG1 || + elf_header->e_ident[EI_MAG2] != ELFMAG2) { ft_putstr("not a valid magic number for elf binary file\n"); return (1); } - if (elf_header.e_ident[EI_CLASS] != ELFCLASS64) + if (elf_header->e_ident[EI_CLASS] != ELFCLASS64) { ft_putstr("sorry, only 64bit elf binaries for now"); return (1); } + Elf64_Shdr *section_array; + Elf64_Shdr *strings_table; + + section_array = (Elf64_Shdr *)(file + elf_header->e_shoff); + strings_table = section_array + elf_header->e_shstrndx; + char *string; + int i = 1; + while (i < elf_header->e_shnum) + { + section_array = section_array + i; + string = (char *)(file + strings_table->sh_offset + section_array->sh_name); + printf("entity name: %s\n", string); + i++; + } ft_putstr("symbol table\n"); return(0); }