NAME=f~?
FILE=-
CMDS=f~?
EXPECT=<<EOF
0
EOF
RUN

NAME=pi asm.midflags=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
pdi 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.midflags=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.midflags=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.midflags=2
FILE=malloc://1024
CMDS=<<EOF
e asm.arch=x86
e asm.bytes=true
e asm.bits=64
wx 554889e54157415641554154534881ec
e asm.midflags=2
f dat.sym = 2
pid 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=pid asm.midflags=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
pid 4
EOF
EXPECT=<<EOF
0x00000000                   55  push rbp
0x00000001               4889e5  mov rbp, rsp
0x00000004                 4157  push r15
0x00000006                 4156  push r14
EOF
RUN

NAME=pij asm.midflags=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
pij 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=pij asm.midflags=2
FILE=malloc://1024
CMDS=<<EOF
e asm.bits=64
e asm.arch=x86
e analysis.arch=x86
wx 554889e54157415641554154534881ec
e asm.midflags=2
f dat.sym = 2
pij 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=pid asm.midflags=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
pid 3
EOF
EXPECT=<<EOF
0x00000000                 31ed  xor ebp, ebp
0x00000002                   49  dec ecx
0x00000003                 89d1  mov ecx, edx
EOF
RUN

NAME=pid asm.midflags=2
FILE=malloc://1024
BROKEN=1
CMDS=<<EOF
e asm.arch=x86
e asm.bits=32
e asm.midflags=1
f mid.flag = 4
wx 31ed4989d15e4889e2
pid 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.midflags=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.midflags=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.midflags=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.midflags=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
