summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Potchik <brian@vector35.com>2017-12-04 13:12:06 -0500
committerBrian Potchik <brian@vector35.com>2017-12-04 13:12:06 -0500
commit448ffe2842b2b1e0d21f905403489d3f865672d8 (patch)
tree42033a41bef73de159ed5566445ac9db2521d6c8
parent7dee9c4f68147bd88d1c60577912c3a91c510331 (diff)
Add MediumLevelIL Function Recognizer.
-rw-r--r--binaryninjaapi.h2
-rw-r--r--binaryninjacore.h1
-rw-r--r--functionrecognizer.cpp18
-rw-r--r--python/functionrecognizer.py15
4 files changed, 36 insertions, 0 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index e4ef4c43..baeb5de6 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -2951,6 +2951,7 @@ namespace BinaryNinja
class FunctionRecognizer
{
static bool RecognizeLowLevelILCallback(void* ctxt, BNBinaryView* data, BNFunction* func, BNLowLevelILFunction* il);
+ static bool RecognizeMediumLevelILCallback(void* ctxt, BNBinaryView* data, BNFunction* func, BNMediumLevelILFunction* il);
public:
FunctionRecognizer();
@@ -2959,6 +2960,7 @@ namespace BinaryNinja
static void RegisterArchitectureFunctionRecognizer(Architecture* arch, FunctionRecognizer* recog);
virtual bool RecognizeLowLevelIL(BinaryView* data, Function* func, LowLevelILFunction* il);
+ virtual bool RecognizeMediumLevelIL(BinaryView* data, Function* func, MediumLevelILFunction* il);
};
class UpdateException: public std::exception
diff --git a/binaryninjacore.h b/binaryninjacore.h
index 82198efd..7a0e585e 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -1191,6 +1191,7 @@ extern "C"
{
void* context;
bool (*recognizeLowLevelIL)(void* ctxt, BNBinaryView* data, BNFunction* func, BNLowLevelILFunction* il);
+ bool (*recognizeMediumLevelIL)(void* ctxt, BNBinaryView* data, BNFunction* func, BNMediumLevelILFunction* il);
};
struct BNTypeParserResult
diff --git a/functionrecognizer.cpp b/functionrecognizer.cpp
index 32c7245c..34f1db80 100644
--- a/functionrecognizer.cpp
+++ b/functionrecognizer.cpp
@@ -38,11 +38,22 @@ bool FunctionRecognizer::RecognizeLowLevelILCallback(void* ctxt, BNBinaryView* d
}
+bool FunctionRecognizer::RecognizeMediumLevelILCallback(void* ctxt, BNBinaryView* data, BNFunction* func, BNMediumLevelILFunction* il)
+{
+ FunctionRecognizer* recog = (FunctionRecognizer*)ctxt;
+ Ref<BinaryView> dataObj = new BinaryView(BNNewViewReference(data));
+ Ref<Function> funcObj = new Function(BNNewFunctionReference(func));
+ Ref<MediumLevelILFunction> ilObj = new MediumLevelILFunction(BNNewMediumLevelILFunctionReference(il));
+ return recog->RecognizeMediumLevelIL(dataObj, funcObj, ilObj);
+}
+
+
void FunctionRecognizer::RegisterGlobalRecognizer(FunctionRecognizer* recog)
{
BNFunctionRecognizer reg;
reg.context = recog;
reg.recognizeLowLevelIL = RecognizeLowLevelILCallback;
+ reg.recognizeMediumLevelIL = RecognizeMediumLevelILCallback;
BNRegisterGlobalFunctionRecognizer(&reg);
}
@@ -52,6 +63,7 @@ void FunctionRecognizer::RegisterArchitectureFunctionRecognizer(Architecture* ar
BNFunctionRecognizer reg;
reg.context = recog;
reg.recognizeLowLevelIL = RecognizeLowLevelILCallback;
+ reg.recognizeMediumLevelIL = RecognizeMediumLevelILCallback;
BNRegisterArchitectureFunctionRecognizer(arch->GetObject(), &reg);
}
@@ -60,3 +72,9 @@ bool FunctionRecognizer::RecognizeLowLevelIL(BinaryView*, Function*, LowLevelILF
{
return false;
}
+
+
+bool FunctionRecognizer::RecognizeMediumLevelIL(BinaryView*, Function*, MediumLevelILFunction*)
+{
+ return false;
+}
diff --git a/python/functionrecognizer.py b/python/functionrecognizer.py
index 8514a2ee..4ac304ca 100644
--- a/python/functionrecognizer.py
+++ b/python/functionrecognizer.py
@@ -36,6 +36,7 @@ class FunctionRecognizer(object):
self._cb = core.BNFunctionRecognizer()
self._cb.context = 0
self._cb.recognizeLowLevelIL = self._cb.recognizeLowLevelIL.__class__(self._recognize_low_level_il)
+ self._cb.recognizeMediumLevelIL = self._cb.recognizeMediumLevelIL.__class__(self._recognize_medium_level_il)
@classmethod
def register_global(cls):
@@ -62,3 +63,17 @@ class FunctionRecognizer(object):
def recognize_low_level_il(self, data, func, il):
return False
+
+ def _recognize_medium_level_il(self, ctxt, data, func, il):
+ try:
+ file_metadata = filemetadata.FileMetadata(handle = core.BNGetFileForView(data))
+ view = binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(data))
+ func = function.Function(view, handle = core.BNNewFunctionReference(func))
+ il = mediumlevelil.MediumLevelILFunction(func.arch, handle = core.BNNewMediumLevelILFunctionReference(il))
+ return self.recognize_medium_level_il(view, func, il)
+ except:
+ log.log_error(traceback.format_exc())
+ return False
+
+ def recognize_medium_level_il(self, data, func, il):
+ return False