diff --git a/alas.py b/alas.py index 4f7ba22ae..b63953474 100644 --- a/alas.py +++ b/alas.py @@ -933,7 +933,9 @@ class AzurLaneAutoScript(AzurLaneAutoScript): def hook_op(self): op = self.config.full_config.HookOp_HookOp_Operation - if op == "inject": + if op == "detect": + CrackResource(self.config, self.device).auto_detect() + elif op == "inject": CrackResource(self.config, self.device).ensure() elif op == "apply": luahook_disable_all(self.config, self.device) diff --git a/config/template.json b/config/template.json index ff7773a5e..843a6e1b7 100644 --- a/config/template.json +++ b/config/template.json @@ -199,7 +199,7 @@ "RestartEveryTime": true, "UpdateEveryTime": true, "PushEveryTime": true, - "Architecture": "auto", + "Architecture": "x86_64", "InjectMethod": "local_patch", "RequestTimeLimit": 10, "UpdateServer": null, diff --git a/module/config/argument/args.json b/module/config/argument/args.json index 1ebc1f742..da8d55d24 100644 --- a/module/config/argument/args.json +++ b/module/config/argument/args.json @@ -780,9 +780,8 @@ }, "Architecture": { "type": "select", - "value": "auto", + "value": "x86_64", "option": [ - "auto", "x86", "x86_64", "arm64-v8a", @@ -17200,6 +17199,7 @@ "type": "select", "value": "apply", "option": [ + "detect", "inject", "apply" ] diff --git a/module/config/argument/argument.yaml b/module/config/argument/argument.yaml index abbddb83e..5addab57e 100644 --- a/module/config/argument/argument.yaml +++ b/module/config/argument/argument.yaml @@ -826,8 +826,8 @@ HookGeneral: UpdateEveryTime: true PushEveryTime: true Architecture: - value: auto - option: [ auto, x86, x86_64, arm64-v8a, armeabi-v7a ] + value: x86_64 + option: [ x86, x86_64, arm64-v8a, armeabi-v7a ] InjectMethod: value: local_patch option: [local_patch, global_patch, outer_inject] @@ -1031,7 +1031,7 @@ Comment: HookOp: Operation: value: apply - option: [ inject, apply ] + option: [ detect, inject, apply ] # ==================== EventShop ====================== diff --git a/module/config/config_generated.py b/module/config/config_generated.py index fa4a1f586..d2dd5a809 100644 --- a/module/config/config_generated.py +++ b/module/config/config_generated.py @@ -489,7 +489,7 @@ class GeneratedConfig: HookGeneral_RestartEveryTime = True HookGeneral_UpdateEveryTime = True HookGeneral_PushEveryTime = True - HookGeneral_Architecture = 'auto' # auto, x86, x86_64, arm64-v8a, armeabi-v7a + HookGeneral_Architecture = 'x86_64' # x86, x86_64, arm64-v8a, armeabi-v7a HookGeneral_InjectMethod = 'local_patch' # local_patch, global_patch, outer_inject HookGeneral_RequestTimeLimit = 10 HookGeneral_UpdateServer = None @@ -661,7 +661,7 @@ class GeneratedConfig: Comment_Content = None # Group `HookOp` - HookOp_Operation = 'apply' # inject, apply + HookOp_Operation = 'apply' # detect, inject, apply # Group `EventShop` EventShop_UnlockSSRShip = True diff --git a/module/config/i18n/en-US.json b/module/config/i18n/en-US.json index 058892988..cf8a22657 100644 --- a/module/config/i18n/en-US.json +++ b/module/config/i18n/en-US.json @@ -2914,7 +2914,6 @@ "Architecture": { "name": "HookGeneral.Architecture.name", "help": "HookGeneral.Architecture.help", - "auto": "auto", "x86": "x86", "x86_64": "x86_64", "arm64-v8a": "arm64-v8a", @@ -3569,6 +3568,7 @@ "Operation": { "name": "HookOp.Operation.name", "help": "HookOp.Operation.help", + "detect": "detect", "inject": "inject", "apply": "apply" } diff --git a/module/config/i18n/ja-JP.json b/module/config/i18n/ja-JP.json index 714a2b4f2..96d25460c 100644 --- a/module/config/i18n/ja-JP.json +++ b/module/config/i18n/ja-JP.json @@ -2914,7 +2914,6 @@ "Architecture": { "name": "HookGeneral.Architecture.name", "help": "HookGeneral.Architecture.help", - "auto": "auto", "x86": "x86", "x86_64": "x86_64", "arm64-v8a": "arm64-v8a", @@ -3569,6 +3568,7 @@ "Operation": { "name": "HookOp.Operation.name", "help": "HookOp.Operation.help", + "detect": "detect", "inject": "inject", "apply": "apply" } diff --git a/module/config/i18n/zh-CN.json b/module/config/i18n/zh-CN.json index 733e5c270..4eea0a947 100644 --- a/module/config/i18n/zh-CN.json +++ b/module/config/i18n/zh-CN.json @@ -2913,8 +2913,7 @@ }, "Architecture": { "name": "架构", - "help": "选择使用的架构,如果自动检测失败,请手动选择\n游戏库目录中看到的架构和选项的对应关系一般如下:\nx86 -> x86\nx86_64 -> x86_64\narm -> armeabi-v7a\narm64 -> arm64-v8a", - "auto": "自动检测", + "help": "选择使用的架构,如果需要自动探测那么在“工具-Hook操作”中使用自动探测\n游戏库目录中看到的架构和选项的对应关系一般如下:\nx86 -> x86\nx86_64 -> x86_64\narm -> armeabi-v7a\narm64 -> arm64-v8a", "x86": "x86", "x86_64": "x86_64", "arm64-v8a": "arm64-v8a", @@ -3569,6 +3568,7 @@ "Operation": { "name": "操作", "help": "", + "detect": "自动探测", "inject": "注入", "apply": "设置Hook" } diff --git a/module/config/i18n/zh-TW.json b/module/config/i18n/zh-TW.json index f751a04d5..f9bc6ccac 100644 --- a/module/config/i18n/zh-TW.json +++ b/module/config/i18n/zh-TW.json @@ -2914,7 +2914,6 @@ "Architecture": { "name": "HookGeneral.Architecture.name", "help": "HookGeneral.Architecture.help", - "auto": "auto", "x86": "x86", "x86_64": "x86_64", "arm64-v8a": "arm64-v8a", @@ -3569,6 +3568,7 @@ "Operation": { "name": "HookOp.Operation.name", "help": "HookOp.Operation.help", + "detect": "detect", "inject": "inject", "apply": "apply" } diff --git a/module/luahook/crack.py b/module/luahook/crack.py index e7fadc14e..a9dac1277 100644 --- a/module/luahook/crack.py +++ b/module/luahook/crack.py @@ -1,6 +1,7 @@ import hashlib import json import os +import time from pathlib import Path from typing import Union, List, Type @@ -179,6 +180,7 @@ class CrackResource: "x86": "x86", "x86_64": "x86", "armv7": "armeabi-v7a", + "arm": "armeabi-v7a", "arm64": "arm64-v8a", "aarch64": "arm64-v8a", "aarch": "armeabi-v7a", @@ -191,11 +193,9 @@ class CrackResource: arch_conf = config.full_config.Hook_HookGeneral_Architecture if arch_conf == "auto": - arch_ret = device.adb_shell("uname -m").lower() - self.arch = self.ARCH_MAP.get(arch_ret, "") - if not self.arch: - raise CrackerError(f"Unsupported arch: {arch_ret}") - logger.info(f"Arch: {arch_ret} -> {self.arch}") + logger.warning("Please Tools-HookOp to auto detect, use default x86_64") + config.full_config.Hook_HookGeneral_Architecture = "x86_64" + self.arch = "x86_64" else: self.arch = arch_conf logger.info(f"Use arch: {self.arch}") @@ -339,6 +339,34 @@ class CrackResource: return self.__is_exist(f"{self.game_lib_dir}/libil2cpp.so") and self.__is_exist( f"{self.game_lib_dir}/libtolua.so") + def auto_detect(self): + if not self.device.app_is_running(): + self.device.app_start() + time.sleep(5) + self.__adb_root() + pid = self.device.adb_shell(f"pidof {self.device.package}") + maps = self.device.adb_shell(f"cat /proc/{pid}/maps") + + image_list = maps.splitlines() + + libtolua_path = None + for image in image_list: + if image.find("libtolua.so") != -1: + libtolua_path = image.split(" ")[-1] + break + if libtolua_path is None: + logger.error("Cannot find libtolua.so path") + return + + game_lib_path = libtolua_path.replace("/libtolua.so", "") + arch = CrackResource.ARCH_MAP[game_lib_path.rsplit("/", maxsplit=1)[-1]] + + logger.info(f"Game lib path: {game_lib_path}") + logger.info(f"Game arch: {arch}") + full_config = self.config.full_config + full_config.Hook_HookGeneral_Architecture = arch + full_config.Hook_HookGeneral_GameLibDir = game_lib_path + def ensure(self): if not self.config.full_config.Hook_HookGeneral_Enable: return