Skip to content
mnitchevPublic

About

Process memory visualiser

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

16 Commits

Folders and files

Repository files navigation

mview

mview is a Linux process memory visualizer. It will attempt to read all of the memory pages of a process and print the memory data in a table format, where each address's data is presented in hex format. If an address' value is an ascii character, mview will by default print the ascii character (this can be turned off).

This tool is intended to help with performing a Stack Buffer Overflow, which is why the stack is opened first by default when running mview. However all the mapped memory regions are read and can be visualized. To learn more about what maps are available and how they are read see /proc/[pid]/maps and /proc/[pid]/mem.

mview demo: stack view, disassembly at the program counter, pause, fuzzy search, sections and strings

Installation and running

mview runs on Linux only. Download a static binary (amd64 or arm64) from the releases page:

curl -LO https://github.com/mnitchev/memvis/releases/download/v0.4.1/mview-v0.4.1-linux-amd64
chmod +x mview-v0.4.1-linux-amd64
sudo mv mview-v0.4.1-linux-amd64 /usr/local/bin/mview

Or build it with Rust:

cargo install --path .

To run it:

sudo mview -p <pid> [options]

If you installed it with cargo, run sudo ~/.cargo/bin/mview, because sudo does not search ~/.cargo/bin.

NOTE: You need root privileges to view the memory of another process.

Usage

Usage: mview [OPTIONS] --pid <PID>

Options:
  -p, --pid <PID>                      PID of the process to inspect
  -s, --start-address <START_ADDRESS>  Address to start at (hex). Defaults to the current stack pointer
  -n, --no-ptrace                      Read the stack pointer from /proc/<pid>/syscall instead of using ptrace
  -w, --width <WIDTH>                  Bytes per row [default: 16]
  -b, --print-bytes                    Hide the ASCII column
  -h, --help                           Print help
  -V, --version                        Print version

Interface

  • Regions (left): every mapping from /proc/[pid]/maps. Under each code region, mview lists the executable ELF sections it maps (.init, .plt, .text, .fini). It reads them from the section table of the mapped file. The current entry is highlighted. Unreadable regions are grey. The panel hides when the terminal is too narrow.
  • Memory (right): address, hex bytes, ASCII. The title shows the current ELF section (if known) and the details of the current region. ·· marks unmapped or unreadable bytes.
  • The stack pointer byte has a yellow background, and its row address is yellow.
  • Bytes that change flash red for one second.
  • Asm view (Tab or p): disassembles memory for the host architecture (x86-64 or aarch64) with capstone. The instruction at the program counter is marked with ▶. Bytes that are not code show as data, like objdump does. Printable runs show as .string "..." and everything else as .byte with an ASCII preview. In mapped files, mview knows what is code from the executable ELF sections. So the ELF header, .rodata and the symbol tables show as data even inside an r-xp mapping. Elsewhere, bytes that do not decode as an instruction show as data. Jumps are yellow, calls magenta and returns red. In this view, scrolling moves by instructions.
  • The memory view refreshes 10 times a second. The maps and the registers (SP and PC) refresh once a second.

Controls

The controls follow vim. Most motions take a count, for example 10j or 3l. A pending count or g shows in the status bar.

Key Function
j / k, Down / Up Scroll one row (hex) or instruction (asm) down / up
Ctrl-d / Ctrl-u Scroll half a page down / up
Ctrl-f / Ctrl-b Scroll one page down / up (also PgDn / PgUp)
Space Pause / resume the process (SIGSTOP / SIGCONT). mview resumes it when it exits
gg / G Go to the start / last page of the current section or region
h / l, Left / Right Previous / next entry in the region list (h goes to the start of the current entry first)
s Go to the stack pointer
p Go to the program counter in the asm view
Tab Switch between the hex view and the asm view
: Go to an address. Type it in hex, then press Enter
/, n / N Fuzzy search, next / previous match (see below)
Ctrl-w v Split: open a new window to the right of the current one
Ctrl-w c Close the current window
Ctrl-w w, Ctrl-w h/l Focus the next window, or the window to the left / right
Ctrl-w < / > / = Narrow / widen the current window by 4 columns, or reset all to automatic
< / > / = Narrow / widen the region sidebar, or reset it to automatic
Esc Cancel a pending count, g, prompt or search
q / Ctrl-c Quit

Windows

On a wide terminal you can open several memory windows side by side, like vim's :vsplit. Each window has its own address and its own hex or asm view. For example, to watch the stack and the code at the same time, press Ctrl-w v, then p in the new window. The left window shows the stack in hex with the SP marker, and the right window shows the disassembly at the program counter. Both update live.

Keys act on the focused window, which has a cyan border. The sidebar follows the focused window. Search highlighting, pause and the SP/PC markers apply to all windows. By default, a hex window takes only the width its rows need, and asm windows share the rest. To resize a window, drag the border between it and the next window, or use Ctrl-w < / Ctrl-w >. A resized window keeps its width until Ctrl-w =. Use < or hide the sidebar if the windows get tight.

Mouse

  • The wheel scrolls the pane under the pointer. Over the memory view it moves 3 rows or instructions. Over the sidebar it moves the region list, and the view stays put. The list scrolls back to show the current entry when you move to another region or section.
  • A click on a region or section in the sidebar goes there. A click on a window focuses it. The wheel scrolls the window under the pointer, even when another window has focus.
  • Dragging the border between the sidebar and the memory view resizes the sidebar. Dragging the border between two windows resizes the window on its left. Drag it to the left edge to hide the sidebar.

mview captures the mouse, so to select text in the terminal, hold Shift (Option in iTerm2 on macOS) while you drag.

Search

/ searches the rows on screen as you type. The match is fuzzy and ignores case. The query splits into words at spaces and punctuation. Each word must match inside one word of the row, with its letters in order but not necessarily next to each other. The query words must appear in order. For example, ldr sp matches ldr w1, [sp, #0x1c] and fff matches #0x7fffffff.

  • In the asm view, mview searches each instruction's text.
  • In the hex view, mview searches the ASCII column. It also highlights the matching bytes in the hex column.

Matched characters are black on yellow, and rows that do not match are dimmed. Enter keeps the search while you scroll. Esc clears it.

n / N put the next / previous matching row at the top of the page. The search continues past the page and skips unmapped gaps. The hex view searches readable regions, up to 64 MB per keypress. The asm view searches executable regions and mapped files with a known section table (so it finds strings too). It searches up to 4 MB per keypress.

Development on macOS

./dev.sh builds mview in a Linux container (Docker or OrbStack) and runs it against samples/running. To run another command in the container, pass it as arguments, for example ./dev.sh cargo test.

The source recording is docs/demo.cast. Play it with asciinema play docs/demo.cast. To re-record it after a UI change, run ./dev.sh bash scripts/record-demo.sh.

About

Process memory visualiser

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages