Skip to content

Commit 8922a98

Browse files
committed
Set LLIL expression attribute in Rust
1 parent 4ed524d commit 8922a98

2 files changed

Lines changed: 58 additions & 1 deletion

File tree

rust/src/low_level_il.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
use std::borrow::Cow;
16+
use std::collections::HashSet;
1617
use std::fmt;
1718
use std::fmt::{Debug, Display};
1819
// TODO : provide some way to forbid emitting register reads for certain registers
@@ -316,3 +317,42 @@ pub enum VisitorAction {
316317
Sibling,
317318
Halt,
318319
}
320+
321+
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
322+
pub enum ILInstructionAttribute {
323+
ILAllowDeadStoreElimination,
324+
ILPreventDeadStoreElimination,
325+
MLILAssumePossibleUse,
326+
MLILUnknownSize,
327+
SrcInstructionUsesPointerAuth,
328+
ILPreventAliasAnalysis,
329+
ILIsCFGProtected,
330+
MLILPossiblyUnusedIntermediate,
331+
HLILFoldableExpr,
332+
HLILInvertableCondition,
333+
HLILEarlyReturnPossible,
334+
HLILSwitchRecoveryPossible,
335+
ILTransparentCopy,
336+
}
337+
338+
impl ILInstructionAttribute {
339+
pub fn value(&self) -> u32 {
340+
match self {
341+
Self::ILAllowDeadStoreElimination => 1,
342+
Self::ILPreventDeadStoreElimination => 2,
343+
Self::MLILAssumePossibleUse => 4,
344+
Self::MLILUnknownSize => 8,
345+
Self::SrcInstructionUsesPointerAuth => 16,
346+
Self::ILPreventAliasAnalysis => 32,
347+
Self::ILIsCFGProtected => 64,
348+
Self::MLILPossiblyUnusedIntermediate => 128,
349+
Self::HLILFoldableExpr => 256,
350+
Self::HLILInvertableCondition => 512,
351+
Self::HLILEarlyReturnPossible => 1024,
352+
Self::HLILSwitchRecoveryPossible => 2048,
353+
Self::ILTransparentCopy => 4096,
354+
}
355+
}
356+
}
357+
358+
pub type ILInstructionAttributeSet = HashSet<ILInstructionAttribute>;

rust/src/low_level_il/lifting.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
use std::marker::PhantomData;
1616

17-
use binaryninjacore_sys::{BNAddLowLevelILLabelForAddress, BNLowLevelILOperation};
17+
use binaryninjacore_sys::{
18+
BNAddLowLevelILLabelForAddress, BNLowLevelILOperation, BNSetLowLevelILExprAttributes,
19+
};
1820
use binaryninjacore_sys::{BNLowLevelILLabel, BNRegisterOrConstant};
1921

2022
use super::*;
@@ -1569,6 +1571,21 @@ impl LowLevelILMutableFunction {
15691571
}
15701572
*label = new_label;
15711573
}
1574+
1575+
pub fn set_expr_attributes(
1576+
&self,
1577+
expr: LowLevelExpressionIndex,
1578+
value: &ILInstructionAttributeSet,
1579+
) {
1580+
let mut result = 0u32;
1581+
for flag in value {
1582+
result |= flag.value();
1583+
}
1584+
1585+
unsafe {
1586+
BNSetLowLevelILExprAttributes(self.handle, expr.0, result);
1587+
}
1588+
}
15721589
}
15731590

15741591
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]

0 commit comments

Comments
 (0)