summaryrefslogtreecommitdiff
path: root/rust/src
diff options
context:
space:
mode:
Diffstat (limited to 'rust/src')
-rw-r--r--rust/src/callingconvention.rs36
-rw-r--r--rust/src/function.rs16
-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
-rw-r--r--rust/src/llil/operation.rs20
-rw-r--r--rust/src/mlil/function.rs14
-rw-r--r--rust/src/mlil/instruction.rs10
-rw-r--r--rust/src/mlil/lift.rs1
-rw-r--r--rust/src/types.rs2
11 files changed, 137 insertions, 9 deletions
diff --git a/rust/src/callingconvention.rs b/rust/src/callingconvention.rs
index 991b46a9..ef2725e8 100644
--- a/rust/src/callingconvention.rs
+++ b/rust/src/callingconvention.rs
@@ -569,11 +569,43 @@ impl<A: Architecture> CallingConventionBase for CallingConvention<A> {
}
fn int_arg_registers(&self) -> Vec<A::Register> {
- Vec::new()
+ unsafe {
+ let mut count = 0;
+ let regs = BNGetIntegerArgumentRegisters(self.handle, &mut count);
+ let arch = self.arch_handle.borrow();
+
+ let res = slice::from_raw_parts(regs, count)
+ .iter()
+ .map(|&r| {
+ arch.register_from_id(r)
+ .expect("bad reg id from CallingConvention")
+ })
+ .collect();
+
+ BNFreeRegisterList(regs);
+
+ res
+ }
}
fn float_arg_registers(&self) -> Vec<A::Register> {
- Vec::new()
+ unsafe {
+ let mut count = 0;
+ let regs = BNGetFloatArgumentRegisters(self.handle, &mut count);
+ let arch = self.arch_handle.borrow();
+
+ let res = slice::from_raw_parts(regs, count)
+ .iter()
+ .map(|&r| {
+ arch.register_from_id(r)
+ .expect("bad reg id from CallingConvention")
+ })
+ .collect();
+
+ BNFreeRegisterList(regs);
+
+ res
+ }
}
fn arg_registers_shared_index(&self) -> bool {
diff --git a/rust/src/function.rs b/rust/src/function.rs
index d2f685df..74e05ea5 100644
--- a/rust/src/function.rs
+++ b/rust/src/function.rs
@@ -314,6 +314,22 @@ impl Function {
}
}
+ pub fn parameter_variables(&self) -> Conf<Vec<Variable>> {
+ unsafe {
+ let mut variables = BNGetFunctionParameterVariables(self.handle);
+ let mut result = Vec::with_capacity(variables.count);
+ let confidence = variables.confidence;
+ let vars = std::slice::from_raw_parts(variables.vars, variables.count);
+
+ for i in 0..variables.count {
+ result.push(Variable::from_raw(vars[i]));
+ }
+
+ BNFreeParameterVariables(&mut variables);
+ Conf::new(result, confidence)
+ }
+ }
+
pub fn apply_imported_types(&self, sym: &Symbol, t: Option<&Type>) {
unsafe {
BNApplyImportedTypes(
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 {
diff --git a/rust/src/llil/operation.rs b/rust/src/llil/operation.rs
index 3c40f207..3ba4fa78 100644
--- a/rust/src/llil/operation.rs
+++ b/rust/src/llil/operation.rs
@@ -89,10 +89,10 @@ pub struct Syscall;
pub struct Intrinsic;
impl<'func, A, M, V> Operation<'func, A, M, NonSSA<V>, Intrinsic>
- where
- A: 'func + Architecture,
- M: FunctionMutability,
- V: NonSSAVariant,
+where
+ A: 'func + Architecture,
+ M: FunctionMutability,
+ V: NonSSAVariant,
{
// TODO: Support register and expression lists
pub fn intrinsic(&self) -> Option<A::Intrinsic> {
@@ -382,12 +382,20 @@ where
}
}
+ pub fn true_target_idx(&self) -> usize {
+ self.op.operands[1] as usize
+ }
+
pub fn false_target(&self) -> Instruction<'func, A, M, F> {
Instruction {
function: self.function,
instr_idx: self.op.operands[2] as usize,
}
}
+
+ pub fn false_target_idx(&self) -> usize {
+ self.op.operands[2] as usize
+ }
}
// LLIL_GOTO
@@ -405,6 +413,10 @@ where
instr_idx: self.op.operands[0] as usize,
}
}
+
+ pub fn target_idx(&self) -> usize {
+ self.op.operands[0] as usize
+ }
}
// LLIL_FLAG_COND
diff --git a/rust/src/mlil/function.rs b/rust/src/mlil/function.rs
index 16cc5102..0b662578 100644
--- a/rust/src/mlil/function.rs
+++ b/rust/src/mlil/function.rs
@@ -2,6 +2,7 @@ use core::hash::{Hash, Hasher};
use binaryninjacore_sys::BNFreeMediumLevelILFunction;
use binaryninjacore_sys::BNGetMediumLevelILBasicBlockList;
+use binaryninjacore_sys::BNGetMediumLevelILIndexForInstruction;
use binaryninjacore_sys::BNGetMediumLevelILInstructionCount;
use binaryninjacore_sys::BNGetMediumLevelILOwnerFunction;
use binaryninjacore_sys::BNGetMediumLevelILSSAForm;
@@ -65,6 +66,19 @@ impl MediumLevelILFunction {
self.instruction_from_idx(expr_idx).lift()
}
+ pub fn instruction_from_instruction_idx(&self, instr_idx: usize) -> MediumLevelILInstruction {
+ MediumLevelILInstruction::new(self.to_owned(), unsafe {
+ BNGetMediumLevelILIndexForInstruction(self.handle, instr_idx)
+ })
+ }
+
+ pub fn lifted_instruction_from_instruction_idx(
+ &self,
+ instr_idx: usize,
+ ) -> MediumLevelILLiftedInstruction {
+ self.instruction_from_instruction_idx(instr_idx).lift()
+ }
+
pub fn instruction_count(&self) -> usize {
unsafe { BNGetMediumLevelILInstructionCount(self.handle) }
}
diff --git a/rust/src/mlil/instruction.rs b/rust/src/mlil/instruction.rs
index 3b5dcfb4..bd2cc717 100644
--- a/rust/src/mlil/instruction.rs
+++ b/rust/src/mlil/instruction.rs
@@ -18,6 +18,7 @@ pub struct MediumLevelILInstruction {
pub function: Ref<MediumLevelILFunction>,
pub address: u64,
pub index: usize,
+ pub size: usize,
pub kind: MediumLevelILInstructionKind,
}
@@ -704,7 +705,12 @@ impl MediumLevelILInstruction {
}),
// translated directly into a list for Expression or Variables
// TODO MLIL_MEMORY_INTRINSIC_SSA needs to be handled properly
- MLIL_CALL_OUTPUT | MLIL_CALL_PARAM | MLIL_CALL_PARAM_SSA | MLIL_CALL_OUTPUT_SSA | MLIL_MEMORY_INTRINSIC_OUTPUT_SSA | MLIL_MEMORY_INTRINSIC_SSA => {
+ MLIL_CALL_OUTPUT
+ | MLIL_CALL_PARAM
+ | MLIL_CALL_PARAM_SSA
+ | MLIL_CALL_OUTPUT_SSA
+ | MLIL_MEMORY_INTRINSIC_OUTPUT_SSA
+ | MLIL_MEMORY_INTRINSIC_SSA => {
unreachable!()
}
};
@@ -713,6 +719,7 @@ impl MediumLevelILInstruction {
function,
address: op.address,
index,
+ size: op.size,
kind,
}
}
@@ -1022,6 +1029,7 @@ impl MediumLevelILInstruction {
function: self.function.clone(),
address: self.address,
index: self.index,
+ size: self.size,
kind,
}
}
diff --git a/rust/src/mlil/lift.rs b/rust/src/mlil/lift.rs
index 39e8e983..e8548b06 100644
--- a/rust/src/mlil/lift.rs
+++ b/rust/src/mlil/lift.rs
@@ -27,6 +27,7 @@ pub struct MediumLevelILLiftedInstruction {
pub function: Ref<MediumLevelILFunction>,
pub address: u64,
pub index: usize,
+ pub size: usize,
pub kind: MediumLevelILLiftedInstructionKind,
}
diff --git a/rust/src/types.rs b/rust/src/types.rs
index 280d50fd..426b0487 100644
--- a/rust/src/types.rs
+++ b/rust/src/types.rs
@@ -1235,7 +1235,7 @@ impl fmt::Debug for Type {
self.handle,
container,
"".as_ptr() as *const c_char,
- 80,
+ 64,
false,
BNTokenEscapingType::NoTokenEscapingType,
&mut count as *mut usize,