From 94b38cee51eff16f1e79945806088c7ae60016d7 Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Wed, 1 Mar 2017 03:45:51 -0500 Subject: Adding framework for medium level IL --- binaryninjaapi.h | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'binaryninjaapi.h') diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 58ea890e..1367e7c1 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -1862,6 +1862,7 @@ namespace BinaryNinja }; class FunctionGraph; + class MediumLevelILFunction; class Function: public CoreRefCountObject { @@ -1913,6 +1914,8 @@ namespace BinaryNinja std::set GetFlagsReadByLiftedILInstruction(size_t i); std::set GetFlagsWrittenByLiftedILInstruction(size_t i); + Ref GetMediumLevelIL() const; + Ref GetType() const; void SetAutoType(Type* type); void SetUserType(Type* type); @@ -2182,6 +2185,73 @@ namespace BinaryNinja RegisterValue GetExprValue(size_t expr); }; + struct MediumLevelILLabel: public BNMediumLevelILLabel + { + MediumLevelILLabel(); + }; + + class MediumLevelILFunction: public CoreRefCountObject + { + public: + MediumLevelILFunction(Architecture* arch, Function* func = nullptr); + MediumLevelILFunction(BNMediumLevelILFunction* func); + + uint64_t GetCurrentAddress() const; + void SetCurrentAddress(Architecture* arch, uint64_t addr); + size_t GetInstructionStart(Architecture* arch, uint64_t addr); + + ExprId AddExpr(BNMediumLevelILOperation operation, size_t size, + ExprId a = 0, ExprId b = 0, ExprId c = 0, ExprId d = 0, ExprId e = 0); + ExprId AddInstruction(ExprId expr); + + ExprId SetVar(size_t size, const BNILVariable& var, ExprId src); + ExprId SetVarField(size_t size, const BNILVariable& var, int64_t offset, ExprId src); + ExprId SetVarSSA(size_t size, const BNILVariable& var, size_t index, ExprId src); + ExprId SetVarFieldSSA(size_t size, const BNILVariable& var, int64_t offset, size_t varIndex, ExprId src); + ExprId Var(size_t size, const BNILVariable& var); + ExprId VarField(size_t size, const BNILVariable& var, int64_t offset); + ExprId VarSSA(size_t size, const BNILVariable& var, size_t index); + ExprId VarFieldSSA(size_t size, const BNILVariable& var, int64_t offset, size_t varIndex); + + ExprId Goto(BNMediumLevelILLabel& label); + ExprId If(ExprId operand, BNMediumLevelILLabel& t, BNMediumLevelILLabel& f); + void MarkLabel(BNMediumLevelILLabel& label); + + std::vector GetOperandList(ExprId i, size_t listOperand); + ExprId AddLabelList(const std::vector& labels); + ExprId AddOperandList(const std::vector operands); + + BNILVariable GetVariable(ExprId i, size_t varOperand); + + BNMediumLevelILInstruction operator[](size_t i) const; + size_t GetIndexForInstruction(size_t i) const; + size_t GetInstructionCount() const; + + void Finalize(); + + bool GetExprText(Architecture* arch, ExprId expr, std::vector& tokens); + bool GetInstructionText(Function* func, Architecture* arch, size_t i, + std::vector& tokens); + + std::vector> GetBasicBlocks() const; + + Ref GetSSAForm() const; + Ref GetNonSSAForm() const; + size_t GetSSAInstructionIndex(size_t instr) const; + size_t GetNonSSAInstructionIndex(size_t instr) const; + size_t GetSSAExprIndex(size_t instr) const; + size_t GetNonSSAExprIndex(size_t instr) const; + + size_t GetSSAVarDefinition(const BNILVariable& var, size_t idx) const; + size_t GetSSAMemoryDefinition(size_t idx) const; + std::set GetSSAVarUses(const BNILVariable& var, size_t idx) const; + std::set GetSSAMemoryUses(size_t idx) const; + + RegisterValue GetSSAVarValue(const BNILVariable& var, size_t idx); + RegisterValue GetExprValue(size_t expr); + }; + class FunctionRecognizer { static bool RecognizeLowLevelILCallback(void* ctxt, BNBinaryView* data, BNFunction* func, BNLowLevelILFunction* il); -- cgit v1.3.1