首页 > 其他分享 >从执行文件查看elf文件的各种详细信息

从执行文件查看elf文件的各种详细信息

时间:2023-12-30 17:56:15浏览次数:22  
标签:__ 文件 PROGBITS DEFAULT GLOBAL elf 0000000000000000 -- 详细信息

代码如下program8_6.c:

1 #include <stdio.h>
2
3 int a = 0x55555555;
4 int b = 0x66666666;
5 int c = 0x77777777;
6 int d = 0x88888888;
7
8 int main()
9 {
10     a = 0x11111111;
11     b = 0x22222222;
12     c = 0x33333333;
13     d = 0x44444444;
14
15     printf("Variable: \taddresses: \n");
16     printf("a %x\t%x\n", a, &a);
17     printf("b %x\t%x\n", b, &b);
18     printf("c %x\t%x\n", c, &c);
19     printf("d %x\t%x\n", d, &d);
20
21     printf("Finished!\n");
22
23     return 0;
24 }

gcc program8_6.c -o program8_6生成可执行文件,查看elf文件的常见部分,使用命令readelf,选项如下:

readelf [-a|--all]
[-h|--file-header]
[-l|--program-headers|--segments]
[-S|--section-headers|--sections]
[-g|--section-groups]
[-t|--section-details]
[-e|--headers]
[-s|--syms|--symbols]
[--dyn-syms|--lto-syms]
[--sym-base=[0|8|10|16]]
[--demangle=style|--no-demangle]
[--quiet]
[--recurse-limit|--no-recurse-limit]
[-U method|--unicode=method]
[-n|--notes]
[-r|--relocs]
[-u|--unwind]
[-d|--dynamic]
[-V|--version-info]
[-A|--arch-specific]
[-D|--use-dynamic]
[-L|--lint|--enable-checks]
[-x <number or name>|--hex-dump=<number or name>]
[-p <number or name>|--string-dump=<number or name>]
[-R <number or name>|--relocated-dump=<number or name>]
[-z|--decompress]
[-c|--archive-index]
[-w[lLiaprmfFsoORtUuTgAck]|
--debug-dump[=rawline,=decodedline,=info,=abbrev,=pubnames,=arang
es,=macro,=frames,=frames-interp,=str,=str-offsets,=loc,=Ranges,=pubtypes,=trace_
info,=trace_abbrev,=trace_aranges,=gdb_index,=addr,=cu_index,=links]]
[-wK|--debug-dump=follow-links]
[-wN|--debug-dump=no-follow-links]
[-P|--process-links]
[--dwarf-depth=n]
[--dwarf-start=n]
[--ctf=section]
[--ctf-parent=section]
[--ctf-symbols=section]
[--ctf-strings=section]
[-I|--histogram]
[-v|--version]
[-W|--wide]
[-T|--silent-truncation]
[-H|--help]

最常见的有-a:等同于 --file-header = -h , --program-headers = -l , --sections  = -S , --symbols = -s , --relocs = -r, --dynamic = -d , --notes = -n, --version-info = -V, --arch-specific = -A, --unwind = -u, --section-groups = -g and --histogram = -I.

根据自行的情况,查看即可。

查看文件头:readelf -h program8_6

ELF Header:
Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class:                             ELF64
Data:                              2's complement, little endian
Version:                           1 (current)
OS/ABI:                            UNIX - System V
ABI Version:                       0
Type:                              DYN (Position-Independent Executable file)
Machine:                           Advanced Micro Devices X86-64
Version:                           0x1
Entry point address:               0x1080
Start of program headers:          64 (bytes into file)
Start of section headers:          15056 (bytes into file)
Flags:                             0x0
Size of this header:               64 (bytes)
Size of program headers:           56 (bytes)
Number of program headers:         13
Size of section headers:           64 (bytes)
Number of section headers:         37
Section header string table index: 36

查看程序头段:readelf -l program8_6

