This introduces the ability to split asm strings into tokens and assign a type to them. This means: * Each asm strings is assigned a list of tokens. Each token points to a sub-string. * A token has a type attached which describes it (e.g. register token, operator token, mnemonic token etc.) * A generic parsing method is introduced which splits an asm string into tokens. The pattern it parses is `<mnem> <op> <op> ...`. * Instead of the generic method, plugins can create the token strings on their own. * An API method was introduced to help plugins implement their own parsing methods via regex patterns. * Custom token strings are stored in `RzAsmOp.asm_toks` Additionally the coloring of asm strings is now exclusively done via the token strings. * For this a function was added to colorize tokenized asm strings according to their token types.
416 lines
5.7 KiB
Text
416 lines
5.7 KiB
Text
NAME=ahi s + endian
|
||
FILE==
|
||
CMDS=<<EOF
|
||
wx b8410d4300
|
||
e asm.arch=x86
|
||
ahi s
|
||
e cfg.bigendian=false
|
||
pi 1
|
||
e cfg.bigendian=true
|
||
pi 1
|
||
EOF
|
||
EXPECT=<<EOF
|
||
mov eax, 'C\x0dA'
|
||
mov eax, 'A\x0dC'
|
||
EOF
|
||
RUN
|
||
|
||
NAME=ahi s + endian 2
|
||
FILE==
|
||
CMDS=<<EOF
|
||
wx b841424300
|
||
e asm.arch=x86
|
||
ahi s
|
||
e cfg.bigendian=false
|
||
pi 1
|
||
e cfg.bigendian=true
|
||
pi 1
|
||
EOF
|
||
EXPECT=<<EOF
|
||
mov eax, 'CBA'
|
||
mov eax, 'ABC'
|
||
EOF
|
||
RUN
|
||
|
||
NAME=1: ahi none
|
||
FILE==
|
||
CMDS=<<EOF
|
||
e asm.bits=64
|
||
e asm.arch=x86
|
||
wx 4881ec48060000
|
||
pi 1
|
||
EOF
|
||
EXPECT=<<EOF
|
||
sub rsp, 0x648
|
||
EOF
|
||
RUN
|
||
|
||
NAME=ahi with colors
|
||
FILE==
|
||
CMDS=<<EOF
|
||
e asm.bits=64
|
||
e asm.bytes=true
|
||
e asm.arch=x86
|
||
e scr.color=1
|
||
wx 4881ec48060000
|
||
pd 1
|
||
ahi 10
|
||
pd 1
|
||
EOF
|
||
EXPECT=<<EOF
|
||
[32m[7m0x00000000[0m [33m48[37m81[37mec[33m48[37m06[32m00[37m.[0m [33msub[0m[37m [0m[36mrsp[0m[37m, [0m[33m0x648[0m[0m[0m
|
||
[32m[7m0x00000000[0m [33m48[37m81[37mec[33m48[37m06[32m00[37m.[0m [33msub[0m[37m [0m[36mrsp[0m[37m, [0m[33m1608[0m[0m[0m
|
||
EOF
|
||
RUN
|
||
|
||
NAME=ahi 0x41 -> 'A'
|
||
FILE==
|
||
CMDS=<<EOF
|
||
e asm.bits=64
|
||
e asm.arch=x86
|
||
wx 4881ec48060000
|
||
wx 4883f841 # cmp rax, 0x41
|
||
pi 1
|
||
ahi s
|
||
pi 1
|
||
EOF
|
||
EXPECT=<<EOF
|
||
cmp rax, 0x41
|
||
cmp rax, 'A'
|
||
EOF
|
||
RUN
|
||
|
||
NAME=ahi 0xe -> 1
|
||
FILE==
|
||
CMDS=<<EOF
|
||
e asm.bits=64
|
||
e asm.arch=x86
|
||
wx 4881ec48060000
|
||
wx 4883f80e # cmp rax, 0xe
|
||
pi 1
|
||
ahi 2
|
||
pi 1
|
||
EOF
|
||
EXPECT=<<EOF
|
||
cmp rax, 0xe
|
||
cmp rax, 1110b
|
||
EOF
|
||
RUN
|
||
|
||
NAME=ahi 4 -> 1
|
||
FILE==
|
||
CMDS=<<EOF
|
||
e asm.bits=64
|
||
e asm.arch=x86
|
||
wx 4881ec48060000
|
||
wx 4883f804 # cmp rax, 4
|
||
pi 1
|
||
ahi 2
|
||
pi 1
|
||
EOF
|
||
EXPECT=<<EOF
|
||
cmp rax, 4
|
||
cmp rax, 100b
|
||
EOF
|
||
RUN
|
||
|
||
NAME=2: ahi none
|
||
FILE==
|
||
CMDS=<<EOF
|
||
e asm.bits=64
|
||
e asm.bytes=true
|
||
e asm.arch=x86
|
||
wx 4881ec48060000
|
||
pd 1
|
||
EOF
|
||
EXPECT=<<EOF
|
||
0x00000000 4881ec480600. sub rsp, 0x648
|
||
EOF
|
||
RUN
|
||
|
||
NAME=3: ahi none
|
||
FILE==
|
||
CMDS=<<EOF
|
||
e asm.bits=64
|
||
e asm.bytes=true
|
||
e asm.arch=x86
|
||
ahi 16
|
||
wx 4881ec48060000
|
||
pd 1
|
||
EOF
|
||
EXPECT=<<EOF
|
||
0x00000000 4881ec480600. sub rsp, 0x648
|
||
EOF
|
||
RUN
|
||
|
||
NAME=1: ahi 10
|
||
FILE==
|
||
CMDS=<<EOF
|
||
e asm.bits=64
|
||
e asm.bytes=true
|
||
e asm.arch=x86
|
||
wx 4881ec48060000
|
||
ahi 10
|
||
pd 1
|
||
EOF
|
||
EXPECT=<<EOF
|
||
0x00000000 4881ec480600. sub rsp, 1608
|
||
EOF
|
||
RUN
|
||
|
||
NAME=ahi 8
|
||
FILE==
|
||
CMDS=<<EOF
|
||
e asm.bits=64
|
||
e asm.bytes=true
|
||
e asm.arch=x86
|
||
wx 4881ec48060000
|
||
ahi 8
|
||
pd 1
|
||
EOF
|
||
EXPECT=<<EOF
|
||
0x00000000 4881ec480600. sub rsp, 03110
|
||
EOF
|
||
RUN
|
||
|
||
NAME=1: ahi 2
|
||
FILE==
|
||
CMDS=<<EOF
|
||
e asm.bits=64
|
||
e asm.bytes=true
|
||
e asm.arch=x86
|
||
wx 4881ec48060000
|
||
ahi 2
|
||
pd 1
|
||
EOF
|
||
EXPECT=<<EOF
|
||
0x00000000 4881ec480600. sub rsp, 11001001000b
|
||
EOF
|
||
RUN
|
||
|
||
NAME=ahi 2 - pi
|
||
FILE==
|
||
CMDS=<<EOF
|
||
e asm.bits=64
|
||
e asm.arch=x86
|
||
wx 4881ec48060000
|
||
ahi 2
|
||
pi 1
|
||
EOF
|
||
EXPECT=<<EOF
|
||
sub rsp, 11001001000b
|
||
EOF
|
||
RUN
|
||
|
||
NAME=2: ahi 2
|
||
FILE=malloc://16
|
||
CMDS=<<EOF
|
||
e asm.arch=x86
|
||
e asm.bits=64
|
||
wx 4883e4f0
|
||
ahi 2
|
||
pi 1
|
||
EOF
|
||
EXPECT=<<EOF
|
||
and rsp, 1111111111111111111111111111111111111111111111111111111111110000b
|
||
EOF
|
||
RUN
|
||
|
||
NAME=2: ahi 10
|
||
FILE=malloc://16
|
||
CMDS=<<EOF
|
||
e asm.arch=x86
|
||
e asm.bits=64
|
||
wx 4883e4f0
|
||
ahi 10
|
||
pi 1
|
||
EOF
|
||
EXPECT=<<EOF
|
||
and rsp, -16
|
||
EOF
|
||
RUN
|
||
|
||
NAME=1: ahi s
|
||
FILE=malloc://16
|
||
CMDS=<<EOF
|
||
e asm.arch=x86
|
||
e asm.bits=64
|
||
wx b841414141
|
||
ahi s
|
||
pi 1
|
||
EOF
|
||
EXPECT=<<EOF
|
||
mov eax, 'AAAA'
|
||
EOF
|
||
RUN
|
||
|
||
NAME=ahl*
|
||
FILE=malloc://16
|
||
CMDS=<<EOF
|
||
e asm.arch=x86
|
||
e asm.bits=64
|
||
wx 4883e4f0
|
||
ahi 10 @ 0x00404879
|
||
ahl*
|
||
EOF
|
||
EXPECT=<<EOF
|
||
ahi 10 @ 0x404879
|
||
EOF
|
||
RUN
|
||
|
||
NAME=ahl.
|
||
FILE=malloc://16
|
||
CMDS=<<EOF
|
||
ahi 10 @ 0x8
|
||
s 0x8
|
||
ahl.
|
||
EOF
|
||
EXPECT=<<EOF
|
||
0x00000008 => immbase=10
|
||
EOF
|
||
RUN
|
||
|
||
NAME=64bit ahi 10
|
||
FILE==
|
||
ARGS=-m 0x100001000
|
||
CMDS=<<EOF
|
||
e io.va
|
||
e asm.sub.rel=false
|
||
e asm.bytes=true
|
||
e asm.hint.lea=false
|
||
e asm.arch=x86
|
||
e asm.bits=64
|
||
e io.va=true
|
||
wx c7055f44000000000000
|
||
pd 1
|
||
e asm.sub.rel=true; pd 1
|
||
ahi 10; pd 1
|
||
EOF
|
||
EXPECT=<<EOF
|
||
true
|
||
0x100001000 c7055f440000. mov dword [rip + 0x445f], 0 ; [0x100005469:4]=-1
|
||
0x100001000 c7055f440000. mov dword [0x100005469], 0 ; [0x100005469:4]=-1
|
||
0x100001000 c7055f440000. mov dword [4294988905], 0 ; [0x100005469:4]=-1
|
||
EOF
|
||
RUN
|
||
|
||
NAME=2: ahi s
|
||
FILE==
|
||
CMDS=<<EOF
|
||
e asm.bits=64
|
||
e asm.arch=x86
|
||
wx 67c744246864616572
|
||
pi 1
|
||
ahi s 1
|
||
pi 1
|
||
EOF
|
||
EXPECT=<<EOF
|
||
mov dword [esp + 0x68], 0x72656164
|
||
mov dword [esp + 0x68], 'read'
|
||
EOF
|
||
RUN
|
||
|
||
NAME=ahi s 2
|
||
FILE==
|
||
CMDS=<<EOF
|
||
wx b868584d56
|
||
e asm.arch=x86
|
||
e asm.bits=64
|
||
ahi s
|
||
pi 1
|
||
EOF
|
||
EXPECT=<<EOF
|
||
mov eax, 'VMXh'
|
||
EOF
|
||
RUN
|
||
|
||
NAME=ahi s - pd with colors
|
||
FILE==
|
||
CMDS=<<EOF
|
||
e asm.bytes=false
|
||
e asm.comments=false
|
||
e asm.bits=64
|
||
e asm.arch=x86
|
||
wx 67c74424681b5b306d
|
||
ahi s 1
|
||
e scr.color=0
|
||
pd 1
|
||
e scr.color=1
|
||
pd 1
|
||
EOF
|
||
EXPECT=<<EOF
|
||
0x00000000 mov dword [esp + 0x68], 'm0[\x1b'
|
||
[32m[7m0x00000000[0m [37mmov[0m[37m [0m[37mdword[0m[37m [[0m[36mesp[0m[37m [0m[37m+[0m[37m [0m[33m0x68[0m[37m], [0m[33m'm0[\x1b'[0m[0m
|
||
EOF
|
||
RUN
|
||
|
||
NAME=ahi nword
|
||
FILE==
|
||
CMDS=<<EOF
|
||
e asm.arch=x86
|
||
e asm.bits=64
|
||
e asm.bytes=false
|
||
wx c7458843c6ff00
|
||
pdq 1
|
||
ahi 10
|
||
pdq 1
|
||
ahi-
|
||
ahi 10 1
|
||
pdq 1
|
||
EOF
|
||
EXPECT=<<EOF
|
||
0x00000000 mov dword [rbp - 0x78], 0xffc643
|
||
0x00000000 mov dword [rbp - 120], 0xffc643
|
||
0x00000000 mov dword [rbp - 0x78], 16762435
|
||
EOF
|
||
RUN
|
||
|
||
NAME=ahi 10 and 10u imm (x86_32)
|
||
ARGS=-a x86 -b 32
|
||
FILE==
|
||
CMDS=<<EOF
|
||
e asm.bytes=false
|
||
wa "cmp eax, -1"
|
||
pd 1
|
||
ahi 10
|
||
pd 1
|
||
ahi 10u
|
||
pd 1
|
||
EOF
|
||
EXPECT=<<EOF
|
||
0x00000000 cmp eax, 0xffffffff
|
||
0x00000000 cmp eax, -1
|
||
0x00000000 cmp eax, 4294967295
|
||
EOF
|
||
RUN
|
||
|
||
NAME=ahi 10 and 10u imm (x86_64)
|
||
ARGS=-a x86 -b 64
|
||
FILE==
|
||
CMDS=<<EOF
|
||
e asm.bytes=false
|
||
wa "cmp eax, -1"
|
||
pd 1
|
||
ahi 10
|
||
pd 1
|
||
ahi 10u
|
||
pd 1
|
||
?e
|
||
ah-
|
||
wa "cmp rax, -1"
|
||
pd 1
|
||
ahi 10
|
||
pd 1
|
||
ahi 10u
|
||
pd 1
|
||
EOF
|
||
EXPECT=<<EOF
|
||
0x00000000 cmp eax, 0xffffffff
|
||
0x00000000 cmp eax, -1
|
||
0x00000000 cmp eax, 4294967295
|
||
|
||
0x00000000 cmp rax, 0xffffffffffffffff
|
||
0x00000000 cmp rax, -1
|
||
0x00000000 cmp rax, 18446744073709551615
|
||
EOF
|
||
RUN
|