mirror of
https://github.com/kvorschk/Magisk.git
synced 2026-12-04 19:10:47 -05:00
su: add legacy cmd compatibility check
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -68,6 +68,7 @@
|
||||
<string name="thirtymin">30 分钟</string>
|
||||
<string name="sixtymin">60 分钟</string>
|
||||
<string name="su_allow_toast">%1$s 已被授予超级用户权限</string>
|
||||
<string name="su_legacy_cmd">警告:检测到不支持的命令行</string>
|
||||
<string name="su_deny_toast">%1$s 已被拒绝超级用户权限</string>
|
||||
<string name="su_snack_grant">已授予 %1$s 超级用户权限</string>
|
||||
<string name="su_snack_deny">已拒绝 %1$s 超级用户权限</string>
|
||||
|
||||
@@ -59,6 +59,7 @@
|
||||
<string name="grant">Grant</string>
|
||||
<string name="superuser_grant">Grant Superuser</string>
|
||||
<string name="su_allow_toast">%1$s was granted Superuser rights</string>
|
||||
<string name="su_legacy_cmd">Warning: Unsupported command line detected</string>
|
||||
<string name="su_deny_toast">%1$s was denied Superuser rights</string>
|
||||
<string name="su_snack_grant">Superuser rights of %1$s are granted</string>
|
||||
<string name="su_snack_deny">Superuser rights of %1$s are denied</string>
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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<const char *> 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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user