summaryrefslogtreecommitdiff
path: root/rust/src
diff options
context:
space:
mode:
authorRusty Wagner <rusty.wagner@gmail.com>2024-05-29 15:35:01 -0400
committerRusty Wagner <rusty.wagner@gmail.com>2024-05-29 15:35:01 -0400
commit204ae53289987522b7f3a5ed4424289d8e497340 (patch)
tree64962532f85d19b4cb3fb3dd5d8520f925f2adc0 /rust/src
parent309e4b3d84987bba9d8ad0990c8cbec781f90b7a (diff)
Add LLIL_JUMP_TO target list to Rust API
Diffstat (limited to 'rust/src')
-rw-r--r--rust/src/llil/operation.rs54
1 files changed, 52 insertions, 2 deletions
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<A, M, F>,
+ 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<u64, usize> {
+ 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