From 9c7ed0cc4ebe08871a7b83e0f56a542c0f31f835 Mon Sep 17 00:00:00 2001 From: rose <47357290+rompse@users.noreply.github.com> Date: Tue, 9 Nov 2021 20:09:44 -0500 Subject: Decompile to C --- binaryninjaapi.h | 11 +++++++++++ binaryninjacore.h | 13 ++++++++++++- function.cpp | 6 ++++++ languagerepresentation.cpp | 15 +++++++++++++++ linearviewobject.cpp | 7 +++++++ python/lineardisassembly.py | 6 ++++++ 6 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 languagerepresentation.cpp diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 77b949b6..2203c803 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -2314,6 +2314,7 @@ __attribute__ ((format (printf, 1, 2))) class LowLevelILFunction; class MediumLevelILFunction; class HighLevelILFunction; + class LanguageRepresentationFunction; class FunctionRecognizer; class CallingConvention; class RelocationHandler; @@ -3506,6 +3507,7 @@ __attribute__ ((format (printf, 1, 2))) Ref GetMediumLevelILIfAvailable() const; Ref GetHighLevelIL() const; Ref GetHighLevelILIfAvailable() const; + Ref GetLanguageRepresentation() const; Ref GetType() const; Confidence> GetReturnType() const; @@ -4871,6 +4873,14 @@ __attribute__ ((format (printf, 1, 2))) std::set GetUsesForLabel(uint64_t label); }; + class LanguageRepresentationFunction: public CoreRefCountObject + { + public: + LanguageRepresentationFunction(Architecture* arch, Function* func = nullptr); + LanguageRepresentationFunction(BNLanguageRepresentationFunction* func); + }; + class FunctionRecognizer { static bool RecognizeLowLevelILCallback(void* ctxt, BNBinaryView* data, BNFunction* func, BNLowLevelILFunction* il); @@ -6070,6 +6080,7 @@ __attribute__ ((format (printf, 1, 2))) static Ref CreateMappedMediumLevelILSSAForm(BinaryView* view, DisassemblySettings* settings); static Ref CreateHighLevelIL(BinaryView* view, DisassemblySettings* settings); static Ref CreateHighLevelILSSAForm(BinaryView* view, DisassemblySettings* settings); + static Ref CreateLanguageRepresentation(BinaryView* view, DisassemblySettings* settings); }; class LinearViewCursor: public CoreRefCountObject Function::GetHighLevelILIfAvailable() const } +Ref Function::GetLanguageRepresentation() const +{ + return new LanguageRepresentationFunction(BNGetFunctionLanguageRepresentation(m_object)); +} + + Ref Function::GetType() const { return new Type(BNGetFunctionType(m_object)); diff --git a/languagerepresentation.cpp b/languagerepresentation.cpp new file mode 100644 index 00000000..62f592e8 --- /dev/null +++ b/languagerepresentation.cpp @@ -0,0 +1,15 @@ +#include "binaryninjaapi.h" + +using namespace BinaryNinja; +using namespace std; + +LanguageRepresentationFunction::LanguageRepresentationFunction(Architecture* arch, Function* func) +{ + m_object = BNCreateLanguageRepresentationFunction(arch->GetObject(), func ? func->GetObject() : nullptr); +} + + +LanguageRepresentationFunction::LanguageRepresentationFunction(BNLanguageRepresentationFunction* func) +{ + m_object = func; +} \ No newline at end of file diff --git a/linearviewobject.cpp b/linearviewobject.cpp index cbfebe29..17229836 100644 --- a/linearviewobject.cpp +++ b/linearviewobject.cpp @@ -276,3 +276,10 @@ Ref LinearViewObject::CreateHighLevelILSSAForm(BinaryView* vie return new LinearViewObject(BNCreateLinearViewHighLevelILSSAForm(view->GetObject(), settings ? settings->GetObject() : nullptr)); } + + +Ref LinearViewObject::CreateLanguageRepresentation(BinaryView* view, DisassemblySettings* settings) +{ + return new LinearViewObject(BNCreateLinearViewLanguageRepresentation(view->GetObject(), + settings ? settings->GetObject() : nullptr)); +} diff --git a/python/lineardisassembly.py b/python/lineardisassembly.py index 42b7e333..c295841e 100644 --- a/python/lineardisassembly.py +++ b/python/lineardisassembly.py @@ -341,6 +341,12 @@ class LinearViewObject: _settings = _settings.handle return LinearViewObject(core.BNCreateLinearViewHighLevelILSSAForm(view.handle, _settings)) + @staticmethod + def language_representation(view:'binaryview.BinaryView', settings:Optional['_function.DisassemblySettings'] = None) -> 'LinearViewObject': + _settings = settings + if _settings is not None: + _settings = _settings.handle + return LinearViewObject(core.BNCreateLinearViewLanguageRepresentation(view.handle, _settings)) class LinearViewCursor: def __init__(self, root_object, handle = None): -- cgit v1.3.1