[llvm-dev] Relinking (syscall-free) ELF executable into Mach-O and PE executables
Matt P. Dziubinski via llvm-dev
llvm-dev at lists.llvm.org
Fri Jul 20 13:59:03 PDT 2018
Hi,
On 7/20/2018 09:46, ardi via llvm-dev wrote:
> Would this be possible with just LLVM tools, or would other
> libraries/tools also be needed?
I'd expect you'd run into the issues mentioned by Reid.
That being said, in terms of building blocks -- i.e., executables
manipulation per se -- I'd recommend LIEF (Library to Instrument
Executable Formats):
https://github.com/lief-project/LIEF
It supports multiple formats (including ELF, PE, and Mach-O). What's
relevant here in particular is that you can extract code and data from
an existing executable -- as well as build another one from scratch
(with a given code and data):
https://lief.quarkslab.com/doc/latest/tutorials/01_play_with_formats.html
https://lief.quarkslab.com/doc/latest/tutorials/02_pe_from_scratch.html
One of the challenges you may also run into is (mentioned in
https://lief.quarkslab.com/doc/latest/tutorials/08_elf_bin2lib.html --
admittedly a somewhat different context):
"For non-PIE executables such transformation would be very difficult
because it requires to transform first the executable into a relocatable
executable. It means creating relocations, patching absolute jump, …"
In terms of existing work, you may also want to take a look at:
- Exodus (a tool to relocate Linux ELF binaries from one system to
another): https://github.com/Intoli/exodus
- loadlibrary (a library that allows native Linux programs to load and
call functions from a Windows DLL): https://github.com/taviso/loadlibrary
- wine-binfmt: https://reposcope.com/package/wine-binfmt
More executables resources which may be of help:
https://github.com/MattPD/cpplinks/blob/master/executables.md
Best,
Matt
More information about the llvm-dev
mailing list