rizin/test/db/cmd/cmd_print
NOT XVilka c9a372c333
librz/cons/histogram: revamp visual horizontal histogram (#6365, #4431) (#6440)
This rewrites the look of the interactive horizontal histogram in Rizin -
the output of `p==v`, `p==ev`, `p==mv`, `p==0v`, `p==fv`, `p==pv`, `p==zv`,
`p==Sv` and the analysis-based interactive variants. It closes #6365 and
#4431 in full, and now sits on top of the recently merged static-histogram
PR (#6427) so it reuses the new RzHistogramOptions struct and its helpers.

Five sub-tasks from #6365:
  - Context-aware vertical ruler with up to 5 anchor labels (top, bottom,
    quarter, half, three-quarter) honouring opts->value_min..value_max,
    value_precision, value_scale and value_unit. Reuses the static
    helpers compute_ruler_gutter, render_ruler_gutter, label_value_at and
    select_ruler_label_rows so visual and static stay consistent.
  - X-axis byte-offset ruler at the bottom: `^` ticks every (addr_w + 3)
    cols followed by absolute byte offsets computed from opts->offpos +
    realj * blocksize.
  - Cursor offset + percentage shown right-aligned on the status line, with
    "Index N data V" on the left.
  - Top minimap: Unicode block characters (▁▂▃▄▅▆▇█) for the density of
    each slice of the whole data, plus a ┏━━━┓ window indicator showing the
    visible slice. Always rendered when the new `scr.hist.minimap` config
    is true. When the terminal is wide (hist->w > 200) the minimap shrinks
    by 43 columns to make room for a two-line `px 0x20`-style hex preview
    panel on the right showing the 32 bytes at the cursor's file offset.
    Each byte is wrapped in its px-style colour code (b0x00 / b0x7f /
    b0xff / btext / other) when opts->color is set, matching rz_print's
    rz_print_byte_color exactly. A trailing safety pad keeps the canvas
    from clipping the last byte of the first hex row.
  - Missing-half bug on `p==v` when the cursor is at offset 0 fixed by
    clamping `adder` to [0, histogramwidth - span]. The old expression
    `barnumber + 1 - histogramwidth/(zoom*2)` was always negative for the
    default barnumber=0, causing the rendering loop to read `data[-N]`
    (segfault on large files, missing left half on small ones).

Cursor visibility:
  - The cursor column is drawn as a CONTINUOUS vertical line connecting two
    plain markers at the top and bottom, ALWAYS exactly one character wide.
    The line itself uses the dedicated `wordhl` palette colour (default
    red background, configurable via `ec wordhl ...`), drawn on every
    chart row so the cursor is always a full-height vertical strip. The
    markers (`▼` at the top and `▲` at the bottom, or ASCII `v` / `^`
    when scr.utf8=false) are intentionally left un-highlighted so they
    read as a clean pair of arrows pointing at the cursor column.
  - The cursor screen column is computed up-front (j_cursor) by inverting
    the data-to-column map (rel * zoom * width / histogramwidth). Two
    distinct widening bugs are avoided this way:
      1. sizeofonebar > 1 (high zoom) - each data index spans several
         screen columns; only j == j_cursor && kbar == 0 renders as the
         cursor, the remaining kbar columns fall through to the gradient.
      2. histogramwidth < width (chart much wider than data) - several
         adjacent screen columns map to the same data index via integer
         truncation; only the j_cursor column may render as the cursor.

Interactive keybindings & live config:
  - The `:` hotkey drops into rz_core_visual_prompt_input, matching the
    rest of Rizin's visual modes. Lets the user run arbitrary rizin
    commands without leaving the histogram.
  - The `?` help text now uses the same colour-coded format as the
    visual / visual-bit-editor modes (rz_core_visual_append_help with
    pal.args for keys and pal.help for descriptions), shown via
    rz_cons_less_str.
  - The config-driven opts (scr.hist.minimap, scr.hist.block, scr.utf8,
    scr.color, hex.offset) are re-read on every redraw via
    refresh_visual_opts_from_config, so `:` `e scr.hist.minimap=true`
    <Enter> takes effect immediately without having to quit and re-enter.
    The canvas's `color` field is refreshed alongside so `scr.color`
    changes take effect on the same redraw.

Hex preview panel:
  - When the terminal is wide (hist->w > 200) and the minimap is enabled,
    the visual mode shows a two-line hex preview on the right of the
    minimap rows: 32 bytes at the cursor's file offset, formatted as 8
    pairs of 2 bytes separated by spaces (`abcd ef00 1234 5678 ...`),
    matching `px 0x20` minus the header / offsets / ASCII column. The
    bytes are fetched live via rz_io_read_at_mapped each redraw, so
    moving the cursor (`h` / `l`) updates the preview.
  - Each byte gets its px-style colour code: green for 0x00, red for
    0xff, yellow for 0x7f, btext (white) for printable ASCII, "other"
    (magenta) for non-printable. Mirrors rz_print_byte_color so the
    histogram preview reads consistently with `px`.
  - A trailing safety pad keeps the canvas from clipping the last hex
    byte of the first row (a side effect of UTF-8 minimap glyphs
    interacting with the canvas's width tracking when the row fills
    the canvas exactly).
  - Implemented via two new fields on RzHistogramInteractive
    (`cursor_bytes`, `cursor_bytes_len`) that the caller fills in just
    before the render call and clears right after. The minimap helper
    grows two extra parameters that the visual function passes through;
    when the panel is disabled (narrow terminal, no cursor_bytes, or
    shrinking the minimap would leave it < 40 cols) the helper falls
    back to the previous full-width minimap.

Closes #4431 in full:
  - The negative-offset crash above is the immediate segfault from the
    bug report.
  - `print_histogram_bytes` now samples one byte per block instead of
    reading nblocks contiguous bytes from core->offset. For an 8 GB file
    shown across 80 bars the original code rendered the first 80 bytes
    of the file; the new code samples at offsets brange->from + i *
    blocksize so the chart represents the full span.
  - The inner `int i` in the column-aggregation loop is renamed to `k`
    to drop the shadow over the outer `size_t i`.

Refactor on the cmd_print.c side:
  - New default_visual_opts(core, offset) returns an RZ_OWN
    RzHistogramOptions* pre-populated for the visual commands (ruler=true,
    minimap from scr.hist.minimap, offpos from caller, palette and
    screen-mode toggles from config via refresh_visual_opts_from_config).
    The nine print_visual_bytes call sites now build opts via this helper,
    then pass it to print_visual_bytes which takes ownership. Entropy
    sets value_max=8 / value_precision=1 / data_f=fdata so the visual
    histogram shows the Shannon range matching the static side.
  - `print_visual_bytes(core, opts, data, brange)` now propagates opts
    cleanup along every error path; rz_histogram_interactive_new no
    longer leaves a heap-allocated opts pointer dangling. The redraw loop
    fetches 32 cursor bytes via rz_io_read_at_mapped, points
    hist->cursor_bytes at a stack buffer for the call, then NULLs it
    back so the next iteration's fetch is independent.
  - RzHistogramInteractive gains `blocksize`, `cursor_bytes` and
    `cursor_bytes_len` fields.

New config option:
  - `scr.hist.minimap` (bool, default true) controls whether the top
    minimap is shown for p==v / p==ev. Surfaces as `opts->minimap` and
    is honoured by `rz_histogram_interactive_horizontal`. When true,
    the minimap is ALWAYS rendered (provided there's room) - even when
    the chart already shows the full data, in which case the window
    indicator spans the whole map. Changes via `:` `e scr.hist.minimap=...`
    <Enter> are picked up on the very next redraw.

Tests (33 total, 10 new for the visual side):
  - test_histogram_interactive_horizontal_basic - smoke test with
    barnumber=0 (pins the #4431 crash regression).
  - test_histogram_interactive_horizontal_ruler_percent - fractional
    labels with value_max=100 / value_scale=0.01 / unit="%".
  - test_histogram_interactive_horizontal_ruler_default - the legacy
    0..255 byte ruler.
  - test_histogram_interactive_horizontal_no_negative_adder - covers
    `p==v` at offset 0 on a small data set.
  - test_histogram_interactive_horizontal_percent - status-line percent
    indicator present.
  - test_histogram_interactive_horizontal_cursor_markers - the ▼/▲
    cursor markers (and ASCII v/^ fallback) appear on the cursor column,
    left un-highlighted.
  - test_histogram_interactive_horizontal_cursor_full_line - the cursor
    bar is rendered on every chart row between the markers regardless
    of the data threshold (continuous vertical line).
  - test_histogram_interactive_horizontal_cursor_width - pins single-
    char width across BOTH cursor-widening bugs: high zoom (sizeofonebar
    > 1) AND chart wider than data (histogramwidth < width).
  - test_histogram_interactive_horizontal_minimap_toggle - pins the
    scr.hist.minimap gating across {zoomed, not zoomed} when
    opts->minimap=true / =false.
  - test_histogram_interactive_horizontal_hex_preview - 4 cases: wide
    terminal + cursor_bytes shows the hex panel; narrow terminal
    suppresses it; missing cursor_bytes suppresses it; colour mode
    emits ANSI escape sequences for the bytes.
  Both p== integration tests in test/db/cmd/cmd_print pass with their
  regenerated EXPECT blocks (the per-block sampling change moves the
  visible bars for small buffers).

Co-authored-by: Anton Kochkov <anton.kochkov@gmail.com>
2026-06-07 14:00:31 +08:00

995 lines
43 KiB
Text
Raw Permalink 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=p2 hello-linux-x86_64
FILE=bins/elf/analysis/hello-linux-x86_64
CMDS=p2 16
EXPECT=<<EOF
----..==----##..
--==####..####..
==..##..------==
--==####..####--
==..==##--##==##
..----####--====
==..==..########
##..##==--==##--
EOF
RUN
NAME=p= various tests with malloc://
FILE==
CMDS=<<EOF
e zoom.in=block
p=p" 1 " 1 EN
echo -------
b 2
wx 0xff
e zoom.in=block
p= 2 2@ 0
EOF
EXPECT=<<EOF
0x00000000 000 0000 |#
-------
0x00000000 000 00ff |###################################################
0x00000001 001 0000 |#
EOF
RUN
NAME=p=e 5
FILE=bins/elf/arm1.bin
CMDS=p=e 5@ 0
EXPECT=<<EOF
0x00000000 000 009f |########
0x0001bec1 001 00c3 |#
0x00037d82 002 00c3 |#
0x00053c43 003 00c3 |#######################################
0x0006fb04 004 0051 |################
EOF
RUN
NAME=p= tests
FILE=bins/elf/arm1.bin
ARGS=-n
CMDS=<<EOF
p=d @!10 @ 0
echo -------
p=r
echo -------
p=r 0.73 0.06
echo -------
p=rj 0.73 0.06
echo -------
p=rq 0.73 0.06
echo -------
p=rl 0.73 0.06
echo -------
p=rt 0.73 0.06
echo -------
p=p 5@ 0
echo -------
e zoom.in=block
p=e 5 0x100
echo -------
e zoom.in=block
p=e 5 0x100 1
echo -------
e zoom.in=block
p=p 5 0x100
echo -------
e zoom.in=block
p=p 5 0x100 1
EOF
EXPECT=<<EOF
min: 0 0x0
max: 127 0x7f
unique (count): 6 0x6
range (max-min): 127 0x7f
size (of block): 10 0xa
-------
0x00000000 Falling entropy edge
-------
0x00010a00 Rising entropy edge
0x00017200 Rising entropy edge
0x00017f00 Rising entropy edge
0x0004a800 Rising entropy edge
0x0005f000 Rising entropy edge
0x00063d00 Falling entropy edge
0x00064000 Falling entropy edge
0x0006cd00 Falling entropy edge
0x00070200 Rising entropy edge
0x00073200 Falling entropy edge
0x00074300 Falling entropy edge
-------
[{"addr":68096,"index":266,"edge_type":"rising entropy edge","entropy_value":0.730819},{"addr":94720,"index":370,"edge_type":"rising entropy edge","entropy_value":0.730736},{"addr":98048,"index":383,"edge_type":"rising entropy edge","entropy_value":0.733761},{"addr":305152,"index":1192,"edge_type":"rising entropy edge","entropy_value":0.730632},{"addr":389120,"index":1520,"edge_type":"rising entropy edge","entropy_value":0.757028},{"addr":408832,"index":1597,"edge_type":"falling entropy edge","entropy_value":0.042506},{"addr":409600,"index":1600,"edge_type":"falling entropy edge","entropy_value":0.000000},{"addr":445696,"index":1741,"edge_type":"falling entropy edge","entropy_value":0.058047},{"addr":459264,"index":1794,"edge_type":"rising entropy edge","entropy_value":0.760109},{"addr":471552,"index":1842,"edge_type":"falling entropy edge","entropy_value":0.000000},{"addr":475904,"index":1859,"edge_type":"falling entropy edge","entropy_value":0.024685}]
-------
0x00010a00
0x00017200
0x00017f00
0x0004a800
0x0005f000
0x00063d00
0x00064000
0x0006cd00
0x00070200
0x00073200
0x00074300
-------
0x00010a00 10a Rising entropy edge (0.730819)
0x00017200 172 Rising entropy edge (0.730736)
0x00017f00 17f Rising entropy edge (0.733761)
0x0004a800 4a8 Rising entropy edge (0.730632)
0x0005f000 5f0 Rising entropy edge (0.757028)
0x00063d00 63d Falling entropy edge (0.042506)
0x00064000 640 Falling entropy edge (0.000000)
0x0006cd00 6cd Falling entropy edge (0.058047)
0x00070200 702 Rising entropy edge (0.760109)
0x00073200 732 Falling entropy edge (0.000000)
0x00074300 743 Falling entropy edge (0.024685)
-------
addr index edge_type entropy_value
-------------------------------------------------
0x10a00 266 rising entropy edge 0.730819
0x17200 370 rising entropy edge 0.730736
0x17f00 383 rising entropy edge 0.733761
0x4a800 1192 rising entropy edge 0.730632
0x5f000 1520 rising entropy edge 0.757028
0x63d00 1597 falling entropy edge 0.042506
0x64000 1600 falling entropy edge 0.000000
0x6cd00 1741 falling entropy edge 0.058047
0x70200 1794 rising entropy edge 0.760109
0x73200 1842 falling entropy edge 0.000000
0x74300 1859 falling entropy edge 0.024685
-------
0x00000000 000 0032 |##########
0x0001bec1 001 0031 |#
0x00037d82 002 0035 |###
0x00053c43 003 0040 |###########
0x0006fb04 004 0076 |########################
-------
0x00000000 000 005a |##################
0x00000033 001 004c |###
0x00000066 002 0057 |#################
0x00000099 003 004b |###############
0x000000cc 004 0043 |##############
-------
0x00000000 000 004c |###
0x00000033 001 0057 |#################
0x00000066 002 004b |###############
0x00000099 003 0043 |#############
0x000000cc 004 003f |#############
-------
0x00000000 000 0032 |#########
0x00000033 001 0019 |#
0x00000066 002 001e |#
0x00000099 003 001e |##
0x000000cc 004 0028 |########
-------
0x00000000 000 0019 |#
0x00000033 001 001e |#
0x00000066 002 001e |##
0x00000099 003 0028 |#######
0x000000cc 004 001e |######
EOF
RUN
NAME=ppd/ endianness
FILE==
CMDS=<<EOF
e asm.arch=arm
e cfg.bigendian=false
ppd/ 0x41574141
e cfg.bigendian=true
ppd/ 0x41574141
EOF
EXPECT=<<EOF
64
65
EOF
RUN
NAME=p8 10
FILE=malloc://1024
CMDS=wx 90909090909090909090 ; p8 10
EXPECT=<<EOF
90909090909090909090
EOF
RUN
NAME=pi 3
FILE=malloc://512
CMDS=<<EOF
e asm.arch=x86
e asm.bits=64
wx b8010000004839ca7f
pi 3
EOF
EXPECT=<<EOF
mov eax, 0x01
cmp rdx, rcx
jnle 0xa
EOF
RUN
NAME=pia output
FILE=bins/elf/analysis/hello-linux-x86_64
CMDS=<<EOF
pia 10
EOF
EXPECT=<<EOF
xor ebp, ebp
in eax, dx
mov r9, rdx
mov ecx, edx
rcr dword [rsi+0x48], 0x01
pop rsi
mov rdx, rsp
mov edx, esp
loop 0x400462
invalid
EOF
RUN
NAME=pdj 3
FILE=malloc://512
CMDS=<<EOF
e asm.arch=x86
e asm.bits=64
wx b8010000004839ca7f
pdj 3
EOF
EXPECT=<<EOF
[{"offset":0,"val":1,"esil":"1,rax,=","refptr":false,"fcn_addr":0,"fcn_last":0,"size":5,"opcode":"mov eax, 0x01","disasm":"mov eax, 0x01","bytes":"b801000000","family":"cpu","type":"mov","reloc":false,"type_num":9,"type2_num":0},{"offset":5,"esil":"rcx,rdx,==,$z,zf,:=,64,$b,cf,:=,$p,pf,:=,63,$s,sf,:=,rcx,0x8000000000000000,-,!,63,$o,^,of,:=,3,$b,af,:=","refptr":false,"fcn_addr":0,"fcn_last":0,"size":3,"opcode":"cmp rdx, rcx","disasm":"cmp rdx, rcx","bytes":"4839ca","family":"cpu","type":"cmp","reloc":false,"type_num":15,"type2_num":0},{"offset":8,"esil":"sf,of,!,^,zf,!,&,?{,10,rip,=,}","refptr":false,"fcn_addr":0,"fcn_last":0,"size":2,"opcode":"jnle 0xa","disasm":"jnle 0xa","bytes":"7f00","family":"cpu","type":"cjmp","reloc":false,"type_num":2147483649,"type2_num":0,"jump":10,"fail":10}]
EOF
RUN
NAME=pi 6
FILE=malloc://512
CMDS=<<EOF
e asm.arch=x86
e asm.bits=64
wx b8010000004839ca7f00b8010000004839ca7f00
pi 6
EOF
EXPECT=<<EOF
mov eax, 0x01
cmp rdx, rcx
jnle 0xa
mov eax, 0x01
cmp rdx, rcx
jnle 0x14
EOF
RUN
NAME=pi -5 @ 0x0040050f
FILE=bins/elf/analysis/main
CMDS=<<EOF
e asm.arch=x86
e asm.bits=64
pi -5 @ 0x0040050f
echo -------
pdj -3 @ 0x0040050f
echo -------
s 0x0040050f
pi -5
echo -------
aaa
pi -5 @ 0x0040050f
EOF
EXPECT=<<EOF
pop rbp
jmp sym.register_tm_clones
push rbp
mov rbp, rsp
mov edi, str.Hello_World
-------
[{"offset":4195590,"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,"flags":["main","sym.main"]},{"offset":4195591,"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":4195594,"ptr":4195780,"val":4195780,"esil":"4195780,rdi,=","refptr":false,"fcn_addr":0,"fcn_last":0,"size":5,"opcode":"mov edi, 0x4005c4","disasm":"mov edi, str.Hello_World","bytes":"bfc4054000","family":"cpu","type":"mov","reloc":false,"type_num":9,"type2_num":0}]
-------
pop rbp
jmp sym.register_tm_clones
push rbp
mov rbp, rsp
mov edi, str.Hello_World
-------
pop rbp
jmp sym.register_tm_clones
push rbp
mov rbp, rsp
mov edi, str.Hello_World
EOF
RUN
NAME=pif bsz
FILE=malloc://1024
CMDS=<<EOF
e asm.arch=x86
e asm.bits=64
wx 5b415c415d415e415f5dc3
af
b 2
pif
EOF
EXPECT=<<EOF
pop rbx
pop r12
pop r13
pop r14
pop r15
pop rbp
ret
EOF
RUN
NAME=pi~?
FILE=malloc://1024
CMDS=<<EOF
pi 200~?
pi 200~?
pd 200~?
EOF
EXPECT=<<EOF
200
200
200
EOF
RUN
NAME=tmpbits
FILE==
CMDS=<<EOF
e asm.arch=x86
e asm.bits=64
p8 1 @b:32
e asm.bits
EOF
EXPECT=<<EOF
00
64
EOF
RUN
NAME=tmpbits
FILE==
CMDS=<<EOF
e asm.arch=x86
e asm.bits=32
p8 1 @b:64
e asm.bits
EOF
EXPECT=<<EOF
00
32
EOF
RUN
NAME=pi 3
FILE=malloc://512
CMDS=<<EOF
e asm.arch=x86
e asm.bits=64
wx b8010000004839ca7f
pi 3
EOF
EXPECT=<<EOF
mov eax, 0x01
cmp rdx, rcx
jnle 0xa
EOF
RUN
NAME=pdj 3 (2)
FILE=malloc://512
CMDS=<<EOF
e asm.arch=x86
e asm.bits=64
wx b8010000004839ca7f
pdj 3
EOF
EXPECT=<<EOF
[{"offset":0,"val":1,"esil":"1,rax,=","refptr":false,"fcn_addr":0,"fcn_last":0,"size":5,"opcode":"mov eax, 0x01","disasm":"mov eax, 0x01","bytes":"b801000000","family":"cpu","type":"mov","reloc":false,"type_num":9,"type2_num":0},{"offset":5,"esil":"rcx,rdx,==,$z,zf,:=,64,$b,cf,:=,$p,pf,:=,63,$s,sf,:=,rcx,0x8000000000000000,-,!,63,$o,^,of,:=,3,$b,af,:=","refptr":false,"fcn_addr":0,"fcn_last":0,"size":3,"opcode":"cmp rdx, rcx","disasm":"cmp rdx, rcx","bytes":"4839ca","family":"cpu","type":"cmp","reloc":false,"type_num":15,"type2_num":0},{"offset":8,"esil":"sf,of,!,^,zf,!,&,?{,10,rip,=,}","refptr":false,"fcn_addr":0,"fcn_last":0,"size":2,"opcode":"jnle 0xa","disasm":"jnle 0xa","bytes":"7f00","family":"cpu","type":"cjmp","reloc":false,"type_num":2147483649,"type2_num":0,"jump":10,"fail":10}]
EOF
RUN
NAME=pi 6
FILE=malloc://512
CMDS=<<EOF
e asm.arch=x86
e asm.bits=64
wx b8010000004839ca7f00b8010000004839ca7f00
pi 6
EOF
EXPECT=<<EOF
mov eax, 0x01
cmp rdx, rcx
jnle 0xa
mov eax, 0x01
cmp rdx, rcx
jnle 0x14
EOF
RUN
NAME=pi -3 @ 10
FILE=malloc://512
CMDS=<<EOF
e asm.arch=x86
e asm.bits=64
wx b8010000004839ca7f00
pi -3 @ 10
EOF
EXPECT=<<EOF
mov eax, 0x01
cmp rdx, rcx
jnle 0xa
EOF
RUN
NAME=pdj -3 @ 10
FILE=malloc://512
CMDS=<<EOF
e asm.arch=x86
e asm.bits=64
wx b8010000004839ca7f00
pdj -3 @ 10~{}
EOF
EXPECT=<<EOF
[
{
"offset": 0,
"val": 1,
"esil": "1,rax,=",
"refptr": false,
"fcn_addr": 0,
"fcn_last": 0,
"size": 5,
"opcode": "mov eax, 0x01",
"disasm": "mov eax, 0x01",
"bytes": "b801000000",
"family": "cpu",
"type": "mov",
"reloc": false,
"type_num": 9,
"type2_num": 0
},
{
"offset": 5,
"esil": "rcx,rdx,==,$z,zf,:=,64,$b,cf,:=,$p,pf,:=,63,$s,sf,:=,rcx,0x8000000000000000,-,!,63,$o,^,of,:=,3,$b,af,:=",
"refptr": false,
"fcn_addr": 0,
"fcn_last": 0,
"size": 3,
"opcode": "cmp rdx, rcx",
"disasm": "cmp rdx, rcx",
"bytes": "4839ca",
"family": "cpu",
"type": "cmp",
"reloc": false,
"type_num": 15,
"type2_num": 0
},
{
"offset": 8,
"esil": "sf,of,!,^,zf,!,&,?{,10,rip,=,}",
"refptr": false,
"fcn_addr": 0,
"fcn_last": 0,
"size": 2,
"opcode": "jnle 0xa",
"disasm": "jnle 0xa",
"bytes": "7f00",
"family": "cpu",
"type": "cjmp",
"reloc": false,
"type_num": 2147483649,
"type2_num": 0,
"jump": 10,
"fail": 10
}
]
EOF
RUN
NAME=pi -10
FILE=malloc://1024
CMDS=<<EOF
e asm.arch=x86
e asm.bits=64
wx 90909090909090909090 ; s 10 ; pi -10
EOF
EXPECT=<<EOF
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
EOF
RUN
NAME=pif bsz
FILE=malloc://1024
CMDS=<<EOF
e asm.arch=x86
e asm.bits=64
wx 5b415c415d415e415f5dc3
af
b 2
pif
EOF
EXPECT=<<EOF
pop rbx
pop r12
pop r13
pop r14
pop r15
pop rbp
ret
EOF
RUN
NAME=pi~?
FILE=malloc://1024
CMDS=<<EOF
pi 200~?
pi 200~?
pd 200~?
EOF
EXPECT=<<EOF
200
200
200
EOF
RUN
NAME=tmpbits
FILE==
CMDS=<<EOF
e asm.arch=x86
e asm.bits=64
p8 1 @b:32
e asm.bits
e asm.bits=32
p8 1 @b:64
e asm.bits
EOF
EXPECT=<<EOF
00
64
00
32
EOF
RUN
NAME=pm olf
FILE=bins/elf/ioli/crackme0x00
ARGS=-n
CMDS=pm bins/src/olf.magic
EXPECT=<<EOF
0x00000000 OLF 32-bit LSB
EOF
RUN
NAME=pm lzma
FILE=bins/other/hello-world.lzma
CMDS=<<EOF
pm
pmj
EOF
EXPECT=<<EOF
0x00000000 LZMA BE compressed data dictionary size: 32768 bytes,
[{"address":0,"magic":"LZMA BE compressed data dictionary size: 32768 bytes,"}]
EOF
EXPECT_ERR=
RUN
NAME=pm hello.c
FILE=bins/src/hello.c
CMDS=pm
EXPECT=<<EOF
0x00000000 C source code
EOF
RUN
NAME=pm elf/main
FILE=bins/elf/analysis/main
ARGS=-n
CMDS=<<EOF
pm
pmj
EOF
EXPECT=<<EOF
0x00000000 ELF 64-bit LSB executable, x86-64, version 1
[{"address":0,"magic":"ELF 64-bit LSB executable, x86-64, version 1"}]
EOF
RUN
NAME=pm mach0/fatmach0-3true
FILE=bins/mach0/fatmach0-3true
ARGS=-n
CMDS=pm
EXPECT=<<EOF
0x00000000 Fat-Mach-O version 3.0 Mach-O fat file with 3 architectures
0x00001000 Mach-O
0x00003140 MacOS Deteched Code Signature
0x00005000 Mach-O
0x00007120 MacOS Deteched Code Signature
0x00009000 Mach-O
0x0000b060 MacOS Deteched Code Signature
EOF
RUN
NAME=pm perl/exam.pm
FILE=bins/perl/exam.pm
ARGS=-n
CMDS=pm
EXPECT=<<EOF
0x00000000 Perl5 module source text
EOF
RUN
NAME=pm perl/exam.pl
FILE=bins/perl/exam.pl
ARGS=-n
CMDS=pm
EXPECT=<<EOF
0x00000000 Perl script text executable
EOF
RUN
NAME=pm java/Hello.class
FILE=bins/java/Hello.class
ARGS=-n
CMDS=pm
EXPECT=<<EOF
0x00000000 Java CLASS
EOF
RUN
NAME=pm pe/a.exe
FILE=bins/pe/a.exe
ARGS=-n
CMDS=pm
EXPECT=<<EOF
0x00000000 PE for MS Windows (console) Intel 80386 32-bit
EOF
RUN
NAME=pib from beginning of bb & inside bb
FILE=bins/elf/analysis/x64-loop
CMDS=<<EOF
s main
af
pib
echo -------
so 2
pib
EOF
EXPECT=<<EOF
push rbp
mov rbp, rsp
sub rsp, 0x20
mov dword [var_1ch], edi
mov qword [var_28h], rsi
mov dword [var_ch], 0x00
jmp 0x400523
-------
sub rsp, 0x20
mov dword [var_1ch], edi
mov qword [var_28h], rsi
mov dword [var_ch], 0x00
jmp 0x400523
EOF
RUN
NAME=pI size > bocksize
FILE=malloc://1024
CMDS=<<EOF
e asm.arch=x86
e asm.bits=64
wx 90909090909090909090
b 1
pI 10
EOF
EXPECT=<<EOF
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
EOF
RUN
NAME=psW 32 utf32le & psM 32 utf32be
FILE=bins/elf/crackme0x00b
CMDS=<<EOF
psW @ obj.pass.1964
echo --------
psM @ 0x0804a03d
EOF
EXPECT=<<EOF
w0wgreat
--------
w0wgreat
EOF
RUN
NAME=io.unalloc, io.unalloc.ch and prc
FILE=bins/elf/analysis/tiny.elf
CMDS=<<EOF
. scripts/palette.rz
(print; prc 0x00010032-0x0000fffa @ 0x0000fffa)
e io.unalloc=true
e scr.color=0
.(print)
echo
e io.unalloc.ch=-
.(print)
echo
e scr.color=3
e io.unalloc.ch=
.(print)
echo
e io.unalloc.ch=?
.(print)
EOF
EXPECT=<<EOF
0x0000fffa ????????????se,,,,,,
0x0001000a .. ..
0x0001001a en....OO,,OO;; ..
0x0001002a .. ##########
0x0000fffa ------------se,,,,,,
0x0001000a .. ..
0x0001001a en....OO,,OO;; ..
0x0001002a .. ##########
0x0000fffa ............se         
0x0001000a                 
0x0001001a       en         
0x0001002a         
0x0000fffa ????????????se         
0x0001000a                 
0x0001001a       en         
0x0001002a         
EOF
RUN
NAME=prc text color
FILE==
CMDS=<<EOF
. scripts/palette.rz
woe 0 0xff 1
(test_flag; f `p8 1`)
.(test_flag) @@s:0 0x100 1
e scr.color=3
prc 256
EOF
EXPECT=<<EOF
0x00000000 000102030405060708090a0b0c0d0e0f
0x00000010 101112131415161718191a1b1c1d1e1f
0x00000020 202122232425262728292a2b2c2d2e2f
0x00000030 303132333435363738393a3b3c3d3e3f
0x00000040 404142434445464748494a4b4c4d4e4f
0x00000050 505152535455565758595a5b5c5d5e5f
0x00000060 606162636465666768696a6b6c6d6e6f
0x00000070 707172737475767778797a7b7c7d7e7f
0x00000080 808182838485868788898a8b8c8d8e8f
0x00000090 909192939495969798999a9b9c9d9e9f
0x000000a0 a0a1a2a3a4a5a6a7a8a9aaabacadaeaf
0x000000b0 b0b1b2b3b4b5b6b7b8b9babbbcbdbebf
0x000000c0 c0c1c2c3c4c5c6c7c8c9cacbcccdcecf
0x000000d0 d0d1d2d3d4d5d6d7d8d9dadbdcdddedf
0x000000e0 e0e1e2e3e4e5e6e7e8e9eaebecedeeef
0x000000f0 f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff
EOF
RUN
NAME=prc single-char-flag fix
FILE==
CMDS=<<EOF
woe 0 0xff 1
f s @ 0x77
prc 256
EOF
EXPECT=<<EOF
0x00000000
0x00000010
0x00000020 ................................
0x00000030 ................................
0x00000040 ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
0x00000050 ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
0x00000060 ::::::::::::::::::::::::::::::::
0x00000070 :::::::::::::: s::::::::::::::::
0x00000080 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
0x00000090 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
0x000000a0 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
0x000000b0 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
0x000000c0 OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
0x000000d0 OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
0x000000e0 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
0x000000f0 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@##
EOF
RUN
NAME=prc hex.offset=0
FILE==
CMDS=<<EOF
e hex.offset=0
woe 0 0xff 1
f s @ 0x77
prc 256
EOF
EXPECT=<<EOF
................................
................................
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
::::::::::::::::::::::::::::::::
:::::::::::::: s::::::::::::::::
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@##
EOF
RUN
NAME=p=e hex.offset=0
FILE==
CMDS=<<EOF
e hex.offset=0
e scr.color=0
woe 0 0xff 1
p=e 10
EOF
EXPECT=<<EOF
000 00b4 |#
001 00b4 |#
002 00b4 |#
003 00b4 |#
004 00b4 |###################################
005 0004 |
006 0000 |#
007 0000 |#
008 0000 |#
009 0000 |#
EOF
RUN
NAME=pxA hex.offset=0
FILE==
CMDS=<<EOF
e asm.arch=x86
e asm.bits=64
e hex.offset=0
e scr.color=0
woe 0 0xff 1
pxA 10
EOF
EXPECT=<<EOF
++++++ _| 10
EOF
RUN
NAME=pxf
FILE=bins/elf/analysis/main
CMDS=<<EOF
e asm.arch=x86
e asm.bits=64
aaa
pxf
EOF
EXPECT=<<EOF
0x00400410 31ed 4989 d15e 4889 e248 83e4 f050 5449 1.I..^H..H...PTI
0x00400420 c7c0 b005 4000 48c7 c120 0540 0048 c7c7 ....@.H.. .@.H..
EOF
RUN
NAME=p== horizontal histogram ruler
FILE=malloc://8
CMDS=<<EOF
wx ff00ff00ff00ff00
e scr.color=0
e scr.hist.ruler=true
e scr.utf8=false
p== 8
echo ---
e scr.utf8=true
p== 8
EOF
EXPECT=<<EOF
255|########## ########## ########## ##########
|########## ########## ########## ##########
|########## ########## ########## ##########
197|########## ########## ########## ##########
|########## ########## ########## ##########
|########## ########## ########## ##########
138|########## ########## ########## ##########
|########## ########## ########## ##########
|########## ########## ########## ##########
79|########## ########## ########## ##########
|########## ########## ########## ##########
|########## ########## ########## ##########
|########## ########## ########## ##########
0|##########__________##########_________##########__________##########_________
^ ^ ^
0x0 0x3 0x7
---
255│██████████ ██████████ ██████████ ██████████
│██████████ ██████████ ██████████ ██████████
│██████████ ██████████ ██████████ ██████████
197│██████████ ██████████ ██████████ ██████████
│██████████ ██████████ ██████████ ██████████
│██████████ ██████████ ██████████ ██████████
138│██████████ ██████████ ██████████ ██████████
│██████████ ██████████ ██████████ ██████████
│██████████ ██████████ ██████████ ██████████
79│██████████ ██████████ ██████████ ██████████
│██████████ ██████████ ██████████ ██████████
│██████████ ██████████ ██████████ ██████████
│██████████ ██████████ ██████████ ██████████
0│██████████__________██████████_________██████████__________██████████_________
^ ^ ^
0x0 0x3 0x7
EOF
RUN
NAME=p== horizontal histogram ruler complex
FILE=malloc://182
CMDS=<<EOF
wx 31ed4989d15e4889e24883e4f050544531c031c9488d3d85e4ffffff1517080200f4662e0f1f8400000000000f1f4000488d3de90a0200488d05e20a02004839f87415488b05f60702004885c07409ffe00f1f8000000000c30f1f8000000000488d3db90a0200488d35b20a02004829fe4889f048c1ee3f48c1f8034801c648d1fe7414488b05f50702004885c07408ffe0660f1f440000c30f1f8000000000f30f1efa803dbd0a020000752b5548833dd2070200004889e5740c488b3de6070200e801dfffffe864ffffffc605950a0200015dc30f1f00c30f1f8000000000f30f1efae977ffffff662e0f1f840000000000662e0f1f840000000000662e0f
e scr.color=0
e scr.hist.ruler=true
e scr.utf8=false
p== 80
echo ---
e scr.utf8=true
p== 80
EOF
EXPECT=<<EOF
255| # #
| # # # # # # # #
| # # ## # # # # # # # #
197| # # # ## # # # # # # # # #
| # # # ## # # # ## # # # # ## # #
| # # # ## # # # ## # # # # # ## # #
138| # # # ## # # # ## # # # # # ## # #
| # ### ## # ## # ## ## # ## ## # # ## # # #
| # ### ## # ## # ## ## # ## ## # # ### ### #
79| # ### ## # # ## # ## ## # ## ## # # ### #### #
| ## #### ## # # ## # ## ## # ## ## # # ### #### #
| ####### #### # # ### ## ## ## ### # ## ## ############ #### #
|############## # # ### ## ## ## ### # ## ## ############ #### #
0|###############__#_#___###__##_#####_####__##__##__##_############___#####_##_
^ ^ ^
0x0 0x4e 0x9e
---
255│ █ █
│ █ █ █ █ █ █ █ █
│ █ █ ██ █ █ █ █ █ █ █ █
197│ █ █ █ ██ █ █ █ █ █ █ █ █ █
│ █ █ █ ██ █ █ █ ██ █ █ █ █ ██ █ █
│ █ █ █ ██ █ █ █ ██ █ █ █ █ █ ██ █ █
138│ █ █ █ ██ █ █ █ ██ █ █ █ █ █ ██ █ █
│ █ ███ ██ █ ██ █ ██ ██ █ ██ ██ █ █ ██ █ █ █
│ █ ███ ██ █ ██ █ ██ ██ █ ██ ██ █ █ ███ ███ █
79│ █ ███ ██ █ █ ██ █ ██ ██ █ ██ ██ █ █ ███ ████ █
│ ██ ████ ██ █ █ ██ █ ██ ██ █ ██ ██ █ █ ███ ████ █
│ ███████ ████ █ █ ███ ██ ██ ██ ███ █ ██ ██ ████████████ ████ █
│██████████████ █ █ ███ ██ ██ ██ ███ █ ██ ██ ████████████ ████ █
0│███████████████__█_█___███__██_█████_████__██__██__██_████████████___█████_██_
^ ^ ^
0x0 0x4e 0x9e
EOF
RUN