rizin/test/db/formats/elf/sections
Riccardo Schirone 27e0d7ae82
RzBin: improve handling of addresses in ELF (#2591)
* RzBin/ELF: avoid the creation of useless flags at 0

Use UT64_MAX as an error value for addresses like symbols, imports,
sections, etc., and do not create flags for those because they are not
meaningful. This is useful for imports that do not have an address in
the virtual/file space and for non-alloc sections (e.g. .comment).
2022-05-10 10:17:35 +08:00

176 lines
9.2 KiB
Text

NAME=sections list
FILE=bins/elf/analysis/main_wrong_sect
CMDS=iS;iSS
EXPECT=<<EOF
paddr size vaddr vsize align perm name type flags
-----------------------------------------------------------------------------------------
0x00000000 0x0 ---------- 0x0 0x0 ---- NULL
0x00000200 0x1c 0x00404500 0x1c 0x0 -r-- .interp PROGBITS alloc
0x0000021c 0x20 0x0040021c 0x20 0x0 -r-- .note.ABI-tag NOTE alloc
0x0000023c 0x24 0x0040023c 0x24 0x0 -r-- .note.gnu.build-id NOTE alloc
0x00000260 0x1c 0x00400260 0x1c 0x0 -r-- .gnu.hash GNU_HASH alloc
0x00000280 0x60 0x00400280 0x60 0x0 -r-- .dynsym DYNSYM alloc
0x000002e0 0x3d 0x004002e0 0x3d 0x0 -r-- .dynstr STRTAB alloc
0x0000031e 0x8 0x0040031e 0x8 0x0 -r-- .gnu.version VERSYM alloc
0x00000328 0x20 0x00400328 0x20 0x0 -r-- .gnu.version_r VERNEED alloc
0x00000348 0x18 0x00400348 0x18 0x0 -r-- .rela.dyn RELA alloc
0x00000360 0x48 0x00400360 0x48 0x0 -r-- .rela.plt RELA alloc
0x000003a8 0x1a 0x004003a8 0x1a 0x0 -r-x .init PROGBITS alloc,execute
0x000003d0 0x40 0x004003d0 0x40 0x0 -r-x .plt PROGBITS alloc,execute
0x00000410 0x1a2 0x00410570 0x1a2 0x0 -r-x .text PROGBITS alloc,execute
0x000005b4 0x9 0x004005b4 0x9 0x0 -r-x .fini PROGBITS alloc,execute
0x000005c0 0x10 0x004005c0 0x10 0x0 -r-- .rodata PROGBITS alloc
0x000005d0 0x34 0x004005d0 0x34 0x0 -r-- .eh_frame_hdr PROGBITS alloc
0x00000608 0xd4 0x00400608 0xd4 0x0 -r-- .eh_frame PROGBITS alloc
0x000006e0 0x8 0x006006e0 0x8 0x0 -rw- .init_array INIT_ARRAY write,alloc
0x000006e8 0x8 0x006006e8 0x8 0x0 -rw- .fini_array FINI_ARRAY write,alloc
0x000006f0 0x8 0x006006f0 0x8 0x0 -rw- .jcr PROGBITS write,alloc
0x000006f8 0x1d0 0x006006f8 0x1d0 0x0 -rw- .dynamic DYNAMIC write,alloc
0x000008c8 0x8 0x006008c8 0x8 0x0 -rw- .got PROGBITS write,alloc
0x000008d0 0x30 0x006008d0 0x30 0x0 -rw- .got.plt PROGBITS write,alloc
0x00000900 0x10 0x00600900 0x10 0x0 -rw- .data PROGBITS write,alloc
0x00000910 0x0 0x00600910 0x8 0x0 -rw- .bss NOBITS write,alloc
0x00000910 0x22 ---------- 0x22 0x0 ---- .comment PROGBITS merge,strings
0x00000940 0xd0 ---------- 0xd0 0x0 ---- .debug_aranges PROGBITS
0x00000a10 0x188 ---------- 0x188 0x0 ---- .debug_info PROGBITS
0x00000b98 0x76 ---------- 0x76 0x0 ---- .debug_abbrev PROGBITS
0x00000c0e 0x149 ---------- 0x149 0x0 ---- .debug_line PROGBITS
0x00000d57 0x8a ---------- 0x8a 0x0 ---- .debug_str PROGBITS merge,strings
0x00000df0 0x80 ---------- 0x80 0x0 ---- .debug_ranges PROGBITS
0x00000e70 0x156 ---------- 0x156 0x0 ---- .shstrtab STRTAB
0x000018c8 0x6d8 ---------- 0x6d8 0x0 ---- .symtab SYMTAB
0x00001fa0 0x23a ---------- 0x23a 0x0 ---- .strtab STRTAB
paddr size vaddr vsize align perm name
-------------------------------------------------------------
0x00000040 0x1c0 0x00400040 0x1c0 0x8 -r-x PHDR
0x00000200 0x1c 0x00400200 0x1c 0x1 -r-- INTERP
0x00000000 0x6dc 0x00400000 0x6dc 0x200000 -r-x LOAD0
0x000006e0 0x230 0x006006e0 0x238 0x200000 -rw- LOAD1
0x000006f8 0x1d0 0x006006f8 0x1d0 0x8 -rw- DYNAMIC
0x0000021c 0x44 0x0040021c 0x44 0x4 -r-- NOTE
0x000005d0 0x34 0x004005d0 0x34 0x4 -r-- GNU_EH_FRAME
0x00000000 0x0 0x00000000 0x0 0x10 -rw- GNU_STACK
0x00000000 0x40 0x00400000 0x40 0x0 -rw- ehdr
EOF
RUN
NAME=section text start (not mapped)
FILE=bins/elf/analysis/main_wrong_sect
CMDS=?v section..text
EXPECT=<<EOF
0x410570
EOF
RUN
NAME=only phdrs mapped
FILE=bins/elf/analysis/main_wrong_sect
CMDS=p8 10 @ section..text
EXPECT=<<EOF
ffffffffffffffffffff
EOF
RUN
NAME=also map ehdr if ET_REL
FILE=bins/elf/pngrutil_o
CMDS=oml
EXPECT=<<EOF
1 fd: 4 +0x00000000 0x0800870c - 0x080090c7 r-- vmap.reloc-targets
2 fd: 5 +0x00000034 0x08000034 * 0x080055c7 r-x vmap..text
3 fd: 3 +0x00007328 0x08007328 - 0x0800852f --x fmap..rel.text
4 fd: 5 +0x000055c8 0x080055c8 - 0x0800642b r-- vmap..rodata
5 fd: 3 +0x00008530 0x08008530 - 0x0800858f --- fmap..rel.rodata
6 fd: 3 +0x0000642c 0x0800642c - 0x08006461 --- fmap..comment
7 fd: 5 +0x00006464 0x08006464 - 0x080068cb r-- vmap..eh_frame
8 fd: 3 +0x00008590 0x08008590 - 0x0800869f --- fmap..rel.eh_frame
9 fd: 3 +0x000086a0 0x080086a0 - 0x08008702 --- fmap..shstrtab
10 fd: 3 +0x000068cc 0x080068cc - 0x08006e5b --- fmap..symtab
11 fd: 3 +0x00006e5c 0x08006e5c - 0x08007325 --- fmap..strtab
12 fd: 3 +0x00000000 0x08000000 - 0x08000033 r-- fmap.ehdr
EOF
RUN
NAME=true binary invalid section offset
FILE=bins/elf/true-invalid-section-offset
CMDS=iS
EXPECT=<<EOF
paddr size vaddr vsize align perm name type flags
--------------------------------------------------
EOF
RUN
NAME=disable sections load
FILE=bins/elf/analysis/hello-linux-x86_64
ARGS=-e log.level=4 -e elf.load.sections=false
CMDS=iS
EXPECT=<<EOF
paddr size vaddr vsize align perm name type flags
-----------------------------------------------------------------
0x000008d0 0x0 0x006008d0 0x0 0x0 ---- .got.plt NULL
0x00000348 0x18 0x00400348 0x18 0x0 ---- .rela.dyn NULL
0x00000360 0x48 0x00400360 0x48 0x0 ---- .rela.plt NULL
EOF
RUN
NAME=disable sections checks
FILE=bins/elf/libmemalloc-dump-mem
ARGS=-e log.level=4 -e elf.checks.sections=false
CMDS=iS
EXPECT=<<EOF
paddr size vaddr vsize align perm name type flags
------------------------------------------------------------------------------------------------------------------------------------------------------------
0x67006570 0x6d007570 ---------- 0x6d007570 0x0 --w- invalid0 LOPROC+0x036f706d write,strings,info,TLS
0x6568206d 0x6c007061 ---------- 0x6c007061 0x0 ---x invalid1 0x206b6361 execute,merge,strings,info,extra_os_processing_reqd,group,TLS,compressed
0x61705f65 0x6e696464 ---------- 0x6e696464 0x0 --wx invalid2 LOPROC+0x0475706d write,execute,strings,info,extra_os_processing_reqd,group,TLS,compressed
0x65757274 0x6f207700 ---------- 0x6f207700 0x0 --wx invalid3 0x6d5f6266 write,execute,strings,info,extra_os_processing_reqd,TLS,compressed
0x68746469 0x20736920 0x77007461 0x20736920 0x0 -r-x invalid4 0x20323156 alloc,execute,strings,info,extra_os_processing_reqd,group,TLS,compressed
0x66754220 0x73726566 0x3a732500 0x73726566 0x0 -r-- invalid5 0x6f662050 alloc,merge,strings,info,extra_os_processing_reqd,TLS,compressed
0x2020424f 0x20202020 0x4c425f54 0x20202020 0x0 -rwx invalid6 0x465f4c45 write,alloc,execute,info,group
0x313d3d74 0x6e750020 0x68676965 0x6e750020 0x0 -r-x invalid7 0x61682074 alloc,execute,merge,strings,info,extra_os_processing_reqd,TLS
0x6c61203a 0x61636f6c ---------- 0x61636f6c 0x0 ---- invalid8 0x3a74616d strings
0x69537265 0x6e41657a 0x66667542 0x6e41657a 0x0 -r-- invalid9 0x300726f alloc,extra_os_processing_reqd,group,TLS
0x00000000 0x0 ---------- 0x0 0x0 ---- invalid10 LOPROC+0x02656666
0x00000000 0x0 ---------- 0x0 0x0 ---- invalid11 NULL
0x00000000 0x0 ---------- 0x0 0x0 ---- invalid12 NULL
0x00000000 0x0 ---------- 0x0 0x0 ---- invalid13 NULL
0x00000000 0x0 ---------- 0x0 0x0 ---- invalid14 NULL
0x00000000 0x0 ---------- 0x0 0x0 ---- invalid15 NULL
0x00000000 0x0 ---------- 0x0 0x0 ---- invalid16 NULL
0x00000000 0x0 ---------- 0x0 0x0 ---- invalid17 NULL
0x00000000 0x0 ---------- 0x0 0x0 ---- invalid18 NULL
0x00000000 0x0 ---------- 0x0 0x0 ---- invalid19 NULL
0x00000000 0x0 ---------- 0x0 0x0 ---- invalid20 NULL
0x00000000 0x0 ---------- 0x0 0x0 ---- invalid21 NULL
0x00000000 0x0 ---------- 0x0 0x0 ---- invalid22 NULL
EOF
EXPECT_ERR=<<EOF
WARNING: Invalid strtab at 0x0 (check array failed).
WARNING: Failed to initialize section string table.
EOF
RUN
NAME=disable segments checks
FILE=bins/elf/analysis/tiny.elf
ARGS=-e log.level=4 -e elf.checks.segments=false
CMDS=iS
EXPECT=<<EOF
paddr size vaddr vsize align perm name type flags
--------------------------------------------------
EOF
EXPECT_ERR=<<EOF
WARNING: Failed to read ELF header (e_phnum).
WARNING: Failed to read ELF header (e_shentsize).
WARNING: Failed to read ELF header (e_shnum).
WARNING: Failed to read ELF header (e_shstrndx).
WARNING: The binary seems to be a tiny elf (45 bytes). Reload e_phnum value.
WARNING: Failed to initialize section header.
EOF
RUN
NAME=more than 65535 segments
FILE=gzip://bins/elf/core/more-than-65535-segments.gz
CMDS=iSS~?
TIMEOUT=2040
EXPECT=<<EOF
131073
EOF
RUN