Skip to content

Commit e767296

Browse files
committed
Rename LowLevelILExpression to Expression in Rust API
1 parent 4c03aca commit e767296

File tree

9 files changed

+256
-299
lines changed

9 files changed

+256
-299
lines changed

arch/riscv/src/lib.rs

Lines changed: 26 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use std::marker::PhantomData;
3737
use binaryninja::architecture::{BranchKind, IntrinsicId, RegisterId};
3838
use binaryninja::confidence::{Conf, MAX_CONFIDENCE, MIN_CONFIDENCE};
3939
use binaryninja::logger::Logger;
40-
use binaryninja::low_level_il::expression::{LowLevelILExpressionKind, ValueExpr};
40+
use binaryninja::low_level_il::expression::{ExpressionKind, ValueExpr};
4141
use binaryninja::low_level_il::instruction::InstructionKind;
4242
use binaryninja::low_level_il::lifting::{
4343
LiftableLowLevelIL, LiftableLowLevelILWithSize, LowLevelILLabel,
@@ -2868,9 +2868,7 @@ impl FunctionRecognizer for RiscVELFPLTRecognizer {
28682868
let (auipc_dest, plt_base) = match auipc {
28692869
InstructionKind::SetReg(r) => {
28702870
let value = match r.source_expr().kind() {
2871-
LowLevelILExpressionKind::Const(v) | LowLevelILExpressionKind::ConstPtr(v) => {
2872-
v.value()
2873-
}
2871+
ExpressionKind::Const(v) | ExpressionKind::ConstPtr(v) => v.value(),
28742872
_ => return false,
28752873
};
28762874
(r.dest_reg(), value)
@@ -2882,43 +2880,28 @@ impl FunctionRecognizer for RiscVELFPLTRecognizer {
28822880
let load = next_llil_instr.next().unwrap().kind();
28832881
let (mut entry, mut target_reg) = match load {
28842882
InstructionKind::SetReg(r) => match r.source_expr().kind() {
2885-
LowLevelILExpressionKind::Load(l) => {
2883+
ExpressionKind::Load(l) => {
28862884
let target_reg = r.dest_reg();
28872885
let entry = match l.source_mem_expr().kind() {
2888-
LowLevelILExpressionKind::Reg(lr) if lr.source_reg() == auipc_dest => {
2889-
plt_base
2890-
}
2891-
LowLevelILExpressionKind::Add(a) => {
2892-
match (a.left().kind(), a.right().kind()) {
2893-
(
2894-
LowLevelILExpressionKind::Reg(a),
2895-
LowLevelILExpressionKind::Const(b)
2896-
| LowLevelILExpressionKind::ConstPtr(b),
2897-
) if a.source_reg() == auipc_dest => {
2898-
plt_base.wrapping_add(b.value())
2899-
}
2900-
(
2901-
LowLevelILExpressionKind::Const(b)
2902-
| LowLevelILExpressionKind::ConstPtr(b),
2903-
LowLevelILExpressionKind::Reg(a),
2904-
) if a.source_reg() == auipc_dest => {
2905-
plt_base.wrapping_add(b.value())
2906-
}
2907-
_ => return false,
2908-
}
2909-
}
2910-
LowLevelILExpressionKind::Sub(a) => {
2911-
match (a.left().kind(), a.right().kind()) {
2912-
(
2913-
LowLevelILExpressionKind::Reg(a),
2914-
LowLevelILExpressionKind::Const(b)
2915-
| LowLevelILExpressionKind::ConstPtr(b),
2916-
) if a.source_reg() == auipc_dest => {
2917-
plt_base.wrapping_sub(b.value())
2918-
}
2919-
_ => return false,
2920-
}
2921-
}
2886+
ExpressionKind::Reg(lr) if lr.source_reg() == auipc_dest => plt_base,
2887+
ExpressionKind::Add(a) => match (a.left().kind(), a.right().kind()) {
2888+
(
2889+
ExpressionKind::Reg(a),
2890+
ExpressionKind::Const(b) | ExpressionKind::ConstPtr(b),
2891+
) if a.source_reg() == auipc_dest => plt_base.wrapping_add(b.value()),
2892+
(
2893+
ExpressionKind::Const(b) | ExpressionKind::ConstPtr(b),
2894+
ExpressionKind::Reg(a),
2895+
) if a.source_reg() == auipc_dest => plt_base.wrapping_add(b.value()),
2896+
_ => return false,
2897+
},
2898+
ExpressionKind::Sub(a) => match (a.left().kind(), a.right().kind()) {
2899+
(
2900+
ExpressionKind::Reg(a),
2901+
ExpressionKind::Const(b) | ExpressionKind::ConstPtr(b),
2902+
) if a.source_reg() == auipc_dest => plt_base.wrapping_sub(b.value()),
2903+
_ => return false,
2904+
},
29222905
_ => return false,
29232906
};
29242907
(entry, target_reg)
@@ -2945,7 +2928,7 @@ impl FunctionRecognizer for RiscVELFPLTRecognizer {
29452928
match &temp_reg_inst {
29462929
InstructionKind::SetReg(r) if llil.instruction_count() >= 5 => {
29472930
match r.source_expr().kind() {
2948-
LowLevelILExpressionKind::Reg(op) if target_reg == op.source_reg() => {
2931+
ExpressionKind::Reg(op) if target_reg == op.source_reg() => {
29492932
// Update the target_reg to the temp reg.
29502933
target_reg = r.dest_reg();
29512934
temp_reg_inst = next_llil_instr.next().unwrap().kind()
@@ -2961,9 +2944,7 @@ impl FunctionRecognizer for RiscVELFPLTRecognizer {
29612944
let (next_pc_dest, next_pc, cur_pc) = match next_pc_inst {
29622945
InstructionKind::SetReg(r) => {
29632946
let value = match r.source_expr().kind() {
2964-
LowLevelILExpressionKind::Const(v) | LowLevelILExpressionKind::ConstPtr(v) => {
2965-
v.value()
2966-
}
2947+
ExpressionKind::Const(v) | ExpressionKind::ConstPtr(v) => v.value(),
29672948
_ => return false,
29682949
};
29692950
(r.dest_reg(), value, r.address())
@@ -2979,13 +2960,13 @@ impl FunctionRecognizer for RiscVELFPLTRecognizer {
29792960
match jump {
29802961
InstructionKind::TailCall(j) => {
29812962
match j.target().kind() {
2982-
LowLevelILExpressionKind::Reg(r) if r.source_reg() == target_reg => (),
2963+
ExpressionKind::Reg(r) if r.source_reg() == target_reg => (),
29832964
_ => return false,
29842965
};
29852966
}
29862967
InstructionKind::Jump(j) => {
29872968
match j.target().kind() {
2988-
LowLevelILExpressionKind::Reg(r) if r.source_reg() == target_reg => (),
2969+
ExpressionKind::Reg(r) if r.source_reg() == target_reg => (),
29892970
_ => return false,
29902971
};
29912972
}

plugins/warp/src/lib.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use binaryninja::basic_block::BasicBlock as BNBasicBlock;
99
use binaryninja::binary_view::BinaryViewExt;
1010
use binaryninja::confidence::MAX_CONFIDENCE;
1111
use binaryninja::function::{Function as BNFunction, NativeBlock};
12-
use binaryninja::low_level_il::expression::{ExpressionHandler, LowLevelILExpressionKind};
12+
use binaryninja::low_level_il::expression::{ExpressionHandler, ExpressionKind};
1313
use binaryninja::low_level_il::function::{
1414
FunctionMutability, LowLevelILFunction, NonSSA, RegularNonSSA,
1515
};
@@ -101,9 +101,7 @@ pub fn basic_block_guid<M: FunctionMutability>(
101101
InstructionKind::Nop(_) => true,
102102
InstructionKind::SetReg(op) => {
103103
match op.source_expr().kind() {
104-
LowLevelILExpressionKind::Reg(source_op)
105-
if op.dest_reg() == source_op.source_reg() =>
106-
{
104+
ExpressionKind::Reg(source_op) if op.dest_reg() == source_op.source_reg() => {
107105
match op.dest_reg() {
108106
LowLevelILRegisterKind::Arch(r) => {
109107
// If this register has no implicit extend then we can safely assume it's a NOP.
@@ -125,18 +123,16 @@ pub fn basic_block_guid<M: FunctionMutability>(
125123
};
126124

127125
let is_variant_instr = |instr: &Instruction<M, NonSSA<RegularNonSSA>>| {
128-
let is_variant_expr = |expr: &LowLevelILExpressionKind<M, NonSSA<RegularNonSSA>>| {
126+
let is_variant_expr = |expr: &ExpressionKind<M, NonSSA<RegularNonSSA>>| {
129127
// TODO: Checking the section here is slow, we should gather all section ranges outside of this.
130128
match expr {
131-
LowLevelILExpressionKind::ConstPtr(op)
132-
if !view.sections_at(op.value()).is_empty() =>
133-
{
129+
ExpressionKind::ConstPtr(op) if !view.sections_at(op.value()).is_empty() => {
134130
// Constant Pointer must be in a section for it to be relocatable.
135131
// NOTE: We cannot utilize segments here as there will be a zero based segment.
136132
true
137133
}
138-
LowLevelILExpressionKind::ExternPtr(_) => true,
139-
LowLevelILExpressionKind::Const(op) if !view.sections_at(op.value()).is_empty() => {
134+
ExpressionKind::ExternPtr(_) => true,
135+
ExpressionKind::Const(op) if !view.sections_at(op.value()).is_empty() => {
140136
// Constant value must be in a section for it to be relocatable.
141137
// NOTE: We cannot utilize segments here as there will be a zero based segment.
142138
true

rust/examples/workflow.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use binaryninja::binary_view::BinaryViewExt;
2-
use binaryninja::low_level_il::expression::{ExpressionHandler, LowLevelILExpressionKind};
2+
use binaryninja::low_level_il::expression::{ExpressionHandler, ExpressionKind};
33
use binaryninja::low_level_il::instruction::InstructionHandler;
44
use binaryninja::low_level_il::VisitorAction;
55
use binaryninja::workflow::{Activity, AnalysisContext, Workflow};
@@ -29,7 +29,7 @@ fn example_activity(analysis_context: &AnalysisContext) {
2929
for instr in basic_block.iter() {
3030
if let Some(llil_instr) = llil.instruction_at(instr) {
3131
llil_instr.visit_tree(&mut |expr| {
32-
if let LowLevelILExpressionKind::Const(_op) = expr.kind() {
32+
if let ExpressionKind::Const(_op) = expr.kind() {
3333
// Replace all consts with 0x1337.
3434
println!("Replacing llil expression @ 0x{:x} : {}", instr, expr.index);
3535
unsafe {
@@ -71,7 +71,7 @@ pub fn main() {
7171
for block in &llil.basic_blocks() {
7272
for instr in block.iter() {
7373
instr.visit_tree(&mut |expr| {
74-
if let LowLevelILExpressionKind::Const(value) = expr.kind() {
74+
if let ExpressionKind::Const(value) = expr.kind() {
7575
if value.value() == 0x1337 {
7676
println!(
7777
"Found constant 0x1337 at instruction 0x{:x} in function {}",

rust/src/low_level_il.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,14 @@ use self::instruction::*;
3838
pub type MutableLiftedILFunction = LowLevelILFunction<Mutable, NonSSA<LiftedNonSSA>>;
3939
pub type LiftedILFunction = LowLevelILFunction<Finalized, NonSSA<LiftedNonSSA>>;
4040
pub type MutableLiftedILExpr<'a, ReturnType> =
41-
LowLevelILExpression<'a, Mutable, NonSSA<LiftedNonSSA>, ReturnType>;
41+
Expression<'a, Mutable, NonSSA<LiftedNonSSA>, ReturnType>;
4242
pub type RegularLowLevelILFunction = LowLevelILFunction<Finalized, NonSSA<RegularNonSSA>>;
4343
pub type RegularLowLevelILInstruction<'a> = Instruction<'a, Finalized, NonSSA<RegularNonSSA>>;
4444
pub type RegularLowLevelILInstructionKind<'a> =
4545
InstructionKind<'a, Finalized, NonSSA<RegularNonSSA>>;
4646
pub type RegularLowLevelILExpression<'a, ReturnType> =
47-
LowLevelILExpression<'a, Finalized, NonSSA<RegularNonSSA>, ReturnType>;
48-
pub type RegularLowLevelILExpressionKind<'a> =
49-
LowLevelILExpressionKind<'a, Finalized, NonSSA<RegularNonSSA>>;
47+
Expression<'a, Finalized, NonSSA<RegularNonSSA>, ReturnType>;
48+
pub type RegularLowLevelILExpressionKind<'a> = ExpressionKind<'a, Finalized, NonSSA<RegularNonSSA>>;
5049
pub type LowLevelILSSAFunction = LowLevelILFunction<Finalized, SSA>;
5150

5251
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]

0 commit comments

Comments
 (0)