資源簡介
《ELF文件格式分析.pdf》文檔,非常不錯的elf格式參考文檔,參考elf解析過程,能很快掌握elf文件格式

代碼片段和文件信息
#include?
#include?
#include?
#include?“elf.h“
#define?INVALID?????????????????(-1)
#define?SECTION_NAME_SHSTRTAB???“.shstrtab“
#define?SECTION_NAME_SYMTAB?????“.symtab“
#define?SECTION_NAME_STRTAB?????“.strtab“
#define?SECTION_NAME_DYNSYM?????“.dynsym“
#define?SECTION_NAME_DYNSTR?????“.dynstr“
/**
*?字串和枚舉轉換結構體
*/
typedef?struct
{
????int?enum_value;
????char?*?enum_str;
}?ENUM_S;
char?*?enum2str(ENUM_S?*?specs_enum?int?enum_value)
{
????int?i?=?0;
????if?(NULL?==?specs_enum)
????{
????????printf(“param?error!?enum:%#x\n“?(int)specs_enum);
????????return?NULL;
????}
????for?(i?=?0;?specs_enum->enum_str?!=?NULL;?specs_enum++?i++)
????{
????????if?(specs_enum->enum_value?==?enum_value)
????????{
????????????return?specs_enum->enum_str;
????????}
????}
????printf(“enum_value?not?match:%d?\n“?enum_value);
????return?NULL;
}
int?str2enum(ENUM_S?*?specs_enum?const?char?*?enum_str)
{
????int?i?=?0;
????if?((NULL?==?specs_enum)?||?(NULL?==?enum_str))
????{
????????printf(“param?error!?specs_enum:%#x?enum_str:%#x\n“?(int)specs_enum?(int)enum_str);
????????return?-1;
????}
????for?(i?=?0;?specs_enum->enum_str?!=?NULL;?specs_enum++?i++)
????{
????????if?(0?==?strcmp(specs_enum->enum_str?enum_str))
????????{
????????????return?(int)specs_enum->enum_value;
????????}
????}
????printf(“enum_str?not?match:%s?\n“?enum_str);
????return?-1;
}
char?*?readFile(char?*?file?int?*?size)
{
????int?fsize?=?0;
????char?*?mem?=?NULL;
????FILE?*?fp?=?NULL;
????fp?=?fopen(file?“rb“);
????if?(fp?==?NULL)
????{
????????perror(“fopen?error!“);
????????goto?RELEASE;
????}
????fseek(fp?0?SEEK_END);
????fsize?=?ftell(fp);
????mem?=?malloc(fsize);
????if?(mem?==?NULL)
????{
????????perror(“malloc?error!“);
????????goto?RELEASE;
????}
????printf(“readFile?size:%d\n“?size);
????fseek(fp?0?SEEK_SET);
????fread(mem?fsize?1?fp);
????*size?=?fsize;
RELEASE:
????fclose(fp);
????return?mem;
}
int?parseHeader(Elf32_Ehdr?*?header)
{
????int?i?=?0;
????/*?magic?num?*/
????ENUM_S?e_class[]?=?{?{ELFCLASS32?“ELF32“}?{ELFCLASS64?“ELF64“}?{INVALID?NULL}};
????ENUM_S?e_data[]?=?{?{ELFDATA2LSB?“little?endian“}?{ELFDATA2MSB?“big?endian“}?{INVALID?NULL}};
????ENUM_S?e_osabi[]?=?{?{ELFOSABI_NONE?“UNIX?-?System?V“}?{ELFOSABI_ARM_AEABI?“ARM?EABI“}?{ELFOSABI_ARM?“ARM“}?{INVALID?NULL}};
????/*?elf?header?*/
????ENUM_S?e_type[]?=
????{
????????{ET_REL?“Relocatable?file“}
????????{ET_EXEC?“Executable?file“}
????????{ET_DYN?“Shared?object?file“}
????????{ET_CORE?“Core?file“}
????????{INVALID?NULL}
????};
????ENUM_S?e_machine[]?=?{{EM_386?“Intel?80386“}?{EM_ARM?“ARM“}?{INVALID?NULL}};
????unsigned?char?*?e_ident?=?header->e_ident;
????if?((e_ident[EI_MAG0]?!=?ELFMAG0)?||?(e_ident[EI_MAG1]?!=?ELFMAG1)?||
????????????(e_ident[EI_MAG2]?!=?ELFMAG2)?||?(e_ident[EI_MAG2]?!=?ELFMAG2))
????{
?
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????873434??2017-04-25?21:12??ELF文件格式分析.pdf
?????文件??????15705??2018-03-22?17:18??readelf.c
-----------?---------??----------?-----??----
???????????????889139????????????????????2
- 上一篇:基于51單片機的溫度警報器的設計
- 下一篇:編譯原理SLR1分析
評論
共有 條評論