colorize output

This commit is contained in:
🪞👃🪞 2025-02-22 22:15:20 +02:00
parent 9deba511bd
commit 40356b31c7
2 changed files with 15 additions and 6 deletions

View file

@ -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<str> {
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()
}
}

View file

@ -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<T> = Result<T, Box<dyn std::error::Error>>;
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,