From f2b794bf897a2e208407bf5f4a13f4f813531e68 Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Fri, 20 Feb 2015 03:12:19 -0500 Subject: Initial code for generating function graphs --- functiongraphblock.cpp | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 functiongraphblock.cpp (limited to 'functiongraphblock.cpp') diff --git a/functiongraphblock.cpp b/functiongraphblock.cpp new file mode 100644 index 00000000..8afdef60 --- /dev/null +++ b/functiongraphblock.cpp @@ -0,0 +1,78 @@ +#include "binaryninjaapi.h" + +using namespace BinaryNinja; +using namespace std; + + +FunctionGraphBlock::FunctionGraphBlock(BNFunctionGraphBlock* block): m_block(block) +{ +} + + +FunctionGraphBlock::~FunctionGraphBlock() +{ + BNFreeFunctionGraphBlock(m_block); +} + + +int FunctionGraphBlock::GetX() const +{ + return BNGetFunctionGraphBlockX(m_block); +} + + +int FunctionGraphBlock::GetY() const +{ + return BNGetFunctionGraphBlockY(m_block); +} + + +int FunctionGraphBlock::GetWidth() const +{ + return BNGetFunctionGraphBlockWidth(m_block); +} + + +int FunctionGraphBlock::GetHeight() const +{ + return BNGetFunctionGraphBlockHeight(m_block); +} + + +vector FunctionGraphBlock::GetLines() const +{ + size_t count; + BNFunctionGraphTextLine* lines = BNGetFunctionGraphBlockLines(m_block, &count); + + vector result; + for (size_t i = 0; i < count; i++) + { + FunctionGraphTextLine line; + line.addr = lines[i].addr; + for (size_t j = 0; j < lines[i].count; j++) + { + InstructionTextToken token; + token.type = lines[i].tokens[j].type; + token.text = lines[i].tokens[j].text; + token.value = lines[i].tokens[j].value; + line.tokens.push_back(token); + } + result.push_back(line); + } + + BNFreeFunctionGraphBlockLines(lines, count); + return result; +} + + +vector FunctionGraphBlock::GetOutgoingEdges() const +{ + size_t count; + BNBasicBlockEdge* edges = BNGetFunctionGraphBlockOutgoingEdges(m_block, &count); + + vector result; + result.insert(result.begin(), &edges[0], &edges[count]); + + BNFreeFunctionGraphBlockOutgoingEdgeList(edges); + return result; +} -- cgit v1.3.1