ELF头解析

来源:互联网 发布:淘宝头条怎么发布文章 编辑:程序博客网 时间:2024/06/04 17:46
int Parse_ELF_Executable(char *exeFileData, ulong_t exeFileLength,    struct Exe_Format *exeFormat){//    TODO("Parse an ELF executable image");    int i = 0;    Print("elf file length: %d \n", (int)exeFileLength);    elfHeader *elf_head = (elfHeader *)exeFileData;    exeFormat->numSegments = elf_head->phnum;    exeFormat->entryAddr = elf_head->entry;    programHeader *ph = (programHeader *)(exeFileData + elf_head->phoff);    for(i=0;i<elf_head->phnum;i++)    {           exeFormat->segmentList[i].offsetInFile = ph[i].offset;        exeFormat->segmentList[i].lengthInFile = ph[i].fileSize;        exeFormat->segmentList[i].startAddress = ph[i].paddr;        exeFormat->segmentList[i].sizeInMemory = ph[i].memSize;        exeFormat->segmentList[i].protFlags = ph[i].flags;    }               return 0;}



void ELF_Print(char* msg);char  s1[40] = "Hi ! This is the first string\n";int main(int argc, char** argv){   char  s2[40] = "Hi ! This is the second string\n";    ELF_Print(s1);   ELF_Print(s2);    return 0;}