Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Question How to move section entry from elf?


    ELF format:
    1. 0x00 ~ 0x33 is file header
    2. section headers and segment headers must be consecutive

    And section entry can store in any other location in the file, specify by offset

    I want to move a section entry(.dynsym) to another location
    And, for ELF32 only

    I write an utility "ModifyElf.exe" to do this easily, it is based on ELFIO project

    The Process:
    1. ModifyElf.exe
    The utility can move a section entry of elf file. Usage:
    ModifyElf.exe <srcfile> <dstfile> <sectionname> <mov2fileend:0|1> <clearold:0|1>
    args:
    <srcfile> -> src so file path
    <dstfile> -> dst so file path
    <sectionname> -> section name, just support ".dynsym " currently
    <mov2fileend:0|1> -> mov2fileend:0 move section entry to the unused padding spaces of so file, don't increase file size
    mov2fileend:1 move section entry to the end of so file, will increase file size
    <clearold:0|1> -> clearold:0 don't clear the original section entry
    clearold:1 set all bytes of original section entry to 0xFF

    for example:
    ModifyElf.exe e:\test\libfoo_ori.so e:\test\libfoo.so .dynsym mov2fileend:0 clearold:1

    2. libfoo.so and linux_hello
    linux_hello call dlopen to load libfoo.so, and call myfn from libfoo.so, myfn just printf a string

    neil0#vm32:~/share/test$ sudo chmod a+x linux_hello
    neil0#vm32:~/share/test$ export LD_LIBRARY_PATH=~/share/test:$LD_LIBRARY_PATH
    neil0#vm32:~/share/test$ ./linux_hello
    dlopen ok!
    call myfn...!

    3. modify and exec
    Run ModifyElf.exe e:\test\libfoo_ori.so e:\test\libfoo.so .dynsym mov2fileend:0 clearold:1
    Move section entry to padding spaces, get a new so file, replace it in linux,and exec linux_hello.
    And, it's OK!You can use file compare tool to see diff between libfoo.so and libfoo_ori.so

    Run ModifyElf.exe e:\test\libfoo_ori.so e:\test\libfoo.so .dynsym mov2fileend:1 clearold:1
    Move section entry to file end,get a new so file, replace it in linux,and exec linux_hello
    Unfortunately it's said "Segmentation fault"

    So could you tell me why I can't move it to file end and how should I do if I want to do this? Thanks!
    Attached Files Attached Files

  2. #2
    Linux Enthusiast
    Join Date
    Dec 2011
    Location
    Turtle Island West
    Posts
    602
    CAUTION:

    This is a tarbomb.

    contains:
    Code:
    -rw-r--r-- 1 user user 165888 Jun  3 15:33 ModifyElf.exe
    -rw-r--r-- 1 user user   6902 Jun  3 07:53 libfoo.so
    -rw-r--r-- 1 user user   7439 Jun  3 07:53 linux_hello
    -rw-r--r-- 1 user user     93 Jun  3 09:41 run.cmd
    No source code given. Use your own discretion.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •