Skip to content

Commit 6eea1f3

Browse files
Merge pull request #212 from wcampbell0x2a/162-display-registers-ptr-to-stack
2 parents 7123699 + f9fda7a commit 6eea1f3

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/snapshots/heretek__tests__render_app.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ snapshot_kind: text
1717
" r8 → 0x110 ║"
1818
" r9 → 0x4 ▼"
1919
"Stack───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────"
20-
" <stack_0> → <stack_6> → <stack_6_0> → <stack_6_1> → <rbp_1> → <rbp_2> → 0x00 "
20+
" <stack_0> (rsp)→ <stack_6> → <stack_6_0> → <stack_6_1> → <rbp_1> → <rbp_2> → 0x00 "
2121
" <stack_1> → 0x40f022 → malloc+418 (test rax,rax) "
2222
" <stack_2> → 0x494b00 → sbb al,0x0 "
2323
" <stack_3> → 0x4a40e8 → DW.ref.__gcc_personality_v0+0 (xor BYTE PTR [rsi+0x47],ah) "
2424
" <stack_4> → 0x00 "
2525
" <stack_5> → 0x4ab198 → 0x00 "
2626
" <stack_6> → <stack_6_0> → <stack_6_1> → <rbp_1> → <rbp_2> → 0x00 "
2727
" <stack_7> → 0x01 "
28-
" <stack_8> → <rbp_1> → <rbp_2> → 0x00 "
28+
" <stack_8> (rbp)→ <rbp_1> → <rbp_2> → 0x00 "
2929
" <stack_9> → 0x401d68 → __libc_start_call_main+104 (mov edi,eax) "
3030
"Instructions (main)─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────"
3131
" 0x401823 this+1e pop rbp "

src/ui/stack.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::collections::HashMap;
2+
13
use ratatui::prelude::Stylize;
24
use ratatui::text::{Line, Span, Text};
35
use ratatui::widgets::{Block, Borders, Paragraph};
@@ -14,6 +16,20 @@ pub fn draw_stack(state: &mut State, f: &mut Frame, stack: Rect) {
1416
let width: usize = if state.ptr_size == PtrSize::Size32 { 11 } else { 19 };
1517

1618
let stacks = state.stack.clone();
19+
20+
// Build map of address -> register names
21+
let mut addr_to_regs: HashMap<u64, Vec<String>> = HashMap::new();
22+
for reg in &state.registers {
23+
if let Some(ref register) = reg.register
24+
&& let Some(ref val_str) = register.value
25+
&& let Some(hex) = val_str.strip_prefix("0x")
26+
&& let Ok(val) = u64::from_str_radix(hex, 16)
27+
&& stacks.contains_key(&val)
28+
{
29+
addr_to_regs.entry(val).or_default().push(reg.name.clone());
30+
}
31+
}
32+
1733
for (addr, values) in &stacks {
1834
let filepath = state.filepath.clone().unwrap_or_default();
1935
let filepath = filepath.to_string_lossy();
@@ -24,6 +40,10 @@ pub fn draw_stack(state: &mut State, f: &mut Frame, stack: Rect) {
2440
let span = Span::from(format!(" {hex_string}{:padding$}", "", padding = padding_width))
2541
.style(Style::new().fg(PURPLE));
2642
let mut spans = vec![span];
43+
if let Some(reg_names) = addr_to_regs.get(addr) {
44+
let annotation = format!(" ({})", reg_names.join(", "));
45+
spans.push(Span::from(annotation).style(Style::new().fg(ORANGE)));
46+
}
2747
add_deref_to_span(values, &mut spans, state, &filepath, &mut longest_cells, width);
2848
let line = Line::from(spans);
2949
lines.push(line);

0 commit comments

Comments
 (0)