From c3f344a38ca4b027b4e69b0f82d3184622d6da79 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Tue, 29 Apr 2025 16:05:54 -0400 Subject: [Rust] Pretty print LLIL sub expressions --- rust/src/architecture.rs | 3 ++- rust/src/low_level_il/expression.rs | 10 +++++----- rust/src/low_level_il/function.rs | 6 +++--- 3 files changed, 10 insertions(+), 9 deletions(-) (limited to 'rust/src') diff --git a/rust/src/architecture.rs b/rust/src/architecture.rs index 3573f1fb..7ad10dfb 100644 --- a/rust/src/architecture.rs +++ b/rust/src/architecture.rs @@ -418,7 +418,7 @@ pub trait Intrinsic: Debug + Sized + Clone + Copy { fn outputs(&self) -> Vec>>; } -pub trait Architecture: 'static + Sized + AsRef { +pub trait Architecture: 'static + Sized + AsRef + Debug { type Handle: Borrow + Clone; type RegisterInfo: RegisterInfo; @@ -3234,6 +3234,7 @@ where } } +#[derive(Debug)] pub struct CustomArchitectureHandle where A: 'static + Architecture> + Send + Sync, diff --git a/rust/src/low_level_il/expression.rs b/rust/src/low_level_il/expression.rs index fd403c76..f8fcf9f7 100644 --- a/rust/src/low_level_il/expression.rs +++ b/rust/src/low_level_il/expression.rs @@ -21,7 +21,7 @@ use super::VisitorAction; use super::*; use crate::architecture::Architecture; use std::fmt; -use std::fmt::{Display, Formatter}; +use std::fmt::{Debug, Display, Formatter}; use std::marker::PhantomData; /// Used as a marker for an [`LowLevelILExpression`] that **can** produce a value. @@ -32,7 +32,7 @@ pub struct ValueExpr; #[derive(Copy, Clone, Debug)] pub struct VoidExpr; -pub trait ExpressionResultType: 'static {} +pub trait ExpressionResultType: 'static + Debug {} impl ExpressionResultType for ValueExpr {} impl ExpressionResultType for VoidExpr {} @@ -102,9 +102,9 @@ where R: ExpressionResultType, { fn fmt(&self, f: &mut Formatter) -> fmt::Result { - f.debug_struct("Expression") - .field("index", &self.index) - .finish() + let op = unsafe { BNGetLowLevelILByIndex(self.function.handle, self.index.0) }; + let t = unsafe { LowLevelILExpressionKind::from_raw(self.function, op) }; + t.fmt(f) } } diff --git a/rust/src/low_level_il/function.rs b/rust/src/low_level_il/function.rs index 85037632..301c3f09 100644 --- a/rust/src/low_level_il/function.rs +++ b/rust/src/low_level_il/function.rs @@ -35,7 +35,7 @@ pub struct Mutable; #[derive(Copy, Clone, Debug)] pub struct Finalized; -pub trait FunctionMutability: 'static {} +pub trait FunctionMutability: 'static + Debug {} impl FunctionMutability for Mutable {} impl FunctionMutability for Finalized {} @@ -44,7 +44,7 @@ pub struct LiftedNonSSA; #[derive(Copy, Clone, Debug)] pub struct RegularNonSSA; -pub trait NonSSAVariant: 'static {} +pub trait NonSSAVariant: 'static + Debug {} impl NonSSAVariant for LiftedNonSSA {} impl NonSSAVariant for RegularNonSSA {} @@ -53,7 +53,7 @@ pub struct SSA; #[derive(Copy, Clone, Debug)] pub struct NonSSA(V); -pub trait FunctionForm: 'static {} +pub trait FunctionForm: 'static + Debug {} impl FunctionForm for SSA {} impl FunctionForm for NonSSA {} -- cgit v1.3.1