From 5841af2db8e8dcf4e0da0c438ac040c5fa90038b Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Tue, 21 Aug 2018 15:47:34 -0400 Subject: Add return hint MLIL instruction (used in intermediate stages, not emitted in final forms) --- binaryninjaapi.h | 1 + binaryninjacore.h | 1 + mediumlevelilinstruction.cpp | 9 +++++++++ mediumlevelilinstruction.h | 4 ++++ python/mediumlevelil.py | 1 + 5 files changed, 16 insertions(+) diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 32ed38d2..e0406592 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -3187,6 +3187,7 @@ namespace BinaryNinja ExprId Jump(ExprId dest, const ILSourceLocation& loc = ILSourceLocation()); ExprId JumpTo(ExprId dest, const std::vector& targets, const ILSourceLocation& loc = ILSourceLocation()); + ExprId ReturnHint(ExprId dest, const ILSourceLocation& loc = ILSourceLocation()); ExprId Call(const std::vector& output, ExprId dest, const std::vector& params, const ILSourceLocation& loc = ILSourceLocation()); ExprId CallUntyped(const std::vector& output, ExprId dest, const std::vector& params, diff --git a/binaryninjacore.h b/binaryninjacore.h index c8fb9f8f..e029f208 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -851,6 +851,7 @@ extern "C" MLIL_LOW_PART, MLIL_JUMP, MLIL_JUMP_TO, + MLIL_RET_HINT, // Intermediate stages, does not appear in final forms MLIL_CALL, // Not valid in SSA form (see MLIL_CALL_SSA) MLIL_CALL_UNTYPED, // Not valid in SSA form (see MLIL_CALL_UNTYPED_SSA) MLIL_CALL_OUTPUT, // Only valid within MLIL_CALL, MLIL_SYSCALL, MLIL_TAILCALL family instructions diff --git a/mediumlevelilinstruction.cpp b/mediumlevelilinstruction.cpp index 9cf82b08..93587c34 100644 --- a/mediumlevelilinstruction.cpp +++ b/mediumlevelilinstruction.cpp @@ -122,6 +122,7 @@ unordered_map> {MLIL_ADDRESS_OF_FIELD, {SourceVariableMediumLevelOperandUsage, OffsetMediumLevelOperandUsage}}, {MLIL_JUMP, {DestExprMediumLevelOperandUsage}}, {MLIL_JUMP_TO, {DestExprMediumLevelOperandUsage, TargetListMediumLevelOperandUsage}}, + {MLIL_RET_HINT, {DestExprMediumLevelOperandUsage}}, {MLIL_CALL, {OutputVariablesMediumLevelOperandUsage, DestExprMediumLevelOperandUsage, ParameterExprsMediumLevelOperandUsage}}, {MLIL_CALL_UNTYPED, {OutputVariablesSubExprMediumLevelOperandUsage, DestExprMediumLevelOperandUsage, @@ -1322,6 +1323,7 @@ void MediumLevelILInstruction::VisitExprs(const std::function& output, ExprId dest, const vector& params, const ILSourceLocation& loc) { diff --git a/mediumlevelilinstruction.h b/mediumlevelilinstruction.h index b37b8832..d39ea87d 100644 --- a/mediumlevelilinstruction.h +++ b/mediumlevelilinstruction.h @@ -814,6 +814,10 @@ namespace BinaryNinja MediumLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(0); } MediumLevelILIndexList GetTargetList() const { return GetRawOperandAsIndexList(1); } }; + template <> struct MediumLevelILInstructionAccessor: public MediumLevelILInstructionBase + { + MediumLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(0); } + }; template <> struct MediumLevelILInstructionAccessor: public MediumLevelILInstructionBase { diff --git a/python/mediumlevelil.py b/python/mediumlevelil.py index cfa8f900..774231ab 100644 --- a/python/mediumlevelil.py +++ b/python/mediumlevelil.py @@ -128,6 +128,7 @@ class MediumLevelILInstruction(object): MediumLevelILOperation.MLIL_LOW_PART: [("src", "expr")], MediumLevelILOperation.MLIL_JUMP: [("dest", "expr")], MediumLevelILOperation.MLIL_JUMP_TO: [("dest", "expr"), ("targets", "int_list")], + MediumLevelILOperation.MLIL_RET_HINT: [("dest", "expr")], MediumLevelILOperation.MLIL_CALL: [("output", "var_list"), ("dest", "expr"), ("params", "expr_list")], MediumLevelILOperation.MLIL_CALL_UNTYPED: [("output", "expr"), ("dest", "expr"), ("params", "expr"), ("stack", "expr")], MediumLevelILOperation.MLIL_CALL_OUTPUT: [("dest", "var_list")], -- cgit v1.3.1