Skip to content

Commit 1b666ca

Browse files
committed
[Rust] Don't panic when a Rust plug-in encounters an unhandled MLIL instruction
`MediumLevelILInstruction` does not yet handle `MLIL_CALL_OUTPUT`, `MLIL_CALL_PARAM`, `MLIL_CALL_PARAM_SSA`, `MLIL_CALL_OUTPUT_SSA`, `MLIL_MEMORY_INTRINSIC_OUTPUT_SSA`, or `MLIL_MEMORY_INTRINSIC_SSA`. Map these to a `NotYetImplemented` kind rather than panicking since a panic takes down the entire app.
1 parent 5304630 commit 1b666ca

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

rust/src/medium_level_il/instruction.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -609,9 +609,7 @@ impl MediumLevelILInstruction {
609609
| MLIL_CALL_PARAM_SSA
610610
| MLIL_CALL_OUTPUT_SSA
611611
| MLIL_MEMORY_INTRINSIC_OUTPUT_SSA
612-
| MLIL_MEMORY_INTRINSIC_SSA => {
613-
unimplemented!()
614-
}
612+
| MLIL_MEMORY_INTRINSIC_SSA => Op::NotYetImplemented,
615613
};
616614

617615
Self {
@@ -633,6 +631,7 @@ impl MediumLevelILInstruction {
633631
Bp => Lifted::Bp,
634632
Undef => Lifted::Undef,
635633
Unimpl => Lifted::Unimpl,
634+
NotYetImplemented => Lifted::NotYetImplemented,
636635
If(op) => Lifted::If(LiftedIf {
637636
condition: self.lift_operand(op.condition),
638637
dest_true: op.dest_true,
@@ -1629,6 +1628,9 @@ pub enum MediumLevelILInstructionKind {
16291628
VarSsaField(VarSsaField),
16301629
VarAliasedField(VarSsaField),
16311630
Trap(Trap),
1631+
// A placeholder for instructions that the Rust bindings do not yet support.
1632+
// Distinct from `Unimpl` as that is a valid instruction.
1633+
NotYetImplemented,
16321634
}
16331635

16341636
fn get_float(value: u64, size: usize) -> f64 {

rust/src/medium_level_il/lift.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ pub enum MediumLevelILLiftedInstructionKind {
175175
VarSsaField(VarSsaField),
176176
VarAliasedField(VarSsaField),
177177
Trap(Trap),
178+
// A placeholder for instructions that the Rust bindings do not yet support.
179+
// Distinct from `Unimpl` as that is a valid instruction.
180+
NotYetImplemented,
178181
}
179182

180183
impl MediumLevelILLiftedInstruction {
@@ -186,6 +189,7 @@ impl MediumLevelILLiftedInstruction {
186189
Bp => "Bp",
187190
Undef => "Undef",
188191
Unimpl => "Unimpl",
192+
NotYetImplemented => "NotYetImplemented",
189193
If(_) => "If",
190194
FloatConst(_) => "FloatConst",
191195
Const(_) => "Const",
@@ -318,7 +322,7 @@ impl MediumLevelILLiftedInstruction {
318322
use MediumLevelILLiftedInstructionKind::*;
319323
use MediumLevelILLiftedOperand as Operand;
320324
match &self.kind {
321-
Nop | Noret | Bp | Undef | Unimpl => vec![],
325+
Nop | Noret | Bp | Undef | Unimpl | NotYetImplemented => vec![],
322326
If(op) => vec![
323327
("condition", Operand::Expr(*op.condition.clone())),
324328
("dest_true", Operand::InstructionIndex(op.dest_true)),

0 commit comments

Comments
 (0)