summaryrefslogtreecommitdiff
path: root/functiongraph.cpp
diff options
context:
space:
mode:
authorRusty Wagner <rusty@vector35.com>2015-02-20 03:12:19 -0500
committerRusty Wagner <rusty@vector35.com>2015-02-20 03:12:19 -0500
commitf2b794bf897a2e208407bf5f4a13f4f813531e68 (patch)
treed439622fedebdede54833c445251040a60ad30cb /functiongraph.cpp
parent584e4d244a9124f6ec403162994434ff085e9c5d (diff)
Initial code for generating function graphs
Diffstat (limited to 'functiongraph.cpp')
-rw-r--r--functiongraph.cpp117
1 files changed, 117 insertions, 0 deletions
diff --git a/functiongraph.cpp b/functiongraph.cpp
new file mode 100644
index 00000000..476c2fe2
--- /dev/null
+++ b/functiongraph.cpp
@@ -0,0 +1,117 @@
+#include "binaryninjaapi.h"
+
+using namespace BinaryNinja;
+using namespace std;
+
+
+FunctionGraph::FunctionGraph(BNFunctionGraph* graph): m_graph(graph)
+{
+}
+
+
+FunctionGraph::~FunctionGraph()
+{
+ BNFreeFunctionGraph(m_graph);
+}
+
+
+void FunctionGraph::CompleteCallback(void* ctxt)
+{
+ FunctionGraph* graph = (FunctionGraph*)ctxt;
+ graph->m_completeFunc();
+}
+
+
+Ref<Function> FunctionGraph::GetFunction() const
+{
+ return new Function(BNNewFunctionReference(BNGetFunctionForFunctionGraph(m_graph)));
+}
+
+
+int FunctionGraph::GetHorizontalBlockMargin() const
+{
+ return BNGetHorizontalFunctionGraphBlockMargin(m_graph);
+}
+
+
+int FunctionGraph::GetVerticalBlockMargin() const
+{
+ return BNGetVerticalFunctionGraphBlockMargin(m_graph);
+}
+
+
+void FunctionGraph::SetBlockMargins(int horiz, int vert)
+{
+ BNSetFunctionGraphBlockMargins(m_graph, horiz, vert);
+}
+
+
+void FunctionGraph::StartLayout()
+{
+ BNStartFunctionGraphLayout(m_graph);
+}
+
+
+bool FunctionGraph::IsLayoutComplete()
+{
+ return BNIsFunctionGraphLayoutComplete(m_graph);
+}
+
+
+void FunctionGraph::OnComplete(const std::function<void()>& func)
+{
+ m_completeFunc = func;
+ BNSetFunctionGraphCompleteCallback(m_graph, this, CompleteCallback);
+}
+
+
+vector<Ref<FunctionGraphBlock>> FunctionGraph::GetBlocks() const
+{
+ size_t count;
+ BNFunctionGraphBlock** blocks = BNGetFunctionGraphBlocks(m_graph, &count);
+
+ vector<Ref<FunctionGraphBlock>> result;
+ for (size_t i = 0; i < count; i++)
+ result.push_back(new FunctionGraphBlock(BNNewFunctionGraphBlockReference(blocks[i])));
+
+ BNFreeFunctionGraphBlockList(blocks, count);
+ return result;
+}
+
+
+int FunctionGraph::GetLeftExtent() const
+{
+ return BNGetFunctionGraphLeftExtent(m_graph);
+}
+
+
+int FunctionGraph::GetTopExtent() const
+{
+ return BNGetFunctionGraphTopExtent(m_graph);
+}
+
+
+int FunctionGraph::GetRightExtent() const
+{
+ return BNGetFunctionGraphRightExtent(m_graph);
+}
+
+
+int FunctionGraph::GetBottomExtent() const
+{
+ return BNGetFunctionGraphBottomExtent(m_graph);
+}
+
+
+vector<Ref<FunctionGraphBlock>> FunctionGraph::GetBlocksInRegion(int left, int top, int right, int bottom)
+{
+ size_t count;
+ BNFunctionGraphBlock** blocks = BNGetFunctionGraphBlocksInRegion(m_graph, left, top, right, bottom, &count);
+
+ vector<Ref<FunctionGraphBlock>> result;
+ for (size_t i = 0; i < count; i++)
+ result.push_back(new FunctionGraphBlock(BNNewFunctionGraphBlockReference(blocks[i])));
+
+ BNFreeFunctionGraphBlockList(blocks, count);
+ return result;
+}