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 --- python/binaryview.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'python') diff --git a/python/binaryview.py b/python/binaryview.py index 25953b34..35ef6a40 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -1098,6 +1098,15 @@ class BinaryView(object): def max_function_size_for_analysis(self, size): core.BNSetMaxFunctionSizeForAnalysis(self.handle, size) + @property + def new_auto_function_analysis_suppressed(self): + """Whether or not automatically discovered functions will be analyzed""" + return core.BNGetNewAutoFunctionAnalysisSuppressed(self.handle) + + @new_auto_function_analysis_suppressed.setter + def new_auto_function_analysis_suppressed(self, suppress): + core.BNSetNewAutoFunctionAnalysisSuppressed(self.handle, suppress) + def __len__(self): return int(core.BNGetViewLength(self.handle)) -- cgit v1.3.1 From cfeda2e333f094e678289ff4a64635bf9d76982a Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Wed, 1 Aug 2018 17:27:15 -0400 Subject: Fix analysis_info broken in python merge from b460b9495a. --- python/binaryview.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'python') diff --git a/python/binaryview.py b/python/binaryview.py index 35ef6a40..63a12caa 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -983,7 +983,7 @@ class BinaryView(object): info = info_ref[0] active_info_list = [] for i in xrange(0, info.count): - func = function.Function(self, core.BNNewFunctionReference(info.activeInfo[i].func)) + func = binaryninja.function.Function(self, core.BNNewFunctionReference(info.activeInfo[i].func)) active_info = ActiveAnalysisInfo(func, info.activeInfo[i].analysisTime, info.activeInfo[i].updateCount, info.activeInfo[i].submitCount) active_info_list.append(active_info) result = AnalysisInfo(info.state, info.analysisTime, active_info_list) -- cgit v1.3.1 From dc720468f601d849aba0c4cb152422de93c18082 Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Thu, 2 Aug 2018 14:33:34 -0400 Subject: Fix DownloadProvider broken in python merge from b460b9495a. --- python/downloadprovider.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'python') diff --git a/python/downloadprovider.py b/python/downloadprovider.py index 14368ee7..1c94aef3 100644 --- a/python/downloadprovider.py +++ b/python/downloadprovider.py @@ -26,6 +26,8 @@ import traceback # Binary Ninja Components import binaryninja._binaryninjacore as core + +import binaryninja from binaryninja.setting import Setting from binaryninja import with_metaclass from binaryninja import startup @@ -79,7 +81,7 @@ class _DownloadProviderMetaclass(type): @property def list(self): """List all DownloadProvider types (read-only)""" - startup._init_plugins() + binaryninja._init_plugins() count = ctypes.c_ulonglong() types = core.BNGetDownloadProviderList(count) result = [] @@ -89,7 +91,7 @@ class _DownloadProviderMetaclass(type): return result def __iter__(self): - startup._init_plugins() + binaryninja._init_plugins() count = ctypes.c_ulonglong() types = core.BNGetDownloadProviderList(count) try: @@ -99,7 +101,7 @@ class _DownloadProviderMetaclass(type): core.BNFreeDownloadProviderList(types) def __getitem__(self, value): - startup._init_plugins() + binaryninja._init_plugins() provider = core.BNGetDownloadProviderByName(str(value)) if provider is None: raise KeyError("'%s' is not a valid download provider" % str(value)) -- cgit v1.3.1 From 25e1a12bb57a7ec6e29f9641429eb29183c32d75 Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Thu, 2 Aug 2018 14:34:06 -0400 Subject: Fix Update import broken in python merge from b460b9495a. --- python/update.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'python') diff --git a/python/update.py b/python/update.py index 7f5d6f9c..90128056 100644 --- a/python/update.py +++ b/python/update.py @@ -23,6 +23,8 @@ import ctypes # Binary Ninja components from binaryninja import _binaryninjacore as core + +import binaryninja from binaryninja.enums import UpdateResult # 2-3 compatibility -- cgit v1.3.1 From 824f451696a65f0a0b23d7328f332d95330cca8f Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Fri, 10 Aug 2018 14:36:25 -0400 Subject: Expose BNIsUIEnabled via Python. --- python/__init__.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'python') diff --git a/python/__init__.py b/python/__init__.py index 9d183465..947739ca 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -249,3 +249,6 @@ core_product_type = core.BNGetProductType() core_license_count = core.BNGetLicenseCount() '''License count from the license file''' + +core_ui_enabled = core.BNIsUIEnabled() +'''Indicates that a UI exists and the UI has invoked BNInitUI''' -- cgit v1.3.1 From 5adbd368a2f312aff5d949df5d7bbf1097c10bbd Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Fri, 10 Aug 2018 14:44:21 -0400 Subject: Return the boolean value from bv.navigate in the Python API. --- python/binaryview.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'python') diff --git a/python/binaryview.py b/python/binaryview.py index 63a12caa..5e3e765d 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -1747,7 +1747,7 @@ class BinaryView(object): self.file.redo() def navigate(self, view, offset): - self.file.navigate(view, offset) + return self.file.navigate(view, offset) def read(self, addr, length): """ -- cgit v1.3.1 From e9db9c0b3626a5d16b522caf26041c0375c8b30b Mon Sep 17 00:00:00 2001 From: Kyle Martin Date: Thu, 16 Aug 2018 11:22:20 -0400 Subject: Fix Python3 Multiline Input In Script Console --- python/scriptingprovider.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'python') diff --git a/python/scriptingprovider.py b/python/scriptingprovider.py index 37642ed4..5b5d830e 100644 --- a/python/scriptingprovider.py +++ b/python/scriptingprovider.py @@ -612,7 +612,10 @@ class PythonScriptingInstance(ScriptingInstance): return ScriptingProviderExecuteResult.SuccessfulScriptExecution try: - result = code.compile_command(text) + if isinstance(text, str): + result = code.compile_command(text) + else: + result = code.compile_command(text.decode("charmap")) except: result = False @@ -661,4 +664,4 @@ def redirect_stdio(): sys.stdin = _PythonScriptingInstanceInput(sys.stdin) sys.stdout = _PythonScriptingInstanceOutput(sys.stdout, False) sys.stderr = _PythonScriptingInstanceOutput(sys.stderr, True) - sys.excepthook = sys.__excepthook__ \ No newline at end of file + sys.excepthook = sys.__excepthook__ -- 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 'python') 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 'python') 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