From 5d0f774334c1bea3935001bf665d614c39a60d0f Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Wed, 4 Mar 2015 01:47:13 -0500 Subject: Add architecture to graph edges, and add edge routing data field for layout --- architecture.cpp | 9 +++++---- basicblock.cpp | 12 +++++++++--- binaryninjaapi.h | 25 ++++++++++++++++++++----- binaryviewtype.cpp | 10 ++-------- functiongraphblock.cpp | 18 +++++++++++++----- 5 files changed, 49 insertions(+), 25 deletions(-) diff --git a/architecture.cpp b/architecture.cpp index 576a14e3..f5ef6cc6 100644 --- a/architecture.cpp +++ b/architecture.cpp @@ -11,12 +11,13 @@ InstructionInfo::InstructionInfo() } -void InstructionInfo::AddBranch(BNBranchType type, uint64_t target) +void InstructionInfo::AddBranch(BNBranchType type, uint64_t target, Architecture* arch) { if (branchCount >= BN_MAX_INSTRUCTION_BRANCHES) return; branchType[branchCount] = type; - branchTarget[branchCount++] = target; + branchTarget[branchCount] = target; + branchArch[branchCount++] = arch ? arch->GetArchitectureObject() : nullptr; } @@ -116,9 +117,9 @@ vector> Architecture::GetList() vector> result; for (size_t i = 0; i < count; i++) - result.push_back(new CoreArchitecture(BNNewArchitectureReference(archs[i]))); + result.push_back(new CoreArchitecture(archs[i])); - BNFreeArchitectureList(archs, count); + BNFreeArchitectureList(archs); return result; } diff --git a/basicblock.cpp b/basicblock.cpp index 6f308307..a1becd10 100644 --- a/basicblock.cpp +++ b/basicblock.cpp @@ -45,14 +45,20 @@ uint64_t BasicBlock::GetLength() const } -vector BasicBlock::GetOutgoingEdges() const +vector BasicBlock::GetOutgoingEdges() const { size_t count; BNBasicBlockEdge* array = BNGetBasicBlockOutgoingEdges(m_block, &count); - vector result; + vector result; for (size_t i = 0; i < count; i++) - result.push_back(array[i]); + { + BasicBlockEdge edge; + edge.type = array[i].type; + edge.target = array[i].target; + edge.arch = array[i].arch ? new CoreArchitecture(array[i].arch) : nullptr; + result.push_back(edge); + } BNFreeBasicBlockOutgoingEdgeList(array); return result; diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 2b0d53ad..63e8f1a5 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -424,7 +424,7 @@ namespace BinaryNinja public: BinaryViewType(const std::string& name, const std::string& longName); - virtual ~BinaryViewType(); + virtual ~BinaryViewType() {} static void Register(BinaryViewType* type); static Ref GetByName(const std::string& name); @@ -613,7 +613,7 @@ namespace BinaryNinja struct InstructionInfo: public BNInstructionInfo { InstructionInfo(); - void AddBranch(BNBranchType type, uint64_t target = 0); + void AddBranch(BNBranchType type, uint64_t target = 0, Architecture* arch = nullptr); }; struct InstructionTextToken @@ -664,6 +664,13 @@ namespace BinaryNinja class Function; + struct BasicBlockEdge + { + BNBranchType type; + uint64_t target; + Ref arch; + }; + class BasicBlock: public RefCountObject { BNBasicBlock* m_block; @@ -679,7 +686,7 @@ namespace BinaryNinja uint64_t GetEnd() const; uint64_t GetLength() const; - std::vector GetOutgoingEdges() const; + std::vector GetOutgoingEdges() const; }; class FunctionGraph; @@ -693,7 +700,7 @@ namespace BinaryNinja ~Function(); BNFunction* GetFunctionObject() const { return m_func; } - + Ref GetArchitecture() const; uint64_t GetStart() const; @@ -708,6 +715,14 @@ namespace BinaryNinja std::vector tokens; }; + struct FunctionGraphEdge + { + BNBranchType type; + uint64_t target; + Ref arch; + std::vector points; + }; + class FunctionGraphBlock: public RefCountObject { BNFunctionGraphBlock* m_block; @@ -724,7 +739,7 @@ namespace BinaryNinja int GetHeight() const; std::vector GetLines() const; - std::vector GetOutgoingEdges() const; + std::vector GetOutgoingEdges() const; }; class FunctionGraph: public RefCountObject diff --git a/binaryviewtype.cpp b/binaryviewtype.cpp index 5d74de2b..0bd17e5f 100644 --- a/binaryviewtype.cpp +++ b/binaryviewtype.cpp @@ -32,12 +32,6 @@ BinaryViewType::BinaryViewType(const string& name, const string& longName): } -BinaryViewType::~BinaryViewType() -{ - BNFreeBinaryViewType(m_type); -} - - void BinaryViewType::Register(BinaryViewType* type) { BNCustomBinaryViewType callbacks; @@ -67,9 +61,9 @@ vector> BinaryViewType::GetViewTypesForData(BinaryView* data vector> result; for (size_t i = 0; i < count; i++) - result.push_back(new CoreBinaryViewType(BNNewViewTypeReference(types[i]))); + result.push_back(new CoreBinaryViewType(types[i])); - BNFreeBinaryViewTypeList(types, count); + BNFreeBinaryViewTypeList(types); return result; } diff --git a/functiongraphblock.cpp b/functiongraphblock.cpp index 8afdef60..3914cc18 100644 --- a/functiongraphblock.cpp +++ b/functiongraphblock.cpp @@ -65,14 +65,22 @@ vector FunctionGraphBlock::GetLines() const } -vector FunctionGraphBlock::GetOutgoingEdges() const +vector FunctionGraphBlock::GetOutgoingEdges() const { size_t count; - BNBasicBlockEdge* edges = BNGetFunctionGraphBlockOutgoingEdges(m_block, &count); + BNFunctionGraphEdge* edges = BNGetFunctionGraphBlockOutgoingEdges(m_block, &count); - vector result; - result.insert(result.begin(), &edges[0], &edges[count]); + vector result; + for (size_t i = 0; i < count; i++) + { + FunctionGraphEdge edge; + edge.type = edges[i].type; + edge.target = edges[i].target; + edge.arch = edges[i].arch ? new CoreArchitecture(edges[i].arch) : nullptr; + edge.points.insert(edge.points.begin(), &edges[i].points[0], &edges[i].points[edges[i].pointCount]); + result.push_back(edge); + } - BNFreeFunctionGraphBlockOutgoingEdgeList(edges); + BNFreeFunctionGraphBlockOutgoingEdgeList(edges, count); return result; } -- cgit v1.3.1