def list_packages(device=None): array = [] for item in Shell.stdout(fmt('shell pm list packages', device)).split('\n'): item = item.strip() if item: array.append(item[item.find(':')+1:]) return array
def list_devices(): # 列出连接的手机 array = [] lines = Shell.stdout(fmt('devices')).split('\n') for i in range(1, len(lines)): # List of devices attached item = lines[i] if item: array.append(item[:item.find('\tdevice')]) return array
def set_mac_address(user_pwd, if_name, mac_addr): print(user_pwd) if Cross.IS_MACOSX: ret = Shell.run('echo "%s" | sudo -S ifconfig %s lladdr %s' % (user_pwd, if_name, mac_addr)) print('set_mac_addr returncode =', ret) elif Cross.IS_LINUX: pass elif Cross.IS_WINDOWS: pass
def net_turn_off(user_pwd, if_list=None): print(user_pwd) if Cross.IS_MACOSX: for device in if_list: ret = Shell.run('echo "%s" | sudo -S ifconfig %s %s' % (user_pwd, device, 'down')) print('net_turn_off returncode =', ret) elif Cross.IS_LINUX: pass elif Cross.IS_WINDOWS: pass
def sign(unsign_apk, signed_apk, sign_config=None): # 签名APK if sign_config is None: sign_config = { 'keystore': os.path.join(APK2DIR, 'sign/myapk.jks'), 'storepwd': '666666', 'keypwd': '666666', 'alias': 'joli' } return Shell.run( 'jarsigner -verbose -keystore %s -storepass %s -keypass %s -signedjar %s %s %s' % (sign_config['keystore'], sign_config['storepwd'], sign_config['keypwd'], signed_apk, unsign_apk, sign_config['alias']))
def net_turn_on(user_pwd, if_list): print(user_pwd) if Cross.IS_MACOSX: # networksetup -listallhardwareports # networksetup -setairportpower %(HardwareDevice)s on/off # ifconfig %(HardwareDevice)s up/down for device in if_list: ret = Shell.run('echo "%s" | sudo -S ifconfig %s %s' % (user_pwd, device, 'up')) print('net_turn_on returncode =', ret) elif Cross.IS_LINUX: pass elif Cross.IS_WINDOWS: pass
def screenshot(image='/sdcard/screenshot.png', device=None): # 在手机上截图 return Shell.run(fmt('shell /system/bin/screencap -p %s' % image, device))
def install(apk, appid=None, device=None): # 安装应用 if appid and appid in list_packages(device): retcode = Shell.run(fmt('uninstall %s' % appid, device)) assert 0 == retcode, 'uninstall apk fail:%d' % retcode return Shell.run(fmt('install %s' % apk, device))
def pull(src, dst, device=None): # 从手机上传到电脑 return Shell.run(fmt('pull %s %s' % (src, dst), device))
def bapk(dist, apk): # 回编APK return Shell.run('java -Djava.awt.headless=true -jar %s b -f -o %s %s' % (APK2JAR, apk, dist))
def dapk(apk, dist): # 反编APK return Shell.run('java -Djava.awt.headless=true -jar %s d -f -o %s %s' % (APK2JAR, dist, apk))
def is_net_ok(): return 0 == Shell.run('ping www.baidu.com -c 2')
def test_hack_luac(): unluac = '/Users/joli/source/mac/app/hack/unluac_2015_06_13.jar' src = '/Users/joli/Desktop/apps/apk/res2/script/main.lua' dst = '/Users/joli/Desktop/apps/apk/res2/script/main1.lua' Shell.run('java -Djava.awt.headless=true -jar %s %s>%s' % (unluac, src, dst))