def run(self): if monitor_type != TYPE_SOURCE_MODIFICATION and monitor_type != TYPE_HOOK: self.log.info("Only 1 or 2 is allowed to set on argument '-m' ") return system_img_path = None if self.monitor_type == TYPE_SOURCE_MODIFICATION: system_img_path = utils.get_system_img_path() if not os.path.exists(system_img_path): system_img_path = None self.emu_client = EmulatorClient(self.emu_port, self.emu_name, system_img_path) self.emu_client.start_emulator() #Install demo apk smcc_apk = utils.get_demo_apk_path('Smcc.apk') if os.path.exists(smcc_apk): self.log.info('Install Smcc.apk...') self.emu_client.install_app(smcc_apk) else: self.log.info('%s not exists' % smcc_apk) if self.monitor_type == TYPE_HOOK: # Root self.emu_client.root_emulator() # Install demo apks sandbox_apk = utils.get_demo_apk_path('SandBox.apk') if os.path.exists(sandbox_apk): self.log.info('Install SandBox.apk ...') self.emu_client.install_app(sandbox_apk) else: self.log.info('%s not exists' % sandbox_apk)
def run(self): apk_list = [] apk_list.append(utils.get_demo_apk_path('AntiEmulator.apk')) apk_list.append(utils.get_demo_apk_path('FakeFacebook.apk')) for apk_file in apk_list: if not os.path.exists(apk_file): self.log.info('"%s not exists!' % apk_file) return # Start emulator self.emu_client = EmulatorClient(self.emu_port, self.emu_name) self.emu_client.start_emulator() # Root emulator self.emu_client.root_emulator() # Repackage decompiled_dir = utils.get_decompiled_dir() if not os.path.exists(decompiled_dir): os.makedirs(decompiled_dir) repackage_dir = utils.get_repackage_dir() if not os.path.exists(repackage_dir): os.makedirs(repackage_dir) for apk_file in apk_list: apk_file_name = os.path.basename(apk_file) decompiled_dir = os.path.join(decompiled_dir, apk_file_name) repackage_path = os.path.join(repackage_dir, apk_file_name) repackage = Repackage(decompiled_dir, repackage_path, apk_file) self.log.info('Decompile %s...' % apk_file) repackage.decompile(NO_RES) self.log.info('Modifying Smali...') self.__scan_build_prop(decompiled_dir) self.log.info('Repackaging and singing...' ) repackage.do_repackage() if not os.path.exists(repackage_path): self.log.info('%s not exists' % repackage_path) continue self.emu_client.install_app(repackage_path) # Install EmulatorAntiDetect.apk demo_apk_path = utils.get_demo_apk_path('EmulatorAntiDetect.apk') if not os.path.exists(demo_apk_path): self.log.info('%s not exists!' % demo_apk_path) return self.emu_client.install_app(demo_apk_path)
def run(self): self.apk_file = utils.get_demo_apk_path('SlideMe.apk') if not os.path.exists(self.apk_file): self.log.info('"%s not exists!' % self.apk_file) return # Start emulator self.emu_client = EmulatorClient(self.emu_port, self.emu_name) self.emu_client.start_emulator() # Repackage if self.launcher_type == TYPE_REPACAKGE: decompiled_dir = utils.get_decompiled_dir() if not os.path.exists(decompiled_dir): os.makedirs(decompiled_dir) repackage_dir = utils.get_repackage_dir() if not os.path.exists(repackage_dir): os.makedirs(repackage_dir) apk_file_name = os.path.basename(self.apk_file) decompiled_dir = os.path.join(decompiled_dir, apk_file_name) repackage_path = os.path.join(repackage_dir, apk_file_name) repackage = Repackage(decompiled_dir, repackage_path, self.apk_file) self.log.info('Decompile %s...' % self.apk_file) repackage.decompile(NO_SRC) self.log.info('Modifying AndroidManifest...') self.__modify_manifest(decompiled_dir) self.log.info('Repackaging and singing...' ) repackage.do_repackage() if not os.path.exists(repackage_path): self.log.info('%s not exists' % repackage_path) return self.emu_client.install_app(repackage_path) elif self.launcher_type == TYPE_HOOK: # Root emulator self.emu_client.root_emulator() # Install demo apks component_proxy_apk = utils.get_demo_apk_path('ComponentProxy.apk') if not os.path.exists(component_proxy_apk): self.log.info('%s not exists' % component_proxy_apk) return self.emu_client.install_app(component_proxy_apk) self.emu_client.install_app(self.apk_file)
class CompoentLauncher: def __init__(self, launcher_type, emu_port, emu_name): self.launcher_type = launcher_type self.emu_port = emu_port self.emu_name = emu_name self.emu_client = None self.log = logging.getLogger(utils.LOGGER_NAME) def run(self): self.apk_file = utils.get_demo_apk_path('SlideMe.apk') if not os.path.exists(self.apk_file): self.log.info('"%s not exists!' % self.apk_file) return # Start emulator self.emu_client = EmulatorClient(self.emu_port, self.emu_name) self.emu_client.start_emulator() # Repackage if self.launcher_type == TYPE_REPACAKGE: decompiled_dir = utils.get_decompiled_dir() if not os.path.exists(decompiled_dir): os.makedirs(decompiled_dir) repackage_dir = utils.get_repackage_dir() if not os.path.exists(repackage_dir): os.makedirs(repackage_dir) apk_file_name = os.path.basename(self.apk_file) decompiled_dir = os.path.join(decompiled_dir, apk_file_name) repackage_path = os.path.join(repackage_dir, apk_file_name) repackage = Repackage(decompiled_dir, repackage_path, self.apk_file) self.log.info('Decompile %s...' % self.apk_file) repackage.decompile(NO_SRC) self.log.info('Modifying AndroidManifest...') self.__modify_manifest(decompiled_dir) self.log.info('Repackaging and singing...' ) repackage.do_repackage() if not os.path.exists(repackage_path): self.log.info('%s not exists' % repackage_path) return self.emu_client.install_app(repackage_path) elif self.launcher_type == TYPE_HOOK: # Root emulator self.emu_client.root_emulator() # Install demo apks component_proxy_apk = utils.get_demo_apk_path('ComponentProxy.apk') if not os.path.exists(component_proxy_apk): self.log.info('%s not exists' % component_proxy_apk) return self.emu_client.install_app(component_proxy_apk) self.emu_client.install_app(self.apk_file) def __modify_manifest(self, decompiled_dir): try: import xml.etree.cElementTree as ET except ImportError: import xml.etree.ElementTree as ET manifest_path = os.path.join(decompiled_dir, 'AndroidManifest.xml') if not os.path.exists(manifest_path): self.log.info('%s not exists' % manifest_path) self.has_error = True return try: manifest_tree = ET.ElementTree(file=manifest_path) ET.register_namespace('android', MANIFEST_NAMESPACE) # Activity for activity_elem in manifest_tree.iter(tag='activity'): activity_elem.set('{%s}exported' % MANIFEST_NAMESPACE, 'true') if activity_elem.attrib.has_key('{%s}permission' % MANIFEST_NAMESPACE): activity_elem.attrib.pop('{%s}permission' % MANIFEST_NAMESPACE) # Receiver for receiver_elem in manifest_tree.iter(tag='receiver'): receiver_elem.set('{%s}exported' % MANIFEST_NAMESPACE, 'true') if receiver_elem.attrib.has_key('{%s}permission' % MANIFEST_NAMESPACE): receiver_elem.attrib.pop('{%s}permission' % MANIFEST_NAMESPACE) # Service for service_elem in manifest_tree.iter(tag='service'): service_elem.set('{%s}exported' % MANIFEST_NAMESPACE, 'true') if service_elem.attrib.has_key('{%s}permission' % MANIFEST_NAMESPACE): service_elem.attrib.pop('{%s}permission' % MANIFEST_NAMESPACE) manifest_tree.write(manifest_path) except Exception, ex: self.has_error = True self.log.exception(ex)
class EmulatorHide: def __init__(self, emu_port, emu_name): self.emu_port = emu_port self.emu_name = emu_name self.emu_client = None self.log = logging.getLogger(utils.LOGGER_NAME) def run(self): apk_list = [] apk_list.append(utils.get_demo_apk_path('AntiEmulator.apk')) apk_list.append(utils.get_demo_apk_path('FakeFacebook.apk')) for apk_file in apk_list: if not os.path.exists(apk_file): self.log.info('"%s not exists!' % apk_file) return # Start emulator self.emu_client = EmulatorClient(self.emu_port, self.emu_name) self.emu_client.start_emulator() # Root emulator self.emu_client.root_emulator() # Repackage decompiled_dir = utils.get_decompiled_dir() if not os.path.exists(decompiled_dir): os.makedirs(decompiled_dir) repackage_dir = utils.get_repackage_dir() if not os.path.exists(repackage_dir): os.makedirs(repackage_dir) for apk_file in apk_list: apk_file_name = os.path.basename(apk_file) decompiled_dir = os.path.join(decompiled_dir, apk_file_name) repackage_path = os.path.join(repackage_dir, apk_file_name) repackage = Repackage(decompiled_dir, repackage_path, apk_file) self.log.info('Decompile %s...' % apk_file) repackage.decompile(NO_RES) self.log.info('Modifying Smali...') self.__scan_build_prop(decompiled_dir) self.log.info('Repackaging and singing...' ) repackage.do_repackage() if not os.path.exists(repackage_path): self.log.info('%s not exists' % repackage_path) continue self.emu_client.install_app(repackage_path) # Install EmulatorAntiDetect.apk demo_apk_path = utils.get_demo_apk_path('EmulatorAntiDetect.apk') if not os.path.exists(demo_apk_path): self.log.info('%s not exists!' % demo_apk_path) return self.emu_client.install_app(demo_apk_path) def __scan_build_prop(self, decompiled_dir): is_build_prop = False smali_dir = os.path.join(decompiled_dir, 'smali') if os.path.exists(smali_dir): for root, dir, smali_files in os.walk(smali_dir): for smali_file in smali_files: ori_smali_path = os.path.join(root, smali_file) ori_smali_obj = open(ori_smali_path, 'r') modified_smali_path = os.path.join(root, '%s.new' % smali_file) modified_smali_obj = open(modified_smali_path, 'w') line = ori_smali_obj.readline() while line: new_line = line.strip() if new_line.startswith('sget-object'): for build_str in BUILD_LIST: if build_str in new_line: is_build_prop = True line = line.replace('Landroid/os', 'Lbndroid/os') break modified_smali_obj.write(line) line = ori_smali_obj.readline() ori_smali_obj.close() modified_smali_obj.close() os.remove(ori_smali_path) os.rename(modified_smali_path, ori_smali_path) if is_build_prop: build_smali_dir = os.path.join(decompiled_dir, 'smali', 'bndroid', 'os') if not os.path.exists(build_smali_dir): os.makedirs(build_smali_dir) build_smali_file = utils.get_tool_path('Build.smali') if not os.path.exists(build_smali_file): self.log.info('%s not exists!' % build_smali_file) build_smali_dst_file = os.path.join(build_smali_dir, 'Build.smali') shutil.copy(build_smali_file, build_smali_dst_file)