NAME=baddr ==
FILE=bins/elf/analysis/hello-linux-x86_64
CMDS=!rz-bin -qe ${RZ_FILE};!rz-bin -B 0x400000 -qe ${RZ_FILE}
EXPECT=<<EOF
0x00400410
0x00400410
EOF
RUN

NAME=baddr > 0
FILE=bins/elf/analysis/hello-linux-x86_64
CMDS=!rz-bin -qe ${RZ_FILE};!rz-bin -B 0x800000 -qe ${RZ_FILE}
EXPECT=<<EOF
0x00400410
0x00800410
EOF
RUN

NAME=baddr 0
FILE=bins/elf/analysis/hello-linux-x86_64
CMDS=!rz-bin -qe ${RZ_FILE};!rz-bin -B 0 -qe ${RZ_FILE}
EXPECT=<<EOF
0x00400410
0x00000410
EOF
RUN

NAME=laddr 0
FILE=bins/elf/analysis/hello-linux-x86_64
CMDS=!rz-bin -G 0 -e ${RZ_FILE}
EXPECT=<<EOF
[Entrypoints]
vaddr=0x00400410 paddr=0x00000410 haddr=0x00000018 hvaddr=0x00400018 type=program

1 entrypoints
EOF
RUN

NAME=laddr 0 && baddr 0
FILE=bins/elf/analysis/hello-linux-x86_64
CMDS=!rz-bin -G 0 -B 0 -e ${RZ_FILE}
EXPECT=<<EOF
[Entrypoints]
vaddr=0x00000410 paddr=0x00000410 haddr=0x00000018 hvaddr=0x00000018 type=program

1 entrypoints
EOF
RUN

NAME=rz-bin -k file
FILE=bins/elf/analysis/hello-linux-x86_64
CMDS=!rz-bin -k ${RZ_FILE}
EXPECT=<<EOF
EOF
EXPECT_ERR=<<EOF
Missing file.
EOF
RUN

NAME=rz-bin -K md5 -S file
FILE=bins/pe/a.exe
CMDS=!rz-bin -K md5 -S ${RZ_FILE}
EXPECT=<<EOF
[Sections]

nth paddr        size vaddr        vsize perm md5                              name
-----------------------------------------------------------------------------------
0   0x00000400  0xa00 0x00401000  0x1000 -r-x 3d6a5b8dc5e41b09659638ad5735e5b5 .text
1   0x00000e00  0x200 0x00402000  0x1000 -rw- b3c542ba67f2d1a949fa1a25ce22f7e3 .data
2   0x00001000  0x200 0x00403000  0x1000 -r-- c9a877a4e945b087b8323830442c88d6 .rdata
3   0x00000000    0x0 0x00404000  0x1000 -rw- d41d8cd98f00b204e9800998ecf8427e .bss
4   0x00001200  0x400 0x00405000  0x1000 -rw- 963212dc58a74f32e0f6ffce84dcf7ea .idata

EOF
RUN

NAME=rz-bin -s file pe
FILE=bins/pe/a.exe
CMDS=!rz-bin -s ${RZ_FILE}|wc -l|awk "{print \$1}"
EXPECT=<<EOF
24
EOF
RUN

NAME=rz-bin -s file elf
FILE=bins/elf/analysis/x86-helloworld-gcc
CMDS=!rz-bin -s ${RZ_FILE}|wc -l|awk "{print \$1}"
EXPECT=<<EOF
69
EOF
RUN

NAME=rz-bin -S, -SS, -rS and -rSS file elf
FILE=bins/elf/analysis/x86-helloworld-gcc
CMDS=<<EOF
!rz-bin -S ${RZ_FILE}|wc -l|awk "{print \$1}"
!rz-bin -SS ${RZ_FILE}|wc -l|awk "{print \$1}"
!env RZ_BIN_PREFIX=prixfixe rz-bin -S ${RZ_FILE}
!env RZ_BIN_PREFIX=prixfixe rz-bin -SS ${RZ_FILE}
EOF
EXPECT=<<EOF
35
14
[Sections]

nth paddr        size vaddr       vsize perm name
-------------------------------------------------
0   0x00000000    0x0 0x00000000    0x0 ---- prixfixe.
1   0x00000134   0x13 0x08048134   0x13 -r-- prixfixe..interp
2   0x00000148   0x20 0x08048148   0x20 -r-- prixfixe..note.ABI_tag
3   0x00000168   0x24 0x08048168   0x24 -r-- prixfixe..note.gnu.build_id
4   0x0000018c   0x20 0x0804818c   0x20 -r-- prixfixe..gnu.hash
5   0x000001ac   0x50 0x080481ac   0x50 -r-- prixfixe..dynsym
6   0x000001fc   0x4a 0x080481fc   0x4a -r-- prixfixe..dynstr
7   0x00000246    0xa 0x08048246    0xa -r-- prixfixe..gnu.version
8   0x00000250   0x20 0x08048250   0x20 -r-- prixfixe..gnu.version_r
9   0x00000270    0x8 0x08048270    0x8 -r-- prixfixe..rel.dyn
10  0x00000278   0x18 0x08048278   0x18 -r-- prixfixe..rel.plt
11  0x00000290   0x23 0x08048290   0x23 -r-x prixfixe..init
12  0x000002c0   0x40 0x080482c0   0x40 -r-x prixfixe..plt
13  0x00000300  0x194 0x08048300  0x194 -r-x prixfixe..text
14  0x00000494   0x14 0x08048494   0x14 -r-x prixfixe..fini
15  0x000004a8   0x15 0x080484a8   0x15 -r-- prixfixe..rodata
16  0x000004c0   0x2c 0x080484c0   0x2c -r-- prixfixe..eh_frame_hdr
17  0x000004ec   0xb0 0x080484ec   0xb0 -r-- prixfixe..eh_frame
18  0x0000059c    0x4 0x0804959c    0x4 -rw- prixfixe..init_array
19  0x000005a0    0x4 0x080495a0    0x4 -rw- prixfixe..fini_array
20  0x000005a4    0x4 0x080495a4    0x4 -rw- prixfixe..jcr
21  0x000005a8   0xe8 0x080495a8   0xe8 -rw- prixfixe..dynamic
22  0x00000690    0x4 0x08049690    0x4 -rw- prixfixe..got
23  0x00000694   0x18 0x08049694   0x18 -rw- prixfixe..got.plt
24  0x000006ac    0x8 0x080496ac    0x8 -rw- prixfixe..data
25  0x000006b4    0x0 0x080496b4    0x4 -rw- prixfixe..bss
26  0x000006b4   0x11 0x00000000   0x11 ---- prixfixe..comment
27  0x000006c5  0x106 0x00000000  0x106 ---- prixfixe..shstrtab
28  0x00000c7c  0x450 0x00000000  0x450 ---- prixfixe..symtab
29  0x000010cc  0x257 0x00000000  0x257 ---- prixfixe..strtab

