コード例 #1
0
ファイル: apk.py プロジェクト: angr/cle
    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)
コード例 #2
0
ファイル: test3.py プロジェクト: Carina6/minitest
#!/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)
コード例 #3
0
            for chunk in r.iter_content(chunk_size=1024):
                if chunk:
                    file.write(chunk)


if len(sys.argv) > 1:
    search(" ".join(sys.argv[1:]))
    if len(APPS) > 0:
        print('Downloading {}.apk ...'.format(APPS[00][2].split('/')[-1]))
        download(APPS[00][2])
        print('Download completed!')
        apk_file = format(APPS[00][2].split('/')[-1]) + '.apk'

        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            apk = APK(apk_file)
            # print(apk.package)
            # print(apk.version_name)
            apk_version_name = apk.version_name
            # print(apk.version_code)
            apk_version_code = apk.version_code
            # print(apk.icon_info)
            # print(apk.icon_data)
            apk_name = apk.application
            # print('Apk Name : '+apk_name)
            print(apk_name + ' ' + apk_version_name + '_' + apk_version_code +
                  '.apk')
            # os.rename(apk_file, apk_name+' '+apk_version_name+'_'+apk_version_code+'.apk')
            copyfile(
                apk_file, apk_name + ' ' + apk_version_name + '_' +
                apk_version_code + '.apk')
コード例 #4
0
def extract_secrets(apk: APK, decrypt_ciphers: list, encrypt_cipher: AESCipher,
                    replaced_values: dict, other_secrets: bool = False) -> dict:
    secret_keys = set()

    if other_secrets:
        with open(Path(os.path.dirname(__file__)).joinpath('other_secrets.txt'), 'r') as f:
            for line in f:
                secret_keys.add(line.strip())

    res = apk.get_android_resources()
    logging.getLogger("pyaxmlparser.stringblock").setLevel(logging.ERROR)
    res._analyse()
    logging.getLogger("pyaxmlparser.stringblock").setLevel(logging.NOTSET)

    strings = res.values[apk.get_package()]['\x00\x00']['string']

    valmap = {}
    for index, (property_name, value) in enumerate(strings):
        for decrypt_cipher in decrypt_ciphers:
            try:
                known = decrypt_cipher.decrypt(value)
                valmap[property_name] = known

                if property_name in replaced_values:
                    known = replaced_values[property_name]
                if encrypt_cipher is not None:
                    strings[index][1] = encrypt_cipher.encrypt(known).upper()
                break
            except (TypeError, ValueError, IndexError):
                # add the secret keys to the value map
                if property_name in secret_keys:
                    valmap[property_name] = value
                # ignore other values which cannot be decrypted

    if encrypt_cipher is not None:
        buff = '<?xml version="1.0" encoding="utf-8"?>\n'
        buff += '<resources>\n'

        char_map = {
            '<': '&lt;',
            '@': '\@'
        }
        for key, value in strings:
            value = value.replace('&', '&amp;')
            for old_symbol, new_symbol in char_map.items():
                value = value.replace(old_symbol, new_symbol)

            if '\n' in value or '\'' in value:
                value = '"{}"'.format(value)

            if value == '':
                buff += '    <string name="{}"/>\n'.format(key)
            else:
                buff += '    <string name="{}">{}</string>\n'.format(key, value)

        buff += '</resources>\n'

        xml = buff.encode('utf-8')

        with open('resigned-strings.xml', 'wb') as f:
            f.write(xml)

    return valmap
コード例 #5
0
from pyaxmlparser import APK

apk = APK('USBDebug 1.0_1.apk')
print(apk.package)
print(apk.version_name)
print(apk.version_code)
print(apk.icon_info)
print(apk.icon_data)
print(apk.application)
コード例 #6
0
	repair_container()
	result = {}
	apk_package = ""
	apk_full_path = filels[index]
	# frida_server_kill_process()
	# time.sleep(1)
	# frida_server_start_process()
	try:
		# fetch apk file
		print ("Install application: "+apk_full_path)
		
		filename = getLogdir(apk_full_path,dir)
		# install apk
		print(check_output("adb install "+apk_full_path+"|exit", shell=True,timeout=10).decode())
		# get package name
		apk = APK(apk_full_path)
		package_name = apk.packagename
		print (index)
		print (filename)
		print (package_name)
	except Exception as e:
		f=open("runlog.txt","a+").write("Error in file: "+filename+"\n")
		exit

	docker_id = '192.168.0.36'
	launchable_activity = utils.get_launchable_activity_from_aapt(
        apk_full_path)
	run_apk_res = utils.run_apk(docker_id, package_name, launchable_activity)

    # get all pid of the app while it runs
	pids = utils.get_app_pid(docker_id,package_name)
コード例 #7
0
def get_meta_from_apk(apk: APK) -> ApkMetadata:
    return int(apk.version_code), Path(
        apk.filename), apk.get_app_name(), apk.version_name