summaryrefslogtreecommitdiff
path: root/binaryninjaapi.h
diff options
context:
space:
mode:
Diffstat (limited to 'binaryninjaapi.h')
-rw-r--r--binaryninjaapi.h170
1 files changed, 132 insertions, 38 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index a3db346a..b5c2867b 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -54,6 +54,7 @@ namespace BinaryNinja
virtual ~RefCountObject() {}
RefCountObject* GetObject() { return this; }
+ static RefCountObject* GetObject(RefCountObject* obj) { return obj; }
void AddRef()
{
@@ -107,6 +108,13 @@ namespace BinaryNinja
T* GetObject() const { return m_object; }
+ static T* GetObject(CoreRefCountObject* obj)
+ {
+ if (!obj)
+ return nullptr;
+ return obj->GetObject();
+ }
+
void AddRef()
{
if (m_object && (m_refs != 0))
@@ -164,6 +172,13 @@ namespace BinaryNinja
T* GetObject() const { return m_object; }
+ static T* GetObject(StaticCoreRefCountObject* obj)
+ {
+ if (!obj)
+ return nullptr;
+ return obj->GetObject();
+ }
+
void AddRef()
{
AddRefInternal();
@@ -252,32 +267,32 @@ namespace BinaryNinja
bool operator==(const T* obj) const
{
- return m_obj->GetObject() == obj->GetObject();
+ return T::GetObject(m_obj) == T::GetObject(obj);
}
bool operator==(const Ref<T>& obj) const
{
- return m_obj->GetObject() == obj.m_obj->GetObject();
+ return T::GetObject(m_obj) == T::GetObject(obj.m_obj);
}
bool operator!=(const T* obj) const
{
- return m_obj->GetObject() != obj->GetObject();
+ return T::GetObject(m_obj) != T::GetObject(obj);
}
bool operator!=(const Ref<T>& obj) const
{
- return m_obj->GetObject() != obj.m_obj->GetObject();
+ return T::GetObject(m_obj) != T::GetObject(obj.m_obj);
}
bool operator<(const T* obj) const
{
- return m_obj->GetObject() < obj->GetObject();
+ return T::GetObject(m_obj) < T::GetObject(obj);
}
bool operator<(const Ref<T>& obj) const
{
- return m_obj->GetObject() < obj.m_obj->GetObject();
+ return T::GetObject(m_obj) < T::GetObject(obj.m_obj);
}
T* GetPtr() const
@@ -494,6 +509,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 +644,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);
@@ -991,6 +1010,9 @@ namespace BinaryNinja
uint64_t addr;
size_t instrIndex;
std::vector<InstructionTextToken> tokens;
+ BNHighlightColor highlight;
+
+ DisassemblyTextLine();
};
struct LinearDisassemblyPosition
@@ -1336,6 +1358,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);
@@ -2354,7 +2377,7 @@ namespace BinaryNinja
static PossibleValueSet FromAPIObject(BNPossibleValueSet& value);
};
- class FunctionGraph;
+ class FlowGraph;
class MediumLevelILFunction;
class Function: public CoreRefCountObject<BNFunction, BNNewFunctionReference, BNFreeFunction>
@@ -2365,6 +2388,7 @@ namespace BinaryNinja
Function(BNFunction* func);
virtual ~Function();
+ Ref<BinaryView> GetView() const;
Ref<Architecture> GetArchitecture() const;
Ref<Platform> GetPlatform() const;
uint64_t GetStart() const;
@@ -2442,7 +2466,7 @@ namespace BinaryNinja
void ApplyImportedTypes(Symbol* sym);
void ApplyAutoDiscoveredType(Type* type);
- Ref<FunctionGraph> CreateFunctionGraph();
+ Ref<FlowGraph> CreateFunctionGraph(BNFunctionGraphType type, DisassemblySettings* settings = nullptr);
std::map<int64_t, std::vector<VariableNameAndType>> GetStackLayout();
void CreateAutoStackVariable(int64_t offset, const Confidence<Ref<Type>>& type, const std::string& name);
@@ -2481,6 +2505,7 @@ namespace BinaryNinja
Confidence<size_t> GetCallStackAdjustment(Architecture* arch, uint64_t addr);
std::map<uint32_t, Confidence<int32_t>> GetCallRegisterStackAdjustment(Architecture* arch, uint64_t addr);
Confidence<int32_t> GetCallRegisterStackAdjustment(Architecture* arch, uint64_t addr, uint32_t regStack);
+ bool IsCallInstruction(Architecture* arch, uint64_t addr);
std::vector<std::vector<InstructionTextToken>> GetBlockAnnotations(Architecture* arch, uint64_t addr);
@@ -2523,6 +2548,10 @@ namespace BinaryNinja
BNAnalysisSkipReason GetAnalysisSkipReason();
BNFunctionAnalysisSkipOverride GetAnalysisSkipOverride();
void SetAnalysisSkipOverride(BNFunctionAnalysisSkipOverride skip);
+
+ Ref<FlowGraph> GetUnresolvedStackAdjustmentGraph();
+
+ void RequestDebugReport(const std::string& name);
};
class AdvancedFunctionAnalysisDataRequestor
@@ -2539,79 +2568,118 @@ namespace BinaryNinja
void SetFunction(Function* func);
};
- struct FunctionGraphEdge
+ class FlowGraphNode;
+
+ struct FlowGraphEdge
{
BNBranchType type;
- Ref<BasicBlock> target;
+ Ref<FlowGraphNode> target;
std::vector<BNPoint> points;
bool backEdge;
};
- class FunctionGraphBlock: public CoreRefCountObject<BNFunctionGraphBlock,
- BNNewFunctionGraphBlockReference, BNFreeFunctionGraphBlock>
+ class FlowGraphNode: public CoreRefCountObject<BNFlowGraphNode,
+ BNNewFlowGraphNodeReference, BNFreeFlowGraphNode>
{
std::vector<DisassemblyTextLine> m_cachedLines;
- std::vector<FunctionGraphEdge> m_cachedEdges;
+ std::vector<FlowGraphEdge> m_cachedEdges;
bool m_cachedLinesValid, m_cachedEdgesValid;
public:
- FunctionGraphBlock(BNFunctionGraphBlock* block);
+ FlowGraphNode(FlowGraph* graph);
+ FlowGraphNode(BNFlowGraphNode* node);
Ref<BasicBlock> GetBasicBlock() const;
- Ref<Architecture> 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<DisassemblyTextLine>& GetLines();
- const std::vector<FunctionGraphEdge>& GetOutgoingEdges();
+ void SetLines(const std::vector<DisassemblyTextLine>& lines);
+ const std::vector<FlowGraphEdge>& GetOutgoingEdges();
+ void AddOutgoingEdge(BNBranchType type, FlowGraphNode* target);
+
+ BNHighlightColor GetHighlight() const;
+ void SetHighlight(const BNHighlightColor& color);
};
- class FunctionGraph: public RefCountObject
+ class FlowGraphLayoutRequest: public RefCountObject
{
- BNFunctionGraph* m_graph;
+ BNFlowGraphLayoutRequest* m_object;
std::function<void()> m_completeFunc;
- std::map<BNFunctionGraphBlock*, Ref<FunctionGraphBlock>> m_cachedBlocks;
static void CompleteCallback(void* ctxt);
public:
- FunctionGraph(BNFunctionGraph* graph);
- ~FunctionGraph();
+ FlowGraphLayoutRequest(FlowGraph* graph, const std::function<void()>& completeFunc);
+ virtual ~FlowGraphLayoutRequest();
- BNFunctionGraph* GetGraphObject() const { return m_graph; }
+ BNFlowGraphLayoutRequest* GetObject() const { return m_object; }
- Ref<Function> GetFunction() const;
+ Ref<FlowGraph> GetGraph() const;
+ bool IsComplete() const;
+ void Abort();
+ };
+
+ class FlowGraph: public CoreRefCountObject<BNFlowGraph, BNNewFlowGraphReference, BNFreeFlowGraph>
+ {
+ std::map<BNFlowGraphNode*, Ref<FlowGraphNode>> m_cachedNodes;
+
+ static void PrepareForLayoutCallback(void* ctxt);
+ static void PopulateNodesCallback(void* ctxt);
+ static void CompleteLayoutCallback(void* ctxt);
+ static BNFlowGraph* UpdateCallback(void* ctxt);
+
+ protected:
+ FlowGraph(BNFlowGraph* graph);
+
+ void FinishPrepareForLayout();
+ virtual void PrepareForLayout();
+ virtual void PopulateNodes();
+ virtual void CompleteLayout();
+
+ public:
+ FlowGraph();
- int GetHorizontalBlockMargin() const;
- int GetVerticalBlockMargin() const;
- void SetBlockMargins(int horiz, int vert);
+ Ref<Function> GetFunction() const;
+ void SetFunction(Function* func);
- Ref<DisassemblySettings> GetSettings();
+ int GetHorizontalNodeMargin() const;
+ int GetVerticalNodeMargin() const;
+ void SetNodeMargins(int horiz, int vert);
- void StartLayout(BNFunctionGraphType = NormalFunctionGraph);
+ Ref<FlowGraphLayoutRequest> StartLayout(const std::function<void()>& func);
bool IsLayoutComplete();
- void OnComplete(const std::function<void()>& func);
- void Abort();
- std::vector<Ref<FunctionGraphBlock>> GetBlocks();
- bool HasBlocks() const;
+ std::vector<Ref<FlowGraphNode>> GetNodes();
+ Ref<FlowGraphNode> GetNode(size_t i);
+ bool HasNodes() const;
+ size_t AddNode(FlowGraphNode* node);
int GetWidth() const;
int GetHeight() const;
- std::vector<Ref<FunctionGraphBlock>> GetBlocksInRegion(int left, int top, int right, int bottom);
-
- bool IsOptionSet(BNDisassemblyOption option) const;
- void SetOption(BNDisassemblyOption option, bool state = true);
+ std::vector<Ref<FlowGraphNode>> GetNodesInRegion(int left, int top, int right, int bottom);
bool IsILGraph() const;
bool IsLowLevelILGraph() const;
bool IsMediumLevelILGraph() const;
Ref<LowLevelILFunction> GetLowLevelILFunction() const;
Ref<MediumLevelILFunction> GetMediumLevelILFunction() const;
+ void SetLowLevelILFunction(LowLevelILFunction* func);
+ void SetMediumLevelILFunction(MediumLevelILFunction* func);
+
+ void Show(const std::string& title);
+
+ virtual Ref<FlowGraph> Update();
+ };
+
+ class CoreFlowGraph: public FlowGraph
+ {
+ public:
+ CoreFlowGraph(BNFlowGraph* graph);
+ virtual Ref<FlowGraph> Update() override;
};
struct LowLevelILLabel: public BNLowLevelILLabel
@@ -3125,6 +3193,7 @@ namespace BinaryNinja
ExprId Jump(ExprId dest, const ILSourceLocation& loc = ILSourceLocation());
ExprId JumpTo(ExprId dest, const std::vector<BNMediumLevelILLabel*>& targets,
const ILSourceLocation& loc = ILSourceLocation());
+ ExprId ReturnHint(ExprId dest, const ILSourceLocation& loc = ILSourceLocation());
ExprId Call(const std::vector<Variable>& output, ExprId dest, const std::vector<ExprId>& params,
const ILSourceLocation& loc = ILSourceLocation());
ExprId CallUntyped(const std::vector<Variable>& output, ExprId dest, const std::vector<Variable>& params,
@@ -3883,6 +3952,29 @@ namespace BinaryNinja
static FormInputField DirectoryName(const std::string& prompt, const std::string& defaultName = "");
};
+ class ReportCollection: public CoreRefCountObject<BNReportCollection,
+ BNNewReportCollectionReference, BNFreeReportCollection>
+ {
+ public:
+ ReportCollection();
+ ReportCollection(BNReportCollection* reports);
+
+ size_t GetCount() const;
+ BNReportType GetType(size_t i) const;
+ Ref<BinaryView> 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<FlowGraph> GetFlowGraph(size_t i) const;
+
+ void AddPlainTextReport(Ref<BinaryView> view, const std::string& title, const std::string& contents);
+ void AddMarkdownReport(Ref<BinaryView> view, const std::string& title, const std::string& contents,
+ const std::string& plainText = "");
+ void AddHTMLReport(Ref<BinaryView> view, const std::string& title, const std::string& contents,
+ const std::string& plainText = "");
+ void AddGraphReport(Ref<BinaryView> view, const std::string& title, Ref<FlowGraph> graph);
+ };
+
class InteractionHandler
{
public:
@@ -3891,6 +3983,8 @@ namespace BinaryNinja
const std::string& plainText);
virtual void ShowHTMLReport(Ref<BinaryView> view, const std::string& title, const std::string& contents,
const std::string& plainText);
+ virtual void ShowGraphReport(Ref<BinaryView> view, const std::string& title, Ref<FlowGraph> graph);
+ virtual void ShowReportCollection(const std::string& title, Ref<ReportCollection> 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);