summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRusty Wagner <rusty@vector35.com>2018-09-04 20:15:18 -0400
committerRusty Wagner <rusty@vector35.com>2018-09-04 20:15:18 -0400
commite51031010b107089dd7b5b69039ac42b856a0769 (patch)
tree02e4e9deb3453ce7c0372c00db3bdb98c83e6667
parentd13dba15dab0484fa237bf741948582afb517253 (diff)
Add API to create graphs of IL functions
-rw-r--r--binaryninjaapi.h4
-rw-r--r--binaryninjacore.h4
-rw-r--r--lowlevelil.cpp7
-rw-r--r--mediumlevelil.cpp7
-rw-r--r--python/lowlevelil.py13
-rw-r--r--python/mediumlevelil.py14
6 files changed, 43 insertions, 6 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index 722edcd3..901ea65d 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -3051,6 +3051,8 @@ namespace BinaryNinja
size_t GetMediumLevelILExprIndex(size_t expr) const;
size_t GetMappedMediumLevelILInstructionIndex(size_t instr) const;
size_t GetMappedMediumLevelILExprIndex(size_t expr) const;
+
+ Ref<FlowGraph> CreateFunctionGraph(DisassemblySettings* settings = nullptr);
};
struct MediumLevelILLabel: public BNMediumLevelILLabel
@@ -3382,6 +3384,8 @@ namespace BinaryNinja
Confidence<Ref<Type>> GetExprType(size_t expr);
Confidence<Ref<Type>> GetExprType(const MediumLevelILInstruction& expr);
+
+ Ref<FlowGraph> CreateFunctionGraph(DisassemblySettings* settings = nullptr);
};
class FunctionRecognizer
diff --git a/binaryninjacore.h b/binaryninjacore.h
index b15ceabd..0916112f 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -2663,6 +2663,10 @@ extern "C"
BINARYNINJACOREAPI BNFlowGraph* BNCreateFlowGraph();
BINARYNINJACOREAPI BNFlowGraph* BNCreateFunctionGraph(BNFunction* func, BNFunctionGraphType type,
BNDisassemblySettings* settings);
+ BINARYNINJACOREAPI BNFlowGraph* BNCreateLowLevelILFunctionGraph(BNLowLevelILFunction* func,
+ BNDisassemblySettings* settings);
+ BINARYNINJACOREAPI BNFlowGraph* BNCreateMediumLevelILFunctionGraph(BNMediumLevelILFunction* func,
+ BNDisassemblySettings* settings);
BINARYNINJACOREAPI BNFlowGraph* BNCreateCustomFlowGraph(BNCustomFlowGraph* callbacks);
BINARYNINJACOREAPI BNFlowGraph* BNNewFlowGraphReference(BNFlowGraph* graph);
BINARYNINJACOREAPI void BNFreeFlowGraph(BNFlowGraph* graph);
diff --git a/lowlevelil.cpp b/lowlevelil.cpp
index 40748327..3e09e085 100644
--- a/lowlevelil.cpp
+++ b/lowlevelil.cpp
@@ -766,3 +766,10 @@ size_t LowLevelILFunction::GetMappedMediumLevelILExprIndex(size_t expr) const
{
return BNGetMappedMediumLevelILExprIndex(m_object, expr);
}
+
+
+Ref<FlowGraph> LowLevelILFunction::CreateFunctionGraph(DisassemblySettings* settings)
+{
+ BNFlowGraph* graph = BNCreateLowLevelILFunctionGraph(m_object, settings ? settings->GetObject() : nullptr);
+ return new CoreFlowGraph(graph);
+}
diff --git a/mediumlevelil.cpp b/mediumlevelil.cpp
index cac45dd6..2d1fe904 100644
--- a/mediumlevelil.cpp
+++ b/mediumlevelil.cpp
@@ -738,3 +738,10 @@ Confidence<Ref<Type>> MediumLevelILFunction::GetExprType(const MediumLevelILInst
{
return GetExprType(expr.exprIndex);
}
+
+
+Ref<FlowGraph> MediumLevelILFunction::CreateFunctionGraph(DisassemblySettings* settings)
+{
+ BNFlowGraph* graph = BNCreateMediumLevelILFunctionGraph(m_object, settings ? settings->GetObject() : nullptr);
+ return new CoreFlowGraph(graph);
+}
diff --git a/python/lowlevelil.py b/python/lowlevelil.py
index ec7c37fd..b2a28d6e 100644
--- a/python/lowlevelil.py
+++ b/python/lowlevelil.py
@@ -734,9 +734,9 @@ class LowLevelILFunction(object):
if handle is not None:
self.handle = core.handle_of_type(handle, core.BNLowLevelILFunction)
else:
- func_handle = None
- if self.source_function is not None:
- func_handle = self.source_function.handle
+ if self.source_function is None:
+ raise ValueError("IL functions must be created with an associated function")
+ func_handle = self.source_function.handle
self.handle = core.BNCreateLowLevelILFunction(arch.handle, func_handle)
def __del__(self):
@@ -2354,6 +2354,13 @@ class LowLevelILFunction(object):
return None
return result
+ def create_graph(self, settings = None):
+ if settings is not None:
+ settings_obj = settings.handle
+ else:
+ settings_obj = None
+ return binaryninja.flowgraph.CoreFlowGraph(core.BNCreateLowLevelILFunctionGraph(self.handle, settings_obj))
+
class LowLevelILBasicBlock(basicblock.BasicBlock):
def __init__(self, view, handle, owner):
diff --git a/python/mediumlevelil.py b/python/mediumlevelil.py
index d8347ebf..a862adca 100644
--- a/python/mediumlevelil.py
+++ b/python/mediumlevelil.py
@@ -22,6 +22,7 @@ import ctypes
import struct
# Binary Ninja components
+import binaryninja
from binaryninja import _binaryninjacore as core
from binaryninja.enums import MediumLevelILOperation, InstructionTextTokenType, ILBranchDependence
from binaryninja import basicblock #required for MediumLevelILBasicBlock argument
@@ -616,9 +617,9 @@ class MediumLevelILFunction(object):
if handle is not None:
self.handle = core.handle_of_type(handle, core.BNMediumLevelILFunction)
else:
- func_handle = None
- if self.source_function is not None:
- func_handle = self.source_function.handle
+ if self.source_function is None:
+ raise ValueError("IL functions must be created with an associated function")
+ func_handle = self.source_function.handle
self.handle = core.BNCreateMediumLevelILFunction(arch.handle, func_handle)
def __del__(self):
@@ -939,6 +940,13 @@ class MediumLevelILFunction(object):
return None
return result
+ def create_graph(self, settings = None):
+ if settings is not None:
+ settings_obj = settings.handle
+ else:
+ settings_obj = None
+ return binaryninja.flowgraph.CoreFlowGraph(core.BNCreateMediumLevelILFunctionGraph(self.handle, settings_obj))
+
class MediumLevelILBasicBlock(basicblock.BasicBlock):
def __init__(self, view, handle, owner):