summaryrefslogtreecommitdiff
path: root/rust/src
diff options
context:
space:
mode:
authorGlenn Smith <glenn@vector35.com>2024-03-05 02:09:39 -0500
committerGlenn Smith <glenn@vector35.com>2024-03-05 14:01:31 -0500
commit0609276712622908254065546102381466033141 (patch)
tree2b5fe0e1e16f0fcb21e09c5fb87e360f1968a76d /rust/src
parent2596349220399080054037011947884060414345 (diff)
Rust: Implement instruction_llil for CoreArchitecture
Diffstat (limited to 'rust/src')
-rw-r--r--rust/src/architecture.rs19
-rw-r--r--rust/src/llil/function.rs32
2 files changed, 46 insertions, 5 deletions
diff --git a/rust/src/architecture.rs b/rust/src/architecture.rs
index 1d343972..ee0e3cd3 100644
--- a/rust/src/architecture.rs
+++ b/rust/src/architecture.rs
@@ -1172,14 +1172,23 @@ impl Architecture for CoreArchitecture {
}
}
}
-
+
fn instruction_llil(
&self,
- _data: &[u8],
- _addr: u64,
- _il: &mut Lifter<Self>,
+ data: &[u8],
+ addr: u64,
+ il: &mut Lifter<Self>,
) -> Option<(usize, bool)> {
- None
+ let mut size = data.len();
+ let success = unsafe {
+ BNGetInstructionLowLevelIL(self.0, data.as_ptr(), addr, &mut size as *mut _, il.handle)
+ };
+
+ if !success {
+ None
+ } else {
+ Some((size, true))
+ }
}
fn flag_write_llil<'a>(
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<CoreArchitecture, Mutable, NonSSA<LiftedNonSSA>> {
+ pub fn new(
+ arch: CoreArchitecture,
+ source_func: Option<crate::function::Function>,
+ ) -> Result<Ref<Self>, ()> {
+ 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<A, M, F>
where
A: 'func + Architecture,