Skip to content

Show asm and function offset in asm deref #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/gdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,12 @@ fn recv_exec_result_asm_insns(
let new_asms = parse_asm_insns_values(asm);
if !new_asms.is_empty() {
if let Some(func_name) = &new_asms[0].func_name {
deref.final_assembly = func_name.to_owned();
deref.final_assembly = format!(
"{}+{} ({})",
func_name.to_owned(),
new_asms[0].offset,
new_asms[0].inst
);
} else {
deref.final_assembly = new_asms[0].inst.to_owned();
}
Expand All @@ -373,7 +378,12 @@ fn recv_exec_result_asm_insns(
if !new_asms.is_empty() {
// Try and show func_name, otherwise asm
if let Some(func_name) = &new_asms[0].func_name {
deref.final_assembly = func_name.to_owned();
deref.final_assembly = format!(
"{}+{} ({})",
func_name.to_owned(),
new_asms[0].offset,
new_asms[0].inst
);
} else {
deref.final_assembly = new_asms[0].inst.to_owned();
}
Expand Down
44 changes: 22 additions & 22 deletions src/snapshots/heretek__tests__render_app.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@ snapshot_kind: text
"────────────────────────────────────────────────────────────────────────|heretek-v0.3.0|────────────────────────────────────────────────────────────────────────"
" F1 main | F2 registers | F3 stack | F4 instructions | F5 output | F6 mapping | F7 hexdump | Heap | Stack | Code "
"Registers───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────"
" rax 0x401825 main "
" rbx 0x1 "
" rcx <rcx_0> 0x04 "
" rdx <rdx_0> <rdx_1> "<rdx_2>" "
" rsi <rsi_0> <rsi_1> "<rsi_2>" "
" rdi 0x1 "
" rbp <stack_8> <rbp_1> <rbp_2> 0x00 "
" rsp <stack_0> <stack_6> <stack_6_0> <stack_6_1> <rbp_1> <rbp_2> 0x00 "
" r8 0x110 "
" r9 0x4 "
" r10 0x478490 pthread_cond_signal "
" r11 0xf "
" rax 0x401825 main+0 (push %rbp) "
" rbx 0x1 "
" rcx <rcx_0> 0x04 "
" rdx <rdx_0> <rdx_1> "<rdx_2>" "
" rsi <rsi_0> <rsi_1> "<rsi_2>" "
" rdi 0x1 "
" rbp <stack_8> <rbp_1> <rbp_2> 0x00 "
" rsp <stack_0> <stack_6> <stack_6_0> <stack_6_1> <rbp_1> <rbp_2> 0x00 "
" r8 0x110 "
" r9 0x4 "
" r10 0x478490 pthread_cond_signal+0 (endbr64) "
" r11 0xf "
"Stack───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────"
" <stack_0> <stack_6> <stack_6_0> <stack_6_1> <rbp_1> <rbp_2> 0x00 "
" <stack_1> 0x40f022 malloc "
" <stack_2> 0x494b00 sbb $0x0,%al "
" <stack_3> 0x4a40e8 DW.ref.__gcc_personality_v0 "
" <stack_4> 0x00 "
" <stack_5> 0x4ab198 0x00 "
" <stack_6> <stack_6_0> <stack_6_1> <rbp_1> <rbp_2> 0x00 "
" <stack_7> 0x01 "
" <stack_8> <rbp_1> <rbp_2> 0x00 "
" <stack_9> 0x401d68 __libc_start_call_main "
" <stack_0> <stack_6> <stack_6_0> <stack_6_1> <rbp_1> <rbp_2> 0x00 "
" <stack_1> 0x40f022 malloc+418 (test %rax,%rax) "
" <stack_2> 0x494b00 sbb $0x0,%al "
" <stack_3> 0x4a40e8 DW.ref.__gcc_personality_v0+0 (xor %ah,0x47(%rsi)) "
" <stack_4> 0x00 "
" <stack_5> 0x4ab198 0x00 "
" <stack_6> <stack_6_0> <stack_6_1> <rbp_1> <rbp_2> 0x00 "
" <stack_7> 0x01 "
" <stack_8> <rbp_1> <rbp_2> 0x00 "
" <stack_9> 0x401d68 __libc_start_call_main+104 (mov %eax,%edi) "
"Instructions (main)─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────"
" 0x401823 this+1e pop %rbp "
" 0x401824 this+1f ret "
Expand Down
8 changes: 4 additions & 4 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub fn add_deref_to_span(
.all(|a| a.is_ascii_alphabetic() || a.is_ascii_graphic() || a.is_ascii_whitespace())
{
if let Ok(s) = std::str::from_utf8(&bytes) {
let cell = Span::from(format!(" \"{}\"", s)).style(Style::new().fg(YELLOW));
let cell = Span::from(format!(" \"{}\"", s)).style(Style::new().fg(YELLOW));
spans.push(cell);
continue;
}
Expand All @@ -153,17 +153,17 @@ pub fn add_deref_to_span(
let hex_width = hex_string.len();
let padding_width = width.saturating_sub(hex_width);
let mut span =
Span::from(format!(" {}{:padding$}", hex_string, "", padding = padding_width));
Span::from(format!(" {}{:padding$}", hex_string, "", padding = padding_width));
let (is_stack, is_heap, is_text) = app.classify_val(*v, filepath);
apply_val_color(&mut span, is_stack, is_heap, is_text);
spans.push(span);
}
if deref.repeated_pattern {
spans.push(Span::from(" [loop detected]").style(Style::new().fg(GRAY)));
spans.push(Span::from(" [loop detected]").style(Style::new().fg(GRAY)));
}
if !deref.final_assembly.is_empty() {
spans.push(
Span::from(format!(" {:width$}", deref.final_assembly, width = width))
Span::from(format!(" {:width$}", deref.final_assembly, width = width))
.style(Style::new().fg(ORANGE)),
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/registers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub fn draw_registers(app: &App, f: &mut Frame, register: Rect) {
let hex_width = hex_string.len();
let padding_width = width.saturating_sub(hex_width);
let mut span = Span::from(format!(
" {}{:padding$}",
" {}{:padding$}",
hex_string,
"",
padding = padding_width
Expand Down