解析 .dynamic 节,并不对所以平台支持
/*
* ParseAllDyna.c
*
* Created on: 2014年7月19日
* Author: angel-toms
*/
#include "ElfParser.h"
void print_elf_section_of_dynamic(MemMapping* mem,Elf32_Ehdr* pHeader,Elf32_Shdr* pSheader){
Elf32_Dyn* pDyncMem = NULL;
u1* shStringTableMem = NULL;
u4 i = 0;
u4 size = 0;
u1 buf[75];
LookupSection* pLookupSection = NULL;
Elf32_Shdr* pDynamic = NULL;
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_DYNAMIC && strcmp((const char*)(shStringTableMem + pSheader[i].sh_name),".dynamic") == 0){
size = (pSheader[i].sh_size / pSheader[i].sh_entsize);
pDyncMem = (Elf32_Dyn*) (mem->base + pSheader[i].sh_offset);
pDynamic = (Elf32_Shdr*)&pSheader[i];
break;
}
continue;
}
if(NULL != pDyncMem){
//@1 by default ,dynamic link .dynstr ,so it sh_link is the index
pLookupSection = get_section_by_index(mem,pHeader,pSheader,pDynamic->sh_link);
if(NULL == pLookupSection){
printf("Error,get section by index failed");
goto Exit;
}
printf("Dynamic section :\n");
printf("Tag Type Name/Value\n");
i = 0;
for( ; i < size ; i++ ){
printf("0x%.8x ",pDyncMem[i].d_tag);
switch(pDyncMem[i].d_tag){
case DT_NULL:
printf("%-65s","Terminating entry");
printf("0x%d ",pDyncMem[i].d_un.d_val);
break;
case DT_NEEDED:
printf("%-65s","String table offset of a needed shared library");
printf("[ %s ]",(pLookupSection->base + pDyncMem[i].d_un.d_val));//because @1 ,so in here not check the section
break;
case DT_PLTRELSZ:
printf("%-65s","Total size in bytes of PLT relocations");
printf("%d (bytes) ",pDyncMem[i].d_un.d_val);
break;
case DT_PLTGOT:
printf("%-65s","Processor-dependent address");
printf("0x%.8x ",pDyncMem[i].d_un.d_ptr);
break;
case DT_HASH:
printf("%-65s","Address of symbol hash table");
printf("0x%.8x ",pDyncMem[i].d_un.d_ptr);
break;
case DT_STRTAB:
printf("%-65s","Address of string table");
printf("0x%.8x ",pDyncMem[i].d_un.d_ptr);
break;
case DT_SYMTAB:
printf("%-65s","Address of symbol table");
printf("0x%.8x ",pDyncMem[i].d_un.d_ptr);
break;
case DT_RELA:
printf("%-65s","Address of ElfNN_Rela rel