From 652b830e5cb46ed2677e7639462f597b8e5f47c4 Mon Sep 17 00:00:00 2001 From: Peter LaFosse Date: Thu, 7 Sep 2017 22:35:34 -0400 Subject: Add some convenience api's for accessing strings, and iterating over all basic blocks and instructions --- python/binaryview.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) (limited to 'python') diff --git a/python/binaryview.py b/python/binaryview.py index d002b38f..19af6264 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -88,10 +88,15 @@ class BinaryDataNotification(object): class StringReference(object): - def __init__(self, string_type, start, length): + def __init__(self, bv, string_type, start, length): self.type = string_type self.start = start self.length = length + self.view = bv + + @property + def value(self): + return self.view.read(self.start, self.length) def __repr__(self): return "<%s: %#x, len %#x>" % (self.type, self.start, self.length) @@ -659,6 +664,50 @@ class BinaryView(object): """ _BinaryViewAssociatedDataStore.set_default(name, value) + @property + def basic_blocks(self): + """A generator of all BasicBlock objects in the BinaryView""" + for func in self: + for block in func.basic_blocks: + yield block + + @property + def llil_basic_blocks(self): + """A generator of all LowLevelILBasicBlock objects in the BinaryView""" + for func in self: + for il_block in func.low_level_il.basic_blocks: + yield il_block + + @property + def mlil_basic_blocks(self): + """A generator of all MediumLevelILBasicBlock objects in the BinaryView""" + for func in self: + for il_block in func.medium_level_il.basic_blocks: + yield il_block + + @property + def instructions(self): + """A generator of instruction tokens and their start addresses""" + for block in self.basic_blocks: + start = block.start + for i in block: + yield (i[0], start) + start += i[1] + + @property + def llil_instructions(self): + """A generator of llil instructions""" + for block in self.llil_basic_blocks: + for i in block: + yield i + + @property + def mlil_instructions(self): + """A generator of mlil instructions""" + for block in self.mlil_basic_blocks: + for i in block: + yield i + def __del__(self): for i in self.notifications.values(): i._unregister() @@ -2601,7 +2650,7 @@ class BinaryView(object): strings = core.BNGetStringsInRange(self.handle, start, length, count) result = [] for i in xrange(0, count.value): - result.append(StringReference(StringType(strings[i].type), strings[i].start, strings[i].length)) + result.append(StringReference(self, StringType(strings[i].type), strings[i].start, strings[i].length)) core.BNFreeStringReferenceList(strings) return result -- cgit v1.3.1 From eecc63abf9c528ab209d56fef62cb3be7518f4e2 Mon Sep 17 00:00:00 2001 From: Peter LaFosse Date: Thu, 21 Sep 2017 16:27:04 -0400 Subject: Add segment permission properties --- python/binaryview.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'python') diff --git a/python/binaryview.py b/python/binaryview.py index 19af6264..9304d412 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -412,6 +412,18 @@ class Segment(object): self.data_length = data_length self.flags = flags + @property + def executable(self): + return (self.flags & SegmentFlag.SegmentExecutable) != 0 + + @property + def writable(self): + return (self.flags & SegmentFlag.SegmentWritable) != 0 + + @property + def readable(self): + return (self.flags & SegmentFlag.SegmentReadable) != 0 + @property def end(self): return self.start + self.length @@ -421,9 +433,9 @@ class Segment(object): def __repr__(self): return "" % (self.start, self.end, - "r" if (self.flags & SegmentFlag.SegmentReadable) != 0 else "-", - "w" if (self.flags & SegmentFlag.SegmentWritable) != 0 else "-", - "x" if (self.flags & SegmentFlag.SegmentExecutable) != 0 else "-") + "r" if self.readable else "-", + "w" if self.writable else "-", + "x" if self.executable else "-") class Section(object): -- cgit v1.3.1 From 93879514f6167764e87a6bd0e223516ddc331455 Mon Sep 17 00:00:00 2001 From: Peter LaFosse Date: Thu, 21 Sep 2017 16:36:18 -0400 Subject: Bugfix for BasicBlock incoming edges source and target were swapped --- python/basicblock.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'python') diff --git a/python/basicblock.py b/python/basicblock.py index 72f31876..26db925d 100644 --- a/python/basicblock.py +++ b/python/basicblock.py @@ -140,7 +140,7 @@ class BasicBlock(object): target = self._create_instance(self.view, core.BNNewBasicBlockReference(edges[i].target)) else: target = None - result.append(BasicBlockEdge(branch_type, self, target, edges[i].backEdge)) + result.append(BasicBlockEdge(branch_type, target, self, edges[i].backEdge)) core.BNFreeBasicBlockEdgeList(edges, count.value) return result -- cgit v1.3.1 From 01aec7ed694b537192093d37a7933f710bc0d70b Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Wed, 18 Oct 2017 17:03:37 -0400 Subject: UI Updates for Product and Update Status. --- binaryninjaapi.cpp | 18 ++++++++++++++++++ binaryninjaapi.h | 4 +++- binaryninjacore.h | 8 ++++++-- python/__init__.py | 7 +++++++ python/update.py | 2 +- update.cpp | 4 ++-- 6 files changed, 37 insertions(+), 6 deletions(-) (limited to 'python') diff --git a/binaryninjaapi.cpp b/binaryninjaapi.cpp index 6f488788..b774cf2b 100644 --- a/binaryninjaapi.cpp +++ b/binaryninjaapi.cpp @@ -173,6 +173,15 @@ string BinaryNinja::GetVersionString() } +string BinaryNinja::GetLicensedUserEmail() +{ + char* str = BNGetLicensedUserEmail(); + string result = str; + BNFreeString(str); + return result; +} + + string BinaryNinja::GetProduct() { char* str = BNGetProduct(); @@ -191,6 +200,15 @@ string BinaryNinja::GetProductType() } +string BinaryNinja::GetSerialNumber() +{ + char* str = BNGetSerialNumber(); + string result = str; + BNFreeString(str); + return result; +} + + int BinaryNinja::GetLicenseCount() { return BNGetLicenseCount(); diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 9d4a7257..a6276b00 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -575,8 +575,10 @@ namespace BinaryNinja std::string& output, std::string& errors, bool stdoutIsText=false, bool stderrIsText=true); std::string GetVersionString(); + std::string GetLicensedUserEmail(); std::string GetProduct(); std::string GetProductType(); + std::string GetSerialNumber(); int GetLicenseCount(); bool IsUIEnabled(); uint32_t GetBuildId(); @@ -2969,7 +2971,7 @@ namespace BinaryNinja static std::vector GetList(); - bool AreUpdatesAvailable(); + bool AreUpdatesAvailable(uint64_t* expireTime, uint64_t* serverTime); BNUpdateResult UpdateToVersion(const std::string& version); BNUpdateResult UpdateToVersion(const std::string& version, diff --git a/binaryninjacore.h b/binaryninjacore.h index 1bb4c726..870c2de3 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -1203,7 +1203,8 @@ extern "C" { UpdateFailed = 0, UpdateSuccess = 1, - AlreadyUpToDate = 2 + AlreadyUpToDate = 2, + UpdateAvailable = 3 }; struct BNUpdateChannel @@ -1603,7 +1604,10 @@ extern "C" BINARYNINJACOREAPI char* BNGetVersionString(void); BINARYNINJACOREAPI uint32_t BNGetBuildId(void); + BINARYNINJACOREAPI char* BNGetSerialNumber(void); + BINARYNINJACOREAPI uint64_t BNGetLicenseExpirationTime(void); BINARYNINJACOREAPI bool BNIsLicenseValidated(void); + BINARYNINJACOREAPI char* BNGetLicensedUserEmail(void); BINARYNINJACOREAPI char* BNGetProduct(void); BINARYNINJACOREAPI char* BNGetProductType(void); BINARYNINJACOREAPI int BNGetLicenseCount(void); @@ -2769,7 +2773,7 @@ extern "C" BINARYNINJACOREAPI BNUpdateVersion* BNGetUpdateChannelVersions(const char* channel, size_t* count, char** errors); BINARYNINJACOREAPI void BNFreeUpdateChannelVersionList(BNUpdateVersion* list, size_t count); - BINARYNINJACOREAPI bool BNAreUpdatesAvailable(const char* channel, char** errors); + BINARYNINJACOREAPI bool BNAreUpdatesAvailable(const char* channel, uint64_t* expireTime, uint64_t* serverTime, char** errors); BINARYNINJACOREAPI BNUpdateResult BNUpdateToVersion(const char* channel, const char* version, char** errors, bool (*progress)(void* ctxt, uint64_t progress, uint64_t total), diff --git a/python/__init__.py b/python/__init__.py index f4a8fac8..729e4f8a 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -21,6 +21,7 @@ import atexit import sys +from time import gmtime # Binary Ninja components import _binaryninjacore as core @@ -147,6 +148,12 @@ core_version = core.BNGetVersionString() core_build_id = core.BNGetBuildId() '''Build ID''' +core_serial = core.BNGetSerialNumber() +'''Serial Number''' + +core_expires = gmtime(core.BNGetLicenseExpirationTime()) +'''License Expiration''' + core_product = core.BNGetProduct() '''Product string from the license file''' diff --git a/python/update.py b/python/update.py index be6962d7..1eb8ea61 100644 --- a/python/update.py +++ b/python/update.py @@ -154,7 +154,7 @@ class UpdateChannel(object): def updates_available(self): """Whether updates are available (read-only)""" errors = ctypes.c_char_p() - result = core.BNAreUpdatesAvailable(self.name, errors) + result = core.BNAreUpdatesAvailable(self.name, None, None, errors) if errors: error_str = errors.value core.BNFreeString(ctypes.cast(errors, ctypes.POINTER(ctypes.c_byte))) diff --git a/update.cpp b/update.cpp index 135fee5e..0ec69892 100644 --- a/update.cpp +++ b/update.cpp @@ -67,10 +67,10 @@ vector UpdateChannel::GetList() } -bool UpdateChannel::AreUpdatesAvailable() +bool UpdateChannel::AreUpdatesAvailable(uint64_t* expireTime, uint64_t* serverTime) { char* errors; - bool result = BNAreUpdatesAvailable(name.c_str(), &errors); + bool result = BNAreUpdatesAvailable(name.c_str(), expireTime, serverTime, &errors); if (errors) { -- cgit v1.3.1