[Segments]

nth paddr        size vaddr       vsize perm name
-------------------------------------------------
0   0x00000034  0x100 0x08048034  0x100 -r-x prixfixe.PHDR
1   0x00000134   0x13 0x08048134   0x13 -r-- prixfixe.INTERP
2   0x00000000  0x59c 0x08048000  0x59c -r-x prixfixe.LOAD0
3   0x0000059c  0x118 0x0804959c  0x11c -rw- prixfixe.LOAD1
4   0x000005a8   0xe8 0x080495a8   0xe8 -rw- prixfixe.DYNAMIC
5   0x00000148   0x44 0x08048148   0x44 -r-- prixfixe.NOTE
6   0x000004c0   0x2c 0x080484c0   0x2c -r-- prixfixe.GNU_EH_FRAME
7   0x00000000    0x0 0x00000000    0x0 -rw- prixfixe.GNU_STACK
8   0x00000000   0x34 0x08048000   0x34 -rw- prixfixe.ehdr

EOF
RUN

NAME=rz-bin -SSS
FILE=bins/elf/analysis/x86-helloworld-gcc
CMDS=!rz-bin -SSS ${RZ_FILE}|wc -l|awk "{print \$1}"
EXPECT=<<EOF
13
EOF
RUN

NAME=rz-bin -z pe
FILE=bins/pe/a.exe
CMDS=!rz-bin -z ${RZ_FILE}|wc -l|awk "{print \$1}"
EXPECT=<<EOF
7
EOF
RUN

NAME=rz-bin -zz pe
FILE=bins/pe/ioli/w32/crackme0x00.exe
CMDS=!rz-bin -zz ${RZ_FILE} | grep "Password:"
EXPECT=<<EOF
86  0x00002619 0x00404019 10  11   .rdata  ascii   Password: 
EOF
RUN

NAME=rz-bin -zzz pe
FILE=bins/pe/ioli/w32/crackme0x00.exe
CMDS=!rz-bin -zzz ${RZ_FILE} | grep "Password:"
EXPECT=<<EOF
086 0x00002619 0x00404019  10  11 (.rdata) ascii Password: 
EOF
RUN

NAME=rz-bin -zzq pe
FILE=bins/pe/ioli/w32/crackme0x00.exe
CMDS=!rz-bin -zzq ${RZ_FILE} | grep "Password:"
EXPECT=<<EOF
0x404019 11 10 Password: 
EOF
RUN

NAME=rz-bin -zzzq pe
FILE=bins/pe/ioli/w32/crackme0x00.exe
CMDS=!rz-bin -zzzq ${RZ_FILE} | grep "Password:"
EXPECT=<<EOF
0x00404019 Password: 
EOF
RUN

NAME=rz-bin -zzqq pe
FILE=bins/pe/ioli/w32/crackme0x00.exe
CMDS=!rz-bin -zzqq ${RZ_FILE} | grep "Password:"
EXPECT=<<EOF
Password: 
EOF
RUN

NAME=rz-bin -zzzqq pe
FILE=bins/pe/ioli/w32/crackme0x00.exe
CMDS=!rz-bin -zzzqq ${RZ_FILE} | grep "Password:"
EXPECT=<<EOF
Password: 
EOF
RUN

NAME=rz-bin -z elf
FILE=bins/elf/analysis/x86-helloworld-gcc
CMDS=!rz-bin -z ${RZ_FILE}|wc -l|awk "{print \$1}"
EXPECT=<<EOF
4
EOF
RUN

NAME=rz-bin -G 0x1000 -rs fatmach0
FILE=bins/mach0/fatmach0-3true
CMDS=!rz-bin -G 0x1000 -rs ${RZ_FILE}|grep "f " | wc -l|awk "{print \$1}"
EXPECT=<<EOF
3
EOF
RUN

NAME=rz-bin -G 0x1300 -rs fatmach0
FILE=bins/mach0/fatmach0-3true
CMDS=!rz-bin -G 0x1300 -rs ${RZ_FILE}|wc -l|awk "{print \$1}"
EXPECT=<<EOF
1
EOF
RUN

NAME=rz-bin -G 0x1000 -e fatmach0
FILE=bins/mach0/fatmach0-3true
CMDS=!rz-bin -G 0x1000 -e ${RZ_FILE}
EXPECT=<<EOF
[Entrypoints]
vaddr=0x100000ef8 paddr=0x00001ef8 haddr=0x00000570 type=program

1 entrypoints
EOF
RUN

NAME=rz-bin -e fatmach0
BROKEN=1
FILE=bins/mach0/fatmach0-3true
CMDS=!rz-bin -e ${RZ_FILE}
EXPECT=<<EOF
[Entrypoints]
vaddr=0x100000ef8 paddr=0x00001ef8 baddr=0x100000000 laddr=0x00001000 haddr=0x00000570 type=program

