From 0609276712622908254065546102381466033141 Mon Sep 17 00:00:00 2001 From: Glenn Smith Date: Tue, 5 Mar 2024 02:09:39 -0500 Subject: Rust: Implement instruction_llil for CoreArchitecture --- rust/src/llil/function.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'rust/src/llil/function.rs') diff --git a/rust/src/llil/function.rs b/rust/src/llil/function.rs index f0aba63a..8f1eac62 100644 --- a/rust/src/llil/function.rs +++ b/rust/src/llil/function.rs @@ -20,6 +20,7 @@ use binaryninjacore_sys::BNNewLowLevelILFunctionReference; use std::borrow::Borrow; use std::marker::PhantomData; +use crate::architecture::CoreArchitecture; use crate::basicblock::BasicBlock; use crate::rc::*; @@ -174,6 +175,37 @@ where } } +// Allow instantiating Lifted IL functions for querying Lifted IL from Architectures +impl Function> { + pub fn new( + arch: CoreArchitecture, + source_func: Option, + ) -> Result, ()> { + use binaryninjacore_sys::BNCreateLowLevelILFunction; + use std::ptr::null_mut; + + let handle = unsafe { + match source_func { + Some(func) => BNCreateLowLevelILFunction(arch.0, func.handle), + None => BNCreateLowLevelILFunction(arch.0, null_mut()), + } + }; + if handle.is_null() { + return Err(()); + } + + Ok(unsafe { + Ref::new(Self { + borrower: arch, + handle, + _arch: PhantomData, + _mutability: PhantomData, + _form: PhantomData, + }) + }) + } +} + impl<'func, A, M, F> ToOwned for Function where A: 'func + Architecture, -- cgit v1.3.1