summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/__init__.py45
1 files changed, 37 insertions, 8 deletions
diff --git a/python/__init__.py b/python/__init__.py
index c659aa1c..c8f42251 100644
--- a/python/__init__.py
+++ b/python/__init__.py
@@ -27,10 +27,15 @@ from time import gmtime
# 2-3 compatibility
+PY2 = sys.version_info[0] == 2
+PY3 = sys.version_info[0] == 3
+PY34 = sys.version_info[0:2] >= (3, 4)
+
try:
import builtins # __builtins__ for python2
except ImportError:
pass
+
def range(*args):
""" A Python2 and Python3 Compatible Range Generator """
try:
@@ -38,17 +43,37 @@ def range(*args):
except NameError:
return builtins.range(*args)
+def valid_import(mod_name):
+ if PY2:
+ import imp
+ try:
+ imp.find_module(mod_name)
+ found = True
+ except ImportError:
+ found = False
+ elif PY34:
+ import importlib
+ mod_spec = importlib.util.find_spec(mod_name)
+ found = mod_spec is not None
+ elif PY3:
+ import importlib
+ mod_loader = importlib.find_loader(mod_name)
+ found = mod_loader is not None
+ else:
+ return False
+ return found
+
def with_metaclass(meta, *bases):
- """Create a base class with a metaclass."""
- class metaclass(type):
- def __new__(cls, name, this_bases, d):
- return meta(name, bases, d)
+ """Create a base class with a metaclass."""
+ class metaclass(type):
+ def __new__(cls, name, this_bases, d):
+ return meta(name, bases, d)
- @classmethod
- def __prepare__(cls, name, this_bases):
- return meta.__prepare__(name, bases)
- return type.__new__(metaclass, 'temporary_class', (), {})
+ @classmethod
+ def __prepare__(cls, name, this_bases):
+ return meta.__prepare__(name, bases)
+ return type.__new__(metaclass, 'temporary_class', (), {})
try:
@@ -315,3 +340,7 @@ def get_memory_usage_info():
result[info[i].name] = info[i].value
core.BNFreeMemoryUsageInfo(info, count.value)
return result
+
+if not valid_import("binaryninjaui") and not core_ui_enabled():
+ #Use print because we're headless and log_functions won't work yet
+ print("BINARYNINJAUI module not available.\nPlease re-run the install_api.py python script (with the appropriate version of python you plan to use) to properly set up your Binary Ninja python paths.") \ No newline at end of file