From bfa6fce83383e7be1458a917f8e6dbf71bdab28b Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Mon, 4 Jun 2018 14:12:26 -0400 Subject: Generic flow graph API and report collections --- binaryninjaapi.h | 104 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 74 insertions(+), 30 deletions(-) (limited to 'binaryninjaapi.h') diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 05c8c4e3..3582b265 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -494,6 +494,8 @@ namespace BinaryNinja class MainThreadActionHandler; class InteractionHandler; class QualifiedName; + class FlowGraph; + class ReportCollection; struct FormInputField; /*! Logs to the error console with the given BNLogLevel. @@ -627,6 +629,8 @@ namespace BinaryNinja const std::string& plainText = ""); void ShowHTMLReport(const std::string& title, const std::string& contents, const std::string& plainText = ""); + void ShowGraphReport(const std::string& title, FlowGraph* graph); + void ShowReportCollection(const std::string& title, ReportCollection* reports); bool GetTextLineInput(std::string& result, const std::string& prompt, const std::string& title); bool GetIntegerInput(int64_t& result, const std::string& prompt, const std::string& title); @@ -988,6 +992,9 @@ namespace BinaryNinja uint64_t addr; size_t instrIndex; std::vector tokens; + BNHighlightColor highlight; + + DisassemblyTextLine(); }; struct LinearDisassemblyPosition @@ -1313,6 +1320,7 @@ namespace BinaryNinja void ShowPlainTextReport(const std::string& title, const std::string& contents); void ShowMarkdownReport(const std::string& title, const std::string& contents, const std::string& plainText); void ShowHTMLReport(const std::string& title, const std::string& contents, const std::string& plainText); + void ShowGraphReport(const std::string& title, FlowGraph* graph); bool GetAddressInput(uint64_t& result, const std::string& prompt, const std::string& title); bool GetAddressInput(uint64_t& result, const std::string& prompt, const std::string& title, uint64_t currentAddress); @@ -2327,7 +2335,7 @@ namespace BinaryNinja static PossibleValueSet FromAPIObject(BNPossibleValueSet& value); }; - class FunctionGraph; + class FlowGraph; class MediumLevelILFunction; class Function: public CoreRefCountObject @@ -2338,6 +2346,7 @@ namespace BinaryNinja Function(BNFunction* func); virtual ~Function(); + Ref GetView() const; Ref GetArchitecture() const; Ref GetPlatform() const; uint64_t GetStart() const; @@ -2415,7 +2424,7 @@ namespace BinaryNinja void ApplyImportedTypes(Symbol* sym); void ApplyAutoDiscoveredType(Type* type); - Ref CreateFunctionGraph(); + Ref CreateFunctionGraph(BNFunctionGraphType type, DisassemblySettings* settings = nullptr); std::map> GetStackLayout(); void CreateAutoStackVariable(int64_t offset, const Confidence>& type, const std::string& name); @@ -2495,6 +2504,8 @@ namespace BinaryNinja bool IsAnalysisSkipped(); BNFunctionAnalysisSkipOverride GetAnalysisSkipOverride(); void SetAnalysisSkipOverride(BNFunctionAnalysisSkipOverride skip); + + Ref GetUnresolvedStackAdjustmentGraph(); }; class AdvancedFunctionAnalysisDataRequestor @@ -2511,79 +2522,87 @@ namespace BinaryNinja void SetFunction(Function* func); }; - struct FunctionGraphEdge + class FlowGraphNode; + + struct FlowGraphEdge { BNBranchType type; - Ref target; + Ref target; std::vector points; bool backEdge; }; - class FunctionGraphBlock: public CoreRefCountObject + class FlowGraphNode: public CoreRefCountObject { std::vector m_cachedLines; - std::vector m_cachedEdges; + std::vector m_cachedEdges; bool m_cachedLinesValid, m_cachedEdgesValid; public: - FunctionGraphBlock(BNFunctionGraphBlock* block); + FlowGraphNode(FlowGraph* graph); + FlowGraphNode(BNFlowGraphNode* node); Ref GetBasicBlock() const; - Ref GetArchitecture() const; - uint64_t GetStart() const; - uint64_t GetEnd() const; + void SetBasicBlock(BasicBlock* block); int GetX() const; int GetY() const; int GetWidth() const; int GetHeight() const; const std::vector& GetLines(); - const std::vector& GetOutgoingEdges(); + void SetLines(const std::vector& lines); + const std::vector& GetOutgoingEdges(); + void AddOutgoingEdge(BNBranchType type, FlowGraphNode* target); + + BNHighlightColor GetHighlight() const; + void SetHighlight(const BNHighlightColor& color); }; - class FunctionGraph: public RefCountObject + class FlowGraph: public RefCountObject { - BNFunctionGraph* m_graph; + BNFlowGraph* m_graph; std::function m_completeFunc; - std::map> m_cachedBlocks; + std::map> m_cachedNodes; static void CompleteCallback(void* ctxt); public: - FunctionGraph(BNFunctionGraph* graph); - ~FunctionGraph(); + FlowGraph(BNFlowGraph* graph); + ~FlowGraph(); - BNFunctionGraph* GetGraphObject() const { return m_graph; } + BNFlowGraph* GetGraphObject() const { return m_graph; } Ref GetFunction() const; + void SetFunction(Function* func); - int GetHorizontalBlockMargin() const; - int GetVerticalBlockMargin() const; - void SetBlockMargins(int horiz, int vert); - - Ref GetSettings(); + int GetHorizontalNodeMargin() const; + int GetVerticalNodeMargin() const; + void SetNodeMargins(int horiz, int vert); - void StartLayout(BNFunctionGraphType = NormalFunctionGraph); + void StartLayout(); bool IsLayoutComplete(); void OnComplete(const std::function& func); void Abort(); - std::vector> GetBlocks(); - bool HasBlocks() const; + std::vector> GetNodes(); + Ref GetNode(size_t i); + bool HasNodes() const; + size_t AddNode(FlowGraphNode* node); int GetWidth() const; int GetHeight() const; - std::vector> GetBlocksInRegion(int left, int top, int right, int bottom); - - bool IsOptionSet(BNDisassemblyOption option) const; - void SetOption(BNDisassemblyOption option, bool state = true); + std::vector> GetNodesInRegion(int left, int top, int right, int bottom); bool IsILGraph() const; bool IsLowLevelILGraph() const; bool IsMediumLevelILGraph() const; Ref GetLowLevelILFunction() const; Ref GetMediumLevelILFunction() const; + void SetLowLevelILFunction(LowLevelILFunction* func); + void SetMediumLevelILFunction(MediumLevelILFunction* func); + + void Show(const std::string& title); }; struct LowLevelILLabel: public BNLowLevelILLabel @@ -3776,6 +3795,29 @@ namespace BinaryNinja static FormInputField DirectoryName(const std::string& prompt, const std::string& defaultName = ""); }; + class ReportCollection: public CoreRefCountObject + { + public: + ReportCollection(); + ReportCollection(BNReportCollection* reports); + + size_t GetCount() const; + BNReportType GetType(size_t i) const; + Ref GetView(size_t i) const; + std::string GetTitle(size_t i) const; + std::string GetContents(size_t i) const; + std::string GetPlainText(size_t i) const; + Ref GetFlowGraph(size_t i) const; + + void AddPlainTextReport(Ref view, const std::string& title, const std::string& contents); + void AddMarkdownReport(Ref view, const std::string& title, const std::string& contents, + const std::string& plainText = ""); + void AddHTMLReport(Ref view, const std::string& title, const std::string& contents, + const std::string& plainText = ""); + void AddGraphReport(Ref view, const std::string& title, Ref graph); + }; + class InteractionHandler { public: @@ -3784,6 +3826,8 @@ namespace BinaryNinja const std::string& plainText); virtual void ShowHTMLReport(Ref view, const std::string& title, const std::string& contents, const std::string& plainText); + virtual void ShowGraphReport(Ref view, const std::string& title, Ref graph); + virtual void ShowReportCollection(const std::string& title, Ref reports); virtual bool GetTextLineInput(std::string& result, const std::string& prompt, const std::string& title) = 0; virtual bool GetIntegerInput(int64_t& result, const std::string& prompt, const std::string& title); -- cgit v1.3.1