Skip to content

Commit 881220d

Browse files
committed
[Rust] Rename ExpressionBuilder to LowLevelILExpressionBuilder
1 parent e09a04d commit 881220d

File tree

2 files changed

+50
-29
lines changed

2 files changed

+50
-29
lines changed

rust/src/low_level_il/lifting.rs

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ where
695695
}
696696
}
697697

698-
pub struct ExpressionBuilder<'func, R>
698+
pub struct LowLevelILExpressionBuilder<'func, R>
699699
where
700700
R: ExpressionResultType,
701701
{
@@ -711,7 +711,7 @@ where
711711
_ty: PhantomData<R>,
712712
}
713713

714-
impl<'a, R> ExpressionBuilder<'a, R>
714+
impl<'a, R> LowLevelILExpressionBuilder<'a, R>
715715
where
716716
R: ExpressionResultType,
717717
{
@@ -720,7 +720,7 @@ where
720720
op: BNLowLevelILOperation,
721721
size: usize,
722722
) -> Self {
723-
ExpressionBuilder {
723+
LowLevelILExpressionBuilder {
724724
function,
725725
op,
726726
location: None,
@@ -739,7 +739,7 @@ where
739739

740740
let instr = unsafe { BNGetLowLevelILByIndex(expr.function.handle, expr.index.0) };
741741

742-
ExpressionBuilder {
742+
LowLevelILExpressionBuilder {
743743
function: expr.function,
744744
op: instr.operation,
745745
location: Some(LowLevelILSourceLocation::from(&instr)),
@@ -798,6 +798,9 @@ where
798798
self
799799
}
800800

801+
// TODO: I would have preferred to pass in the LLIL function as a ref here instead of keeping it
802+
// TODO: in the builder. But all architectures append with that implied llil function with `append()`
803+
// TODO: so we would be ergonomically worse, until the functions like il.set_reg or whatever go away.
801804
pub fn build(self) -> LowLevelILExpression<'a, Mutable, NonSSA, R> {
802805
use binaryninjacore_sys::BNLowLevelILAddExpr;
803806
use binaryninjacore_sys::BNLowLevelILAddExprWithLocation;
@@ -840,7 +843,7 @@ where
840843
}
841844
}
842845

843-
impl<'a, R> LiftableLowLevelIL<'a> for ExpressionBuilder<'a, R>
846+
impl<'a, R> LiftableLowLevelIL<'a> for LowLevelILExpressionBuilder<'a, R>
844847
where
845848
R: ExpressionResultType,
846849
{
@@ -856,7 +859,7 @@ where
856859
}
857860
}
858861

859-
impl<'a> LiftableLowLevelILWithSize<'a> for ExpressionBuilder<'a, ValueExpr> {
862+
impl<'a> LiftableLowLevelILWithSize<'a> for LowLevelILExpressionBuilder<'a, ValueExpr> {
860863
fn lift_with_size(
861864
il: &'a LowLevelILMutableFunction,
862865
expr: Self,
@@ -895,10 +898,10 @@ macro_rules! no_arg_lifter {
895898

896899
macro_rules! sized_no_arg_lifter {
897900
($name:ident, $op:ident, $result:ty) => {
898-
pub fn $name(&self, size: usize) -> ExpressionBuilder<$result> {
901+
pub fn $name(&self, size: usize) -> LowLevelILExpressionBuilder<$result> {
899902
use binaryninjacore_sys::BNLowLevelILOperation::$op;
900903

901-
ExpressionBuilder::new(self, $op, size)
904+
LowLevelILExpressionBuilder::new(self, $op, size)
902905
}
903906
};
904907
}
@@ -925,30 +928,38 @@ macro_rules! unsized_unary_op_lifter {
925928

926929
macro_rules! sized_unary_op_lifter {
927930
($name:ident, $op:ident, $result:ty) => {
928-
pub fn $name<'a, E>(&'a self, size: usize, expr: E) -> ExpressionBuilder<'a, $result>
931+
pub fn $name<'a, E>(
932+
&'a self,
933+
size: usize,
934+
expr: E,
935+
) -> LowLevelILExpressionBuilder<'a, $result>
929936
where
930937
E: LiftableLowLevelILWithSize<'a>,
931938
{
932939
use binaryninjacore_sys::BNLowLevelILOperation::$op;
933940

934941
let expr = E::lift_with_size(self, expr, size);
935942

936-
ExpressionBuilder::new(self, $op, size).with_op1(expr.index.0 as u64)
943+
LowLevelILExpressionBuilder::new(self, $op, size).with_op1(expr.index.0 as u64)
937944
}
938945
};
939946
}
940947

941948
macro_rules! size_changing_unary_op_lifter {
942949
($name:ident, $op:ident, $result:ty) => {
943-
pub fn $name<'a, E>(&'a self, size: usize, expr: E) -> ExpressionBuilder<'a, $result>
950+
pub fn $name<'a, E>(
951+
&'a self,
952+
size: usize,
953+
expr: E,
954+
) -> LowLevelILExpressionBuilder<'a, $result>
944955
where
945956
E: LiftableLowLevelILWithSize<'a>,
946957
{
947958
use binaryninjacore_sys::BNLowLevelILOperation::$op;
948959

949960
let expr = E::lift(self, expr);
950961

951-
ExpressionBuilder::new(self, $op, size).with_op1(expr.index.0 as u64)
962+
LowLevelILExpressionBuilder::new(self, $op, size).with_op1(expr.index.0 as u64)
952963
}
953964
};
954965
}
@@ -960,7 +971,7 @@ macro_rules! binary_op_lifter {
960971
size: usize,
961972
left: L,
962973
right: R,
963-
) -> ExpressionBuilder<'a, ValueExpr>
974+
) -> LowLevelILExpressionBuilder<'a, ValueExpr>
964975
where
965976
L: LiftableLowLevelILWithSize<'a>,
966977
R: LiftableLowLevelILWithSize<'a>,
@@ -970,7 +981,7 @@ macro_rules! binary_op_lifter {
970981
let left = L::lift_with_size(self, left, size);
971982
let right = R::lift_with_size(self, right, size);
972983

973-
ExpressionBuilder::new(self, $op, size)
984+
LowLevelILExpressionBuilder::new(self, $op, size)
974985
.with_op1(left.index.0 as u64)
975986
.with_op2(right.index.0 as u64)
976987
}
@@ -985,7 +996,7 @@ macro_rules! binary_op_carry_lifter {
985996
left: L,
986997
right: R,
987998
carry: C,
988-
) -> ExpressionBuilder<'a, ValueExpr>
999+
) -> LowLevelILExpressionBuilder<'a, ValueExpr>
9891000
where
9901001
L: LiftableLowLevelILWithSize<'a>,
9911002
R: LiftableLowLevelILWithSize<'a>,
@@ -997,7 +1008,7 @@ macro_rules! binary_op_carry_lifter {
9971008
let right = R::lift_with_size(self, right, size);
9981009
let carry = C::lift_with_size(self, carry, 0);
9991010

1000-
ExpressionBuilder::new(self, $op, size)
1011+
LowLevelILExpressionBuilder::new(self, $op, size)
10011012
.with_op1(left.index.0 as u64)
10021013
.with_op2(right.index.0 as u64)
10031014
.with_op3(carry.index.0 as u64)
@@ -1006,7 +1017,7 @@ macro_rules! binary_op_carry_lifter {
10061017
}
10071018

10081019
impl LowLevelILMutableFunction {
1009-
pub const NO_INPUTS: [ExpressionBuilder<'static, ValueExpr>; 0] = [];
1020+
pub const NO_INPUTS: [LowLevelILExpressionBuilder<'static, ValueExpr>; 0] = [];
10101021
pub const NO_OUTPUTS: [LowLevelILRegisterKind<CoreRegister>; 0] = [];
10111022

10121023
pub fn expression<'a, E: LiftableLowLevelIL<'a>>(
@@ -1199,7 +1210,7 @@ impl LowLevelILMutableFunction {
11991210
size: usize,
12001211
dest_reg: LR,
12011212
expr: E,
1202-
) -> ExpressionBuilder<'a, VoidExpr>
1213+
) -> LowLevelILExpressionBuilder<'a, VoidExpr>
12031214
where
12041215
R: ArchReg,
12051216
LR: Into<LowLevelILRegisterKind<R>>,
@@ -1212,7 +1223,7 @@ impl LowLevelILMutableFunction {
12121223

12131224
let expr = E::lift_with_size(self, expr, size);
12141225

1215-
ExpressionBuilder::new(self, LLIL_SET_REG, size)
1226+
LowLevelILExpressionBuilder::new(self, LLIL_SET_REG, size)
12161227
.with_op1(dest_reg)
12171228
.with_op2(expr.index.0 as u64)
12181229
}
@@ -1223,7 +1234,7 @@ impl LowLevelILMutableFunction {
12231234
hi_reg: LR,
12241235
lo_reg: LR,
12251236
expr: E,
1226-
) -> ExpressionBuilder<'a, VoidExpr>
1237+
) -> LowLevelILExpressionBuilder<'a, VoidExpr>
12271238
where
12281239
R: ArchReg,
12291240
LR: Into<LowLevelILRegisterKind<R>>,
@@ -1237,7 +1248,7 @@ impl LowLevelILMutableFunction {
12371248

12381249
let expr = E::lift_with_size(self, expr, size);
12391250

1240-
ExpressionBuilder::new(self, LLIL_SET_REG_SPLIT, size)
1251+
LowLevelILExpressionBuilder::new(self, LLIL_SET_REG_SPLIT, size)
12411252
.with_op1(hi_reg)
12421253
.with_op2(lo_reg)
12431254
.with_op3(expr.index.0 as u64)
@@ -1291,7 +1302,7 @@ impl LowLevelILMutableFunction {
12911302
&'a self,
12921303
dest_flag: impl Flag,
12931304
expr: E,
1294-
) -> ExpressionBuilder<'a, VoidExpr>
1305+
) -> LowLevelILExpressionBuilder<'a, VoidExpr>
12951306
where
12961307
E: LiftableLowLevelILWithSize<'a>,
12971308
{
@@ -1301,7 +1312,7 @@ impl LowLevelILMutableFunction {
13011312

13021313
let expr = E::lift_with_size(self, expr, 0);
13031314

1304-
ExpressionBuilder::new(self, LLIL_SET_FLAG, 0)
1315+
LowLevelILExpressionBuilder::new(self, LLIL_SET_FLAG, 0)
13051316
.with_op1(dest_flag.id())
13061317
.with_op2(expr.index.0 as u64)
13071318
}
@@ -1311,23 +1322,27 @@ impl LowLevelILMutableFunction {
13111322
FlagBit(usize, Flag<A>, u64),
13121323
*/
13131324

1314-
pub fn load<'a, E>(&'a self, size: usize, source_mem: E) -> ExpressionBuilder<'a, ValueExpr>
1325+
pub fn load<'a, E>(
1326+
&'a self,
1327+
size: usize,
1328+
source_mem: E,
1329+
) -> LowLevelILExpressionBuilder<'a, ValueExpr>
13151330
where
13161331
E: LiftableLowLevelIL<'a, Result = ValueExpr>,
13171332
{
13181333
use binaryninjacore_sys::BNLowLevelILOperation::LLIL_LOAD;
13191334

13201335
let expr = E::lift(self, source_mem);
13211336

1322-
ExpressionBuilder::new(self, LLIL_LOAD, size).with_op1(expr.index.0 as u64)
1337+
LowLevelILExpressionBuilder::new(self, LLIL_LOAD, size).with_op1(expr.index.0 as u64)
13231338
}
13241339

13251340
pub fn store<'a, D, V>(
13261341
&'a self,
13271342
size: usize,
13281343
dest_mem: D,
13291344
value: V,
1330-
) -> ExpressionBuilder<'a, VoidExpr>
1345+
) -> LowLevelILExpressionBuilder<'a, VoidExpr>
13311346
where
13321347
D: LiftableLowLevelIL<'a, Result = ValueExpr>,
13331348
V: LiftableLowLevelILWithSize<'a>,
@@ -1337,7 +1352,7 @@ impl LowLevelILMutableFunction {
13371352
let dest_mem = D::lift(self, dest_mem);
13381353
let value = V::lift_with_size(self, value, size);
13391354

1340-
ExpressionBuilder::new(self, LLIL_STORE, size)
1355+
LowLevelILExpressionBuilder::new(self, LLIL_STORE, size)
13411356
.with_op1(dest_mem.index.0 as u64)
13421357
.with_op2(value.index.0 as u64)
13431358
}
@@ -1348,7 +1363,7 @@ impl LowLevelILMutableFunction {
13481363
outputs: impl IntoIterator<Item = O>,
13491364
intrinsic: impl Intrinsic,
13501365
inputs: impl IntoIterator<Item = P>,
1351-
) -> ExpressionBuilder<'a, VoidExpr>
1366+
) -> LowLevelILExpressionBuilder<'a, VoidExpr>
13521367
where
13531368
R: ArchReg,
13541369
O: Into<LowLevelILRegisterKind<R>>,
@@ -1386,7 +1401,7 @@ impl LowLevelILMutableFunction {
13861401
)
13871402
};
13881403

1389-
ExpressionBuilder::new(self, LLIL_INTRINSIC, 0)
1404+
LowLevelILExpressionBuilder::new(self, LLIL_INTRINSIC, 0)
13901405
.with_op1(output_expr_idx as u64)
13911406
.with_op2(intrinsic.id().0 as u64)
13921407
.with_op3(input_expr_idx as u64)

rust/tests/low_level_il.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use binaryninja::low_level_il::function::LowLevelILFunction;
88
use binaryninja::low_level_il::instruction::{
99
InstructionHandler, LowLevelILInstructionKind, LowLevelInstructionIndex,
1010
};
11+
use binaryninja::low_level_il::lifting::LowLevelILExpressionBuilder;
1112
use binaryninja::low_level_il::{LowLevelILRegisterKind, LowLevelILSSARegisterKind, VisitorAction};
1213
use std::path::PathBuf;
1314

@@ -355,4 +356,9 @@ fn test_llil_lifting() {
355356
_ => panic!("Expected Value"),
356357
}
357358
println!("{:?}", instr_0.kind());
359+
360+
LowLevelILExpressionBuilder::new()
361+
.const_int(100)
362+
.set_reg(expr_0.index, eax_reg)
363+
.build();
358364
}

0 commit comments

Comments
 (0)