Feature: support process management on rooted Android hosts
Android 7 起 /proc 是 hidepid=2 + SELinux,普通 APK 连其它 PID 都看不到, 因此进程管理做成 root-only:登录时探测 su(常见路径 + which su,都不行再 su -c id 兜底),有 root 才声明 CLIENT_CAP_PROCESS。否定结果只缓存 5 分钟, 避免用户误点一次「拒绝」后整个进程生命周期都用不了。 - 客户端:RootProcess.kt 通过 su 枚举 /proc、批量 kill;子连接协议与 Linux 一致(TOKEN_PSLIST / COMMAND_KILLPROCESS / 空 TOKEN_WSLIST)。 - 服务端:MCP list_processes/kill_process 与 GUI 进程管理对无能力位的 APK 直接回「需要 root」,不再下发 COMMAND_SYSTEM 后干等超时。 验证:Android 编译通过;模拟器上的 su 仅 root:shell 可执行,验证了非 root 拒绝路径(MCP -32005 + GUI 提示)。真 root 设备的枚举/kill 待实机验证。 Model: deepseek-flash Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
1 parent
998c16edc5
commit
b7f87c958a
8 files changed
+447
-10
No files matched your search
@@ -5757,6 +5757,28 @@ VOID CMy2015RemoteDlg::OnOnlineCmdManager()
|
||||
|
||||
VOID CMy2015RemoteDlg::OnOnlineProcessManager()
|
||||
{
|
||||
// Android 只有 root(su)设备才声明 CLIENT_CAP_PROCESS:Android 7 起 /proc 是
|
||||
// hidepid=2 + SELinux,普通 APK 枚举不到其它进程。提前拦下,别让用户以为
|
||||
// 点了没反应(客户端兜底会回一条消息,但主控这边先说清楚更快)。
|
||||
bool blocked = false;
|
||||
EnterCriticalSection(&m_cs);
|
||||
POSITION pos = m_CList_Online.GetFirstSelectedItemPosition();
|
||||
while (pos) {
|
||||
int iItem = m_CList_Online.GetNextSelectedItem(pos);
|
||||
context* ctx = GetContextByListIndex(iItem);
|
||||
if (ctx && ctx->GetAdditionalData(RES_CLIENT_TYPE) == "APK" && !ctx->SupportsProcess()) {
|
||||
blocked = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
LeaveCriticalSection(&m_cs);
|
||||
if (blocked) {
|
||||
MessageBoxL("该 Android 主机未取得 root,无法查看进程列表。\n\n"
|
||||
"Android 7 起 /proc 受 hidepid/SELinux 限制,普通应用无法枚举其它进程。",
|
||||
"提示", MB_ICONINFORMATION);
|
||||
return;
|
||||
}
|
||||
|
||||
BYTE bToken = COMMAND_SYSTEM;
|
||||
SendSelectedCommand(&bToken, sizeof(BYTE));
|
||||
}
|
||||
|
||||
@@ -389,7 +389,9 @@ const char* kServerInstructions =
|
||||
u8"需要声明 CLIENT_CAP_TERMINAL 的新版 APK,老 APK 返回 -32005)、文件管理"
|
||||
u8"(list_files / download_file / upload_file / read_file;路径是盘符形式 I:\\、S:\\、P:\\,"
|
||||
u8"I 是内部存储、S 起是 SD 卡/U 盘、P 是应用私有目录;未授予「所有文件访问」时"
|
||||
u8"I/S 下的文件可能读不了,只能正常使用 P:\\),以及 "
|
||||
u8"I/S 下的文件可能读不了,只能正常使用 P:\\)、进程列表与杀进程"
|
||||
u8"(list_processes / kill_process,仅限取得 root 的设备:Android 7+ 的 /proc 受 "
|
||||
u8"hidepid=2 + SELinux 限制,非 root 设备不声明 CLIENT_CAP_PROCESS,直接返回 -32005),以及 "
|
||||
u8"host_set_remark / host_set_watch_level 这两个只改服务端本地数据的工具。其余一律不支持。\n"
|
||||
u8"copy_files_c2c 是唯一有方向性的工具:源端 src_id 必须是 win,目标端 dst_id 可以是 "
|
||||
u8"win / lnx / mac。Linux 和 macOS 只能当接收方,不能当发送方(反向不支持)。\n"
|
||||
@@ -3154,6 +3156,15 @@ std::string BuildListProcesses(const Json::Value& id, const Json::Value& args, C
|
||||
if (!ctx)
|
||||
return BuildError(id, -32002, "Host not found or offline: " + std::to_string(devId));
|
||||
|
||||
// Android 只有取得 root(su)时才声明 CLIENT_CAP_PROCESS——Android 7+ 的 /proc
|
||||
// 是 hidepid=2 + SELinux,普通 APK 枚举不到其它进程。没有能力位就提前拒绝,
|
||||
// 否则客户端不认 COMMAND_SYSTEM,这里会白等到超时。
|
||||
CString clientType = ctx->GetAdditionalData(RES_CLIENT_TYPE);
|
||||
if (clientType == "APK" && !ctx->SupportsProcess())
|
||||
return BuildError(id, -32005,
|
||||
"process management requires root on Android: this host has no su, "
|
||||
"so it does not declare CLIENT_CAP_PROCESS");
|
||||
|
||||
CMcpServer& mcp = CMcpServer::Instance();
|
||||
if (!mcp.BeginPending(devId, "list_processes"))
|
||||
return BuildError(id, -32003, BusyMessage("Device busy: another request is pending for this host", devId));
|
||||
@@ -3171,8 +3182,7 @@ std::string BuildListProcesses(const Json::Value& id, const Json::Value& args, C
|
||||
// 进程名/路径编码按 clientType 判定:Windows 走 A 接口(QueryFullProcessImageNameA 等)
|
||||
// =客户端 ANSI(GBK/936),不随 CLIENT_CAP_UTF8 转 UTF-8;LNX/MAC/APK 的 /proc 天然 UTF-8。
|
||||
// 不能用 GetClientEncoding——它按能力位返回 CP_UTF8,会误解 Windows 客户端的 GBK 进程名。
|
||||
CString clientType = ctx->GetAdditionalData(RES_CLIENT_TYPE);
|
||||
UINT cp = (clientType == "LNX" || clientType == "MAC") ? CP_UTF8 : 936;
|
||||
UINT cp = (clientType == "LNX" || clientType == "MAC" || clientType == "APK") ? CP_UTF8 : 936;
|
||||
|
||||
Json::Value procs = ParseProcessList(data, cp);
|
||||
|
||||
@@ -9830,8 +9840,11 @@ std::string BuildKillProcess(const Json::Value& id, const Json::Value& args, CMy
|
||||
return BuildError(id, -32005,
|
||||
"macOS client is too old for kill_process: "
|
||||
"it does not declare CLIENT_CAP_PROCESS; upgrade the client first");
|
||||
if (clientType == "APK")
|
||||
return BuildError(id, -32005, "kill_process is only supported on Windows, Linux and macOS hosts");
|
||||
// Android:只有 root(su)设备才声明 CLIENT_CAP_PROCESS(hidepid=2 + SELinux)
|
||||
if (clientType == "APK" && !ctx->SupportsProcess())
|
||||
return BuildError(id, -32005,
|
||||
"kill_process requires root on Android: this host has no su, "
|
||||
"so it does not declare CLIENT_CAP_PROCESS");
|
||||
|
||||
CMcpServer& mcp = CMcpServer::Instance();
|
||||
if (mcp.IsReadonly())
|
||||
@@ -12009,7 +12022,8 @@ const ToolPlatform kToolPlatforms[] = {
|
||||
// 门禁因入参没有 id 而直接放行(与其它服务端本地工具相同)。
|
||||
{ "build_client", kPlatWin|kPlatLnx|kPlatMac|kPlatApk },
|
||||
// ---- win+lnx+mac ---- SYSTEM / LIST_DRIVE / QUERY_LOG / V2 文件传输
|
||||
{ "list_processes", kPlatWin|kPlatLnx|kPlatMac },
|
||||
// Android 只在 root 设备上声明 CLIENT_CAP_PROCESS;工具内部按能力位提前拒绝
|
||||
{ "list_processes", kPlatWin|kPlatLnx|kPlatMac|kPlatApk },
|
||||
// Android 新版实现了 COMMAND_LIST_DRIVE → FileManager 子连接(盘符 I:/S:/P:)。
|
||||
// 老 APK 没有这个实现,却也声明了 CLIENT_CAP_V2,无法按能力位提前区分;
|
||||
// 老包的表现是超时(-32001),升级 APK 即可。
|
||||
@@ -12045,7 +12059,8 @@ const ToolPlatform kToolPlatforms[] = {
|
||||
{ "terminal_close", kPlatWin|kPlatLnx|kPlatMac|kPlatApk },
|
||||
// macOS 客户端有 COMMAND_SYSTEM → SystemManager(proc_listpids + SIGKILL),
|
||||
// 新版声明 CLIENT_CAP_PROCESS;老构建按能力位提前拒绝。
|
||||
{ "kill_process", kPlatWin|kPlatLnx|kPlatMac },
|
||||
// 同上:Android 需要 root,工具内部按 CLIENT_CAP_PROCESS 提前拒绝
|
||||
{ "kill_process", kPlatWin|kPlatLnx|kPlatMac|kPlatApk },
|
||||
// http_probe 要走终端通道(Windows 用 PowerShell、Linux 用 curl)。
|
||||
// macOS 终端已开放,但这里的 POSIX 命令用了 `base64 -w`(GNU 专有),BSD base64
|
||||
// 没有这个开关,头和体都会解不出来——等换成两平台通用的折行写法再放行。
|
||||
|
||||
@@ -2260,3 +2260,4 @@ APK
|
||||
完整性级别受限=Integritaetsstufe eingeschraenkt
|
||||
修复命令已复制到剪贴板。\n\n请按 Win+X 打开「终端(管理员)」,粘贴执行后再重新启动本程序。=Der Reparaturbefehl wurde in die Zwischenablage kopiert.\n\nDruecken Sie Win+X, oeffnen Sie Terminal (Administrator), fuegen Sie den Befehl ein und starten Sie das Programm danach neu.
|
||||
已复制=Kopiert
|
||||
该 Android 主机未取得 root,无法查看进程列表。\n\nAndroid 7 起 /proc 受 hidepid/SELinux 限制,普通应用无法枚举其它进程。=Dieser Android-Host hat kein Root, daher ist die Prozessliste nicht verfuegbar.\n\nAb Android 7 ist /proc durch hidepid/SELinux eingeschraenkt; eine normale App kann keine anderen Prozesse auflisten.
|
||||
@@ -2272,3 +2272,4 @@ APK
|
||||
完整性级别受限=Integrity Level Restricted
|
||||
修复命令已复制到剪贴板。\n\n请按 Win+X 打开「终端(管理员)」,粘贴执行后再重新启动本程序。=The fix command has been copied to the clipboard.\n\nPress Win+X to open Terminal (Admin), paste and run it, then restart this program.
|
||||
已复制=Copied
|
||||
该 Android 主机未取得 root,无法查看进程列表。\n\nAndroid 7 起 /proc 受 hidepid/SELinux 限制,普通应用无法枚举其它进程。=This Android host is not rooted, so the process list is unavailable.\n\nAndroid 7+ restricts /proc with hidepid/SELinux, so a normal app cannot enumerate other processes.
|
||||
@@ -2265,3 +2265,4 @@ APK
|
||||
完整性级别受限=完整性層級受限
|
||||
修复命令已复制到剪贴板。\n\n请按 Win+X 打开「终端(管理员)」,粘贴执行后再重新启动本程序。=修復命令已複製到剪貼簿。\n\n請按 Win+X 開啟「終端機(系統管理員)」,貼上執行後再重新啟動本程式。
|
||||
已复制=已複製
|
||||
该 Android 主机未取得 root,无法查看进程列表。\n\nAndroid 7 起 /proc 受 hidepid/SELinux 限制,普通应用无法枚举其它进程。=該 Android 主機未取得 root,無法查看處理程序清單。\n\nAndroid 7 起 /proc 受 hidepid/SELinux 限制,一般應用程式無法列舉其他處理程序。
|
||||
Reference in new issue
Block a user