From 3001f77f0c8ed23ee004dd0765030f056b086984 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Mon, 9 Jun 2025 23:28:34 -0400 Subject: [Rust] Add `LowLevelILExpression::{value, possible_values, possible_values_with_opts}` Needed this for WARP plugin --- rust/src/low_level_il/expression.rs | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'rust/src/low_level_il/expression.rs') diff --git a/rust/src/low_level_il/expression.rs b/rust/src/low_level_il/expression.rs index d2dbe169..5135f1c7 100644 --- a/rust/src/low_level_il/expression.rs +++ b/rust/src/low_level_il/expression.rs @@ -12,14 +12,18 @@ // See the License for the specific language governing permissions and // limitations under the License. -use binaryninjacore_sys::BNGetLowLevelILByIndex; use binaryninjacore_sys::BNLowLevelILInstruction; +use binaryninjacore_sys::{ + BNGetLowLevelILByIndex, BNGetLowLevelILExprValue, BNGetLowLevelILPossibleExprValues, +}; use super::operation; use super::operation::Operation; use super::VisitorAction; use super::*; use crate::architecture::CoreFlagWrite; +use crate::variable::{PossibleValueSet, RegisterValue}; +use crate::DataFlowQueryOption; use std::fmt; use std::fmt::{Debug, Display, Formatter}; use std::marker::PhantomData; @@ -213,11 +217,38 @@ where } } -impl LowLevelILExpression<'_, Finalized, F, ValueExpr> +impl LowLevelILExpression<'_, M, F, ValueExpr> where + M: FunctionMutability, F: FunctionForm, { - // TODO possible values + /// Value of expression if constant or a known value. + /// + /// NOTE: If a value is expressed but not concrete, use [`LowLevelILExpression::possible_values`]. + pub fn value(&self) -> RegisterValue { + let value = unsafe { BNGetLowLevelILExprValue(self.function.handle, self.index.0) }; + RegisterValue::from(value) + } + + /// Possible values of expression using path-sensitive static data flow analysis + pub fn possible_values(&self) -> PossibleValueSet { + self.possible_values_with_opts(&[]) + } + + /// Possible values of expression using path-sensitive static data flow analysis + pub fn possible_values_with_opts(&self, options: &[DataFlowQueryOption]) -> PossibleValueSet { + let value = unsafe { + BNGetLowLevelILPossibleExprValues( + self.function.handle, + self.index.0, + options.as_ptr() as *mut _, + options.len(), + ) + }; + PossibleValueSet::from_owned_core_raw(value) + } + + // TODO: Possible register, stack and flag values. } #[derive(Debug)] -- cgit v1.3.1