ELF 解析符号包,包含symtab 和dynsym,并未对所以平台支持
/*
* ParseDynSymTable.c
*
* Created on: 2014年7月19日
* Author: angel-toms
*/
#include "ElfParser.h"
Elf32_Sym* get_elf_section_of_sym_table(MemMapping* mem,Elf32_Ehdr* pHeader,Elf32_Shdr* pSheader){
Elf32_Sym* pSymMem = NULL;
u1* shStringTableMem = NULL;
u4 i = 0;
shStringTableMem = get_elf_section_of_shstr_table(mem,pHeader,pSheader);
if(NULL == shStringTableMem){
printf("Error,get elf section header string table failed !\n");
goto Exit;
}
for( ; i < pHeader->e_shnum ; i++){
if(pSheader[i].sh_type == SHT_SYMTAB && strcmp((const char*)(shStringTableMem + pSheader[i].sh_name),".symtab") == 0){
pSymMem = calloc(1,pSheader[i].sh_size);
if(NULL == pSymMem){
perror("Error,calloc elf sym table failed");
goto Exit;
}
memcpy(pSymMem,(mem->base + pSheader[i].sh_offset),pSheader[i].sh_size);
break;
}
continue;
}
Exit:
if(shStringTableMem)
free(shStringTableMem);
return pSymMem;
}
Elf32_Sym* get_elf_section_of_dynsym_table(MemMapping* mem,Elf32_Ehdr* pHeader,Elf32_Shdr* pSheader){
Elf32_Sym* pDynmMem = NULL;
u1* shStringTableMem = NULL;
u4 i = 0;
shStringTableMem = get_elf_section_of_shstr_table(mem,pHeader,pSheader);
if(NULL == shStringTableMem){
printf("Error,get elf section header string table failed !\n");
goto Exit;
}
for( ; i < pHeader->e_shnum ; i++){
if(pSheader[i].sh_type == SHT_SYMTAB && strcmp((const char*)(shStringTableMem + pSheader[i].sh_name),".symtab") == 0){
pDynmMem = calloc(1,pSheader[i].sh_size);
if(NULL == pDynmMem){
perror("Error,calloc elf dyn sym section failed");
goto Exit;
}
memcpy(pDynmMem,(mem->base + pSheader[i].sh_offset),pSheader[i].sh_size);
break;
}
continue;
}
Exit:
if(shStringTableMem)
free(shStringTableMem);
return pDynmMem;
}
void print_elf_section_of_sym_table(MemMapping* mem,Elf32_Ehdr* pHeader,Elf32_Shdr* pSheader){
Elf32_Sym* pSymMem = NULL;
u1* shStringTableMem = NULL;
u4 i = 0;
u4 size = 0;
L