diff options
| author | Mason Reed <mason@vector35.com> | 2025-07-02 17:24:52 -0400 |
|---|---|---|
| committer | Mason Reed <mason@vector35.com> | 2025-07-02 17:25:04 -0400 |
| commit | 3e9f4866914f882bc92aaf99dd1f4d17a8168afb (patch) | |
| tree | 4df9bc2598d8bef9bed888b17555bd0c12df79ef /rust/src/low_level_il | |
| parent | d2347c98b7095eb25a87d4d7ab281e42ef206786 (diff) | |
[Rust] Add missing `LLIL_FLOAT_CONST` low level IL expression
Diffstat (limited to 'rust/src/low_level_il')
| -rw-r--r-- | rust/src/low_level_il/expression.rs | 14 | ||||
| -rw-r--r-- | rust/src/low_level_il/operation.rs | 56 |
2 files changed, 68 insertions, 2 deletions
diff --git a/rust/src/low_level_il/expression.rs b/rust/src/low_level_il/expression.rs index 93780eec..5aa698e2 100644 --- a/rust/src/low_level_il/expression.rs +++ b/rust/src/low_level_il/expression.rs @@ -348,6 +348,8 @@ where Ceil(Operation<'func, M, F, operation::UnaryOp>), Ftrunc(Operation<'func, M, F, operation::UnaryOp>), + FloatConst(Operation<'func, M, F, operation::FloatConst>), + FcmpE(Operation<'func, M, F, operation::Condition>), FcmpNE(Operation<'func, M, F, operation::Condition>), FcmpLT(Operation<'func, M, F, operation::Condition>), @@ -513,6 +515,10 @@ where LLIL_FCMP_O => LowLevelILExpressionKind::FcmpO(Operation::new(function, op, index)), LLIL_FCMP_UO => LowLevelILExpressionKind::FcmpUO(Operation::new(function, op, index)), + LLIL_FLOAT_CONST => { + LowLevelILExpressionKind::FloatConst(Operation::new(function, op, index)) + } + LLIL_SEPARATE_PARAM_LIST_SSA => { LowLevelILExpressionKind::SeparateParamListSsa(Operation::new(function, op, index)) } @@ -524,7 +530,7 @@ where LowLevelILExpressionKind::UnimplMem(Operation::new(function, op, index)) } - // TODO TEST_BIT ADD_OVERFLOW LLIL_REG_STACK_PUSH + // TODO TEST_BIT ADD_OVERFLOW LLIL_REG_STACK_PUSH _ => { #[cfg(debug_assertions)] log::error!( @@ -698,7 +704,7 @@ where Pop(_) | Reg(_) | RegSsa(_) | RegPartialSsa(_) | RegSplit(_) | RegSplitSsa(_) | Const(_) | ConstPtr(_) | Flag(_) | FlagBit(_) | ExternPtr(_) | FlagCond(_) | FlagGroup(_) | Unimpl(_) | Undef(_) | RegStackPop(_) | CallOutputSsa(_) - | CallStackSsa(_) => {} + | CallStackSsa(_) | FloatConst(_) => {} } VisitorAction::Sibling @@ -742,6 +748,8 @@ where Const(ref op) | ConstPtr(ref op) => &op.op, + FloatConst(ref op) => &op.op, + ExternPtr(ref op) => &op.op, RegStackPop(ref op) => &op.op, @@ -812,6 +820,8 @@ impl LowLevelILExpressionKind<'_, Mutable, NonSSA> { Const(ref op) | ConstPtr(ref op) => op.flag_write(), + FloatConst(ref op) => op.flag_write(), + ExternPtr(ref op) => op.flag_write(), RegStackPop(ref op) => op.flag_write(), diff --git a/rust/src/low_level_il/operation.rs b/rust/src/low_level_il/operation.rs index 0db23c82..a2b289d3 100644 --- a/rust/src/low_level_il/operation.rs +++ b/rust/src/low_level_il/operation.rs @@ -1653,6 +1653,61 @@ where } } +// LLIL_FLOAT_CONST +pub struct FloatConst; + +impl<M, F> Operation<'_, M, F, FloatConst> +where + M: FunctionMutability, + F: FunctionForm, +{ + pub fn size(&self) -> usize { + self.op.size + } + + pub fn raw_value(&self) -> u64 { + self.op.operands[0] + } + + pub fn float_value(&self) -> f64 { + let raw_bits = self.raw_value(); + match self.op.size { + 4 => { + // For f32, take the lower 32 bits and convert to f32 + let bits32 = (raw_bits & 0xFFFFFFFF) as u32; + f32::from_bits(bits32) as f64 + } + 8 => { + // For f64, use all 64 bits + f64::from_bits(raw_bits) + } + _ => { + // Log error for unexpected sizes + log::error!( + "il expr @ {:x} has invalid float size {} (expected 4 or 8 bytes)", + self.op.address, + self.op.size + ); + f64::NAN + } + } + } +} + +impl<M, F> Debug for Operation<'_, M, F, FloatConst> +where + M: FunctionMutability, + F: FunctionForm, +{ + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.debug_struct("FloatConst") + .field("size", &self.size()) + .field("float_value", &self.float_value()) + .field("raw_value", &self.raw_value()) + .finish() + } +} + // LLIL_EXTERN_PTR pub struct Extern; @@ -2186,6 +2241,7 @@ impl OperationArguments for RegPhi {} impl OperationArguments for FlagPhi {} impl OperationArguments for MemPhi {} impl OperationArguments for Const {} +impl OperationArguments for FloatConst {} impl OperationArguments for Extern {} impl OperationArguments for BinaryOp {} impl OperationArguments for BinaryOpCarry {} |
