目录
动态加载器的了解
在【维基百科】中动态加载是一种机制,通过该机制,计算机程序可以在运行时将库(或其他二进制)加载到存储器中,检索包含在库中的函数和变量的地址,执行那些函数或访问那些变量,以及从存储器中卸载库。它是计算机程序使用其他软件的三种机制之一;另外两种是静态链接和动态链接。与静态链接和动态链接不同,动态加载允许计算机程序在缺少这些库的情况下启动,以发现可用的库,并潜在地获得附加功能。
为了想了解Linux系统中一个执行文件到底是怎样被执行。
写了一个简单求和C文件,进行编译后,生成了一个可执行文件。
#include<stdio.h>
int sum(int x)
{
int sumvalue = 0;
for(int i = 1; i <= x; i++)
{
sumvalue += i;
}
return sumvalue;
}
int main()
{
int n = 100;
int value;
value = sum(n);
printf("sum = %d\n", value);
}
在Linux中可以通过file和readelf指令来查看执行文件的大概信息以及文件的elf相关信息。
1、通过file 执行文件名 可以查看到执行文件是静态执行文件还是动态执行文件。statically linked \ dynamically linked。
$ file ./demo
./demo: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=a0c5f362e76df504e8c9f9be25369c7209a6193e, not stripped
2、readelf -h查看指令帮助
readelf: Warning: Nothing to do.
Usage: readelf <option(s)> elf-file(s)
Display information about the contents of ELF format files
Options are:
-a --all Equivalent to: -h -l -S -s -r -d -V -A -I
-h --file-header Display the ELF file header
-l --program-headers Display the program headers
--segments An alias for --program-headers
-S --section-headers Display the sections' header
--sections An alias for --section-headers
-g --section-groups Display the section groups
-t --section-details Display the section details
-e --headers Equivalent to: -h -l -S
-s --syms Display the symbol table
--symbols An alias for --syms
--dyn-syms Display the dynamic symbol table
-n --notes Display the core notes (if present)
-r --relocs Display the relocations (if present)
-u --unwind Display the unwind info (if present)
-d --dynamic Display the dynamic section (if present)
-V --version-info Display the version sections (if present)
-A --arch-specific Display architecture specific information (if any)
-c --archive-index Display the symbol/file index in an archive
-D --use-dynamic Use the dynamic section info when displaying symbols
-x --hex-dump=<number|name>
Dump the contents of section <number|name> as bytes
-p --string-dump=<number|name>
Dump the contents of section <number|name> as strings
-R --relocated-dump=<number|name>
Dump the contents of section <number|name> as relocated bytes
-z --decompress Decompress section before dumping it
-w[lLiaprmfFsoRtUuTgAckK] or
--debug-dump[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=ma
理解Linux动态加载器与ELF文件

本文介绍了Linux动态加载器的工作原理,通过分析`file`和`readelf`命令展示了ELF文件的详细信息,特别是动态链接部分。在动态链接的ELF文件中,`INTERP`节指出需要`ld-linux-x86-64.so.2`加载器。通过`ldd`命令检查程序依赖,当ELF文件无执行权限时,可以利用动态库的执行权限来运行程序,如`/lib64/ld-linux-x86-64.so.2`执行`readflag`来获取CTF挑战的flag。
最低0.47元/天 解锁文章

2113

被折叠的 条评论
为什么被折叠?