Elf file type is DYN (Position-Independent Executable file)
Entry point 0x1080
There are 13 program headers, starting at offset 64

Program Headers:
Type           Offset             VirtAddr           PhysAddr
FileSiz            MemSiz              Flags  Align
PHDR           0x0000000000000040 0x0000000000000040 0x0000000000000040
0x00000000000002d8 0x00000000000002d8  R      0x8
INTERP         0x0000000000000318 0x0000000000000318 0x0000000000000318
0x000000000000001c 0x000000000000001c  R      0x1
[Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]
LOAD           0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000660 0x0000000000000660  R      0x1000
LOAD           0x0000000000001000 0x0000000000001000 0x0000000000001000
0x0000000000000259 0x0000000000000259  R E    0x1000
LOAD           0x0000000000002000 0x0000000000002000 0x0000000000002000
0x000000000000012c 0x000000000000012c  R      0x1000
LOAD           0x0000000000002db0 0x0000000000003db0 0x0000000000003db0
0x0000000000000270 0x0000000000000278  RW     0x1000
DYNAMIC        0x0000000000002dc0 0x0000000000003dc0 0x0000000000003dc0
0x00000000000001f0 0x00000000000001f0  RW     0x8
NOTE           0x0000000000000338 0x0000000000000338 0x0000000000000338
0x0000000000000030 0x0000000000000030  R      0x8
NOTE           0x0000000000000368 0x0000000000000368 0x0000000000000368
0x0000000000000044 0x0000000000000044  R      0x4
GNU_PROPERTY   0x0000000000000338 0x0000000000000338 0x0000000000000338
0x0000000000000030 0x0000000000000030  R      0x8
GNU_EH_FRAME   0x000000000000204c 0x000000000000204c 0x000000000000204c
0x0000000000000034 0x0000000000000034  R      0x4
GNU_STACK      0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000  RW     0x10
GNU_RELRO      0x0000000000002db0 0x0000000000003db0 0x0000000000003db0
0x0000000000000250 0x0000000000000250  R      0x1

Section to Segment mapping:
Segment Sections...
00
01     .interp
02     .interp .note.gnu.property .note.gnu.build-id .note.ABI-tag .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn .rela.plt
03     .init .plt .plt.got .plt.sec .text .fini
04     .rodata .eh_frame_hdr .eh_frame
05     .init_array .fini_array .dynamic .got .data .bss
06     .dynamic
07     .note.gnu.property
08     .note.gnu.build-id .note.ABI-tag
09     .note.gnu.property
10     .eh_frame_hdr
11
12     .init_array .fini_array .dynamic .got

查看程序头section:readelf -S program8_6

There are 37 section headers, starting at offset 0x3ad0:

