abby sobh abby sobh - 10 days ago 3
Linux Question

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

Answer

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.

Comments