summaryrefslogtreecommitdiff
path: root/rust/src
diff options
context:
space:
mode:
authorRusty Wagner <rusty.wagner@gmail.com>2024-04-26 18:26:12 -0400
committerRusty Wagner <rusty.wagner@gmail.com>2024-04-30 13:12:21 -0400
commitbec653143bd78f1662ed1a556c4b00471f395fcc (patch)
tree30e5db55a4660970f6730315851ee09d848555e5 /rust/src
parentf193132145f62cac0ffeebc3ff918ebf9dd37103 (diff)
Add HLIL APIs to fetch the root or by instruction index, and expose the operation size in the Rust API
Diffstat (limited to 'rust/src')
-rw-r--r--rust/src/hlil/function.rs41
-rw-r--r--rust/src/hlil/instruction.rs3
-rw-r--r--rust/src/hlil/lift.rs1
-rw-r--r--rust/src/hlil/operation.rs2
4 files changed, 46 insertions, 1 deletions
diff --git a/rust/src/hlil/function.rs b/rust/src/hlil/function.rs
index 4bad7f0f..25608d71 100644
--- a/rust/src/hlil/function.rs
+++ b/rust/src/hlil/function.rs
@@ -2,8 +2,10 @@ use std::hash::{Hash, Hasher};
use binaryninjacore_sys::BNFreeHighLevelILFunction;
use binaryninjacore_sys::BNGetHighLevelILBasicBlockList;
+use binaryninjacore_sys::BNGetHighLevelILIndexForInstruction;
use binaryninjacore_sys::BNGetHighLevelILInstructionCount;
use binaryninjacore_sys::BNGetHighLevelILOwnerFunction;
+use binaryninjacore_sys::BNGetHighLevelILRootExpr;
use binaryninjacore_sys::BNGetHighLevelILSSAForm;
use binaryninjacore_sys::BNHighLevelILFunction;
use binaryninjacore_sys::BNNewHighLevelILFunctionReference;
@@ -52,6 +54,29 @@ impl HighLevelILFunction {
self.instruction_from_idx(expr_idx).lift()
}
+ pub fn instruction_from_instruction_idx(&self, instr_idx: usize) -> HighLevelILInstruction {
+ HighLevelILInstruction::new(self.as_non_ast(), unsafe {
+ BNGetHighLevelILIndexForInstruction(self.handle, instr_idx)
+ })
+ }
+
+ pub fn lifted_instruction_from_instruction_idx(
+ &self,
+ instr_idx: usize,
+ ) -> HighLevelILLiftedInstruction {
+ self.instruction_from_instruction_idx(instr_idx).lift()
+ }
+
+ pub fn root(&self) -> HighLevelILInstruction {
+ HighLevelILInstruction::new(self.as_ast(), unsafe {
+ BNGetHighLevelILRootExpr(self.handle)
+ })
+ }
+
+ pub fn lifted_root(&self) -> HighLevelILLiftedInstruction {
+ self.root().lift()
+ }
+
pub fn instruction_count(&self) -> usize {
unsafe { BNGetHighLevelILInstructionCount(self.handle) }
}
@@ -81,6 +106,22 @@ impl HighLevelILFunction {
unsafe { Array::new(blocks, count, context) }
}
+
+ pub fn as_ast(&self) -> Ref<HighLevelILFunction> {
+ Self {
+ handle: self.handle,
+ full_ast: true,
+ }
+ .to_owned()
+ }
+
+ pub fn as_non_ast(&self) -> Ref<HighLevelILFunction> {
+ Self {
+ handle: self.handle,
+ full_ast: false,
+ }
+ .to_owned()
+ }
}
impl ToOwned for HighLevelILFunction {
diff --git a/rust/src/hlil/instruction.rs b/rust/src/hlil/instruction.rs
index 9bffadaf..7e77e379 100644
--- a/rust/src/hlil/instruction.rs
+++ b/rust/src/hlil/instruction.rs
@@ -16,6 +16,7 @@ pub struct HighLevelILInstruction {
pub function: Ref<HighLevelILFunction>,
pub address: u64,
pub index: usize,
+ pub size: usize,
pub kind: HighLevelILInstructionKind,
}
@@ -629,6 +630,7 @@ impl HighLevelILInstruction {
function,
address: op.address,
index,
+ size: op.size,
kind,
}
}
@@ -878,6 +880,7 @@ impl HighLevelILInstruction {
function: self.function.clone(),
address: self.address,
index: self.index,
+ size: self.size,
kind,
}
}
diff --git a/rust/src/hlil/lift.rs b/rust/src/hlil/lift.rs
index 74ae0c64..731a785c 100644
--- a/rust/src/hlil/lift.rs
+++ b/rust/src/hlil/lift.rs
@@ -24,6 +24,7 @@ pub struct HighLevelILLiftedInstruction {
pub function: Ref<HighLevelILFunction>,
pub address: u64,
pub index: usize,
+ pub size: usize,
pub kind: HighLevelILLiftedInstructionKind,
}
diff --git a/rust/src/hlil/operation.rs b/rust/src/hlil/operation.rs
index 965d9517..ee0d437b 100644
--- a/rust/src/hlil/operation.rs
+++ b/rust/src/hlil/operation.rs
@@ -9,7 +9,7 @@ use super::HighLevelILLiftedInstruction;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct GotoLabel {
pub(crate) function: Ref<Function>,
- pub(crate) target: u64,
+ pub target: u64,
}
impl GotoLabel {