Section Headers:
[Nr] Name              Type             Address           Offset
Size              EntSize          Flags  Link  Info  Align
[ 0]                   NULL             0000000000000000  00000000
0000000000000000  0000000000000000           0     0     0
[ 1] .interp           PROGBITS         0000000000000318  00000318
000000000000001c  0000000000000000   A       0     0     1
[ 2] .note.gnu.pr[...] NOTE             0000000000000338  00000338
0000000000000030  0000000000000000   A       0     0     8
[ 3] .note.gnu.bu[...] NOTE             0000000000000368  00000368
0000000000000024  0000000000000000   A       0     0     4
[ 4] .note.ABI-tag     NOTE             000000000000038c  0000038c
0000000000000020  0000000000000000   A       0     0     4
[ 5] .gnu.hash         GNU_HASH         00000000000003b0  000003b0
0000000000000024  0000000000000000   A       6     0     8
[ 6] .dynsym           DYNSYM           00000000000003d8  000003d8
00000000000000c0  0000000000000018   A       7     1     8
[ 7] .dynstr           STRTAB           0000000000000498  00000498
0000000000000094  0000000000000000   A       0     0     1
[ 8] .gnu.version      VERSYM           000000000000052c  0000052c
0000000000000010  0000000000000002   A       6     0     2
[ 9] .gnu.version_r    VERNEED          0000000000000540  00000540
0000000000000030  0000000000000000   A       7     1     8
[10] .rela.dyn         RELA             0000000000000570  00000570
00000000000000c0  0000000000000018   A       6     0     8
[11] .rela.plt         RELA             0000000000000630  00000630
0000000000000030  0000000000000018  AI       6    24     8
[12] .init             PROGBITS         0000000000001000  00001000
000000000000001b  0000000000000000  AX       0     0     4
[13] .plt              PROGBITS         0000000000001020  00001020
0000000000000030  0000000000000010  AX       0     0     16
[14] .plt.got          PROGBITS         0000000000001050  00001050
0000000000000010  0000000000000010  AX       0     0     16
[15] .plt.sec          PROGBITS         0000000000001060  00001060
0000000000000020  0000000000000010  AX       0     0     16
[16] .text             PROGBITS         0000000000001080  00001080
00000000000001ca  0000000000000000  AX       0     0     16
[17] .fini             PROGBITS         000000000000124c  0000124c
000000000000000d  0000000000000000  AX       0     0     4
[18] .rodata           PROGBITS         0000000000002000  00002000
0000000000000049  0000000000000000   A       0     0     4
[19] .eh_frame_hdr     PROGBITS         000000000000204c  0000204c
0000000000000034  0000000000000000   A       0     0     4
[20] .eh_frame         PROGBITS         0000000000002080  00002080
00000000000000ac  0000000000000000   A       0     0     8
[21] .init_array       INIT_ARRAY       0000000000003db0  00002db0
0000000000000008  0000000000000008  WA       0     0     8
[22] .fini_array       FINI_ARRAY       0000000000003db8  00002db8
0000000000000008  0000000000000008  WA       0     0     8
[23] .dynamic          DYNAMIC          0000000000003dc0  00002dc0
00000000000001f0  0000000000000010  WA       7     0     8
[24] .got              PROGBITS         0000000000003fb0  00002fb0
0000000000000050  0000000000000008  WA       0     0     8
[25] .data             PROGBITS         0000000000004000  00003000
0000000000000020  0000000000000000  WA       0     0     8
[26] .bss              NOBITS           0000000000004020  00003020
0000000000000008  0000000000000000  WA       0     0     1
[27] .comment          PROGBITS         0000000000000000  00003020
000000000000002b  0000000000000001  MS       0     0     1
[28] .debug_aranges    PROGBITS         0000000000000000  0000304b
0000000000000030  0000000000000000           0     0     1
[29] .debug_info       PROGBITS         0000000000000000  0000307b
00000000000000f7  0000000000000000           0     0     1
[30] .debug_abbrev     PROGBITS         0000000000000000  00003172
000000000000008b  0000000000000000           0     0     1
[31] .debug_line       PROGBITS         0000000000000000  000031fd
000000000000006e  0000000000000000           0     0     1
[32] .debug_str        PROGBITS         0000000000000000  0000326b
00000000000000e0  0000000000000001  MS       0     0     1
[33] .debug_line_str   PROGBITS         0000000000000000  0000334b
0000000000000046  0000000000000001  MS       0     0     1
[34] .symtab           SYMTAB           0000000000000000  00003398
00000000000003d8  0000000000000018          35    18     8
[35] .strtab           STRTAB           0000000000000000  00003770
00000000000001f5  0000000000000000           0     0     1
[36] .shstrtab         STRTAB           0000000000000000  00003965
000000000000016a  0000000000000000           0     0     1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
L (link order), O (extra OS processing required), G (group), T (TLS),
C (compressed), x (unknown), o (OS specific), E (exclude),
D (mbind), l (large), p (processor specific)

查看程序头标号:readelf -s program8_6

