|
#!/usr/bin/env python3 |
|
#-*- coding:utf-8 -*- |
|
from subprocess import check_call, Popen, PIPE, DEVNULL |
|
from time import sleep |
|
import sys |
|
|
|
# ============================================================================== |
|
# お前の環境によって変更すべき項目 |
|
# ============================================================================== |
|
|
|
# PC側のNovaLauncherの保存先 ※空白を含むパスは無効 |
|
NOVA_LAUNCHER_APK = r"C:\nova.apk" |
|
|
|
# Noxのインストール先のbinディレクトリ |
|
NOX_BIN_DIR = r"C:\Program Files(x86)\Nox\bin" |
|
|
|
# Nox.exeの保存先 |
|
NOX_EXE = NOX_BIN_DIR+r"\Nox.exe" |
|
|
|
# nox_adb.exeの保存先 |
|
NOX_ADB = NOX_BIN_DIR+r"\nox_adb.exe" |
|
|
|
# NoxConsole.exeの保存先 |
|
NOX_CONSOLE = NOX_BIN_DIR+r"\NoxConsole.exe" |
|
|
|
# インスタンス作成時のAndroidバージョン 4 or 5 or 7 |
|
ANDROID_TYPE = 5 |
|
|
|
# ------------------------------------------------------------------------------ |
|
|
|
def main(): |
|
args = sys.argv |
|
if (2 <= len(args)): |
|
if (args[1] == "create"): |
|
command_create_instance(args) |
|
elif (args[1] == "rootrun"): |
|
command_rootrun_instance(args) |
|
elif (args[1] == "removeads"): |
|
command_remove_ads(args) |
|
else: |
|
command_help(args) |
|
else: |
|
command_help(args) |
|
|
|
def command_help(args): |
|
print('''\ |
|
mynoxcmd.py ver: 1.0 |
|
Noxインストール時の補助スクリプト |
|
|
|
Commands: |
|
python mynoxcmd.py create <num> - Android新規インスタンスを<num>個作成する |
|
python mynoxcmd.py rootrun - 全てのインスタンスをROOT起動する |
|
python mynoxcmd.py rootrun <name> <num> - <name>以降に作成された<num>個のインスタンスをROOT起動する |
|
python mynoxcmd.py removeads - 起動中の全てのインスタンスのNoxLauncherとBrowserを削除してNovaLauncherをインストールする |
|
''') |
|
|
|
def command_rootrun_instance(args): |
|
with Popen([NOX_CONSOLE,"list"],cwd=NOX_BIN_DIR,stdout=PIPE) as p: |
|
out,err = p.communicate() |
|
lines = [ s.strip().split(',')[0] for s in out.decode("utf8").split('\n') if s ] |
|
index = 0 |
|
length = len(lines) |
|
if (len(args) == 4): |
|
index = lines.index(args[2]) if args[2] in lines else -1 |
|
if (index == -1): |
|
print(args[2]+" is notfound") |
|
return |
|
length = int(args[3]) |
|
for i in range(index,index+length): |
|
if (0 < i): |
|
sleep(5) |
|
Popen([NOX_EXE, "-clone:"+lines[i],"-lang:jp","-locale:jp","-root:true"]) |
|
print("Launch "+lines[i]) |
|
|
|
def command_create_instance(args): |
|
if (len(args) != 3): |
|
print("num is null!") |
|
return |
|
num = int(args[2]) |
|
with Popen([NOX_CONSOLE, "list"],cwd=NOX_BIN_DIR,stdout=PIPE) as p: |
|
out, err = p.communicate() |
|
index = len([ s.strip() for s in out.decode("utf8").split('\n') if s ]) |
|
for i in range(index,index+num): |
|
with Popen([NOX_CONSOLE, "add", "-name:Nox_"+str(i), "-systemtype:"+str(ANDROID_TYPE)],stdout=PIPE,stderr=PIPE,cwd=NOX_BIN_DIR) as p: |
|
out, err = p.communicate() |
|
print("Created Nox_"+str(i)) |
|
|
|
def command_remove_ads(args): |
|
with Popen([NOX_ADB,"devices"], stdout=PIPE, stderr=DEVNULL) as p: |
|
out, err = p.communicate() |
|
devices = [ s.strip() for s in out.decode("utf8").split('\n') if s ] |
|
for line in devices: |
|
if (line.endswith("device") and line.startswith("127.0.0.1:")): |
|
address, port = line.split('\t')[0].split(':') |
|
if (62000 < int(port) and int(port) < 63000): |
|
install_nova(address+":"+port) |
|
uninstall_adwares(address+":"+port) |
|
print("Completed") |
|
|
|
def install_nova(specific_device): |
|
print("["+specific_device+"] Installing Nova Launcher") |
|
check_call([NOX_ADB, "-s", specific_device, "install", "-r", NOVA_LAUNCHER_APK]) |
|
with Popen([NOX_ADB,"-s",specific_device,"shell"],stdin=PIPE,stdout=DEVNULL) as p: |
|
p.communicate(b'pm disable-user --user 0 com.vphone.launcher\nam start com.teslacoilsw.launcher\nappwidget grantbind --package com.teslacoilsw.launcher --user 0\nexit\n') |
|
|
|
def uninstall_adwares(specific_device): |
|
print("["+specific_device+"] Removing NoxLauncher & Browser") |
|
with Popen([NOX_ADB,"-s",specific_device,"shell"],stdin=PIPE,stdout=DEVNULL) as p: |
|
p.communicate(b'pm uninstall -k --user 0 com.android.browser\npm uninstall -k --user 0 com.vphone.launcher\nmount -o rw,remount /system\nrm -rf /system/app/Browser\nrm -rf /system/app/Launcher\nexit\n') |
|
|
|
if __name__ == "__main__": |
|
main() |