Skip to content

Commit 2b7557d

Browse files
committed
More rust cleanup
- Renamed common name conflictions (I will put my justification in the PR) - Fixed invalid instruction retrieval for LLIL - Added common aliases for llil function, instruction and expression types (see my comment in the PR) - Refactored the instruction retrieval for LLIL, MLIL and HLIL - Added instruction index types to MLIL and HLIL - Moved llil module to lowlevelil module (mlil and hlil will be moved as well) - Added preliminary LLIL unit testing
1 parent f9099a6 commit 2b7557d

36 files changed

+1681
-1034
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ members = [
2222

2323
[profile.release]
2424
lto = true
25-
debug = "full"
25+
debug = "full"

arch/msp430/src/architecture.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use binaryninja::{
88
UnusedIntrinsic, UnusedRegisterStack, UnusedRegisterStackInfo,
99
},
1010
disassembly::{InstructionTextToken, InstructionTextTokenKind},
11-
llil::{LiftedExpr, Lifter},
1211
Endianness,
1312
};
1413

@@ -20,6 +19,8 @@ use msp430_asm::{
2019
use binaryninja::architecture::{
2120
BranchKind, FlagClassId, FlagGroupId, FlagId, FlagWriteId, RegisterId,
2221
};
22+
use binaryninja::lowlevelil::expression::ValueExpr;
23+
use binaryninja::lowlevelil::{MutableLiftedILExpr, MutableLiftedILFunction};
2324
use log::error;
2425

2526
const MIN_MNEMONIC: usize = 9;
@@ -192,7 +193,7 @@ impl Architecture for Msp430 {
192193
&self,
193194
data: &[u8],
194195
addr: u64,
195-
il: &mut Lifter<Self>,
196+
il: &mut MutableLiftedILFunction<Self>,
196197
) -> Option<(usize, bool)> {
197198
match msp430_asm::decode(data) {
198199
Ok(inst) => {
@@ -224,8 +225,8 @@ impl Architecture for Msp430 {
224225
fn flag_group_llil<'a>(
225226
&self,
226227
_group: Self::FlagGroup,
227-
_il: &'a mut Lifter<Self>,
228-
) -> Option<LiftedExpr<'a, Self>> {
228+
_il: &'a mut MutableLiftedILFunction<Self>,
229+
) -> Option<MutableLiftedILExpr<'a, Self, ValueExpr>> {
229230
None
230231
}
231232

arch/msp430/src/lift.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ use crate::flag::{Flag, FlagWrite};
33
use crate::register::Register;
44
use crate::Msp430;
55

6-
use binaryninja::{
7-
architecture::FlagCondition,
8-
llil::{Label, LiftedNonSSA, Lifter, Mutable, NonSSA},
9-
};
6+
use binaryninja::{architecture::FlagCondition, lowlevelil::lifting::Label};
107

118
use msp430_asm::emulate::Emulated;
129
use msp430_asm::instruction::Instruction;
@@ -15,6 +12,8 @@ use msp430_asm::operand::{Operand, OperandWidth};
1512
use msp430_asm::single_operand::SingleOperand;
1613
use msp430_asm::two_operand::TwoOperand;
1714

15+
use binaryninja::lowlevelil::expression::ValueExpr;
16+
use binaryninja::lowlevelil::{MutableLiftedILExpr, MutableLiftedILFunction};
1817
use log::info;
1918

2019
macro_rules! auto_increment {
@@ -169,7 +168,11 @@ macro_rules! conditional_jump {
169168
};
170169
}
171170

172-
pub(crate) fn lift_instruction(inst: &Instruction, addr: u64, il: &Lifter<Msp430>) {
171+
pub(crate) fn lift_instruction(
172+
inst: &Instruction,
173+
addr: u64,
174+
il: &MutableLiftedILFunction<Msp430>,
175+
) {
173176
match inst {
174177
Instruction::Rrc(inst) => {
175178
let size = match inst.operand_width() {
@@ -631,14 +634,8 @@ pub(crate) fn lift_instruction(inst: &Instruction, addr: u64, il: &Lifter<Msp430
631634
fn lift_source_operand<'a>(
632635
operand: &Operand,
633636
size: usize,
634-
il: &'a Lifter<Msp430>,
635-
) -> binaryninja::llil::Expression<
636-
'a,
637-
Msp430,
638-
Mutable,
639-
NonSSA<LiftedNonSSA>,
640-
binaryninja::llil::ValueExpr,
641-
> {
637+
il: &'a MutableLiftedILFunction<Msp430>,
638+
) -> MutableLiftedILExpr<'a, Msp430, ValueExpr> {
642639
match operand {
643640
Operand::RegisterDirect(r) => il.reg(size, Register::try_from(*r as u32).unwrap()),
644641
Operand::Indexed((r, offset)) => il

arch/msp430/src/register.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use binaryninja::architecture;
22
use binaryninja::architecture::{ImplicitRegisterExtend, RegisterId};
33

4+
use binaryninja::lowlevelil::LowLevelILRegister;
45
use std::borrow::Cow;
56

67
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -133,8 +134,8 @@ impl architecture::RegisterInfo for Register {
133134
}
134135
}
135136

136-
impl From<Register> for binaryninja::llil::Register<Register> {
137+
impl From<Register> for LowLevelILRegister<Register> {
137138
fn from(register: Register) -> Self {
138-
binaryninja::llil::Register::ArchReg(register)
139+
LowLevelILRegister::ArchReg(register)
139140
}
140141
}

0 commit comments

Comments
 (0)