How to convert a dynamically linked application to statically?

I have an application, say gedit, that is dynamically connected and I don't have source code. Therefore, I can not compile it as I like. what I want to do is make it statically linked and transfer it to a system that does not have the necessary libraries to run this application. So can this be done and how?

+4
source share
1 answer

It is theoretically possible. You basically have to do the same job as the dynamic linker, with some changes, i.e.

  • delete all sections from the source file
  • Allow characters
  • find libraries
  • instead of loading them into memory, assemble them into a “virtual image”
  • allow internal links
  • flushes everything in an independent file.

So objdump , objcopy and objcopy will be some of your friends.

The task is not easy, and the result will be neither automatic nor (possibly) stable.

You can check this code to others who have tried the same thing, actually intercepting the dynamic linker (i.e. all the steps above except the last one) and flushing the results to disk.

It is based on this tool , so any of them makes a bet whether it works on the latest kernels.

(This is probably not the case, and you should at least plan it to reflect new structures. This is my attempt at the same time. Caution emptor).

+1
source

Source: https://habr.com/ru/post/1488950/


All Articles