From 55f03641aae150e6acf37ec53759a0f1a0c8e727 Mon Sep 17 00:00:00 2001 From: uye <99072975+ABA2396@users.noreply.github.com> Date: Fri, 25 Jul 2025 21:20:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20uuid=20=E4=B8=8E=20version=20=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E9=94=99=E8=AF=AF=E6=A0=BC=E5=BC=8F=E6=97=B6=E5=B4=A9?= =?UTF-8?q?=E6=BA=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix #13351 --- src/MaaCore/Controller/AdbController.cpp | 36 +++++++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/MaaCore/Controller/AdbController.cpp b/src/MaaCore/Controller/AdbController.cpp index e211a58775..dcbd9b236d 100644 --- a/src/MaaCore/Controller/AdbController.cpp +++ b/src/MaaCore/Controller/AdbController.cpp @@ -965,8 +965,21 @@ bool asst::AdbController::connect(const std::string& adb_path, const std::string return false; } - auto& uuid_str = uuid_ret.value(); + std::string raw_output = std::move(uuid_ret.value()); + std::string uuid_str = raw_output; std::erase_if(uuid_str, [](char c) { return !std::isdigit(c) && !std::isalpha(c); }); + + std::regex hex_regex("^[0-9a-fA-F]{8,}$"); + if (uuid_str.empty() || !std::regex_match(uuid_str, hex_regex)) { + json::value info = get_info_json() | json::object { + { "what", "ConnectFailed" }, + { "why", "Uuid invalid or shell command not available" }, + }; + info["details"]["raw_output"] = std::move(raw_output); + callback(AsstMsg::ConnectionInfo, info); + return false; + } + m_uuid = std::move(uuid_str); json::value info = get_info_json() | json::object { @@ -988,9 +1001,24 @@ bool asst::AdbController::connect(const std::string& adb_path, const std::string return false; } - auto& version_str = version_ret.value(); - convert_lf(version_str); - m_version = std::stoul(version_str); + std::string raw_output = version_ret.value(); + convert_lf(raw_output); + + std::erase_if(raw_output, [](char c) { return !std::isalnum(static_cast(c)); }); + bool all_digit = !raw_output.empty() && + ranges::all_of(raw_output, [](char c) { return std::isdigit(static_cast(c)); }); + + if (!all_digit) { + json::value info = get_info_json() | json::object { + { "what", "ConnectFailed" }, + { "why", "Android version invalid or shell command not available" }, + }; + info["details"]["raw_output"] = std::move(version_ret.value()); + callback(AsstMsg::ConnectionInfo, info); + return false; + } + + m_version = std::stoul(raw_output); } if (need_exit()) {