Skip to content

Instantly share code, notes, and snippets.

@erectorOps
Last active February 22, 2020 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erectorOps/7f1fc1b3a60f52fd6a39702431d3f4b1 to your computer and use it in GitHub Desktop.
Save erectorOps/7f1fc1b3a60f52fd6a39702431d3f4b1 to your computer and use it in GitHub Desktop.
Nox App Playerのランチャーとブラウザ削除する。インスタンス複数個一気に作成。全インスタンスをROOT起動する。

環境

  • Windows 10 64bit
  • Python 3.6.2 :: Anaconda custom (64-bit)
  • Nox App Player 6.3.0.0

事前準備

  • apkpure.com等からNovaLauncher.apkをDLしnova.apkにリネームしてC:\nova.apkに置く
  • Noxのインストール先が標準以外の場合はmynoxcmd.pyをテキストエディターで開いて各ファイルパスを変更する

使い方

1.コマンドプロンプトからpython mynoxcmd.pyを呼び出します

  • Noxの新規インスタンスを < num > 個作成する

    • $ python mynoxcmd.py create num
  • Noxの全インスタンスをROOT起動する

    • $ python mynoxcmd.py rootrun
  • name以降に作成されたnum個のインスタンスをROOT起動する

    • $ python mynoxcmd.py rootrun name num
  • 起動中の全てのインスタンスのNoxLauncherとBrowserを削除してNovaLauncherをインストールする

    • $ python mynoxcmd.py removeads

使用例(PowerShell)

PS C:> python .\mynoxcmd.py create 2

 Created Nox_3  
 Created Nox_4  

PS C:> python .\mynoxcmd.py rootrun Nox_3 2

 Launch Nox_3  
 Launch Nox_4  

PS C:> python .\mynoxcmd.py removeads

 [127.0.0.1:62028] Installing Nova Launcher  
 [100%] /data/data/tmp/nova.apk  
       pkg: /data/data/tmp/nova.apk  
 Success  
 [127.0.0.1:62028] Removing NoxLauncher & Browser  
 [127.0.0.1:62027] Installing Nova Launcher  
 [100%] /data/data/tmp/nova.apk  
       pkg: /data/data/tmp/nova.apk  
 Success  
 [127.0.0.1:62027] Removing NoxLauncher & Browser  
 Completed  
#!/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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment