rizin/test/db/cmd/cmd_pipe
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

144 lines
6.5 KiB
Text
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

NAME=pipe args
FILE==
CMDS=#!pipe echo hello world
EXPECT=<<EOF
hello world
EOF
RUN
NAME=rzpipe.py
FILE=bins/elf/_Exit (42)
CMDS=<<EOF
?q `env~?^ASAN_LD_PRELOAD=`
?+ env LD_PRELOAD=`env ASAN_LD_PRELOAD`
#!pipe python3 scripts/get-funcs.py
EOF
EXPECT=<<EOF
Function names:
entry0
sym.imp._Exit
Disassembly of entry0:
;-- section..text:
;-- .text:
;-- _start():
/ entry0 ();
| 0x08049020 push ebp ; [09] -r-x section size 16 named .text
| 0x08049021 mov ebp, esp
| 0x08049023 sub esp, 8
| 0x08049026 sub esp, 0xc
| 0x08049029 push 0x2a ; '*' ; 42
\ 0x0804902b call sym.imp._Exit ; void _Exit(int status)
EOF
RUN
NAME=rzpipe load project
FILE=--
CMDS=<<EOF
?q `env~?^ASAN_LD_PRELOAD=`
?+ env LD_PRELOAD=`env ASAN_LD_PRELOAD`
!python3 -c 'import rzpipe;rz=rzpipe.open("--");rz.cmd("Po bins/other/ls.rzdb");print(rz.cmd("?v custom_main"))'
EOF
EXPECT=<<EOF
0x4070
EOF
RUN
NAME=rzpipe.py - shared memory (shm://)
FILE=bins/elf/_Exit (42)
CMDS=<<EOF
?q `env~?^ASAN_LD_PRELOAD=`
?+ env LD_PRELOAD=`env ASAN_LD_PRELOAD`
#!pipe python3 scripts/shared_memory.py
EOF
EXPECT=<<EOF
Copying bins/elf/_Exit (42)...
Copied bins/elf/_Exit (42) succesfully
-------------
Shared buffer size 0x360c
-------------
{'arch': 'x86', 'baddr': 134512640, 'binsz': 13073, 'bintype': 'elf', 'bits': 32, 'class': 'ELF32', 'compiler': 'GCC: (GNU) 9.2.1 20190827 (Red Hat 9.2.1-1)', 'endian': 'LE', 'intrp': '/lib/ld-linux.so.2', 'laddr': 0, 'lang': 'c++', 'machine': 'Intel 80386', 'maxopsz': 16, 'minopsz': 1, 'os': 'linux', 'pcalign': 0, 'relro': 'partial', 'rpath': 'NONE', 'subsys': 'linux', 'stripped': False, 'crypto': False, 'havecode': True, 'va': True, 'sanitiz': False, 'static': False, 'linenum': True, 'lsyms': True, 'canary': False, 'PIE': False, 'RELROCS': True, 'NX': True}
- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
0x08049020 5589 e583 ec08 83ec 0c6a 2ae8 e0ff ffff U........j*.....
0x08049020 1 16 entry0
0x08049010 1 6 sym.imp._Exit
;-- section..text:
;-- .text:
;-- _start():
/ entry0 ();
| 0x08049020 push ebp ; [09] -r-x section size 16 named .text
| 0x08049021 mov ebp, esp
| 0x08049023 sub esp, 8
| 0x08049026 sub esp, 0xc
| 0x08049029 push 0x2a ; '*' ; 42 ; int status
\ 0x0804902b call sym.imp._Exit ; void _Exit(int status)
Copying bins/pe/winver.exe...
Copied bins/pe/winver.exe succesfully
-------------
Shared buffer size 0x400
-------------
{'arch': 'x86', 'baddr': 4194304, 'binsz': 1024, 'bintype': 'pe', 'bits': 32, 'retguard': False, 'class': 'PE32', 'cmp.csum': '0x00005082', 'compiled': 'Thu Jan 1 00:00:00 1970 UTC', 'endian': 'LE', 'hdr.csum': '0x00000000', 'laddr': 0, 'lang': 'c', 'machine': 'i386', 'maxopsz': 16, 'minopsz': 1, 'os': 'windows', 'overlay': False, 'cc': 'cdecl', 'pcalign': 0, 'signed': False, 'subsys': 'Windows CUI', 'stripped': False, 'crypto': False, 'havecode': True, 'va': True, 'sanitiz': False, 'static': False, 'linenum': False, 'lsyms': False, 'canary': False, 'PIE': False, 'RELROCS': False, 'NX': False}
- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
0x00401000 6880 1040 00ff 15b4 1140 00ff 3590 1040 h..@.....@..5..@
0x00401000 1 58 entry0
;-- section.sect_0:
/ entry0 ();
| 0x00401000 push 0x401080 ; LPOSVERSIONINFOA lpVersionInformation ; [00] -rwx section size 4096 named sect_0
| 0x00401005 call dword [sym.imp.kernel32.dll_GetVersionExA] ; 0x4011b4 ; BOOL GetVersionExA(LPOSVERSIONINFOA lpVersionInformation)
| 0x0040100b push dword [0x401090]
| 0x00401011 push dword [0x40108c]
| 0x00401017 push dword [0x401088]
| 0x0040101d push dword [0x401084]
| 0x00401023 push str.a_PE_overriding_OS_values:_OS_Ver__i._i._i_PlatformID__i ; 0x40103c ; " * a PE overriding OS values: OS Ver %i.%i.%i PlatformID %i\n\n" ; const char *format
| 0x00401028 call dword [sym.imp.msvcrt.dll_printf] ; 0x4011bc ; int printf(const char *format)
| 0x0040102e add esp, 0x10
| 0x00401031 nop
| 0x00401032 push 0 ; UINT uExitCode
\ 0x00401034 call dword [sym.imp.kernel32.dll_ExitProcess] ; 0x4011b0 ; VOID ExitProcess(UINT uExitCode)
Copying bins/mach0/mach0_2-x86_64...
Copied bins/mach0/mach0_2-x86_64 succesfully
-------------
Shared buffer size 0x10e8
-------------
{'arch': 'x86', 'baddr': 4294967296, 'binsz': 4328, 'bintype': 'mach0', 'bits': 64, 'class': 'MACH064', 'endian': 'LE', 'intrp': '/usr/lib/dyld', 'laddr': 0, 'lang': 'c', 'machine': 'x86 64 all', 'maxopsz': 16, 'minopsz': 1, 'os': 'macos', 'pcalign': 0, 'subsys': 'darwin', 'stripped': False, 'crypto': False, 'havecode': True, 'va': True, 'sanitiz': False, 'static': False, 'linenum': False, 'lsyms': False, 'canary': False, 'PIE': True, 'RELROCS': False, 'NX': False}
- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
0x100000f70 5548 89e5 4883 ec10 c745 fc00 0000 0089 UH..H....E......
0x100000f70 1 36 entry0
0x100000f40 1 45 sym._foo
0x100000ef0 4 65 sym._bar
0x1000001d5 1 171 fcn.1000001d5
0x1000002e0 13 3088 -> 3110 fcn.1000002e0
;-- main:
;-- _main:
;-- func.100000f70:
/ entry0 (int64_t arg1, int64_t arg2);
| ; var int64_t var_10h @ rbp-0x10
| ; var int64_t var_8h @ rbp-0x8
| ; var int64_t var_4h @ rbp-0x4
| ; arg int64_t arg1 @ rdi
| ; arg int64_t arg2 @ rsi
| 0x100000f70 push rbp
| 0x100000f71 mov rbp, rsp
| 0x100000f74 sub rsp, 0x10
| 0x100000f78 mov dword [var_4h], 0
| 0x100000f7f mov dword [var_8h], edi ; arg1
| 0x100000f82 mov qword [var_10h], rsi ; arg2
| 0x100000f86 mov edi, dword [var_8h] ; int64_t arg1
| 0x100000f89 call sym._foo
| 0x100000f8e add rsp, 0x10
| 0x100000f92 pop rbp
\ 0x100000f93 ret
EOF
RUN