diff options
| -rw-r--r-- | architecture.cpp | 9 | ||||
| -rw-r--r-- | basicblock.cpp | 12 | ||||
| -rw-r--r-- | binaryninjaapi.h | 25 | ||||
| -rw-r--r-- | binaryviewtype.cpp | 10 | ||||
| -rw-r--r-- | 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<Ref<Architecture>> Architecture::GetList() vector<Ref<Architecture>> 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<BNBasicBlockEdge> BasicBlock::GetOutgoingEdges() const +vector<BasicBlockEdge> BasicBlock::GetOutgoingEdges() const { size_t count; BNBasicBlockEdge* array = BNGetBasicBlockOutgoingEdges(m_block, &count); - vector<BNBasicBlockEdge> result; + vector<BasicBlockEdge> 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<BinaryViewType> 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<Architecture> arch; + }; + class BasicBlock: public RefCountObject { BNBasicBlock* m_block; @@ -679,7 +686,7 @@ namespace BinaryNinja uint64_t GetEnd() const; uint64_t GetLength() const; - std::vector<BNBasicBlockEdge> GetOutgoingEdges() const; + std::vector<BasicBlockEdge> GetOutgoingEdges() const; }; class FunctionGraph; @@ -693,7 +700,7 @@ namespace BinaryNinja ~Function(); BNFunction* GetFunctionObject() const { return m_func; } - + Ref<Architecture> GetArchitecture() const; uint64_t GetStart() const; @@ -708,6 +715,14 @@ namespace BinaryNinja std::vector<InstructionTextToken> tokens; }; + struct FunctionGraphEdge + { + BNBranchType type; + uint64_t target; + Ref<Architecture> arch; + std::vector<BNPoint> points; + }; + class FunctionGraphBlock: public RefCountObject { BNFunctionGraphBlock* m_block; @@ -724,7 +739,7 @@ namespace BinaryNinja int GetHeight() const; std::vector<FunctionGraphTextLine> GetLines() const; - std::vector<BNBasicBlockEdge> GetOutgoingEdges() const; + std::vector<FunctionGraphEdge> 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<Ref<BinaryViewType>> BinaryViewType::GetViewTypesForData(BinaryView* data vector<Ref<BinaryViewType>> 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<FunctionGraphTextLine> FunctionGraphBlock::GetLines() const } -vector<BNBasicBlockEdge> FunctionGraphBlock::GetOutgoingEdges() const +vector<FunctionGraphEdge> FunctionGraphBlock::GetOutgoingEdges() const { size_t count; - BNBasicBlockEdge* edges = BNGetFunctionGraphBlockOutgoingEdges(m_block, &count); + BNFunctionGraphEdge* edges = BNGetFunctionGraphBlockOutgoingEdges(m_block, &count); - vector<BNBasicBlockEdge> result; - result.insert(result.begin(), &edges[0], &edges[count]); + vector<FunctionGraphEdge> 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; } |