1 entrypoints
EOF
RUN

NAME=rz-bin -G 0x5000 -e fatmach0
FILE=bins/mach0/fatmach0-3true
CMDS=!rz-bin -G 0x5000 -e ${RZ_FILE}
EXPECT=<<EOF
[Entrypoints]
vaddr=0x00001f44 paddr=0x00005f44 haddr=0x00000420 type=program

1 entrypoints
EOF
RUN

NAME=rz-bin -a x86 -b 32 -e fatmach0
BROKEN=1
FILE=bins/mach0/fatmach0-3true
CMDS=!rz-bin -a x86 -b 32 -e ${RZ_FILE}
EXPECT=<<EOF
[Entrypoints]
vaddr=0x00001f44 paddr=0x00005f44 baddr=0x00001000 laddr=0x00005000 haddr=0x00000420 type=program

1 entrypoints
EOF
RUN

NAME=rz-bin -B 0x2000000 -G 0x1000 -e fatmach0
FILE=bins/mach0/fatmach0-3true
CMDS=!rz-bin -B 0x2000000 -G 0x1000 -e ${RZ_FILE}
EXPECT=<<EOF
[Entrypoints]
vaddr=0x02000ef8 paddr=0x00001ef8 haddr=0x00000570 type=program

1 entrypoints
EOF
RUN

NAME=TODO: test on pie fatmach0
BROKEN=1
FILE=bins/mach0/fatmach0-3true
CMDS=!rz-bin -B 0x2000000 -G 0x1000 -e ${RZ_FILE}
EXPECT=<<EOF
???
EOF
RUN

NAME=rz-bin -B 0x2000000 -e arm64
FILE=bins/mach0/hello-ios-arm64
CMDS=!rz-bin -B 0x2000000 -e ${RZ_FILE}
EXPECT=<<EOF
[Entrypoints]
vaddr=0x02007f34 paddr=0x00007f34 haddr=0x00000468 type=program

1 entrypoints
EOF
RUN

NAME=rz-bin -a x86 -b 32 -i fatmach0
FILE=bins/mach0/fatmach0-3true
CMDS=!rz-bin -a x86 -b 32 -i ${RZ_FILE}
EXPECT=<<EOF
[Imports]
nth vaddr      bind type lib name
---------------------------------
0   0x00001f94 NONE FUNC     exit
1   0x00000000 NONE FUNC     dyld_stub_binder

EOF
RUN

NAME=rz-bin -G 0x5000 -i fatmach0
FILE=bins/mach0/fatmach0-3true
CMDS=!rz-bin -G 0x5000 -i ${RZ_FILE}
EXPECT=<<EOF
[Imports]
nth vaddr      bind type lib name
---------------------------------
0   0x00001f94 NONE FUNC     exit
1   0x00000000 NONE FUNC     dyld_stub_binder

EOF
RUN

NAME=rz-bin -qqz
FILE=bins/elf/analysis/hello-linux-x86_64
CMDS=!rz-bin -qqz ${RZ_FILE}
EXPECT=<<EOF
Hello World
EOF
RUN

NAME=rz-bin -qqzz
FILE=bins/elf/analysis/hello-linux-x86_64
CMDS=<<EOF
!!rz-bin -qqzz ${RZ_FILE}~do_global_dtors_aux_fini_array_entry
!!rz-bin -qqzz ${RZ_FILE}~?
EOF
EXPECT=<<EOF
__do_global_dtors_aux_fini_array_entry
82
EOF
RUN

NAME=rz-bin -qqzzz
FILE=bins/elf/analysis/hello-linux-x86_64
CMDS=<<EOF
!!rz-bin -qqzzz ${RZ_FILE}~do_global_dtors_aux_fini_array_entry
!!rz-bin -qqzzz ${RZ_FILE}~?
EOF
EXPECT=<<EOF
__do_global_dtors_aux_fini_array_entry
82
EOF
RUN

NAME=rz-bin -qOr
FILE=bins/elf/analysis/ls-linux-x86_64-zlul
CMDS=<<EOF
!rz-bin -qOr/.data/-1 ${FILE}
!rz-bin -qOr/.data/-1 ${FILE}
EOF
EXPECT=<<EOF
EOF
RUN

NAME=rz-bin -qOp/.data/rwx on PE32
FILE=bins/pe/test.exe
CMDS=<<EOF
mkdir .tmp
rm .tmp/rz-bintestpe1.exe
!rz-bin -qOp/.data/rwx -o.tmp/rz-bintestpe1.exe ${RZ_FILE}
!rz-bin -S .tmp/rz-bintestpe1.exe
rm .tmp/rz-bintestpe1.exe
EOF
EXPECT=<<EOF
wx e0000040 @ 0x244
[Sections]

nth paddr         size vaddr        vsize perm name
---------------------------------------------------
0   0x00000400  0x8a00 0x00401000  0x9000 -r-x .text
1   0x00008e00  0x2400 0x0040a000  0x3000 -r-- .rdata
2   0x0000b200  0x1000 0x0040d000  0x3000 -rwx .data
3   0x0000c200   0x200 0x00410000  0x1000 -r-- .rsrc
4   0x0000c400   0xe00 0x00411000  0x1000 -r-- .reloc

EOF
RUN

NAME=rz-bin -qOp//8 on PE32+
FILE=bins/pe/normal64.exe
CMDS=<<EOF
mkdir .tmp
rm .tmp/rz-bintestpe2.exe
!rz-bin -qOp//8 -o.tmp/rz-bintestpe2.exe ${RZ_FILE}
!rz-bin -S .tmp/rz-bintestpe2.exe
rm .tmp/rz-bintestpe2.exe
EOF
EXPECT=<<EOF
wx 10000000 @ 0x16c
[Sections]

nth paddr        size vaddr        vsize perm name
--------------------------------------------------
0   0x00000200  0x200 0x00401000  0x1000 s--- sect_0

