加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 可以更改动态libc.so地址吗?

发布时间:2020-12-13 22:48:29 所属栏目:Linux 来源:网络整理
导读:命令 gcc main.c -o mainldd main 让 linux-gate.so.1 = (0x00f67000)libc.so.6 = /lib/i386-linux-gnu/libc.so.6 (0x00b7d000)/lib/ld-linux.so.2 (0x00ae5000) 是否可以更改libc.so.6将在内存中映射的地址?例如,将libc.so.6映射到,例如0xb0000000. 我正在
命令

gcc main.c -o main
ldd main

linux-gate.so.1 => (0x00f67000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0x00b7d000)
/lib/ld-linux.so.2 (0x00ae5000)

是否可以更改libc.so.6将在内存中映射的地址?例如,将libc.so.6映射到,例如0xb0000000.

我正在运行Xubuntu 32bit:Linux 3.2.0-23-generic i686 i686 i386 GNU / Linux

解决方法

有一个预链接实用程序( wiki page),它能够改变所有库的加载地址(它被称为“基地址”).

有关prelink如何工作的一些信息:http://www.acsu.buffalo.edu/~charngda/elf.html

What does this prelink do? It changes the base address of a dynamic library to the actual address in the user program’s address space when it is loaded into memory. Of course,ld.so recognizes GNU_PRELINKED tag and will load a dynamic library to its this base address (recall the first argument of mmap is the preferred address; of course,this is subject to the operating system.)

Normally,a dynamic library is built as position independent code,i.e. the -fPIC compiler command-line option,and thus the base address is 0. For example,a normal libc.so has ELF program header as follows (readelf -l command)…

根据man prelink,有一个prelink实用程序选项可以将给定库重新定位(重定位)到指定的地址:

-r --reloc-only=ADDRESS
Instead of prelinking,just relink given shared libraries to the specified base address.

预链接–reloc-only = 0x7896000 libc.so.6应足以实现您想要的更改.

PS:您可以在本地libc副本上执行此重定位,然后通过export LD_LIBRARY_PATH = / path / to / your / rebased / copy:$LD_LIBRARY_PATH给出它的路径

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读