diff options
Diffstat (limited to 'elfreader.c')
-rw-r--r-- | elfreader.c | 58 |
1 files changed, 35 insertions, 23 deletions
diff --git a/elfreader.c b/elfreader.c index b514da3..eb0edf7 100644 --- a/elfreader.c +++ b/elfreader.c @@ -347,6 +347,7 @@ Elf_Ehdr* elf_header( FILE *f, Elf_Ident *ident, int sysorder ) elf_ehdr_32( ret, (Elf32_Ehdr *)buf, byteorder ); ret->type = ELF_TYPE_32; ret->byteorder = byteorder; + PNL(); } else if ( class == ELF_TYPE_64 ) { PNL(); @@ -648,10 +649,17 @@ Elf_Shdr** elf_shdr( FILE *f, Elf_Ehdr *ehdr ) void section_info( Elf_Shdr* shdr, Elf_Shdr_strtab *strtab ) { printf("ELF SECTION HEADER:\n"); + if ( NULL == shdr || NULL == strtab ) + { + ENL(); + return; + } if ( strtab != NULL ) { char *s = NULL; s = strtab_name( strtab, shdr->sh_name); + //printf("sh_name,0x%x\n",shdr->sh_name); + //printf("offset,0x%x\n",strtab->offset+shdr->sh_name); if ( s != NULL ) { printf("NAME :%s\n", s); @@ -659,41 +667,45 @@ void section_info( Elf_Shdr* shdr, Elf_Shdr_strtab *strtab ) //s = NULL; } } - printf("TYPE : 0x%02x\n", shdr->sh_type); - printf("OFFSET: 0x%08x\n", shdr->sh_offset); + printf("NAME : 0x%08x ", shdr->sh_name); + printf("TYPE : 0x%02x ", shdr->sh_type); + printf("OFFSET: 0x%08x ", shdr->sh_offset); printf("SIZE : 0x%08x\n", shdr->sh_size); } -Elf_Shdr_strtab* strtab_search( FILE *f, Elf_Shdr **shdr ) +Elf_Shdr_strtab* strtab_search( FILE *f, Elf_Ehdr *ehdr, Elf_Shdr **shdr ) { + uint16_t strndx; + int i; + Elf_Shdr_strtab *ret = NULL; Elf_Shdr *iter = NULL; - if ( shdr == NULL ) + if ( NULL == shdr || NULL == *shdr || NULL == ehdr || NULL == f ) { return NULL; } - iter = shdr[0]; - while ( iter != NULL ) + strndx = ehdr->e_shstrndx; + if (strndx != 0) { - if ( iter->sh_type == SHT_STRTAB ) - { - ret = malloc( sizeof(Elf_Shdr_strtab) ); - ret->offset = iter->sh_offset; - ret->sz_tab = iter->sh_size; - ret->strtab = malloc(ret->sz_tab); - fseek( f, ret->offset, SEEK_SET ); - if ( fread( ret->strtab, 1, ret->sz_tab, f ) != ret->sz_tab ) - { - free( ret->strtab ); - free( ret ); - printf("Cannot read strtab\n"); - return NULL; - } - return ret; - } - iter++; + iter = shdr[strndx]; + } else + { + return NULL; + } + + ret = malloc( sizeof(Elf_Shdr_strtab) ); + ret->offset = iter->sh_offset; + ret->sz_tab = iter->sh_size; + ret->strtab = malloc(ret->sz_tab); + fseek( f, ret->offset, SEEK_SET ); + if ( fread( ret->strtab, 1, ret->sz_tab, f ) != ret->sz_tab ) + { + free( ret->strtab ); + free( ret ); + printf("Cannot read strtab\n"); + return NULL; } return ret; |