From b8f49d5fecc354ad25533efad8660f4c07b9879b Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 27 Jul 2018 20:24:10 -0400 Subject: Expose the ability to suppress analysis of auto-discovered functions --- binaryninjaapi.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'binaryninjaapi.h') diff --git a/binaryninjaapi.h b/binaryninjaapi.h index f2c15fde..4678f1eb 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -1374,6 +1374,8 @@ namespace BinaryNinja void SetParametersForAnalysis(BNAnalysisParameters params); uint64_t GetMaxFunctionSizeForAnalysis(); void SetMaxFunctionSizeForAnalysis(uint64_t size); + bool GetNewAutoFunctionAnalysisSuppressed(); + void SetNewAutoFunctionAnalysisSuppressed(bool suppress); }; class BinaryData: public BinaryView -- cgit v1.3.1 From a4cde026330c26bd45d87120adb7c21d7199192c Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Fri, 10 Aug 2018 10:21:34 -0400 Subject: Make Metadata constructors explicit. --- binaryninjaapi.h | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'binaryninjaapi.h') diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 4678f1eb..e4504d1a 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -4015,21 +4015,21 @@ namespace BinaryNinja class Metadata: public CoreRefCountObject { public: - Metadata(BNMetadata* structuredData); - Metadata(bool data); - Metadata(const std::string& data); - Metadata(uint64_t data); - Metadata(int64_t data); - Metadata(double data); - Metadata(const std::vector& data); - Metadata(const std::vector& data); - Metadata(const std::vector& data); - Metadata(const std::vector& data); - Metadata(const std::vector& data); - Metadata(const std::vector& data); - Metadata(const std::vector>& data); - Metadata(const std::map>& data); - Metadata(MetadataType type); + explicit Metadata(BNMetadata* structuredData); + explicit Metadata(bool data); + explicit Metadata(const std::string& data); + explicit Metadata(uint64_t data); + explicit Metadata(int64_t data); + explicit Metadata(double data); + explicit Metadata(const std::vector& data); + explicit Metadata(const std::vector& data); + explicit Metadata(const std::vector& data); + explicit Metadata(const std::vector& data); + explicit Metadata(const std::vector& data); + explicit Metadata(const std::vector& data); + explicit Metadata(const std::vector>& data); + explicit Metadata(const std::map>& data); + explicit Metadata(MetadataType type); virtual ~Metadata() {} bool operator==(const Metadata& rhs); -- cgit v1.3.1 From 06a10105c9dd2512859597b848251f9c32037125 Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Fri, 10 Aug 2018 10:23:11 -0400 Subject: Fix ScriptingProvider reference counting and instance cleanup. --- binaryninjaapi.h | 2 ++ scriptingprovider.cpp | 7 +++++++ 2 files changed, 9 insertions(+) (limited to 'binaryninjaapi.h') diff --git a/binaryninjaapi.h b/binaryninjaapi.h index e4504d1a..147a49fb 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -3743,6 +3743,7 @@ namespace BinaryNinja protected: ScriptingInstance(ScriptingProvider* provider); ScriptingInstance(BNScriptingInstance* instance); + virtual ~ScriptingInstance(); static void DestroyInstanceCallback(void* ctxt); static BNScriptingProviderExecuteResult ExecuteScriptInputCallback(void* ctxt, const char* input); @@ -3775,6 +3776,7 @@ namespace BinaryNinja { public: CoreScriptingInstance(BNScriptingInstance* instance); + virtual ~CoreScriptingInstance() {}; virtual BNScriptingProviderExecuteResult ExecuteScriptInput(const std::string& input) override; virtual void SetCurrentBinaryView(BinaryView* view) override; diff --git a/scriptingprovider.cpp b/scriptingprovider.cpp index 6a52e095..475d69ce 100644 --- a/scriptingprovider.cpp +++ b/scriptingprovider.cpp @@ -60,6 +60,7 @@ ScriptingInstance::ScriptingInstance(ScriptingProvider* provider) cb.setCurrentBasicBlock = SetCurrentBasicBlockCallback; cb.setCurrentAddress = SetCurrentAddressCallback; cb.setCurrentSelection = SetCurrentSelectionCallback; + AddRefForRegistration(); m_object = BNInitScriptingInstance(provider->GetObject(), &cb); } @@ -70,6 +71,12 @@ ScriptingInstance::ScriptingInstance(BNScriptingInstance* instance) } +ScriptingInstance::~ScriptingInstance() +{ + BNFreeScriptingInstance(m_object); +} + + void ScriptingInstance::DestroyInstanceCallback(void* ctxt) { ScriptingInstance* instance = (ScriptingInstance*)ctxt; -- cgit v1.3.1 From 6ef32157e767aacd142012206bcf79c48266da2a Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Fri, 10 Aug 2018 13:56:34 -0400 Subject: Fix DownloadProvider reference counting and instance cleanup. --- binaryninjaapi.h | 2 ++ downloadprovider.cpp | 7 +++++++ 2 files changed, 9 insertions(+) (limited to 'binaryninjaapi.h') diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 147a49fb..a11bef1c 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -3669,6 +3669,7 @@ namespace BinaryNinja protected: DownloadInstance(DownloadProvider* provider); DownloadInstance(BNDownloadInstance* instance); + virtual ~DownloadInstance(); static void DestroyInstanceCallback(void* ctxt); static int PerformRequestCallback(void* ctxt, const char* url); @@ -3688,6 +3689,7 @@ namespace BinaryNinja { public: CoreDownloadInstance(BNDownloadInstance* instance); + virtual ~CoreDownloadInstance() {}; virtual int PerformRequest(const std::string& url) override; }; diff --git a/downloadprovider.cpp b/downloadprovider.cpp index 0e3483df..436e2516 100644 --- a/downloadprovider.cpp +++ b/downloadprovider.cpp @@ -10,6 +10,7 @@ DownloadInstance::DownloadInstance(DownloadProvider* provider) cb.context = this; cb.destroyInstance = DestroyInstanceCallback; cb.performRequest = PerformRequestCallback; + AddRefForRegistration(); m_object = BNInitDownloadInstance(provider->GetObject(), &cb); } @@ -20,6 +21,12 @@ DownloadInstance::DownloadInstance(BNDownloadInstance* instance) } +DownloadInstance::~DownloadInstance() +{ + BNFreeDownloadInstance(m_object); +} + + void DownloadInstance::DestroyInstanceCallback(void* ctxt) { DownloadInstance* instance = (DownloadInstance*)ctxt; -- cgit v1.3.1 From 199092fb6960090d88c8fecba1a0dbe503a9f7e0 Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Fri, 10 Aug 2018 13:58:07 -0400 Subject: Finish DownloadProvider C++ API. --- binaryninjaapi.h | 5 +++-- downloadprovider.cpp | 22 +++++++++++++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) (limited to 'binaryninjaapi.h') diff --git a/binaryninjaapi.h b/binaryninjaapi.h index a11bef1c..6cfa49bf 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -3680,9 +3680,10 @@ namespace BinaryNinja virtual int PerformRequest(const std::string& url) = 0; int PerformRequest(const std::string& url, BNDownloadInstanceOutputCallbacks* callbacks); - - std::string GetError() const; + uint64_t WriteDataCallback(uint8_t* data, uint64_t len); + bool NotifyProgressCallback(uint64_t progress, uint64_t total); void SetError(const std::string& error); + std::string GetError() const; }; class CoreDownloadInstance: public DownloadInstance diff --git a/downloadprovider.cpp b/downloadprovider.cpp index 436e2516..8e56bbf5 100644 --- a/downloadprovider.cpp +++ b/downloadprovider.cpp @@ -41,12 +41,15 @@ int DownloadInstance::PerformRequestCallback(void* ctxt, const char* url) } -string DownloadInstance::GetError() const +uint64_t DownloadInstance::WriteDataCallback(uint8_t* data, uint64_t len) { - char* str = BNGetErrorForDownloadInstance(m_object); - string result = str; - BNFreeString(str); - return result; + return BNWriteDataForDownloadInstance(m_object, data, len); +} + + +bool DownloadInstance::NotifyProgressCallback(uint64_t progress, uint64_t total) +{ + return BNNotifyProgressForDownloadInstance(m_object, progress, total); } @@ -56,6 +59,15 @@ void DownloadInstance::SetError(const string& error) } +string DownloadInstance::GetError() const +{ + char* str = BNGetErrorForDownloadInstance(m_object); + string result = str; + BNFreeString(str); + return result; +} + + int DownloadInstance::PerformRequest(const string& url, BNDownloadInstanceOutputCallbacks* callbacks) { return BNPerformDownloadRequest(m_object, url.c_str(), callbacks); -- cgit v1.3.1 From e8e844ef24483102103e6d20e8debbc78a687d17 Mon Sep 17 00:00:00 2001 From: Ryan Snyder Date: Wed, 15 Aug 2018 09:43:26 -0400 Subject: Expose ScriptingProvider name in C++ bindings --- binaryninjaapi.h | 2 ++ docs/getting-started.md | 19 ++++++++++--------- scriptingprovider.cpp | 9 +++++++++ 3 files changed, 21 insertions(+), 9 deletions(-) (limited to 'binaryninjaapi.h') diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 6cfa49bf..620c0472 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -3802,6 +3802,8 @@ namespace BinaryNinja public: virtual Ref CreateNewInstance() = 0; + std::string GetName(); + static std::vector> GetList(); static Ref GetByName(const std::string& name); static void Register(ScriptingProvider* provider); diff --git a/docs/getting-started.md b/docs/getting-started.md index 7e7e4acb..0e0bd596 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -265,9 +265,10 @@ Settings are stored in the _user_ directory in the file `settings.json`. Each to | ui | activeContent | boolean | True | Allow Binary Ninja to connect to the web to check for updates | | ui | colorblind | boolean | True | Choose colors that are visible to those with red/green colorblind | | ui | debug | boolean | False | Enable developer debugging features (Additional views: Lifted IL, and SSA forms) | -| ui | recent-file-limit | integer | 10 | Specify limit for number of recent files | +| ui | recent-file-limit | integer | 10 | Specify limit for number of recent files | +| ui | scriptingprovider | string | "Python" | Specify the registered ScriptingProvider that controls the 'Console' in the UI | | pdb | local-store-absolute | string | "" | Absolute path specifying where the pdb symbol store exists on this machine, overrides relative path | -| pdb | local-store-relative | string | "symbols" | Path *relative* to the binaryninja _user_ directory, sepcifying the pdb symbol store | +| pdb | local-store-relative | string | "symbols" | Path *relative* to the binaryninja _user_ directory, sepcifying the pdb symbol store | | pdb | auto-download-pdb | boolean | True | Automatically download pdb files from specified symbol servers | | pdb | symbol-server-list | list(string) | ["http://msdl.microsoft.com/download/symbols"] | List of servers to query for pdb symbols. | | python | interpreter | string | "python27.{dylib,dll,so.1}" | Python interpreter to load if one is not already present when plugins are loaded | @@ -275,13 +276,13 @@ Settings are stored in the _user_ directory in the file `settings.json`. Each to Below is an example `settings.json` setting various options: ``` { - "ui" : - { - "activeContent" : false, - "colorblind" : false, - "debug" : true - "recent-file-limit" : 10 - } + "ui" : + { + "activeContent" : false, + "colorblind" : false, + "debug" : true + "recent-file-limit" : 10 + } "pdb" : { "local-store-absolute" : "C:\Symbols", diff --git a/scriptingprovider.cpp b/scriptingprovider.cpp index 475d69ce..2a233cfe 100644 --- a/scriptingprovider.cpp +++ b/scriptingprovider.cpp @@ -252,6 +252,15 @@ BNScriptingInstance* ScriptingProvider::CreateInstanceCallback(void* ctxt) } +string ScriptingProvider::GetName() +{ + char* providerNameRaw = BNGetScriptingProviderName(m_object); + string providerName(providerNameRaw); + BNFreeString(providerNameRaw); + return providerName; +} + + vector> ScriptingProvider::GetList() { size_t count; -- cgit v1.3.1 From cecb2af5e8ec590500379e4b103531649de4e5a2 Mon Sep 17 00:00:00 2001 From: Ryan Snyder Date: Mon, 20 Aug 2018 18:58:00 -0400 Subject: api: add methods to get basic block objects from IL instrs --- binaryninjaapi.h | 2 ++ binaryninjacore.h | 2 ++ lowlevelil.cpp | 9 +++++++++ mediumlevelil.cpp | 9 +++++++++ python/lowlevelil.py | 5 +++++ python/mediumlevelil.py | 5 +++++ 6 files changed, 32 insertions(+) (limited to 'binaryninjaapi.h') diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 620c0472..b00689e0 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -2937,6 +2937,7 @@ namespace BinaryNinja uint32_t GetTemporaryFlagCount(); std::vector> GetBasicBlocks() const; + Ref GetBasicBlockForInstruction(size_t i) const; Ref GetSSAForm() const; Ref GetNonSSAForm() const; @@ -3256,6 +3257,7 @@ namespace BinaryNinja void VisitAllExprs(const std::function& func); std::vector> GetBasicBlocks() const; + Ref GetBasicBlockForInstruction(size_t i) const; Ref GetSSAForm() const; Ref GetNonSSAForm() const; diff --git a/binaryninjacore.h b/binaryninjacore.h index e5949066..c2d9f9f7 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -2768,6 +2768,7 @@ extern "C" BINARYNINJACOREAPI uint32_t BNGetLowLevelILTemporaryFlagCount(BNLowLevelILFunction* func); BINARYNINJACOREAPI BNBasicBlock** BNGetLowLevelILBasicBlockList(BNLowLevelILFunction* func, size_t* count); + BINARYNINJACOREAPI BNBasicBlock* BNGetLowLevelILBasicBlockForInstruction(BNLowLevelILFunction* func, size_t i); BINARYNINJACOREAPI BNLowLevelILFunction* BNGetLowLevelILSSAForm(BNLowLevelILFunction* func); BINARYNINJACOREAPI BNLowLevelILFunction* BNGetLowLevelILNonSSAForm(BNLowLevelILFunction* func); @@ -2889,6 +2890,7 @@ extern "C" BNArchitecture* arch, size_t i, BNInstructionTextToken** tokens, size_t* count); BINARYNINJACOREAPI BNBasicBlock** BNGetMediumLevelILBasicBlockList(BNMediumLevelILFunction* func, size_t* count); + BINARYNINJACOREAPI BNBasicBlock* BNGetMediumLevelILBasicBlockForInstruction(BNMediumLevelILFunction* func, size_t i); BINARYNINJACOREAPI BNMediumLevelILFunction* BNGetMediumLevelILSSAForm(BNMediumLevelILFunction* func); BINARYNINJACOREAPI BNMediumLevelILFunction* BNGetMediumLevelILNonSSAForm(BNMediumLevelILFunction* func); diff --git a/lowlevelil.cpp b/lowlevelil.cpp index 79138159..40748327 100644 --- a/lowlevelil.cpp +++ b/lowlevelil.cpp @@ -491,6 +491,15 @@ vector> LowLevelILFunction::GetBasicBlocks() const } +Ref LowLevelILFunction::GetBasicBlockForInstruction(size_t i) const +{ + BNBasicBlock* block = BNGetLowLevelILBasicBlockForInstruction(m_object, i); + if (!block) + return nullptr; + return new BasicBlock(block); +} + + Ref LowLevelILFunction::GetSSAForm() const { BNLowLevelILFunction* func = BNGetLowLevelILSSAForm(m_object); diff --git a/mediumlevelil.cpp b/mediumlevelil.cpp index 1795a54d..cac45dd6 100644 --- a/mediumlevelil.cpp +++ b/mediumlevelil.cpp @@ -404,6 +404,15 @@ vector> MediumLevelILFunction::GetBasicBlocks() const } +Ref MediumLevelILFunction::GetBasicBlockForInstruction(size_t i) const +{ + BNBasicBlock* block = BNGetMediumLevelILBasicBlockForInstruction(m_object, i); + if (!block) + return nullptr; + return new BasicBlock(block); +} + + Ref MediumLevelILFunction::GetSSAForm() const { BNMediumLevelILFunction* func = BNGetMediumLevelILSSAForm(m_object); diff --git a/python/lowlevelil.py b/python/lowlevelil.py index e714eb48..41579719 100644 --- a/python/lowlevelil.py +++ b/python/lowlevelil.py @@ -536,6 +536,11 @@ class LowLevelILInstruction(object): core.BNFreeInstructionText(tokens, count.value) return result + @property + def il_basic_block(self): + """IL basic block object containing this expression (read-only) (only available on finalized functions)""" + return LowLevelILBasicBlock(self.function.source_function.view, core.BNGetLowLevelILBasicBlockForInstruction(self.function.handle, self.instr_index), self.function) + @property def ssa_form(self): """SSA form of expression (read-only)""" diff --git a/python/mediumlevelil.py b/python/mediumlevelil.py index cfa8f900..c024d287 100644 --- a/python/mediumlevelil.py +++ b/python/mediumlevelil.py @@ -333,6 +333,11 @@ class MediumLevelILInstruction(object): core.BNFreeInstructionText(tokens, count.value) return result + @property + def il_basic_block(self): + """IL basic block object containing this expression (read-only) (only available on finalized functions)""" + return MediumLevelILBasicBlock(self.function.source_function.view, core.BNGetMediumLevelILBasicBlockForInstruction(self.function.handle, self.instr_index), self.function) + @property def ssa_form(self): """SSA form of expression (read-only)""" -- cgit v1.3.1 From ebed7129ba102453f04f99e2f78278ff8aeef6f9 Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Thu, 23 Aug 2018 00:57:06 -0400 Subject: add support for original_filename property --- binaryninjaapi.h | 3 +++ binaryninjacore.h | 3 +++ filemetadata.cpp | 15 +++++++++++++++ python/filemetadata.py | 11 ++++++++++- 4 files changed, 31 insertions(+), 1 deletion(-) (limited to 'binaryninjaapi.h') diff --git a/binaryninjaapi.h b/binaryninjaapi.h index b00689e0..a3db346a 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -821,6 +821,9 @@ namespace BinaryNinja void SetNavigationHandler(NavigationHandler* handler); + std::string GetOriginalFilename() const; + void SetOriginalFilename(const std::string& name); + std::string GetFilename() const; void SetFilename(const std::string& name); diff --git a/binaryninjacore.h b/binaryninjacore.h index c2d9f9f7..45ffc077 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -1950,6 +1950,9 @@ extern "C" BINARYNINJACOREAPI bool BNSaveAutoSnapshotWithProgress(BNBinaryView* data, void* ctxt, void (*progress)(void* ctxt, size_t progress, size_t total)); + BINARYNINJACOREAPI char* BNGetOriginalFilename(BNFileMetadata* file); + BINARYNINJACOREAPI void BNSetOriginalFilename(BNFileMetadata* file, const char* name); + BINARYNINJACOREAPI char* BNGetFilename(BNFileMetadata* file); BINARYNINJACOREAPI void BNSetFilename(BNFileMetadata* file, const char* name); diff --git a/filemetadata.cpp b/filemetadata.cpp index dc08fe30..bbde5d72 100644 --- a/filemetadata.cpp +++ b/filemetadata.cpp @@ -208,6 +208,21 @@ void FileMetadata::SetNavigationHandler(NavigationHandler* handler) } +string FileMetadata::GetOriginalFilename() const +{ + char* str = BNGetOriginalFilename(m_object); + string result = str; + BNFreeString(str); + return result; +} + + +void FileMetadata::SetOriginalFilename(const string& name) +{ + BNSetOriginalFilename(m_object, name.c_str()); +} + + string FileMetadata::GetFilename() const { char* str = BNGetFilename(m_object); diff --git a/python/filemetadata.py b/python/filemetadata.py index cafe1d67..4d51f4d9 100644 --- a/python/filemetadata.py +++ b/python/filemetadata.py @@ -113,9 +113,18 @@ class FileMetadata(object): def set_default_session_data(cls, name, value): _FileMetadataAssociatedDataStore.set_default(name, value) + @property + def original_filename(self): + """The original name of the binary opened if a bndb, otherwise reads or sets the current filename (read/write)""" + return core.BNGetOriginalFilename(self.handle) + + @original_filename.setter + def original_filename(self, value): + core.BNSetOriginalFilename(self.handle, str(value)) + @property def filename(self): - """The name of the file (read/write)""" + """The name of the open bndb or binary filename (read/write)""" return core.BNGetFilename(self.handle) @filename.setter -- cgit v1.3.1