update rust crate

This commit is contained in:
2024-08-17 16:20:28 +02:00
parent 670fa334db
commit 2167e0512a
88 changed files with 20508 additions and 1741 deletions
+41
View File
@@ -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 {
+15 -11
View File
@@ -1,12 +1,10 @@
use binaryninjacore_sys::BNFromVariableIdentifier;
use binaryninjacore_sys::BNGetHighLevelILByIndex;
use binaryninjacore_sys::BNHighLevelILOperation;
use crate::architecture::CoreIntrinsic;
use crate::operand_iter::OperandIter;
use crate::rc::Ref;
use crate::types::{
ConstantData, ILIntrinsic, RegisterValue, RegisterValueType, SSAVariable, Variable,
};
use crate::types::{ConstantData, RegisterValue, RegisterValueType, SSAVariable, Variable};
use super::operation::*;
use super::{HighLevelILFunction, HighLevelILLiftedInstruction, HighLevelILLiftedInstructionKind};
@@ -15,6 +13,8 @@ use super::{HighLevelILFunction, HighLevelILLiftedInstruction, HighLevelILLifted
pub struct HighLevelILInstruction {
pub function: Ref<HighLevelILFunction>,
pub address: u64,
pub index: usize,
pub size: usize,
pub kind: HighLevelILInstructionKind,
}
@@ -144,8 +144,8 @@ pub enum HighLevelILInstructionKind {
DoWhileSsa(WhileSsa),
}
impl HighLevelILInstruction {
pub(crate) fn new(function: Ref<HighLevelILFunction>, idx: usize) -> Self {
let op = unsafe { BNGetHighLevelILByIndex(function.handle, idx, function.full_ast) };
pub(crate) fn new(function: Ref<HighLevelILFunction>, index: usize) -> Self {
let op = unsafe { BNGetHighLevelILByIndex(function.handle, index, function.full_ast) };
use BNHighLevelILOperation::*;
use HighLevelILInstructionKind as Op;
let kind = match op.operation {
@@ -610,8 +610,8 @@ impl HighLevelILInstruction {
body: op.operands[1] as usize,
}),
HLIL_DO_WHILE => Op::DoWhile(While {
condition: op.operands[0] as usize,
body: op.operands[1] as usize,
body: op.operands[0] as usize,
condition: op.operands[1] as usize,
}),
HLIL_WHILE_SSA => Op::WhileSsa(WhileSsa {
condition_phi: op.operands[0] as usize,
@@ -627,6 +627,8 @@ impl HighLevelILInstruction {
Self {
function,
address: op.address,
index,
size: op.size,
kind,
}
}
@@ -809,11 +811,11 @@ impl HighLevelILInstruction {
cond_false: self.lift_operand(op.cond_false),
}),
Intrinsic(op) => Lifted::Intrinsic(LiftedIntrinsic {
intrinsic: ILIntrinsic::new(self.function.get_function().arch(), op.intrinsic),
intrinsic: CoreIntrinsic(self.function.get_function().arch().0, op.intrinsic),
params: self.lift_instruction_list(op.first_param, op.num_params),
}),
IntrinsicSsa(op) => Lifted::IntrinsicSsa(LiftedIntrinsicSsa {
intrinsic: ILIntrinsic::new(self.function.get_function().arch(), op.intrinsic),
intrinsic: CoreIntrinsic(self.function.get_function().arch().0, op.intrinsic),
params: self.lift_instruction_list(op.first_param, op.num_params),
dest_memory: op.dest_memory,
src_memory: op.src_memory,
@@ -875,6 +877,8 @@ impl HighLevelILInstruction {
HighLevelILLiftedInstruction {
function: self.function.clone(),
address: self.address,
index: self.index,
size: self.size,
kind,
}
}
@@ -979,7 +983,7 @@ fn get_float(value: u64, size: usize) -> f64 {
}
fn get_var(id: u64) -> Variable {
unsafe { Variable::from_raw(BNFromVariableIdentifier(id)) }
unsafe { Variable::from_identifier(id) }
}
fn get_member_index(idx: u64) -> Option<usize> {
+135 -3
View File
@@ -1,7 +1,9 @@
use super::{operation::*, HighLevelILFunction};
use super::operation::*;
use super::HighLevelILFunction;
use crate::architecture::CoreIntrinsic;
use crate::rc::Ref;
use crate::types::{ConstantData, ILIntrinsic, SSAVariable, Variable};
use crate::types::{ConstantData, SSAVariable, Variable};
#[derive(Clone)]
pub enum HighLevelILLiftedOperand {
@@ -11,7 +13,7 @@ pub enum HighLevelILLiftedOperand {
Float(f64),
Int(u64),
IntList(Vec<u64>),
Intrinsic(ILIntrinsic),
Intrinsic(CoreIntrinsic),
Label(GotoLabel),
MemberIndex(Option<usize>),
Var(Variable),
@@ -23,6 +25,8 @@ pub enum HighLevelILLiftedOperand {
pub struct HighLevelILLiftedInstruction {
pub function: Ref<HighLevelILFunction>,
pub address: u64,
pub index: usize,
pub size: usize,
pub kind: HighLevelILLiftedInstructionKind,
}
@@ -153,6 +157,134 @@ pub enum HighLevelILLiftedInstructionKind {
}
impl HighLevelILLiftedInstruction {
pub fn name(&self) -> &'static str {
use HighLevelILLiftedInstructionKind::*;
match self.kind {
Nop => "Nop",
Break => "Break",
Continue => "Continue",
Noret => "Noret",
Unreachable => "Unreachable",
Bp => "Bp",
Undef => "Undef",
Unimpl => "Unimpl",
Adc(_) => "Adc",
Sbb(_) => "Sbb",
Rlc(_) => "Rlc",
Rrc(_) => "Rrc",
Add(_) => "Add",
Sub(_) => "Sub",
And(_) => "And",
Or(_) => "Or",
Xor(_) => "Xor",
Lsl(_) => "Lsl",
Lsr(_) => "Lsr",
Asr(_) => "Asr",
Rol(_) => "Rol",
Ror(_) => "Ror",
Mul(_) => "Mul",
MuluDp(_) => "MuluDp",
MulsDp(_) => "MulsDp",
Divu(_) => "Divu",
DivuDp(_) => "DivuDp",
Divs(_) => "Divs",
DivsDp(_) => "DivsDp",
Modu(_) => "Modu",
ModuDp(_) => "ModuDp",
Mods(_) => "Mods",
ModsDp(_) => "ModsDp",
CmpE(_) => "CmpE",
CmpNe(_) => "CmpNe",
CmpSlt(_) => "CmpSlt",
CmpUlt(_) => "CmpUlt",
CmpSle(_) => "CmpSle",
CmpUle(_) => "CmpUle",
CmpSge(_) => "CmpSge",
CmpUge(_) => "CmpUge",
CmpSgt(_) => "CmpSgt",
CmpUgt(_) => "CmpUgt",
TestBit(_) => "TestBit",
AddOverflow(_) => "AddOverflow",
Fadd(_) => "Fadd",
Fsub(_) => "Fsub",
Fmul(_) => "Fmul",
Fdiv(_) => "Fdiv",
FcmpE(_) => "FcmpE",
FcmpNe(_) => "FcmpNe",
FcmpLt(_) => "FcmpLt",
FcmpLe(_) => "FcmpLe",
FcmpGe(_) => "FcmpGe",
FcmpGt(_) => "FcmpGt",
FcmpO(_) => "FcmpO",
FcmpUo(_) => "FcmpUo",
ArrayIndex(_) => "ArrayIndex",
ArrayIndexSsa(_) => "ArrayIndexSsa",
Assign(_) => "Assign",
AssignMemSsa(_) => "AssignMemSsa",
AssignUnpack(_) => "AssignUnpack",
AssignUnpackMemSsa(_) => "AssignUnpackMemSsa",
Block(_) => "Block",
Call(_) => "Call",
Tailcall(_) => "Tailcall",
CallSsa(_) => "CallSsa",
Case(_) => "Case",
Const(_) => "Const",
ConstPtr(_) => "ConstPtr",
Import(_) => "Import",
ConstData(_) => "ConstData",
Deref(_) => "Deref",
AddressOf(_) => "AddressOf",
Neg(_) => "Neg",
Not(_) => "Not",
Sx(_) => "Sx",
Zx(_) => "Zx",
LowPart(_) => "LowPart",
BoolToInt(_) => "BoolToInt",
UnimplMem(_) => "UnimplMem",
Fsqrt(_) => "Fsqrt",
Fneg(_) => "Fneg",
Fabs(_) => "Fabs",
FloatToInt(_) => "FloatToInt",
IntToFloat(_) => "IntToFloat",
FloatConv(_) => "FloatConv",
RoundToInt(_) => "RoundToInt",
Floor(_) => "Floor",
Ceil(_) => "Ceil",
Ftrunc(_) => "Ftrunc",
DerefFieldSsa(_) => "DerefFieldSsa",
DerefSsa(_) => "DerefSsa",
ExternPtr(_) => "ExternPtr",
FloatConst(_) => "FloatConst",
For(_) => "For",
ForSsa(_) => "ForSsa",
Goto(_) => "Goto",
Label(_) => "Label",
If(_) => "If",
Intrinsic(_) => "Intrinsic",
IntrinsicSsa(_) => "IntrinsicSsa",
Jump(_) => "Jump",
MemPhi(_) => "MemPhi",
Ret(_) => "Ret",
Split(_) => "Split",
StructField(_) => "StructField",
DerefField(_) => "DerefField",
Switch(_) => "Switch",
Syscall(_) => "Syscall",
SyscallSsa(_) => "SyscallSsa",
Trap(_) => "Trap",
VarDeclare(_) => "VarDeclare",
Var(_) => "Var",
VarInit(_) => "VarInit",
VarInitSsa(_) => "VarInitSsa",
VarPhi(_) => "VarPhi",
VarSsa(_) => "VarSsa",
While(_) => "While",
DoWhile(_) => "DoWhile",
WhileSsa(_) => "WhileSsa",
DoWhileSsa(_) => "DoWhileSsa",
}
}
pub fn operands(&self) -> Vec<(&'static str, HighLevelILLiftedOperand)> {
use HighLevelILLiftedInstructionKind::*;
use HighLevelILLiftedOperand as Operand;
+8 -8
View File
@@ -1,22 +1,22 @@
use binaryninjacore_sys::BNGetGotoLabelName;
use crate::architecture::CoreIntrinsic;
use crate::function::Function;
use crate::rc::Ref;
use crate::types::{ConstantData, ILIntrinsic, SSAVariable, Variable};
use crate::string::BnString;
use crate::types::{ConstantData, SSAVariable, Variable};
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 {
pub fn name(&self) -> &str {
let raw_str = unsafe { BNGetGotoLabelName(self.function.handle, self.target) };
let c_str = unsafe { core::ffi::CStr::from_ptr(raw_str) };
c_str.to_str().unwrap()
pub fn name(&self) -> BnString {
unsafe { BnString::from_raw(BNGetGotoLabelName(self.function.handle, self.target)) }
}
}
@@ -320,7 +320,7 @@ pub struct Intrinsic {
}
#[derive(Clone, Debug, PartialEq)]
pub struct LiftedIntrinsic {
pub intrinsic: ILIntrinsic,
pub intrinsic: CoreIntrinsic,
pub params: Vec<HighLevelILLiftedInstruction>,
}
@@ -335,7 +335,7 @@ pub struct IntrinsicSsa {
}
#[derive(Clone, Debug, PartialEq)]
pub struct LiftedIntrinsicSsa {
pub intrinsic: ILIntrinsic,
pub intrinsic: CoreIntrinsic,
pub params: Vec<HighLevelILLiftedInstruction>,
pub dest_memory: u64,
pub src_memory: u64,