diff --git a/app/core/src/main/java/com/topjohnwu/magisk/core/su/SuCallbackHandler.kt b/app/core/src/main/java/com/topjohnwu/magisk/core/su/SuCallbackHandler.kt index f0a6842fb..cd67c7e0c 100644 --- a/app/core/src/main/java/com/topjohnwu/magisk/core/su/SuCallbackHandler.kt +++ b/app/core/src/main/java/com/topjohnwu/magisk/core/su/SuCallbackHandler.kt @@ -63,6 +63,7 @@ object SuCallbackHandler { val toUid = data.getIntComp("to.uid", -1) val pid = data.getIntComp("pid", -1) val command = data.getString("command", "") + val legacyCmd = data.getBoolean("legacy_cmd", false) val target = data.getIntComp("target", -1) val seContext = data.getString("context", "") val gids = data.getString("gids", "") @@ -76,7 +77,7 @@ object SuCallbackHandler { }.getOrNull() ?: createSuLog(fromUid, toUid, pid, command, policy, target, seContext, gids) if (notify) - notify(context, log.action >= SuPolicy.ALLOW, log.appName) + notify(context, log.action >= SuPolicy.ALLOW, log.appName, legacyCmd) runBlocking { ServiceLocator.logRepo.insert(log) } SuEvents.notifyLogUpdated() @@ -93,17 +94,24 @@ object SuCallbackHandler { pm.getPackageInfo(uid, pid)?.applicationInfo?.getLabel(pm) }.getOrNull() ?: "[UID] $uid" - notify(context, policy >= SuPolicy.ALLOW, appName) + notify(context, policy >= SuPolicy.ALLOW, appName, false) } - private fun notify(context: Context, granted: Boolean, appName: String) { + private fun notify( + context: Context, granted: Boolean, + appName: String, legacyCmd: Boolean + ) { + val resId = if (granted) R.string.su_allow_toast else R.string.su_deny_toast + var str = context.getString(resId, appName) + if (legacyCmd) { + str += "\n${context.getString(R.string.su_legacy_cmd)}" + } when (Config.suNotification) { Config.Value.NOTIFICATION_TOAST -> { - val resId = if (granted) R.string.su_allow_toast else R.string.su_deny_toast - context.toast(context.getString(resId, appName), Toast.LENGTH_SHORT) + context.toast(str, Toast.LENGTH_SHORT) } Config.Value.NOTIFICATION_STATUS_BAR -> { - Notifications.suNotification(granted, appName) + Notifications.suNotification(granted, str) } } } diff --git a/app/core/src/main/java/com/topjohnwu/magisk/core/view/Notifications.kt b/app/core/src/main/java/com/topjohnwu/magisk/core/view/Notifications.kt index 4a28beea0..6ee615801 100644 --- a/app/core/src/main/java/com/topjohnwu/magisk/core/view/Notifications.kt +++ b/app/core/src/main/java/com/topjohnwu/magisk/core/view/Notifications.kt @@ -107,7 +107,7 @@ object Notifications { private const val SU_NOTIFICATION_TIMEOUT_MS = 3_000L @SuppressLint("InlinedApi") - fun suNotification(granted: Boolean, appName: String) { + fun suNotification(granted: Boolean, text: String) { AppContext.apply { val flag = PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT val pending = PendingIntent.getActivity(this, 0, selfLaunchIntent(), flag) @@ -115,11 +115,6 @@ object Notifications { if (granted) R.string.su_notification_granted_title else R.string.su_notification_denied_title ) - val text = getString( - if (granted) R.string.su_allow_toast - else R.string.su_deny_toast, - appName - ) val builder = if (SDK_INT >= Build.VERSION_CODES.O) { Notification.Builder(this, SU_CHANNEL) .setSmallIcon(getBitmap(R.drawable.ic_magisk_outline).toIcon()) diff --git a/app/core/src/main/res/values-zh-rCN/strings.xml b/app/core/src/main/res/values-zh-rCN/strings.xml index 5e4478dae..838b6931d 100644 --- a/app/core/src/main/res/values-zh-rCN/strings.xml +++ b/app/core/src/main/res/values-zh-rCN/strings.xml @@ -68,6 +68,7 @@ 30 分钟 60 分钟 %1$s 已被授予超级用户权限 + 警告:检测到不支持的命令行 %1$s 已被拒绝超级用户权限 已授予 %1$s 超级用户权限 已拒绝 %1$s 超级用户权限 diff --git a/app/core/src/main/res/values/strings.xml b/app/core/src/main/res/values/strings.xml index 473d7f6bc..20b9babaf 100644 --- a/app/core/src/main/res/values/strings.xml +++ b/app/core/src/main/res/values/strings.xml @@ -59,6 +59,7 @@ Grant Grant Superuser %1$s was granted Superuser rights + Warning: Unsupported command line detected %1$s was denied Superuser rights Superuser rights of %1$s are granted Superuser rights of %1$s are denied diff --git a/native/src/core/su/connect.rs b/native/src/core/su/connect.rs index 58e9e584b..acee435ef 100644 --- a/native/src/core/su/connect.rs +++ b/native/src/core/su/connect.rs @@ -109,7 +109,15 @@ impl MagiskD { } fn app_notify(&self, cred: &UCred, info: &SuInfo, request: &SuRequest) { - let command = &request.command.join(" "); + let mut command = request.command.join(" "); + let mut legacy_cmd = false; + if request.command.len() >= 4 + && request.command[1] == "-c" + && !request.command[2].contains(b" ") + { + command = format!("(Syntax Error) {}", command); + legacy_cmd = true; + } let extras = [ Extra { key: "from.uid", @@ -141,7 +149,11 @@ impl MagiskD { }, Extra { key: "command", - value: Str(command), + value: Str(&command), + }, + Extra { + key: "legacy_cmd", + value: Bool(legacy_cmd), }, Extra { key: "notify", diff --git a/native/src/core/su/su.cpp b/native/src/core/su/su.cpp index 5af39148b..7c97d1295 100644 --- a/native/src/core/su/su.cpp +++ b/native/src/core/su/su.cpp @@ -224,7 +224,7 @@ end: interactive |= !has_command; // Determine which one of our streams are attached to a TTY int atty = 0; - if (isatty(STDIN_FILENO) && interactive) atty |= ATTY_IN; + if (isatty(STDIN_FILENO) && interactive) atty |= ATTY_IN; if (isatty(STDOUT_FILENO) && interactive) atty |= ATTY_OUT; if (isatty(STDERR_FILENO) && interactive) atty |= ATTY_ERR; @@ -410,8 +410,25 @@ void exec_root_shell(int client, int pid, SuRequest &req, MntNsMode mode) { } vector argv; - for (auto &str: req.command) { - argv.push_back(str.c_str()); + string cmd; + if (req.command.size() >= 4 && + string_view(req.command[1].c_str()) == "-c" && + string_view(req.command[2].c_str()).find(' ') == string::npos) { + cmd = req.command[2].c_str(); + for (size_t i = 3; i < req.command.size(); ++i) { + cmd += ' '; + cmd += req.command[i].c_str(); + } + + argv.reserve(4); + argv.push_back(req.command[0].c_str()); + argv.push_back(req.command[1].c_str()); + argv.push_back(cmd.c_str()); + } else { + argv.reserve(req.command.size() + 1); + for (auto &arg: req.command) { + argv.push_back(arg.c_str()); + } } argv.push_back(nullptr);