Skip to content

Commit 4c03aca

Browse files
committed
Rename LowLevelILInstruction to Instruction in Rust API
1 parent 809f97f commit 4c03aca

File tree

8 files changed

+74
-91
lines changed

8 files changed

+74
-91
lines changed

arch/riscv/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use binaryninja::architecture::{BranchKind, IntrinsicId, RegisterId};
3838
use binaryninja::confidence::{Conf, MAX_CONFIDENCE, MIN_CONFIDENCE};
3939
use binaryninja::logger::Logger;
4040
use binaryninja::low_level_il::expression::{LowLevelILExpressionKind, ValueExpr};
41-
use binaryninja::low_level_il::instruction::LowLevelILInstructionKind;
41+
use binaryninja::low_level_il::instruction::InstructionKind;
4242
use binaryninja::low_level_il::lifting::{
4343
LiftableLowLevelIL, LiftableLowLevelILWithSize, LowLevelILLabel,
4444
};
@@ -2866,7 +2866,7 @@ impl FunctionRecognizer for RiscVELFPLTRecognizer {
28662866
// Match instruction that fetches PC-relative PLT address range
28672867
let auipc = next_llil_instr.next().unwrap().kind();
28682868
let (auipc_dest, plt_base) = match auipc {
2869-
LowLevelILInstructionKind::SetReg(r) => {
2869+
InstructionKind::SetReg(r) => {
28702870
let value = match r.source_expr().kind() {
28712871
LowLevelILExpressionKind::Const(v) | LowLevelILExpressionKind::ConstPtr(v) => {
28722872
v.value()
@@ -2881,7 +2881,7 @@ impl FunctionRecognizer for RiscVELFPLTRecognizer {
28812881
// Match load instruction that loads the imported address
28822882
let load = next_llil_instr.next().unwrap().kind();
28832883
let (mut entry, mut target_reg) = match load {
2884-
LowLevelILInstructionKind::SetReg(r) => match r.source_expr().kind() {
2884+
InstructionKind::SetReg(r) => match r.source_expr().kind() {
28852885
LowLevelILExpressionKind::Load(l) => {
28862886
let target_reg = r.dest_reg();
28872887
let entry = match l.source_mem_expr().kind() {
@@ -2943,7 +2943,7 @@ impl FunctionRecognizer for RiscVELFPLTRecognizer {
29432943
// (OPTIONAL) Check if we are storing in temp0, adjust target reg if so
29442944
let mut temp_reg_inst = next_llil_instr.next().unwrap().kind();
29452945
match &temp_reg_inst {
2946-
LowLevelILInstructionKind::SetReg(r) if llil.instruction_count() >= 5 => {
2946+
InstructionKind::SetReg(r) if llil.instruction_count() >= 5 => {
29472947
match r.source_expr().kind() {
29482948
LowLevelILExpressionKind::Reg(op) if target_reg == op.source_reg() => {
29492949
// Update the target_reg to the temp reg.
@@ -2959,7 +2959,7 @@ impl FunctionRecognizer for RiscVELFPLTRecognizer {
29592959
// Match instruction that stores the next instruction address into a register
29602960
let next_pc_inst = temp_reg_inst;
29612961
let (next_pc_dest, next_pc, cur_pc) = match next_pc_inst {
2962-
LowLevelILInstructionKind::SetReg(r) => {
2962+
InstructionKind::SetReg(r) => {
29632963
let value = match r.source_expr().kind() {
29642964
LowLevelILExpressionKind::Const(v) | LowLevelILExpressionKind::ConstPtr(v) => {
29652965
v.value()
@@ -2977,13 +2977,13 @@ impl FunctionRecognizer for RiscVELFPLTRecognizer {
29772977
// Match tail call at the end and make sure it is going to the import
29782978
let jump = next_llil_instr.next().unwrap().kind();
29792979
match jump {
2980-
LowLevelILInstructionKind::TailCall(j) => {
2980+
InstructionKind::TailCall(j) => {
29812981
match j.target().kind() {
29822982
LowLevelILExpressionKind::Reg(r) if r.source_reg() == target_reg => (),
29832983
_ => return false,
29842984
};
29852985
}
2986-
LowLevelILInstructionKind::Jump(j) => {
2986+
InstructionKind::Jump(j) => {
29872987
match j.target().kind() {
29882988
LowLevelILExpressionKind::Reg(r) if r.source_reg() == target_reg => (),
29892989
_ => return false,

plugins/warp/src/lib.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ use binaryninja::low_level_il::expression::{ExpressionHandler, LowLevelILExpress
1313
use binaryninja::low_level_il::function::{
1414
FunctionMutability, LowLevelILFunction, NonSSA, RegularNonSSA,
1515
};
16-
use binaryninja::low_level_il::instruction::{
17-
InstructionHandler, LowLevelILInstruction, LowLevelILInstructionKind,
18-
};
16+
use binaryninja::low_level_il::instruction::{Instruction, InstructionHandler, InstructionKind};
1917
use binaryninja::low_level_il::{LowLevelILRegisterKind, VisitorAction};
2018
use binaryninja::rc::Ref as BNRef;
2119
use std::path::PathBuf;
@@ -98,10 +96,10 @@ pub fn basic_block_guid<M: FunctionMutability>(
9896
let max_instr_len = arch.max_instr_len();
9997

10098
// NOPs and useless moves are blacklisted to allow for hot-patchable functions.
101-
let is_blacklisted_instr = |instr: &LowLevelILInstruction<M, NonSSA<RegularNonSSA>>| {
99+
let is_blacklisted_instr = |instr: &Instruction<M, NonSSA<RegularNonSSA>>| {
102100
match instr.kind() {
103-
LowLevelILInstructionKind::Nop(_) => true,
104-
LowLevelILInstructionKind::SetReg(op) => {
101+
InstructionKind::Nop(_) => true,
102+
InstructionKind::SetReg(op) => {
105103
match op.source_expr().kind() {
106104
LowLevelILExpressionKind::Reg(source_op)
107105
if op.dest_reg() == source_op.source_reg() =>
@@ -126,7 +124,7 @@ pub fn basic_block_guid<M: FunctionMutability>(
126124
}
127125
};
128126

129-
let is_variant_instr = |instr: &LowLevelILInstruction<M, NonSSA<RegularNonSSA>>| {
127+
let is_variant_instr = |instr: &Instruction<M, NonSSA<RegularNonSSA>>| {
130128
let is_variant_expr = |expr: &LowLevelILExpressionKind<M, NonSSA<RegularNonSSA>>| {
131129
// TODO: Checking the section here is slow, we should gather all section ranges outside of this.
132130
match expr {

rust/src/low_level_il.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,9 @@ pub type LiftedILFunction = LowLevelILFunction<Finalized, NonSSA<LiftedNonSSA>>;
4040
pub type MutableLiftedILExpr<'a, ReturnType> =
4141
LowLevelILExpression<'a, Mutable, NonSSA<LiftedNonSSA>, ReturnType>;
4242
pub type RegularLowLevelILFunction = LowLevelILFunction<Finalized, NonSSA<RegularNonSSA>>;
43-
pub type RegularLowLevelILInstruction<'a> =
44-
LowLevelILInstruction<'a, Finalized, NonSSA<RegularNonSSA>>;
43+
pub type RegularLowLevelILInstruction<'a> = Instruction<'a, Finalized, NonSSA<RegularNonSSA>>;
4544
pub type RegularLowLevelILInstructionKind<'a> =
46-
LowLevelILInstructionKind<'a, Finalized, NonSSA<RegularNonSSA>>;
45+
InstructionKind<'a, Finalized, NonSSA<RegularNonSSA>>;
4746
pub type RegularLowLevelILExpression<'a, ReturnType> =
4847
LowLevelILExpression<'a, Finalized, NonSSA<RegularNonSSA>, ReturnType>;
4948
pub type RegularLowLevelILExpressionKind<'a> =

rust/src/low_level_il/block.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ where
3333
M: FunctionMutability,
3434
F: FunctionForm,
3535
{
36-
type Instruction = LowLevelILInstruction<'func, M, F>;
36+
type Instruction = Instruction<'func, M, F>;
3737
type InstructionIndex = LowLevelInstructionIndex;
3838
type Iter = LowLevelILBlockIter<'func, M, F>;
3939

40-
fn start(&self, block: &BasicBlock<Self>) -> LowLevelILInstruction<'func, M, F> {
40+
fn start(&self, block: &BasicBlock<Self>) -> Instruction<'func, M, F> {
4141
self.function
4242
.instruction_from_index(block.start_index())
4343
.unwrap()
@@ -90,7 +90,7 @@ where
9090
M: FunctionMutability,
9191
F: FunctionForm,
9292
{
93-
type Item = LowLevelILInstruction<'func, M, F>;
93+
type Item = Instruction<'func, M, F>;
9494

9595
fn next(&mut self) -> Option<Self::Item> {
9696
self.range

rust/src/low_level_il/function.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,8 @@ where
105105
}
106106
}
107107

108-
pub fn instruction_at<L: Into<Location>>(&self, loc: L) -> Option<LowLevelILInstruction<M, F>> {
109-
Some(LowLevelILInstruction::new(
110-
self,
111-
self.instruction_index_at(loc)?,
112-
))
108+
pub fn instruction_at<L: Into<Location>>(&self, loc: L) -> Option<Instruction<M, F>> {
109+
Some(Instruction::new(self, self.instruction_index_at(loc)?))
113110
}
114111

115112
pub fn instruction_index_at<L: Into<Location>>(
@@ -132,11 +129,11 @@ where
132129
pub fn instruction_from_index(
133130
&self,
134131
index: LowLevelInstructionIndex,
135-
) -> Option<LowLevelILInstruction<M, F>> {
132+
) -> Option<Instruction<M, F>> {
136133
if index.0 >= self.instruction_count() {
137134
None
138135
} else {
139-
Some(LowLevelILInstruction::new(self, index))
136+
Some(Instruction::new(self, index))
140137
}
141138
}
142139

rust/src/low_level_il/instruction.rs

Lines changed: 37 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,12 @@ impl Display for LowLevelInstructionIndex {
4949
}
5050
}
5151

52-
// TODO: Probably want to rename this with a LowLevelIL prefix to avoid collisions when we add handlers for other ILs
5352
pub trait InstructionHandler<'func, M, F>
5453
where
5554
M: FunctionMutability,
5655
F: FunctionForm,
5756
{
58-
fn kind(&self) -> LowLevelILInstructionKind<'func, M, F>;
57+
fn kind(&self) -> InstructionKind<'func, M, F>;
5958

6059
/// Visit the sub expressions of this instruction.
6160
///
@@ -65,7 +64,7 @@ where
6564
T: FnMut(&LowLevelILExpression<'func, M, F, ValueExpr>) -> VisitorAction;
6665
}
6766

68-
pub struct LowLevelILInstruction<'func, M, F>
67+
pub struct Instruction<'func, M, F>
6968
where
7069
M: FunctionMutability,
7170
F: FunctionForm,
@@ -74,7 +73,7 @@ where
7473
pub index: LowLevelInstructionIndex,
7574
}
7675

77-
impl<'func, M, F> LowLevelILInstruction<'func, M, F>
76+
impl<'func, M, F> Instruction<'func, M, F>
7877
where
7978
M: FunctionMutability,
8079
F: FunctionForm,
@@ -100,7 +99,7 @@ where
10099
}
101100
}
102101

103-
impl<'func, M, F> Debug for LowLevelILInstruction<'func, M, F>
102+
impl<'func, M, F> Debug for Instruction<'func, M, F>
104103
where
105104
M: FunctionMutability,
106105
F: FunctionForm,
@@ -114,21 +113,19 @@ where
114113
}
115114
}
116115

117-
impl<'func, M> InstructionHandler<'func, M, SSA> for LowLevelILInstruction<'func, M, SSA>
116+
impl<'func, M> InstructionHandler<'func, M, SSA> for Instruction<'func, M, SSA>
118117
where
119118
M: FunctionMutability,
120119
{
121-
fn kind(&self) -> LowLevelILInstructionKind<'func, M, SSA> {
120+
fn kind(&self) -> InstructionKind<'func, M, SSA> {
122121
#[allow(unused_imports)]
123122
use binaryninjacore_sys::BNLowLevelILOperation::*;
124123
let raw_op = self.into_raw();
125124
#[allow(clippy::match_single_binding)]
126125
match raw_op.operation {
127126
// Any invalid ops for Non-Lifted IL will be checked here.
128127
// SAFETY: We have checked for illegal operations.
129-
_ => unsafe {
130-
LowLevelILInstructionKind::from_raw(self.function, self.expr_idx(), raw_op)
131-
},
128+
_ => unsafe { InstructionKind::from_raw(self.function, self.expr_idx(), raw_op) },
132129
}
133130
}
134131

@@ -142,21 +139,19 @@ where
142139
}
143140

144141
impl<'func, M> InstructionHandler<'func, M, NonSSA<LiftedNonSSA>>
145-
for LowLevelILInstruction<'func, M, NonSSA<LiftedNonSSA>>
142+
for Instruction<'func, M, NonSSA<LiftedNonSSA>>
146143
where
147144
M: FunctionMutability,
148145
{
149-
fn kind(&self) -> LowLevelILInstructionKind<'func, M, NonSSA<LiftedNonSSA>> {
146+
fn kind(&self) -> InstructionKind<'func, M, NonSSA<LiftedNonSSA>> {
150147
#[allow(unused_imports)]
151148
use binaryninjacore_sys::BNLowLevelILOperation::*;
152149
let raw_op = self.into_raw();
153150
#[allow(clippy::match_single_binding)]
154151
match raw_op.operation {
155152
// Any invalid ops for Non-Lifted IL will be checked here.
156153
// SAFETY: We have checked for illegal operations.
157-
_ => unsafe {
158-
LowLevelILInstructionKind::from_raw(self.function, self.expr_idx(), raw_op)
159-
},
154+
_ => unsafe { InstructionKind::from_raw(self.function, self.expr_idx(), raw_op) },
160155
}
161156
}
162157

@@ -170,21 +165,19 @@ where
170165
}
171166

172167
impl<'func, M> InstructionHandler<'func, M, NonSSA<RegularNonSSA>>
173-
for LowLevelILInstruction<'func, M, NonSSA<RegularNonSSA>>
168+
for Instruction<'func, M, NonSSA<RegularNonSSA>>
174169
where
175170
M: FunctionMutability,
176171
{
177-
fn kind(&self) -> LowLevelILInstructionKind<'func, M, NonSSA<RegularNonSSA>> {
172+
fn kind(&self) -> InstructionKind<'func, M, NonSSA<RegularNonSSA>> {
178173
#[allow(unused_imports)]
179174
use binaryninjacore_sys::BNLowLevelILOperation::*;
180175
let raw_op = self.into_raw();
181176
#[allow(clippy::match_single_binding)]
182177
match raw_op.operation {
183178
// Any invalid ops for Non-Lifted IL will be checked here.
184179
// SAFETY: We have checked for illegal operations.
185-
_ => unsafe {
186-
LowLevelILInstructionKind::from_raw(self.function, self.expr_idx(), raw_op)
187-
},
180+
_ => unsafe { InstructionKind::from_raw(self.function, self.expr_idx(), raw_op) },
188181
}
189182
}
190183

@@ -200,7 +193,7 @@ where
200193
}
201194

202195
#[derive(Debug)]
203-
pub enum LowLevelILInstructionKind<'func, M, F>
196+
pub enum InstructionKind<'func, M, F>
204197
where
205198
M: FunctionMutability,
206199
F: FunctionForm,
@@ -237,7 +230,7 @@ where
237230
Value(LowLevelILExpression<'func, M, F, ValueExpr>),
238231
}
239232

240-
impl<'func, M, F> LowLevelILInstructionKind<'func, M, F>
233+
impl<'func, M, F> InstructionKind<'func, M, F>
241234
where
242235
M: FunctionMutability,
243236
F: FunctionForm,
@@ -250,59 +243,55 @@ where
250243
use binaryninjacore_sys::BNLowLevelILOperation::*;
251244

252245
match op.operation {
253-
LLIL_NOP => LowLevelILInstructionKind::Nop(Operation::new(function, op)),
246+
LLIL_NOP => InstructionKind::Nop(Operation::new(function, op)),
254247
LLIL_SET_REG | LLIL_SET_REG_SSA => {
255-
LowLevelILInstructionKind::SetReg(Operation::new(function, op))
248+
InstructionKind::SetReg(Operation::new(function, op))
256249
}
257250
LLIL_SET_REG_SPLIT | LLIL_SET_REG_SPLIT_SSA => {
258-
LowLevelILInstructionKind::SetRegSplit(Operation::new(function, op))
251+
InstructionKind::SetRegSplit(Operation::new(function, op))
259252
}
260253
LLIL_SET_FLAG | LLIL_SET_FLAG_SSA => {
261-
LowLevelILInstructionKind::SetFlag(Operation::new(function, op))
254+
InstructionKind::SetFlag(Operation::new(function, op))
262255
}
263-
LLIL_STORE | LLIL_STORE_SSA => {
264-
LowLevelILInstructionKind::Store(Operation::new(function, op))
265-
}
266-
LLIL_PUSH => LowLevelILInstructionKind::Push(Operation::new(function, op)),
256+
LLIL_STORE | LLIL_STORE_SSA => InstructionKind::Store(Operation::new(function, op)),
257+
LLIL_PUSH => InstructionKind::Push(Operation::new(function, op)),
267258

268-
LLIL_REG_STACK_PUSH => {
269-
LowLevelILInstructionKind::RegStackPush(Operation::new(function, op))
270-
}
259+
LLIL_REG_STACK_PUSH => InstructionKind::RegStackPush(Operation::new(function, op)),
271260

272-
LLIL_JUMP => LowLevelILInstructionKind::Jump(Operation::new(function, op)),
273-
LLIL_JUMP_TO => LowLevelILInstructionKind::JumpTo(Operation::new(function, op)),
261+
LLIL_JUMP => InstructionKind::Jump(Operation::new(function, op)),
262+
LLIL_JUMP_TO => InstructionKind::JumpTo(Operation::new(function, op)),
274263

275264
LLIL_CALL | LLIL_CALL_STACK_ADJUST | LLIL_CALL_SSA => {
276-
LowLevelILInstructionKind::Call(Operation::new(function, op))
265+
InstructionKind::Call(Operation::new(function, op))
277266
}
278267
LLIL_TAILCALL | LLIL_TAILCALL_SSA => {
279-
LowLevelILInstructionKind::TailCall(Operation::new(function, op))
268+
InstructionKind::TailCall(Operation::new(function, op))
280269
}
281270

282-
LLIL_RET => LowLevelILInstructionKind::Ret(Operation::new(function, op)),
283-
LLIL_NORET => LowLevelILInstructionKind::NoRet(Operation::new(function, op)),
271+
LLIL_RET => InstructionKind::Ret(Operation::new(function, op)),
272+
LLIL_NORET => InstructionKind::NoRet(Operation::new(function, op)),
284273

285-
LLIL_IF => LowLevelILInstructionKind::If(Operation::new(function, op)),
286-
LLIL_GOTO => LowLevelILInstructionKind::Goto(Operation::new(function, op)),
274+
LLIL_IF => InstructionKind::If(Operation::new(function, op)),
275+
LLIL_GOTO => InstructionKind::Goto(Operation::new(function, op)),
287276

288277
LLIL_SYSCALL | LLIL_SYSCALL_SSA => {
289-
LowLevelILInstructionKind::Syscall(Operation::new(function, op))
278+
InstructionKind::Syscall(Operation::new(function, op))
290279
}
291280
LLIL_INTRINSIC | LLIL_INTRINSIC_SSA => {
292-
LowLevelILInstructionKind::Intrinsic(Operation::new(function, op))
281+
InstructionKind::Intrinsic(Operation::new(function, op))
293282
}
294-
LLIL_BP => LowLevelILInstructionKind::Bp(Operation::new(function, op)),
295-
LLIL_TRAP => LowLevelILInstructionKind::Trap(Operation::new(function, op)),
296-
LLIL_UNDEF => LowLevelILInstructionKind::Undef(Operation::new(function, op)),
297-
_ => LowLevelILInstructionKind::Value(LowLevelILExpression::new(function, expr_index)),
283+
LLIL_BP => InstructionKind::Bp(Operation::new(function, op)),
284+
LLIL_TRAP => InstructionKind::Trap(Operation::new(function, op)),
285+
LLIL_UNDEF => InstructionKind::Undef(Operation::new(function, op)),
286+
_ => InstructionKind::Value(LowLevelILExpression::new(function, expr_index)),
298287
}
299288
}
300289

301290
fn visit_sub_expressions<T>(&self, mut visitor: T) -> VisitorAction
302291
where
303292
T: FnMut(&LowLevelILExpression<'func, M, F, ValueExpr>) -> VisitorAction,
304293
{
305-
use LowLevelILInstructionKind::*;
294+
use InstructionKind::*;
306295

307296
macro_rules! visit {
308297
($expr:expr) => {

0 commit comments

Comments
 (0)