load ELF file into memory

前端 未结 2 614
太阳男子
太阳男子 2021-02-13 15:18

I\'m trying to put an elf file into memory and then execute it, these are the steps:

1- file to put into memory

int main()
{
   printf(\"Hello world! \\n         


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-13 15:57

    I'm trying to put an elf file into memory and then execute it,

    For a fully-statically-linked executable, your steps would work (except you need to jump to _start == entry point 0x8120, not main).

    Then I have copied all the elf bytes into the allocations

    Another possible problem is not paying attention to the .p_offset. Your memcpyies should look something like this:

    unsigned char buf1[0x16828];  // read 0x16828 bytes from start of file
    memcpy(0x8000, buf1, 0x16828);
    
    unsigned char buf2[0x250];  // read 0x250 bytes from offset 0x016840 into the file
    memcpy(0x0001f840, buf2, 0x250);
    

提交回复
热议问题