Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to bypass shared library dependencies required for an already-compiled executable?

I know there are many ways to remove/add library dependencies reported prior to compiling an executable for use in Linux. However, after a bit of searching I have not been able to find the way to bypass these dependencies when given only the executable and no binaries. For example, if I run ldd on the executable and there is a shared library that is not found and I do not think is necessary for the program to run.

Thank you

like image 547
abby sobh Avatar asked Oct 21 '22 18:10

abby sobh


2 Answers

You could try patchElf, which is claimed to be "A small utility to modify the dynamic linker and RPATH of ELF executables"

Home page: http://nixos.org/patchelf.html. github repository: https://github.com/NixOS/patchelf

like image 83
Chaim Geretz Avatar answered Oct 24 '22 01:10

Chaim Geretz


For example, if I run ldd on the executable and there is a shared library that is not found and I do not think is necessary for the program to run.

You can trivially test whether your belief is correct: create an empty "stub" shared library with the name that ldd reports as not found, and test whether the executable runs correctly when you make use of that stub (e.g. via LD_LIBRARY_PATH).

If the executable does in fact work (which is somewhat unlikely), you can binary-patch the .dynamic section of the executable to remove the unnecessary dependency -- .dynamic is simply a fixed-sized table of Elf{32,64}_Dyn records, terminated by a record with .d_tag == DT_NULL (the needed libraries are represented by records with .d_tag == DT_NEEDED. You can therefore find the unnecessary record, and simply "slide" all following records one slot up in the table.

like image 31
Employed Russian Avatar answered Oct 24 '22 00:10

Employed Russian