Files
SimpleRemoter/server/2015Remote/context.h
T
yuanyuanxianganddeepseek-flash 36618b0ad0 Feature: Install Android APK updates pushed from the master
The master now sends COMMAND_UPDATE to Android hosts: it picks a
"Build Client -> Android" APK, checks the ZIP magic and that the package
carries this master's fingerprint, then sends [cmd][size][APK][xxh64].
The client verifies length and hash, writes filesDir/update.apk and
commits a PackageInstaller session, so the system installer still asks
the user to confirm - an app cannot replace itself silently. Write and
hash failures come back over TOKEN_CLIENT_MSG, so the master sees why
nothing happened instead of a silently dropped packet.

Sending the wrong file is what the fingerprint check guards against: a
template without the master id installs fine and then cannot connect
back. "Send anyway" is offered only after spelling that out, and the
client advertises CLIENT_CAP_APK_UPDATE (0x0400) so an old APK gets
"install a new build once by hand" instead of a packet it would discard.

Also report the real versionName/versionCode at login instead of the
hardcoded v1.0.0, add android/tools/verify_update_apk.py (pre-send check
of size, ZIP_STORED libs, ABI, package, versionCode and the decrypted
CONNECT_ADDRESS, which it still locates after BuildDlg rewrote szFlag),
and translate the nine new strings in en_US, zh_TW and de_DE.

Verified on the emulator and against the live release server: generate,
sign, send, install, and the device reconnects and re-grants screen
capture. Language packs are GBK and were appended as bytes.

Co-Authored-By: deepseek-flash
2026-11-11 00:53:29 +01:00