EOF
RUN

NAME=rz-bin -ee -j
FILE=bins/elf/analysis/x86-helloworld-gcc
CMDS=!!rz-bin -ee -j ${RZ_FILE}~{}
EXPECT=<<EOF
{
  "initfini": [
    {
      "vaddr": 134513616,
      "paddr": 976,
      "baddr": 134512640,
      "laddr": 0,
      "hvaddr": 134518172,
      "hpaddr": 1436,
      "type": "init"
    },
    {
      "vaddr": 134513584,
      "paddr": 944,
      "baddr": 134512640,
      "laddr": 0,
      "hvaddr": 134518176,
      "hpaddr": 1440,
      "type": "fini"
    }
  ]
}
EOF
RUN

NAME=-ee baddr 0
FILE=bins/elf/analysis/x86-helloworld-gcc
CMDS=!rz-bin -ee -B 0 ${RZ_FILE}
EXPECT=<<EOF
[Constructors]
vaddr=0x000003d0 paddr=0x000003d0 hvaddr=0x0000159c hpaddr=0x0000059c type=init
vaddr=0x000003b0 paddr=0x000003b0 hvaddr=0x000015a0 hpaddr=0x000005a0 type=fini

2 entrypoints
EOF
RUN

NAME=rz-bin -g
FILE=bins/elf/analysis/x86-helloworld-gcc
CMDS=!rz-bin -g ${RZ_FILE}
EXPECT=<<EOF
[Sections]

nth paddr        size vaddr       vsize perm name
-------------------------------------------------
0   0x00000000    0x0 0x00000000    0x0 ---- 
1   0x00000134   0x13 0x08048134   0x13 -r-- .interp
2   0x00000148   0x20 0x08048148   0x20 -r-- .note.ABI_tag
3   0x00000168   0x24 0x08048168   0x24 -r-- .note.gnu.build_id
4   0x0000018c   0x20 0x0804818c   0x20 -r-- .gnu.hash
5   0x000001ac   0x50 0x080481ac   0x50 -r-- .dynsym
6   0x000001fc   0x4a 0x080481fc   0x4a -r-- .dynstr
7   0x00000246    0xa 0x08048246    0xa -r-- .gnu.version
8   0x00000250   0x20 0x08048250   0x20 -r-- .gnu.version_r
9   0x00000270    0x8 0x08048270    0x8 -r-- .rel.dyn
10  0x00000278   0x18 0x08048278   0x18 -r-- .rel.plt
11  0x00000290   0x23 0x08048290   0x23 -r-x .init
12  0x000002c0   0x40 0x080482c0   0x40 -r-x .plt
13  0x00000300  0x194 0x08048300  0x194 -r-x .text
14  0x00000494   0x14 0x08048494   0x14 -r-x .fini
15  0x000004a8   0x15 0x080484a8   0x15 -r-- .rodata
16  0x000004c0   0x2c 0x080484c0   0x2c -r-- .eh_frame_hdr
17  0x000004ec   0xb0 0x080484ec   0xb0 -r-- .eh_frame
18  0x0000059c    0x4 0x0804959c    0x4 -rw- .init_array
19  0x000005a0    0x4 0x080495a0    0x4 -rw- .fini_array
20  0x000005a4    0x4 0x080495a4    0x4 -rw- .jcr
21  0x000005a8   0xe8 0x080495a8   0xe8 -rw- .dynamic
22  0x00000690    0x4 0x08049690    0x4 -rw- .got
23  0x00000694   0x18 0x08049694   0x18 -rw- .got.plt
24  0x000006ac    0x8 0x080496ac    0x8 -rw- .data
25  0x000006b4    0x0 0x080496b4    0x4 -rw- .bss
26  0x000006b4   0x11 0x00000000   0x11 ---- .comment
27  0x000006c5  0x106 0x00000000  0x106 ---- .shstrtab
28  0x00000c7c  0x450 0x00000000  0x450 ---- .symtab
29  0x000010cc  0x257 0x00000000  0x257 ---- .strtab

[Segments]

nth paddr        size vaddr       vsize perm name
-------------------------------------------------
0   0x00000034  0x100 0x08048034  0x100 -r-x PHDR
1   0x00000134   0x13 0x08048134   0x13 -r-- INTERP
2   0x00000000  0x59c 0x08048000  0x59c -r-x LOAD0
3   0x0000059c  0x118 0x0804959c  0x11c -rw- LOAD1
4   0x000005a8   0xe8 0x080495a8   0xe8 -rw- DYNAMIC
5   0x00000148   0x44 0x08048148   0x44 -r-- NOTE
6   0x000004c0   0x2c 0x080484c0   0x2c -r-- GNU_EH_FRAME
7   0x00000000    0x0 0x00000000    0x0 -rw- GNU_STACK
8   0x00000000   0x34 0x08048000   0x34 -rw- ehdr

[Entrypoints]
vaddr=0x08048300 paddr=0x00000300 haddr=0x00000018 hvaddr=0x08048018 type=program

1 entrypoints
[Constructors]
vaddr=0x080483d0 paddr=0x000003d0 hvaddr=0x0804959c hpaddr=0x0000059c type=init
vaddr=0x080483b0 paddr=0x000003b0 hvaddr=0x080495a0 hpaddr=0x000005a0 type=fini

2 entrypoints
[Main]
vaddr=0x08048400 paddr=0x00000400
[Imports]
nth vaddr      bind   type   lib name
-------------------------------------
1   0x080482d0 GLOBAL FUNC       puts
2   0x080482e0 WEAK   NOTYPE     __gmon_start__
3   0x080482f0 GLOBAL FUNC       __libc_start_main

[Symbols]

