From c669c8d00c5c185f0a72049f5b751762719af815 Mon Sep 17 00:00:00 2001 From: CoderKang Date: Thu, 18 Sep 2025 22:26:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9B=B4=E6=96=B0=20magisk.py=20?= =?UTF-8?q?=E6=96=87=E4=BB=B6=EF=BC=8C=E9=87=8D=E6=9E=84=E4=B8=BB=E6=9C=BA?= =?UTF-8?q?=E6=9E=B6=E6=9E=84=E8=8E=B7=E5=8F=96=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=91=BD=E4=BB=A4=E8=A1=8C=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E6=94=AF=E6=8C=81=EF=BC=8C=E7=A1=AE=E4=BF=9D=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E8=BF=87=E7=A8=8B=E7=9A=84=E7=81=B5=E6=B4=BB=E6=80=A7=E5=92=8C?= =?UTF-8?q?=E5=8F=AF=E9=85=8D=E7=BD=AE=E6=80=A7=E3=80=82=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=20magisk.rc=20=E6=96=87=E4=BB=B6=EF=BC=8C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20/sbin=20=E7=9B=AE=E5=BD=95=E7=9A=84?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- magisk.py | 58 ++++++++++++++++++++++++++----------------------------- magisk.rc | 1 + 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/magisk.py b/magisk.py index e02e105..88440be 100644 --- a/magisk.py +++ b/magisk.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 +import argparse import hashlib import os -import platform import re import shutil import subprocess @@ -24,24 +24,6 @@ def download_file(url, file_path): urllib.request.urlretrieve(url, file_path) -def get_host_arch(): - """获取主机架构信息""" - machine = platform.machine() - - mapping = { - "i686": ("x86", 32), - "x86_64": ("x86_64", 64), - "aarch64": ("arm64", 64), - "armv7l": ("arm", 32), - "armv8l": ("arm", 32) - } - if machine in mapping: - return mapping[machine] - - print(f"Warning: platform.machine '{machine}' architecture not recognized, defaulting to arm64") - return ("x86_64", 64) - - def run_command(cmd): """运行命令""" try: @@ -52,14 +34,22 @@ def run_command(cmd): class Magisk: - def __init__(self): + def __init__(self, target_arch="arm64"): self.download_loc = os.path.join(os.path.dirname(os.path.abspath(__file__)), "downloads") self.dl_link = "https://github.com/topjohnwu/Magisk/releases/download/v30.2/Magisk-v30.2.apk" self.dl_file_name = os.path.join(self.download_loc, "magisk.apk") self.act_md5 = "2691c30ccf059af2536cb0af803c787c" self.extract_to = os.path.join(os.path.dirname(os.path.abspath(__file__)), "temp") self.copy_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "magisk") - self.machine = get_host_arch() + self.target_arch = target_arch + + # 架构映射 + self.arch_map = { + "x86": "x86", + "x86_64": "x86_64", + "arm": "armeabi-v7a", + "arm64": "arm64-v8a" + } def download(self): """下载 Magisk APK""" @@ -107,16 +97,8 @@ class Magisk: shutil.rmtree(self.copy_dir) os.makedirs(self.copy_dir, exist_ok=True) - # 架构映射 - arch_map = { - "x86": "x86", - "x86_64": "x86_64", - "arm": "armeabi-v7a", - "arm64": "arm64-v8a" - } - # 复制主要架构的库文件 - lib_dir = os.path.join(self.extract_to, "lib", arch_map[self.machine[0]]) + lib_dir = os.path.join(self.extract_to, "lib", self.arch_map[self.target_arch]) if os.path.exists(lib_dir): for parent, dirnames, filenames in os.walk(lib_dir): for filename in filenames: @@ -174,7 +156,21 @@ class Magisk: def main(): """主函数""" - magisk = Magisk() + parser = argparse.ArgumentParser(description='Magisk vendor package builder') + + parser.add_argument('--arch', + choices=['x86', 'x86_64', 'arm', 'arm64'], + default='arm64', + help='指定目标架构 (默认: arm64)') + + args = parser.parse_args() + + print(f"==> Using target architecture: {args.arch}") + + # 创建 Magisk 实例 + magisk = Magisk(target_arch=args.arch) + + # 执行构建 success = magisk.run() if success: diff --git a/magisk.rc b/magisk.rc index eecc59f..495eab9 100644 --- a/magisk.rc +++ b/magisk.rc @@ -9,6 +9,7 @@ service bootanim /system/bin/bootanimation on post-fs-data start logd + mkdir /sbin 755 chmod 0755 /system/etc/init/magisk/magisk chmod 0755 /system/etc/init/magisk/magiskboot chmod 0755 /system/etc/init/magisk/magiskinit