Skip to content

Commit

Permalink
Decompile to C
Browse files Browse the repository at this point in the history
  • Loading branch information
rose4096 authored and plafosse committed Jan 17, 2022
1 parent e621ce1 commit 9c7ed0c
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 1 deletion.
11 changes: 11 additions & 0 deletions binaryninjaapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -2314,6 +2314,7 @@ __attribute__ ((format (printf, 1, 2)))
class LowLevelILFunction;
class MediumLevelILFunction;
class HighLevelILFunction;
class LanguageRepresentationFunction;
class FunctionRecognizer;
class CallingConvention;
class RelocationHandler;
Expand Down Expand Up @@ -3506,6 +3507,7 @@ __attribute__ ((format (printf, 1, 2)))
Ref<MediumLevelILFunction> GetMediumLevelILIfAvailable() const;
Ref<HighLevelILFunction> GetHighLevelIL() const;
Ref<HighLevelILFunction> GetHighLevelILIfAvailable() const;
Ref<LanguageRepresentationFunction> GetLanguageRepresentation() const;

Ref<Type> GetType() const;
Confidence<Ref<Type>> GetReturnType() const;
Expand Down Expand Up @@ -4871,6 +4873,14 @@ __attribute__ ((format (printf, 1, 2)))
std::set<size_t> GetUsesForLabel(uint64_t label);
};

class LanguageRepresentationFunction: public CoreRefCountObject<BNLanguageRepresentationFunction,
BNNewLanguageRepresentationFunctionReference, BNFreeLanguageRepresentationFunction>
{
public:
LanguageRepresentationFunction(Architecture* arch, Function* func = nullptr);
LanguageRepresentationFunction(BNLanguageRepresentationFunction* func);
};

class FunctionRecognizer
{
static bool RecognizeLowLevelILCallback(void* ctxt, BNBinaryView* data, BNFunction* func, BNLowLevelILFunction* il);
Expand Down Expand Up @@ -6070,6 +6080,7 @@ __attribute__ ((format (printf, 1, 2)))
static Ref<LinearViewObject> CreateMappedMediumLevelILSSAForm(BinaryView* view, DisassemblySettings* settings);
static Ref<LinearViewObject> CreateHighLevelIL(BinaryView* view, DisassemblySettings* settings);
static Ref<LinearViewObject> CreateHighLevelILSSAForm(BinaryView* view, DisassemblySettings* settings);
static Ref<LinearViewObject> CreateLanguageRepresentation(BinaryView* view, DisassemblySettings* settings);
};

class LinearViewCursor: public CoreRefCountObject<BNLinearViewCursor,
Expand Down
13 changes: 12 additions & 1 deletion binaryninjacore.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ extern "C"
struct BNLowLevelILFunction;
struct BNMediumLevelILFunction;
struct BNHighLevelILFunction;
struct BNLanguageRepresentationFunction;
struct BNType;
struct BNTypeBuilder;
struct BNTypeLibrary;
Expand Down Expand Up @@ -587,7 +588,8 @@ extern "C"
MappedMediumLevelILFunctionGraph = 6,
MappedMediumLevelILSSAFormFunctionGraph = 7,
HighLevelILFunctionGraph = 8,
HighLevelILSSAFormFunctionGraph = 9
HighLevelILSSAFormFunctionGraph = 9,
HighLevelLanguageRepresentationFunctionGraph = 10,
};

