Skip to content

Commit be0f095

Browse files
committed
[Rust] Add LowLevelILFunction::{get_ssa_register_value, get_ssa_flag_value}
These are available on `LowLevelILFunction<M, SSA>`.
1 parent 6293afc commit be0f095

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

rust/src/low_level_il/function.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ use std::marker::PhantomData;
1818

1919
use binaryninjacore_sys::*;
2020

21-
use crate::architecture::CoreArchitecture;
21+
use crate::architecture::{CoreArchitecture, CoreFlag};
2222
use crate::basic_block::BasicBlock;
2323
use crate::function::Function;
2424
use crate::low_level_il::block::LowLevelILBlock;
2525
use crate::rc::*;
26+
use crate::variable::RegisterValue;
2627

2728
use super::*;
2829

@@ -297,6 +298,37 @@ impl<M: FunctionMutability> Ref<LowLevelILFunction<M, SSA>> {
297298
};
298299
self.instruction_from_index(LowLevelInstructionIndex(instr_idx))
299300
}
301+
302+
/// Returns the value of the given SSA register.
303+
#[must_use]
304+
pub fn get_ssa_register_value<R: ArchReg>(
305+
&self,
306+
reg: &LowLevelILSSARegisterKind<R>,
307+
) -> Option<RegisterValue> {
308+
let register_id = match reg {
309+
LowLevelILSSARegisterKind::Full { kind, .. } => kind.id(),
310+
LowLevelILSSARegisterKind::Partial { partial_reg, .. } => partial_reg.id(),
311+
};
312+
let value = unsafe {
313+
BNGetLowLevelILSSARegisterValue(self.handle, register_id.into(), reg.version() as usize)
314+
};
315+
if value.state == BNRegisterValueType::UndeterminedValue {
316+
return None;
317+
}
318+
Some(value.into())
319+
}
320+
321+
/// Returns the value of the given SSA flag.
322+
#[must_use]
323+
pub fn get_ssa_flag_value(&self, flag: &LowLevelILSSAFlag<CoreFlag>) -> Option<RegisterValue> {
324+
let value = unsafe {
325+
BNGetLowLevelILSSAFlagValue(self.handle, flag.flag.id().0, flag.version as usize)
326+
};
327+
if value.state == BNRegisterValueType::UndeterminedValue {
328+
return None;
329+
}
330+
Some(value.into())
331+
}
300332
}
301333

302334
impl<M, F> ToOwned for LowLevelILFunction<M, F>

0 commit comments

Comments
 (0)