什么是LD_PRELOAD技巧?

时间:2022-09-06 21:29:08

I came across a reference to it recently on proggit and (as of now) it is not explained.

我最近在proggit上遇到了一个关于它的引用,(到现在为止)它没有被解释。

I suspect this might be it, but I don't know for sure.

我怀疑可能就是这个,但我不确定。

8 个解决方案

#1


313  

If you set LD_PRELOAD to the path of a shared object, that file will be loaded before any other library (including the C runtime, libc.so). So to run ls with your special malloc() implementation, do this:

如果将LD_PRELOAD设置为共享对象的路径,那么该文件将在任何其他库(包括C运行时,libc.so)之前加载。因此,要使用特殊的malloc()实现运行ls,请执行以下操作:

$ LD_PRELOAD=/path/to/my/malloc.so /bin/ls

#2


35  

You can override symbols in the stock libraries by creating a library with the same symbols and specifying the library in LD_PRELOAD.

通过创建具有相同符号的库并在LD_PRELOAD中指定库,您可以覆盖库存库中的符号。

Some people use it to specify libraries in nonstandard locations, but LD_LIBRARY_PATH is better for that purpose.

有些人使用它在非标准位置指定库,但LD_LIBRARY_PATH更适合这个目的。

#3


28  

With LD_PRELOAD you can give libraries precedence.

使用LD_PRELOAD,可以优先考虑库。

For example you can write a library which implement malloc and free. And by loading these with LD_PRELOAD your malloc and free will be executed rather than the standard ones.

例如,您可以编写一个实现malloc和free的库。通过加载这些LD_PRELOAD,您的malloc和free将被执行,而不是标准的。

#4


20  

As many people mentioned, using LD_PRELOAD to preload library. BTW, you can CHECK if the setting is available by ldd command.

正如许多人提到的,使用LD_PRELOAD来预加载库。顺便说一句,您可以通过ldd命令检查设置是否可用。

Example: suppose you need to preload your own libselinux.so.1.

示例:假设您需要预加载自己的libselinux.so.1。

> ldd /bin/ls
    ...
    libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f3927b1d000)
    libacl.so.1 => /lib/x86_64-linux-gnu/libacl.so.1 (0x00007f3927914000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f392754f000)
    libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f3927311000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f392710c000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f3927d65000)
    libattr.so.1 => /lib/x86_64-linux-gnu/libattr.so.1 (0x00007f3926f07000)

Thus, set your preload environment:

因此,设置您的预加载环境:

  export LD_PRELOAD=/home/patric/libselinux.so.1

Check your library again:

再次检查你的图书馆:

>ldd /bin/ls
    ...
    libselinux.so.1 =>
    /home/patric/libselinux.so.1 (0x00007fb9245d8000)
    ...

#5


9  

LD_PRELOAD lists shared libraries with functions that override the standard set, just as /etc/ld.so.preload does. These are implemented by the loader /lib/ld-linux.so. If you want to override just a few selected functions, you can do this by creating an overriding object file and setting LD_PRELOAD; the functions in this object file will override just those functions leaving others as they were.

LD_PRELOAD用覆盖标准集的函数列出共享库,就像/etc/ld. so一样。预加载。这些都是由加载器/lib/ld-linux实现的。如果您只想覆盖一些选定的函数,您可以通过创建一个覆盖对象文件并设置LD_PRELOAD来实现这一点;这个对象文件中的函数将重写这些函数,使其他函数保持原样。

For more information on shared libraries visit http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html

有关共享库的更多信息,请访问http://tldp.org/howto/program-library - howto/shared libraries.html

#6


4  

it's easy to export mylib.so to env:

导出mylib很容易。所以env:

$ export LD_PRELOAD=/path/mylib.so
$ ./mybin

to disable :

禁用:

$ export LD_PRELOAD=

#7


2  

Here is a detailed blog post about preloading:

以下是一篇关于预加载的详细博文:

https://blog.cryptomilk.org/2014/07/21/what-is-preloading/

https://blog.cryptomilk.org/2014/07/21/what-is-preloading/

#8


1  

Using LD_PRELOAD path, you can force the application loader to load provided shared object, over the default provided.

使用LD_PRELOAD路径,您可以强制应用程序加载程序加载程序加载提供的共享对象,而不是默认提供的对象。

Developers uses this to debug their applications by providing different versions of the shared objects.

开发人员通过提供不同版本的共享对象来调试他们的应用程序。

