From 40356b31c782473485bd18faea27c2ce8a99263f Mon Sep 17 00:00:00 2001 From: unspeaker Date: Sat, 22 Feb 2025 22:15:20 +0200 Subject: [PATCH] colorize output --- crates/vestal/src/show.rs | 18 ++++++++++++------ crates/vestal/src/util.rs | 3 +++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/crates/vestal/src/show.rs b/crates/vestal/src/show.rs index 37c75ab..5c87ad0 100644 --- a/crates/vestal/src/show.rs +++ b/crates/vestal/src/show.rs @@ -38,10 +38,12 @@ impl Show { let module = call.map(|call|call.module.as_ref()).flatten(); let method = call.map(|call|call.method.as_ref()).flatten(); if module.is_some() || method.is_some() { - println!(" {}{}{}", + println!(" {GREEN}{}{}{}{RESET}", module.map(|x|x.as_ref()).unwrap_or(&""), if module.is_some() && method.is_some() { "::" } else { "" }, method.map(|x|x.as_ref()).unwrap_or(&"")); + } else { + println!(" {RED}(unresolved){RESET}"); } } @@ -69,7 +71,7 @@ impl Show { } else { write!(&mut output, " "); } - write!(&mut output, "{byte:08x}"); + write!(&mut output, "{:08x}", byte + base); } write!(&mut output, "{DIM}"); if (byte >= addr) && (byte < addr + length) { @@ -85,23 +87,27 @@ impl Show { } } write!(&mut output, "{:02x}", dll.code[byte]); + write!(&mut output, "{RESET}"); if byte % line == line - 1 { + if snap(byte) == snap(addr) { + let dasm = Self::call_dasm(&dll.code[addr..addr+length]); + write!(&mut output, " -> {dasm}"); + } write!(&mut output, " \n"); } - write!(&mut output, "{RESET}"); } print!("{output}"); } - pub fn call_dasm (bytes: &[u8]) { + pub fn call_dasm (bytes: &[u8]) -> Arc { let mut decoder = Decoder::with_ip(64, bytes, 0x0, DecoderOptions::NONE); while decoder.can_decode() { let position = decoder.position(); let instruction = decoder.decode(); let opcodes = &bytes[position..position+instruction.len()]; - println!(" ╰-------> {BOLD}{instruction}{RESET} ({DIM}{}{RESET})", fmt_bytes(opcodes)); - break + return format!("{BOLD}{instruction}{RESET} ({DIM}{}{RESET})", fmt_bytes(opcodes)).into() } + Default::default() } } diff --git a/crates/vestal/src/util.rs b/crates/vestal/src/util.rs index db72f74..8c72160 100644 --- a/crates/vestal/src/util.rs +++ b/crates/vestal/src/util.rs @@ -17,12 +17,15 @@ pub(crate) use ::pretty_hex::*; pub(crate) use ::exe::{Buffer, PE, VecPE, PtrPE, types::*, headers::*}; pub(crate) use ::iced_x86::{Encoder, Decoder, DecoderOptions, Instruction, OpKind, FlowControl}; pub(crate) type Usually = Result>; +pub const ESC: &str = "\u{001b}"; pub const RESET: &str = "\u{001b}[0m"; pub const BOLD: &str = "\u{001b}[1m"; pub const DIM: &str = "\u{001b}[2m"; pub const ITALIC: &str = "\u{001b}[3m"; pub const UNDERLINE: &str = "\u{001b}[4m"; pub const INVERT: &str = "\u{001b}[7m"; +pub const RED: &str = "\u{001b}[1;31m"; +pub const GREEN: &str = "\u{001b}[1;32m"; pub enum Verbosity { Silent, Terse,