diff options
| author | Rusty Wagner <rusty@vector35.com> | 2020-04-14 21:25:41 -0400 |
|---|---|---|
| committer | Rusty Wagner <rusty@vector35.com> | 2020-04-17 14:20:35 -0400 |
| commit | 072c5cd6eee7af9671e6c4fe583e77bc3bcbdd1d (patch) | |
| tree | 52e8b1018c7588dc540a687c8219ad2803de13af | |
| parent | 1385e2dbd9be1db21114d95b7c4767773e2b0692 (diff) | |
Add IL support to linear view
| -rw-r--r-- | binaryninjaapi.h | 10 | ||||
| -rw-r--r-- | binaryninjacore.h | 17 | ||||
| -rw-r--r-- | function.cpp | 18 | ||||
| -rw-r--r-- | linearviewobject.cpp | 49 | ||||
| -rw-r--r-- | python/function.py | 15 | ||||
| -rw-r--r-- | python/lineardisassembly.py | 42 | ||||
| -rw-r--r-- | ui/linearview.h | 9 |
7 files changed, 159 insertions, 1 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 9d85f616..c91b13c4 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -2962,6 +2962,7 @@ __attribute__ ((format (printf, 1, 2))) void RemoveUserCodeReference(Architecture* fromArch, uint64_t fromAddr, uint64_t toAddr); Ref<LowLevelILFunction> GetLowLevelIL() const; + Ref<LowLevelILFunction> GetLowLevelILIfAvailable() const; size_t GetLowLevelILForInstruction(Architecture* arch, uint64_t addr); std::vector<size_t> GetLowLevelILExitsForInstruction(Architecture* arch, uint64_t addr); RegisterValue GetRegisterValueAtInstruction(Architecture* arch, uint64_t addr, uint32_t reg); @@ -2976,6 +2977,7 @@ __attribute__ ((format (printf, 1, 2))) std::vector<BNConstantReference> GetConstantsReferencedByInstruction(Architecture* arch, uint64_t addr); Ref<LowLevelILFunction> GetLiftedIL() const; + Ref<LowLevelILFunction> GetLiftedILIfAvailable() const; size_t GetLiftedILForInstruction(Architecture* arch, uint64_t addr); std::set<size_t> GetLiftedILFlagUsesForDefinition(size_t i, uint32_t flag); std::set<size_t> GetLiftedILFlagDefinitionsForUse(size_t i, uint32_t flag); @@ -2983,6 +2985,7 @@ __attribute__ ((format (printf, 1, 2))) std::set<uint32_t> GetFlagsWrittenByLiftedILInstruction(size_t i); Ref<MediumLevelILFunction> GetMediumLevelIL() const; + Ref<MediumLevelILFunction> GetMediumLevelILIfAvailable() const; Ref<Type> GetType() const; Confidence<Ref<Type>> GetReturnType() const; @@ -4990,6 +4993,13 @@ __attribute__ ((format (printf, 1, 2))) Ref<LinearViewObject> GetChildForOrderingIndex(uint64_t idx); static Ref<LinearViewObject> CreateDisassembly(BinaryView* view, DisassemblySettings* settings); + static Ref<LinearViewObject> CreateLiftedIL(BinaryView* view, DisassemblySettings* settings); + static Ref<LinearViewObject> CreateLowLevelIL(BinaryView* view, DisassemblySettings* settings); + static Ref<LinearViewObject> CreateLowLevelILSSAForm(BinaryView* view, DisassemblySettings* settings); + static Ref<LinearViewObject> CreateMediumLevelIL(BinaryView* view, DisassemblySettings* settings); + static Ref<LinearViewObject> CreateMediumLevelILSSAForm(BinaryView* view, DisassemblySettings* settings); + static Ref<LinearViewObject> CreateMappedMediumLevelIL(BinaryView* view, DisassemblySettings* settings); + static Ref<LinearViewObject> CreateMappedMediumLevelILSSAForm(BinaryView* view, DisassemblySettings* settings); }; class LinearViewCursor: public CoreRefCountObject<BNLinearViewCursor, diff --git a/binaryninjacore.h b/binaryninjacore.h index 49c9e3d5..941540f0 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -2691,11 +2691,13 @@ __attribute__ ((format (printf, 1, 2))) BINARYNINJACOREAPI BNBasicBlock** BNGetBasicBlocksStartingAtAddress(BNBinaryView* view, uint64_t addr, size_t* count); BINARYNINJACOREAPI BNLowLevelILFunction* BNGetFunctionLowLevelIL(BNFunction* func); + BINARYNINJACOREAPI BNLowLevelILFunction* BNGetFunctionLowLevelILIfAvailable(BNFunction* func); BINARYNINJACOREAPI size_t BNGetLowLevelILForInstruction(BNFunction* func, BNArchitecture* arch, uint64_t addr); BINARYNINJACOREAPI size_t* BNGetLowLevelILExitsForInstruction(BNFunction* func, BNArchitecture* arch, uint64_t addr, size_t* count); BINARYNINJACOREAPI void BNFreeILInstructionList(size_t* list); BINARYNINJACOREAPI BNMediumLevelILFunction* BNGetFunctionMediumLevelIL(BNFunction* func); + BINARYNINJACOREAPI BNMediumLevelILFunction* BNGetFunctionMediumLevelILIfAvailable(BNFunction* func); BINARYNINJACOREAPI BNRegisterValue BNGetRegisterValueAtInstruction(BNFunction* func, BNArchitecture* arch, uint64_t addr, uint32_t reg); BINARYNINJACOREAPI BNRegisterValue BNGetRegisterValueAfterInstruction(BNFunction* func, BNArchitecture* arch, @@ -2721,6 +2723,7 @@ __attribute__ ((format (printf, 1, 2))) BINARYNINJACOREAPI void BNFreeConstantReferenceList(BNConstantReference* refs); BINARYNINJACOREAPI BNLowLevelILFunction* BNGetFunctionLiftedIL(BNFunction* func); + BINARYNINJACOREAPI BNLowLevelILFunction* BNGetFunctionLiftedILIfAvailable(BNFunction* func); BINARYNINJACOREAPI size_t BNGetLiftedILForInstruction(BNFunction* func, BNArchitecture* arch, uint64_t addr); BINARYNINJACOREAPI size_t* BNGetLiftedILFlagUsesForDefinition(BNFunction* func, size_t i, uint32_t flag, size_t* count); BINARYNINJACOREAPI size_t* BNGetLiftedILFlagDefinitionsForUse(BNFunction* func, size_t i, uint32_t flag, size_t* count); @@ -2973,6 +2976,20 @@ __attribute__ ((format (printf, 1, 2))) BINARYNINJACOREAPI BNLinearViewObject* BNCreateLinearViewDisassembly(BNBinaryView* view, BNDisassemblySettings* settings); + BINARYNINJACOREAPI BNLinearViewObject* BNCreateLinearViewLiftedIL(BNBinaryView* view, + BNDisassemblySettings* settings); + BINARYNINJACOREAPI BNLinearViewObject* BNCreateLinearViewLowLevelIL(BNBinaryView* view, + BNDisassemblySettings* settings); + BINARYNINJACOREAPI BNLinearViewObject* BNCreateLinearViewLowLevelILSSAForm(BNBinaryView* view, + BNDisassemblySettings* settings); + BINARYNINJACOREAPI BNLinearViewObject* BNCreateLinearViewMediumLevelIL(BNBinaryView* view, + BNDisassemblySettings* settings); + BINARYNINJACOREAPI BNLinearViewObject* BNCreateLinearViewMediumLevelILSSAForm(BNBinaryView* view, + BNDisassemblySettings* settings); + BINARYNINJACOREAPI BNLinearViewObject* BNCreateLinearViewMappedMediumLevelIL(BNBinaryView* view, + BNDisassemblySettings* settings); + BINARYNINJACOREAPI BNLinearViewObject* BNCreateLinearViewMappedMediumLevelILSSAForm(BNBinaryView* view, + BNDisassemblySettings* settings); BINARYNINJACOREAPI BNLinearViewObject* BNNewLinearViewObjectReference(BNLinearViewObject* obj); BINARYNINJACOREAPI void BNFreeLinearViewObject(BNLinearViewObject* obj); BINARYNINJACOREAPI BNLinearViewObject* BNGetFirstLinearViewObjectChild(BNLinearViewObject* obj); diff --git a/function.cpp b/function.cpp index c218a78e..0cffb6bc 100644 --- a/function.cpp +++ b/function.cpp @@ -293,6 +293,12 @@ Ref<LowLevelILFunction> Function::GetLowLevelIL() const } +Ref<LowLevelILFunction> Function::GetLowLevelILIfAvailable() const +{ + return new LowLevelILFunction(BNGetFunctionLowLevelILIfAvailable(m_object)); +} + + size_t Function::GetLowLevelILForInstruction(Architecture* arch, uint64_t addr) { return BNGetLowLevelILForInstruction(m_object, arch->GetObject(), addr); @@ -467,6 +473,12 @@ Ref<LowLevelILFunction> Function::GetLiftedIL() const } +Ref<LowLevelILFunction> Function::GetLiftedILIfAvailable() const +{ + return new LowLevelILFunction(BNGetFunctionLiftedILIfAvailable(m_object)); +} + + size_t Function::GetLiftedILForInstruction(Architecture* arch, uint64_t addr) { return BNGetLiftedILForInstruction(m_object, arch->GetObject(), addr); @@ -527,6 +539,12 @@ Ref<MediumLevelILFunction> Function::GetMediumLevelIL() const } +Ref<MediumLevelILFunction> Function::GetMediumLevelILIfAvailable() const +{ + return new MediumLevelILFunction(BNGetFunctionMediumLevelILIfAvailable(m_object)); +} + + Ref<Type> Function::GetType() const { return new Type(BNGetFunctionType(m_object)); diff --git a/linearviewobject.cpp b/linearviewobject.cpp index 3cd8f360..19c7e4b3 100644 --- a/linearviewobject.cpp +++ b/linearviewobject.cpp @@ -204,3 +204,52 @@ Ref<LinearViewObject> LinearViewObject::CreateDisassembly(BinaryView* view, Disa return new LinearViewObject(BNCreateLinearViewDisassembly(view->GetObject(), settings ? settings->GetObject() : nullptr)); } + + +Ref<LinearViewObject> LinearViewObject::CreateLiftedIL(BinaryView* view, DisassemblySettings* settings) +{ + return new LinearViewObject(BNCreateLinearViewLiftedIL(view->GetObject(), + settings ? settings->GetObject() : nullptr)); +} + + +Ref<LinearViewObject> LinearViewObject::CreateLowLevelIL(BinaryView* view, DisassemblySettings* settings) +{ + return new LinearViewObject(BNCreateLinearViewLowLevelIL(view->GetObject(), + settings ? settings->GetObject() : nullptr)); +} + + +Ref<LinearViewObject> LinearViewObject::CreateLowLevelILSSAForm(BinaryView* view, DisassemblySettings* settings) +{ + return new LinearViewObject(BNCreateLinearViewLowLevelILSSAForm(view->GetObject(), + settings ? settings->GetObject() : nullptr)); +} + + +Ref<LinearViewObject> LinearViewObject::CreateMediumLevelIL(BinaryView* view, DisassemblySettings* settings) +{ + return new LinearViewObject(BNCreateLinearViewMediumLevelIL(view->GetObject(), + settings ? settings->GetObject() : nullptr)); +} + + +Ref<LinearViewObject> LinearViewObject::CreateMediumLevelILSSAForm(BinaryView* view, DisassemblySettings* settings) +{ + return new LinearViewObject(BNCreateLinearViewMediumLevelILSSAForm(view->GetObject(), + settings ? settings->GetObject() : nullptr)); +} + + +Ref<LinearViewObject> LinearViewObject::CreateMappedMediumLevelIL(BinaryView* view, DisassemblySettings* settings) +{ + return new LinearViewObject(BNCreateLinearViewMappedMediumLevelIL(view->GetObject(), + settings ? settings->GetObject() : nullptr)); +} + + +Ref<LinearViewObject> LinearViewObject::CreateMappedMediumLevelILSSAForm(BinaryView* view, DisassemblySettings* settings) +{ + return new LinearViewObject(BNCreateLinearViewMappedMediumLevelILSSAForm(view->GetObject(), + settings ? settings->GetObject() : nullptr)); +} diff --git a/python/function.py b/python/function.py index bdd04590..7cee467c 100644 --- a/python/function.py +++ b/python/function.py @@ -1215,11 +1215,21 @@ class Function(object): return binaryninja.lowlevelil.LowLevelILFunction(self.arch, core.BNGetFunctionLowLevelIL(self.handle), self) @property + def llil_if_available(self): + """returns LowLevelILFunction used to represent Function low level IL, or None if not loaded (read-only)""" + return binaryninja.lowlevelil.LowLevelILFunction(self.arch, core.BNGetFunctionLowLevelILIfAvailable(self.handle), self) + + @property def lifted_il(self): """returns LowLevelILFunction used to represent lifted IL (read-only)""" return binaryninja.lowlevelil.LowLevelILFunction(self.arch, core.BNGetFunctionLiftedIL(self.handle), self) @property + def lifted_il_if_available(self): + """returns LowLevelILFunction used to represent lifted IL, or None if not loaded (read-only)""" + return binaryninja.lowlevelil.LowLevelILFunction(self.arch, core.BNGetFunctionLiftedILIfAvailable(self.handle), self) + + @property def medium_level_il(self): """Deprecated property provided for compatibility. Use mlil instead.""" return binaryninja.mediumlevelil.MediumLevelILFunction(self.arch, core.BNGetFunctionMediumLevelIL(self.handle), self) @@ -1230,6 +1240,11 @@ class Function(object): return binaryninja.mediumlevelil.MediumLevelILFunction(self.arch, core.BNGetFunctionMediumLevelIL(self.handle), self) @property + def mlil_if_available(self): + """Function medium level IL, or None if not loaded (read-only)""" + return binaryninja.mediumlevelil.MediumLevelILFunction(self.arch, core.BNGetFunctionMediumLevelILIfAvailable(self.handle), self) + + @property def function_type(self): """Function type object, can be set with either a string representing the function prototype (`str(function)` shows examples) or a :py:class:`Type` object""" return types.Type(core.BNGetFunctionType(self.handle), platform = self.platform) diff --git a/python/lineardisassembly.py b/python/lineardisassembly.py index a23c829f..ec213a19 100644 --- a/python/lineardisassembly.py +++ b/python/lineardisassembly.py @@ -258,6 +258,48 @@ class LinearViewObject(object): settings = settings.handle return LinearViewObject(core.BNCreateLinearViewDisassembly(view.handle, settings)) + @classmethod + def lifted_il(cls, view, settings = None): + if settings is not None: + settings = settings.handle + return LinearViewObject(core.BNCreateLinearViewLiftedIL(view.handle, settings)) + + @classmethod + def llil(cls, view, settings = None): + if settings is not None: + settings = settings.handle + return LinearViewObject(core.BNCreateLinearViewLowLevelIL(view.handle, settings)) + + @classmethod + def llil_ssa_form(cls, view, settings = None): + if settings is not None: + settings = settings.handle + return LinearViewObject(core.BNCreateLinearViewLowLevelILSSAForm(view.handle, settings)) + + @classmethod + def mlil(cls, view, settings = None): + if settings is not None: + settings = settings.handle + return LinearViewObject(core.BNCreateLinearViewMediumLevelIL(view.handle, settings)) + + @classmethod + def mlil_ssa_form(cls, view, settings = None): + if settings is not None: + settings = settings.handle + return LinearViewObject(core.BNCreateLinearViewMediumLevelILSSAForm(view.handle, settings)) + + @classmethod + def mmlil(cls, view, settings = None): + if settings is not None: + settings = settings.handle + return LinearViewObject(core.BNCreateLinearViewMappedMediumLevelIL(view.handle, settings)) + + @classmethod + def mmlil_ssa_form(cls, view, settings = None): + if settings is not None: + settings = settings.handle + return LinearViewObject(core.BNCreateLinearViewMappedMediumLevelILSSAForm(view.handle, settings)) + class LinearViewCursor(object): def __init__(self, root_object, handle = None): diff --git a/ui/linearview.h b/ui/linearview.h index b4928785..0c76fe83 100644 --- a/ui/linearview.h +++ b/ui/linearview.h @@ -117,7 +117,9 @@ class BINARYNINJAUIAPI LinearView: public QAbstractScrollArea, public View, publ uint64_t m_navByRefTarget; bool m_navByRef = false; - DisassemblySettingsRef m_settings; + SettingsRef m_settings; + DisassemblySettingsRef m_options; + BNFunctionGraphType m_type; BinaryNinja::Ref<BinaryNinja::LinearViewCursor> m_topPosition, m_bottomPosition; std::vector<LinearViewLine> m_lines; @@ -128,6 +130,8 @@ class BINARYNINJAUIAPI LinearView: public QAbstractScrollArea, public View, publ ContextMenuManager m_contextMenuManager; QPointer<CommentDialog> m_commentDialog; + std::map<FunctionRef, BinaryNinja::AdvancedFunctionAnalysisDataRequestor> m_analysisRequestors; + void adjustSize(int width, int height); void setTopToAddress(uint64_t addr); @@ -171,6 +175,8 @@ class BINARYNINJAUIAPI LinearView: public QAbstractScrollArea, public View, publ BinaryNinja::LinearViewCursor* newCursor); uint64_t getOrderingIndexForLine(const LinearViewLine& line); + void updateAnalysisRequestorsForCache(); + private Q_SLOTS: void viewInHexEditor(); void viewInGraph(); @@ -280,6 +286,7 @@ public: virtual HighlightTokenState getHighlightTokenState() override { return m_highlight; } void toggleOption(BNDisassemblyOption option); + void setViewType(BNFunctionGraphType type); virtual bool goToReference(FunctionRef func, uint64_t source, uint64_t target) override; QFont getFont() override { return m_render.getFont(); } |
