From 204ae53289987522b7f3a5ed4424289d8e497340 Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Wed, 29 May 2024 15:35:01 -0400 Subject: Add LLIL_JUMP_TO target list to Rust API --- rust/src/llil/operation.rs | 54 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) (limited to 'rust/src') diff --git a/rust/src/llil/operation.rs b/rust/src/llil/operation.rs index 3ba4fa78..dfcfbc17 100644 --- a/rust/src/llil/operation.rs +++ b/rust/src/llil/operation.rs @@ -12,8 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -use binaryninjacore_sys::BNLowLevelILInstruction; +use binaryninjacore_sys::{BNGetLowLevelILByIndex, BNLowLevelILInstruction}; +use std::collections::BTreeMap; use std::marker::PhantomData; use std::mem; @@ -312,6 +313,36 @@ where // LLIL_JUMP_TO pub struct JumpTo; +struct TargetListIter<'func, A, M, F> +where + A: 'func + Architecture, + M: FunctionMutability, + F: FunctionForm, +{ + function: &'func Function, + cursor: BNLowLevelILInstruction, + cursor_operand: usize, +} + +impl<'func, A, M, F> TargetListIter<'func, A, M, F> +where + A: 'func + Architecture, + M: FunctionMutability, + F: FunctionForm, +{ + fn next(&mut self) -> u64 { + if self.cursor_operand >= 3 { + self.cursor = unsafe { + BNGetLowLevelILByIndex(self.function.handle, self.cursor.operands[3] as usize) + }; + self.cursor_operand = 0; + } + let result = self.cursor.operands[self.cursor_operand]; + self.cursor_operand += 1; + result + } +} + impl<'func, A, M, F> Operation<'func, A, M, F, JumpTo> where A: 'func + Architecture, @@ -321,7 +352,26 @@ where pub fn target(&self) -> Expression<'func, A, M, F, ValueExpr> { Expression::new(self.function, self.op.operands[0] as usize) } - // TODO target list + + pub fn target_list(&self) -> BTreeMap { + let mut result = BTreeMap::new(); + let count = self.op.operands[1] as usize / 2; + let mut list = TargetListIter { + function: self.function, + cursor: unsafe { + BNGetLowLevelILByIndex(self.function.handle, self.op.operands[2] as usize) + }, + cursor_operand: 0, + }; + + for _ in 0..count { + let value = list.next(); + let target = list.next() as usize; + result.insert(value, target); + } + + result + } } // LLIL_CALL, LLIL_CALL_SSA -- cgit v1.3.1