nth paddr       vaddr      bind   type   size lib name
------------------------------------------------------
4    0x000004ac 0x080484ac GLOBAL OBJ    4        _IO_stdin_used
1    0x00000134 0x08048134 LOCAL  SECT   0        .interp
2    0x00000148 0x08048148 LOCAL  SECT   0        .note.ABI-tag
3    0x00000168 0x08048168 LOCAL  SECT   0        .note.gnu.build-id
4    0x0000018c 0x0804818c LOCAL  SECT   0        .gnu.hash
5    0x000001ac 0x080481ac LOCAL  SECT   0        .dynsym
6    0x000001fc 0x080481fc LOCAL  SECT   0        .dynstr
7    0x00000246 0x08048246 LOCAL  SECT   0        .gnu.version
8    0x00000250 0x08048250 LOCAL  SECT   0        .gnu.version_r
9    0x00000270 0x08048270 LOCAL  SECT   0        .rel.dyn
10   0x00000278 0x08048278 LOCAL  SECT   0        .rel.plt
11   0x00000290 0x08048290 LOCAL  SECT   0        .init
12   0x000002c0 0x080482c0 LOCAL  SECT   0        .plt
13   0x00000300 0x08048300 LOCAL  SECT   0        .text
14   0x00000494 0x08048494 LOCAL  SECT   0        .fini
15   0x000004a8 0x080484a8 LOCAL  SECT   0        .rodata
16   0x000004c0 0x080484c0 LOCAL  SECT   0        .eh_frame_hdr
17   0x000004ec 0x080484ec LOCAL  SECT   0        .eh_frame
18   0x0000059c 0x0804959c LOCAL  SECT   0        .init_array
19   0x000005a0 0x080495a0 LOCAL  SECT   0        .fini_array
20   0x000005a4 0x080495a4 LOCAL  SECT   0        .jcr
21   0x000005a8 0x080495a8 LOCAL  SECT   0        .dynamic
22   0x00000690 0x08049690 LOCAL  SECT   0        .got
23   0x00000694 0x08049694 LOCAL  SECT   0        .got.plt
24   0x000006ac 0x080496ac LOCAL  SECT   0        .data
25   ---------- 0x080496b4 LOCAL  SECT   0        .bss
26   ---------- 0x00000000 LOCAL  SECT   0        .comment
27   ---------- 0x00000000 LOCAL  FILE   0        init.c
28   ---------- 0x00000000 LOCAL  FILE   0        
29   ---------- 0x00000000 LOCAL  FILE   0        crtstuff.c
30   0x000005a4 0x080495a4 LOCAL  OBJ    0        __JCR_LIST__
31   0x00000340 0x08048340 LOCAL  FUNC   0        deregister_tm_clones
32   0x00000370 0x08048370 LOCAL  FUNC   0        register_tm_clones
33   0x000003b0 0x080483b0 LOCAL  FUNC   0        __do_global_dtors_aux
34   ---------- 0x080496b4 LOCAL  OBJ    1        completed.5979
35   0x000005a0 0x080495a0 LOCAL  OBJ    0        __do_global_dtors_aux_fini_array_entry
36   0x000003d0 0x080483d0 LOCAL  FUNC   0        frame_dummy
37   0x0000059c 0x0804959c LOCAL  OBJ    0        __frame_dummy_init_array_entry
38   ---------- 0x00000000 LOCAL  FILE   0        hello.c
39   ---------- 0x00000000 LOCAL  FILE   0        crtstuff.c
40   0x00000598 0x08048598 LOCAL  OBJ    0        __FRAME_END__
41   0x000005a4 0x080495a4 LOCAL  OBJ    0        __JCR_END__
42   ---------- 0x00000000 LOCAL  FILE   0        
43   0x000005a0 0x080495a0 LOCAL  NOTYPE 0        __init_array_end
44   0x000005a8 0x080495a8 LOCAL  OBJ    0        _DYNAMIC
45   0x0000059c 0x0804959c LOCAL  NOTYPE 0        __init_array_start
46   0x00000694 0x08049694 LOCAL  OBJ    0        _GLOBAL_OFFSET_TABLE_
47   0x00000490 0x08048490 GLOBAL FUNC   2        __libc_csu_fini
49   0x00000330 0x08048330 GLOBAL FUNC   4        __x86.get_pc_thunk.bx
50   0x000006ac 0x080496ac WEAK   NOTYPE 0        data_start
51   ---------- 0x080496b4 GLOBAL NOTYPE 0        _edata
52   0x00000494 0x08048494 GLOBAL FUNC   0        _fini
53   0x000006ac 0x080496ac GLOBAL NOTYPE 0        __data_start
56   0x000006b0 0x080496b0 GLOBAL OBJ    0        __dso_handle
59   0x00000420 0x08048420 GLOBAL FUNC   97       __libc_csu_init
60   ---------- 0x080496b8 GLOBAL NOTYPE 0        _end
61   0x00000300 0x08048300 GLOBAL FUNC   0        _start
62   0x000004a8 0x080484a8 GLOBAL OBJ    4        _fp_hw
63   ---------- 0x080496b4 GLOBAL NOTYPE 0        __bss_start
64   0x00000400 0x08048400 GLOBAL FUNC   28       main
66   ---------- 0x080496b4 GLOBAL OBJ    0        __TMC_END__
68   0x00000290 0x08048290 GLOBAL FUNC   0        _init
1    0x000002d0 0x080482d0 GLOBAL FUNC   16       imp.puts
2    0x000002e0 0x080482e0 WEAK   NOTYPE 16       imp.__gmon_start__
3    0x000002f0 0x080482f0 GLOBAL FUNC   16       imp.__libc_start_main
[Strings]
nth paddr      vaddr      len size section type  string
-------------------------------------------------------
0   0x000004b0 0x080484b0 12  13   .rodata ascii Hello world!
arch     x86
baddr    0x8048000
binsz    4899
bintype  elf
bits     32
canary   false
class    ELF32
compiler GCC: (GNU) 4.8.2
crypto   false
endian   little
havecode true
intrp    /lib/ld-linux.so.2
laddr    0x0
lang     c
linenum  true
lsyms    true
machine  Intel 80386
maxopsz  16
minopsz  1
nx       true
os       linux
pcalign  0
pic      false
relocs   true
relro    no
rpath    NONE
sanitiz  false
static   false
stripped false
subsys   linux
va       true
0x00000000  ELF MAGIC   0x464c457f
0x00000010  Type        0x0002
0x00000012  Machine     0x0003
0x00000014  Version     0x00000001
0x00000018  Entrypoint  0x08048300
0x0000001c  PhOff       0x00000034
0x00000020  ShOff       0x000007cc
0x00000024  Flags       0x00000000
0x00000028  EhSize      52
0x0000002a  PhentSize   32
0x0000002c  PhNum       8
0x0000002e  ShentSize   40
0x00000030  ShNum       30
0x00000032  ShrStrndx   27
[Linked libraries]
libc.so.6

