上传文件至 /
This commit is contained in:
132
miuiauto.py
Normal file
132
miuiauto.py
Normal file
@@ -0,0 +1,132 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import glob
|
||||
|
||||
def log(level, msg):
|
||||
icons = {'INFO': '[*]', 'SUCCESS': '[✓]', 'ERROR': '[✗]', 'WARNING': '[!]'}
|
||||
print(f"{icons.get(level, '[*]')} {msg}")
|
||||
|
||||
def run_cmd(cmd):
|
||||
try:
|
||||
result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
|
||||
return result.returncode == 0
|
||||
except:
|
||||
return False
|
||||
|
||||
def check_glibc():
|
||||
"""检测 glibc 是否已安装"""
|
||||
log('INFO', "检测 glibc...")
|
||||
|
||||
# 检查关键路径
|
||||
paths = ['/lib/libc.so.6', '/usr/glibc-compat/lib/libc.so.6']
|
||||
for path in paths:
|
||||
if os.path.exists(path):
|
||||
log('SUCCESS', f"glibc 已安装: {path}")
|
||||
return True
|
||||
|
||||
# 检查 apk 包
|
||||
if run_cmd("apk list --installed | grep -q glibc"):
|
||||
log('SUCCESS', "glibc 已通过 apk 安装")
|
||||
return True
|
||||
|
||||
log('WARNING', "未检测到 glibc")
|
||||
return False
|
||||
|
||||
def install_glibc():
|
||||
"""运行 glibc.py 安装脚本"""
|
||||
if not os.path.exists("glibc.py"):
|
||||
log('ERROR', "找不到 glibc.py 脚本")
|
||||
return False
|
||||
|
||||
log('INFO', "运行 glibc.py 安装...")
|
||||
return os.system("python3 glibc.py") == 0
|
||||
|
||||
def find_miuiauto_files():
|
||||
"""查找 miuiauto 相关二进制文件"""
|
||||
log('INFO', "搜索 miuiauto 二进制文件...")
|
||||
|
||||
files = []
|
||||
for pattern in ["*miuiauto*", "*MIUIAUTO*", "*MiuiAuto*"]:
|
||||
files.extend(glob.glob(pattern))
|
||||
|
||||
# 过滤二进制文件
|
||||
binaries = []
|
||||
for f in files:
|
||||
if os.path.isfile(f) and is_binary(f):
|
||||
binaries.append(f)
|
||||
log('INFO', f"找到: {f}")
|
||||
|
||||
return binaries
|
||||
|
||||
def is_binary(file_path):
|
||||
"""检查是否为二进制文件"""
|
||||
try:
|
||||
with open(file_path, 'rb') as f:
|
||||
chunk = f.read(512)
|
||||
return b'\x00' in chunk or chunk.startswith(b'\x7fELF')
|
||||
except:
|
||||
return False
|
||||
|
||||
def run_binary(binary_path):
|
||||
"""添加执行权限并运行二进制文件"""
|
||||
name = os.path.basename(binary_path)
|
||||
log('INFO', f"运行 {name}...")
|
||||
|
||||
# 添加执行权限
|
||||
os.system(f"chmod +x '{binary_path}'")
|
||||
|
||||
# 运行程序
|
||||
print("=" * 40)
|
||||
result = os.system(f"./{name}")
|
||||
print("=" * 40)
|
||||
|
||||
if result == 0:
|
||||
log('SUCCESS', f"{name} 运行完成")
|
||||
else:
|
||||
log('WARNING', f"{name} 退出码: {result}")
|
||||
|
||||
return result == 0
|
||||
|
||||
def main():
|
||||
print("=" * 40)
|
||||
print(" MiuiAuto 自动运行工具")
|
||||
print("=" * 40)
|
||||
|
||||
# 检查权限
|
||||
if os.geteuid() != 0:
|
||||
log('ERROR', "需要 root 权限")
|
||||
log('INFO', "使用: sudo python3 miuiauto.py")
|
||||
return False
|
||||
|
||||
# 1. 检测/安装 glibc
|
||||
if check_glibc():
|
||||
log('SUCCESS', "glibc 已安装,跳过")
|
||||
else:
|
||||
log('INFO', "安装 glibc...")
|
||||
if not install_glibc():
|
||||
log('ERROR', "glibc 安装失败")
|
||||
return False
|
||||
|
||||
# 2. 查找并运行 miuiauto 文件
|
||||
binaries = find_miuiauto_files()
|
||||
if not binaries:
|
||||
log('ERROR', "未找到 miuiauto 二进制文件")
|
||||
return False
|
||||
|
||||
# 3. 运行所有找到的文件
|
||||
for binary in binaries:
|
||||
run_binary(binary)
|
||||
|
||||
log('SUCCESS', "完成!")
|
||||
return True
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
success = main()
|
||||
sys.exit(0 if success else 1)
|
||||
except KeyboardInterrupt:
|
||||
print("\n")
|
||||
log('WARNING', "用户中断")
|
||||
sys.exit(1)
|
||||
Reference in New Issue
Block a user