mirror of
https://github.com/kunkundi/crossdesk.git
synced 2026-07-01 03:19:31 +08:00
Compare commits
10 Commits
v1.3.4
...
06c53fdc9c
| Author | SHA1 | Date | |
|---|---|---|---|
| 06c53fdc9c | |||
| 665f4e684c | |||
| 52b894fe0e | |||
| 82c0cbbad4 | |||
| ce004af379 | |||
| 15bd9e9fdc | |||
| 37aabeaf72 | |||
| 473737ac9b | |||
| 1e29ec708f | |||
| 515d517a99 |
@@ -242,6 +242,11 @@ jobs:
|
||||
cd "${{ github.workspace }}\scripts\windows"
|
||||
makensis /DVERSION=$env:VERSION_NUM nsis_script.nsi
|
||||
|
||||
- name: Build Portable CrossDesk
|
||||
run: |
|
||||
xmake f --CROSSDESK_VERSION=${{ env.VERSION_NUM }} --USE_CUDA=true --CROSSDESK_PORTABLE=true -y
|
||||
xmake b -vy crossdesk
|
||||
|
||||
- name: Package Portable
|
||||
shell: pwsh
|
||||
run: |
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
||||
|
||||
<!-- 应用程序标识 -->
|
||||
<assemblyIdentity
|
||||
version="1.0.0.0"
|
||||
processorArchitecture="*"
|
||||
name="CrossDesk"
|
||||
type="win32" />
|
||||
|
||||
<!-- 描述信息 -->
|
||||
<description>CrossDesk Application</description>
|
||||
|
||||
<!-- 权限:要求管理员运行 -->
|
||||
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
<security>
|
||||
<requestedPrivileges>
|
||||
@@ -20,24 +16,17 @@
|
||||
</security>
|
||||
</trustInfo>
|
||||
|
||||
<!-- DPI 感知设置:支持高分屏 -->
|
||||
<application xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
<windowsSettings>
|
||||
<!-- Windows Vista/7 风格 DPI 感知 -->
|
||||
<dpiAware>true/pm</dpiAware>
|
||||
<!-- Windows 10/11 高级 DPI 感知 -->
|
||||
<dpiAwareness>PerMonitorV2</dpiAwareness>
|
||||
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/pm</dpiAware>
|
||||
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
|
||||
</windowsSettings>
|
||||
</application>
|
||||
|
||||
<!-- Windows 兼容性声明 -->
|
||||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||
<application>
|
||||
<!-- 支持 Windows 10 -->
|
||||
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
|
||||
<!-- 支持 Windows 11(向下兼容 Win10 GUID) -->
|
||||
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
|
||||
</application>
|
||||
</compatibility>
|
||||
|
||||
</assembly>
|
||||
</assembly>
|
||||
|
||||
@@ -1,2 +1,11 @@
|
||||
// Application icon resource; load by the resource name IDI_ICON1.
|
||||
IDI_ICON1 ICON "..\\..\\icons\\windows\\crossdesk.ico"
|
||||
|
||||
#define CREATEPROCESS_MANIFEST_RESOURCE_ID 1
|
||||
#define RT_MANIFEST 24
|
||||
|
||||
#ifdef CROSSDESK_DEBUG
|
||||
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "crossdesk_debug.manifest"
|
||||
#else
|
||||
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "crossdesk.manifest"
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
||||
|
||||
<assemblyIdentity
|
||||
version="1.0.0.0"
|
||||
name="CrossDesk"
|
||||
type="win32" />
|
||||
|
||||
<description>CrossDesk Application</description>
|
||||
|
||||
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
<security>
|
||||
<requestedPrivileges>
|
||||
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
|
||||
</requestedPrivileges>
|
||||
</security>
|
||||
</trustInfo>
|
||||
|
||||
<application xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
<windowsSettings>
|
||||
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/pm</dpiAware>
|
||||
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
|
||||
</windowsSettings>
|
||||
</application>
|
||||
|
||||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||
<application>
|
||||
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
|
||||
</application>
|
||||
</compatibility>
|
||||
|
||||
</assembly>
|
||||
@@ -40,7 +40,7 @@ typedef enum {
|
||||
wheel_horizontal
|
||||
} MouseFlag;
|
||||
typedef enum { key_down = 0, key_up } KeyFlag;
|
||||
typedef enum { send_sas = 0 } ServiceCommandFlag;
|
||||
typedef enum { send_sas = 0, lock_workstation } ServiceCommandFlag;
|
||||
typedef struct {
|
||||
float x;
|
||||
float y;
|
||||
@@ -235,4 +235,4 @@ class DeviceController {
|
||||
// virtual int Unhook();
|
||||
};
|
||||
} // namespace crossdesk
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -269,10 +269,30 @@ inline bool IsFunctionKey(int key_code) {
|
||||
}
|
||||
}
|
||||
|
||||
CGEventFlags ToCGEventFlags(uint32_t injected_flags) {
|
||||
CGEventFlags flags = 0;
|
||||
if ((injected_flags & kMacInjectedModifierShift) != 0) {
|
||||
flags |= kCGEventFlagMaskShift;
|
||||
}
|
||||
if ((injected_flags & kMacInjectedModifierControl) != 0) {
|
||||
flags |= kCGEventFlagMaskControl;
|
||||
}
|
||||
if ((injected_flags & kMacInjectedModifierOption) != 0) {
|
||||
flags |= kCGEventFlagMaskAlternate;
|
||||
}
|
||||
if ((injected_flags & kMacInjectedModifierCommand) != 0) {
|
||||
flags |= kCGEventFlagMaskCommand;
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
int KeyboardCapturer::SendKeyboardCommand(int key_code, bool is_down,
|
||||
uint32_t scan_code, bool extended) {
|
||||
(void)scan_code;
|
||||
(void)extended;
|
||||
const uint32_t injected_flags =
|
||||
injected_modifier_state_.Update(key_code, is_down);
|
||||
|
||||
if (vkCodeToCGKeyCode.find(key_code) != vkCodeToCGKeyCode.end()) {
|
||||
CGKeyCode cg_key_code = vkCodeToCGKeyCode[key_code];
|
||||
CGEventRef event = CGEventCreateKeyboardEvent(NULL, cg_key_code, is_down);
|
||||
@@ -281,7 +301,7 @@ int KeyboardCapturer::SendKeyboardCommand(int key_code, bool is_down,
|
||||
return -1;
|
||||
}
|
||||
|
||||
CGEventSetFlags(event, 0);
|
||||
CGEventSetFlags(event, ToCGEventFlags(injected_flags));
|
||||
CGEventPost(kCGHIDEventTap, event);
|
||||
CFRelease(event);
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
|
||||
#include "device_controller.h"
|
||||
#include "macos_keyboard_modifier_state.h"
|
||||
|
||||
namespace crossdesk {
|
||||
|
||||
@@ -36,6 +37,7 @@ class KeyboardCapturer : public DeviceController {
|
||||
bool option_flag_ = false;
|
||||
bool command_flag_ = false;
|
||||
int fn_key_code_ = 0x3F;
|
||||
MacKeyboardModifierState injected_modifier_state_;
|
||||
};
|
||||
} // namespace crossdesk
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* @Author: DI JUNKUN
|
||||
* @Date: 2026-05-21
|
||||
* Copyright (c) 2026 by DI JUNKUN, All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _MACOS_KEYBOARD_MODIFIER_STATE_H_
|
||||
#define _MACOS_KEYBOARD_MODIFIER_STATE_H_
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace crossdesk {
|
||||
|
||||
inline constexpr uint32_t kMacInjectedModifierShift = 1u << 0;
|
||||
inline constexpr uint32_t kMacInjectedModifierControl = 1u << 1;
|
||||
inline constexpr uint32_t kMacInjectedModifierOption = 1u << 2;
|
||||
inline constexpr uint32_t kMacInjectedModifierCommand = 1u << 3;
|
||||
|
||||
class MacKeyboardModifierState {
|
||||
public:
|
||||
uint32_t Update(int key_code, bool is_down) {
|
||||
bool* state = MutableStateForVk(key_code);
|
||||
if (state != nullptr) {
|
||||
*state = is_down;
|
||||
}
|
||||
return flags();
|
||||
}
|
||||
|
||||
uint32_t flags() const {
|
||||
uint32_t result = 0;
|
||||
if (left_shift_down_ || right_shift_down_) {
|
||||
result |= kMacInjectedModifierShift;
|
||||
}
|
||||
if (left_control_down_ || right_control_down_) {
|
||||
result |= kMacInjectedModifierControl;
|
||||
}
|
||||
if (left_option_down_ || right_option_down_) {
|
||||
result |= kMacInjectedModifierOption;
|
||||
}
|
||||
if (left_command_down_ || right_command_down_) {
|
||||
result |= kMacInjectedModifierCommand;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void Clear() {
|
||||
left_shift_down_ = false;
|
||||
right_shift_down_ = false;
|
||||
left_control_down_ = false;
|
||||
right_control_down_ = false;
|
||||
left_option_down_ = false;
|
||||
right_option_down_ = false;
|
||||
left_command_down_ = false;
|
||||
right_command_down_ = false;
|
||||
}
|
||||
|
||||
private:
|
||||
bool* MutableStateForVk(int key_code) {
|
||||
switch (key_code) {
|
||||
case 0xA0: // VK_LSHIFT
|
||||
return &left_shift_down_;
|
||||
case 0xA1: // VK_RSHIFT
|
||||
return &right_shift_down_;
|
||||
case 0xA2: // VK_LCONTROL
|
||||
return &left_control_down_;
|
||||
case 0xA3: // VK_RCONTROL
|
||||
return &right_control_down_;
|
||||
case 0xA4: // VK_LMENU / left Option
|
||||
return &left_option_down_;
|
||||
case 0xA5: // VK_RMENU / right Option
|
||||
return &right_option_down_;
|
||||
case 0x5B: // VK_LWIN / left Command
|
||||
return &left_command_down_;
|
||||
case 0x5C: // VK_RWIN / right Command
|
||||
return &right_command_down_;
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool left_shift_down_ = false;
|
||||
bool right_shift_down_ = false;
|
||||
bool left_control_down_ = false;
|
||||
bool right_control_down_ = false;
|
||||
bool left_option_down_ = false;
|
||||
bool right_option_down_ = false;
|
||||
bool left_command_down_ = false;
|
||||
bool right_command_down_ = false;
|
||||
};
|
||||
|
||||
} // namespace crossdesk
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "mouse_controller.h"
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
#include "rd_log.h"
|
||||
|
||||
namespace crossdesk {
|
||||
@@ -18,7 +20,14 @@ int MouseController::Destroy() { return 0; }
|
||||
|
||||
int MouseController::SendMouseCommand(RemoteAction remote_action,
|
||||
int display_index) {
|
||||
INPUT ip;
|
||||
if (display_index < 0 ||
|
||||
display_index >= static_cast<int>(display_info_list_.size())) {
|
||||
LOG_WARN("Mouse command skipped, invalid display_index={}, displays={}",
|
||||
display_index, display_info_list_.size());
|
||||
return -1;
|
||||
}
|
||||
|
||||
INPUT ip = {0};
|
||||
|
||||
if (remote_action.type == ControlType::mouse) {
|
||||
ip.type = INPUT_MOUSE;
|
||||
@@ -63,13 +72,25 @@ int MouseController::SendMouseCommand(RemoteAction remote_action,
|
||||
|
||||
ip.mi.time = 0;
|
||||
|
||||
SetCursorPos(ip.mi.dx, ip.mi.dy);
|
||||
if (!SetCursorPos(ip.mi.dx, ip.mi.dy)) {
|
||||
LOG_WARN("SetCursorPos failed for mouse x={}, y={}, flag={}, err={}",
|
||||
ip.mi.dx, ip.mi.dy, static_cast<int>(remote_action.m.flag),
|
||||
GetLastError());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ip.mi.dwFlags != MOUSEEVENTF_MOVE) {
|
||||
SendInput(1, &ip, sizeof(INPUT));
|
||||
UINT sent = SendInput(1, &ip, sizeof(INPUT));
|
||||
if (sent != 1) {
|
||||
LOG_WARN(
|
||||
"SendInput failed for mouse x={}, y={}, wheel={}, flag={}, err={}",
|
||||
ip.mi.dx, ip.mi.dy, remote_action.m.s,
|
||||
static_cast<int>(remote_action.m.flag), GetLastError());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
} // namespace crossdesk
|
||||
} // namespace crossdesk
|
||||
|
||||
@@ -51,7 +51,9 @@ struct TranslationRow {
|
||||
X(release_mouse, u8"释放", "Release", u8"Освободить") \
|
||||
X(audio_capture, u8"声音", "Audio", u8"Звук") \
|
||||
X(mute, u8" 静音", " Mute", u8"Без звука") \
|
||||
X(send_shortcut, u8"发送组合键", "Send Shortcut", u8"Сочетания клавиш") \
|
||||
X(send_sas, u8"发送SAS", "Send SAS", u8"Отправить SAS") \
|
||||
X(lock_remote, u8"锁定远端", "Lock Remote", u8"Заблокировать") \
|
||||
X(remote_password_box_visible, u8"远端密码框已出现", \
|
||||
"Remote password box visible", u8"Окно ввода пароля видно") \
|
||||
X(remote_lock_screen_hint, u8"远端处于锁屏封面,可发送SAS", \
|
||||
|
||||
@@ -204,11 +204,11 @@ int Render::ConnectTo(const std::string& remote_id, const char* password,
|
||||
props->params_.user_id = props->local_id_.c_str();
|
||||
props->peer_ = CreatePeer(&props->params_);
|
||||
|
||||
props->control_window_width_ = title_bar_height_ * 9.0f;
|
||||
props->control_window_width_ = title_bar_height_ * 10.0f;
|
||||
props->control_window_height_ = title_bar_height_ * 1.3f;
|
||||
props->control_window_min_width_ = title_bar_height_ * 0.65f;
|
||||
props->control_window_min_height_ = title_bar_height_ * 1.3f;
|
||||
props->control_window_max_width_ = title_bar_height_ * 9.0f;
|
||||
props->control_window_max_width_ = title_bar_height_ * 10.0f;
|
||||
props->control_window_max_height_ = title_bar_height_ * 7.0f;
|
||||
|
||||
props->connection_status_ = ConnectionStatus::Connecting;
|
||||
@@ -272,4 +272,4 @@ int Render::ConnectTo(const std::string& remote_id, const char* password,
|
||||
|
||||
return 0;
|
||||
}
|
||||
} // namespace crossdesk
|
||||
} // namespace crossdesk
|
||||
|
||||
+48
-4
@@ -82,15 +82,22 @@ HICON LoadTrayIcon() {
|
||||
|
||||
struct WindowsServiceInteractiveStatus {
|
||||
bool available = false;
|
||||
bool sas_secure_desktop_grace_active = false;
|
||||
unsigned int error_code = 0;
|
||||
std::string interactive_stage;
|
||||
std::string error;
|
||||
};
|
||||
|
||||
constexpr uint32_t kWindowsServiceStatusIntervalMs = 1000;
|
||||
constexpr DWORD kWindowsServiceQueryTimeoutMs = 100;
|
||||
constexpr uint32_t kWindowsServiceSasSecureDesktopGraceMs = 2000;
|
||||
constexpr DWORD kWindowsServiceQueryTimeoutMs = 500;
|
||||
constexpr DWORD kWindowsServiceSasTimeoutMs = 500;
|
||||
|
||||
bool IsTransientWindowsServiceStatusError(const std::string& error) {
|
||||
return error == "pipe_unavailable" || error == "pipe_connect_failed" ||
|
||||
error == "pipe_read_failed";
|
||||
}
|
||||
|
||||
RemoteAction BuildWindowsServiceStatusAction(
|
||||
const WindowsServiceInteractiveStatus& status) {
|
||||
RemoteAction action{};
|
||||
@@ -125,6 +132,8 @@ bool QueryWindowsServiceInteractiveStatus(
|
||||
}
|
||||
|
||||
status->interactive_stage = json.value("interactive_stage", std::string());
|
||||
status->sas_secure_desktop_grace_active =
|
||||
json.value("sas_secure_desktop_grace_active", false);
|
||||
|
||||
if (ShouldNormalizeUnlockToUserDesktop(
|
||||
json.value("interactive_lock_screen_visible", false),
|
||||
@@ -1923,6 +1932,12 @@ void Render::HandleWindowsServiceIntegration() {
|
||||
LOG_WARN("Remote SAS request failed: {}", response);
|
||||
} else {
|
||||
LOG_INFO("Remote SAS request forwarded to local Windows service");
|
||||
optimistic_windows_secure_desktop_until_tick_ =
|
||||
static_cast<uint32_t>(SDL_GetTicks()) +
|
||||
kWindowsServiceSasSecureDesktopGraceMs;
|
||||
local_service_status_received_ = true;
|
||||
local_service_available_ = true;
|
||||
local_interactive_stage_ = "secure-desktop";
|
||||
}
|
||||
last_windows_service_status_tick_ = 0;
|
||||
force_broadcast = true;
|
||||
@@ -1938,9 +1953,32 @@ void Render::HandleWindowsServiceIntegration() {
|
||||
|
||||
WindowsServiceInteractiveStatus status;
|
||||
const bool status_ok = QueryWindowsServiceInteractiveStatus(&status);
|
||||
local_service_status_received_ = status_ok;
|
||||
WindowsServiceInteractiveStatus broadcast_status = status;
|
||||
const bool previous_secure_desktop_interaction =
|
||||
IsSecureDesktopInteractionRequired(local_interactive_stage_);
|
||||
const bool optimistic_secure_desktop_active =
|
||||
optimistic_windows_secure_desktop_until_tick_ != 0 &&
|
||||
static_cast<int32_t>(optimistic_windows_secure_desktop_until_tick_ -
|
||||
now) > 0;
|
||||
const bool keep_optimistic_secure_desktop =
|
||||
status_ok && status.available && optimistic_secure_desktop_active &&
|
||||
status.sas_secure_desktop_grace_active &&
|
||||
status.interactive_stage == "user-desktop";
|
||||
local_service_status_received_ =
|
||||
status_ok || previous_secure_desktop_interaction;
|
||||
local_service_available_ = status.available;
|
||||
local_interactive_stage_ = status.available ? status.interactive_stage : "";
|
||||
if (status.available) {
|
||||
if (keep_optimistic_secure_desktop) {
|
||||
local_interactive_stage_ = "secure-desktop";
|
||||
broadcast_status.interactive_stage = local_interactive_stage_;
|
||||
} else {
|
||||
local_interactive_stage_ = status.interactive_stage;
|
||||
optimistic_windows_secure_desktop_until_tick_ = 0;
|
||||
}
|
||||
} else if (!previous_secure_desktop_interaction) {
|
||||
local_interactive_stage_.clear();
|
||||
optimistic_windows_secure_desktop_until_tick_ = 0;
|
||||
}
|
||||
|
||||
if (status_ok) {
|
||||
const bool availability_changed =
|
||||
@@ -1953,6 +1991,11 @@ void Render::HandleWindowsServiceIntegration() {
|
||||
if (status.available) {
|
||||
LOG_INFO(
|
||||
"Local Windows service available for secure desktop integration");
|
||||
} else if (IsTransientWindowsServiceStatusError(status.error)) {
|
||||
LOG_INFO(
|
||||
"Local Windows service temporarily unavailable, keeping last "
|
||||
"secure desktop state: error={}, code={}",
|
||||
status.error, status.error_code);
|
||||
} else {
|
||||
LOG_WARN(
|
||||
"Local Windows service unavailable, secure desktop integration "
|
||||
@@ -1973,7 +2016,7 @@ void Render::HandleWindowsServiceIntegration() {
|
||||
last_logged_service_error_code = 0;
|
||||
}
|
||||
|
||||
RemoteAction remote_action = BuildWindowsServiceStatusAction(status);
|
||||
RemoteAction remote_action = BuildWindowsServiceStatusAction(broadcast_status);
|
||||
std::string msg = remote_action.to_json();
|
||||
int ret = SendReliableDataFrame(peer_, msg.data(), msg.size(),
|
||||
control_data_label_.c_str());
|
||||
@@ -1992,6 +2035,7 @@ void Render::ResetLocalWindowsServiceState(bool clear_pending_sas) {
|
||||
local_service_status_received_ = false;
|
||||
local_service_available_ = false;
|
||||
local_interactive_stage_.clear();
|
||||
optimistic_windows_secure_desktop_until_tick_ = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
+4
-2
@@ -115,6 +115,7 @@ class Render {
|
||||
bool is_control_bar_in_left_ = true;
|
||||
bool control_bar_hovered_ = false;
|
||||
bool display_selectable_hovered_ = false;
|
||||
bool shortcut_selectable_hovered_ = false;
|
||||
bool control_bar_expand_ = true;
|
||||
bool reset_control_bar_pos_ = false;
|
||||
bool control_window_width_is_changing_ = false;
|
||||
@@ -125,10 +126,10 @@ class Render {
|
||||
float sub_stream_window_width_ = 1280;
|
||||
float sub_stream_window_height_ = 720;
|
||||
float control_window_min_width_ = 20;
|
||||
float control_window_max_width_ = 230;
|
||||
float control_window_max_width_ = 300;
|
||||
float control_window_min_height_ = 38;
|
||||
float control_window_max_height_ = 180;
|
||||
float control_window_width_ = 230;
|
||||
float control_window_width_ = 300;
|
||||
float control_window_height_ = 38;
|
||||
float control_bar_pos_x_ = 0;
|
||||
float control_bar_pos_y_ = 30;
|
||||
@@ -546,6 +547,7 @@ class Render {
|
||||
std::string local_interactive_stage_;
|
||||
uint32_t last_local_secure_input_block_log_tick_ = 0;
|
||||
uint32_t last_windows_service_status_tick_ = 0;
|
||||
uint32_t optimistic_windows_secure_desktop_until_tick_ = 0;
|
||||
#endif
|
||||
|
||||
// stream window render
|
||||
|
||||
@@ -317,6 +317,22 @@ void LogSecureDesktopInputBlocked(uint32_t* last_tick, const char* side,
|
||||
"cannot drive the Windows password UI",
|
||||
side != nullptr ? side : "unknown", stage != nullptr ? stage : "");
|
||||
}
|
||||
|
||||
bool IsTransientSecureDesktopInputFailure(const nlohmann::json& response,
|
||||
const RemoteAction& action) {
|
||||
if (!response.is_object()) {
|
||||
return false;
|
||||
}
|
||||
if (response.value("error", std::string()) != "send_input_failed") {
|
||||
return false;
|
||||
}
|
||||
if (response.value("code", 0u) != ERROR_ACCESS_DENIED) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return action.type == ControlType::keyboard &&
|
||||
action.k.flag == KeyFlag::key_up;
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace
|
||||
@@ -492,7 +508,7 @@ int Render::ProcessKeyboardEvent(const SDL_Event& event) {
|
||||
|
||||
int Render::ProcessMouseEvent(const SDL_Event& event) {
|
||||
controlled_remote_id_ = "";
|
||||
RemoteAction remote_action;
|
||||
RemoteAction remote_action{};
|
||||
float cursor_x = last_mouse_event.motion.x;
|
||||
float cursor_y = last_mouse_event.motion.y;
|
||||
|
||||
@@ -563,9 +579,9 @@ int Render::ProcessMouseEvent(const SDL_Event& event) {
|
||||
|
||||
const bool file_transfer_window_hovered =
|
||||
props->file_transfer_.file_transfer_window_hovered_;
|
||||
const bool overlay_hovered = props->control_bar_hovered_ ||
|
||||
props->display_selectable_hovered_ ||
|
||||
file_transfer_window_hovered;
|
||||
const bool overlay_hovered =
|
||||
props->control_bar_hovered_ || props->display_selectable_hovered_ ||
|
||||
props->shortcut_selectable_hovered_ || file_transfer_window_hovered;
|
||||
|
||||
const SDL_FRect render_rect = props->stream_render_rect_f_;
|
||||
if (render_rect.w <= 1.0f || render_rect.h <= 1.0f) {
|
||||
@@ -1063,6 +1079,11 @@ void Render::OnReceiveDataBufferCb(const char* data, size_t size,
|
||||
if (remote_action.c.flag == ServiceCommandFlag::send_sas) {
|
||||
render->pending_windows_service_sas_.store(true,
|
||||
std::memory_order_relaxed);
|
||||
} else if (remote_action.c.flag == ServiceCommandFlag::lock_workstation) {
|
||||
if (!LockWorkStation()) {
|
||||
LOG_WARN("Remote lock workstation request failed, error={}",
|
||||
GetLastError());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return;
|
||||
@@ -1099,7 +1120,6 @@ void Render::OnReceiveDataBufferCb(const char* data, size_t size,
|
||||
// remote
|
||||
#if _WIN32
|
||||
if (render->local_service_status_received_ &&
|
||||
render->local_service_available_ &&
|
||||
IsSecureDesktopInteractionRequired(render->local_interactive_stage_)) {
|
||||
if (remote_action.type == ControlType::mouse) {
|
||||
int absolute_x = 0;
|
||||
@@ -1140,6 +1160,14 @@ void Render::OnReceiveDataBufferCb(const char* data, size_t size,
|
||||
remote_action.k.extended, 1000);
|
||||
auto json = nlohmann::json::parse(response, nullptr, false);
|
||||
if (json.is_discarded() || !json.value("ok", false)) {
|
||||
if (!json.is_discarded() &&
|
||||
IsTransientSecureDesktopInputFailure(json, remote_action)) {
|
||||
LOG_INFO(
|
||||
"Secure desktop keyboard injection transient failure, "
|
||||
"key_code={}, is_down={}, response={}",
|
||||
key_code, is_down, response);
|
||||
return;
|
||||
}
|
||||
LogSecureDesktopInputBlocked(
|
||||
&render->last_local_secure_input_block_log_tick_, "local",
|
||||
render->local_interactive_stage_.c_str());
|
||||
|
||||
@@ -163,6 +163,7 @@ int Render::ControlBar(std::shared_ptr<SubStreamWindowProperties>& props) {
|
||||
ImVec2 btn_min = ImGui::GetItemRectMin();
|
||||
ImVec2 btn_size_actual = ImGui::GetItemRectSize();
|
||||
|
||||
props->display_selectable_hovered_ = false;
|
||||
if (ImGui::BeginPopup("display")) {
|
||||
ImGui::SetWindowFontScale(0.5f);
|
||||
for (int i = 0; i < props->display_info_list_.size(); i++) {
|
||||
@@ -178,8 +179,9 @@ int Render::ControlBar(std::shared_ptr<SubStreamWindowProperties>& props) {
|
||||
props->control_data_label_.c_str());
|
||||
}
|
||||
}
|
||||
props->display_selectable_hovered_ = ImGui::IsWindowHovered();
|
||||
}
|
||||
props->display_selectable_hovered_ =
|
||||
ImGui::IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows);
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
@@ -193,6 +195,61 @@ int Render::ControlBar(std::shared_ptr<SubStreamWindowProperties>& props) {
|
||||
text_pos, IM_COL32(0, 0, 0, 255),
|
||||
std::to_string(props->selected_display_ + 1).c_str());
|
||||
|
||||
auto send_service_command = [&](ServiceCommandFlag flag,
|
||||
const char* log_action) {
|
||||
if (props->connection_status_ == ConnectionStatus::Connected &&
|
||||
props->peer_) {
|
||||
RemoteAction remote_action;
|
||||
remote_action.type = ControlType::service_command;
|
||||
remote_action.c.flag = flag;
|
||||
std::string msg = remote_action.to_json();
|
||||
int ret = SendReliableDataFrame(props->peer_, msg.c_str(), msg.size(),
|
||||
props->control_data_label_.c_str());
|
||||
if (ret != 0) {
|
||||
LOG_WARN("Send {} command failed, remote_id={}, ret={}", log_action,
|
||||
props->remote_id_, ret);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ImGui::SameLine();
|
||||
std::string shortcut = ICON_FA_KEYBOARD;
|
||||
ImGui::SetWindowFontScale(0.5f);
|
||||
if (ImGui::Button(shortcut.c_str(), ImVec2(button_width, button_height))) {
|
||||
ImGui::OpenPopup("shortcut");
|
||||
}
|
||||
|
||||
if (ImGui::IsItemHovered()) {
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::SetWindowFontScale(0.5f);
|
||||
ImGui::Text(
|
||||
"%s",
|
||||
localization::send_shortcut[localization_language_index_].c_str());
|
||||
ImGui::SetWindowFontScale(1.0f);
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
|
||||
props->shortcut_selectable_hovered_ = false;
|
||||
if (ImGui::BeginPopup("shortcut")) {
|
||||
ImGui::SetWindowFontScale(0.5f);
|
||||
std::string sas_label =
|
||||
"Ctrl+Alt+Del - " +
|
||||
localization::send_sas[localization_language_index_];
|
||||
std::string lock_label =
|
||||
"Win+L - " + localization::lock_remote[localization_language_index_];
|
||||
if (ImGui::Selectable(sas_label.c_str())) {
|
||||
send_service_command(ServiceCommandFlag::send_sas, "SAS");
|
||||
}
|
||||
if (ImGui::Selectable(lock_label.c_str())) {
|
||||
send_service_command(ServiceCommandFlag::lock_workstation,
|
||||
"remote lock");
|
||||
}
|
||||
props->shortcut_selectable_hovered_ =
|
||||
ImGui::IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows);
|
||||
ImGui::SetWindowFontScale(1.0f);
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
float mouse_x = ImGui::GetCursorScreenPos().x;
|
||||
float mouse_y = ImGui::GetCursorScreenPos().y;
|
||||
@@ -486,4 +543,4 @@ int Render::NetTrafficStats(std::shared_ptr<SubStreamWindowProperties>& props) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
} // namespace crossdesk
|
||||
} // namespace crossdesk
|
||||
|
||||
@@ -1,12 +1,98 @@
|
||||
#include "path_manager.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
|
||||
#ifndef CROSSDESK_PORTABLE
|
||||
#define CROSSDESK_PORTABLE 0
|
||||
#endif
|
||||
|
||||
#if CROSSDESK_PORTABLE
|
||||
#if defined(__APPLE__)
|
||||
#include <mach-o/dyld.h>
|
||||
#elif !defined(_WIN32)
|
||||
#include <limits.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
#if CROSSDESK_PORTABLE
|
||||
std::filesystem::path GetExecutableDirectory() {
|
||||
#ifdef _WIN32
|
||||
std::vector<wchar_t> buffer(MAX_PATH);
|
||||
while (true) {
|
||||
DWORD length =
|
||||
GetModuleFileNameW(nullptr, buffer.data(),
|
||||
static_cast<DWORD>(buffer.size()));
|
||||
if (length == 0) {
|
||||
return {};
|
||||
}
|
||||
if (length < buffer.size()) {
|
||||
return std::filesystem::path(buffer.data(), buffer.data() + length)
|
||||
.parent_path();
|
||||
}
|
||||
if (buffer.size() >= 32768) {
|
||||
return {};
|
||||
}
|
||||
buffer.resize(buffer.size() * 2);
|
||||
}
|
||||
#elif defined(__APPLE__)
|
||||
uint32_t size = 0;
|
||||
_NSGetExecutablePath(nullptr, &size);
|
||||
std::vector<char> buffer(size + 1);
|
||||
if (_NSGetExecutablePath(buffer.data(), &size) != 0) {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::error_code ec;
|
||||
std::filesystem::path executable =
|
||||
std::filesystem::weakly_canonical(buffer.data(), ec);
|
||||
if (ec) {
|
||||
executable = buffer.data();
|
||||
}
|
||||
return executable.parent_path();
|
||||
#else
|
||||
std::vector<char> buffer(PATH_MAX);
|
||||
while (true) {
|
||||
ssize_t length = readlink("/proc/self/exe", buffer.data(),
|
||||
buffer.size() - 1);
|
||||
if (length <= 0) {
|
||||
return {};
|
||||
}
|
||||
if (static_cast<size_t>(length) < buffer.size() - 1) {
|
||||
buffer[static_cast<size_t>(length)] = '\0';
|
||||
return std::filesystem::path(buffer.data()).parent_path();
|
||||
}
|
||||
buffer.resize(buffer.size() * 2);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
std::filesystem::path GetPortableRootPath() {
|
||||
std::filesystem::path executable_dir = GetExecutableDirectory();
|
||||
if (!executable_dir.empty()) {
|
||||
return executable_dir;
|
||||
}
|
||||
|
||||
std::error_code ec;
|
||||
std::filesystem::path current = std::filesystem::current_path(ec);
|
||||
return ec ? std::filesystem::path(".") : current;
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace crossdesk {
|
||||
|
||||
PathManager::PathManager(const std::string& app_name) : app_name_(app_name) {}
|
||||
|
||||
std::filesystem::path PathManager::GetConfigPath() {
|
||||
#if CROSSDESK_PORTABLE
|
||||
return GetPortableRootPath() / "data";
|
||||
#else
|
||||
#ifdef _WIN32
|
||||
return GetKnownFolder(FOLDERID_RoamingAppData) / app_name_;
|
||||
#elif __APPLE__
|
||||
@@ -14,9 +100,13 @@ std::filesystem::path PathManager::GetConfigPath() {
|
||||
#else
|
||||
return GetEnvOrDefault("XDG_CONFIG_HOME", GetHome() + "/.config") / app_name_;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
std::filesystem::path PathManager::GetCachePath() {
|
||||
#if CROSSDESK_PORTABLE
|
||||
return GetPortableRootPath() / "data";
|
||||
#else
|
||||
#ifdef _WIN32
|
||||
#ifdef CROSSDESK_DEBUG
|
||||
return "cache";
|
||||
@@ -28,9 +118,13 @@ std::filesystem::path PathManager::GetCachePath() {
|
||||
#else
|
||||
return GetEnvOrDefault("XDG_CACHE_HOME", GetHome() + "/.cache") / app_name_;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
std::filesystem::path PathManager::GetLogPath() {
|
||||
#if CROSSDESK_PORTABLE
|
||||
return GetPortableRootPath() / "logs";
|
||||
#else
|
||||
#ifdef _WIN32
|
||||
return GetKnownFolder(FOLDERID_LocalAppData) / app_name_ / "logs";
|
||||
#elif __APPLE__
|
||||
@@ -38,6 +132,7 @@ std::filesystem::path PathManager::GetLogPath() {
|
||||
#else
|
||||
return GetCachePath() / "logs";
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
bool PathManager::CreateDirectories(const std::filesystem::path& p) {
|
||||
@@ -93,4 +188,4 @@ std::filesystem::path PathManager::GetEnvOrDefault(const char* env_var,
|
||||
|
||||
return std::filesystem::path(def);
|
||||
}
|
||||
} // namespace crossdesk
|
||||
} // namespace crossdesk
|
||||
|
||||
@@ -29,11 +29,13 @@ namespace {
|
||||
using Json = nlohmann::json;
|
||||
|
||||
constexpr DWORD kSecureDesktopStatusIntervalMs = 250;
|
||||
constexpr DWORD kSecureDesktopStatusPipeTimeoutMs = 150;
|
||||
constexpr DWORD kSecureDesktopStatusPipeTimeoutMs = 500;
|
||||
constexpr DWORD kSecureDesktopHelperPipeTimeoutMs = 120;
|
||||
constexpr DWORD kSecureDesktopTransientErrorGraceMs = 1500;
|
||||
constexpr DWORD kSecureDesktopTransientErrorLogIntervalMs = 5000;
|
||||
constexpr int kSecureDesktopCaptureMinIntervalMs = 100;
|
||||
constexpr int kSecureDesktopCaptureMinFps = 30;
|
||||
constexpr int kSecureDesktopCaptureMaxIntervalMs =
|
||||
1000 / kSecureDesktopCaptureMinFps;
|
||||
|
||||
struct SecureDesktopServiceStatus {
|
||||
bool service_available = false;
|
||||
@@ -129,10 +131,28 @@ class WgcPluginCapturer final : public ScreenCapturer {
|
||||
};
|
||||
|
||||
std::string BuildSecureCaptureCommand(int left, int top, int width, int height,
|
||||
bool show_cursor) {
|
||||
bool show_cursor,
|
||||
const std::string& stage) {
|
||||
std::ostringstream stream;
|
||||
stream << kCrossDeskSecureInputCaptureCommandPrefix << left << ":" << top
|
||||
<< ":" << width << ":" << height << ":" << (show_cursor ? 1 : 0);
|
||||
if (!stage.empty()) {
|
||||
stream << ":" << stage;
|
||||
}
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
std::string BuildSecureCaptureStartCommand(int left, int top, int width,
|
||||
int height, bool show_cursor,
|
||||
int fps,
|
||||
const std::string& stage) {
|
||||
std::ostringstream stream;
|
||||
stream << kCrossDeskSecureInputCaptureStartCommandPrefix << left << ":" << top
|
||||
<< ":" << width << ":" << height << ":" << (show_cursor ? 1 : 0)
|
||||
<< ":" << fps;
|
||||
if (!stage.empty()) {
|
||||
stream << ":" << stage;
|
||||
}
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
@@ -148,6 +168,11 @@ bool IsTransientSecureDesktopFrameError(const std::string& error_message) {
|
||||
error_message.find("\"error\":\"bitblt_failed\"") != std::string::npos;
|
||||
}
|
||||
|
||||
bool IsTransientWindowsServiceStatusError(const std::string& error) {
|
||||
return error == "pipe_unavailable" || error == "pipe_connect_failed" ||
|
||||
error == "pipe_read_failed";
|
||||
}
|
||||
|
||||
bool ReadPipeMessage(HANDLE pipe, std::vector<uint8_t>* response_out,
|
||||
DWORD* error_code_out = nullptr) {
|
||||
if (response_out == nullptr) {
|
||||
@@ -274,17 +299,15 @@ bool QuerySecureDesktopServiceStatus(SecureDesktopServiceStatus* status) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool QuerySecureDesktopHelperFrame(DWORD session_id, int left, int top,
|
||||
int width, int height, bool show_cursor,
|
||||
std::vector<uint8_t>* nv12_frame_out,
|
||||
int* captured_width_out,
|
||||
int* captured_height_out,
|
||||
std::string* error_out) {
|
||||
if (nv12_frame_out == nullptr || captured_width_out == nullptr ||
|
||||
captured_height_out == nullptr) {
|
||||
bool QuerySecureDesktopHelperCommand(DWORD session_id,
|
||||
const std::string& command,
|
||||
std::vector<uint8_t>* response_out,
|
||||
std::string* error_out) {
|
||||
if (response_out == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
response_out->clear();
|
||||
const std::wstring pipe_name =
|
||||
GetCrossDeskSecureInputHelperPipeName(session_id);
|
||||
if (!WaitNamedPipeW(pipe_name.c_str(), kSecureDesktopHelperPipeTimeoutMs)) {
|
||||
@@ -306,8 +329,6 @@ bool QuerySecureDesktopHelperFrame(DWORD session_id, int left, int top,
|
||||
DWORD pipe_mode = PIPE_READMODE_MESSAGE;
|
||||
SetNamedPipeHandleState(pipe, &pipe_mode, nullptr, nullptr);
|
||||
|
||||
const std::string command =
|
||||
BuildSecureCaptureCommand(left, top, width, height, show_cursor);
|
||||
DWORD bytes_written = 0;
|
||||
if (!WriteFile(pipe, command.data(), static_cast<DWORD>(command.size()),
|
||||
&bytes_written, nullptr)) {
|
||||
@@ -319,9 +340,8 @@ bool QuerySecureDesktopHelperFrame(DWORD session_id, int left, int top,
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> response;
|
||||
DWORD read_error = 0;
|
||||
const bool read_ok = ReadPipeMessage(pipe, &response, &read_error);
|
||||
const bool read_ok = ReadPipeMessage(pipe, response_out, &read_error);
|
||||
CloseHandle(pipe);
|
||||
if (!read_ok) {
|
||||
if (error_out != nullptr) {
|
||||
@@ -330,6 +350,29 @@ bool QuerySecureDesktopHelperFrame(DWORD session_id, int left, int top,
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool QuerySecureDesktopHelperFrame(DWORD session_id, int left, int top,
|
||||
int width, int height, bool show_cursor,
|
||||
const std::string& stage,
|
||||
std::vector<uint8_t>* nv12_frame_out,
|
||||
int* captured_width_out,
|
||||
int* captured_height_out,
|
||||
std::string* error_out) {
|
||||
if (nv12_frame_out == nullptr || captured_width_out == nullptr ||
|
||||
captured_height_out == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string command =
|
||||
BuildSecureCaptureCommand(left, top, width, height, show_cursor, stage);
|
||||
std::vector<uint8_t> response;
|
||||
if (!QuerySecureDesktopHelperCommand(session_id, command, &response,
|
||||
error_out)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ParseSecureDesktopFrameResponse(response, nv12_frame_out,
|
||||
captured_width_out,
|
||||
captured_height_out, error_out);
|
||||
@@ -496,6 +539,7 @@ int ScreenCapturerWin::Stop() {
|
||||
ret = impl_->Stop();
|
||||
}
|
||||
StopSecureCaptureThread();
|
||||
StopSecureDesktopSharedCapture(secure_shared_session_id_);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -616,10 +660,239 @@ bool ScreenCapturerWin::GetCurrentCaptureRegion(int* left, int* top, int* width,
|
||||
return true;
|
||||
}
|
||||
|
||||
void ScreenCapturerWin::CloseSecureDesktopSharedFrame() {
|
||||
if (secure_frame_view_ != nullptr) {
|
||||
UnmapViewOfFile(secure_frame_view_);
|
||||
secure_frame_view_ = nullptr;
|
||||
}
|
||||
if (secure_frame_ready_event_ != nullptr) {
|
||||
CloseHandle(secure_frame_ready_event_);
|
||||
secure_frame_ready_event_ = nullptr;
|
||||
}
|
||||
if (secure_frame_mapping_ != nullptr) {
|
||||
CloseHandle(secure_frame_mapping_);
|
||||
secure_frame_mapping_ = nullptr;
|
||||
}
|
||||
secure_frame_view_size_ = 0;
|
||||
}
|
||||
|
||||
void ScreenCapturerWin::StopSecureDesktopSharedCapture(DWORD session_id) {
|
||||
DWORD target_session_id = session_id;
|
||||
if (target_session_id == 0xFFFFFFFF) {
|
||||
target_session_id = secure_shared_session_id_;
|
||||
}
|
||||
|
||||
if (secure_shared_capture_started_ &&
|
||||
target_session_id != 0xFFFFFFFF) {
|
||||
std::vector<uint8_t> response;
|
||||
std::string error_message;
|
||||
QuerySecureDesktopHelperCommand(
|
||||
target_session_id, kCrossDeskSecureInputCaptureStopCommand, &response,
|
||||
&error_message);
|
||||
}
|
||||
|
||||
CloseSecureDesktopSharedFrame();
|
||||
secure_shared_capture_started_ = false;
|
||||
secure_shared_session_id_ = 0xFFFFFFFF;
|
||||
secure_shared_left_ = 0;
|
||||
secure_shared_top_ = 0;
|
||||
secure_shared_width_ = 0;
|
||||
secure_shared_height_ = 0;
|
||||
secure_shared_fps_ = 0;
|
||||
secure_shared_show_cursor_ = true;
|
||||
secure_shared_stage_.clear();
|
||||
}
|
||||
|
||||
bool ScreenCapturerWin::OpenSecureDesktopSharedFrame(DWORD session_id,
|
||||
size_t min_size,
|
||||
std::string* error_out) {
|
||||
if (secure_frame_view_ != nullptr &&
|
||||
secure_shared_session_id_ == session_id &&
|
||||
secure_frame_view_size_ >= min_size) {
|
||||
return true;
|
||||
}
|
||||
|
||||
CloseSecureDesktopSharedFrame();
|
||||
|
||||
const std::wstring mapping_name =
|
||||
GetCrossDeskSecureDesktopFrameMappingName(session_id);
|
||||
HANDLE frame_mapping =
|
||||
OpenFileMappingW(FILE_MAP_READ, FALSE, mapping_name.c_str());
|
||||
if (frame_mapping == nullptr) {
|
||||
if (error_out != nullptr) {
|
||||
*error_out = "open_frame_mapping_failed:" +
|
||||
std::to_string(GetLastError());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
auto* frame_view =
|
||||
static_cast<uint8_t*>(MapViewOfFile(frame_mapping, FILE_MAP_READ, 0, 0, 0));
|
||||
if (frame_view == nullptr) {
|
||||
const DWORD error = GetLastError();
|
||||
CloseHandle(frame_mapping);
|
||||
if (error_out != nullptr) {
|
||||
*error_out = "map_frame_view_failed:" + std::to_string(error);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::wstring event_name =
|
||||
GetCrossDeskSecureDesktopFrameReadyEventName(session_id);
|
||||
HANDLE frame_ready_event =
|
||||
OpenEventW(SYNCHRONIZE, FALSE, event_name.c_str());
|
||||
if (frame_ready_event == nullptr) {
|
||||
const DWORD error = GetLastError();
|
||||
UnmapViewOfFile(frame_view);
|
||||
CloseHandle(frame_mapping);
|
||||
if (error_out != nullptr) {
|
||||
*error_out = "open_frame_event_failed:" + std::to_string(error);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
secure_frame_mapping_ = frame_mapping;
|
||||
secure_frame_ready_event_ = frame_ready_event;
|
||||
secure_frame_view_ = frame_view;
|
||||
secure_frame_view_size_ = min_size;
|
||||
secure_shared_session_id_ = session_id;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ScreenCapturerWin::ReadSecureDesktopSharedFrame(
|
||||
DWORD wait_ms, std::vector<uint8_t>* nv12_frame_out, int* width_out,
|
||||
int* height_out, std::string* error_out) {
|
||||
if (nv12_frame_out == nullptr || width_out == nullptr ||
|
||||
height_out == nullptr || secure_frame_view_ == nullptr ||
|
||||
secure_frame_ready_event_ == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const DWORD wait_result = WaitForSingleObject(secure_frame_ready_event_,
|
||||
wait_ms);
|
||||
if (wait_result == WAIT_TIMEOUT) {
|
||||
if (error_out != nullptr) {
|
||||
*error_out = "frame_wait_timeout";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (wait_result != WAIT_OBJECT_0) {
|
||||
if (error_out != nullptr) {
|
||||
*error_out = "frame_wait_failed:" + std::to_string(GetLastError());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
auto* header =
|
||||
reinterpret_cast<CrossDeskSecureDesktopSharedFrameHeader*>(
|
||||
secure_frame_view_);
|
||||
if (header->magic != kCrossDeskSecureDesktopFrameMagic ||
|
||||
header->version != kCrossDeskSecureDesktopFrameVersion) {
|
||||
if (error_out != nullptr) {
|
||||
*error_out = "invalid_shared_frame_header";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (header->writing != 0) {
|
||||
if (error_out != nullptr) {
|
||||
*error_out = "shared_frame_write_in_progress";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const uint32_t sequence = header->sequence;
|
||||
const uint32_t payload_size = header->payload_size;
|
||||
const uint32_t buffer_size = header->buffer_size;
|
||||
if (payload_size == 0 || payload_size > buffer_size ||
|
||||
sizeof(*header) + static_cast<size_t>(payload_size) >
|
||||
secure_frame_view_size_) {
|
||||
if (error_out != nullptr) {
|
||||
*error_out = "invalid_shared_frame_size";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
nv12_frame_out->resize(payload_size);
|
||||
std::memcpy(nv12_frame_out->data(), secure_frame_view_ + sizeof(*header),
|
||||
payload_size);
|
||||
MemoryBarrier();
|
||||
if (header->writing != 0 || header->sequence != sequence) {
|
||||
if (error_out != nullptr) {
|
||||
*error_out = "shared_frame_changed_during_read";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
*width_out = static_cast<int>(header->width);
|
||||
*height_out = static_cast<int>(header->height);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ScreenCapturerWin::StartSecureDesktopSharedCapture(
|
||||
DWORD session_id, int left, int top, int width, int height,
|
||||
const std::string& stage, bool show_cursor, int fps,
|
||||
std::string* error_out) {
|
||||
const size_t payload_size = static_cast<size_t>(width) * height * 3 / 2;
|
||||
const size_t mapping_size =
|
||||
sizeof(CrossDeskSecureDesktopSharedFrameHeader) + payload_size;
|
||||
if (payload_size == 0) {
|
||||
if (error_out != nullptr) {
|
||||
*error_out = "invalid_capture_size";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (secure_shared_capture_started_ &&
|
||||
secure_shared_session_id_ == session_id &&
|
||||
secure_shared_left_ == left && secure_shared_top_ == top &&
|
||||
secure_shared_width_ == width && secure_shared_height_ == height &&
|
||||
secure_shared_stage_ == stage &&
|
||||
secure_shared_show_cursor_ == show_cursor && secure_shared_fps_ == fps &&
|
||||
OpenSecureDesktopSharedFrame(session_id, mapping_size, error_out)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
StopSecureDesktopSharedCapture(secure_shared_session_id_);
|
||||
|
||||
const std::string command =
|
||||
BuildSecureCaptureStartCommand(left, top, width, height, show_cursor, fps,
|
||||
stage);
|
||||
std::vector<uint8_t> response;
|
||||
if (!QuerySecureDesktopHelperCommand(session_id, command, &response,
|
||||
error_out)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Json json = Json::parse(response.begin(), response.end(), nullptr, false);
|
||||
if (json.is_discarded() || !json.value("ok", false)) {
|
||||
if (error_out != nullptr) {
|
||||
*error_out = ExtractPipeTextResponse(response);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
secure_shared_capture_started_ = true;
|
||||
secure_shared_session_id_ = session_id;
|
||||
secure_shared_left_ = left;
|
||||
secure_shared_top_ = top;
|
||||
secure_shared_width_ = width;
|
||||
secure_shared_height_ = height;
|
||||
secure_shared_show_cursor_ = show_cursor;
|
||||
secure_shared_fps_ = fps;
|
||||
secure_shared_stage_ = stage;
|
||||
|
||||
if (!OpenSecureDesktopSharedFrame(session_id, mapping_size, error_out)) {
|
||||
StopSecureDesktopSharedCapture(session_id);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ScreenCapturerWin::SecureDesktopCaptureLoop() {
|
||||
const int frame_interval_ms =
|
||||
fps_ > 0 ? (std::max)(kSecureDesktopCaptureMinIntervalMs, 1000 / fps_)
|
||||
: kSecureDesktopCaptureMinIntervalMs;
|
||||
fps_ > 0 ? (std::min)(kSecureDesktopCaptureMaxIntervalMs, 1000 / fps_)
|
||||
: kSecureDesktopCaptureMaxIntervalMs;
|
||||
ULONGLONG last_status_tick = 0;
|
||||
ULONGLONG last_error_tick = 0;
|
||||
bool last_capture_active = false;
|
||||
@@ -653,6 +926,11 @@ void ScreenCapturerWin::SecureDesktopCaptureLoop() {
|
||||
"Windows capturer secure desktop service available, polling "
|
||||
"session_id={}",
|
||||
status.active_session_id);
|
||||
} else if (IsTransientWindowsServiceStatusError(status.error)) {
|
||||
LOG_INFO(
|
||||
"Windows capturer secure desktop service temporarily unavailable: "
|
||||
"error={}, code={}",
|
||||
status.error, status.error_code);
|
||||
} else {
|
||||
LOG_WARN(
|
||||
"Windows capturer secure desktop service unavailable: "
|
||||
@@ -686,12 +964,14 @@ void ScreenCapturerWin::SecureDesktopCaptureLoop() {
|
||||
}
|
||||
|
||||
if (!status.capture_active || status.active_session_id == 0xFFFFFFFF) {
|
||||
StopSecureDesktopSharedCapture(secure_shared_session_id_);
|
||||
std::this_thread::sleep_for(
|
||||
std::chrono::milliseconds(status.service_available ? 50 : 200));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!status.helper_running) {
|
||||
StopSecureDesktopSharedCapture(secure_shared_session_id_);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(30));
|
||||
continue;
|
||||
}
|
||||
@@ -702,6 +982,7 @@ void ScreenCapturerWin::SecureDesktopCaptureLoop() {
|
||||
int height = 0;
|
||||
std::string display_name;
|
||||
if (!GetCurrentCaptureRegion(&left, &top, &width, &height, &display_name)) {
|
||||
StopSecureDesktopSharedCapture(secure_shared_session_id_);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
continue;
|
||||
}
|
||||
@@ -709,15 +990,40 @@ void ScreenCapturerWin::SecureDesktopCaptureLoop() {
|
||||
int captured_width = 0;
|
||||
int captured_height = 0;
|
||||
std::string error_message;
|
||||
if (QuerySecureDesktopHelperFrame(
|
||||
status.active_session_id, left, top, width, height,
|
||||
show_cursor_.load(std::memory_order_relaxed), &secure_frame,
|
||||
bool frame_delivered = false;
|
||||
const bool show_cursor = show_cursor_.load(std::memory_order_relaxed);
|
||||
const int shared_fps =
|
||||
fps_ > 0 ? (std::max)(kSecureDesktopCaptureMinFps, fps_)
|
||||
: kSecureDesktopCaptureMinFps;
|
||||
|
||||
if (StartSecureDesktopSharedCapture(status.active_session_id, left, top,
|
||||
width, height,
|
||||
status.interactive_stage, show_cursor,
|
||||
shared_fps, &error_message) &&
|
||||
ReadSecureDesktopSharedFrame(
|
||||
static_cast<DWORD>(frame_interval_ms + 20), &secure_frame,
|
||||
&captured_width, &captured_height, &error_message)) {
|
||||
if (cb_orig_ && !secure_frame.empty()) {
|
||||
cb_orig_(secure_frame.data(), static_cast<int>(secure_frame.size()),
|
||||
captured_width, captured_height, display_name.c_str());
|
||||
}
|
||||
} else {
|
||||
frame_delivered = true;
|
||||
}
|
||||
|
||||
if (!frame_delivered &&
|
||||
QuerySecureDesktopHelperFrame(status.active_session_id, left, top,
|
||||
width, height, show_cursor,
|
||||
status.interactive_stage,
|
||||
&secure_frame, &captured_width,
|
||||
&captured_height, &error_message)) {
|
||||
if (cb_orig_ && !secure_frame.empty()) {
|
||||
cb_orig_(secure_frame.data(), static_cast<int>(secure_frame.size()),
|
||||
captured_width, captured_height, display_name.c_str());
|
||||
}
|
||||
frame_delivered = true;
|
||||
}
|
||||
|
||||
if (!frame_delivered) {
|
||||
const bool transient_error =
|
||||
IsTransientSecureDesktopFrameError(error_message);
|
||||
const bool in_grace_period = capture_stage_started_tick != 0 &&
|
||||
@@ -731,10 +1037,19 @@ void ScreenCapturerWin::SecureDesktopCaptureLoop() {
|
||||
continue;
|
||||
}
|
||||
if (now - last_error_tick >= log_interval) {
|
||||
LOG_WARN(
|
||||
"Windows capturer secure desktop frame query failed, stage='{}', "
|
||||
"session_id={}, error={}",
|
||||
status.interactive_stage, status.active_session_id, error_message);
|
||||
if (transient_error) {
|
||||
LOG_INFO(
|
||||
"Windows capturer secure desktop transient frame query failed, "
|
||||
"stage='{}', session_id={}, error={}",
|
||||
status.interactive_stage, status.active_session_id,
|
||||
error_message);
|
||||
} else {
|
||||
LOG_WARN(
|
||||
"Windows capturer secure desktop frame query failed, stage='{}', "
|
||||
"session_id={}, error={}",
|
||||
status.interactive_stage, status.active_session_id,
|
||||
error_message);
|
||||
}
|
||||
last_error_tick = now;
|
||||
}
|
||||
}
|
||||
@@ -742,7 +1057,8 @@ void ScreenCapturerWin::SecureDesktopCaptureLoop() {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(frame_interval_ms));
|
||||
}
|
||||
|
||||
StopSecureDesktopSharedCapture(secure_shared_session_id_);
|
||||
secure_desktop_capture_active_.store(false, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
} // namespace crossdesk
|
||||
} // namespace crossdesk
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <Windows.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
@@ -59,6 +60,19 @@ class ScreenCapturerWin : public ScreenCapturer {
|
||||
int initial_monitor_index_ = 0;
|
||||
std::atomic<bool> secure_desktop_capture_active_{false};
|
||||
std::thread secure_capture_thread_;
|
||||
HANDLE secure_frame_mapping_ = nullptr;
|
||||
HANDLE secure_frame_ready_event_ = nullptr;
|
||||
uint8_t* secure_frame_view_ = nullptr;
|
||||
size_t secure_frame_view_size_ = 0;
|
||||
DWORD secure_shared_session_id_ = 0xFFFFFFFF;
|
||||
int secure_shared_left_ = 0;
|
||||
int secure_shared_top_ = 0;
|
||||
int secure_shared_width_ = 0;
|
||||
int secure_shared_height_ = 0;
|
||||
int secure_shared_fps_ = 0;
|
||||
bool secure_shared_show_cursor_ = true;
|
||||
std::string secure_shared_stage_;
|
||||
bool secure_shared_capture_started_ = false;
|
||||
|
||||
void BuildCanonicalFromImpl();
|
||||
void RebuildAliasesFromImpl();
|
||||
@@ -66,6 +80,19 @@ class ScreenCapturerWin : public ScreenCapturer {
|
||||
void SecureDesktopCaptureLoop();
|
||||
bool GetCurrentCaptureRegion(int* left, int* top, int* width, int* height,
|
||||
std::string* display_name);
|
||||
bool StartSecureDesktopSharedCapture(DWORD session_id, int left, int top,
|
||||
int width, int height,
|
||||
const std::string& stage,
|
||||
bool show_cursor, int fps,
|
||||
std::string* error_out);
|
||||
void StopSecureDesktopSharedCapture(DWORD session_id);
|
||||
bool OpenSecureDesktopSharedFrame(DWORD session_id, size_t min_size,
|
||||
std::string* error_out);
|
||||
bool ReadSecureDesktopSharedFrame(DWORD wait_ms,
|
||||
std::vector<uint8_t>* nv12_frame_out,
|
||||
int* width_out, int* height_out,
|
||||
std::string* error_out);
|
||||
void CloseSecureDesktopSharedFrame();
|
||||
};
|
||||
} // namespace crossdesk
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -13,7 +13,8 @@ namespace crossdesk {
|
||||
|
||||
inline bool IsSecureDesktopInteractionRequired(
|
||||
const std::string& interactive_stage) {
|
||||
return interactive_stage == "credential-ui" ||
|
||||
return interactive_stage == "lock-screen" ||
|
||||
interactive_stage == "credential-ui" ||
|
||||
interactive_stage == "secure-desktop";
|
||||
}
|
||||
|
||||
@@ -38,4 +39,4 @@ inline bool ShouldNormalizeUnlockToUserDesktop(
|
||||
|
||||
} // namespace crossdesk
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -31,6 +31,7 @@ constexpr char kSecureDesktopMouseIpcCommandPrefix[] = "secure-input-mouse:";
|
||||
constexpr wchar_t kCrossDeskClientProcessName[] = L"crossdesk.exe";
|
||||
constexpr DWORD kCrossDeskClientMonitorIntervalMs = 1000;
|
||||
constexpr ULONGLONG kCrossDeskClientMonitorStartupGraceMs = 5000;
|
||||
constexpr ULONGLONG kSasSecureDesktopGraceMs = 15000;
|
||||
|
||||
using SendSasFunction = VOID(WINAPI*)(BOOL);
|
||||
|
||||
@@ -46,6 +47,13 @@ struct InputDesktopInfo {
|
||||
std::string name;
|
||||
};
|
||||
|
||||
struct SecureDesktopMouseRequest {
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int wheel = 0;
|
||||
int flag = 0;
|
||||
};
|
||||
|
||||
struct ScopedEnvironmentBlock {
|
||||
~ScopedEnvironmentBlock() {
|
||||
if (environment != nullptr) {
|
||||
@@ -255,8 +263,8 @@ bool GrantCrossDeskServiceStartAccessToAuthenticatedUsers(SC_HANDLE service) {
|
||||
std::string QueryNamedPipeMessage(const std::wstring& pipe_name,
|
||||
const std::string& command,
|
||||
DWORD timeout_ms) {
|
||||
constexpr int kPipeConnectRetryCount = 3;
|
||||
constexpr DWORD kPipeConnectRetryDelayMs = 15;
|
||||
const ULONGLONG deadline_tick = GetTickCount64() + timeout_ms;
|
||||
|
||||
auto is_transient_pipe_error = [](DWORD error) {
|
||||
return error == ERROR_FILE_NOT_FOUND || error == ERROR_PIPE_BUSY ||
|
||||
@@ -264,12 +272,23 @@ std::string QueryNamedPipeMessage(const std::wstring& pipe_name,
|
||||
};
|
||||
|
||||
HANDLE pipe = INVALID_HANDLE_VALUE;
|
||||
for (int attempt = 0; attempt < kPipeConnectRetryCount; ++attempt) {
|
||||
if (!WaitNamedPipeW(pipe_name.c_str(), timeout_ms)) {
|
||||
DWORD last_error = ERROR_SEM_TIMEOUT;
|
||||
while (GetTickCount64() <= deadline_tick) {
|
||||
const ULONGLONG now = GetTickCount64();
|
||||
const DWORD wait_timeout =
|
||||
deadline_tick > now
|
||||
? static_cast<DWORD>((std::min)(
|
||||
deadline_tick - now, static_cast<ULONGLONG>(MAXDWORD)))
|
||||
: 0;
|
||||
|
||||
if (!WaitNamedPipeW(pipe_name.c_str(), wait_timeout)) {
|
||||
const DWORD error = GetLastError();
|
||||
if (attempt + 1 < kPipeConnectRetryCount &&
|
||||
is_transient_pipe_error(error)) {
|
||||
Sleep(kPipeConnectRetryDelayMs);
|
||||
last_error = error;
|
||||
const ULONGLONG retry_tick = GetTickCount64();
|
||||
if (is_transient_pipe_error(error) && retry_tick < deadline_tick) {
|
||||
Sleep(static_cast<DWORD>((std::min)(
|
||||
static_cast<ULONGLONG>(kPipeConnectRetryDelayMs),
|
||||
deadline_tick - retry_tick)));
|
||||
continue;
|
||||
}
|
||||
return BuildErrorJson("pipe_unavailable", error);
|
||||
@@ -282,14 +301,21 @@ std::string QueryNamedPipeMessage(const std::wstring& pipe_name,
|
||||
}
|
||||
|
||||
const DWORD error = GetLastError();
|
||||
if (attempt + 1 < kPipeConnectRetryCount &&
|
||||
is_transient_pipe_error(error)) {
|
||||
Sleep(kPipeConnectRetryDelayMs);
|
||||
last_error = error;
|
||||
const ULONGLONG retry_tick = GetTickCount64();
|
||||
if (is_transient_pipe_error(error) && retry_tick < deadline_tick) {
|
||||
Sleep(static_cast<DWORD>((std::min)(
|
||||
static_cast<ULONGLONG>(kPipeConnectRetryDelayMs),
|
||||
deadline_tick - retry_tick)));
|
||||
continue;
|
||||
}
|
||||
return BuildErrorJson("pipe_connect_failed", error);
|
||||
}
|
||||
|
||||
if (pipe == INVALID_HANDLE_VALUE) {
|
||||
return BuildErrorJson("pipe_unavailable", last_error);
|
||||
}
|
||||
|
||||
DWORD pipe_mode = PIPE_READMODE_MESSAGE;
|
||||
SetNamedPipeHandleState(pipe, &pipe_mode, nullptr, nullptr);
|
||||
|
||||
@@ -330,12 +356,27 @@ std::string BuildSecureDesktopMouseIpcCommand(int x, int y, int wheel,
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
std::string BuildSecureInputHelperKeyboardCommand(int key_code, bool is_down,
|
||||
uint32_t scan_code,
|
||||
bool extended) {
|
||||
std::string BuildSecureInputHelperKeyboardCommand(
|
||||
int key_code, bool is_down, uint32_t scan_code, bool extended,
|
||||
const std::string& interactive_stage) {
|
||||
std::ostringstream stream;
|
||||
stream << kCrossDeskSecureInputKeyboardCommandPrefix << key_code << ":"
|
||||
<< (is_down ? 1 : 0) << ":" << scan_code << ":" << (extended ? 1 : 0);
|
||||
if (!interactive_stage.empty()) {
|
||||
stream << ":" << interactive_stage;
|
||||
}
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
std::string BuildSecureInputHelperMouseCommand(
|
||||
int x, int y, int wheel, int flag,
|
||||
const std::string& interactive_stage) {
|
||||
std::ostringstream stream;
|
||||
stream << kCrossDeskSecureInputMouseCommandPrefix << x << ":" << y << ":"
|
||||
<< wheel << ":" << flag;
|
||||
if (!interactive_stage.empty()) {
|
||||
stream << ":" << interactive_stage;
|
||||
}
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
@@ -412,6 +453,57 @@ bool ParseSecureDesktopKeyboardIpcCommand(const std::string& command,
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ParseSecureDesktopMouseIpcCommand(const std::string& command,
|
||||
SecureDesktopMouseRequest* request_out) {
|
||||
if (request_out == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (command.rfind(kSecureDesktopMouseIpcCommandPrefix, 0) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const size_t x_begin = sizeof(kSecureDesktopMouseIpcCommandPrefix) - 1;
|
||||
size_t separator = command.find(':', x_begin);
|
||||
if (separator == std::string::npos) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
request_out->x = std::stoi(command.substr(x_begin, separator - x_begin));
|
||||
} catch (...) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const size_t y_begin = separator + 1;
|
||||
separator = command.find(':', y_begin);
|
||||
if (separator == std::string::npos) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
request_out->y = std::stoi(command.substr(y_begin, separator - y_begin));
|
||||
} catch (...) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const size_t wheel_begin = separator + 1;
|
||||
separator = command.find(':', wheel_begin);
|
||||
if (separator == std::string::npos) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
request_out->wheel =
|
||||
std::stoi(command.substr(wheel_begin, separator - wheel_begin));
|
||||
request_out->flag = std::stoi(command.substr(separator + 1));
|
||||
} catch (...) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CreateSessionSystemToken(DWORD session_id, HANDLE* token_out,
|
||||
DWORD* error_code_out = nullptr) {
|
||||
if (token_out == nullptr) {
|
||||
@@ -499,6 +591,15 @@ const char* DetermineInteractiveStage(bool lock_app_visible,
|
||||
return "user-desktop";
|
||||
}
|
||||
|
||||
std::wstring SecureInputHelperDesktopForStage(
|
||||
const std::string& interactive_stage) {
|
||||
if (interactive_stage == "credential-ui" ||
|
||||
interactive_stage == "secure-desktop") {
|
||||
return L"winsta0\\Winlogon";
|
||||
}
|
||||
return L"winsta0\\default";
|
||||
}
|
||||
|
||||
bool GetSessionUserName(DWORD session_id, std::wstring* username_out) {
|
||||
if (username_out == nullptr) {
|
||||
return false;
|
||||
@@ -927,12 +1028,14 @@ int CrossDeskServiceHost::InitializeRuntime() {
|
||||
session_helper_report_credential_ui_visible_ = false;
|
||||
session_helper_report_unlock_ui_visible_ = false;
|
||||
secure_input_helper_running_ = false;
|
||||
sas_secure_desktop_seen_ = false;
|
||||
last_sas_error_code_ = 0;
|
||||
last_sas_success_ = false;
|
||||
session_helper_started_at_tick_ = 0;
|
||||
session_helper_report_state_age_ms_ = 0;
|
||||
session_helper_report_uptime_ms_ = 0;
|
||||
secure_input_helper_started_at_tick_ = 0;
|
||||
sas_secure_desktop_until_tick_ = 0;
|
||||
session_helper_process_handle_ = nullptr;
|
||||
session_helper_stop_event_ = nullptr;
|
||||
secure_input_helper_process_handle_ = nullptr;
|
||||
@@ -944,6 +1047,7 @@ int CrossDeskServiceHost::InitializeRuntime() {
|
||||
session_helper_report_input_desktop_.clear();
|
||||
session_helper_report_interactive_stage_.clear();
|
||||
secure_input_helper_last_error_.clear();
|
||||
secure_input_helper_interactive_stage_.clear();
|
||||
last_session_event_type_ = 0;
|
||||
last_session_event_session_id_ = active_session_id_;
|
||||
RefreshSessionState();
|
||||
@@ -1219,7 +1323,8 @@ bool CrossDeskServiceHost::IsHelperReportingLockScreenLocked() const {
|
||||
}
|
||||
|
||||
bool CrossDeskServiceHost::HasSecureInputUiLocked() const {
|
||||
return prelogin_ || secure_desktop_active_ || logon_ui_visible_ ||
|
||||
return IsSasSecureDesktopGraceActiveLocked() || prelogin_ ||
|
||||
secure_desktop_active_ || logon_ui_visible_ ||
|
||||
session_helper_report_credential_ui_visible_ ||
|
||||
session_helper_report_secure_desktop_active_ ||
|
||||
session_helper_report_unlock_ui_visible_ ||
|
||||
@@ -1227,6 +1332,30 @@ bool CrossDeskServiceHost::HasSecureInputUiLocked() const {
|
||||
session_helper_report_interactive_stage_ == "secure-desktop";
|
||||
}
|
||||
|
||||
void CrossDeskServiceHost::UpdateSasSecureDesktopGraceLocked(
|
||||
const std::string& observed_stage) {
|
||||
if (sas_secure_desktop_until_tick_ == 0) {
|
||||
sas_secure_desktop_seen_ = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (observed_stage == "credential-ui" || observed_stage == "secure-desktop" ||
|
||||
observed_stage == "lock-screen") {
|
||||
sas_secure_desktop_seen_ = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (sas_secure_desktop_seen_ && observed_stage == "user-desktop") {
|
||||
sas_secure_desktop_until_tick_ = 0;
|
||||
sas_secure_desktop_seen_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool CrossDeskServiceHost::IsSasSecureDesktopGraceActiveLocked() const {
|
||||
return last_sas_success_ && sas_secure_desktop_until_tick_ != 0 &&
|
||||
GetTickCount64() < sas_secure_desktop_until_tick_;
|
||||
}
|
||||
|
||||
bool CrossDeskServiceHost::ShouldKeepSecureInputHelperLocked(
|
||||
DWORD target_session_id) const {
|
||||
if (target_session_id == 0xFFFFFFFF) {
|
||||
@@ -1237,6 +1366,23 @@ bool CrossDeskServiceHost::ShouldKeepSecureInputHelperLocked(
|
||||
IsHelperReportingLockScreenLocked());
|
||||
}
|
||||
|
||||
std::string CrossDeskServiceHost::ResolveInteractiveStageLocked() const {
|
||||
if (IsSasSecureDesktopGraceActiveLocked() &&
|
||||
(session_helper_report_interactive_stage_.empty() ||
|
||||
session_helper_report_interactive_stage_ == "user-desktop")) {
|
||||
return "secure-desktop";
|
||||
}
|
||||
|
||||
if (!session_helper_report_interactive_stage_.empty()) {
|
||||
return session_helper_report_interactive_stage_;
|
||||
}
|
||||
|
||||
return DetermineInteractiveStage(
|
||||
IsHelperReportingLockScreenLocked(),
|
||||
session_helper_report_credential_ui_visible_ || logon_ui_visible_,
|
||||
session_helper_report_secure_desktop_active_ || secure_desktop_active_);
|
||||
}
|
||||
|
||||
std::wstring CrossDeskServiceHost::GetSessionHelperPath() const {
|
||||
std::wstring current_executable = GetCurrentExecutablePathW();
|
||||
if (current_executable.empty()) {
|
||||
@@ -1326,6 +1472,7 @@ void CrossDeskServiceHost::ReapSecureInputHelper() {
|
||||
secure_input_helper_process_id_ = 0;
|
||||
secure_input_helper_exit_code_ = exit_code;
|
||||
secure_input_helper_started_at_tick_ = 0;
|
||||
secure_input_helper_interactive_stage_.clear();
|
||||
}
|
||||
|
||||
if (process_handle != nullptr) {
|
||||
@@ -1384,6 +1531,7 @@ void CrossDeskServiceHost::StopSecureInputHelper() {
|
||||
secure_input_helper_running_ = false;
|
||||
secure_input_helper_process_id_ = 0;
|
||||
secure_input_helper_started_at_tick_ = 0;
|
||||
secure_input_helper_interactive_stage_.clear();
|
||||
}
|
||||
|
||||
if (stop_event_handle != nullptr) {
|
||||
@@ -1511,7 +1659,8 @@ bool CrossDeskServiceHost::LaunchSessionHelper(DWORD session_id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CrossDeskServiceHost::LaunchSecureInputHelper(DWORD session_id) {
|
||||
bool CrossDeskServiceHost::LaunchSecureInputHelper(
|
||||
DWORD session_id, const std::string& interactive_stage) {
|
||||
std::wstring helper_path = GetSecureInputHelperPath();
|
||||
if (helper_path.empty() || !std::filesystem::exists(helper_path)) {
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
@@ -1545,7 +1694,10 @@ bool CrossDeskServiceHost::LaunchSecureInputHelper(DWORD session_id) {
|
||||
|
||||
STARTUPINFOW startup_info{};
|
||||
startup_info.cb = sizeof(startup_info);
|
||||
startup_info.lpDesktop = const_cast<LPWSTR>(L"winsta0\\Winlogon");
|
||||
std::wstring secure_input_helper_desktop =
|
||||
SecureInputHelperDesktopForStage(interactive_stage);
|
||||
startup_info.lpDesktop =
|
||||
const_cast<LPWSTR>(secure_input_helper_desktop.c_str());
|
||||
PROCESS_INFORMATION process_info{};
|
||||
BOOL created = FALSE;
|
||||
|
||||
@@ -1594,10 +1746,14 @@ bool CrossDeskServiceHost::LaunchSecureInputHelper(DWORD session_id) {
|
||||
secure_input_helper_last_error_.clear();
|
||||
secure_input_helper_running_ = true;
|
||||
secure_input_helper_started_at_tick_ = GetTickCount64();
|
||||
secure_input_helper_interactive_stage_ = interactive_stage;
|
||||
}
|
||||
|
||||
LOG_INFO("Secure input helper started: session_id={}, pid={}", session_id,
|
||||
process_info.dwProcessId);
|
||||
LOG_INFO(
|
||||
"Secure input helper started: session_id={}, pid={}, stage='{}', "
|
||||
"desktop='{}'",
|
||||
session_id, process_info.dwProcessId, interactive_stage,
|
||||
WideToUtf8(secure_input_helper_desktop));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1696,6 +1852,7 @@ void CrossDeskServiceHost::RefreshSessionHelperReportedState() {
|
||||
json.value("interactive_stage", std::string());
|
||||
session_helper_report_state_age_ms_ = json.value("state_age_ms", 0ull);
|
||||
session_helper_report_uptime_ms_ = json.value("uptime_ms", 0ull);
|
||||
UpdateSasSecureDesktopGraceLocked(session_helper_report_interactive_stage_);
|
||||
}
|
||||
|
||||
void CrossDeskServiceHost::RecordSessionEvent(DWORD event_type,
|
||||
@@ -1759,7 +1916,13 @@ std::string CrossDeskServiceHost::HandleIpcCommand(const std::string& command) {
|
||||
if (ParseSecureDesktopKeyboardIpcCommand(normalized, &key_code, &is_down,
|
||||
&scan_code, &extended)) {
|
||||
return SendSecureDesktopKeyboardInput(key_code, is_down, scan_code,
|
||||
extended);
|
||||
extended);
|
||||
}
|
||||
SecureDesktopMouseRequest mouse_request;
|
||||
if (ParseSecureDesktopMouseIpcCommand(normalized, &mouse_request)) {
|
||||
return SendSecureDesktopMouseInput(mouse_request.x, mouse_request.y,
|
||||
mouse_request.wheel,
|
||||
mouse_request.flag);
|
||||
}
|
||||
return BuildErrorJson("unknown_command");
|
||||
}
|
||||
@@ -1773,21 +1936,26 @@ std::string CrossDeskServiceHost::BuildStatusResponse() {
|
||||
bool keep_secure_input_helper = false;
|
||||
bool launch_secure_input_helper = false;
|
||||
DWORD secure_input_target_session_id = 0xFFFFFFFF;
|
||||
std::string secure_input_interactive_stage;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
secure_input_target_session_id = active_session_id_;
|
||||
secure_input_interactive_stage = ResolveInteractiveStageLocked();
|
||||
keep_secure_input_helper =
|
||||
ShouldKeepSecureInputHelperLocked(secure_input_target_session_id);
|
||||
launch_secure_input_helper =
|
||||
keep_secure_input_helper &&
|
||||
(!secure_input_helper_running_ ||
|
||||
secure_input_helper_session_id_ != secure_input_target_session_id);
|
||||
secure_input_helper_session_id_ != secure_input_target_session_id ||
|
||||
secure_input_helper_interactive_stage_ !=
|
||||
secure_input_interactive_stage);
|
||||
}
|
||||
|
||||
if (keep_secure_input_helper) {
|
||||
if (launch_secure_input_helper) {
|
||||
StopSecureInputHelper();
|
||||
LaunchSecureInputHelper(secure_input_target_session_id);
|
||||
LaunchSecureInputHelper(secure_input_target_session_id,
|
||||
secure_input_interactive_stage);
|
||||
}
|
||||
} else {
|
||||
StopSecureInputHelper();
|
||||
@@ -1811,7 +1979,11 @@ std::string CrossDeskServiceHost::BuildStatusResponse() {
|
||||
EscapeJsonString(session_helper_report_input_desktop_);
|
||||
std::string secure_input_helper_last_error =
|
||||
EscapeJsonString(secure_input_helper_last_error_);
|
||||
std::string secure_input_helper_interactive_stage =
|
||||
EscapeJsonString(secure_input_helper_interactive_stage_);
|
||||
bool interactive_state_ready = session_helper_status_ok_;
|
||||
const bool sas_secure_desktop_grace_active =
|
||||
IsSasSecureDesktopGraceActiveLocked();
|
||||
const char* interactive_state_source =
|
||||
interactive_state_ready ? "session-helper" : "service-host";
|
||||
const bool effective_session_locked = GetEffectiveSessionLockedLocked();
|
||||
@@ -1825,21 +1997,24 @@ std::string CrossDeskServiceHost::BuildStatusResponse() {
|
||||
bool unlock_ui_visible = interactive_state_ready
|
||||
? session_helper_report_unlock_ui_visible_
|
||||
: (logon_ui_visible_ || secure_desktop_active_);
|
||||
unlock_ui_visible = unlock_ui_visible || sas_secure_desktop_grace_active;
|
||||
bool interactive_secure_desktop_active =
|
||||
interactive_state_ready ? session_helper_report_secure_desktop_active_
|
||||
: secure_desktop_active_;
|
||||
interactive_secure_desktop_active =
|
||||
interactive_secure_desktop_active || sas_secure_desktop_grace_active;
|
||||
bool interactive_logon_ui_visible =
|
||||
interactive_state_ready ? session_helper_report_logon_ui_visible_
|
||||
: logon_ui_visible_;
|
||||
bool interactive_session_locked = effective_session_locked ||
|
||||
interactive_lock_screen_visible ||
|
||||
unlock_ui_visible;
|
||||
unlock_ui_visible ||
|
||||
sas_secure_desktop_grace_active;
|
||||
std::string interactive_input_desktop = EscapeJsonString(
|
||||
interactive_state_ready ? session_helper_report_input_desktop_
|
||||
: input_desktop_name_);
|
||||
std::string interactive_stage = EscapeJsonString(DetermineInteractiveStage(
|
||||
interactive_lock_screen_visible, credential_ui_visible,
|
||||
interactive_secure_desktop_active));
|
||||
std::string raw_interactive_stage = ResolveInteractiveStageLocked();
|
||||
std::string interactive_stage = EscapeJsonString(raw_interactive_stage);
|
||||
std::ostringstream stream;
|
||||
stream << "{\"ok\":true,\"service\":\"CrossDeskService\""
|
||||
<< ",\"active_session_id\":" << active_session_id_
|
||||
@@ -1860,6 +2035,8 @@ std::string CrossDeskServiceHost::BuildStatusResponse() {
|
||||
<< (interactive_logon_ui_visible ? "true" : "false")
|
||||
<< ",\"interactive_secure_desktop_active\":"
|
||||
<< (interactive_secure_desktop_active ? "true" : "false")
|
||||
<< ",\"sas_secure_desktop_grace_active\":"
|
||||
<< (sas_secure_desktop_grace_active ? "true" : "false")
|
||||
<< ",\"unlock_ui_visible\":" << (unlock_ui_visible ? "true" : "false")
|
||||
<< ",\"credential_ui_visible\":"
|
||||
<< (credential_ui_visible ? "true" : "false")
|
||||
@@ -1933,6 +2110,8 @@ std::string CrossDeskServiceHost::BuildStatusResponse() {
|
||||
<< secure_input_helper_last_error << "\""
|
||||
<< ",\"secure_input_helper_last_error_code\":"
|
||||
<< secure_input_helper_last_error_code_
|
||||
<< ",\"secure_input_helper_stage\":\""
|
||||
<< secure_input_helper_interactive_stage << "\""
|
||||
<< ",\"secure_input_helper_uptime_ms\":"
|
||||
<< (secure_input_helper_started_at_tick_ >= started_at_tick_
|
||||
? (GetTickCount64() - secure_input_helper_started_at_tick_)
|
||||
@@ -1962,10 +2141,14 @@ std::string CrossDeskServiceHost::SendSecureAttentionSequence() {
|
||||
SasResult result = SendSasNow();
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
last_sas_tick_ = GetTickCount64();
|
||||
const ULONGLONG now = GetTickCount64();
|
||||
last_sas_tick_ = now;
|
||||
last_sas_success_ = result.success;
|
||||
last_sas_error_code_ = result.error_code;
|
||||
last_sas_error_ = result.error;
|
||||
sas_secure_desktop_until_tick_ =
|
||||
result.success ? now + kSasSecureDesktopGraceMs : 0;
|
||||
sas_secure_desktop_seen_ = false;
|
||||
}
|
||||
|
||||
if (!result.success) {
|
||||
@@ -1979,15 +2162,21 @@ std::string CrossDeskServiceHost::SendSecureDesktopKeyboardInput(
|
||||
RefreshSessionState();
|
||||
ReapSecureInputHelper();
|
||||
EnsureSessionHelper();
|
||||
RefreshSessionHelperReportedState();
|
||||
|
||||
DWORD target_session_id = 0xFFFFFFFF;
|
||||
bool helper_running = false;
|
||||
bool can_inject = false;
|
||||
std::string interactive_stage;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
target_session_id = active_session_id_;
|
||||
interactive_stage = ResolveInteractiveStageLocked();
|
||||
const bool helper_stage_matches =
|
||||
secure_input_helper_interactive_stage_ == interactive_stage;
|
||||
helper_running = secure_input_helper_running_ &&
|
||||
secure_input_helper_session_id_ == target_session_id;
|
||||
secure_input_helper_session_id_ == target_session_id &&
|
||||
helper_stage_matches;
|
||||
can_inject = GetEffectiveSessionLockedLocked() || HasSecureInputUiLocked();
|
||||
}
|
||||
|
||||
@@ -2000,7 +2189,7 @@ std::string CrossDeskServiceHost::SendSecureDesktopKeyboardInput(
|
||||
|
||||
if (!helper_running) {
|
||||
StopSecureInputHelper();
|
||||
if (!LaunchSecureInputHelper(target_session_id)) {
|
||||
if (!LaunchSecureInputHelper(target_session_id, interactive_stage)) {
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
return BuildErrorJson(secure_input_helper_last_error_.c_str(),
|
||||
secure_input_helper_last_error_code_);
|
||||
@@ -2010,7 +2199,53 @@ std::string CrossDeskServiceHost::SendSecureDesktopKeyboardInput(
|
||||
return QueryNamedPipeMessage(
|
||||
GetCrossDeskSecureInputHelperPipeName(target_session_id),
|
||||
BuildSecureInputHelperKeyboardCommand(key_code, is_down, scan_code,
|
||||
extended),
|
||||
extended, interactive_stage),
|
||||
1000);
|
||||
}
|
||||
|
||||
std::string CrossDeskServiceHost::SendSecureDesktopMouseInput(int x, int y,
|
||||
int wheel,
|
||||
int flag) {
|
||||
RefreshSessionState();
|
||||
ReapSecureInputHelper();
|
||||
EnsureSessionHelper();
|
||||
RefreshSessionHelperReportedState();
|
||||
|
||||
DWORD target_session_id = 0xFFFFFFFF;
|
||||
bool helper_running = false;
|
||||
bool can_inject = false;
|
||||
std::string interactive_stage;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
target_session_id = active_session_id_;
|
||||
interactive_stage = ResolveInteractiveStageLocked();
|
||||
const bool helper_stage_matches =
|
||||
secure_input_helper_interactive_stage_ == interactive_stage;
|
||||
helper_running = secure_input_helper_running_ &&
|
||||
secure_input_helper_session_id_ == target_session_id &&
|
||||
helper_stage_matches;
|
||||
can_inject = GetEffectiveSessionLockedLocked() || HasSecureInputUiLocked();
|
||||
}
|
||||
|
||||
if (target_session_id == 0xFFFFFFFF) {
|
||||
return BuildErrorJson("no_active_console_session");
|
||||
}
|
||||
if (!can_inject) {
|
||||
return BuildErrorJson("secure_input_not_active");
|
||||
}
|
||||
|
||||
if (!helper_running) {
|
||||
StopSecureInputHelper();
|
||||
if (!LaunchSecureInputHelper(target_session_id, interactive_stage)) {
|
||||
std::lock_guard<std::mutex> lock(state_mutex_);
|
||||
return BuildErrorJson(secure_input_helper_last_error_.c_str(),
|
||||
secure_input_helper_last_error_code_);
|
||||
}
|
||||
}
|
||||
|
||||
return QueryNamedPipeMessage(
|
||||
GetCrossDeskSecureInputHelperPipeName(target_session_id),
|
||||
BuildSecureInputHelperMouseCommand(x, y, wheel, flag, interactive_stage),
|
||||
1000);
|
||||
}
|
||||
|
||||
@@ -2238,4 +2473,4 @@ std::string SendCrossDeskSecureDesktopMouseInput(int x, int y, int wheel,
|
||||
BuildSecureDesktopMouseIpcCommand(x, y, wheel, flag), timeout_ms);
|
||||
}
|
||||
|
||||
} // namespace crossdesk
|
||||
} // namespace crossdesk
|
||||
|
||||
@@ -45,7 +45,8 @@ class CrossDeskServiceHost {
|
||||
bool LaunchSessionHelper(DWORD session_id);
|
||||
void ReapSecureInputHelper();
|
||||
void StopSecureInputHelper();
|
||||
bool LaunchSecureInputHelper(DWORD session_id);
|
||||
bool LaunchSecureInputHelper(DWORD session_id,
|
||||
const std::string& interactive_stage);
|
||||
std::wstring GetSessionHelperPath() const;
|
||||
std::wstring GetSessionHelperStopEventName(DWORD session_id) const;
|
||||
std::wstring GetSecureInputHelperPath() const;
|
||||
@@ -55,7 +56,10 @@ class CrossDeskServiceHost {
|
||||
bool GetEffectiveSessionLockedLocked() const;
|
||||
bool IsHelperReportingLockScreenLocked() const;
|
||||
bool HasSecureInputUiLocked() const;
|
||||
void UpdateSasSecureDesktopGraceLocked(const std::string& observed_stage);
|
||||
bool IsSasSecureDesktopGraceActiveLocked() const;
|
||||
bool ShouldKeepSecureInputHelperLocked(DWORD target_session_id) const;
|
||||
std::string ResolveInteractiveStageLocked() const;
|
||||
void RefreshSessionHelperReportedState();
|
||||
void RecordSessionEvent(DWORD event_type, DWORD session_id);
|
||||
std::string HandleIpcCommand(const std::string& command);
|
||||
@@ -64,6 +68,7 @@ class CrossDeskServiceHost {
|
||||
std::string SendSecureDesktopKeyboardInput(int key_code, bool is_down,
|
||||
uint32_t scan_code = 0,
|
||||
bool extended = false);
|
||||
std::string SendSecureDesktopMouseInput(int x, int y, int wheel, int flag);
|
||||
|
||||
static void WINAPI ServiceMain(DWORD argc, LPWSTR* argv);
|
||||
static BOOL WINAPI ConsoleControlHandler(DWORD control_type);
|
||||
@@ -100,6 +105,7 @@ class CrossDeskServiceHost {
|
||||
ULONGLONG session_helper_report_state_age_ms_ = 0;
|
||||
ULONGLONG session_helper_report_uptime_ms_ = 0;
|
||||
ULONGLONG secure_input_helper_started_at_tick_ = 0;
|
||||
ULONGLONG sas_secure_desktop_until_tick_ = 0;
|
||||
bool session_locked_ = false;
|
||||
bool logon_ui_visible_ = false;
|
||||
bool prelogin_ = false;
|
||||
@@ -116,6 +122,7 @@ class CrossDeskServiceHost {
|
||||
bool session_helper_report_unlock_ui_visible_ = false;
|
||||
bool secure_input_helper_running_ = false;
|
||||
bool console_mode_ = false;
|
||||
bool sas_secure_desktop_seen_ = false;
|
||||
DWORD last_sas_error_code_ = 0;
|
||||
bool last_sas_success_ = false;
|
||||
HANDLE session_helper_process_handle_ = nullptr;
|
||||
@@ -129,6 +136,7 @@ class CrossDeskServiceHost {
|
||||
std::string session_helper_report_input_desktop_;
|
||||
std::string session_helper_report_interactive_stage_;
|
||||
std::string secure_input_helper_last_error_;
|
||||
std::string secure_input_helper_interactive_stage_;
|
||||
|
||||
static CrossDeskServiceHost* instance_;
|
||||
};
|
||||
@@ -150,4 +158,4 @@ std::string SendCrossDeskSecureDesktopMouseInput(int x, int y, int wheel,
|
||||
|
||||
} // namespace crossdesk
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -23,7 +23,15 @@ inline constexpr char kCrossDeskSecureInputKeyboardCommandPrefix[] =
|
||||
"keyboard:";
|
||||
inline constexpr char kCrossDeskSecureInputMouseCommandPrefix[] = "mouse:";
|
||||
inline constexpr char kCrossDeskSecureInputCaptureCommandPrefix[] = "capture:";
|
||||
inline constexpr char kCrossDeskSecureInputCaptureStartCommandPrefix[] =
|
||||
"capture-start:";
|
||||
inline constexpr char kCrossDeskSecureInputCaptureStopCommand[] =
|
||||
"capture-stop";
|
||||
inline constexpr DWORD kCrossDeskSecureInputPipeBufferBytes = 16 * 1024 * 1024;
|
||||
inline constexpr wchar_t kCrossDeskSecureDesktopFrameMappingPrefix[] =
|
||||
L"Global\\CrossDeskSecureDesktopFrame-";
|
||||
inline constexpr wchar_t kCrossDeskSecureDesktopFrameReadyEventPrefix[] =
|
||||
L"Global\\CrossDeskSecureDesktopFrameReady-";
|
||||
inline constexpr uint32_t kCrossDeskSecureDesktopFrameMagic = 0x50444358;
|
||||
inline constexpr uint32_t kCrossDeskSecureDesktopFrameVersion = 1;
|
||||
|
||||
@@ -37,6 +45,19 @@ struct CrossDeskSecureDesktopFrameHeader {
|
||||
uint32_t height;
|
||||
uint32_t payload_size;
|
||||
};
|
||||
|
||||
struct CrossDeskSecureDesktopSharedFrameHeader {
|
||||
uint32_t magic;
|
||||
uint32_t version;
|
||||
volatile uint32_t writing;
|
||||
uint32_t sequence;
|
||||
int32_t left;
|
||||
int32_t top;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t payload_size;
|
||||
uint32_t buffer_size;
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
inline std::wstring GetCrossDeskSessionHelperPipeName(DWORD session_id) {
|
||||
@@ -49,6 +70,18 @@ inline std::wstring GetCrossDeskSecureInputHelperPipeName(DWORD session_id) {
|
||||
std::to_wstring(session_id);
|
||||
}
|
||||
|
||||
inline std::wstring GetCrossDeskSecureDesktopFrameMappingName(
|
||||
DWORD session_id) {
|
||||
return std::wstring(kCrossDeskSecureDesktopFrameMappingPrefix) +
|
||||
std::to_wstring(session_id);
|
||||
}
|
||||
|
||||
inline std::wstring GetCrossDeskSecureDesktopFrameReadyEventName(
|
||||
DWORD session_id) {
|
||||
return std::wstring(kCrossDeskSecureDesktopFrameReadyEventPrefix) +
|
||||
std::to_wstring(session_id);
|
||||
}
|
||||
|
||||
} // namespace crossdesk
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
+1
-1
Submodule submodules/minirtc updated: a9259b3be3...b8affa443e
@@ -0,0 +1,97 @@
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
namespace {
|
||||
|
||||
std::filesystem::path FindRepoRoot() {
|
||||
std::filesystem::path current = std::filesystem::current_path();
|
||||
while (!current.empty()) {
|
||||
if (std::filesystem::exists(current / "xmake.lua") &&
|
||||
std::filesystem::exists(current / "src/gui/toolbars/control_bar.cpp")) {
|
||||
return current;
|
||||
}
|
||||
current = current.parent_path();
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string ReadFile(const std::filesystem::path& path) {
|
||||
std::ifstream file(path, std::ios::binary);
|
||||
if (!file) {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::ostringstream stream;
|
||||
stream << file.rdbuf();
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
bool ExpectContains(const char* name, const std::string& value,
|
||||
const std::string& expected) {
|
||||
if (value.find(expected) != std::string::npos) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::cerr << name << " missing expected text: " << expected << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ExpectResetBeforeDisplayPopup(const std::string& value) {
|
||||
const std::string reset = "props->display_selectable_hovered_ = false;";
|
||||
const std::string popup = "ImGui::BeginPopup(\"display\")";
|
||||
const size_t reset_pos = value.find(reset);
|
||||
const size_t popup_pos = value.find(popup);
|
||||
|
||||
if (reset_pos != std::string::npos && popup_pos != std::string::npos &&
|
||||
reset_pos < popup_pos) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::cerr << "control_bar.cpp must clear display_selectable_hovered_ before "
|
||||
"checking the display popup\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ExpectResetBeforeShortcutPopup(const std::string& value) {
|
||||
const std::string reset = "props->shortcut_selectable_hovered_ = false;";
|
||||
const std::string popup = "ImGui::BeginPopup(\"shortcut\")";
|
||||
const size_t reset_pos = value.find(reset);
|
||||
const size_t popup_pos = value.find(popup);
|
||||
|
||||
if (reset_pos != std::string::npos && popup_pos != std::string::npos &&
|
||||
reset_pos < popup_pos) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::cerr << "control_bar.cpp must clear shortcut_selectable_hovered_ before "
|
||||
"checking the shortcut popup\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
const std::filesystem::path repo_root = FindRepoRoot();
|
||||
if (repo_root.empty()) {
|
||||
std::cerr << "failed to locate repository root\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
const std::string control_bar =
|
||||
ReadFile(repo_root / "src/gui/toolbars/control_bar.cpp");
|
||||
|
||||
bool ok = true;
|
||||
ok &= ExpectContains("control_bar.cpp", control_bar,
|
||||
"props->display_selectable_hovered_ = false;");
|
||||
ok &= ExpectContains("control_bar.cpp", control_bar,
|
||||
"ImGui::IsWindowHovered("
|
||||
"ImGuiHoveredFlags_RootAndChildWindows)");
|
||||
ok &= ExpectResetBeforeDisplayPopup(control_bar);
|
||||
ok &= ExpectContains("control_bar.cpp", control_bar,
|
||||
"props->shortcut_selectable_hovered_ =");
|
||||
ok &= ExpectResetBeforeShortcutPopup(control_bar);
|
||||
return ok ? 0 : 1;
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
#include "macos_keyboard_modifier_state.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
|
||||
namespace {
|
||||
|
||||
bool ExpectEqual(const char* name, uint32_t actual, uint32_t expected) {
|
||||
if (actual == expected) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::cerr << name << " mismatch\n"
|
||||
<< " expected: " << expected << "\n"
|
||||
<< " actual: " << actual << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
crossdesk::MacKeyboardModifierState state;
|
||||
|
||||
bool ok = true;
|
||||
ok &= ExpectEqual("initial flags", state.flags(), 0);
|
||||
ok &= ExpectEqual("left shift down", state.Update(0xA0, true),
|
||||
crossdesk::kMacInjectedModifierShift);
|
||||
ok &= ExpectEqual("shifted semicolon keeps shift",
|
||||
state.Update(0xBA, true),
|
||||
crossdesk::kMacInjectedModifierShift);
|
||||
ok &= ExpectEqual("semicolon up keeps shift", state.Update(0xBA, false),
|
||||
crossdesk::kMacInjectedModifierShift);
|
||||
ok &= ExpectEqual("right shift down while left held",
|
||||
state.Update(0xA1, true),
|
||||
crossdesk::kMacInjectedModifierShift);
|
||||
ok &= ExpectEqual("left shift up while right held", state.Update(0xA0, false),
|
||||
crossdesk::kMacInjectedModifierShift);
|
||||
ok &= ExpectEqual("right shift up clears shift", state.Update(0xA1, false),
|
||||
0);
|
||||
|
||||
ok &= ExpectEqual("left control down", state.Update(0xA2, true),
|
||||
crossdesk::kMacInjectedModifierControl);
|
||||
ok &= ExpectEqual("right alt adds option", state.Update(0xA5, true),
|
||||
crossdesk::kMacInjectedModifierControl |
|
||||
crossdesk::kMacInjectedModifierOption);
|
||||
ok &= ExpectEqual("left command adds command", state.Update(0x5B, true),
|
||||
crossdesk::kMacInjectedModifierControl |
|
||||
crossdesk::kMacInjectedModifierOption |
|
||||
crossdesk::kMacInjectedModifierCommand);
|
||||
ok &= ExpectEqual("left control up leaves option command",
|
||||
state.Update(0xA2, false),
|
||||
crossdesk::kMacInjectedModifierOption |
|
||||
crossdesk::kMacInjectedModifierCommand);
|
||||
ok &= ExpectEqual("right alt up leaves command", state.Update(0xA5, false),
|
||||
crossdesk::kMacInjectedModifierCommand);
|
||||
ok &= ExpectEqual("left command up clears all", state.Update(0x5B, false),
|
||||
0);
|
||||
|
||||
return ok ? 0 : 1;
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
#include "path_manager.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#elif defined(__APPLE__)
|
||||
#include <mach-o/dyld.h>
|
||||
#include <limits.h>
|
||||
#else
|
||||
#include <limits.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
std::filesystem::path GetExecutableDirectory() {
|
||||
#ifdef _WIN32
|
||||
wchar_t buffer[MAX_PATH] = {};
|
||||
DWORD length = GetModuleFileNameW(nullptr, buffer, MAX_PATH);
|
||||
if (length == 0 || length == MAX_PATH) {
|
||||
return {};
|
||||
}
|
||||
return std::filesystem::path(buffer).parent_path();
|
||||
#elif defined(__APPLE__)
|
||||
char buffer[PATH_MAX] = {};
|
||||
uint32_t size = sizeof(buffer);
|
||||
if (_NSGetExecutablePath(buffer, &size) != 0) {
|
||||
return {};
|
||||
}
|
||||
return std::filesystem::weakly_canonical(buffer).parent_path();
|
||||
#else
|
||||
char buffer[PATH_MAX] = {};
|
||||
ssize_t length = readlink("/proc/self/exe", buffer, sizeof(buffer) - 1);
|
||||
if (length <= 0) {
|
||||
return {};
|
||||
}
|
||||
buffer[length] = '\0';
|
||||
return std::filesystem::path(buffer).parent_path();
|
||||
#endif
|
||||
}
|
||||
|
||||
bool ExpectEqual(const char* name,
|
||||
const std::filesystem::path& actual,
|
||||
const std::filesystem::path& expected) {
|
||||
if (actual.lexically_normal() == expected.lexically_normal()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::cerr << name << " mismatch\n"
|
||||
<< " expected: " << expected.string() << "\n"
|
||||
<< " actual: " << actual.string() << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
const std::filesystem::path exe_dir = GetExecutableDirectory();
|
||||
if (exe_dir.empty()) {
|
||||
std::cerr << "failed to resolve executable directory\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
crossdesk::PathManager path_manager("CrossDesk");
|
||||
const std::filesystem::path expected_data = exe_dir / "data";
|
||||
const std::filesystem::path expected_logs = exe_dir / "logs";
|
||||
|
||||
bool ok = true;
|
||||
ok &= ExpectEqual("config path", path_manager.GetConfigPath(), expected_data);
|
||||
ok &= ExpectEqual("cache path", path_manager.GetCachePath(), expected_data);
|
||||
ok &= ExpectEqual("log path", path_manager.GetLogPath(), expected_logs);
|
||||
|
||||
return ok ? 0 : 1;
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
std::string ReadFile(const std::filesystem::path& path) {
|
||||
std::ifstream file(path, std::ios::binary);
|
||||
if (!file) {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::ostringstream stream;
|
||||
stream << file.rdbuf();
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
std::filesystem::path FindRepoRoot() {
|
||||
std::filesystem::path current = std::filesystem::current_path();
|
||||
while (!current.empty()) {
|
||||
if (std::filesystem::exists(current / "xmake.lua") &&
|
||||
std::filesystem::exists(current / "scripts/windows/crossdesk.rc")) {
|
||||
return current;
|
||||
}
|
||||
current = current.parent_path();
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
bool ExpectContains(const char* name, const std::string& value,
|
||||
const std::string& expected) {
|
||||
if (value.find(expected) != std::string::npos) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::cerr << name << " missing expected text: " << expected << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ExpectNotContains(const char* name, const std::string& value,
|
||||
const std::string& unexpected) {
|
||||
if (value.find(unexpected) == std::string::npos) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::cerr << name << " contains unexpected text: " << unexpected << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
bool ExpectActivationContext(const std::filesystem::path& manifest_path) {
|
||||
ACTCTXW context = {};
|
||||
context.cbSize = sizeof(context);
|
||||
std::wstring source = manifest_path.wstring();
|
||||
context.lpSource = source.c_str();
|
||||
|
||||
HANDLE activation_context = CreateActCtxW(&context);
|
||||
if (activation_context == INVALID_HANDLE_VALUE) {
|
||||
std::cerr << "CreateActCtxW failed for " << manifest_path.string()
|
||||
<< ", error=" << GetLastError() << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
ReleaseActCtx(activation_context);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
const std::filesystem::path repo_root = FindRepoRoot();
|
||||
if (repo_root.empty()) {
|
||||
std::cerr << "failed to locate repository root\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
const std::string rc = ReadFile(repo_root / "scripts/windows/crossdesk.rc");
|
||||
const std::string manifest =
|
||||
ReadFile(repo_root / "scripts/windows/crossdesk.manifest");
|
||||
const std::string debug_manifest =
|
||||
ReadFile(repo_root / "scripts/windows/crossdesk_debug.manifest");
|
||||
|
||||
bool ok = true;
|
||||
ok &= ExpectContains("crossdesk.rc", rc, "crossdesk.manifest");
|
||||
ok &= ExpectContains("crossdesk.rc", rc, "crossdesk_debug.manifest");
|
||||
ok &= ExpectContains("crossdesk.rc", rc, "CROSSDESK_DEBUG");
|
||||
ok &= ExpectContains("crossdesk.rc", rc, "RT_MANIFEST");
|
||||
ok &= ExpectContains("crossdesk.manifest", manifest,
|
||||
"level=\"requireAdministrator\"");
|
||||
ok &= ExpectContains("crossdesk.manifest", manifest,
|
||||
"http://schemas.microsoft.com/SMI/2005/WindowsSettings");
|
||||
ok &= ExpectContains("crossdesk.manifest", manifest,
|
||||
"http://schemas.microsoft.com/SMI/2016/WindowsSettings");
|
||||
ok &= ExpectNotContains("crossdesk.manifest", manifest,
|
||||
"processorArchitecture=\"*\"");
|
||||
ok &= ExpectContains("crossdesk_debug.manifest", debug_manifest,
|
||||
"level=\"asInvoker\"");
|
||||
ok &= ExpectContains("crossdesk_debug.manifest", debug_manifest,
|
||||
"http://schemas.microsoft.com/SMI/2005/WindowsSettings");
|
||||
ok &= ExpectContains("crossdesk_debug.manifest", debug_manifest,
|
||||
"http://schemas.microsoft.com/SMI/2016/WindowsSettings");
|
||||
ok &= ExpectNotContains("crossdesk_debug.manifest", debug_manifest,
|
||||
"processorArchitecture=\"*\"");
|
||||
#ifdef _WIN32
|
||||
ok &= ExpectActivationContext(repo_root / "scripts/windows/crossdesk.manifest");
|
||||
ok &= ExpectActivationContext(
|
||||
repo_root / "scripts/windows/crossdesk_debug.manifest");
|
||||
#endif
|
||||
return ok ? 0 : 1;
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
namespace {
|
||||
|
||||
std::filesystem::path FindRepoRoot() {
|
||||
std::filesystem::path current = std::filesystem::current_path();
|
||||
while (!current.empty()) {
|
||||
if (std::filesystem::exists(current / "xmake.lua") &&
|
||||
std::filesystem::exists(
|
||||
current / "src/device_controller/mouse/windows/mouse_controller.cpp")) {
|
||||
return current;
|
||||
}
|
||||
current = current.parent_path();
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string ReadFile(const std::filesystem::path& path) {
|
||||
std::ifstream file(path, std::ios::binary);
|
||||
if (!file) {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::ostringstream stream;
|
||||
stream << file.rdbuf();
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
bool ExpectContains(const char* name, const std::string& value,
|
||||
const std::string& expected) {
|
||||
if (value.find(expected) != std::string::npos) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::cerr << name << " missing expected text: " << expected << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
const std::filesystem::path repo_root = FindRepoRoot();
|
||||
if (repo_root.empty()) {
|
||||
std::cerr << "failed to locate repository root\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
const std::string mouse_controller = ReadFile(
|
||||
repo_root / "src/device_controller/mouse/windows/mouse_controller.cpp");
|
||||
|
||||
bool ok = true;
|
||||
ok &= ExpectContains("mouse_controller.cpp", mouse_controller,
|
||||
"INPUT ip = {0};");
|
||||
ok &= ExpectContains("mouse_controller.cpp", mouse_controller,
|
||||
"SetCursorPos failed");
|
||||
ok &= ExpectContains("mouse_controller.cpp", mouse_controller,
|
||||
"SendInput failed for mouse");
|
||||
return ok ? 0 : 1;
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "interactive_state.h"
|
||||
|
||||
namespace {
|
||||
|
||||
std::filesystem::path FindRepoRoot() {
|
||||
std::filesystem::path current = std::filesystem::current_path();
|
||||
while (!current.empty()) {
|
||||
if (std::filesystem::exists(current / "xmake.lua") &&
|
||||
std::filesystem::exists(
|
||||
current / "src/service/windows/service_host.cpp")) {
|
||||
return current;
|
||||
}
|
||||
current = current.parent_path();
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string ReadFile(const std::filesystem::path& path) {
|
||||
std::ifstream file(path, std::ios::binary);
|
||||
if (!file) {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::ostringstream stream;
|
||||
stream << file.rdbuf();
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
bool ExpectContains(const char* name, const std::string& value,
|
||||
const std::string& expected) {
|
||||
if (value.find(expected) != std::string::npos) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::cerr << name << " missing expected text: " << expected << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ExpectNotContains(const char* name, const std::string& value,
|
||||
const std::string& unexpected) {
|
||||
if (value.find(unexpected) == std::string::npos) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::cerr << name << " contains unexpected text: " << unexpected << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ExpectTrue(const char* name, bool value) {
|
||||
if (value) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::cerr << name << " expected true\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
const std::filesystem::path repo_root = FindRepoRoot();
|
||||
if (repo_root.empty()) {
|
||||
std::cerr << "failed to locate repository root\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
const std::string control_bar =
|
||||
ReadFile(repo_root / "src/gui/toolbars/control_bar.cpp");
|
||||
const std::string render = ReadFile(repo_root / "src/gui/render.cpp");
|
||||
const std::string render_h = ReadFile(repo_root / "src/gui/render.h");
|
||||
const std::string service_host =
|
||||
ReadFile(repo_root / "src/service/windows/service_host.cpp");
|
||||
const std::string service_host_h =
|
||||
ReadFile(repo_root / "src/service/windows/service_host.h");
|
||||
const std::string session_helper =
|
||||
ReadFile(repo_root / "src/service/windows/session_helper_main.cpp");
|
||||
|
||||
bool ok = true;
|
||||
ok &= ExpectTrue("secure desktop input routing",
|
||||
crossdesk::IsSecureDesktopInteractionRequired(
|
||||
"secure-desktop"));
|
||||
ok &= ExpectNotContains("control_bar.cpp", control_bar,
|
||||
"CanSendSecureAttentionSequence("
|
||||
"props->remote_interactive_stage_)");
|
||||
ok &= ExpectNotContains("control_bar.cpp", control_bar,
|
||||
"ImGui::BeginDisabled();\n"
|
||||
" }\n"
|
||||
" if (ImGui::Selectable(sas_label.c_str()))");
|
||||
ok &= ExpectNotContains("render.cpp", render, "sas_requires_lock_screen");
|
||||
ok &= ExpectContains("render.h", render_h,
|
||||
"optimistic_windows_secure_desktop_until_tick_");
|
||||
ok &= ExpectContains("render.cpp", render,
|
||||
"kWindowsServiceSasSecureDesktopGraceMs");
|
||||
ok &= ExpectContains("render.cpp", render,
|
||||
"status->sas_secure_desktop_grace_active");
|
||||
ok &= ExpectContains("render.cpp", render,
|
||||
"json.value(\"sas_secure_desktop_grace_active\", false)");
|
||||
ok &= ExpectContains("render.cpp", render,
|
||||
"status.sas_secure_desktop_grace_active");
|
||||
ok &= ExpectContains("render.cpp", render,
|
||||
"local_interactive_stage_ = \"secure-desktop\"");
|
||||
ok &= ExpectContains("service_host.h", service_host_h,
|
||||
"sas_secure_desktop_until_tick_");
|
||||
ok &= ExpectContains("service_host.h", service_host_h,
|
||||
"sas_secure_desktop_seen_");
|
||||
ok &= ExpectContains("service_host.cpp", service_host,
|
||||
"kSasSecureDesktopGraceMs");
|
||||
ok &= ExpectContains("service_host.cpp", service_host,
|
||||
"IsSasSecureDesktopGraceActiveLocked()");
|
||||
ok &= ExpectContains("service_host.cpp", service_host,
|
||||
"UpdateSasSecureDesktopGraceLocked("
|
||||
"session_helper_report_interactive_stage_)");
|
||||
ok &= ExpectContains("service_host.cpp", service_host,
|
||||
"sas_secure_desktop_seen_ = true");
|
||||
ok &= ExpectContains("service_host.cpp", service_host,
|
||||
"sas_secure_desktop_until_tick_ = 0");
|
||||
ok &= ExpectContains("service_host.cpp", service_host,
|
||||
"sas_secure_desktop_until_tick_ =");
|
||||
ok &= ExpectContains("service_host.cpp", service_host,
|
||||
"now + kSasSecureDesktopGraceMs");
|
||||
ok &= ExpectContains("service_host.cpp", service_host,
|
||||
"\\\"sas_secure_desktop_grace_active\\\"");
|
||||
ok &= ExpectContains("service_host.cpp", service_host,
|
||||
"raw_interactive_stage = ResolveInteractiveStageLocked()");
|
||||
ok &= ExpectContains("session_helper_main.cpp", session_helper,
|
||||
"kSessionHelperStatePollMs = 1000");
|
||||
ok &= ExpectContains("session_helper_main.cpp", session_helper,
|
||||
"EVENT_SYSTEM_DESKTOPSWITCH");
|
||||
ok &= ExpectContains("session_helper_main.cpp", session_helper,
|
||||
"SetWinEventHook(");
|
||||
ok &= ExpectContains("session_helper_main.cpp", session_helper,
|
||||
"MsgWaitForMultipleObjects");
|
||||
ok &= ExpectContains("session_helper_main.cpp", session_helper,
|
||||
"WaitForSessionHelperStateChange(stop_event, "
|
||||
"desktop_switch_event)");
|
||||
ok &= ExpectContains("session_helper_main.cpp", session_helper,
|
||||
"inaccessible_secure_input_desktop");
|
||||
ok &= ExpectContains("session_helper_main.cpp", session_helper,
|
||||
"desktop_info.error_code == ERROR_ACCESS_DENIED");
|
||||
ok &= ExpectContains("session_helper_main.cpp", session_helper,
|
||||
"secure_desktop_active = input_desktop_is_winlogon ||");
|
||||
return ok ? 0 : 1;
|
||||
}
|
||||
@@ -0,0 +1,225 @@
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
namespace {
|
||||
|
||||
std::filesystem::path FindRepoRoot() {
|
||||
std::filesystem::path current = std::filesystem::current_path();
|
||||
while (!current.empty()) {
|
||||
if (std::filesystem::exists(current / "xmake.lua") &&
|
||||
std::filesystem::exists(current / "src/service/windows/service_host.cpp")) {
|
||||
return current;
|
||||
}
|
||||
current = current.parent_path();
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string ReadFile(const std::filesystem::path& path) {
|
||||
std::ifstream file(path, std::ios::binary);
|
||||
if (!file) {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::ostringstream stream;
|
||||
stream << file.rdbuf();
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
bool ExpectContains(const char* name, const std::string& value,
|
||||
const std::string& expected) {
|
||||
if (value.find(expected) != std::string::npos) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::cerr << name << " missing expected text: " << expected << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ExpectNotContains(const char* name, const std::string& value,
|
||||
const std::string& unexpected) {
|
||||
if (value.find(unexpected) == std::string::npos) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::cerr << name << " contains unexpected text: " << unexpected << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
const std::filesystem::path repo_root = FindRepoRoot();
|
||||
if (repo_root.empty()) {
|
||||
std::cerr << "failed to locate repository root\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
const std::string service_host =
|
||||
ReadFile(repo_root / "src/service/windows/service_host.cpp");
|
||||
const std::string service_host_h =
|
||||
ReadFile(repo_root / "src/service/windows/service_host.h");
|
||||
const std::string session_helper =
|
||||
ReadFile(repo_root / "src/service/windows/session_helper_main.cpp");
|
||||
const std::string targets =
|
||||
ReadFile(repo_root / "xmake/targets.lua");
|
||||
const std::string interactive_state =
|
||||
ReadFile(repo_root / "src/service/windows/interactive_state.h");
|
||||
const std::string render_callback =
|
||||
ReadFile(repo_root / "src/gui/render_callback.cpp");
|
||||
const std::string render = ReadFile(repo_root / "src/gui/render.cpp");
|
||||
const std::string screen_capturer_h =
|
||||
ReadFile(repo_root / "src/screen_capturer/windows/screen_capturer_win.h");
|
||||
const std::string screen_capturer_cpp =
|
||||
ReadFile(repo_root / "src/screen_capturer/windows/screen_capturer_win.cpp");
|
||||
|
||||
bool ok = true;
|
||||
ok &= ExpectContains("service_host.cpp", service_host,
|
||||
"ParseSecureDesktopMouseIpcCommand");
|
||||
ok &= ExpectContains("service_host.cpp", service_host,
|
||||
"BuildSecureInputHelperMouseCommand");
|
||||
ok &= ExpectContains("targets.lua", targets,
|
||||
"target(\"crossdesk_session_helper\")");
|
||||
ok &= ExpectContains("targets.lua", targets,
|
||||
"add_files(\"scripts/windows/crossdesk.rc\")");
|
||||
ok &= ExpectContains("session_helper_main.cpp", session_helper,
|
||||
"EnablePerMonitorDpiAwareness");
|
||||
ok &= ExpectContains("session_helper_main.cpp", session_helper,
|
||||
"SetProcessDpiAwarenessContext(\n"
|
||||
" DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2)");
|
||||
ok &= ExpectContains("session_helper_main.cpp", session_helper,
|
||||
"EnablePerMonitorDpiAwareness();\n\n"
|
||||
" InitializeHelperLogger();");
|
||||
ok &= ExpectContains("service_host.cpp", service_host,
|
||||
"const ULONGLONG deadline_tick = GetTickCount64() + timeout_ms");
|
||||
ok &= ExpectContains("service_host.cpp", service_host,
|
||||
"while (GetTickCount64() <= deadline_tick)");
|
||||
ok &= ExpectNotContains("service_host.cpp", service_host,
|
||||
"constexpr int kPipeConnectRetryCount = 3");
|
||||
ok &= ExpectContains("service_host.cpp", service_host,
|
||||
"BuildSecureInputHelperKeyboardCommand(");
|
||||
ok &= ExpectContains("service_host.cpp", service_host,
|
||||
"const std::string& interactive_stage");
|
||||
ok &= ExpectContains("service_host.h", service_host_h,
|
||||
"bool LaunchSecureInputHelper(DWORD session_id,\n"
|
||||
" const std::string& interactive_stage)");
|
||||
ok &= ExpectContains("service_host.h", service_host_h,
|
||||
"std::string secure_input_helper_interactive_stage_");
|
||||
ok &= ExpectContains("service_host.cpp", service_host,
|
||||
"SecureInputHelperDesktopForStage");
|
||||
ok &= ExpectContains("service_host.cpp", service_host,
|
||||
"return L\"winsta0\\\\Winlogon\"");
|
||||
ok &= ExpectContains("service_host.cpp", service_host,
|
||||
"return L\"winsta0\\\\default\"");
|
||||
ok &= ExpectContains("service_host.cpp", service_host,
|
||||
"secure_input_helper_interactive_stage_ == interactive_stage");
|
||||
ok &= ExpectContains("service_host.cpp", service_host,
|
||||
"secure_input_helper_interactive_stage_ = interactive_stage");
|
||||
ok &= ExpectContains("service_host.cpp", service_host,
|
||||
"secure_input_helper_interactive_stage_.clear()");
|
||||
ok &= ExpectContains("service_host.cpp", service_host,
|
||||
"LaunchSecureInputHelper(target_session_id, interactive_stage)");
|
||||
ok &= ExpectContains("service_host.cpp", service_host,
|
||||
"\\\"secure_input_helper_stage\\\":\\\"");
|
||||
ok &= ExpectContains("service_host.cpp", service_host,
|
||||
"session_helper_report_interactive_stage_");
|
||||
ok &= ExpectContains("service_host.cpp", service_host,
|
||||
"return SendSecureDesktopMouseInput");
|
||||
ok &= ExpectContains("render.cpp", render,
|
||||
"constexpr DWORD kWindowsServiceQueryTimeoutMs = 500");
|
||||
ok &= ExpectContains("screen_capturer_win.cpp", screen_capturer_cpp,
|
||||
"constexpr DWORD kSecureDesktopStatusPipeTimeoutMs = 500");
|
||||
ok &= ExpectContains("render.cpp", render,
|
||||
"IsTransientWindowsServiceStatusError(status.error)");
|
||||
ok &= ExpectContains("screen_capturer_win.cpp", screen_capturer_cpp,
|
||||
"IsTransientWindowsServiceStatusError(status.error)");
|
||||
ok &= ExpectContains("render.cpp", render,
|
||||
"Local Windows service temporarily unavailable");
|
||||
ok &= ExpectContains("screen_capturer_win.cpp", screen_capturer_cpp,
|
||||
"Windows capturer secure desktop service temporarily unavailable");
|
||||
ok &= ExpectContains("screen_capturer_win.cpp", screen_capturer_cpp,
|
||||
"Windows capturer secure desktop transient frame query failed");
|
||||
ok &= ExpectContains("screen_capturer_win.cpp", screen_capturer_cpp,
|
||||
"if (transient_error) {\n"
|
||||
" LOG_INFO(");
|
||||
ok &= ExpectContains("render_callback.cpp", render_callback,
|
||||
"IsTransientSecureDesktopInputFailure");
|
||||
ok &= ExpectContains("render_callback.cpp", render_callback,
|
||||
"Secure desktop keyboard injection transient failure");
|
||||
ok &= ExpectContains("session_helper_main.cpp", session_helper,
|
||||
"MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE");
|
||||
ok &= ExpectContains("session_helper_main.cpp", session_helper,
|
||||
"MOUSEEVENTF_VIRTUALDESK");
|
||||
ok &= ExpectContains("session_helper_main.cpp", session_helper,
|
||||
"std::vector<INPUT> inputs");
|
||||
ok &= ExpectContains("session_helper_main.cpp", session_helper,
|
||||
"SendInput(static_cast<UINT>(inputs.size())");
|
||||
ok &= ExpectNotContains("session_helper_main.cpp", session_helper,
|
||||
"SetCursorPos(request.x, request.y)");
|
||||
ok &= ExpectContains("session_helper_main.cpp", session_helper,
|
||||
"NormalizeAbsoluteMouseCoordinate");
|
||||
ok &= ExpectContains("session_helper_main.cpp", session_helper,
|
||||
"EnsureThreadInteractiveDesktop");
|
||||
ok &= ExpectContains("session_helper_main.cpp", session_helper,
|
||||
"OpenInputDesktop");
|
||||
ok &= ExpectContains("session_helper_main.cpp", session_helper,
|
||||
"DesktopNameForInteractiveStage");
|
||||
ok &= ExpectContains("session_helper_main.cpp", session_helper,
|
||||
"interactive_stage == \"credential-ui\"");
|
||||
ok &= ExpectContains("session_helper_main.cpp", session_helper,
|
||||
"return L\"Winlogon\"");
|
||||
ok &= ExpectContains("session_helper_main.cpp", session_helper,
|
||||
"interactive_stage == \"lock-screen\"");
|
||||
ok &= ExpectContains("session_helper_main.cpp", session_helper,
|
||||
"return L\"Default\"");
|
||||
ok &= ExpectContains("session_helper_main.cpp", session_helper,
|
||||
"EnsureThreadInteractiveDesktopForStage");
|
||||
ok &= ExpectContains("session_helper_main.cpp", session_helper,
|
||||
"switch_interactive_desktop_failed");
|
||||
ok &= ExpectContains("session_helper_main.cpp", session_helper,
|
||||
"Json BuildInputFailureJson");
|
||||
ok &= ExpectContains("session_helper_main.cpp", session_helper,
|
||||
"json[\"target_desktop\"]");
|
||||
ok &= ExpectContains("session_helper_main.cpp", session_helper,
|
||||
"json[\"current_desktop\"]");
|
||||
ok &= ExpectContains("session_helper_main.cpp", session_helper,
|
||||
"json[\"stage\"]");
|
||||
ok &= ExpectContains("session_helper_main.cpp", session_helper,
|
||||
"ParseSecureInputKeyboardCommand(command, &key_code, &is_down, &scan_code,\n"
|
||||
" &extended, &interactive_stage)");
|
||||
ok &= ExpectContains("session_helper_main.cpp", session_helper,
|
||||
"InjectKeyboardInput(key_code, is_down, scan_code, extended,\n"
|
||||
" interactive_stage)");
|
||||
ok &= ExpectContains("session_helper_main.cpp", session_helper,
|
||||
"InjectMouseInput(mouse_request)");
|
||||
ok &= ExpectNotContains("session_helper_main.cpp", session_helper,
|
||||
"EnsureThreadDesktop(L\"Winlogon\", &secure_desktop)");
|
||||
ok &= ExpectContains("service_host.cpp", service_host,
|
||||
"winsta0\\\\default");
|
||||
ok &= ExpectNotContains("service_host.cpp", service_host,
|
||||
"startup_info.lpDesktop = const_cast<LPWSTR>(L\"winsta0\\\\Winlogon\")");
|
||||
ok &= ExpectContains("interactive_state.h", interactive_state,
|
||||
"interactive_stage == \"lock-screen\"");
|
||||
ok &= ExpectContains("render_callback.cpp", render_callback,
|
||||
"RemoteAction remote_action{};");
|
||||
ok &= ExpectContains("render.cpp", render,
|
||||
"previous_secure_desktop_interaction");
|
||||
ok &= ExpectNotContains(
|
||||
"render_callback.cpp", render_callback,
|
||||
"render->local_service_available_ &&\n"
|
||||
" IsSecureDesktopInteractionRequired(render->local_interactive_stage_)");
|
||||
ok &= ExpectContains("screen_capturer_win.h", screen_capturer_h,
|
||||
"std::string secure_shared_stage_;");
|
||||
ok &= ExpectContains("screen_capturer_win.cpp", screen_capturer_cpp,
|
||||
"const std::string& stage");
|
||||
ok &= ExpectContains("screen_capturer_win.cpp", screen_capturer_cpp,
|
||||
"secure_shared_stage_ == stage");
|
||||
ok &= ExpectContains("screen_capturer_win.cpp", screen_capturer_cpp,
|
||||
"secure_shared_stage_ = stage");
|
||||
ok &= ExpectContains("screen_capturer_win.cpp", screen_capturer_cpp,
|
||||
"secure_shared_stage_.clear()");
|
||||
return ok ? 0 : 1;
|
||||
}
|
||||
+8
-1
@@ -23,6 +23,12 @@ function setup_options_and_dependencies()
|
||||
set_description("Enable DRM capture on Linux (assumes dependencies are installed)")
|
||||
option_end()
|
||||
|
||||
option("CROSSDESK_PORTABLE")
|
||||
set_default(false)
|
||||
set_showmenu(true)
|
||||
set_description("Build CrossDesk as a portable package that stores data beside the executable")
|
||||
option_end()
|
||||
|
||||
add_rules("mode.release", "mode.debug")
|
||||
set_languages("c++17")
|
||||
set_encodings("utf-8")
|
||||
@@ -35,6 +41,7 @@ function setup_options_and_dependencies()
|
||||
add_defines("USE_CUDA=" .. (is_config("USE_CUDA", true) and "1" or "0"))
|
||||
add_defines("USE_WAYLAND=" .. (is_config("USE_WAYLAND", true) and "1" or "0"))
|
||||
add_defines("USE_DRM=" .. (is_config("USE_DRM", true) and "1" or "0"))
|
||||
add_defines("CROSSDESK_PORTABLE=" .. (is_config("CROSSDESK_PORTABLE", true) and "1" or "0"))
|
||||
|
||||
if is_mode("debug") then
|
||||
add_defines("CROSSDESK_DEBUG")
|
||||
@@ -47,4 +54,4 @@ function setup_options_and_dependencies()
|
||||
add_requires("nlohmann_json 3.11.3")
|
||||
add_requires("cpp-httplib v0.26.0", {configs = {ssl = true}})
|
||||
add_requires("tinyfiledialogs 3.15.1")
|
||||
end
|
||||
end
|
||||
|
||||
+45
-1
@@ -25,6 +25,46 @@ function setup_targets()
|
||||
add_files("src/path_manager/*.cpp")
|
||||
add_includedirs("src/path_manager", {public = true})
|
||||
|
||||
target("path_manager_portable_test")
|
||||
set_kind("binary")
|
||||
set_default(false)
|
||||
add_defines("CROSSDESK_PORTABLE=1")
|
||||
add_includedirs("src/path_manager")
|
||||
add_files("tests/path_manager_portable_test.cpp",
|
||||
"src/path_manager/path_manager.cpp")
|
||||
|
||||
target("macos_keyboard_modifier_state_test")
|
||||
set_kind("binary")
|
||||
set_default(false)
|
||||
add_includedirs("src/device_controller")
|
||||
add_files("tests/macos_keyboard_modifier_state_test.cpp")
|
||||
|
||||
target("windows_manifest_resource_test")
|
||||
set_kind("binary")
|
||||
set_default(false)
|
||||
add_files("tests/windows_manifest_resource_test.cpp")
|
||||
|
||||
target("windows_service_mouse_ipc_test")
|
||||
set_kind("binary")
|
||||
set_default(false)
|
||||
add_files("tests/windows_service_mouse_ipc_test.cpp")
|
||||
|
||||
target("windows_mouse_controller_safety_test")
|
||||
set_kind("binary")
|
||||
set_default(false)
|
||||
add_files("tests/windows_mouse_controller_safety_test.cpp")
|
||||
|
||||
target("windows_sas_guard_test")
|
||||
set_kind("binary")
|
||||
set_default(false)
|
||||
add_includedirs("src/service/windows")
|
||||
add_files("tests/windows_sas_guard_test.cpp")
|
||||
|
||||
target("display_popup_hover_state_test")
|
||||
set_kind("binary")
|
||||
set_default(false)
|
||||
add_files("tests/display_popup_hover_state_test.cpp")
|
||||
|
||||
target("screen_capturer")
|
||||
set_kind("object")
|
||||
add_deps("rd_log", "common")
|
||||
@@ -159,6 +199,9 @@ function setup_targets()
|
||||
add_packages("libyuv")
|
||||
add_deps("rd_log", "path_manager")
|
||||
add_defines("CROSSDESK_WGC_PLUGIN_BUILD=1")
|
||||
-- Keep the project on C++17 while C++/WinRT still falls back to
|
||||
-- MSVC's deprecated experimental coroutine header.
|
||||
add_defines("_SILENCE_EXPERIMENTAL_COROUTINE_DEPRECATION_WARNINGS")
|
||||
add_links("windowsapp")
|
||||
add_files("src/screen_capturer/windows/screen_capturer_wgc.cpp",
|
||||
"src/screen_capturer/windows/wgc_session_impl.cpp",
|
||||
@@ -180,6 +223,7 @@ function setup_targets()
|
||||
add_deps("rd_log", "path_manager")
|
||||
add_links("Advapi32", "User32", "Wtsapi32", "Gdi32")
|
||||
add_files("src/service/windows/session_helper_main.cpp")
|
||||
add_files("scripts/windows/crossdesk.rc")
|
||||
add_includedirs("src/service/windows", {public = true})
|
||||
end
|
||||
|
||||
@@ -195,4 +239,4 @@ function setup_targets()
|
||||
add_deps("wgc_plugin", "crossdesk_service", "crossdesk_session_helper")
|
||||
add_files("scripts/windows/crossdesk.rc")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user