1 library
[Relocations]

vaddr      paddr      type   name
---------------------------------
0x08049690 0x00000690 SET_32 __gmon_start__
0x080496a0 0x000006a0 SET_32 puts
0x080496a4 0x000006a4 SET_32 __gmon_start__
0x080496a8 0x000006a8 SET_32 __libc_start_main


4 relocations
4899
Version symbols section '.gnu.version' contains 5 entries:
 Addr: 0x08048246  Offset: 0x00000246  Link: 5 (.dynsym)
  0x00000000: 0 (*local*)
  0x00000001: 2 (GLIBC_2.0)
  0x00000002: 0 (*local*)
  0x00000003: 2 (GLIBC_2.0)
  0x00000004: 1 (*global*)


Version need section '.gnu.version_r' contains 1 entries:
 Addr: 0x08048250  Offset: 0x00000250  Link to section: 6 (.dynstr)
  0x00000000: Version: 1  File: libc.so.6  Cnt: 1
  0x00000010:   Name: GLIBC_2.0  Flags: none Version: 2
Section to Segment mapping:
Segment      Section
--------------------
PHDR         
INTERP       .interp 
LOAD0        .interp .note.ABI_tag .note.gnu.build_id .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rel.dyn .rel.plt .init .plt .text .fini .rodata .eh_frame_hdr .eh_frame 
LOAD1        .init_array .fini_array .jcr .dynamic .got .got.plt .data .bss 
DYNAMIC      .dynamic 
NOTE         .note.ABI_tag .note.gnu.build_id 
GNU_EH_FRAME .eh_frame_hdr 
GNU_STACK    
ehdr         

EOF
RUN

NAME=rz-bin -x pemixed.exe
BROKEN=1
FILE=bins/pe/pemixed.exe
CMDS=<<EOF
!rz-bin -x bins/pe/pemixed.exe
!rm -r pemixed.exe.fat
EOF
EXPECT=<<EOF
pemixed.exe.fat/pemixed.exe.unknown_0.0 created (248)
pemixed.exe.fat/pemixed.exe.unknown_0.1 created (35328)
pemixed.exe.fat/pemixed.exe.unknown_0.2 created (35328)
EOF
RUN

NAME=rz-bin -I elf_cpp
FILE=bins/elf/analysis/a.out.cpp
CMDS=!rz-bin -I ${RZ_FILE}
EXPECT=<<EOF
arch     x86
baddr    0x0
binsz    7051
bintype  elf
bits     64
canary   false
class    ELF64
compiler GCC: (Ubuntu 7.3.0-16ubuntu3) 7.3.0
crypto   false
endian   little
havecode true
intrp    /lib64/ld-linux-x86-64.so.2
laddr    0x0
lang     c++
linenum  true
lsyms    true
machine  AMD x86-64 architecture
maxopsz  16
minopsz  1
nx       true
os       linux
pcalign  0
pic      true
relocs   true
relro    full
rpath    NONE
sanitiz  false
static   false
stripped false
subsys   linux
va       true
EOF
RUN

NAME=rz-bin -I asan
FILE=bins/elf/analysis/a.out.asan
CMDS=!rz-bin -I ${RZ_FILE}
EXPECT=<<EOF
arch     x86
baddr    0x400000
binsz    1603255
bintype  elf
bits     64
canary   false
class    ELF64
compiler GCC: (Debian 8.2.0-5) 8.2.0 clang version 6.0.1-6 (tags/RELEASE_601/final)
crypto   false
endian   little
havecode true
intrp    /lib64/ld-linux-x86-64.so.2
laddr    0x0
lang     c++
linenum  true
lsyms    true
machine  AMD x86-64 architecture
maxopsz  16
minopsz  1
nx       true
os       linux
pcalign  0
pic      false
relocs   true
relro    partial
rpath    NONE
sanitiz  true
static   false
stripped false
subsys   linux
va       true
EOF
RUN

NAME=rz-bin -I apple-blocks-ext
FILE=bins/mach0/mach0-blocks-ext
CMDS=!rz-bin -I ${RZ_FILE}
EXPECT=<<EOF
arch     x86
baddr    0x100000000
binsz    9828
bintype  mach0
bits     64
canary   false
class    MACH064
crypto   false
endian   little
havecode true
intrp    /usr/lib/dyld
laddr    0x0
lang     c++ with blocks
linenum  false
lsyms    false
machine  x86 64 all
maxopsz  16
minopsz  1
nx       false
os       darwin
pcalign  0
pic      true
relocs   false
sanitiz  false
static   false
stripped false
subsys   darwin
va       true
EOF
RUN

NAME=rz-bin -s right symbols
FILE=bins/elf/libc.so.0
CMDS=!rz-bin -s ${RZ_FILE} | grep 0002edb0
EXPECT=<<EOF
149   0x0002edb0 0x0002edb0 GLOBAL FUNC   356      getc_unlocked
402   0x0002edb0 0x0002edb0 GLOBAL FUNC   356      __fgetc_unlocked
980   0x0002edb0 0x0002edb0 GLOBAL FUNC   356      fgetc_unlocked
EOF
RUN

