def extract(base, apk): try: path = os.path.dirname(os.path.abspath(__file__)) signer = sign_m2crypto.M2CryptoSigner( op.expanduser('~/.android/adbkey')) # Connect to the device device = adb_commands.AdbCommands.ConnectDevice(rsa_keys=[signer]) # Now we can use Shell, Pull, Push, etc! apk_path = device.Shell('pm path ' + base) new_path = apk_path[apk_path.startswith("package:") and len("package:" ):] real_path = new_path.rstrip("\n\r") print("\n[*] Pulling APK located at: " + real_path) device.Pull(real_path, path + "/" + apk + ".apk") print("[*] Do you want to decompile this new apk? (Y/N)") base = raw_input() if base.rstrip("\n\r") == "y" or base.rstrip("\n\r") == "Y": d2j(apk + ".apk") decompile(apk + ".apk") else: print("Thanks! Please report any issue you may have.") sys.exit(0) except CalledProcessError as e: print(e)
def __init__(self): signer = sign_m2crypto.M2CryptoSigner( op.expanduser("~/.android/adbkey")) self.device = adb_commands.AdbCommands() self.device.ConnectDevice(rsa_keys=[signer]) # ADBInterface.current_interface = self self.kill_media()
def cli(ctx, duration, adbkey, port_path, serial): """ 微信读书自动读书 """ import random import re import time from datetime import datetime from adb import adb_commands, sign_m2crypto logger = ctx.obj.logger # KitKat+ devices require authentication signer = sign_m2crypto.M2CryptoSigner(adbkey) device = adb_commands.AdbCommands() device.ConnectDevice( port_path=port_path.encode() if port_path else None, serial=serial.encode() if serial else None, rsa_keys=[signer], default_timeout_ms=3000, ) logger.info( "设备信息: %s-%s", device.Shell("getprop ro.product.brand").strip(), device.Shell("getprop ro.product.model").strip(), ) pattern = re.compile(r"(\d+)x(\d+)") width, height = pattern.search(device.Shell("wm size")).groups() width = int(width) height = int(height) logger.info("屏幕尺寸: %dx%d", width, height) # 点亮屏幕 device.Shell("input keyevent 224") # 关闭自动亮度 device.Shell("settings put system screen_brightness_mode 0") # 将亮度调到最低 device.Shell("settings put system screen_brightness 0") now = time.time() end_time = now + duration end_datetime = datetime.fromtimestamp(end_time) logger.info("截止时间: %s", end_datetime.isoformat()) pages = 0 while now < end_time: point = { "X": width * random.uniform(0.93, 0.96), "Y": width * random.uniform(0.93, 0.96), } device.Shell("input tap {X} {Y}".format(**point)) pages += 1 logger.info("进行翻页, 第 %d 页,坐标 %s", pages, point) time.sleep(random.randint(30, 40)) now = time.time() logger.info("到达截止时间:%s, 停止运行", end_datetime.isoformat())
def _get_adb_commands_object(self): # KitKat+ devices require authentication signer = sign_m2crypto.M2CryptoSigner(op.expanduser('~/.android/adbkey')) # Connect to the device device = adb_commands.AdbCommands() device.ConnectDevice(rsa_keys=[signer]) return device
def adb_test(): print("Connecting to ADB.") # KitKat+ devices require authentication signer = sign_m2crypto.M2CryptoSigner(op.expanduser('~/.android/adbkey')) # Connect to the device device = adb_commands.AdbCommands() device.ConnectDevice(rsa_keys=[signer]) # Now we can use Shell, Pull, Push, etc! for i in range(10): print(device.Shell('echo %d' % i))
def connect_to_device(verbose = True): if verbose == True: print("CONNECTING TO ADB....") print("If unable to connect, execute adb kill-server") try: signer = sign_m2crypto.M2CryptoSigner(op.expanduser('~/.android/adbkey')) device = adb_commands.AdbCommands() device.ConnectDevice(rsa_keys=[signer]) return device except: print("execute adb kill-server first") return None
def Init(self): try: self.device = adb_commands.AdbCommands() self.signer = None if os.path.exists(self.adbkey): self.signer = sign_m2crypto.M2CryptoSigner( op.expanduser(self.adbkey)) # op.expanduser(r'C:\Users\liuqingping\.android\adbkey')) except Exception as e: self.device = None pass
def push_tflite(name): print("CONNECTING TO ADB....") signer = sign_m2crypto.M2CryptoSigner(op.expanduser('~/.android/adbkey')) device = adb_commands.AdbCommands() device.ConnectDevice(rsa_keys=[signer]) # Check if tflite file is present on disk, then push it into the device file_name = 'model_' + name + '.tflite' destination_dir = '/data/local/tmp/' + file_name if op.exists(file_name): print(device.Push(file_name, destination_dir)) print("FILE PUSHED") return True else: print("FILE NOT PRESENT") return False
def execute_tflite(name): print('EXECUTING') # Should connect again, unnecceary overhead signer = sign_m2crypto.M2CryptoSigner(op.expanduser('~/.android/adbkey')) device = adb_commands.AdbCommands() device.ConnectDevice(rsa_keys=[signer]) # More checks are required, but for now, its okay! benchmark_file = "/data/local/tmp/label_image" image_file = "/data/local/tmp/grace_hopper.bmp" label_file = "/data/local/tmp/labels.txt" model_file = '/data/local/tmp/model_' + name + '.tflite' exec_command = "." + benchmark_file + " -c 100 -v 1 -i " + \ image_file + " -l " + label_file + " -m " + \ model_file + " -t 1" print(exec_command) print(device.Shell(exec_command, timeout_ms=100000)) return
def connect(self): """ Connect to an Amazon Fire TV device. Will attempt to establish ADB connection to the given host. Failure sets state to DISCONNECTED and disables sending actions. """ try: # KitKat+ devices require authentication signer = sign_m2crypto.M2CryptoSigner( op.expanduser('~/.android/adbkey')) # Connect to the device device = adb_commands.AdbCommands() self._adb = device.ConnectDevice(serial=self.host, rsa_keys=[signer]) except socket_error as serr: print 'Exception raised' if serr.errno != errno.ECONNREFUSED: raise serr
def adb_package(apk): print("[*] Searching for app relative to: " + apk + "\n") try: # os.system("adb kill-server") signer = sign_m2crypto.M2CryptoSigner( op.expanduser('~/.android/adbkey')) # Connect to the device device = adb_commands.AdbCommands.ConnectDevice(rsa_keys=[signer]) # Now we can use Shell, Pull, Push, etc! packages = device.Shell('pm list packages | grep ' + apk) print("[*] Packages found! \n\n" + packages) print("[*] Enter package name to extract: ") base = raw_input() extract(base, apk) except CalledProcessError as e: print(e)
def adb(self): signer = sign_m2crypto.M2CryptoSigner(os.path.expanduser(Config.get_config().adb_key_path)) return adb_commands.AdbCommands.Connect(self.usbdev, rsa_keys=[signer])
from adb import adb_commands, sign_m2crypto signer = sign_m2crypto.M2CryptoSigner('/home/sriteja/.android/adbkey') device = adb_commands.AdbCommands() device.ConnectDevice(rsa_keys=[signer]) # for i in range(10): # print(device.Shell('echo %d' % i))
import os.path as op from adb import adb_commands from adb import sign_m2crypto # KitKat+ devices require authentication signer = sign_m2crypto.M2CryptoSigner(op.expanduser('~/.android/adbkey')) # Connect to the device device = adb_commands.AdbCommands() device.ConnectDevice(rsa_keys=[signer]) # Now we can use Shell, Pull, Push, etc! for i in xrange(10): print(device.Shell('echo %d' % i))