summaryrefslogtreecommitdiff
path: root/rust/src/hlil/block.rs
diff options
context:
space:
mode:
authorRubens Brandao <git@rubens.io>2023-11-22 18:57:28 -0300
committerKyleMiles <krm504@nyu.edu>2024-02-02 13:32:45 -0500
commitf682ca69b356755fe6c06bcdd8f4fab73f7d2c78 (patch)
tree3cfc324cfe8043ccc8db1161f1f90c448d097c8a /rust/src/hlil/block.rs
parente1a6bdcd576f7caeaa6f97ff1e337a259057b333 (diff)
Rust API : Add HLIL Bindings
Diffstat (limited to 'rust/src/hlil/block.rs')
-rw-r--r--rust/src/hlil/block.rs63
1 files changed, 63 insertions, 0 deletions
diff --git a/rust/src/hlil/block.rs b/rust/src/hlil/block.rs
new file mode 100644
index 00000000..a90429a4
--- /dev/null
+++ b/rust/src/hlil/block.rs
@@ -0,0 +1,63 @@
+use std::ops::Range;
+
+use binaryninjacore_sys::BNGetHighLevelILIndexForInstruction;
+
+use crate::basicblock::{BasicBlock, BlockContext};
+use crate::rc::Ref;
+
+use super::{HighLevelILFunction, HighLevelILInstruction};
+
+pub struct HighLevelILBlockIter {
+ function: Ref<HighLevelILFunction>,
+ range: Range<u64>,
+}
+
+impl Iterator for HighLevelILBlockIter {
+ type Item = HighLevelILInstruction;
+
+ fn next(&mut self) -> Option<Self::Item> {
+ self.range
+ .next()
+ .map(|i| unsafe {
+ BNGetHighLevelILIndexForInstruction(self.function.handle, i as usize)
+ })
+ .map(|i| HighLevelILInstruction::new(&self.function, i))
+ }
+}
+
+pub struct HighLevelILBlock {
+ pub(crate) function: Ref<HighLevelILFunction>,
+}
+
+impl core::fmt::Debug for HighLevelILBlock {
+ fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
+ write!(f, "mlil_bb {:?}", self.function)
+ }
+}
+
+impl BlockContext for HighLevelILBlock {
+ type Iter = HighLevelILBlockIter;
+ type Instruction = HighLevelILInstruction;
+
+ fn start(&self, block: &BasicBlock<Self>) -> HighLevelILInstruction {
+ let expr_idx = unsafe {
+ BNGetHighLevelILIndexForInstruction(self.function.handle, block.raw_start() as usize)
+ };
+ HighLevelILInstruction::new(&self.function, expr_idx)
+ }
+
+ fn iter(&self, block: &BasicBlock<Self>) -> HighLevelILBlockIter {
+ HighLevelILBlockIter {
+ function: self.function.to_owned(),
+ range: block.raw_start()..block.raw_end(),
+ }
+ }
+}
+
+impl Clone for HighLevelILBlock {
+ fn clone(&self) -> Self {
+ HighLevelILBlock {
+ function: self.function.to_owned(),
+ }
+ }
+}