Skip to content

Commit 0676ca3

Browse files
committed
su: warning legacy cmd
1 parent 18fd3b4 commit 0676ca3

7 files changed

Lines changed: 24 additions & 4 deletions

File tree

app/core/src/main/java/com/topjohnwu/magisk/core/su/SuCallbackHandler.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ object SuCallbackHandler {
5757
val toUid = data.getIntComp("to.uid", -1)
5858
val pid = data.getIntComp("pid", -1)
5959
val command = data.getString("command", "")
60+
val legacyCmd = data.getBoolean("legacy_cmd", false)
6061
val target = data.getIntComp("target", -1)
6162
val seContext = data.getString("context", "")
6263
val gids = data.getString("gids", "")
@@ -70,7 +71,7 @@ object SuCallbackHandler {
7071
}.getOrNull() ?: createSuLog(fromUid, toUid, pid, command, policy, target, seContext, gids)
7172

7273
if (notify)
73-
notify(context, log.action >= SuPolicy.ALLOW, log.appName)
74+
notify(context, log.action >= SuPolicy.ALLOW, log.appName, legacyCmd)
7475

7576
runBlocking { ServiceLocator.logRepo.insert(log) }
7677
}
@@ -79,24 +80,30 @@ object SuCallbackHandler {
7980
val uid = data.getIntComp("from.uid", -1)
8081
val pid = data.getIntComp("pid", -1)
8182
val policy = data.getIntComp("policy", SuPolicy.ALLOW)
83+
val legacyCmd = data.getBoolean("legacy_cmd", false)
8284

8385
val pm = context.packageManager
8486

8587
val appName = runCatching {
8688
pm.getPackageInfo(uid, pid)?.applicationInfo?.getLabel(pm)
8789
}.getOrNull() ?: "[UID] $uid"
8890

89-
notify(context, policy >= SuPolicy.ALLOW, appName)
91+
notify(context, policy >= SuPolicy.ALLOW, appName, legacyCmd)
9092
}
9193

92-
private fun notify(context: Context, granted: Boolean, appName: String) {
94+
private fun notify(context: Context, granted: Boolean,
95+
appName: String, legacyCmd: Boolean) {
9396
if (Config.suNotification == Config.Value.NOTIFICATION_TOAST) {
9497
val resId = if (granted)
9598
R.string.su_allow_toast
9699
else
97100
R.string.su_deny_toast
98101

99-
context.toast(context.getString(resId, appName), Toast.LENGTH_SHORT)
102+
var str = context.getString(resId, appName)
103+
if (legacyCmd) {
104+
str += "\n${context.getString(R.string.su_legacy_cmd)}"
105+
}
106+
context.toast(str, Toast.LENGTH_SHORT)
100107
}
101108
}
102109
}

app/core/src/main/res/values-zh-rCN/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
<string name="thirtymin">30 分钟</string>
6565
<string name="sixtymin">60 分钟</string>
6666
<string name="su_allow_toast">%1$s 已被授予超级用户权限</string>
67+
<string name="su_legacy_cmd">警告:检测到不支持的命令行</string>
6768
<string name="su_deny_toast">%1$s 已被拒绝超级用户权限</string>
6869
<string name="su_snack_grant">已授予 %1$s 超级用户权限</string>
6970
<string name="su_snack_deny">已拒绝 %1$s 超级用户权限</string>

app/core/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
<string name="thirtymin">30 mins</string>
6464
<string name="sixtymin">60 mins</string>
6565
<string name="su_allow_toast">%1$s was granted Superuser rights</string>
66+
<string name="su_legacy_cmd">Warning: Unsupported command line detected</string>
6667
<string name="su_deny_toast">%1$s was denied Superuser rights</string>
6768
<string name="su_snack_grant">Superuser rights of %1$s are granted</string>
6869
<string name="su_snack_deny">Superuser rights of %1$s are denied</string>

native/src/core/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ pub mod ffi {
132132
keep_env: bool,
133133
drop_cap: bool,
134134
command: Vec<String>,
135+
legacy_cmd: bool,
135136
context: String,
136137
gids: Vec<u32>,
137138
}

native/src/core/su/connect.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ impl SuAppContext<'_> {
243243
key: "policy",
244244
value: Int(self.settings.policy.repr),
245245
},
246+
Extra {
247+
key: "legacy_cmd",
248+
value: Bool(self.request.legacy_cmd),
249+
},
246250
];
247251
self.exec_cmd("notify", &extras, true);
248252
}
@@ -282,6 +286,10 @@ impl SuAppContext<'_> {
282286
key: "command",
283287
value: Str(command),
284288
},
289+
Extra {
290+
key: "legacy_cmd",
291+
value: Bool(self.request.legacy_cmd),
292+
},
285293
Extra {
286294
key: "notify",
287295
value: Bool(self.settings.notify),

native/src/core/su/daemon.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ impl Default for SuRequest {
2222
keep_env: false,
2323
drop_cap: false,
2424
command: vec![],
25+
legacy_cmd: false,
2526
context: "".to_string(),
2627
gids: vec![],
2728
}

native/src/core/su/su.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ void exec_root_shell(int client, int pid, SuRequest &req, MntNsMode mode) {
415415
if (req.command.size() >= 4 &&
416416
string_view(req.command[1].c_str()) == "-c" &&
417417
string_view(req.command[2].c_str()).find(' ') == string::npos) {
418+
req.legacy_cmd = true;
418419
cmd = req.command[2].c_str();
419420
for (size_t i = 3; i < req.command.size(); ++i) {
420421
cmd += ' ';

0 commit comments

Comments
 (0)