LIEF icon indicating copy to clipboard operation
LIEF copied to clipboard

Adding a library to a MIPS big endian ELF

Open repnzscasb opened this issue 7 years ago • 1 comments

Consider this simple program

$ cat hello.c 
#include <stdio.h>
int main() { printf("hello\n"); return 0; }

A library

$ cat dummy.c 
int func() { return 3; }

And this python code that uses LIEF to add the library to the "hello" binary

$ cat addlib.py
#!/usr/bin/env python2
import lief
binary = lief.parse("hello")
binary.add_library("dummy.so")
binary.write("hello2")

Compiling big endian mips binaries (I'm using dockcross just for reproducibility):

$ sudo docker run --rm dockcross/linux-mips > dockcross-mips
$ chmod a+x dockcross-mips
$ sudo ./dockcross-mips sh -c '$CC -shared -fPIC -Wall -o dummy.so dummy.c'
$ sudo ./dockcross-mips sh -c '$CC hello.c -o hello'
$ sudo ./dockcross-mips sh -c 'qemu-mips ./hello'
hello
$ ./addlib.py
$ sudo ./dockcross-mips sh -c 'qemu-mips -E LD_LIBRARY_PATH=. ./hello2'
qemu: uncaught target signal 11 (Segmentation fault) - core dumped
Segmentation fault (core dumped)

No issues when doing the same steps on a little endian mips binaries (same applies to armv7, x86-64):

$ sudo docker run --rm dockcross/linux-mipsel > dockcross-mipsel
$ chmod a+x dockcross-mipsel
$ sudo ./dockcross-mipsel sh -c '$CC -shared -fPIC -Wall -o dummy.so dummy.c'
$ sudo ./dockcross-mipsel sh -c '$CC hello.c -o hello'
$ sudo ./dockcross-mipsel sh -c 'qemu-mipsel ./hello'
hello
$ ./addlib.py
$ sudo ./dockcross-mipsel sh -c 'qemu-mipsel -E LD_LIBRARY_PATH=. ./hello2'
hello

repnzscasb avatar Sep 07 '18 15:09 repnzscasb

Hi! MIPS Architecture is not supported yet for modification.

romainthomas avatar Sep 09 '18 03:09 romainthomas