gz / rust-elfloader

Library to load and relocate ELF files.
https://docs.rs/elfloader
Apache License 2.0
117 stars 23 forks source link

Loading ELF on x64 Linux #7

Closed jabedude closed 5 years ago

jabedude commented 6 years ago

I'm having some trouble implementing an ELF loader in Linux with the ElfLoader trait. Questions:

  1. When allocating memory for each section, does the base address need to match what is in the section header?
  2. It doesn't look like this crate has a function for jumping to the start point of the loaded ELF and begin executing, how would that be done with this crate? Could I maybe open a pull request to add that functionality?
gz commented 6 years ago

@jabedude

Regarding 1: Yes the allocate calls you're seeing should contain the virtual base address of the program headers https://github.com/gz/rust-elfloader/blob/d5104bcc29241cc266cde6f045483b760c4744aa/src/lib.rs#L196 I never loaded a binary linked with a Linux compatible linker script, so there may be issues (let me know I'm happy to help troubleshoot).

Regarding 2: I think the functionality is not in the crate yet (I think there is for parsing the header containing the entry point, but there isn't a convenient function for retrieving it). But yes, I'm happy for any pull requests that improve the crate.

gz commented 5 years ago

FYI I updated this crate a little so ElfLoader also gets exposed to relocation entries as well. With this I can successfully load position independent executables too. There is a test that shows how to do it.

If something should not work feel free to open a new issue.

jabedude commented 5 years ago

Thank you, that sounds great! I'll check it out.