enum BNDisassemblyOption
Expand Down Expand Up @@ -3469,6 +3471,7 @@ __attribute__ ((format (printf, 1, 2)))
BINARYNINJACOREAPI BNMediumLevelILFunction* BNGetFunctionMediumLevelILIfAvailable(BNFunction* func);
BINARYNINJACOREAPI BNHighLevelILFunction* BNGetFunctionHighLevelIL(BNFunction* func);
BINARYNINJACOREAPI BNHighLevelILFunction* BNGetFunctionHighLevelILIfAvailable(BNFunction* func);
BINARYNINJACOREAPI BNLanguageRepresentationFunction* BNGetFunctionLanguageRepresentation(BNFunction* func);
BINARYNINJACOREAPI BNRegisterValue BNGetRegisterValueAtInstruction(BNFunction* func, BNArchitecture* arch,
uint64_t addr, uint32_t reg);
BINARYNINJACOREAPI BNRegisterValue BNGetRegisterValueAfterInstruction(BNFunction* func, BNArchitecture* arch,
Expand Down Expand Up @@ -3832,6 +3835,8 @@ __attribute__ ((format (printf, 1, 2)))
BNDisassemblySettings* settings);
BINARYNINJACOREAPI BNLinearViewObject* BNCreateLinearViewHighLevelILSSAForm(BNBinaryView* view,
BNDisassemblySettings* settings);
BINARYNINJACOREAPI BNLinearViewObject* BNCreateLinearViewLanguageRepresentation(BNBinaryView* view,
BNDisassemblySettings* settings);
BINARYNINJACOREAPI BNLinearViewObject* BNNewLinearViewObjectReference(BNLinearViewObject* obj);
BINARYNINJACOREAPI void BNFreeLinearViewObject(BNLinearViewObject* obj);
BINARYNINJACOREAPI BNLinearViewObject* BNGetFirstLinearViewObjectChild(BNLinearViewObject* obj);
Expand Down Expand Up @@ -4713,6 +4718,12 @@ __attribute__ ((format (printf, 1, 2)))
BINARYNINJACOREAPI void BNBinaryViewExportTypeToTypeLibrary(BNBinaryView* view, BNTypeLibrary* lib, BNQualifiedName* name, BNType* type);
BINARYNINJACOREAPI void BNBinaryViewExportObjectToTypeLibrary(BNBinaryView* view, BNTypeLibrary* lib, BNQualifiedName* name, BNType* type);

// Language Representation
BINARYNINJACOREAPI BNLanguageRepresentationFunction* BNCreateLanguageRepresentationFunction(BNArchitecture* arch, BNFunction* func);
BINARYNINJACOREAPI BNLanguageRepresentationFunction* BNNewLanguageRepresentationFunctionReference(BNLanguageRepresentationFunction* func);
BINARYNINJACOREAPI void BNFreeLanguageRepresentationFunction(BNLanguageRepresentationFunction* func);
BINARYNINJACOREAPI BNFunction* BNGetLanguageRepresentationOwnerFunction(BNLanguageRepresentationFunction* func);

// Types
BINARYNINJACOREAPI bool BNTypesEqual(BNType* a, BNType* b);
BINARYNINJACOREAPI bool BNTypesNotEqual(BNType* a, BNType* b);
Expand Down
6 changes: 6 additions & 0 deletions function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,12 @@ Ref<HighLevelILFunction> Function::GetHighLevelILIfAvailable() const
}


Ref<LanguageRepresentationFunction> Function::GetLanguageRepresentation() const
{
return new LanguageRepresentationFunction(BNGetFunctionLanguageRepresentation(m_object));
}


Ref<Type> Function::GetType() const
{
return new Type(BNGetFunctionType(m_object));
Expand Down
15 changes: 15 additions & 0 deletions languagerepresentation.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
7 changes: 7 additions & 0 deletions linearviewobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,10 @@ Ref<LinearViewObject> LinearViewObject::CreateHighLevelILSSAForm(BinaryView* vie
return new LinearViewObject(BNCreateLinearViewHighLevelILSSAForm(view->GetObject(),
settings ? settings->GetObject() : nullptr));
}


Ref<LinearViewObject> LinearViewObject::CreateLanguageRepresentation(BinaryView* view, DisassemblySettings* settings)
{
return new LinearViewObject(BNCreateLinearViewLanguageRepresentation(view->GetObject(),
settings ? settings->GetObject() : nullptr));
}
6 changes: 6 additions & 0 deletions python/lineardisassembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,12 @@ def hlil_ssa_form(view:'binaryview.BinaryView', settings:Optional['_function.Dis
_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):
Expand Down

0 comments on commit 9c7ed0c

Please sign in to comment.