NAME=rz-bin -V
FILE=bins/pe/version_cust.exe
CMDS=!rz-bin -V ${RZ_FILE}
EXPECT=<<EOF
=== VS_VERSIONINFO ===

# VS_FIXEDFILEINFO

  Signature: 0xfeef04bd
  StrucVersion: 0x0
  FileVersion: 0.0.0.0
  ProductVersion: 0.0.0.0
  FileFlagsMask: 0x0
  FileFlags: 0x0
  FileOS: 0x0
  FileType: 0x0
  FileSubType: 0x0

# StringTable

EOF
RUN

NAME=rz-bin -c
FILE=bins/java/test.class
CMDS=!rz-bin -c ${RZ_FILE}
EXPECT=<<EOF
0x00000000 [0x000008f9 - 0x00000b99]    672 class 0 test :: groovy/lang/Script
0x000008f9 method 0      <init>
0x0000092e method 1      <init>
0x0000096e method 2      main
0x000009ae method 3      run
0x00000aba method 4      $getStaticMetaClass
0x00000afb method 5      $createCallSiteArray_1
0x00000b6a method 6      $createCallSiteArray
0x00000b99 method 7      $getCallSiteArray
EOF
RUN

NAME=rz-bin -cq
FILE=bins/java/test.class
CMDS=!rz-bin -cq ${RZ_FILE}
EXPECT=<<EOF
0x00000000 [0x000008f9 - 0x00000b99] test groovy/lang/Script
EOF
RUN