Symbol table '.dynsym' contains 8 entries:
Num:    Value          Size Type    Bind   Vis      Ndx Name
0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
1: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND _[...]@GLIBC_2.34 (2)
2: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND _ITM_deregisterT[...]
3: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND puts@GLIBC_2.2.5 (3)
4: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
5: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND __gmon_start__
6: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND _ITM_registerTMC[...]
7: 0000000000000000     0 FUNC    WEAK   DEFAULT  UND [...]@GLIBC_2.2.5 (3)

Symbol table '.symtab' contains 41 entries:
Num:    Value          Size Type    Bind   Vis      Ndx Name
0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
1: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS Scrt1.o
2: 000000000000038c    32 OBJECT  LOCAL  DEFAULT    4 __abi_tag
3: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS crtstuff.c
4: 00000000000010b0     0 FUNC    LOCAL  DEFAULT   16 deregister_tm_clones
5: 00000000000010e0     0 FUNC    LOCAL  DEFAULT   16 register_tm_clones
6: 0000000000001120     0 FUNC    LOCAL  DEFAULT   16 __do_global_dtors_aux
7: 0000000000004020     1 OBJECT  LOCAL  DEFAULT   26 completed.0
8: 0000000000003db8     0 OBJECT  LOCAL  DEFAULT   22 __do_global_dtor[...]
9: 0000000000001160     0 FUNC    LOCAL  DEFAULT   16 frame_dummy
10: 0000000000003db0     0 OBJECT  LOCAL  DEFAULT   21 __frame_dummy_in[...]
11: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS program8_6.c
12: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS crtstuff.c
13: 0000000000002128     0 OBJECT  LOCAL  DEFAULT   20 __FRAME_END__
14: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS
15: 0000000000003dc0     0 OBJECT  LOCAL  DEFAULT   23 _DYNAMIC
16: 000000000000204c     0 NOTYPE  LOCAL  DEFAULT   19 __GNU_EH_FRAME_HDR
17: 0000000000003fb0     0 OBJECT  LOCAL  DEFAULT   24 _GLOBAL_OFFSET_TABLE_
18: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __libc_start_mai[...]
19: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND _ITM_deregisterT[...]
20: 0000000000004000     0 NOTYPE  WEAK   DEFAULT   25 data_start
21: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND puts@GLIBC_2.2.5
22: 000000000000401c     4 OBJECT  GLOBAL DEFAULT   25 d
23: 0000000000004014     4 OBJECT  GLOBAL DEFAULT   25 b
24: 0000000000004020     0 NOTYPE  GLOBAL DEFAULT   25 _edata
25: 000000000000124c     0 FUNC    GLOBAL HIDDEN    17 _fini
26: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND printf@GLIBC_2.2.5
27: 0000000000004000     0 NOTYPE  GLOBAL DEFAULT   25 __data_start
28: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND __gmon_start__
29: 0000000000004008     0 OBJECT  GLOBAL HIDDEN    25 __dso_handle
30: 0000000000002000     4 OBJECT  GLOBAL DEFAULT   18 _IO_stdin_used
31: 0000000000004028     0 NOTYPE  GLOBAL DEFAULT   26 _end
32: 0000000000001080    38 FUNC    GLOBAL DEFAULT   16 _start
33: 0000000000004018     4 OBJECT  GLOBAL DEFAULT   25 c
34: 0000000000004010     4 OBJECT  GLOBAL DEFAULT   25 a
35: 0000000000004020     0 NOTYPE  GLOBAL DEFAULT   26 __bss_start
36: 0000000000001169   225 FUNC    GLOBAL DEFAULT   16 main
37: 0000000000004020     0 OBJECT  GLOBAL HIDDEN    25 __TMC_END__
38: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND _ITM_registerTMC[...]
39: 0000000000000000     0 FUNC    WEAK   DEFAULT  UND __cxa_finalize@G[...]
40: 0000000000001000     0 FUNC    GLOBAL HIDDEN    12 _init

查看程序relocation信息:readelf -r program8_6 

