diff options
Diffstat (limited to 'binaryninjaapi.h')
| -rw-r--r-- | binaryninjaapi.h | 85 |
1 files changed, 70 insertions, 15 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index d3234dcc..d4df479b 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -346,7 +346,7 @@ namespace BinaryNinja std::string GetPathRelativeToUserPluginDirectory(const std::string& path); bool ExecuteWorkerProcess(const std::string& path, const std::vector<std::string>& args, const DataBuffer& input, - std::string& output, std::string& errors); + std::string& output, std::string& errors, bool stdoutIsText=false, bool stderrIsText=true); std::string GetVersionString(); uint32_t GetBuildId(); @@ -371,6 +371,16 @@ namespace BinaryNinja Ref<MainThreadAction> ExecuteOnMainThread(const std::function<void()>& action); void ExecuteOnMainThreadAndWait(const std::function<void()>& action); + void WorkerEnqueue(const std::function<void()>& action); + void WorkerEnqueue(RefCountObject* owner, const std::function<void()>& action); + void WorkerPriorityEnqueue(const std::function<void()>& action); + void WorkerPriorityEnqueue(RefCountObject* owner, const std::function<void()>& action); + void WorkerInteractiveEnqueue(const std::function<void()>& action); + void WorkerInteractiveEnqueue(RefCountObject* owner, const std::function<void()>& action); + + size_t GetWorkerThreadCount(); + void SetWorkerThreadCount(size_t count); + class DataBuffer { BNDataBuffer* m_buffer; @@ -511,8 +521,14 @@ namespace BinaryNinja bool IsBackedByDatabase() const; bool CreateDatabase(const std::string& name, BinaryView* data); + bool CreateDatabase(const std::string& name, BinaryView* data, + const std::function<void(size_t progress, size_t total)>& progressCallback); Ref<BinaryView> OpenExistingDatabase(const std::string& path); + Ref<BinaryView> OpenExistingDatabase(const std::string& path, + const std::function<void(size_t progress, size_t total)>& progressCallback); bool SaveAutoSnapshot(BinaryView* data); + bool SaveAutoSnapshot(BinaryView* data, + const std::function<void(size_t progress, size_t total)>& progressCallback); void BeginUndoActions(); void CommitUndoActions(); @@ -719,6 +735,7 @@ namespace BinaryNinja virtual bool PerformIsOffsetReadable(uint64_t offset); virtual bool PerformIsOffsetWritable(uint64_t offset); virtual bool PerformIsOffsetExecutable(uint64_t offset); + virtual bool PerformIsOffsetBackedByFile(uint64_t offset); virtual uint64_t PerformGetNextValidOffset(uint64_t offset); virtual uint64_t PerformGetStart() const { return 0; } virtual uint64_t PerformGetLength() const { return 0; } @@ -745,6 +762,7 @@ namespace BinaryNinja static bool IsOffsetReadableCallback(void* ctxt, uint64_t offset); static bool IsOffsetWritableCallback(void* ctxt, uint64_t offset); static bool IsOffsetExecutableCallback(void* ctxt, uint64_t offset); + static bool IsOffsetBackedByFileCallback(void* ctxt, uint64_t offset); static uint64_t GetNextValidOffsetCallback(void* ctxt, uint64_t offset); static uint64_t GetStartCallback(void* ctxt); static uint64_t GetLengthCallback(void* ctxt); @@ -766,7 +784,10 @@ namespace BinaryNinja bool IsAnalysisChanged() const; bool IsBackedByDatabase() const; bool CreateDatabase(const std::string& path); + bool CreateDatabase(const std::string& path, + const std::function<void(size_t progress, size_t total)>& progressCallback); bool SaveAutoSnapshot(); + bool SaveAutoSnapshot(const std::function<void(size_t progress, size_t total)>& progressCallback); void BeginUndoActions(); void AddUndoAction(UndoAction* action); @@ -797,6 +818,7 @@ namespace BinaryNinja bool IsOffsetReadable(uint64_t offset) const; bool IsOffsetWritable(uint64_t offset) const; bool IsOffsetExecutable(uint64_t offset) const; + bool IsOffsetBackedByFile(uint64_t offset) const; uint64_t GetNextValidOffset(uint64_t offset) const; uint64_t GetStart() const; @@ -845,6 +867,7 @@ namespace BinaryNinja Ref<BasicBlock> GetRecentBasicBlockForAddress(uint64_t addr); std::vector<Ref<BasicBlock>> GetBasicBlocksForAddress(uint64_t addr); + std::vector<Ref<BasicBlock>> GetBasicBlocksStartingAtAddress(uint64_t addr); std::vector<ReferenceSource> GetCodeReferences(uint64_t addr); std::vector<ReferenceSource> GetCodeReferences(uint64_t addr, uint64_t len); @@ -857,13 +880,13 @@ namespace BinaryNinja std::vector<Ref<Symbol>> GetSymbolsOfType(BNSymbolType type); std::vector<Ref<Symbol>> GetSymbolsOfType(BNSymbolType type, uint64_t start, uint64_t len); - void DefineAutoSymbol(Symbol* sym); - void UndefineAutoSymbol(Symbol* sym); + void DefineAutoSymbol(Ref<Symbol> sym); + void UndefineAutoSymbol(Ref<Symbol> sym); - void DefineUserSymbol(Symbol* sym); - void UndefineUserSymbol(Symbol* sym); + void DefineUserSymbol(Ref<Symbol> sym); + void UndefineUserSymbol(Ref<Symbol> sym); - void DefineImportedFunction(Symbol* importAddressSym, Function* func); + void DefineImportedFunction(Ref<Symbol> importAddressSym, Ref<Function> func); bool IsNeverBranchPatchAvailable(Architecture* arch, uint64_t addr); bool IsAlwaysBranchPatchAvailable(Architecture* arch, uint64_t addr); @@ -904,12 +927,14 @@ namespace BinaryNinja std::map<std::string, Ref<Type>> GetTypes(); Ref<Type> GetTypeByName(const std::string& name); bool IsTypeAutoDefined(const std::string& name); - void DefineType(const std::string& name, Type* type); - void DefineUserType(const std::string& name, Type* type); + void DefineType(const std::string& name, Ref<Type> type); + void DefineUserType(const std::string& name, Ref<Type> type); void UndefineType(const std::string& name); void UndefineUserType(const std::string& name); bool FindNextData(uint64_t start, const DataBuffer& data, uint64_t& result, BNFindFlag flags = NoFindFlags); + + void Reanalyze(); }; class BinaryData: public BinaryView @@ -1592,8 +1617,11 @@ namespace BinaryNinja class Function: public CoreRefCountObject<BNFunction, BNNewFunctionReference, BNFreeFunction> { + int m_advancedAnalysisRequests; + public: Function(BNFunction* func); + virtual ~Function(); Ref<Architecture> GetArchitecture() const; Ref<Platform> GetPlatform() const; @@ -1602,6 +1630,7 @@ namespace BinaryNinja bool WasAutomaticallyDiscovered() const; bool CanReturn() const; bool HasExplicitlyDefinedType() const; + bool NeedsUpdate() const; std::vector<Ref<BasicBlock>> GetBasicBlocks() const; void MarkRecentUse(); @@ -1626,6 +1655,7 @@ namespace BinaryNinja std::vector<uint32_t> GetRegistersReadByInstruction(Architecture* arch, uint64_t addr); std::vector<uint32_t> GetRegistersWrittenByInstruction(Architecture* arch, uint64_t addr); std::vector<StackVariableReference> GetStackVariablesReferencedByInstruction(Architecture* arch, uint64_t addr); + std::vector<BNConstantReference> GetConstantsReferencedByInstruction(Architecture* arch, uint64_t addr); Ref<LowLevelILFunction> GetLiftedIL() const; size_t GetLiftedILForInstruction(Architecture* arch, uint64_t addr); @@ -1643,8 +1673,8 @@ namespace BinaryNinja Ref<FunctionGraph> CreateFunctionGraph(); std::map<int64_t, StackVariable> GetStackLayout(); - void CreateAutoStackVariable(int64_t offset, Type* type, const std::string& name); - void CreateUserStackVariable(int64_t offset, Type* type, const std::string& name); + void CreateAutoStackVariable(int64_t offset, Ref<Type> type, const std::string& name); + void CreateUserStackVariable(int64_t offset, Ref<Type> type, const std::string& name); void DeleteAutoStackVariable(int64_t offset); void DeleteUserStackVariable(int64_t offset); bool GetStackVariableAtFrameOffset(int64_t offset, StackVariable& var); @@ -1661,6 +1691,26 @@ namespace BinaryNinja size_t operand); void SetIntegerConstantDisplayType(Architecture* arch, uint64_t instrAddr, uint64_t value, size_t operand, BNIntegerDisplayType type); + + void Reanalyze(); + + void RequestAdvancedAnalysisData(); + void ReleaseAdvancedAnalysisData(); + void ReleaseAdvancedAnalysisData(size_t count); + }; + + class AdvancedFunctionAnalysisDataRequestor + { + Ref<Function> m_func; + + public: + AdvancedFunctionAnalysisDataRequestor(Function* func = nullptr); + AdvancedFunctionAnalysisDataRequestor(const AdvancedFunctionAnalysisDataRequestor& req); + ~AdvancedFunctionAnalysisDataRequestor(); + AdvancedFunctionAnalysisDataRequestor& operator=(const AdvancedFunctionAnalysisDataRequestor& req); + + Ref<Function> GetFunction() { return m_func; } + void SetFunction(Function* func); }; struct FunctionGraphEdge @@ -1674,6 +1724,10 @@ namespace BinaryNinja class FunctionGraphBlock: public CoreRefCountObject<BNFunctionGraphBlock, BNNewFunctionGraphBlockReference, BNFreeFunctionGraphBlock> { + std::vector<DisassemblyTextLine> m_cachedLines; + std::vector<FunctionGraphEdge> m_cachedEdges; + bool m_cachedLinesValid, m_cachedEdgesValid; + public: FunctionGraphBlock(BNFunctionGraphBlock* block); @@ -1685,14 +1739,15 @@ namespace BinaryNinja int GetWidth() const; int GetHeight() const; - std::vector<DisassemblyTextLine> GetLines() const; - std::vector<FunctionGraphEdge> GetOutgoingEdges() const; + const std::vector<DisassemblyTextLine>& GetLines(); + const std::vector<FunctionGraphEdge>& GetOutgoingEdges(); }; class FunctionGraph: public RefCountObject { BNFunctionGraph* m_graph; std::function<void()> m_completeFunc; + std::map<BNFunctionGraphBlock*, Ref<FunctionGraphBlock>> m_cachedBlocks; static void CompleteCallback(void* ctxt); @@ -1715,7 +1770,7 @@ namespace BinaryNinja void OnComplete(const std::function<void()>& func); void Abort(); - std::vector<Ref<FunctionGraphBlock>> GetBlocks() const; + std::vector<Ref<FunctionGraphBlock>> GetBlocks(); int GetWidth() const; int GetHeight() const; @@ -1734,7 +1789,7 @@ namespace BinaryNinja BNNewLowLevelILFunctionReference, BNFreeLowLevelILFunction> { public: - LowLevelILFunction(Architecture* arch); + LowLevelILFunction(Architecture* arch, Function* func = nullptr); LowLevelILFunction(BNLowLevelILFunction* func); uint64_t GetCurrentAddress() const; @@ -1829,7 +1884,7 @@ namespace BinaryNinja void AddLabelForAddress(Architecture* arch, ExprId addr); BNLowLevelILLabel* GetLabelForAddress(Architecture* arch, ExprId addr); - void Finalize(Function* func = nullptr); + void Finalize(); bool GetExprText(Architecture* arch, ExprId expr, std::vector<InstructionTextToken>& tokens); bool GetInstructionText(Function* func, Architecture* arch, size_t i, |
