ELF 解析符号包,包含symtab 和dynsym

本文深入探讨了ELF文件格式中的符号表,包括静态符号表.symtab和动态符号表.dynsym,阐述了它们的作用和在不同平台上的应用情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值