summaryrefslogtreecommitdiff
path: root/rust/src
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2024-08-09 13:28:14 -0700
committerMason Reed <mason@vector35.com>2024-09-22 19:18:59 -0400
commit2b05272e4f369bb261eea72832696496cfabd6a0 (patch)
tree9635f98aaa95c31d85cef06c5837dbbcdf1842fb /rust/src
parent23cd21bceaf3b9f47306653a9430393ef6824e8b (diff)
Add LLIL_EXTERN_PTR to rust api
Diffstat (limited to 'rust/src')
-rw-r--r--rust/src/llil/expression.rs9
-rw-r--r--rust/src/llil/operation.rs43
2 files changed, 52 insertions, 0 deletions
diff --git a/rust/src/llil/expression.rs b/rust/src/llil/expression.rs
index 4339787b..94fd52ed 100644
--- a/rust/src/llil/expression.rs
+++ b/rust/src/llil/expression.rs
@@ -98,6 +98,8 @@ where
LLIL_CONST => ExprInfo::Const(Operation::new(function, op)),
LLIL_CONST_PTR => ExprInfo::ConstPtr(Operation::new(function, op)),
+ LLIL_EXTERN_PTR => ExprInfo::ExternPtr(Operation::new(function, op)),
+
LLIL_ADD => ExprInfo::Add(Operation::new(function, op)),
LLIL_ADC => ExprInfo::Adc(Operation::new(function, op)),
LLIL_SUB => ExprInfo::Sub(Operation::new(function, op)),
@@ -392,6 +394,7 @@ where
ConstPtr(Operation<'func, A, M, F, operation::Const>),
Flag(Operation<'func, A, M, F, operation::Flag>),
FlagBit(Operation<'func, A, M, F, operation::FlagBit>),
+ ExternPtr(Operation<'func, A, M, F, operation::Extern>),
Add(Operation<'func, A, M, F, operation::BinaryOp>),
Adc(Operation<'func, A, M, F, operation::BinaryOpCarry>),
@@ -608,6 +611,8 @@ where
Const(ref op) | ConstPtr(ref op) => &op.op,
+ ExternPtr(ref op) => &op.op,
+
Adc(ref op) | Sbb(ref op) | Rlc(ref op) | Rrc(ref op) => &op.op,
Add(ref op) | Sub(ref op) | And(ref op) | Or(ref op) | Xor(ref op) | Lsl(ref op)
@@ -663,6 +668,8 @@ where
Const(ref op) | ConstPtr(ref op) => op.flag_write(),
+ ExternPtr(ref op) => op.flag_write(),
+
Adc(ref op) | Sbb(ref op) | Rlc(ref op) | Rrc(ref op) => op.flag_write(),
Add(ref op) | Sub(ref op) | And(ref op) | Or(ref op) | Xor(ref op) | Lsl(ref op)
@@ -775,6 +782,8 @@ where
Const(ref op) | ConstPtr(ref op) => write!(f, "0x{:x}", op.value()),
+ ExternPtr(ref op) => write!(f, "0x{:x}", op.value()),
+
Adc(ref op) | Sbb(ref op) | Rlc(ref op) | Rrc(ref op) => {
let left = op.left();
let right = op.right();
diff --git a/rust/src/llil/operation.rs b/rust/src/llil/operation.rs
index f42b3693..b65dfa8c 100644
--- a/rust/src/llil/operation.rs
+++ b/rust/src/llil/operation.rs
@@ -607,6 +607,48 @@ where
}
}
+// LLIL_EXTERN_PTR
+pub struct Extern;
+
+impl<'func, A, M, F> Operation<'func, A, M, F, Extern>
+where
+ A: 'func + Architecture,
+ M: FunctionMutability,
+ F: FunctionForm,
+{
+ pub fn size(&self) -> usize {
+ self.op.size
+ }
+
+ pub fn value(&self) -> u64 {
+ #[cfg(debug_assertions)]
+ {
+ let raw = self.op.operands[0] as i64;
+
+ let is_safe = match raw.overflowing_shr(self.op.size as u32 * 8) {
+ (_, true) => true,
+ (res, false) => [-1, 0].contains(&res),
+ };
+
+ if !is_safe {
+ error!(
+ "il expr @ {:x} contains extern 0x{:x} as {} byte value (doesn't fit!)",
+ self.op.address, self.op.operands[0], self.op.size
+ );
+ }
+ }
+
+ let mut mask = -1i64 as u64;
+
+ if self.op.size < mem::size_of::<u64>() {
+ mask <<= self.op.size * 8;
+ mask = !mask;
+ }
+
+ self.op.operands[0] & mask
+ }
+}
+
// LLIL_ADD, LLIL_SUB, LLIL_AND, LLIL_OR
// LLIL_XOR, LLIL_LSL, LLIL_LSR, LLIL_ASR
// LLIL_ROL, LLIL_ROR, LLIL_MUL, LLIL_MULU_DP,
@@ -774,6 +816,7 @@ impl OperationArguments for RegPhi {}
impl OperationArguments for FlagPhi {}
impl OperationArguments for MemPhi {}
impl OperationArguments for Const {}
+impl OperationArguments for Extern {}
impl OperationArguments for BinaryOp {}
impl OperationArguments for BinaryOpCarry {}
impl OperationArguments for DoublePrecDivOp {}