From 3fe86b99d9fb16d18ad1a4bc7b5d8baa3e1bcdad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Andr=C3=A9=20Vadla=20Ravn=C3=A5s?= Date: Fri, 17 Apr 2015 22:17:05 +0200 Subject: [PATCH] Add `frida.__version__` constant --- src/_frida.c | 2 ++ src/frida/__init__.py | 46 ++++++++++++++++++++++--------------------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/_frida.c b/src/_frida.c index 446becd..d727377 100644 --- a/src/_frida.c +++ b/src/_frida.c @@ -1657,6 +1657,8 @@ MOD_INIT (_frida) MOD_DEF (module, "_frida", "Frida", NULL); + PyModule_AddStringConstant (module, "__version__", frida_version_string ()); + Py_INCREF (&PyDeviceManagerType); PyModule_AddObject (module, "DeviceManager", (PyObject *) &PyDeviceManagerType); diff --git a/src/frida/__init__.py b/src/frida/__init__.py index c52a696..0bcfb17 100644 --- a/src/frida/__init__.py +++ b/src/frida/__init__.py @@ -1,8 +1,32 @@ # -*- coding: utf-8 -*- import threading +try: + import _frida +except Exception as ex: + import colorama + from colorama import Back, Fore, Style + import sys + colorama.init(autoreset=True) + print("") + print("***") + if str(ex).startswith("No module named "): + print(Back.RED + Fore.WHITE + Style.BRIGHT + "Frida native extension not found" + Style.RESET_ALL) + print(Fore.WHITE + Style.BRIGHT + "Please check your PYTHONPATH." + Style.RESET_ALL) + else: + print(Back.RED + Fore.WHITE + Style.BRIGHT + "Failed to load the Frida native extension: %s" % ex + Style.RESET_ALL) + if sys.version_info[0] == 2: + current_python_version = "%d.%d" % sys.version_info[:2] + else: + current_python_version = "%d.x" % sys.version_info[0] + print(Fore.WHITE + Style.BRIGHT + "Please ensure that the extension was compiled for Python " + current_python_version + "." + Style.RESET_ALL) + print("***") + print("") + raise ex +__version__ = _frida.__version__ + def spawn(command_line, device_id = None): return get_device_manager().get_device(device_id).spawn(command_line) @@ -60,27 +84,5 @@ def get_device_manager(): global _device_manager if _device_manager is None: from . import core - try: - import _frida - except Exception as ex: - import colorama - from colorama import Back, Fore, Style - import sys - colorama.init(autoreset=True) - print("") - print("***") - if str(ex).startswith("No module named "): - print(Back.RED + Fore.WHITE + Style.BRIGHT + "Frida native extension not found" + Style.RESET_ALL) - print(Fore.WHITE + Style.BRIGHT + "Please check your PYTHONPATH." + Style.RESET_ALL) - else: - print(Back.RED + Fore.WHITE + Style.BRIGHT + "Failed to load the Frida native extension: %s" % ex + Style.RESET_ALL) - if sys.version_info[0] == 2: - current_python_version = "%d.%d" % sys.version_info[:2] - else: - current_python_version = "%d.x" % sys.version_info[0] - print(Fore.WHITE + Style.BRIGHT + "Please ensure that the extension was compiled for Python " + current_python_version + "." + Style.RESET_ALL) - print("***") - print("") - raise ex _device_manager = core.DeviceManager(_frida.DeviceManager()) return _device_manager