class Apk: def __init__(self, path): self.path = path self.apk = APK(self.path) # temporarty hack for ella os.path.basename(path) => path[51:-21] self.name = path[51:-21] self.package = self.apk.package self.activity = self.apk.get_main_activity()
def __init__(self, apk_path, entry_point=None, entry_point_params=(), android_sdk=None, supported_jni_archs=None, jni_libs=None, jni_libs_ld_path=None, **options): """ :param apk_path: Path to APK. :param android_sdk: Path to Android SDK folder (e.g. "/home/angr/android/platforms") The following parameters are optional :param entry_point: Fully qualified name of method that should be used as the entry point. :param supported_jni_archs: List of supported JNI architectures (ABIs) in descending order of preference. :param jni_libs: Name(s) of JNI libs to load (if any). If not specified, we try to extract JNI libs from the APK. :param jni_libs_ld_path: Path(s) where to find libs defined by param jni_libs. Note: Directory of the APK is added by default. """ l.info("Loading APK from %s ...", apk_path) if not android_sdk: raise ValueError('\nPath to Android SDK must be specified explicitly, e.g.\n' ' loading_opts = { "android_sdk" : "/home/angr/android/platforms" }\n' ' proj = angr.Project("/path/to/apk/target.apk", main_opts=loading_opts)') if not supported_jni_archs: supported_jni_archs = default_jni_archs # if jni libs are not defined by the user, we try to extract them from the APK if not jni_libs: l.info("No JNI libs provided. Trying to parse them from the APK.") jni_libs, jni_libs_ld_path = self._extract_jni_libs(apk_path, supported_jni_archs) else: l.info("Using user defined JNI lib(s) %s (load path(s) %s)", jni_libs, jni_libs_ld_path) if not entry_point: try: from pyaxmlparser import APK as APKParser apk_parser = APKParser(apk_path) main_activity = apk_parser.get_main_activity() entry_point = main_activity + '.' + 'onCreate' entry_point_params = ('android.os.Bundle',) except ImportError: l.error("Install pyaxmlparser to identify APK entry point.") # the actual lifting is done by the Soot superclass super(Apk, self).__init__(apk_path, input_format='apk', android_sdk=android_sdk, entry_point=entry_point, entry_point_params=entry_point_params, jni_libs=jni_libs, jni_libs_ld_path=jni_libs_ld_path, **options)
def __init__(self, apk_path, binary_stream, entry_point=None, entry_point_params=(), android_sdk=None, supported_jni_archs=None, jni_libs=None, jni_libs_ld_path=None, **options): """ :param apk_path: Path to APK. :param android_sdk: Path to Android SDK folder (e.g. "/home/angr/android/platforms") The following parameters are optional :param entry_point: Fully qualified name of method that should be used as the entry point. :param supported_jni_archs: List of supported JNI architectures (ABIs) in descending order of preference. :param jni_libs: Name(s) of JNI libs to load (if any). If not specified, we try to extract JNI libs from the APK. :param jni_libs_ld_path: Path(s) where to find libs defined by param jni_libs. Note: Directory of the APK is added by default. """ l.info("Loading APK from %s ...", apk_path) if not android_sdk: raise ValueError( '\nPath to Android SDK must be specified explicitly, e.g.\n' ' loading_opts = { "android_sdk" : "/home/angr/android/platforms" }\n' ' proj = angr.Project("/path/to/apk/target.apk", main_opts=loading_opts)' ) if not supported_jni_archs: supported_jni_archs = default_jni_archs # if jni libs are not defined by the user, we try to extract them from the APK if not jni_libs: l.info("No JNI libs provided. Trying to parse them from the APK.") jni_libs, jni_libs_ld_path = self._extract_jni_libs( apk_path, supported_jni_archs) else: l.info("Using user defined JNI lib(s) %s (load path(s) %s)", jni_libs, jni_libs_ld_path) if not entry_point: try: from pyaxmlparser import APK as APKParser apk_parser = APKParser(apk_path) main_activity = apk_parser.get_main_activity() entry_point = main_activity + '.' + 'onCreate' entry_point_params = ('android.os.Bundle', ) except ImportError: l.error("Install pyaxmlparser to identify APK entry point.") # the actual lifting is done by the Soot superclass super().__init__(apk_path, binary_stream, input_format='apk', android_sdk=android_sdk, entry_point=entry_point, entry_point_params=entry_point_params, jni_libs=jni_libs, jni_libs_ld_path=jni_libs_ld_path, **options)
#!/usr/bin/env python # -*- coding: utf-8 -*- from pyaxmlparser import APK a = APK( "/Users/Xiaobo/Workspace_ARD/minitest/core/resources/poco/pocoservice-debug.apk" ) print(a.xml) print(a.axml) print(a.version_name) print(a.get_target_sdk_version) print(a.get_main_activity()) print(a.apk)