Relocation section '.rela.dyn' at offset 0x570 contains 8 entries:
Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000003db0  000000000008 R_X86_64_RELATIVE                    1160
000000003db8  000000000008 R_X86_64_RELATIVE                    1120
000000004008  000000000008 R_X86_64_RELATIVE                    4008
000000003fd8  000100000006 R_X86_64_GLOB_DAT 0000000000000000 __libc_start_main@GLIBC_2.34 + 0
000000003fe0  000200000006 R_X86_64_GLOB_DAT 0000000000000000 _ITM_deregisterTM[...] + 0
000000003fe8  000500000006 R_X86_64_GLOB_DAT 0000000000000000 __gmon_start__ + 0
000000003ff0  000600000006 R_X86_64_GLOB_DAT 0000000000000000 _ITM_registerTMCl[...] + 0
000000003ff8  000700000006 R_X86_64_GLOB_DAT 0000000000000000 __cxa_finalize@GLIBC_2.2.5 + 0

Relocation section '.rela.plt' at offset 0x630 contains 2 entries:
Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000003fc8  000300000007 R_X86_64_JUMP_SLO 0000000000000000 puts@GLIBC_2.2.5 + 0
000000003fd0  000400000007 R_X86_64_JUMP_SLO 0000000000000000 printf@GLIBC_2.2.5 + 0

查看程序note信息:readelf -n program8_6 

Displaying notes found in: .note.gnu.property
Owner                Data size        Description
GNU                  0x00000020       NT_GNU_PROPERTY_TYPE_0
Properties: x86 feature: IBT, SHSTK
x86 ISA needed: x86-64-baseline

Displaying notes found in: .note.gnu.build-id
Owner                Data size        Description
GNU                  0x00000014       NT_GNU_BUILD_ID (unique build ID bitstring)
Build ID: 0245ec8d557a2b7776c6c869521b41ba0ae10249

Displaying notes found in: .note.ABI-tag
Owner                Data size        Description
GNU                  0x00000010       NT_GNU_ABI_TAG (ABI version tag)
OS: Linux, ABI: 3.2.0

查看程序动态信息:readelf -d program8_6 

Dynamic section at offset 0x2dc0 contains 27 entries:
Tag        Type                         Name/Value
0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
0x000000000000000c (INIT)               0x1000
0x000000000000000d (FINI)               0x124c
0x0000000000000019 (INIT_ARRAY)         0x3db0
0x000000000000001b (INIT_ARRAYSZ)       8 (bytes)
0x000000000000001a (FINI_ARRAY)         0x3db8
0x000000000000001c (FINI_ARRAYSZ)       8 (bytes)
0x000000006ffffef5 (GNU_HASH)           0x3b0
0x0000000000000005 (STRTAB)             0x498
0x0000000000000006 (SYMTAB)             0x3d8
0x000000000000000a (STRSZ)              148 (bytes)
0x000000000000000b (SYMENT)             24 (bytes)
0x0000000000000015 (DEBUG)              0x0
0x0000000000000003 (PLTGOT)             0x3fb0
0x0000000000000002 (PLTRELSZ)           48 (bytes)
0x0000000000000014 (PLTREL)             RELA
0x0000000000000017 (JMPREL)             0x630
0x0000000000000007 (RELA)               0x570
0x0000000000000008 (RELASZ)             192 (bytes)
0x0000000000000009 (RELAENT)            24 (bytes)
0x000000000000001e (FLAGS)              BIND_NOW
0x000000006ffffffb (FLAGS_1)            Flags: NOW PIE
0x000000006ffffffe (VERNEED)            0x540
0x000000006fffffff (VERNEEDNUM)         1
0x000000006ffffff0 (VERSYM)             0x52c
0x000000006ffffff9 (RELACOUNT)          3
0x0000000000000000 (NULL)               0x0

其他的应该是极少数人需要的吧

标签:__,文件,PROGBITS,DEFAULT,GLOBAL,elf,0000000000000000,--,详细信息
From: https://www.cnblogs.com/guochaoxxl/p/17936603.html

