rizin/test/db/cmd/midflags
billow 40ca22202b
Refactor rz_core_print_disasm_json (#2746)
* Split `rz_core_print_disasm_json` as: `rz_core_print_disasm_json` and `rz_core_disasm`
* Use `rz_str_enc_string_as_type` in `ds_init`
* Refactor `rz_core_print_disasm` and `rz_core_handle_backwards_disasm`
* Add `rz_core_asm_bb_middle`
* Move global `disasm_texts` to `RzDisasmState`
* Rewrite `core_analysis_bytes_standard` with `rz_core_analysis_bytes`
* Add `test_rz_core_print_disasm` and `test_rz_core_analysis_bytes`
* Rewrite `rz_core_print_disasm` with `RzCmdStateOutput`
* `pdi` -> `pdq` in tests
* `pdi` -> `pDq` in tests
* `pid` -> `pdq` in tests
* `pId` -> `pDq` in tests
* `pij` -> `pdj` in tests
* `pIj` -> `pDj` in tests
* `pdeqq` -> `pdeQ` in tests
* Remove `pDJ` from `test/db/json/`
2022-07-09 08:10:06 +08:00

421 lines
7.7 KiB
Text

NAME=f~?
FILE==
CMDS=f~?
EXPECT=<<EOF
0
EOF
RUN
NAME=pi asm.flags.middle=2
FILE=malloc://1024
CMDS=<<EOF
e asm.arch=x86
e asm.bytes=true
e asm.bits=64
wx 554889e54157415641554154534881ec
e asm.flags.middle=2
f dat.sym @ 2
pi 4
pdq 4
EOF
EXPECT=<<EOF
push rbp
mov rbp, rsp
mov ebp, esp
push r15
0x00000000 55 push rbp
0x00000001 4889e5 mov rbp, rsp
0x00000002 dat.sym:
0x00000002 89e5 mov ebp, esp
0x00000004 4157 push r15
EOF
RUN
NAME=pi asm.flags.middle=1
FILE=malloc://1024
CMDS=<<EOF
e asm.arch=x86
e asm.bits=64
wx 554889e54157415641554154534881ec
e asm.flags.middle=1
f dat.sym @ 2
pi 4
EOF
EXPECT=<<EOF
push rbp
mov rbp, rsp
push r15
push r14
EOF
RUN
NAME=pi asm.flags.middle=0
FILE=malloc://1024
CMDS=<<EOF
e asm.arch=x86
e asm.bits=64
wx 554889e54157415641554154534881ec
e asm.flags.middle=0
f dat.sym @ 2
pi 4
EOF
EXPECT=<<EOF
push rbp
mov rbp, rsp
push r15
push r14
EOF
RUN
NAME=Another pi asm.flags.middle=2
FILE=malloc://1024
CMDS=<<EOF
e asm.arch=x86
e asm.bytes=true
e asm.bits=64
wx 554889e54157415641554154534881ec
e asm.flags.middle=2
f dat.sym @ 2
pdq 4
EOF
EXPECT=<<EOF
0x00000000 55 push rbp
0x00000001 4889e5 mov rbp, rsp
0x00000002 dat.sym:
0x00000002 89e5 mov ebp, esp
0x00000004 4157 push r15
EOF
RUN
NAME=pdq asm.flags.middle=0
FILE=malloc://1024
CMDS=<<EOF
e asm.arch=x86
e asm.bytes=true
e asm.bits=64
wx 554889e54157415641554154534881ec
e asm.flags.middle=0
f dat.sym @ 2
pdq 4
EOF
EXPECT=<<EOF
0x00000000 55 push rbp
0x00000001 4889e5 mov rbp, rsp
0x00000004 4157 push r15
0x00000006 4156 push r14
EOF
RUN
NAME=pdj asm.flags.middle=0
FILE=malloc://1024
CMDS=<<EOF
e asm.bits=64
e asm.arch=x86
e analysis.arch=x86
wx 554889e54157415641554154534881ec
e asm.flags.middle=0
f dat.sym @ 2
pdj 4~{}
EOF
EXPECT=<<EOF
[
{
"offset": 0,
"esil": "rbp,8,rsp,-,=[8],8,rsp,-=",
"refptr": false,
"fcn_addr": 0,
"fcn_last": 0,
"size": 1,
"opcode": "push rbp",
"disasm": "push rbp",
"bytes": "55",
"family": "cpu",
"type": "rpush",
"reloc": false,
"type_num": 268435468,
"type2_num": 0
},
{
"offset": 1,
"esil": "rsp,rbp,=",
"refptr": false,
"fcn_addr": 0,
"fcn_last": 0,
"size": 3,
"opcode": "mov rbp, rsp",
"disasm": "mov rbp, rsp",
"bytes": "4889e5",
"family": "cpu",
"type": "mov",
"reloc": false,
"type_num": 9,
"type2_num": 0
},
{
"offset": 4,
"esil": "r15,8,rsp,-,=[8],8,rsp,-=",
"refptr": false,
"fcn_addr": 0,
"fcn_last": 0,
"size": 2,
"opcode": "push r15",
"disasm": "push r15",
"bytes": "4157",
"family": "cpu",
"type": "rpush",
"reloc": false,
"type_num": 268435468,
"type2_num": 0
},
{
"offset": 6,
"esil": "r14,8,rsp,-,=[8],8,rsp,-=",
"refptr": false,
"fcn_addr": 0,
"fcn_last": 0,
"size": 2,
"opcode": "push r14",
"disasm": "push r14",
"bytes": "4156",
"family": "cpu",
"type": "rpush",
"reloc": false,
"type_num": 268435468,
"type2_num": 0
}
]
EOF
RUN
NAME=pdj asm.flags.middle=2
FILE=malloc://1024
CMDS=<<EOF
e asm.bits=64
e asm.arch=x86
e analysis.arch=x86
wx 554889e54157415641554154534881ec
e asm.flags.middle=2
f dat.sym @ 2
pdj 4~{}
EOF
EXPECT=<<EOF
[
{
"offset": 0,
"esil": "rbp,8,rsp,-,=[8],8,rsp,-=",
"refptr": false,
"fcn_addr": 0,
"fcn_last": 0,
"size": 1,
"opcode": "push rbp",
"disasm": "push rbp",
"bytes": "55",
"family": "cpu",
"type": "rpush",
"reloc": false,
"type_num": 268435468,
"type2_num": 0
},
{
"offset": 1,
"esil": "rsp,rbp,=",
"refptr": false,
"fcn_addr": 0,
"fcn_last": 0,
"size": 3,
"opcode": "mov rbp, rsp",
"disasm": "mov rbp, rsp",
"bytes": "4889e5",
"family": "cpu",
"type": "mov",
"reloc": false,
"type_num": 9,
"type2_num": 0
},
{
"offset": 2,
"esil": "esp,rbp,=",
"refptr": false,
"fcn_addr": 0,
"fcn_last": 0,
"size": 2,
"opcode": "mov ebp, esp",
"disasm": "mov ebp, esp",
"bytes": "89e5",
"family": "cpu",
"type": "mov",
"reloc": false,
"type_num": 9,
"type2_num": 0,
"flags": [
"dat.sym"
]
},
{
"offset": 4,
"esil": "r15,8,rsp,-,=[8],8,rsp,-=",
"refptr": false,
"fcn_addr": 0,
"fcn_last": 0,
"size": 2,
"opcode": "push r15",
"disasm": "push r15",
"bytes": "4157",
"family": "cpu",
"type": "rpush",
"reloc": false,
"type_num": 268435468,
"type2_num": 0
}
]
EOF
RUN
NAME=pdq asm.flags.middle=0
FILE=malloc://1024
CMDS=<<EOF
e asm.arch=x86
e asm.bytes=true
e asm.bits=32
e asm.flags.middle=0
f mid.flag @ 4
wx 31ed4989d15e4889e2
pdq 3
EOF
EXPECT=<<EOF
0x00000000 31ed xor ebp, ebp
0x00000002 49 dec ecx
0x00000003 89d1 mov ecx, edx
EOF
RUN
NAME=pdq asm.flags.middle=2
FILE=malloc://1024
BROKEN=1
CMDS=<<EOF
e asm.arch=x86
e asm.bits=32
e asm.flags.middle=1
f mid.flag @ 4
wx 31ed4989d15e4889e2
pdq 3
EOF
EXPECT=<<EOF
0x00000000 31ed xor ebp, ebp
0x00000002 49 dec ecx
0x00000003 89d1 mov ecx, edx
0x00000004 mid.flag:
0x00000004 89d1 mov ecx, edx
EOF
RUN
NAME=pd asm.flags.middle=0
FILE=malloc://1024
CMDS=<<EOF
e asm.arch=x86
e asm.bytes=true
e asm.bits=32
e asm.flags.middle=0
e asm.lines.bb=false
f mid.flag @ 4
wx 31ed4989d15e4889e2
pd 4
EOF
EXPECT=<<EOF
0x00000000 31ed xor ebp, ebp
0x00000002 49 dec ecx
0x00000003 89d1 mov ecx, edx
0x00000005 5e pop esi
EOF
RUN
NAME=pd asm.flags.middle=2 mid.flag=5
FILE=malloc://1024
CMDS=<<EOF
e asm.arch=x86
e asm.bits=32
e asm.bytes=true
e asm.lines.bb=false
e asm.flags.middle=2
f mid.flag @ 5
wx 31ed4989d15e4889e2
pd 4
EOF
EXPECT=<<EOF
0x00000000 31ed xor ebp, ebp
0x00000002 49 dec ecx
0x00000003 89d1 mov ecx, edx
;-- mid.flag:
0x00000005 5e pop esi
EOF
RUN
NAME=pd asm.flags.middle=2 mid.flag=4
FILE=malloc://1024
CMDS=<<EOF
e asm.arch=x86
e asm.bits=32
e asm.lines.bb=false
e asm.bytes=true
e asm.flags.middle=2
f mid.flag @ 4
wx 31ed4989d15e4889e2
pd 4
EOF
EXPECT=<<EOF
0x00000000 31ed xor ebp, ebp
0x00000002 49 dec ecx
0x00000003 ~ 89d1 mov ecx, edx
;-- mid.flag:
0x00000004 d15e48 rcr dword [esi + 0x48], 1
EOF
RUN
NAME=antidisasm trick for x86 with midflags
FILE=malloc://1024
CMDS=<<EOF
e asm.arch=x86
e asm.bytes=true
e asm.bits=32
wx 66b8eb0531c074f9e89090909090
e asm.lines.bb=false
e asm.flags.middle=2
f mid.flag @ 2
f mid.flag2 @ 9
pd 6
EOF
EXPECT=<<EOF
0x00000000 ~ 66b8eb05 mov ax, 0x5eb ; 1515
;-- mid.flag:
0x00000002 eb05 jmp mid.flag2
0x00000004 31c0 xor eax, eax
0x00000006 74f9 je 1
0x00000008 ~ e890909090 call 0x9090909d
;-- mid.flag2:
0x00000009 90 nop
EOF
RUN
NAME=asm.flags.middle reset
FILE==
CMDS=<<EOF
e asm.arch=x86
e asm.bytes=true
e asm.bits=64
e asm.bb.middle=false
e asm.flags.middle=2
wx b821c10010ebf9b8210011c1
af @ 3
f sym.dummy @ 9
pd 4 @ 0
EOF
EXPECT=<<EOF
| ; CODE XREF from fcn.00000003 @ 0x5
| ;-- (0x00000003) fcn.00000003:
| 0x00000000 ~ b821c10010 mov eax, 0x1000c121
| 0x00000005 ebf9 jmp 0
0x00000007 ~ b8210011c1 mov eax, 0xc1110021 ; '!'
;-- sym.dummy:
0x00000009 0011 add byte [rcx], dl
EOF
RUN