NAME=ah-
FILE==
CMDS=<<EOF
ahi 10 @ 0
ahi 8 @ 16
echo before:
ahl
ah- @ 0x10
echo after:
ahl
EOF
EXPECT=<<EOF
before:
 0x00000000 => immbase=10
 0x00000010 => immbase=8
after:
 0x00000000 => immbase=10
EOF
RUN

NAME=ah- @ offset
FILE==
CMDS=<<EOF
ahi 10 @ 0
ahi 8 @ 16
echo before:
ahl
ah- @ 0x10
echo after:
ahl
EOF
EXPECT=<<EOF
before:
 0x00000000 => immbase=10
 0x00000010 => immbase=8
after:
 0x00000000 => immbase=10
EOF
RUN

NAME=ahl
FILE==
CMDS=<<EOF
s 0x1337
aha ppc
ahb 16
ahc 0x804804
ahe 3,eax,+=
ahf 0x12345
ahF 0x10
ahh
ahi 10
ahd foo a0,33
ahp 0xc0ff33
ahr 42
ahs 4
ahS jz
aho call

ahi 0x4321 @ 0x0815
echo all:
ahl
echo --
echo at 0x1337:
ahl. @ 0x1337
echo --
echo at 0xdeadbeef
ahl. @ 0xdeadbeef
echo --
echo at 0x42
ahl. @ 0x42
EOF
EXPECT=<<EOF
all:
 0x00000815 => immbase=17185
 0x00001337 => arch='ppc' bits=16 jump=0x00804804 esil='3,eax,+=' fail=0x00012345 stackframe=0x10 high=true immbase=10 opcode='foo a0,33' ptr=0xc0ff33 ret=0x0000002a size=4 syntax='jz' type='call'
--
at 0x1337:
 0x00001337 => arch='ppc' bits=16 jump=0x00804804 esil='3,eax,+=' fail=0x00012345 stackframe=0x10 high=true immbase=10 opcode='foo a0,33' ptr=0xc0ff33 ret=0x0000002a size=4 syntax='jz' type='call'
--
at 0xdeadbeef
 0x00001337 => arch='ppc' bits=16
--
at 0x42
EOF
RUN

NAME=ahl*
FILE==
CMDS=<<EOF
s 0x1337
aha ppc
ahb 16
ahc 0x804804
ahe 3,eax,+=
ahf 0x12345
ahF 0x10
ahh
ahi 10
ahd foo a0,33
ahp 0xc0ff33
ahr 42
ahs 4
ahS jz
aho call

ahi 0x4321 @ 0x0815
echo all:
ahl*
echo --
echo at 0x1337:
ahl.* @ 0x1337
EOF
EXPECT=<<EOF
all:
ahi 17185 @ 0x815
aha ppc @ 0x1337
ahb 16 @ 0x1337
ahc 0x804804 @ 0x1337
ahe 3,eax,+= @ 0x1337
ahf 0x12345 @ 0x1337
ahF 0x10 @ 0x1337
ahh @ 0x1337
ahi 10 @ 0x1337
ahd foo a0,33 @ 0x1337
ahp 0xc0ff33 @ 0x1337
ahr 0x2a @ 0x1337
ahs 0x4 @ 0x1337
ahS jz @ 0x1337
aho call @ 0x1337
--
at 0x1337:
aha ppc @ 0x1337
ahb 16 @ 0x1337
ahc 0x804804 @ 0x1337
ahe 3,eax,+= @ 0x1337
ahf 0x12345 @ 0x1337
ahF 0x10 @ 0x1337
ahh @ 0x1337
ahi 10 @ 0x1337
ahd foo a0,33 @ 0x1337
ahp 0xc0ff33 @ 0x1337
ahr 0x2a @ 0x1337
ahs 0x4 @ 0x1337
ahS jz @ 0x1337
aho call @ 0x1337
EOF
RUN

NAME=ahlj
FILE==
CMDS=<<EOF
s 0x1337
aha ppc
ahb 16
ahc 0x804804
ahe 3,eax,+=
ahf 0x12345
ahF 0x10
ahh
ahi 10
ahd foo a0,33
ahp 0xc0ff33
ahr 42
ahs 4
ahS jz
aho call

ahi 0x4321 @ 0x0815
echo all:
ahlj
echo --
echo at 0x1337:
ahl.j @ 0x1337
EOF
EXPECT=<<EOF
all:
[{"addr":2069,"immbase":17185},{"addr":4919,"arch":"ppc","bits":16,"jump":8407044,"esil":"3,eax,+=","fail":74565,"stackframe":16,"high":true,"immbase":10,"opcode":"foo a0,33","ptr":12648243,"ret":42,"size":4,"syntax":"jz","type":"call"}]
--
at 0x1337:
[{"addr":4919,"arch":"ppc","bits":16,"jump":8407044,"esil":"3,eax,+=","fail":74565,"stackframe":16,"high":true,"immbase":10,"opcode":"foo a0,33","ptr":12648243,"ret":42,"size":4,"syntax":"jz","type":"call"}]
EOF
RUN

NAME=ahd with asm.tabs
FILE=bins/mach0/mac-ls
CMDS=<<EOF
e asm.bytes=true
e asm.flags=0
pd 3
ahd hello world
pd 3
e asm.tabs=1
pd 3
EOF
EXPECT=<<EOF
            0x100001058      55             push  rbp
            0x100001059      4889e5         mov   rbp, rsp
            0x10000105c      4157           push  r15
            0x100001058      55             hello world
            0x100001059      4889e5         mov   rbp, rsp
            0x10000105c      4157           push  r15
            0x100001058      55             hello world
            0x100001059      4889e5         mov rbp, rsp
            0x10000105c      4157           push r15
EOF
RUN

NAME=arch hints for ranges
FILE==
CMDS=<<EOF
aha arm @ 0x42
aha 0 @ 0x84
echo -- all
ahl
echo -- all json
ahlj
echo -- all cmd
ahl*
echo -- before hints
ahl. @ 0
echo -- at first
ahl. @ 0x42
echo -- between hints
ahl. @ 0x60
echo -- at second
ahl. @ 0x84
echo -- after second
ahl. @ 0x100
EOF
EXPECT=<<EOF
-- all
 0x00000042 => arch='arm'
 0x00000084 => arch=RESET
-- all json
[{"addr":66,"arch":"arm"},{"addr":132,"arch":null}]
-- all cmd
aha arm @ 0x42
aha 0 @ 0x84
-- before hints
-- at first
 0x00000042 => arch='arm'
-- between hints
 0x00000042 => arch='arm'
-- at second
 0x00000084 => arch=RESET
-- after second
 0x00000084 => arch=RESET
EOF
RUN

NAME=bits hints for ranges
FILE==
CMDS=<<EOF
ahb 16 @ 0x42
ahb 0 @ 0x84
echo -- all
ahl
echo -- all json
ahlj
echo -- all cmd
ahl*
echo -- before hints
ahl. @ 0
echo -- at first
ahl. @ 0x42
echo -- between hints
ahl. @ 0x60
echo -- at second
ahl. @ 0x84
echo -- after second
ahl. @ 0x100
EOF
EXPECT=<<EOF
-- all
 0x00000042 => bits=16
 0x00000084 => bits=RESET
-- all json
[{"addr":66,"bits":16},{"addr":132,"bits":0}]
-- all cmd
ahb 16 @ 0x42
ahb 0 @ 0x84
-- before hints
-- at first
 0x00000042 => bits=16
-- between hints
 0x00000042 => bits=16
-- at second
 0x00000084 => bits=RESET
-- after second
 0x00000084 => bits=RESET
EOF
RUN