161 lines
7.5 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#pragma once
#include "common/header.h"
#include "common/commands.h"
#include <atlstr.h>
enum {
ONLINELIST_IP = 0, // IP的列顺序
ONLINELIST_ADDR, // 地址
ONLINELIST_LOCATION, // 地理位置
ONLINELIST_COMPUTER_NAME, // 计算机名/备注
ONLINELIST_OS, // 操作系统
ONLINELIST_CPU, // CPU
ONLINELIST_VIDEO, // 摄像头(有无)
ONLINELIST_PING, // PING(对方的网速)
ONLINELIST_VERSION, // 版本信息
ONLINELIST_INSTALLTIME, // 安装时间
ONLINELIST_LOGINTIME, // 活动窗口
ONLINELIST_CLIENTTYPE, // 客户端类型
ONLINELIST_PATH, // 文件路径
ONLINELIST_PUBIP,
ONLINELIST_STARTTIME,
ONLINELIST_CAPABILITIES, // 客户端能力位
ONLINELIST_PRIVILEGE, // 权限级别 (SYSTEM/Admin/User)
ONLINELIST_TLS, // TLS 传输启用标志 (0/1)
ONLINELIST_MAX,
};
class context
{
public:
// 纯虚函数
virtual VOID InitMember(SOCKET s, VOID* svr) = 0;
virtual BOOL Send2Client(PBYTE szBuffer, ULONG ulOriginalLength) = 0;
virtual CString GetClientData(int index)const = 0;
virtual void GetAdditionalData(CString(&s)[RES_MAX]) const = 0;
virtual CString GetAdditionalData(int index) const = 0;
virtual uint64_t GetClientID() const = 0;
virtual std::string GetPeerName() const = 0;
virtual int GetPort() const = 0;
virtual std::string GetProtocol() const = 0;
virtual int GetServerPort() const = 0;
virtual FlagType GetFlagType() const = 0;
virtual std::string GetGroupName() const = 0;
virtual uint64_t GetAliveTime()const = 0;
virtual void SetLastHeartbeat(uint64_t time) = 0;
virtual uint64_t GetLastHeartbeat() = 0;
virtual void CancelIO() = 0;
virtual std::string GetMasterID() const = 0;
public:
virtual ~context() {}
virtual void Destroy() {}
virtual BOOL IsLogin() const
{
return TRUE;
}
virtual void SetGroupName(const std::string& group) {}
// 等待本连接待发送缓冲排空(用于「发写命令 → 补发刷新命令」的背靠背发送:
// 两次 Send2Client 会对同一发送缓冲并发 WSASend,造成竞态/丢包)。非 IOCP
// 服务端无异步发送缓冲,默认立即返回 true;CONTEXT_OBJECT 覆写为轮询发送缓冲
// 归零直到排空或超时。
virtual bool WaitSendIdle(int timeoutMs)
{
(void)timeoutMs;
return true;
}
// 检查客户端是否支持 V2 文件传输
bool SupportsFileV2() const {
CString caps = GetClientData(ONLINELIST_CAPABILITIES);
if (caps.IsEmpty()) return false;
return (strtoul(caps.GetString(), nullptr, 16) & CLIENT_CAP_V2) != 0;
}
// 检查客户端是否使用 UTF-8 协议字符串编码。
// 无此能力位的老客户端:服务端按 CP_ACP(CP936,覆盖 95% 的简中/英语 ASCII 老客户端)解读。
bool SupportsUtf8() const {
CString caps = GetClientData(ONLINELIST_CAPABILITIES);
if (caps.IsEmpty()) return false;
return (strtoul(caps.GetString(), nullptr, 16) & CLIENT_CAP_UTF8) != 0;
}
// 检查客户端是否支持按服务端给出的路径清单向另一客户端发送文件(COMMAND_C2C_SEND_FILES)。
// 只有 Windows 客户端实现该命令,老客户端无此能力位 → 服务端据此在 MCP 侧提前拒绝。
bool SupportsC2CPaths() const {
CString caps = GetClientData(ONLINELIST_CAPABILITIES);
if (caps.IsEmpty()) return false;
return (strtoul(caps.GetString(), nullptr, 16) & CLIENT_CAP_C2C_PATHS) != 0;
}
// 检查客户端作为 C2C 目标端时是否回落盘回执(TOKEN_C2C_RECV_RESULT)。
// 目前只有 Linux 客户端声明;没有此能力位的老客户端/Windows 端不回执,
// 服务端据此决定要不要等回执,避免给它们白等。
bool SupportsC2CRecvAck() const {
CString caps = GetClientData(ONLINELIST_CAPABILITIES);
if (caps.IsEmpty()) return false;
return (strtoul(caps.GetString(), nullptr, 16) & CLIENT_CAP_C2C_RECV_ACK) != 0;
}
// 检查客户端是否支持屏幕预览(双击主机时拉缩略图)。
bool SupportsScreenPreview() const {
CString caps = GetClientData(ONLINELIST_CAPABILITIES);
if (caps.IsEmpty()) return false;
return (strtoul(caps.GetString(), nullptr, 16) & CLIENT_CAP_SCREEN_PREVIEW) != 0;
}
// 检查客户端是否支持强制抓取整个虚拟桌面(COMMAND_SCREEN_SPY 参数 buffer[11],
// 即 wire 索引 12;wire [4..11] 是 HWND,不能占用)。
// 多显示器远程控制依赖它:截图与注入共用虚拟桌面坐标系。
bool SupportsVirtualDesktop() const {
CString caps = GetClientData(ONLINELIST_CAPABILITIES);
if (caps.IsEmpty()) return false;
return (strtoul(caps.GetString(), nullptr, 16) & CLIENT_CAP_VIRTUAL_DESKTOP) != 0;
}
// 检查客户端是否支持窗口信息 RPC(COMMAND_MCP_WINDOW_INFO / TOKEN_MCP_WINDOW_INFO):
// 带屏幕矩形、z 序、前后台/最小化状态的窗口列表,以及窗口激活(CMD_WINDOW_ACTIVATE_FLAG)。
// 未声明的老客户端只能走固定 1044 字节、无矩形的 TOKEN_MACHINE_WINDOWS 旧路径。
bool SupportsWindowInfo() const {
CString caps = GetClientData(ONLINELIST_CAPABILITIES);
if (caps.IsEmpty()) return false;
return (strtoul(caps.GetString(), nullptr, 16) & CLIENT_CAP_WINDOW_INFO) != 0;
}
// 检查客户端是否支持区域/窗口/显示器原生分辨率截图(COMMAND_SCREEN_PREVIEW_REQ 的
// v2 扩展,CLIENT_CAP_SCREEN_REGION)。未声明时 get_screenshot 只能整屏抓取。
bool SupportsScreenCapture() const {
CString caps = GetClientData(ONLINELIST_CAPABILITIES);
if (caps.IsEmpty()) return false;
return (strtoul(caps.GetString(), nullptr, 16) & CLIENT_CAP_SCREEN_REGION) != 0;
}
// 检查客户端是否支持远程协议切换(COMMAND_SET_PROTO)。老客户端没有这个命令,
// 收到也会走 default 丢弃,服务端据此把「协议切换」菜单置灰。
bool SupportsProtoSwitch() const {
CString caps = GetClientData(ONLINELIST_CAPABILITIES);
if (caps.IsEmpty()) return false;
return (strtoul(caps.GetString(), nullptr, 16) & CLIENT_CAP_PROTO_SWITCH) != 0;
}
// 检查客户端是否支持收到 COMMAND_UPDATE 下发的 APK 后拉起系统安装器。
// 只有新版 Android 客户端声明;老 APK 收到命令会走 default 静默丢弃,
// 服务端据此提示「先手动装一次新版」。
bool SupportsApkUpdate() const {
CString caps = GetClientData(ONLINELIST_CAPABILITIES);
if (caps.IsEmpty()) return false;
return (strtoul(caps.GetString(), nullptr, 16) & CLIENT_CAP_APK_UPDATE) != 0;
}
// 本机当前是不是靠「生成时内嵌的 TLS 信任锚」在加密(CLIENT_CAP_EMBEDDED_ANCHOR)。
// 这不是能力声明而是运行时状态:只有这种主机在服务端关掉 TLS 后无法自愈——在线时
// 还能收到「取消 TLS」,离线时发 ClientHello 会被 fail-closed 挡掉,再也进不来。
// 服务端据此在「取消 TLS」确认框里提示数量(设计文档 §3.5、§4.9)。
bool UsesEmbeddedAnchor() const {
CString caps = GetClientData(ONLINELIST_CAPABILITIES);
if (caps.IsEmpty()) return false;
return (strtoul(caps.GetString(), nullptr, 16) & CLIENT_CAP_EMBEDDED_ANCHOR) != 0;
}
};