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 --- function.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'function.cpp') diff --git a/function.cpp b/function.cpp index 835ab144..62a8e1b0 100644 --- a/function.cpp +++ b/function.cpp @@ -119,6 +119,12 @@ Function::~Function() } +Ref Function::GetView() const +{ + return new BinaryView(BNGetFunctionData(m_object)); +} + + Ref Function::GetPlatform() const { return new Platform(BNGetFunctionPlatform(m_object)); @@ -802,10 +808,10 @@ void Function::ApplyAutoDiscoveredType(Type* type) } -Ref Function::CreateFunctionGraph() +Ref Function::CreateFunctionGraph(BNFunctionGraphType type, DisassemblySettings* settings) { - BNFunctionGraph* graph = BNCreateFunctionGraph(m_object); - return new FunctionGraph(graph); + BNFlowGraph* graph = BNCreateFunctionGraph(m_object, type, settings ? settings->GetObject() : nullptr); + return new FlowGraph(graph); } @@ -1338,6 +1344,7 @@ vector Function::GetTypeTokens(DisassemblySettings* setting DisassemblyTextLine line; line.addr = lines[i].addr; line.instrIndex = lines[i].instrIndex; + line.highlight = lines[i].highlight; line.tokens.reserve(lines[i].count); for (size_t j = 0; j < lines[i].count; j++) { @@ -1384,6 +1391,15 @@ void Function::SetAnalysisSkipOverride(BNFunctionAnalysisSkipOverride skip) } +Ref Function::GetUnresolvedStackAdjustmentGraph() +{ + BNFlowGraph* graph = BNGetUnresolvedStackAdjustmentGraph(m_object); + if (!graph) + return nullptr; + return new FlowGraph(graph); +} + + AdvancedFunctionAnalysisDataRequestor::AdvancedFunctionAnalysisDataRequestor(Function* func): m_func(func) { if (m_func) -- cgit v1.3.1 From c5c93fc82b8929d04f62d241ca50228de60fa5f4 Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Fri, 13 Jul 2018 18:43:34 -0400 Subject: Add ability to update custom flow graphs --- binaryninjaapi.h | 13 ++++++++++++- binaryninjacore.h | 3 +++ flowgraph.cpp | 30 ++++++++++++++++++++++++++++++ function.cpp | 4 ++-- interaction.cpp | 4 ++-- python/flowgraph.py | 25 +++++++++++++++++++++++++ python/function.py | 4 ++-- python/interaction.py | 4 ++-- 8 files changed, 78 insertions(+), 9 deletions(-) (limited to 'function.cpp') diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 1133625e..dd685d2b 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -2585,8 +2585,11 @@ namespace BinaryNinja 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(); @@ -2594,7 +2597,6 @@ namespace BinaryNinja public: FlowGraph(); - FlowGraph(BNFlowGraph* graph); ~FlowGraph(); BNFlowGraph* GetGraphObject() const { return m_graph; } @@ -2629,6 +2631,15 @@ namespace BinaryNinja void SetMediumLevelILFunction(MediumLevelILFunction* func); void Show(const std::string& title); + + virtual Ref Update(); + }; + + class CoreFlowGraph: public FlowGraph + { + public: + CoreFlowGraph(BNFlowGraph* graph); + virtual Ref Update() override; }; struct LowLevelILLabel: public BNLowLevelILLabel diff --git a/binaryninjacore.h b/binaryninjacore.h index a32d8364..9359ca0e 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -1778,6 +1778,7 @@ extern "C" void (*prepareForLayout)(void* ctxt); void (*populateNodes)(void* ctxt); void (*completeLayout)(void* ctxt); + BNFlowGraph* (*update)(void* ctxt); }; BINARYNINJACOREAPI char* BNAllocString(const char* contents); @@ -2629,6 +2630,8 @@ extern "C" BINARYNINJACOREAPI void BNFinishPrepareForLayout(BNFlowGraph* graph); + BINARYNINJACOREAPI BNFlowGraph* BNUpdateFlowGraph(BNFlowGraph* graph); + // Symbols BINARYNINJACOREAPI BNSymbol* BNCreateSymbol(BNSymbolType type, const char* shortName, const char* fullName, const char* rawName, uint64_t addr); diff --git a/flowgraph.cpp b/flowgraph.cpp index 4bacee81..c779db0c 100644 --- a/flowgraph.cpp +++ b/flowgraph.cpp @@ -78,6 +78,16 @@ void FlowGraph::CompleteLayoutCallback(void* ctxt) } +BNFlowGraph* FlowGraph::UpdateCallback(void* ctxt) +{ + FlowGraph* graph = (FlowGraph*)ctxt; + Ref result = graph->Update(); + if (!result) + return nullptr; + return BNNewFlowGraphReference(result->GetGraphObject()); +} + + void FlowGraph::FinishPrepareForLayout() { BNFinishPrepareForLayout(m_graph); @@ -313,3 +323,23 @@ void FlowGraph::Show(const string& title) { ShowGraphReport(title, this); } + + +Ref FlowGraph::Update() +{ + return nullptr; +} + + +CoreFlowGraph::CoreFlowGraph(BNFlowGraph* graph): FlowGraph(graph) +{ +} + + +Ref CoreFlowGraph::Update() +{ + BNFlowGraph* graph = BNUpdateFlowGraph(GetGraphObject()); + if (!graph) + return nullptr; + return new CoreFlowGraph(graph); +} diff --git a/function.cpp b/function.cpp index 62a8e1b0..202f6d77 100644 --- a/function.cpp +++ b/function.cpp @@ -811,7 +811,7 @@ void Function::ApplyAutoDiscoveredType(Type* type) Ref Function::CreateFunctionGraph(BNFunctionGraphType type, DisassemblySettings* settings) { BNFlowGraph* graph = BNCreateFunctionGraph(m_object, type, settings ? settings->GetObject() : nullptr); - return new FlowGraph(graph); + return new CoreFlowGraph(graph); } @@ -1396,7 +1396,7 @@ Ref Function::GetUnresolvedStackAdjustmentGraph() BNFlowGraph* graph = BNGetUnresolvedStackAdjustmentGraph(m_object); if (!graph) return nullptr; - return new FlowGraph(graph); + return new CoreFlowGraph(graph); } diff --git a/interaction.cpp b/interaction.cpp index 61c9dfb3..da3942bb 100644 --- a/interaction.cpp +++ b/interaction.cpp @@ -208,7 +208,7 @@ static void ShowGraphReportCallback(void* ctxt, BNBinaryView* view, const char* { InteractionHandler* handler = (InteractionHandler*)ctxt; handler->ShowGraphReport(view ? new BinaryView(BNNewViewReference(view)) : nullptr, title, - new FlowGraph(BNNewFlowGraphReference(graph))); + new CoreFlowGraph(BNNewFlowGraphReference(graph))); } @@ -663,7 +663,7 @@ Ref ReportCollection::GetFlowGraph(size_t i) const BNFlowGraph* graph = BNGetReportFlowGraph(m_object, i); if (!graph) return nullptr; - return new FlowGraph(graph); + return new CoreFlowGraph(graph); } diff --git a/python/flowgraph.py b/python/flowgraph.py index 25fdc430..e6c98597 100644 --- a/python/flowgraph.py +++ b/python/flowgraph.py @@ -268,6 +268,7 @@ class FlowGraph(object): self._ext_cb.prepareForLayout = self._ext_cb.prepareForLayout.__class__(self._prepare_for_layout) self._ext_cb.populateNodes = self._ext_cb.populateNodes.__class__(self._populate_nodes) self._ext_cb.completeLayout = self._ext_cb.completeLayout.__class__(self._complete_layout) + self._ext_cb.update = self._ext_cb.update.__class__(self._update) handle = core.BNCreateCustomFlowGraph(self._ext_cb) self.handle = handle self._on_complete = None @@ -305,6 +306,16 @@ class FlowGraph(object): except: log.log_error(traceback.format_exc()) + def _update(self, ctxt): + try: + graph = self.update() + if graph is None: + return None + return core.BNNewFlowGraphReference(graph.handle) + except: + log.log_error(traceback.format_exc()) + return None + def finish_prepare_for_layout(self): core.BNFinishPrepareForLayout(self.handle) @@ -497,3 +508,17 @@ class FlowGraph(object): def show(self, title): interaction.show_graph_report(title, self) + + def update(self): + return None + + +class CoreFlowGraph(FlowGraph): + def __init__(self, handle): + super(CoreFlowGraph, self).__init__(handle) + + def update(self): + graph = core.BNUpdateFlowGraph(self.handle) + if not graph: + return None + return CoreFlowGraph(graph) diff --git a/python/function.py b/python/function.py index dca9dda6..f64a9677 100644 --- a/python/function.py +++ b/python/function.py @@ -851,7 +851,7 @@ class Function(object): graph = core.BNGetUnresolvedStackAdjustmentGraph(self.handle) if not graph: return None - return flowgraph.FlowGraph(graph) + return flowgraph.CoreFlowGraph(graph) def __iter__(self): count = ctypes.c_ulonglong() @@ -1122,7 +1122,7 @@ class Function(object): settings_obj = settings.handle else: settings_obj = None - return flowgraph.FlowGraph(core.BNCreateFunctionGraph(self.handle, graph_type, settings_obj)) + return flowgraph.CoreFlowGraph(core.BNCreateFunctionGraph(self.handle, graph_type, settings_obj)) def apply_imported_types(self, sym): core.BNApplyImportedTypes(self.handle, sym.handle) diff --git a/python/interaction.py b/python/interaction.py index 81aeb04f..b9aa0c2a 100644 --- a/python/interaction.py +++ b/python/interaction.py @@ -302,7 +302,7 @@ class InteractionHandler(object): view = binaryview.BinaryView(handle = core.BNNewViewReference(view)) else: view = None - self.show_graph_report(view, title, flowgraph.FlowGraph(core.BNNewFlowGraphReference(graph))) + self.show_graph_report(view, title, flowgraph.CoreFlowGraph(core.BNNewFlowGraphReference(graph))) except: log.log_error(traceback.format_exc()) @@ -567,7 +567,7 @@ class ReportCollection(object): plaintext = core.BNGetReportPlainText(self.handle, i) return HTMLReport(title, contents, plaintext, view) elif report_type == ReportType.FlowGraphReportType: - graph = flowgraph.FlowGraph(core.BNGetReportFlowGraph(self.handle, i)) + graph = flowgraph.CoreFlowGraph(core.BNGetReportFlowGraph(self.handle, i)) return FlowGraphReport(title, graph, view) raise TypeError("invalid report type %s" % repr(report_type)) -- cgit v1.3.1 From 7c4025df43511852ecb86d8ab608e1da476d90de Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Thu, 2 Aug 2018 22:46:43 -0400 Subject: Add API to query if an assembly instruction is a call --- binaryninjaapi.h | 1 + binaryninjacore.h | 1 + function.cpp | 6 ++++++ python/function.py | 5 +++++ 4 files changed, 13 insertions(+) (limited to 'function.cpp') diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 53e0a30d..2c467a35 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -2500,6 +2500,7 @@ namespace BinaryNinja Confidence GetCallStackAdjustment(Architecture* arch, uint64_t addr); std::map> GetCallRegisterStackAdjustment(Architecture* arch, uint64_t addr); Confidence GetCallRegisterStackAdjustment(Architecture* arch, uint64_t addr, uint32_t regStack); + bool IsCallInstruction(Architecture* arch, uint64_t addr); std::vector> GetBlockAnnotations(Architecture* arch, uint64_t addr); diff --git a/binaryninjacore.h b/binaryninjacore.h index a26d1fe6..3e060c61 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -2521,6 +2521,7 @@ extern "C" BNArchitecture* arch, uint64_t addr, size_t* count); BINARYNINJACOREAPI BNRegisterStackAdjustment BNGetCallRegisterStackAdjustmentForRegisterStack(BNFunction* func, BNArchitecture* arch, uint64_t addr, uint32_t regStack); + BINARYNINJACOREAPI bool BNIsCallInstruction(BNFunction* func, BNArchitecture* arch, uint64_t addr); BINARYNINJACOREAPI BNInstructionTextLine* BNGetFunctionBlockAnnotations(BNFunction* func, BNArchitecture* arch, uint64_t addr, size_t* count); diff --git a/function.cpp b/function.cpp index ae6d3a6b..1236cec6 100644 --- a/function.cpp +++ b/function.cpp @@ -1116,6 +1116,12 @@ Confidence Function::GetCallRegisterStackAdjustment(Architecture* arch, } +bool Function::IsCallInstruction(Architecture* arch, uint64_t addr) +{ + return BNIsCallInstruction(m_object, arch->GetObject(), addr); +} + + vector> Function::GetBlockAnnotations(Architecture* arch, uint64_t addr) { size_t count; diff --git a/python/function.py b/python/function.py index e840dd5e..64aea87f 100644 --- a/python/function.py +++ b/python/function.py @@ -1586,6 +1586,11 @@ class Function(object): result = types.RegisterStackAdjustmentWithConfidence(adjust.adjustment, confidence = adjust.confidence) return result + def is_call_instruction(self, addr, arch=None): + if arch is None: + arch = self.arch + return core.BNIsCallInstruction(self.handle, arch.handle, addr) + class AdvancedFunctionAnalysisDataRequestor(object): def __init__(self, func = None): -- cgit v1.3.1 From 8e320c4be695cd47ae93673320d525ce513cec90 Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Fri, 17 Aug 2018 22:11:20 -0400 Subject: Fix report collection reference count bug and add debug report support --- binaryninjaapi.h | 2 ++ binaryninjacore.h | 2 ++ function.cpp | 6 ++++++ interaction.cpp | 2 +- python/function.py | 4 ++++ 5 files changed, 15 insertions(+), 1 deletion(-) (limited to 'function.cpp') diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 67d2f7f8..32ed38d2 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -2545,6 +2545,8 @@ namespace BinaryNinja void SetAnalysisSkipOverride(BNFunctionAnalysisSkipOverride skip); Ref GetUnresolvedStackAdjustmentGraph(); + + void RequestDebugReport(const std::string& name); }; class AdvancedFunctionAnalysisDataRequestor diff --git a/binaryninjacore.h b/binaryninjacore.h index 7e353ff0..c8fb9f8f 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -2626,6 +2626,8 @@ extern "C" BINARYNINJACOREAPI BNFlowGraph* BNGetUnresolvedStackAdjustmentGraph(BNFunction* func); + BINARYNINJACOREAPI void BNRequestFunctionDebugReport(BNFunction* func, const char* name); + // Disassembly settings BINARYNINJACOREAPI BNDisassemblySettings* BNCreateDisassemblySettings(void); BINARYNINJACOREAPI BNDisassemblySettings* BNNewDisassemblySettingsReference(BNDisassemblySettings* settings); diff --git a/function.cpp b/function.cpp index 1236cec6..35fe4123 100644 --- a/function.cpp +++ b/function.cpp @@ -1412,6 +1412,12 @@ Ref Function::GetUnresolvedStackAdjustmentGraph() } +void Function::RequestDebugReport(const string& name) +{ + BNRequestFunctionDebugReport(m_object, name.c_str()); +} + + AdvancedFunctionAnalysisDataRequestor::AdvancedFunctionAnalysisDataRequestor(Function* func): m_func(func) { if (m_func) diff --git a/interaction.cpp b/interaction.cpp index b2e62482..5650f629 100644 --- a/interaction.cpp +++ b/interaction.cpp @@ -215,7 +215,7 @@ static void ShowGraphReportCallback(void* ctxt, BNBinaryView* view, const char* static void ShowReportCollectionCallback(void* ctxt, const char* title, BNReportCollection* reports) { InteractionHandler* handler = (InteractionHandler*)ctxt; - handler->ShowReportCollection(title, new ReportCollection(reports)); + handler->ShowReportCollection(title, new ReportCollection(BNNewReportCollectionReference(reports))); } diff --git a/python/function.py b/python/function.py index 64aea87f..295eec7e 100644 --- a/python/function.py +++ b/python/function.py @@ -1591,6 +1591,10 @@ class Function(object): arch = self.arch return core.BNIsCallInstruction(self.handle, arch.handle, addr) + def request_debug_report(self, name): + core.BNRequestFunctionDebugReport(self.handle, name) + self.view.update_analysis() + class AdvancedFunctionAnalysisDataRequestor(object): def __init__(self, func = None): -- cgit v1.3.1 From acf28440dc4e8d805a057b6271a73e0d4e8c9e4f Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Thu, 30 Aug 2018 22:11:22 -0400 Subject: Allow negative stack offsets for functions like alloca_probe --- binaryninjaapi.h | 18 +++++++++--------- binaryninjacore.h | 22 ++++++++++++++-------- function.cpp | 36 ++++++++++++++++++------------------ lowlevelilinstruction.cpp | 6 +++--- lowlevelilinstruction.h | 6 +++--- python/function.py | 20 ++++++++++---------- python/types.py | 2 +- type.cpp | 10 +++++----- 8 files changed, 63 insertions(+), 57 deletions(-) (limited to 'function.cpp') diff --git a/binaryninjaapi.h b/binaryninjaapi.h index b5c2867b..722edcd3 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -2111,7 +2111,7 @@ namespace BinaryNinja void SetConst(const Confidence& cnst); void SetVolatile(const Confidence& vltl); void SetTypeName(const QualifiedName& name); - Confidence GetStackAdjustment() const; + Confidence GetStackAdjustment() const; uint64_t GetElementCount() const; uint64_t GetOffset() const; @@ -2152,7 +2152,7 @@ namespace BinaryNinja static Ref FunctionType(const Confidence>& returnValue, const Confidence>& callingConvention, const std::vector& params, const Confidence& varArg = Confidence(false, 0), - const Confidence& stackAdjust = Confidence(0, 0)); + const Confidence& stackAdjust = Confidence(0, 0)); static std::string GenerateAutoTypeId(const std::string& source, const QualifiedName& name); static std::string GenerateAutoDemangledTypeId(const QualifiedName& name); @@ -2437,7 +2437,7 @@ namespace BinaryNinja Confidence> GetCallingConvention() const; Confidence> GetParameterVariables() const; Confidence HasVariableArguments() const; - Confidence GetStackAdjustment() const; + Confidence GetStackAdjustment() const; std::map> GetRegisterStackAdjustments() const; Confidence> GetClobberedRegisters() const; @@ -2448,7 +2448,7 @@ namespace BinaryNinja void SetAutoParameterVariables(const Confidence>& vars); void SetAutoHasVariableArguments(const Confidence& varArgs); void SetAutoCanReturn(const Confidence& returns); - void SetAutoStackAdjustment(const Confidence& stackAdjust); + void SetAutoStackAdjustment(const Confidence& stackAdjust); void SetAutoRegisterStackAdjustments(const std::map>& regStackAdjust); void SetAutoClobberedRegisters(const Confidence>& clobbered); @@ -2459,7 +2459,7 @@ namespace BinaryNinja void SetParameterVariables(const Confidence>& vars); void SetHasVariableArguments(const Confidence& varArgs); void SetCanReturn(const Confidence& returns); - void SetStackAdjustment(const Confidence& stackAdjust); + void SetStackAdjustment(const Confidence& stackAdjust); void SetRegisterStackAdjustments(const std::map>& regStackAdjust); void SetClobberedRegisters(const Confidence>& clobbered); @@ -2491,18 +2491,18 @@ namespace BinaryNinja std::vector GetIndirectBranches(); std::vector GetIndirectBranchesAt(Architecture* arch, uint64_t addr); - void SetAutoCallStackAdjustment(Architecture* arch, uint64_t addr, const Confidence& adjust); + void SetAutoCallStackAdjustment(Architecture* arch, uint64_t addr, const Confidence& adjust); void SetAutoCallRegisterStackAdjustment(Architecture* arch, uint64_t addr, const std::map>& adjust); void SetAutoCallRegisterStackAdjustment(Architecture* arch, uint64_t addr, uint32_t regStack, const Confidence& adjust); - void SetUserCallStackAdjustment(Architecture* arch, uint64_t addr, const Confidence& adjust); + void SetUserCallStackAdjustment(Architecture* arch, uint64_t addr, const Confidence& adjust); void SetUserCallRegisterStackAdjustment(Architecture* arch, uint64_t addr, const std::map>& adjust); void SetUserCallRegisterStackAdjustment(Architecture* arch, uint64_t addr, uint32_t regStack, const Confidence& adjust); - Confidence GetCallStackAdjustment(Architecture* arch, uint64_t addr); + Confidence GetCallStackAdjustment(Architecture* arch, uint64_t addr); std::map> GetCallRegisterStackAdjustment(Architecture* arch, uint64_t addr); Confidence GetCallRegisterStackAdjustment(Architecture* arch, uint64_t addr, uint32_t regStack); bool IsCallInstruction(Architecture* arch, uint64_t addr); @@ -2875,7 +2875,7 @@ namespace BinaryNinja ExprId JumpTo(ExprId dest, const std::vector& targets, const ILSourceLocation& loc = ILSourceLocation()); ExprId Call(ExprId dest, const ILSourceLocation& loc = ILSourceLocation()); - ExprId CallStackAdjust(ExprId dest, size_t adjust, const std::map& regStackAdjust, + ExprId CallStackAdjust(ExprId dest, int64_t adjust, const std::map& regStackAdjust, const ILSourceLocation& loc = ILSourceLocation()); ExprId TailCall(ExprId dest, const ILSourceLocation& loc = ILSourceLocation()); ExprId CallSSA(const std::vector& output, ExprId dest, const std::vector& params, diff --git a/binaryninjacore.h b/binaryninjacore.h index 21b04bfa..b15ceabd 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -1304,6 +1304,12 @@ extern "C" uint8_t confidence; }; + struct BNOffsetWithConfidence + { + int64_t value; + uint8_t confidence; + }; + struct BNMemberScopeWithConfidence { BNMemberScope value; @@ -2397,7 +2403,7 @@ extern "C" BINARYNINJACOREAPI BNParameterVariablesWithConfidence BNGetFunctionParameterVariables(BNFunction* func); BINARYNINJACOREAPI void BNFreeParameterVariables(BNParameterVariablesWithConfidence* vars); BINARYNINJACOREAPI BNBoolWithConfidence BNFunctionHasVariableArguments(BNFunction* func); - BINARYNINJACOREAPI BNSizeWithConfidence BNGetFunctionStackAdjustment(BNFunction* func); + BINARYNINJACOREAPI BNOffsetWithConfidence BNGetFunctionStackAdjustment(BNFunction* func); BINARYNINJACOREAPI BNRegisterStackAdjustment* BNGetFunctionRegisterStackAdjustments(BNFunction* func, size_t* count); BINARYNINJACOREAPI void BNFreeRegisterStackAdjustments(BNRegisterStackAdjustment* adjustments); BINARYNINJACOREAPI BNRegisterSetWithConfidence BNGetFunctionClobberedRegisters(BNFunction* func); @@ -2409,7 +2415,7 @@ extern "C" BINARYNINJACOREAPI void BNSetAutoFunctionParameterVariables(BNFunction* func, BNParameterVariablesWithConfidence* vars); BINARYNINJACOREAPI void BNSetAutoFunctionHasVariableArguments(BNFunction* func, BNBoolWithConfidence* varArgs); BINARYNINJACOREAPI void BNSetAutoFunctionCanReturn(BNFunction* func, BNBoolWithConfidence* returns); - BINARYNINJACOREAPI void BNSetAutoFunctionStackAdjustment(BNFunction* func, BNSizeWithConfidence* stackAdjust); + BINARYNINJACOREAPI void BNSetAutoFunctionStackAdjustment(BNFunction* func, BNOffsetWithConfidence* stackAdjust); BINARYNINJACOREAPI void BNSetAutoFunctionRegisterStackAdjustments(BNFunction* func, BNRegisterStackAdjustment* adjustments, size_t count); BINARYNINJACOREAPI void BNSetAutoFunctionClobberedRegisters(BNFunction* func, BNRegisterSetWithConfidence* regs); @@ -2420,7 +2426,7 @@ extern "C" BINARYNINJACOREAPI void BNSetUserFunctionParameterVariables(BNFunction* func, BNParameterVariablesWithConfidence* vars); BINARYNINJACOREAPI void BNSetUserFunctionHasVariableArguments(BNFunction* func, BNBoolWithConfidence* varArgs); BINARYNINJACOREAPI void BNSetUserFunctionCanReturn(BNFunction* func, BNBoolWithConfidence* returns); - BINARYNINJACOREAPI void BNSetUserFunctionStackAdjustment(BNFunction* func, BNSizeWithConfidence* stackAdjust); + BINARYNINJACOREAPI void BNSetUserFunctionStackAdjustment(BNFunction* func, BNOffsetWithConfidence* stackAdjust); BINARYNINJACOREAPI void BNSetUserFunctionRegisterStackAdjustments(BNFunction* func, BNRegisterStackAdjustment* adjustments, size_t count); BINARYNINJACOREAPI void BNSetUserFunctionClobberedRegisters(BNFunction* func, BNRegisterSetWithConfidence* regs); @@ -2513,9 +2519,9 @@ extern "C" BINARYNINJACOREAPI void BNFreeIndirectBranchList(BNIndirectBranchInfo* branches); BINARYNINJACOREAPI void BNSetAutoCallStackAdjustment(BNFunction* func, BNArchitecture* arch, uint64_t addr, - size_t adjust, uint8_t confidence); + int64_t adjust, uint8_t confidence); BINARYNINJACOREAPI void BNSetUserCallStackAdjustment(BNFunction* func, BNArchitecture* arch, uint64_t addr, - size_t adjust, uint8_t confidence); + int64_t adjust, uint8_t confidence); BINARYNINJACOREAPI void BNSetAutoCallRegisterStackAdjustment(BNFunction* func, BNArchitecture* arch, uint64_t addr, BNRegisterStackAdjustment* adjust, size_t count); BINARYNINJACOREAPI void BNSetUserCallRegisterStackAdjustment(BNFunction* func, BNArchitecture* arch, uint64_t addr, @@ -2525,7 +2531,7 @@ extern "C" BINARYNINJACOREAPI void BNSetUserCallRegisterStackAdjustmentForRegisterStack(BNFunction* func, BNArchitecture* arch, uint64_t addr, uint32_t regStack, int32_t adjust, uint8_t confidence); - BINARYNINJACOREAPI BNSizeWithConfidence BNGetCallStackAdjustment(BNFunction* func, BNArchitecture* arch, uint64_t addr); + BINARYNINJACOREAPI BNOffsetWithConfidence BNGetCallStackAdjustment(BNFunction* func, BNArchitecture* arch, uint64_t addr); BINARYNINJACOREAPI BNRegisterStackAdjustment* BNGetCallRegisterStackAdjustment(BNFunction* func, BNArchitecture* arch, uint64_t addr, size_t* count); BINARYNINJACOREAPI BNRegisterStackAdjustment BNGetCallRegisterStackAdjustmentForRegisterStack(BNFunction* func, @@ -3027,7 +3033,7 @@ extern "C" BINARYNINJACOREAPI BNType* BNCreateArrayType(BNTypeWithConfidence* type, uint64_t elem); BINARYNINJACOREAPI BNType* BNCreateFunctionType(BNTypeWithConfidence* returnValue, BNCallingConventionWithConfidence* callingConvention, BNFunctionParameter* params, - size_t paramCount, BNBoolWithConfidence* varArg, BNSizeWithConfidence* stackAdjust); + size_t paramCount, BNBoolWithConfidence* varArg, BNOffsetWithConfidence* stackAdjust); BINARYNINJACOREAPI BNType* BNNewTypeReference(BNType* type); BINARYNINJACOREAPI BNType* BNDuplicateType(BNType* type); BINARYNINJACOREAPI char* BNGetTypeAndName(BNType* type, BNQualifiedName* name); @@ -3060,7 +3066,7 @@ extern "C" BINARYNINJACOREAPI void BNTypeSetMemberAccess(BNType* type, BNMemberAccessWithConfidence* access); BINARYNINJACOREAPI void BNTypeSetConst(BNType* type, BNBoolWithConfidence* cnst); BINARYNINJACOREAPI void BNTypeSetVolatile(BNType* type, BNBoolWithConfidence* vltl); - BINARYNINJACOREAPI BNSizeWithConfidence BNGetTypeStackAdjustment(BNType* type); + BINARYNINJACOREAPI BNOffsetWithConfidence BNGetTypeStackAdjustment(BNType* type); BINARYNINJACOREAPI char* BNGetTypeString(BNType* type, BNPlatform* platform); BINARYNINJACOREAPI char* BNGetTypeStringBeforeName(BNType* type, BNPlatform* platform); diff --git a/function.cpp b/function.cpp index 35fe4123..167a6285 100644 --- a/function.cpp +++ b/function.cpp @@ -538,10 +538,10 @@ Confidence Function::HasVariableArguments() const } -Confidence Function::GetStackAdjustment() const +Confidence Function::GetStackAdjustment() const { - BNSizeWithConfidence sc = BNGetFunctionStackAdjustment(m_object); - return Confidence(sc.value, sc.confidence); + BNOffsetWithConfidence oc = BNGetFunctionStackAdjustment(m_object); + return Confidence(oc.value, oc.confidence); } @@ -643,12 +643,12 @@ void Function::SetAutoCanReturn(const Confidence& returns) } -void Function::SetAutoStackAdjustment(const Confidence& stackAdjust) +void Function::SetAutoStackAdjustment(const Confidence& stackAdjust) { - BNSizeWithConfidence sc; - sc.value = stackAdjust.GetValue(); - sc.confidence = stackAdjust.GetConfidence(); - BNSetAutoFunctionStackAdjustment(m_object, &sc); + BNOffsetWithConfidence oc; + oc.value = stackAdjust.GetValue(); + oc.confidence = stackAdjust.GetConfidence(); + BNSetAutoFunctionStackAdjustment(m_object, &oc); } @@ -757,12 +757,12 @@ void Function::SetCanReturn(const Confidence& returns) } -void Function::SetStackAdjustment(const Confidence& stackAdjust) +void Function::SetStackAdjustment(const Confidence& stackAdjust) { - BNSizeWithConfidence sc; - sc.value = stackAdjust.GetValue(); - sc.confidence = stackAdjust.GetConfidence(); - BNSetUserFunctionStackAdjustment(m_object, &sc); + BNOffsetWithConfidence oc; + oc.value = stackAdjust.GetValue(); + oc.confidence = stackAdjust.GetConfidence(); + BNSetUserFunctionStackAdjustment(m_object, &oc); } @@ -1026,7 +1026,7 @@ vector Function::GetIndirectBranchesAt(Architecture* arch, u } -void Function::SetAutoCallStackAdjustment(Architecture* arch, uint64_t addr, const Confidence& adjust) +void Function::SetAutoCallStackAdjustment(Architecture* arch, uint64_t addr, const Confidence& adjust) { BNSetAutoCallStackAdjustment(m_object, arch->GetObject(), addr, adjust.GetValue(), adjust.GetConfidence()); } @@ -1057,7 +1057,7 @@ void Function::SetAutoCallRegisterStackAdjustment(Architecture* arch, uint64_t a } -void Function::SetUserCallStackAdjustment(Architecture* arch, uint64_t addr, const Confidence& adjust) +void Function::SetUserCallStackAdjustment(Architecture* arch, uint64_t addr, const Confidence& adjust) { BNSetUserCallStackAdjustment(m_object, arch->GetObject(), addr, adjust.GetValue(), adjust.GetConfidence()); } @@ -1088,10 +1088,10 @@ void Function::SetUserCallRegisterStackAdjustment(Architecture* arch, uint64_t a } -Confidence Function::GetCallStackAdjustment(Architecture* arch, uint64_t addr) +Confidence Function::GetCallStackAdjustment(Architecture* arch, uint64_t addr) { - BNSizeWithConfidence result = BNGetCallStackAdjustment(m_object, arch->GetObject(), addr); - return Confidence(result.value, result.confidence); + BNOffsetWithConfidence result = BNGetCallStackAdjustment(m_object, arch->GetObject(), addr); + return Confidence(result.value, result.confidence); } diff --git a/lowlevelilinstruction.cpp b/lowlevelilinstruction.cpp index 5f5dc397..9ceef260 100644 --- a/lowlevelilinstruction.cpp +++ b/lowlevelilinstruction.cpp @@ -2498,11 +2498,11 @@ int64_t LowLevelILInstruction::GetVector() const } -size_t LowLevelILInstruction::GetStackAdjustment() const +int64_t LowLevelILInstruction::GetStackAdjustment() const { size_t operandIndex; if (GetOperandIndexForUsage(StackAdjustmentLowLevelOperandUsage, operandIndex)) - return (size_t)GetRawOperandAsInteger(operandIndex); + return GetRawOperandAsInteger(operandIndex); throw LowLevelILInstructionAccessException(); } @@ -3163,7 +3163,7 @@ ExprId LowLevelILFunction::Call(ExprId dest, const ILSourceLocation& loc) } -ExprId LowLevelILFunction::CallStackAdjust(ExprId dest, size_t adjust, +ExprId LowLevelILFunction::CallStackAdjust(ExprId dest, int64_t adjust, const std::map& regStackAdjust, const ILSourceLocation& loc) { vector list; diff --git a/lowlevelilinstruction.h b/lowlevelilinstruction.h index e845bcd0..365575f8 100644 --- a/lowlevelilinstruction.h +++ b/lowlevelilinstruction.h @@ -712,7 +712,7 @@ namespace BinaryNinja template uint32_t GetIntrinsic() const { return As().GetIntrinsic(); } template int64_t GetConstant() const { return As().GetConstant(); } template int64_t GetVector() const { return As().GetVector(); } - template size_t GetStackAdjustment() const { return As().GetStackAdjustment(); } + template int64_t GetStackAdjustment() const { return As().GetStackAdjustment(); } template size_t GetTarget() const { return As().GetTarget(); } template size_t GetTrueTarget() const { return As().GetTrueTarget(); } template size_t GetFalseTarget() const { return As().GetFalseTarget(); } @@ -776,7 +776,7 @@ namespace BinaryNinja uint32_t GetIntrinsic() const; int64_t GetConstant() const; int64_t GetVector() const; - size_t GetStackAdjustment() const; + int64_t GetStackAdjustment() const; size_t GetTarget() const; size_t GetTrueTarget() const; size_t GetFalseTarget() const; @@ -1104,7 +1104,7 @@ namespace BinaryNinja template <> struct LowLevelILInstructionAccessor: public LowLevelILInstructionBase { LowLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(0); } - size_t GetStackAdjustment() const { return (size_t)GetRawOperandAsInteger(1); } + int64_t GetStackAdjustment() const { return GetRawOperandAsInteger(1); } std::map GetRegisterStackAdjustments() const { return GetRawOperandAsRegisterStackAdjustments(2); } }; template <> struct LowLevelILInstructionAccessor: public LowLevelILInstructionBase diff --git a/python/function.py b/python/function.py index 295eec7e..6da86196 100644 --- a/python/function.py +++ b/python/function.py @@ -704,13 +704,13 @@ class Function(object): @stack_adjustment.setter def stack_adjustment(self, value): - sc = core.BNSizeWithConfidence() - sc.value = int(value) + oc = core.BNOffsetWithConfidence() + oc.value = int(value) if hasattr(value, 'confidence'): - sc.confidence = value.confidence + oc.confidence = value.confidence else: - sc.confidence = types.max_confidence - core.BNSetUserFunctionStackAdjustment(self.handle, sc) + oc.confidence = types.max_confidence + core.BNSetUserFunctionStackAdjustment(self.handle, oc) @property def reg_stack_adjustments(self): @@ -1262,13 +1262,13 @@ class Function(object): core.BNSetAutoFunctionCanReturn(self.handle, bc) def set_auto_stack_adjustment(self, value): - sc = core.BNSizeWithConfidence() - sc.value = int(value) + oc = core.BNOffsetWithConfidence() + oc.value = int(value) if hasattr(value, 'confidence'): - sc.confidence = value.confidence + oc.confidence = value.confidence else: - sc.confidence = types.max_confidence - core.BNSetAutoFunctionStackAdjustment(self.handle, sc) + oc.confidence = types.max_confidence + core.BNSetAutoFunctionStackAdjustment(self.handle, oc) def set_auto_reg_stack_adjustments(self, value): adjust = (core.BNRegisterStackAdjustment * len(value))() diff --git a/python/types.py b/python/types.py index 12e7733f..b0db5f33 100644 --- a/python/types.py +++ b/python/types.py @@ -630,7 +630,7 @@ class Type(object): elif not isinstance(stack_adjust, SizeWithConfidence): stack_adjust = SizeWithConfidence(stack_adjust) - stack_adjust_conf = core.BNSizeWithConfidence() + stack_adjust_conf = core.BNOffsetWithConfidence() stack_adjust_conf.value = stack_adjust.value stack_adjust_conf.confidence = stack_adjust.confidence diff --git a/type.cpp b/type.cpp index 85961a3e..1cd52527 100644 --- a/type.cpp +++ b/type.cpp @@ -435,10 +435,10 @@ uint64_t Type::GetOffset() const } -Confidence Type::GetStackAdjustment() const +Confidence Type::GetStackAdjustment() const { - BNSizeWithConfidence result = BNGetTypeStackAdjustment(m_object); - return Confidence(result.value, result.confidence); + BNOffsetWithConfidence result = BNGetTypeStackAdjustment(m_object); + return Confidence(result.value, result.confidence); } @@ -654,7 +654,7 @@ Ref Type::ArrayType(const Confidence>& type, uint64_t elem) Ref Type::FunctionType(const Confidence>& returnValue, const Confidence>& callingConvention, const std::vector& params, const Confidence& varArg, - const Confidence& stackAdjust) + const Confidence& stackAdjust) { BNTypeWithConfidence returnValueConf; returnValueConf.type = returnValue->GetObject(); @@ -680,7 +680,7 @@ Ref Type::FunctionType(const Confidence>& returnValue, varArgConf.value = varArg.GetValue(); varArgConf.confidence = varArg.GetConfidence(); - BNSizeWithConfidence stackAdjustConf; + BNOffsetWithConfidence stackAdjustConf; stackAdjustConf.value = stackAdjust.GetValue(); stackAdjustConf.confidence = stackAdjust.GetConfidence(); -- cgit v1.3.1