rizin/test/db/cmd/cmd_px
NOT XVilka ba8c170852
Migrate from Capstone to Zydis (x86 architecture) (#5164)
* Added build files [Capstone to Zydis]

* x86 Analysis [Capstone to Zydis]

* Changed x86 RzIL [Capstone to Zydis]

* Changed asm and arch files [Capstone to Zydis]

* Compilation, build error and test fixes [Capstone to Zydis]

* Test changes [Capstone to Zydis]

* Remaining changes [Capstone to Zydis]

* Added BE support [Capstone to Zydis]

---------

Co-authored-by: tushar3q34 <tushar3q34@gmail.com>
2025-05-23 13:03:46 +00:00

505 lines
20 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=pxr4
FILE=malloc://1024
CMDS=<<EOF
e asm.arch=x86
e asm.bits=64
e cfg.bigendian=false
woe 1 255 255
sd +11
b 8
pxr8
pxr4
pxr2
pxr1
b 4
pxr8
pxr4
pxr2
pxr1
b 2
pxr8
pxr4
pxr2
pxr1
pxr2
b 1
pxr8
pxr4
pxr2
pxr1
EOF
EXPECT=<<EOF
0x0000000b 0x0101010101010101 ........
0x0000000b 0x01010101 .... 16843009
0x0000000f 0x01010101 .... 16843009
0x0000000b 0101 .. 257 R W X 'add byte [rax], al'
0x0000000d 0101 .. 257 R W X 'add byte [rax], al'
0x0000000f 0101 .. 257 R W X 'add byte [rax], al'
0x00000011 0101 .. 257 R W X 'add byte [rax], al'
- offset - 0 0
0x0000000b 001 .
0x0000000c 001 .
0x0000000d 001 .
0x0000000e 001 .
0x0000000f 001 .
0x00000010 001 .
0x00000011 001 .
0x00000012 001 .
0x0000000b 0x0000000001010101 ....
0x0000000b 0x01010101 .... 16843009
0x0000000b 0101 .. 257 R W X 'add byte [rax], al'
0x0000000d 0101 .. 257 R W X 'add byte [rax], al'
- offset - 0 0
0x0000000b 001 .
0x0000000c 001 .
0x0000000d 001 .
0x0000000e 001 .
0x0000000b 0x0000000000000101 ..
0x0000000b 0x00000101 ..
0x0000000b 0101 .. 257 R W X 'add byte [rax], al'
- offset - 0 0
0x0000000b 001 .
0x0000000c 001 .
0x0000000b 0101 .. 257 R W X 'add byte [rax], al'
0x0000000b 0x0000000000000001 .
0x0000000b 0x00000001 .
0x0000000b 01 .
- offset - 0 0
0x0000000b 001 .
EOF
RUN
NAME=pxr addr size != bits
FILE=malloc://0x2000
CMDS=<<EOF
e asm.arch=6502
w Hello @ 0x1234
wx 3412 @ 2
pxr 8 @ 0
EOF
EXPECT=<<EOF
0x00000000 0000 ..
0x00000002 3412 4. R W X 'pha' Hello
0x00000004 0000 ..
0x00000006 0000 ..
EOF
EXPECT_ERR=
RUN
NAME=px 10
FILE=malloc://1024
CMDS=wx 90909090909090909090 ; px 10
EXPECT=<<EOF
- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
0x00000000 9090 9090 9090 9090 9090 ..........
EOF
RUN
NAME=px -10
FILE=malloc://1024
CMDS=wx 90909090909090909090 ; s 10 ; px -10
EXPECT=<<EOF
- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
0x00000000 9090 9090 9090 9090 9090 ..........
EOF
RUN
NAME=pxdw 16
FILE=malloc://1024
CMDS=<<EOF
wx 1020ffff30400000
pxdw 16
EOF
EXPECT=<<EOF
- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
0x00000000 -57328 16432 0 0 . ..0@..........
EOF
RUN
NAME=pxdw 8
FILE=malloc://1024
CMDS=<<EOF
wx 1020ffff30400000
pxdw 8
EOF
EXPECT=<<EOF
- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
0x00000000 -57328 16432 . ..0@..
EOF
RUN
NAME=pxH
FILE=bins/elf/sse2-add
CMDS=<<EOF
s 0x00000708
pxH 0x6
e hex.section=true
s 0x00000720
pxH 0x6
EOF
EXPECT=<<EOF
0x00000708 0x1f0f obj.__FRAME_END+5799
0x0000070a 0x0084 segment.PHDR+68
0x0000070c 0x0000 segment.LOAD0
.rodata 0x00000720 0x0001 segment.LOAD0+1
.rodata 0x00000722 0x0002 segment.LOAD0+2
.eh_frame_hdr 0x00000724 0x1b01 obj.__FRAME_END+4761
EOF
RUN
NAME=io.unalloc, io.unalloc.ch and pxc
FILE=bins/elf/analysis/tiny.elf
CMDS=<<EOF
. scripts/palette.rz
e io.unalloc=true
(dump; xc 0x00010060-0x0000ffd0 @ 0x0000ffd0-6)
e scr.color=3
e hex.comments=true
.(dump)
echo
e scr.color=0
.(dump)
echo
e hex.comments=false
e io.unalloc.ch=?
.(dump)
echo
e io.unalloc.ch=
.(dump)
EOF
EXPECT=<<EOF
- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF comment
0x0000ffca .... .... .... .... .... .... .... ....                 
0x0000ffda .... .... .... .... .... .... .... ....                 
0x0000ffea .... .... .... .... .... .... .... ....                 
0x0000fffa .... .... .... 7f45 4c46 0100 0000 0000       .ELF...... ; segment.ehdr ; [01] -rw- segment size 45 named ehdr
0x0001000a 0000 0000 0100 0200 0300 2000 0100 2000 .......... ... .
0x0001001a 0100 0400 0000 b32a 31c0 40cd 8000 3400 .......*1.@...4. ; entry0
0x0001002a 2000 0100 0000 0000 0000 0000 0000 0000  ...............
0x0001003a 0000 0000 0000 0000 0000 0000 0000 0000 ................
0x0001004a 0000 0000 0000 0000 0000 0000 0000 0000 ................
- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF comment
0x0000ffca .... .... .... .... .... .... .... ....
0x0000ffda .... .... .... .... .... .... .... ....
0x0000ffea .... .... .... .... .... .... .... ....
0x0000fffa .... .... .... 7f45 4c46 0100 0000 0000 .ELF...... ; segment.ehdr ; [01] -rw- segment size 45 named ehdr
0x0001000a 0000 0000 0100 0200 0300 2000 0100 2000 .......... ... .
0x0001001a 0100 0400 0000 b32a 31c0 40cd 8000 3400 .......*1.@...4. ; entry0
0x0001002a 2000 0100 0000 0000 0000 0000 0000 0000 ...............
0x0001003a 0000 0000 0000 0000 0000 0000 0000 0000 ................
0x0001004a 0000 0000 0000 0000 0000 0000 0000 0000 ................
- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
0x0000ffca ???? ???? ???? ???? ???? ???? ???? ????
0x0000ffda ???? ???? ???? ???? ???? ???? ???? ????
0x0000ffea ???? ???? ???? ???? ???? ???? ???? ????
0x0000fffa ???? ???? ???? 7f45 4c46 0100 0000 0000 .ELF......
0x0001000a 0000 0000 0100 0200 0300 2000 0100 2000 .......... ... .
0x0001001a 0100 0400 0000 b32a 31c0 40cd 8000 3400 .......*1.@...4.
0x0001002a 2000 0100 0000 0000 0000 0000 0000 0000 ...............
0x0001003a 0000 0000 0000 0000 0000 0000 0000 0000 ................
0x0001004a 0000 0000 0000 0000 0000 0000 0000 0000 ................
- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
0x0000ffca
0x0000ffda
0x0000ffea
0x0000fffa 7f45 4c46 0100 0000 0000 .ELF......
0x0001000a 0000 0000 0100 0200 0300 2000 0100 2000 .......... ... .
0x0001001a 0100 0400 0000 b32a 31c0 40cd 8000 3400 .......*1.@...4.
0x0001002a 2000 0100 0000 0000 0000 0000 0000 0000 ...............
0x0001003a 0000 0000 0000 0000 0000 0000 0000 0000 ................
0x0001004a 0000 0000 0000 0000 0000 0000 0000 0000 ................
EOF
RUN
NAME=pxr
FILE=bins/elf/crackme
CMDS=<<EOF
pxr 48 @ 0x00600ae0
echo ===
pxr 24 @ 0x00600ae0+32
EOF
EXPECT=<<EOF
0x00600ae0 0x000000000040055e ^.@..... @ reloc.printf 4195678 .plt R X 'push 0x00'
0x00600ae8 0x000000000040056e n.@..... @ reloc.puts 4195694 .plt R X 'push 0x01'
0x00600af0 0x000000000040057e ~.@..... @ reloc.__libc_start_main 4195710 .plt R X 'push 0x02'
0x00600af8 0x000000000040058e ..@..... @ reloc.fgets 4195726 .plt R X 'push 0x03'
0x00600b00 0x000000000040059e ..@..... @ reloc.strcmp 4195742 .plt R X 'push 0x04'
0x00600b08 0x00000000004005ae ..@..... @ reloc.fflush 4195758 .plt R X 'push 0x05'
===
0x00600b00 0x000000000040059e ..@..... @ reloc.strcmp 4195742 .plt R X 'push 0x04'
0x00600b08 0x00000000004005ae ..@..... @ reloc.fflush 4195758 .plt R X 'push 0x05'
0x00600b10 ..[ null bytes ].. 00000000 loc.__data_start
EOF
RUN
NAME=pxr1248
FILE=bins/elf/crackme
CMDS=<<EOF
pxr4 32@ 0x00600ae0
pxr8 32@ 0x00600ae0
pxr2 32@ 0x00600ae0
e asm.bits=32
pxr 32@ 0x00600ae0
pxr2j 16@ 0x00600ae0~{}
EOF
EXPECT=<<EOF
0x00600ae0 0x0040055e ^.@. @ reloc.printf 4195678 .plt R X 'push 0x00'
0x00600ae4 ..[ null bytes ].. 00000000
0x00600ae8 0x0040056e n.@. @ reloc.puts 4195694 .plt R X 'push 0x01'
0x00600aec ..[ null bytes ].. 00000000
0x00600af0 0x0040057e ~.@. @ reloc.__libc_start_main 4195710 .plt R X 'push 0x02'
0x00600af4 ..[ null bytes ].. 00000000
0x00600af8 0x0040058e ..@. @ reloc.fgets 4195726 .plt R X 'push 0x03'
0x00600afc ..[ null bytes ].. 00000000
0x00600ae0 0x000000000040055e ^.@..... @ reloc.printf 4195678 .plt R X 'push 0x00'
0x00600ae8 0x000000000040056e n.@..... @ reloc.puts 4195694 .plt R X 'push 0x01'
0x00600af0 0x000000000040057e ~.@..... @ reloc.__libc_start_main 4195710 .plt R X 'push 0x02'
0x00600af8 0x000000000040058e ..@..... @ reloc.fgets 4195726 .plt R X 'push 0x03'
0x00600ae0 5e05 ^. @ reloc.printf 1374
0x00600ae2 4000 @. 64 ascii ('@')
0x00600ae4 0000 ..
0x00600ae6 0000 ..
0x00600ae8 6e05 n. @ reloc.puts 1390
0x00600aea 4000 @. 64 ascii ('@')
0x00600aec 0000 ..
0x00600aee 0000 ..
0x00600af0 7e05 ~. @ reloc.__libc_start_main 1406
0x00600af2 4000 @. 64 ascii ('@')
0x00600af4 0000 ..
0x00600af6 0000 ..
0x00600af8 8e05 .. @ reloc.fgets 1422
0x00600afa 4000 @. 64 ascii ('@')
0x00600afc 0000 ..
0x00600afe 0000 ..
0x00600ae0 0x0040055e ^.@. @ reloc.printf .plt R X 'push 0x00'
0x00600ae4 ..[ null bytes ].. 00000000
0x00600ae8 0x0040056e n.@. @ reloc.puts .plt R X 'push 0x01'
0x00600aec ..[ null bytes ].. 00000000
0x00600af0 0x0040057e ~.@. @ reloc.__libc_start_main .plt R X 'push 0x02'
0x00600af4 ..[ null bytes ].. 00000000
0x00600af8 0x0040058e ..@. @ reloc.fgets .plt R X 'push 0x03'
0x00600afc ..[ null bytes ].. 00000000
[
{
"addr": 6294240,
"value": 1374,
"refstr": "1374",
"ref": {
"addr": 1374,
"value": "1374"
}
},
{
"addr": 6294242,
"value": 64,
"refstr": "64 ascii ('@')",
"ref": {
"addr": 64,
"value": "64",
"attr": [
"ascii"
]
}
},
{
"addr": 6294244,
"value": 0,
"refstr": "0",
"ref": {
"addr": 0,
"value": "0",
"attr": [
]
}
},
{
"addr": 6294246,
"value": 0,
"refstr": "0",
"ref": {
"addr": 0,
"value": "0",
"attr": [
]
}
},
{
"addr": 6294248,
"value": 1390,
"refstr": "1390",
"ref": {
"addr": 1390,
"value": "1390"
}
},
{
"addr": 6294250,
"value": 64,
"refstr": "64 ascii ('@')",
"ref": {
"addr": 64,
"value": "64",
"attr": [
"ascii"
]
}
},
{
"addr": 6294252,
"value": 0,
"refstr": "0",
"ref": {
"addr": 0,
"value": "0",
"attr": [
]
}
}
]
EOF
RUN
NAME=pxe
FILE==
CMDS=<<EOF
woe 0 0xff 1
pxe 256
EOF
EXPECT=<<EOF
0x00000000 🌀 🌂 🌅 🌈 🌙 🌞 🌟 🌠 🌰 🌱 🌲 🌳 🌴 🌵 🌷 🌸 ................
0x00000010 🌹 🌺 🌻 🌼 🌽 🌾 🌿 🍀 🍁 🍂 🍃 🍄 🍅 🍆 🍇 🍈 ................
0x00000020 🍉 🍊 🍋 🍌 🍍 🍎 🍏 🍐 🍑 🍒 🍓 🍔 🍕 🍖 🍗 🍘 !"#$%&'()*+,-./
0x00000030 🍜 🍝 🍞 🍟 🍠 🍡 🍢 🍣 🍤 🍥 🍦 🍧 🍨 🍩 🍪 🍫 0123456789:;<=>?
0x00000040 🍬 🍭 🍮 🍯 🍰 🍱 🍲 🍳 🍴 🍵 🍶 🍷 🍸 🍹 🍺 🍻 @ABCDEFGHIJKLMNO
0x00000050 🍼 🎀 🎁 🎂 🎃 🎄 🎅 🎈 🎉 🎊 🎋 🎌 🎍 🎎 🎏 🎒 PQRSTUVWXYZ[\]^_
0x00000060 🎓 🎠 🎡 🎢 🎣 🎤 🎥 🎦 🎧 🎨 🎩 🎪 🎫 🎬 🎭 🎮 `abcdefghijklmno
0x00000070 🎯 🎰 🎱 🎲 🎳 🎴 🎵 🎷 🎸 🎹 🎺 🎻 🎽 🎾 🎿 🏀 pqrstuvwxyz{|}~.
0x00000080 🏁 🏂 🏃 🏄 🏆 🏇 🏈 🏉 🏊 🐀 🐁 🐂 🐃 🐄 🐅 🐆 ................
0x00000090 🐇 🐈 🐉 🐊 🐋 🐌 🐍 🐎 🐏 🐐 🐑 🐒 🐓 🐔 🐕 🐖 ................
0x000000a0 🐗 🐘 🐙 🐚 🐛 🐜 🐝 🐞 🐟 🐠 🐡 🐢 🐣 🐤 🐥 🐦 ................
0x000000b0 🐧 🐨 🐩 🐪 🐫 🐬 🐭 🐮 🐯 🐰 🐱 🐲 🐳 🐴 🐵 🐶 ................
0x000000c0 🐷 🐸 🐹 🐺 🐻 🐼 🐽 🐾 👀 👂 👃 👄 👅 👆 👇 👈 ................
0x000000d0 👉 👊 👋 👌 👍 👎 👏 👐 👑 👒 👓 👔 👕 👖 👗 👘 ................
0x000000e0 👙 👚 👛 👜 👝 👞 👟 👠 👡 👢 👣 👤 👥 👦 👧 👨 ................
0x000000f0 👩 👪 👮 👯 👺 👻 👼 👽 👾 👿 💀 💁 💂 💃 💄 💅 ................
EOF
RUN
NAME=pxi
FILE=malloc://0xd+0x30
CMDS=pxi @x:f30f1efa554889e5ebfe @!0x10+0x30
EXPECT=<<EOF
0 1 2 3 4 5 6 7 8 9 A B C D E F
0: f3 0f 1e fa .U .H 89 e5 eb fe
30: ## ## ##
40: ]
EOF
RUN
NAME=px/ x
FILE=bins/elf/ls
CMDS=<<EOF
pxF 1 x b
pxF 1 x w
pxF 1 x d
pxF 2 x d
pxF 2 x h
EOF
EXPECT=<<EOF
- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
0x00005ae0 f3 .
0x00005ae0 0xfa1e0ff3 ....
0x00005ae0 0x8949ed31fa1e0ff3 ....1.I.
0x00005ae0 0x8949ed31fa1e0ff3 0xe48348e289485ed1 ....1.I..^H..H..
0x00005ae0 0x0ff3 0xfa1e ....
EOF
RUN
NAME=px/ d
FILE=bins/elf/ls
CMDS=<<EOF
pxF 1 d b
pxF 1 d w
pxF 2 d d
pxF 2 d h
EOF
EXPECT=<<EOF
- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
0x00005ae0 -13 .
- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
0x00005ae0 -98693133 ....
- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
0x00005ae0 -8554045218308091917 -1980659273309856047 ....1.I..^H..H..
- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
0x00005ae0 4083 -1506 ....
EOF
RUN
NAME=px/ o
FILE=bins/elf/ls
CMDS=<<EOF
pxF 1 o
pxF 2 o d
pxF 1 o h
pxF 5 o b
EOF
EXPECT=<<EOF
- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
0x00005ae0 363017 036372 061355 111211 ....1.I.
- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
0x00005ae0 363017 036372 061355 111211 321136 110211 342110 203344 ....1.I..^H..H..
- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
0x00005ae0 363017 ..
- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
0x00005ae0 363017 036372 061 ....1
EOF
RUN
NAME=px/ f
FILE=bins/elf/ls
CMDS=<<EOF
pxF 8 f
EOF
EXPECT=<<EOF
0x00005ae0 = -2.05176598e+35
0x00005ae4 = -2.43060218e-33
0x00005ae8 = -2.41187068e-33
0x00005aec = -1.93742019e+22
0x00005af0 = 55657408
0x00005af4 = 1.77202259e-31
0x00005af8 = -6.16297629e-31
0x00005afc = 2.57017785e-38
EOF
RUN
NAME=px/ error cases
FILE=bins/elf/ls
CMDS=<<EOF
pxF 0 x
EOF
EXPECT=<<EOF
EOF
EXPECT_ERR=<<EOF
EOF
RUN
NAME=px/ s
FILE=bins/elf/ls
CMDS=<<EOF
pxF 50 s w
pxF 50 s d
EOF
EXPECT=<<EOF
0x00005b8b u3UH
0x00005b8b u3UH
0x00005c02 F\bH9G\b
0x00005c5a AUATA
EOF
EXPECT_ERR=
RUN