summaryrefslogtreecommitdiff
path: root/binaryninjaapi.h
diff options
context:
space:
mode:
authorRusty Wagner <rusty@vector35.com>2018-09-05 14:39:46 -0400
committerRusty Wagner <rusty@vector35.com>2018-09-05 14:39:46 -0400
commitf4d75c9229d2d76f36f80e97dd49c7aece242600 (patch)
tree0390fc2b624149274c5c01b847d59698055a2974 /binaryninjaapi.h
parentc02c863367ff88c1e562a1110e069bf2842798aa (diff)
parente51031010b107089dd7b5b69039ac42b856a0769 (diff)
Merge branch 'test_stack_adjust' into dev
Diffstat (limited to 'binaryninjaapi.h')
-rw-r--r--binaryninjaapi.h192
1 files changed, 145 insertions, 47 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index a3db346a..901ea65d 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);
@@ -2088,7 +2111,7 @@ namespace BinaryNinja
void SetConst(const Confidence<bool>& cnst);
void SetVolatile(const Confidence<bool>& vltl);
void SetTypeName(const QualifiedName& name);
- Confidence<size_t> GetStackAdjustment() const;
+ Confidence<int64_t> GetStackAdjustment() const;
uint64_t GetElementCount() const;
uint64_t GetOffset() const;
@@ -2129,7 +2152,7 @@ namespace BinaryNinja
static Ref<Type> FunctionType(const Confidence<Ref<Type>>& returnValue,
const Confidence<Ref<CallingConvention>>& callingConvention,
const std::vector<FunctionParameter>& params, const Confidence<bool>& varArg = Confidence<bool>(false, 0),
- const Confidence<size_t>& stackAdjust = Confidence<size_t>(0, 0));
+ const Confidence<int64_t>& stackAdjust = Confidence<int64_t>(0, 0));
static std::string GenerateAutoTypeId(const std::string& source, const QualifiedName& name);
static std::string GenerateAutoDemangledTypeId(const QualifiedName& name);
@@ -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;
@@ -2413,7 +2437,7 @@ namespace BinaryNinja
Confidence<Ref<CallingConvention>> GetCallingConvention() const;
Confidence<std::vector<Variable>> GetParameterVariables() const;
Confidence<bool> HasVariableArguments() const;
- Confidence<size_t> GetStackAdjustment() const;
+ Confidence<int64_t> GetStackAdjustment() const;
std::map<uint32_t, Confidence<int32_t>> GetRegisterStackAdjustments() const;
Confidence<std::set<uint32_t>> GetClobberedRegisters() const;
@@ -2424,7 +2448,7 @@ namespace BinaryNinja
void SetAutoParameterVariables(const Confidence<std::vector<Variable>>& vars);
void SetAutoHasVariableArguments(const Confidence<bool>& varArgs);
void SetAutoCanReturn(const Confidence<bool>& returns);
- void SetAutoStackAdjustment(const Confidence<size_t>& stackAdjust);
+ void SetAutoStackAdjustment(const Confidence<int64_t>& stackAdjust);
void SetAutoRegisterStackAdjustments(const std::map<uint32_t, Confidence<int32_t>>& regStackAdjust);
void SetAutoClobberedRegisters(const Confidence<std::set<uint32_t>>& clobbered);
@@ -2435,14 +2459,14 @@ namespace BinaryNinja
void SetParameterVariables(const Confidence<std::vector<Variable>>& vars);
void SetHasVariableArguments(const Confidence<bool>& varArgs);
void SetCanReturn(const Confidence<bool>& returns);
- void SetStackAdjustment(const Confidence<size_t>& stackAdjust);
+ void SetStackAdjustment(const Confidence<int64_t>& stackAdjust);
void SetRegisterStackAdjustments(const std::map<uint32_t, Confidence<int32_t>>& regStackAdjust);
void SetClobberedRegisters(const Confidence<std::set<uint32_t>>& clobbered);
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);
@@ -2467,20 +2491,21 @@ namespace BinaryNinja
std::vector<IndirectBranchInfo> GetIndirectBranches();
std::vector<IndirectBranchInfo> GetIndirectBranchesAt(Architecture* arch, uint64_t addr);
- void SetAutoCallStackAdjustment(Architecture* arch, uint64_t addr, const Confidence<size_t>& adjust);
+ void SetAutoCallStackAdjustment(Architecture* arch, uint64_t addr, const Confidence<int64_t>& adjust);
void SetAutoCallRegisterStackAdjustment(Architecture* arch, uint64_t addr,
const std::map<uint32_t, Confidence<int32_t>>& adjust);
void SetAutoCallRegisterStackAdjustment(Architecture* arch, uint64_t addr, uint32_t regStack,
const Confidence<int32_t>& adjust);
- void SetUserCallStackAdjustment(Architecture* arch, uint64_t addr, const Confidence<size_t>& adjust);
+ void SetUserCallStackAdjustment(Architecture* arch, uint64_t addr, const Confidence<int64_t>& adjust);
void SetUserCallRegisterStackAdjustment(Architecture* arch, uint64_t addr,
const std::map<uint32_t, Confidence<int32_t>>& adjust);
void SetUserCallRegisterStackAdjustment(Architecture* arch, uint64_t addr, uint32_t regStack,
const Confidence<int32_t>& adjust);
- Confidence<size_t> GetCallStackAdjustment(Architecture* arch, uint64_t addr);
+ Confidence<int64_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);
- int GetHorizontalBlockMargin() const;
- int GetVerticalBlockMargin() const;
- void SetBlockMargins(int horiz, int vert);
+ void FinishPrepareForLayout();
+ virtual void PrepareForLayout();
+ virtual void PopulateNodes();
+ virtual void CompleteLayout();
- Ref<DisassemblySettings> GetSettings();
+ public:
+ FlowGraph();
+
+ Ref<Function> GetFunction() const;
+ void SetFunction(Function* func);
+
+ 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
@@ -2807,7 +2875,7 @@ namespace BinaryNinja
ExprId JumpTo(ExprId dest, const std::vector<BNLowLevelILLabel*>& targets,
const ILSourceLocation& loc = ILSourceLocation());
ExprId Call(ExprId dest, const ILSourceLocation& loc = ILSourceLocation());
- ExprId CallStackAdjust(ExprId dest, size_t adjust, const std::map<uint32_t, int32_t>& regStackAdjust,
+ ExprId CallStackAdjust(ExprId dest, int64_t adjust, const std::map<uint32_t, int32_t>& regStackAdjust,
const ILSourceLocation& loc = ILSourceLocation());
ExprId TailCall(ExprId dest, const ILSourceLocation& loc = ILSourceLocation());
ExprId CallSSA(const std::vector<SSARegister>& output, ExprId dest, const std::vector<ExprId>& params,
@@ -2983,6 +3051,8 @@ namespace BinaryNinja
size_t GetMediumLevelILExprIndex(size_t expr) const;
size_t GetMappedMediumLevelILInstructionIndex(size_t instr) const;
size_t GetMappedMediumLevelILExprIndex(size_t expr) const;
+
+ Ref<FlowGraph> CreateFunctionGraph(DisassemblySettings* settings = nullptr);
};
struct MediumLevelILLabel: public BNMediumLevelILLabel
@@ -3125,6 +3195,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,
@@ -3313,6 +3384,8 @@ namespace BinaryNinja
Confidence<Ref<Type>> GetExprType(size_t expr);
Confidence<Ref<Type>> GetExprType(const MediumLevelILInstruction& expr);
+
+ Ref<FlowGraph> CreateFunctionGraph(DisassemblySettings* settings = nullptr);
};
class FunctionRecognizer
@@ -3883,6 +3956,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 +3987,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);