ELF 解析.dynamic 节

本文详细探讨了ELF文件中的odynamic节,涵盖了其结构、作用和解析过程,重点关注其在不同平台的兼容性问题。
摘要由CSDN通过智能技术生成

解析 .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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值