NAME=rz-bin -D swift
BROKEN=1
FILE=bins/elf/libc.so.0
CMDS=!rz-bin -D swift  _TFSSCfT21_builtinStringLiteralBp8byteSizeBw7isASCIIBi1__SS
EXPECT=<<EOF
Swift.String.init (_builtinStringLiteral(Builtin.RawPointer byteSize__Builtin.Word isASCII__Builtin.Int1 _) -> String
EOF
RUN

NAME=rz-bin -D Unsupported
FILE=--
CMDS=!rz-bin -D XXX LOLILOL
EXPECT_ERR=<<EOF
Unsupported demangler
EOF
RUN

NAME=rz-bin -h
FILE=bins/elf/libc.so.0
CMDS=!rz-bin -h | grep -c Usage
EXPECT=<<EOF
1
EOF
RUN

NAME=rz-bin -O help
FILE=bins/elf/libc.so.0
CMDS=!rz-bin -O help | grep -c Usage
EXPECT=<<EOF
1
EOF
RUN

NAME=rz-bin -O h
FILE=bins/elf/libc.so.0
CMDS=!rz-bin -O h | grep -c Usage
EXPECT=<<EOF
1
EOF
RUN

NAME=rz-bin -O ?
FILE=bins/elf/libc.so.0
CMDS=!rz-bin -O "?" | grep -c Usage
EXPECT=<<EOF
1
EOF
RUN

NAME=rz-bin -O bad op
FILE=-
CMDS=!rz-bin -O bad_op -
EXPECT_ERR=<<EOF
Unknown operation. use -O help
EOF
RUN

NAME=rz-bin -v
FILE=-
CMDS=!rz-bin -v | grep -c build
EXPECT=<<EOF
1
EOF
RUN

NAME=rz-bin -L
FILE=-
CMDS=!rz-bin -L | grep -c any
EXPECT=<<EOF
1
EOF
RUN

NAME=rz-bin -Lq
FILE=-
CMDS=!rz-bin -Lq | grep -c any
EXPECT=<<EOF
1
EOF
RUN

NAME=rz-bin -Lj
FILE=-
CMDS=!rz-bin -Lj | grep -c any
EXPECT=<<EOF
1
EOF
RUN

NAME=rz-bin -Lj any
FILE=-
CMDS=!rz-bin -Lj Dummy | grep -c Dummy
EXPECT=<<EOF
1
EOF
RUN

NAME=rz-bin -U
FILE=bins/pe/resource.exe
CMDS=!rz-bin -U ${RZ_FILE} | grep -c Resource
EXPECT=<<EOF
1
EOF
RUN

NAME=rz-bin -E
FILE=bins/pe/dll.dll
CMDS=!rz-bin -E ${RZ_FILE}
EXPECT=<<EOF
[Exports]

nth paddr       vaddr      bind   type size lib     name
--------------------------------------------------------
0    0x00000224 0x01001024 GLOBAL FUNC 0    dll.dll export
EOF
RUN

NAME=rz-bin -l
FILE=bins/pe/ioli/w32/crackme0x00.exe
CMDS=!rz-bin -l ${RZ_FILE} | grep -c kernel32.dll
EXPECT=<<EOF
1
EOF
RUN

NAME=rz-bin -R
FILE=bins/pe/base.exe
CMDS=!rz-bin -R ${RZ_FILE} | grep -c msvcrt.dll___set_app_type
EXPECT=<<EOF
1
EOF
RUN

NAME=rz-bin -Z
FILE=bins/pe/base.exe
CMDS=!rz-bin -Z ${RZ_FILE}
EXPECT=<<EOF
216569
EOF
RUN

NAME=rz-bin -Zj
FILE=bins/pe/base.exe
CMDS=!rz-bin -Zj ${RZ_FILE}
EXPECT=<<EOF
{"size":216569}
EOF
RUN

NAME=rz-bin -H
FILE=bins/pe/base.exe
CMDS=!rz-bin -H ${RZ_FILE} | grep -c "Machine : 0x14c"
EXPECT=<<EOF
1
EOF
RUN

NAME=rz-bin -d
FILE=bins/elf/analysis/dwarftest
CMDS=!rz-bin -d ${RZ_FILE} | grep -c "0x00400535	/tmp/r2-regressions/.//dwarftest.c"
EXPECT=<<EOF
1
EOF
RUN

NAME=rz-bin -dj
FILE=bins/elf/analysis/dwarftest
CMDS=!rz-bin -dj ${RZ_FILE}
EXPECT=<<EOF
{"dwarf":[[{"name":"CC","file":"dwarftest.c","line_num":7,"addr":4195637},{"name":"CL","file":"dwarftest.c","line_num":7,"line":"","addr":4195637}],[{"name":"CC","file":"dwarftest.c","line_num":4,"addr":4195629},{"name":"CL","file":"dwarftest.c","line_num":4,"line":"","addr":4195629}],[{"name":"CC","file":"dwarftest.c","line_num":12,"addr":4195673},{"name":"CL","file":"dwarftest.c","line_num":12,"line":"","addr":4195673}],[{"name":"CC","file":"dwarftest.c","line_num":8,"addr":4195646},{"name":"CL","file":"dwarftest.c","line_num":8,"line":"","addr":4195646}],[{"name":"CC","file":"dwarftest.c","line_num":7,"addr":4195660},{"name":"CL","file":"dwarftest.c","line_num":7,"line":"","addr":4195660}],[{"name":"CC","file":"dwarftest.c","line_num":7,"addr":4195656},{"name":"CL","file":"dwarftest.c","line_num":7,"line":"","addr":4195656}],[{"name":"CC","file":"dwarftest.c","line_num":11,"addr":4195666},{"name":"CL","file":"dwarftest.c","line_num":11,"line":"","addr":4195666}],[{"name":"CC","file":"dwarftest.c","line_num":12,"addr":4195671},{"name":"CL","file":"dwarftest.c","line_num":12,"line":"","addr":4195671}]]}
EOF
RUN

NAME=rz-bin -P
FILE=bins/pdb/Project1.pdb
CMDS=!rz-bin -P ${RZ_FILE} | grep -c R2_TEST_UNION
EXPECT=<<EOF
1
EOF
RUN

NAME=rz-bin -Pj
FILE=bins/pdb/minimal.pdb
CMDS=!!rz-bin -Pj ${RZ_FILE}~{}
EXPECT=<<EOF
{
  "pdb": {
    "types": [
      {
        "type": "structure",
        "name": "struct_typedef",
        "size": 7,
        "members": [
          {
            "member_type": "char",
            "member_name": "a",
            "offset": 0
          },
          {
            "member_type": "uint16_t",
            "member_name": "b",
            "offset": 1
          },
          {
            "member_type": "int32_t",
            "member_name": "c",
            "offset": 3
          }
        ]
      },
      {
        "type": "structure",
        "name": "<unnamed-tag>",
        "size": 4,
        "members": [
          {
            "member_type": "char[4]",
            "member_name": "a",
            "offset": 0
          },
          {
            "member_type": "int32_t",
            "member_name": "b",
            "offset": 0
          }
        ]
      },
      {
        "type": "structure",
        "name": "unnamed_member_types_typedef",
        "size": 8,
        "members": [
          {
            "member_type": "union <unnamed-tag>",
            "member_name": "a",
            "offset": 0
          },
          {
            "member_type": "int32_t",
            "member_name": "b",
            "offset": 4
          }
        ]
      },
      {
        "type": "structure",
        "name": "bitfield_typedef",
        "size": 1,
        "members": [
          {
            "member_type": "bitfield uint8_t : 1",
            "member_name": "a",
            "offset": 0
          },
          {
            "member_type": "bitfield uint8_t : 2",
            "member_name": "b",
            "offset": 0
          },
          {
            "member_type": "bitfield uint8_t : 3",
            "member_name": "c",
            "offset": 0
          }
        ]
      },
      {
        "type": "structure",
        "name": "union_typedef",
        "size": 4,
        "members": [
          {
            "member_type": "char",
            "member_name": "a",
            "offset": 0
          },
          {
            "member_type": "uint16_t",
            "member_name": "b",
            "offset": 0
          },
          {
            "member_type": "int32_t",
            "member_name": "c",
            "offset": 0
          }
        ]
      }
    ],
    "gvars": [
      {
        "address": 12292,
        "symtype": 0,
        "section_name": ".data",
        "gdata_name": "_uninitialized_global"
      },
      {
        "address": 12288,
        "symtype": 0,
        "section_name": ".data",
        "gdata_name": "_initialized_global"
      },
      {
        "address": 4096,
        "symtype": 2,
        "section_name": ".text",
        "gdata_name": "_function"
      },
      {
        "address": 4182,
        "symtype": 2,
        "section_name": ".text",
        "gdata_name": "_mainCRTStartup"
      },
      {
        "address": 4120,
        "symtype": 2,
        "section_name": ".text",
        "gdata_name": "_main"
      }
    ]
  }
}
EOF
RUN

NAME=rz-bin -S ""
FILE=-
CMDS=!rz-bin -S ""
EXPECT_ERR=<<EOF
Cannot open empty path
EOF
RUN

NAME=rz-bin rust static type
BROKEN=1
FILE=-
CMDS=!rz-bin -D rust '_ZN71_$LT$Test$u20$$u2b$$u20$$u27$static$u20$as$u20$foo..Bar$LT$Test$GT$$GT$3barE'
EXPECT=<<EOF
<Test + 'static as foo::Bar<Test>>::bar
EOF
RUN

NAME=rz-bin rust static type with hash
BROKEN=1
FILE=-
CMDS=!rz-bin -D rust '_ZN96_$LT$core..fmt..Write..write_fmt..Adapter$LT$$u27$a$C$$u20$T$GT$$u20$as$u20$core..fmt..Write$GT$9write_str17he4f4768a2f446facE'
EXPECT=<<EOF
<core::fmt::Write::write_fmt::Adapter<'a, T> as core::fmt::Write>::write_str::he4f4768a2f446fac
EOF
RUN