We've used it to hack certain applications, by overriding existing functions using prepared shared objects.

我们已经使用它来破解某些应用程序,方法是使用准备好的共享对象覆盖现有的函数。

#1


313  

If you set LD_PRELOAD to the path of a shared object, that file will be loaded before any other library (including the C runtime, libc.so). So to run ls with your special malloc() implementation, do this:

如果将LD_PRELOAD设置为共享对象的路径,那么该文件将在任何其他库(包括C运行时,libc.so)之前加载。因此,要使用特殊的malloc()实现运行ls,请执行以下操作:

$ LD_PRELOAD=/path/to/my/malloc.so /bin/ls

#2


35  

You can override symbols in the stock libraries by creating a library with the same symbols and specifying the library in LD_PRELOAD.

通过创建具有相同符号的库并在LD_PRELOAD中指定库,您可以覆盖库存库中的符号。

Some people use it to specify libraries in nonstandard locations, but LD_LIBRARY_PATH is better for that purpose.

有些人使用它在非标准位置指定库,但LD_LIBRARY_PATH更适合这个目的。

#3


28  

With LD_PRELOAD you can give libraries precedence.

使用LD_PRELOAD,可以优先考虑库。

For example you can write a library which implement malloc and free. And by loading these with LD_PRELOAD your malloc and free will be executed rather than the standard ones.

例如,您可以编写一个实现malloc和free的库。通过加载这些LD_PRELOAD,您的malloc和free将被执行,而不是标准的。

#4


20  

As many people mentioned, using LD_PRELOAD to preload library. BTW, you can CHECK if the setting is available by ldd command.

正如许多人提到的,使用LD_PRELOAD来预加载库。顺便说一句,您可以通过ldd命令检查设置是否可用。

Example: suppose you need to preload your own libselinux.so.1.

示例:假设您需要预加载自己的libselinux.so.1。

> ldd /bin/ls
    ...
    libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f3927b1d000)
    libacl.so.1 => /lib/x86_64-linux-gnu/libacl.so.1 (0x00007f3927914000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f392754f000)
    libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f3927311000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f392710c000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f3927d65000)
    libattr.so.1 => /lib/x86_64-linux-gnu/libattr.so.1 (0x00007f3926f07000)

Thus, set your preload environment:

因此,设置您的预加载环境:

  export LD_PRELOAD=/home/patric/libselinux.so.1

Check your library again:

再次检查你的图书馆:

>ldd /bin/ls
    ...
    libselinux.so.1 =>
    /home/patric/libselinux.so.1 (0x00007fb9245d8000)
    ...

#5


9  

LD_PRELOAD lists shared libraries with functions that override the standard set, just as /etc/ld.so.preload does. These are implemented by the loader /lib/ld-linux.so. If you want to override just a few selected functions, you can do this by creating an overriding object file and setting LD_PRELOAD; the functions in this object file will override just those functions leaving others as they were.

LD_PRELOAD用覆盖标准集的函数列出共享库,就像/etc/ld. so一样。预加载。这些都是由加载器/lib/ld-linux实现的。如果您只想覆盖一些选定的函数,您可以通过创建一个覆盖对象文件并设置LD_PRELOAD来实现这一点;这个对象文件中的函数将重写这些函数,使其他函数保持原样。

For more information on shared libraries visit http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html

有关共享库的更多信息,请访问http://tldp.org/howto/program-library - howto/shared libraries.html

#6


4  

it's easy to export mylib.so to env:

导出mylib很容易。所以env:

$ export LD_PRELOAD=/path/mylib.so
$ ./mybin

to disable :

禁用:

$ export LD_PRELOAD=

#7


2  

Here is a detailed blog post about preloading:

以下是一篇关于预加载的详细博文:

https://blog.cryptomilk.org/2014/07/21/what-is-preloading/

https://blog.cryptomilk.org/2014/07/21/what-is-preloading/

#8


1  

Using LD_PRELOAD path, you can force the application loader to load provided shared object, over the default provided.

使用LD_PRELOAD路径,您可以强制应用程序加载程序加载程序加载提供的共享对象,而不是默认提供的对象。

Developers uses this to debug their applications by providing different versions of the shared objects.

开发人员通过提供不同版本的共享对象来调试他们的应用程序。

We've used it to hack certain applications, by overriding existing functions using prepared shared objects.

我们已经使用它来破解某些应用程序,方法是使用准备好的共享对象覆盖现有的函数。