Skip to content

Commit 20ef71e

Browse files
committed
Rename HighLevelILInstruction to Instruction in Rust API
1 parent a7e0392 commit 20ef71e

File tree

5 files changed

+32
-42
lines changed

5 files changed

+32
-42
lines changed

rust/src/high_level_il/block.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ use std::ops::Range;
33
use crate::basic_block::{BasicBlock, BlockContext};
44
use crate::rc::Ref;
55

6-
use super::{HighLevelILFunction, HighLevelILInstruction, HighLevelInstructionIndex};
6+
use super::{HighLevelILFunction, HighLevelInstructionIndex, Instruction};
77

88
pub struct HighLevelILBlockIter {
99
function: Ref<HighLevelILFunction>,
1010
range: Range<usize>,
1111
}
1212

1313
impl Iterator for HighLevelILBlockIter {
14-
type Item = HighLevelILInstruction;
14+
type Item = Instruction;
1515

1616
fn next(&mut self) -> Option<Self::Item> {
1717
self.range
@@ -34,11 +34,11 @@ impl core::fmt::Debug for HighLevelILBlock {
3434
}
3535

3636
impl BlockContext for HighLevelILBlock {
37-
type Instruction = HighLevelILInstruction;
37+
type Instruction = Instruction;
3838
type InstructionIndex = HighLevelInstructionIndex;
3939
type Iter = HighLevelILBlockIter;
4040

41-
fn start(&self, block: &BasicBlock<Self>) -> HighLevelILInstruction {
41+
fn start(&self, block: &BasicBlock<Self>) -> Instruction {
4242
// TODO: Is this start index already mappedd?????
4343
self.function
4444
.instruction_from_index(block.start_index())

rust/src/high_level_il/function.rs

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::hash::{Hash, Hasher};
33

44
use binaryninjacore_sys::*;
55

6-
use super::{HighLevelILBlock, HighLevelILInstruction, HighLevelInstructionIndex};
6+
use super::{HighLevelILBlock, HighLevelInstructionIndex, Instruction};
77
use crate::basic_block::BasicBlock;
88
use crate::function::{Function, Location};
99
use crate::rc::{Array, Ref, RefCountable};
@@ -23,28 +23,22 @@ impl HighLevelILFunction {
2323
Self { handle, full_ast }.to_owned()
2424
}
2525

26-
pub fn instruction_from_index(
27-
&self,
28-
index: HighLevelInstructionIndex,
29-
) -> Option<HighLevelILInstruction> {
26+
pub fn instruction_from_index(&self, index: HighLevelInstructionIndex) -> Option<Instruction> {
3027
if index.0 >= self.instruction_count() {
3128
None
3229
} else {
33-
Some(HighLevelILInstruction::new(self.to_owned(), index))
30+
Some(Instruction::new(self.to_owned(), index))
3431
}
3532
}
3633

3734
pub fn instruction_from_expr_index(
3835
&self,
3936
expr_index: HighLevelInstructionIndex,
40-
) -> Option<HighLevelILInstruction> {
37+
) -> Option<Instruction> {
4138
if expr_index.0 >= self.expression_count() {
4239
None
4340
} else {
44-
Some(HighLevelILInstruction::new_expr(
45-
self.to_owned(),
46-
expr_index,
47-
))
41+
Some(Instruction::new_expr(self.to_owned(), expr_index))
4842
}
4943
}
5044

@@ -53,11 +47,11 @@ impl HighLevelILFunction {
5347
HighLevelInstructionIndex(unsafe { BNGetHighLevelILRootExpr(self.handle) })
5448
}
5549

56-
pub fn root(&self) -> HighLevelILInstruction {
57-
HighLevelILInstruction::new_expr(self.as_ast(), self.root_instruction_index())
50+
pub fn root(&self) -> Instruction {
51+
Instruction::new_expr(self.as_ast(), self.root_instruction_index())
5852
}
5953

60-
pub fn set_root(&self, new_root: &HighLevelILInstruction) {
54+
pub fn set_root(&self, new_root: &Instruction) {
6155
unsafe { BNSetHighLevelILRootExpr(self.handle, new_root.expr_index.0) }
6256
}
6357

@@ -130,7 +124,7 @@ impl HighLevelILFunction {
130124
///
131125
/// Since SSA variables can only be defined once, this will return the single instruction where that occurs.
132126
/// For SSA variable version 0s, which don't have definitions, this will return None instead.
133-
pub fn ssa_variable_definition(&self, variable: SSAVariable) -> Option<HighLevelILInstruction> {
127+
pub fn ssa_variable_definition(&self, variable: SSAVariable) -> Option<Instruction> {
134128
let index = unsafe {
135129
BNGetHighLevelILSSAVarDefinition(
136130
self.handle,
@@ -141,13 +135,13 @@ impl HighLevelILFunction {
141135
self.instruction_from_index(HighLevelInstructionIndex(index))
142136
}
143137

144-
pub fn ssa_memory_definition(&self, version: usize) -> Option<HighLevelILInstruction> {
138+
pub fn ssa_memory_definition(&self, version: usize) -> Option<Instruction> {
145139
let index = unsafe { BNGetHighLevelILSSAMemoryDefinition(self.handle, version) };
146140
self.instruction_from_index(HighLevelInstructionIndex(index))
147141
}
148142

149143
/// Gets all the instructions that use the given SSA variable.
150-
pub fn ssa_variable_uses(&self, variable: SSAVariable) -> Array<HighLevelILInstruction> {
144+
pub fn ssa_variable_uses(&self, variable: SSAVariable) -> Array<Instruction> {
151145
let mut count = 0;
152146
let instrs = unsafe {
153147
BNGetHighLevelILSSAVarUses(
@@ -161,7 +155,7 @@ impl HighLevelILFunction {
161155
unsafe { Array::new(instrs, count, self.to_owned()) }
162156
}
163157

164-
pub fn ssa_memory_uses(&self, version: usize) -> Array<HighLevelILInstruction> {
158+
pub fn ssa_memory_uses(&self, version: usize) -> Array<Instruction> {
165159
let mut count = 0;
166160
let instrs = unsafe { BNGetHighLevelILSSAMemoryUses(self.handle, version, &mut count) };
167161
assert!(!instrs.is_null());
@@ -176,11 +170,7 @@ impl HighLevelILFunction {
176170
}
177171

178172
/// Determines if `variable` is live at a given point in the function
179-
pub fn is_ssa_variable_live_at(
180-
&self,
181-
variable: SSAVariable,
182-
instr: &HighLevelILInstruction,
183-
) -> bool {
173+
pub fn is_ssa_variable_live_at(&self, variable: SSAVariable, instr: &Instruction) -> bool {
184174
unsafe {
185175
BNIsHighLevelILSSAVarLiveAt(
186176
self.handle,
@@ -191,7 +181,7 @@ impl HighLevelILFunction {
191181
}
192182
}
193183

194-
pub fn variable_definitions(&self, variable: Variable) -> Array<HighLevelILInstruction> {
184+
pub fn variable_definitions(&self, variable: Variable) -> Array<Instruction> {
195185
let mut count = 0;
196186
let defs = unsafe {
197187
BNGetHighLevelILVariableDefinitions(self.handle, &variable.into(), &mut count)
@@ -200,7 +190,7 @@ impl HighLevelILFunction {
200190
unsafe { Array::new(defs, count, self.to_owned()) }
201191
}
202192

203-
pub fn variable_uses(&self, variable: Variable) -> Array<HighLevelILInstruction> {
193+
pub fn variable_uses(&self, variable: Variable) -> Array<Instruction> {
204194
let mut count = 0;
205195
let instrs =
206196
unsafe { BNGetHighLevelILVariableUses(self.handle, &variable.into(), &mut count) };
@@ -209,7 +199,7 @@ impl HighLevelILFunction {
209199
}
210200

211201
/// Determines if `variable` is live at a given point in the function
212-
pub fn is_variable_live_at(&self, variable: Variable, instr: &HighLevelILInstruction) -> bool {
202+
pub fn is_variable_live_at(&self, variable: Variable, instr: &Instruction) -> bool {
213203
unsafe { BNIsHighLevelILVarLiveAt(self.handle, &variable.into(), instr.expr_index.0) }
214204
}
215205

rust/src/high_level_il/instruction.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ impl Display for HighLevelInstructionIndex {
4040
}
4141

4242
#[derive(Clone)]
43-
pub struct HighLevelILInstruction {
43+
pub struct Instruction {
4444
pub function: Ref<HighLevelILFunction>,
4545
pub address: u64,
4646
pub expr_index: HighLevelInstructionIndex,
4747
pub size: usize,
48-
pub kind: HighLevelILInstructionKind,
48+
pub kind: InstructionKind,
4949
}
5050

51-
impl HighLevelILInstruction {
51+
impl Instruction {
5252
pub(crate) fn new(
5353
function: Ref<HighLevelILFunction>,
5454
index: HighLevelInstructionIndex,
@@ -65,7 +65,7 @@ impl HighLevelILInstruction {
6565
let op =
6666
unsafe { BNGetHighLevelILByIndex(function.handle, expr_index.0, function.full_ast) };
6767
use BNHighLevelILOperation::*;
68-
use HighLevelILInstructionKind as Op;
68+
use InstructionKind as Op;
6969
let kind = match op.operation {
7070
HLIL_NOP => Op::Nop,
7171
HLIL_BREAK => Op::Break,
@@ -553,8 +553,8 @@ impl HighLevelILInstruction {
553553
}
554554

555555
pub fn lift(&self) -> HighLevelILLiftedInstruction {
556-
use HighLevelILInstructionKind::*;
557556
use HighLevelILLiftedInstructionKind as Lifted;
557+
use InstructionKind::*;
558558
let kind = match self.kind {
559559
Nop => Lifted::Nop,
560560
Break => Lifted::Break,
@@ -949,13 +949,13 @@ impl HighLevelILInstruction {
949949
}
950950
}
951951

952-
impl CoreArrayProvider for HighLevelILInstruction {
952+
impl CoreArrayProvider for Instruction {
953953
type Raw = usize;
954954
type Context = Ref<HighLevelILFunction>;
955955
type Wrapped<'a> = Self;
956956
}
957957

958-
unsafe impl CoreArrayProviderInner for HighLevelILInstruction {
958+
unsafe impl CoreArrayProviderInner for Instruction {
959959
unsafe fn free(raw: *mut Self::Raw, _count: usize, _context: &Self::Context) {
960960
unsafe { BNFreeILInstructionList(raw) }
961961
}
@@ -965,7 +965,7 @@ unsafe impl CoreArrayProviderInner for HighLevelILInstruction {
965965
}
966966
}
967967

968-
impl Debug for HighLevelILInstruction {
968+
impl Debug for Instruction {
969969
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
970970
// TODO: Actual debug impl please!
971971
write!(
@@ -978,7 +978,7 @@ impl Debug for HighLevelILInstruction {
978978
}
979979

980980
#[derive(Debug, Copy, Clone)]
981-
pub enum HighLevelILInstructionKind {
981+
pub enum InstructionKind {
982982
Nop,
983983
Break,
984984
Continue,

rust/src/operand_iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use binaryninjacore_sys::BNHighLevelILOperation;
44
use binaryninjacore_sys::BNMediumLevelILOperation;
55

66
use crate::high_level_il::{
7-
HighLevelILFunction, HighLevelILInstruction, HighLevelInstructionIndex,
7+
HighLevelILFunction, HighLevelInstructionIndex, Instruction as HighLevelILInstruction,
88
};
99
use crate::medium_level_il::{
1010
MediumLevelILFunction, MediumLevelILInstruction, MediumLevelInstructionIndex,

rust/tests/high_level_il.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use binaryninja::binary_view::BinaryViewExt;
22
use binaryninja::headless::Session;
3-
use binaryninja::high_level_il::{HighLevelILInstructionKind, HighLevelInstructionIndex};
3+
use binaryninja::high_level_il::{HighLevelInstructionIndex, InstructionKind};
44
use std::path::PathBuf;
55

66
#[test]
@@ -27,7 +27,7 @@ fn test_hlil_info() {
2727
assert_eq!(instr_0.address, image_base + 0x00025f22);
2828
println!("{:?}", instr_0.kind);
2929
match instr_0.kind {
30-
HighLevelILInstructionKind::Ret(op) => {
30+
InstructionKind::Ret(op) => {
3131
assert_eq!(op.first_src, 4);
3232
assert_eq!(op.num_srcs, 1);
3333
}

0 commit comments

Comments
 (0)