相关文章

  • ELF段的查看
    使用命令readelf-l/usr/bin/chmod,结果:ElffiletypeisDYN(Position-IndependentExecutablefile)Entrypoint0x41e0Thereare13programheaders,startingatoffset64ProgramHeaders:TypeOffsetVirtAddrPhysAddrFileSiz......
  • 判断assets是否包含想要的文件
    publicbooleanisAssetExists(StringpathInAssetsDir){AssetManagerassetManager=AppContext.get().getResources().getAssets();InputStreaminputStream=null;try{inputStream=assetManager.open(pathInAssetsDir);if(null!=i......
  • 往虚拟机共享宿主机文件操作
    1、关闭系统2、打开编辑虚拟机设置;3、选择共享文件夹 4、选择位置   5、启动虚拟机,进入我的电脑,找到共享的文件  Reference:chun-xiaolin001,如何往虚拟机内传文件的3种方法,https://www.u72.net/zhishi/show-97228.html......
  • IP: dns-lookup : 查询域名的公网IP地址 解决 DNS域名解析绑架的问题例如访问 raw.git
    示例:https://github.com/orgs/community/discussions/42655https://github.com/mwaskom/seaborn-data/blob/2b29313169bf8dfa77d8dc930f7bd3eba559a906/dataset_names.txthttps://www.ip-lookup.org/dns-lookup/raw.githubusercontent.comIPDetailsDomain:Raw.githubuser......
  • linux 中实现仅对指定目录下的目录或者文件单独进行迭代
     001、测试目录如下,分别包含目录、文件[root@pc1test]#ls##测试目录dir1dir2dir3dir4file1file2file3file4 002、仅对目录进行迭代 a、[root@pc1test]#ls##测试目录dir1dir2di......
  • SpringBoot2 读取不同环境的配置文件实例
    SpringBoot 可以在application.properties 中配置信息spring.profiles.active来读取不同环境的配置文件。1.  SpringBoot2读取不同环境的配置文件工程运行环境可能有:开发环境、测试环境和生产环境,可以通过修改application.properties 来获取不同环境的的配置信息。首先我......
  • IDEA 中创建 Test 文件夹,Resources文件夹 等各种文件夹
    Sources文件夹里面放 Java 源文件,Test文件夹里面放测试的Java 源文件,Resources文件夹 里面放一些需要加载的配置,例如你使用SSM框架的xml配置文件。1. 第一步在右上角点击对应的 Project Structure(项目结构),如下图所示。2. 第二步点击 Modules。选择要设置的文件夹,点击......
  • 用python打开文件获取文件属性时,运行报错PermissionError: [Errno 13] Permission den
    一:概述在开发中我们经常会使用python程序去对物理主机平台上的文件进行操作,在这里说明一下,python中获取文件属性时,运行出现的错误。二:具体说明<1>获取文件属性的代码importos#创建一个临时目录temp_dir='temp'os.mkdir(temp_dir)#在临时目录中创建一个文件temp_file=o......
  • 下载文件报错:java.io.IOException: UT010029: Stream is closed
    在项目中使用EasyExcel导出excel然后压缩成压缩包下载,下载也是能正常下载就是会抛出这个错误虽然说这个错误不影响下载功能,搞不好就因为这个错误某天系统崩溃,那时候就不是这么好玩了,于是我在百度上疯狂查找有的说是流没有关,要在finally里面把流关了关了之后,满怀期待的重新运......
  • Laravel的基本配置文件 .env 文件
    默认情况下,.env文件包含以下参数APP_ENV=localAPP_DEBUG=trueAPP_KEY=base64:ZPt2wmKE/X4eEhrzJU6XX4R93rCwYG8E2f8QUA7kGK8=APP_URL=http://www.xhcj168.comDB_CONNECTION=mysqlDB_HOST=127.0.0.1DB_PORT=3306DB_DATABASE=homesteadDB_USERNAME=ho......