diff options
| author | Rusty Wagner <rusty.wagner@gmail.com> | 2022-02-04 22:04:52 -0500 |
|---|---|---|
| committer | Rusty Wagner <rusty.wagner@gmail.com> | 2022-06-22 17:38:21 -0400 |
| commit | da250551336d916ad0058bf200e1f0b29ccb2a8f (patch) | |
| tree | ce0bd66003e2eda8f3b8ebc63bc623d265410df5 | |
| parent | 63e72efd13b31c1d2061b978e2a5f4688e7ba4fd (diff) | |
Add unreachable instruction for switch statements with an unreachable default
| -rw-r--r-- | binaryninjaapi.h | 1 | ||||
| -rw-r--r-- | binaryninjacore.h | 8 | ||||
| -rw-r--r-- | highlevelilinstruction.cpp | 10 | ||||
| -rw-r--r-- | highlevelilinstruction.h | 3 | ||||
| -rw-r--r-- | python/highlevelil.py | 7 |
5 files changed, 26 insertions, 3 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index bfa94d6f..8433b1d1 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -5016,6 +5016,7 @@ namespace BinaryNinja { ExprId Jump(ExprId dest, const ILSourceLocation& loc = ILSourceLocation()); ExprId Return(const std::vector<ExprId>& sources, const ILSourceLocation& loc = ILSourceLocation()); ExprId NoReturn(const ILSourceLocation& loc = ILSourceLocation()); + ExprId Unreachable(const ILSourceLocation& loc = ILSourceLocation()); ExprId Goto(uint64_t target, const ILSourceLocation& loc = ILSourceLocation()); ExprId Label(uint64_t target, const ILSourceLocation& loc = ILSourceLocation()); ExprId VarDeclare(const Variable& var, const ILSourceLocation& loc = ILSourceLocation()); diff --git a/binaryninjacore.h b/binaryninjacore.h index 587e5920..fe5a984a 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -36,14 +36,14 @@ // Current ABI version for linking to the core. This is incremented any time // there are changes to the API that affect linking, including new functions, // new types, or modifications to existing functions or types. -#define BN_CURRENT_CORE_ABI_VERSION 21 +#define BN_CURRENT_CORE_ABI_VERSION 22 // Minimum ABI version that is supported for loading of plugins. Plugins that // are linked to an ABI version less than this will not be able to load and // will require rebuilding. The minimum version is increased when there are // incompatible changes that break binary compatibility, such as changes to // existing types or functions. -#define BN_MINIMUM_CORE_ABI_VERSION 20 +#define BN_MINIMUM_CORE_ABI_VERSION 22 #ifdef __GNUC__ #ifdef BINARYNINJACORE_LIBRARY @@ -1276,6 +1276,10 @@ extern "C" HLIL_FCMP_O, HLIL_FCMP_UO, + // Unreachable hint, typically used in switch statements that analysis knows + // has an unreachable default. + HLIL_UNREACHABLE, + // The following instructions are only used in SSA form HLIL_WHILE_SSA, HLIL_DO_WHILE_SSA, diff --git a/highlevelilinstruction.cpp b/highlevelilinstruction.cpp index 0e32673b..98c85ea2 100644 --- a/highlevelilinstruction.cpp +++ b/highlevelilinstruction.cpp @@ -66,7 +66,7 @@ unordered_map<HighLevelILOperandUsage, HighLevelILOperandType> HighLevelILInstru unordered_map<BNHighLevelILOperation, vector<HighLevelILOperandUsage>> HighLevelILInstructionBase::operationOperandUsage = {{HLIL_NOP, {}}, {HLIL_BREAK, {}}, {HLIL_CONTINUE, {}}, - {HLIL_NORET, {}}, {HLIL_BP, {}}, {HLIL_UNDEF, {}}, {HLIL_UNIMPL, {}}, + {HLIL_NORET, {}}, {HLIL_BP, {}}, {HLIL_UNDEF, {}}, {HLIL_UNIMPL, {}}, {HLIL_UNREACHABLE, {}}, {HLIL_BLOCK, {BlockExprsHighLevelOperandUsage}}, {HLIL_IF, {ConditionExprHighLevelOperandUsage, TrueExprHighLevelOperandUsage, FalseExprHighLevelOperandUsage}}, {HLIL_WHILE, {ConditionExprHighLevelOperandUsage, LoopExprHighLevelOperandUsage}}, @@ -1371,6 +1371,8 @@ ExprId HighLevelILInstruction::CopyTo( return dest->Return(params, *this); case HLIL_NORET: return dest->NoReturn(*this); + case HLIL_UNREACHABLE: + return dest->Unreachable(*this); case HLIL_NEG: case HLIL_NOT: case HLIL_SX: @@ -2451,6 +2453,12 @@ ExprId HighLevelILFunction::NoReturn(const ILSourceLocation& loc) } +ExprId HighLevelILFunction::Unreachable(const ILSourceLocation& loc) +{ + return AddExprWithLocation(HLIL_UNREACHABLE, loc, 0); +} + + ExprId HighLevelILFunction::Goto(uint64_t target, const ILSourceLocation& loc) { return AddExprWithLocation(HLIL_GOTO, loc, 0, target); diff --git a/highlevelilinstruction.h b/highlevelilinstruction.h index 9cdb9b1a..97418100 100644 --- a/highlevelilinstruction.h +++ b/highlevelilinstruction.h @@ -1109,6 +1109,9 @@ namespace BinaryNinja template <> struct HighLevelILInstructionAccessor<HLIL_UNIMPL> : public HighLevelILInstructionBase {}; + template <> + struct HighLevelILInstructionAccessor<HLIL_UNREACHABLE> : public HighLevelILInstructionBase + {}; template <> struct HighLevelILInstructionAccessor<HLIL_CONST> : public HighLevelILConstantInstruction diff --git a/python/highlevelil.py b/python/highlevelil.py index 942330bf..395de637 100644 --- a/python/highlevelil.py +++ b/python/highlevelil.py @@ -159,6 +159,7 @@ class HighLevelILInstruction(BaseILInstruction): HighLevelILOperation.HLIL_BREAK: [], HighLevelILOperation.HLIL_CONTINUE: [], HighLevelILOperation.HLIL_JUMP: [ ("dest", "expr") ], HighLevelILOperation.HLIL_RET: [("src", "expr_list")], HighLevelILOperation.HLIL_NORET: [], + HighLevelILOperation.HLIL_UNREACHABLE: [], HighLevelILOperation.HLIL_GOTO: [("target", "label")], HighLevelILOperation.HLIL_LABEL: [ ("target", "label") ], HighLevelILOperation.HLIL_VAR_DECLARE: [("var", "var")], HighLevelILOperation.HLIL_VAR_INIT: [ @@ -1017,6 +1018,11 @@ class HighLevelILNoret(HighLevelILInstruction, Terminal): @dataclass(frozen=True, repr=False, eq=False) +class HighLevelILUnreachable(HighLevelILInstruction, Terminal): + pass + + +@dataclass(frozen=True, repr=False, eq=False) class HighLevelILGoto(HighLevelILInstruction, Terminal): @property def target(self) -> GotoLabel: @@ -1937,6 +1943,7 @@ ILInstruction = { HighLevelILOperation.HLIL_JUMP: HighLevelILJump, # ("dest", "expr"), HighLevelILOperation.HLIL_RET: HighLevelILRet, # ("src", "expr_list"), HighLevelILOperation.HLIL_NORET: HighLevelILNoret, # , + HighLevelILOperation.HLIL_UNREACHABLE: HighLevelILUnreachable, # , HighLevelILOperation.HLIL_GOTO: HighLevelILGoto, # ("target", "label"), HighLevelILOperation.HLIL_LABEL: HighLevelILLabel, # ("target", "label"), HighLevelILOperation.HLIL_VAR_DECLARE: HighLevelILVarDeclare, # ("var", "var"), |
