[idd] helper: run interactive process as desktop user

Explorer file copies were invisible to the Helper because the service
launched its child with a duplicate of the LocalSystem token and changed
only TokenSessionId. The child therefore remained a System-integrity
process. Windows filtered Explorer's file clipboard formats across that
integrity boundary. Basic text and bitmap formats continued to work.

Keep only the SCM service privileged. Obtain the active session user's
primary token with WTSQueryUserToken. For elevated accounts, prefer the
linked limited token. Validate its session and security properties.
Build the user environment and launch the interactive Helper on
WinSta0\Default. Gate Helper activation until the service has rechecked
the active session and registered the clipboard authority.

Use random lifetime, stop, and activation objects owned by the service.
Give the target logon SID synchronization access only. Recheck the
active console session and service state before activation. Make the
lifetime mutex terminate the Helper if the service exits unexpectedly.
Restart it when the active session, IDD host, or authority changes.

Replace the old process-handle mapping transfer with a device-bound
authority protocol on the LGIdd device interface. The service verifies
the exact driver host instance, duplicates only section map rights into
that process, and registers the session, mapping identifier, and handle.
Bind authority lifetime to its WDF file object, revoke it synchronously
on cleanup, and poll the driver host identity while the child is active.

Restrict the device stack to SYSTEM and isolate LGIdd in a unique UMDF
device group. Restrict the shared section to SYSTEM and the target logon
SID. Apply a medium mandatory label that prevents low-integrity readers
and writers. Map it with read/write rights instead of all access.

Give each clipboard mapping a second random authority identifier. Store
it only inside the logon-SID-protected mapping and send it in the
mandatory HELLO. LGIdd matches it against the service-injected mapping.
This authenticates the user Helper without the unsupported UMDF call to
GetNamedPipeClientSessionId. Have the Helper verify that its pipe server
is in session zero.

Extend the pipe endpoint with bounded authentication reads, cancellable
overlapped I/O, periodic authorization checks, and explicit disconnects.
Serialize authority changes with clipboard attach and detach. Prevent
stale cleanup from tearing down a replacement mapping. Disconnect the
user pipe immediately when its owning authority is revoked.

Run clipboard, OLE, display, configuration, and file access in the
user's interactive process. Retain its process token for worker-thread
file operations instead of querying and impersonating the desktop user
from a System process. Store Helper logs in LocalAppData and grant only
the registry rights needed by interactive configuration and UMDF.

Keep immediate, stage-specific Win32 and HRESULT diagnostics throughout
clipboard capture. Probe CF_HDROP while holding the Win32 clipboard and
enumerate the OLE object's advertised file formats. Validate returned
storage and fall back to Shell item paths when direct retrieval fails.
Validate clipboard sequence changes and defer retries during contention
without publishing incomplete clipboard state.

Complete the 1 MiB transfer work with full-sized Windows copy buffers.
Use full-sized FUSE reads and retain the named 64 KiB X11 chunk limit.
Validate the user-writable mapping with CClipboardRing before attaching.

The pipe, mapping, and authority protocols change together. LGIdd.dll,
the INF, and LGIddHelper.exe must be rebuilt and installed as one
matching set.
This commit is contained in:
Geoffrey McRae
2026-08-15 00:11:01 +10:00
parent e40dc19c7e
commit f9ffce528a
35 changed files with 2803 additions and 665 deletions

View File

@@ -154,7 +154,8 @@ bool CClipboardChannel::Attach(HANDLE mapping, uint64_t epoch,
CSRWExclusiveLock lock(m_lifecycleLock);
ClipboardMapping * view = static_cast<ClipboardMapping *>(MapViewOfFile(
mapping, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(ClipboardMapping)));
mapping, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0,
sizeof(ClipboardMapping)));
if (!view)
{
DEBUG_ERROR_HR(GetLastError(), "Failed to map clipboard channel");

View File

@@ -25,15 +25,18 @@
#include <string.h>
void CClipboardRing::Initialize(
ClipboardMapping& mapping, uint64_t epoch)
ClipboardMapping& mapping, uint64_t epoch,
const uint64_t (&authorityId)[2])
{
memset(&mapping, 0, sizeof(mapping));
mapping.magic = LG_CLIPBOARD_MAPPING_MAGIC;
mapping.version = LG_CLIPBOARD_MAPPING_VERSION;
mapping.size = sizeof(mapping);
mapping.slotBytes = KVMFR_CLIPBOARD_DATA_BYTES;
mapping.slotCount = KVMFR_CLIPBOARD_SLOT_COUNT;
mapping.epoch = epoch;
mapping.magic = LG_CLIPBOARD_MAPPING_MAGIC;
mapping.version = LG_CLIPBOARD_MAPPING_VERSION;
mapping.size = sizeof(mapping);
mapping.slotBytes = KVMFR_CLIPBOARD_DATA_BYTES;
mapping.slotCount = KVMFR_CLIPBOARD_SLOT_COUNT;
mapping.epoch = epoch;
mapping.authorityId[0] = authorityId[0];
mapping.authorityId[1] = authorityId[1];
}
bool CClipboardRing::Valid(
@@ -44,6 +47,7 @@ bool CClipboardRing::Valid(
mapping.size != sizeof(mapping) ||
mapping.slotBytes != KVMFR_CLIPBOARD_DATA_BYTES ||
mapping.slotCount != KVMFR_CLIPBOARD_SLOT_COUNT ||
!mapping.authorityId[0] || !mapping.authorityId[1] ||
!mapping.epoch || mapping.epoch != epoch)
return false;

View File

@@ -32,7 +32,8 @@ enum class ClipboardRingReadResult
class CClipboardRing
{
public:
static void Initialize(ClipboardMapping& mapping, uint64_t epoch);
static void Initialize(ClipboardMapping& mapping, uint64_t epoch,
const uint64_t (&authorityId)[2]);
static bool Valid(const ClipboardMapping& mapping, uint64_t epoch);
static ClipboardRingSlot * BeginWrite(

View File

@@ -21,6 +21,7 @@
#include <Windows.h>
#include <string>
#include <cerrno>
#include <stdio.h>
#include <malloc.h>
#include <strsafe.h>
@@ -100,25 +101,39 @@ inline static void iso8601(wchar_t *buf, size_t count)
wcsftime(buf, count, L"%Y-%m-%d %H:%M:%SZ", &utc);
}
inline static std::wstring getLogPath()
inline static std::wstring getLogPath(CDebug::Location location)
{
PWSTR pszPath;
if (FAILED(SHGetKnownFolderPath(FOLDERID_ProgramData, 0, NULL, &pszPath)))
const KNOWNFOLDERID& folder = location == CDebug::Location::LocalAppData ?
FOLDERID_LocalAppData : FOLDERID_ProgramData;
const HRESULT folderResult =
SHGetKnownFolderPath(folder, KF_FLAG_CREATE, NULL, &pszPath);
if (FAILED(folderResult))
{
DEBUG_ERROR("Failed to get ProgramData path");
DEBUG_ERROR_HR(folderResult, "Failed to get the log directory root");
return L"";
}
std::wstring result(pszPath);
CoTaskMemFree(pszPath);
result += L"\\Looking Glass (IDD)\\";
result += L"\\Looking Glass (IDD)";
if (!CreateDirectoryW(result.c_str(), nullptr))
{
const DWORD directoryError = GetLastError();
if (directoryError != ERROR_ALREADY_EXISTS)
{
DEBUG_ERROR_HR(directoryError, "Failed to create the log directory");
return L"";
}
}
result += L"\\";
return result;
}
void CDebug::Init(const wchar_t * name)
void CDebug::Init(const wchar_t * name, Location location)
{
m_logDir = getLogPath();
m_logDir = getLogPath(location);
// don't redirect the debug output if running under a debugger
if (IsDebuggerPresent())
@@ -150,10 +165,13 @@ void CDebug::Init(const wchar_t * name)
}
/// open the new log file
errno = 0;
std::ofstream stream(logFile, std::ios::out | std::ios::trunc);
const int openError = errno;
if (!stream.is_open())
{
DEBUG_ERROR_HR(GetLastError(), "Failed to open the log file %s", logFile.c_str());
DEBUG_ERROR(L"Failed to open the log file %s (errno=%d)",
logFile.c_str(), openError ? openError : EIO);
return;
}
@@ -336,10 +354,12 @@ void CDebug::LogStrHR(CDebug::Level level, HRESULT hr, const char *function, int
wchar_t *result;
if (aswprintf(&result, wide ? L"%s (0x%08lX (%u): %s)" : L"%S (0x%08lX (%u): %s)", str, hr, hr, hrBuffer) < 0)
{
LocalFree(hrBuffer);
Write(L"Out of memory while logging");
return;
}
LocalFree(hrBuffer);
LogStr(level, function, line, true, result);
free(result);
}

View File

@@ -32,6 +32,12 @@ class CDebug
public:
enum class Location
{
ProgramData,
LocalAppData,
};
enum Level
{
LEVEL_NONE = 0,
@@ -46,7 +52,8 @@ class CDebug
};
const wchar_t *logDir() { return m_logDir.c_str(); }
void Init(const wchar_t * name);
void Init(const wchar_t * name,
Location location = Location::ProgramData);
void Log_va(CDebug::Level level, const char *function, int line, const wchar_t *fmt, va_list args);
void Log(CDebug::Level level, const char *function, int line, const wchar_t *fmt, ...);
void Log_va(CDebug::Level level, const char *function, int line, const char *fmt, va_list args);
@@ -86,4 +93,4 @@ extern CDebug g_debug;
#define DEBUG_ERROR_HR(hr, fmt, ...) g_debug.LogHR(CDebug::LEVEL_ERROR, hr, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
#define DEBUG_TRACE_HR(hr, fmt, ...) g_debug.LogHR(CDebug::LEVEL_TRACE, hr, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
#define DEBUG_FIXME_HR(hr, fmt, ...) g_debug.LogHR(CDebug::LEVEL_FIXME, hr, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
#define DEBUG_FATAL_HR(hr, fmt, ...) g_debug.LogHR(CDebug::LEVEL_FATAL, hr, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
#define DEBUG_FATAL_HR(hr, fmt, ...) g_debug.LogHR(CDebug::LEVEL_FATAL, hr, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)

View File

@@ -26,11 +26,13 @@
#include <stdint.h>
#include <vector>
const DWORD CPipeEndpoint::CLIENT_RETRY_INITIAL_MS = 100;
const DWORD CPipeEndpoint::CLIENT_RETRY_MAX_MS = 2000;
const DWORD CPipeEndpoint::SERVER_RETRY_MS = 1000;
const DWORD CPipeEndpoint::WRITE_TIMEOUT_MS = 250;
const DWORD CPipeEndpoint::WAIT_FIRST_OBJECT_VALUE = 0;
const DWORD CPipeEndpoint::CLIENT_RETRY_INITIAL_MS = 100;
const DWORD CPipeEndpoint::CLIENT_RETRY_MAX_MS = 2000;
const DWORD CPipeEndpoint::SERVER_RETRY_MS = 1000;
const DWORD CPipeEndpoint::AUTHENTICATION_TIMEOUT_MS = 2000;
const DWORD CPipeEndpoint::AUTHORIZATION_POLL_MS = 1000;
const DWORD CPipeEndpoint::WRITE_TIMEOUT_MS = 250;
const DWORD CPipeEndpoint::WAIT_FIRST_OBJECT_VALUE = 0;
bool CPipeEndpoint::IsDisconnectedError(DWORD error)
{
@@ -55,7 +57,12 @@ CPipeEndpoint::PipeIoResult CPipeEndpoint::WaitForOverlapped(
CancelIoEx(pipe, overlapped);
if (GetOverlappedResult(pipe, overlapped, transferred, TRUE))
return PipeIoResult::Success;
DEBUG_WARN("Named pipe write timed out");
const DWORD error = GetLastError();
if (error == ERROR_OPERATION_ABORTED)
return PipeIoResult::TimedOut;
if (IsDisconnectedError(error))
return PipeIoResult::Disconnected;
DEBUG_WARN_HR(error, "Failed to cancel timed-out named pipe I/O");
return PipeIoResult::Error;
}
@@ -94,7 +101,8 @@ CPipeEndpoint::PipeIoResult CPipeEndpoint::ReadMessage(
HANDLE ioEvent,
void * message,
DWORD messageSize,
DWORD * bytesRead)
DWORD * bytesRead,
DWORD timeoutMs)
{
ResetEvent(ioEvent);
OVERLAPPED overlapped = {};
@@ -106,7 +114,7 @@ CPipeEndpoint::PipeIoResult CPipeEndpoint::ReadMessage(
const DWORD error = GetLastError();
if (error == ERROR_IO_PENDING)
return WaitForOverlapped(
pipe, ioEvent, &overlapped, bytesRead);
pipe, ioEvent, &overlapped, bytesRead, timeoutMs);
if (error == ERROR_OPERATION_ABORTED &&
WaitForSingleObject(m_stopEvent, 0) == WAIT_FIRST_OBJECT_VALUE)
@@ -167,6 +175,8 @@ CPipeEndpoint::PipeIoResult CPipeEndpoint::WriteMessage(
bytesWritten);
result = PipeIoResult::Error;
}
else if (result == PipeIoResult::TimedOut)
DEBUG_WARN("Named pipe write timed out");
return result;
}
@@ -179,27 +189,39 @@ CPipeEndpoint::~CPipeEndpoint()
bool CPipeEndpoint::Start(
const wchar_t * pipeName,
Mode mode,
size_t messageSize)
size_t messageSize,
const SECURITY_ATTRIBUTES * serverSecurity,
DWORD serverOpenMode,
DWORD serverPipeMode)
{
Stop();
if (!pipeName || !*pipeName || !messageSize || messageSize > MAXDWORD)
return false;
m_pipeName = pipeName;
m_mode = mode;
m_messageSize = messageSize;
m_stopEvent = CreateEventW(nullptr, TRUE, FALSE, nullptr);
m_writeEvent = CreateEventW(nullptr, TRUE, FALSE, nullptr);
if (!m_stopEvent || !m_writeEvent)
m_pipeName = pipeName;
m_mode = mode;
m_messageSize = messageSize;
m_hasServerSecurity = serverSecurity != nullptr;
m_serverSecurity = serverSecurity ? *serverSecurity :
SECURITY_ATTRIBUTES {};
m_serverOpenMode = serverOpenMode;
m_serverPipeMode = serverPipeMode;
m_stopEvent = CreateEventW(nullptr, TRUE, FALSE, nullptr);
if (!m_stopEvent)
{
DEBUG_ERROR_HR(GetLastError(), "Failed to create named pipe events");
if (m_writeEvent)
CloseHandle(m_writeEvent);
if (m_stopEvent)
CloseHandle(m_stopEvent);
m_writeEvent = nullptr;
m_stopEvent = nullptr;
const DWORD error = GetLastError();
DEBUG_ERROR_HR(error, "Failed to create the named pipe stop event");
return false;
}
m_writeEvent = CreateEventW(nullptr, TRUE, FALSE, nullptr);
if (!m_writeEvent)
{
const DWORD error = GetLastError();
DEBUG_ERROR_HR(error, "Failed to create the named pipe write event");
CloseHandle(m_stopEvent);
m_stopEvent = nullptr;
return false;
}
@@ -287,6 +309,19 @@ void CPipeEndpoint::Stop()
Atomic::Store(m_connected, false);
}
void CPipeEndpoint::DisconnectClient()
{
Atomic::Store(m_connected, false);
CSRWSharedLock lock(m_pipeLock);
if (m_pipe != INVALID_HANDLE_VALUE &&
!CancelIoEx(m_pipe, nullptr))
{
const DWORD error = GetLastError();
if (error != ERROR_NOT_FOUND)
DEBUG_WARN_HR(error, "Failed to cancel named pipe client I/O");
}
}
bool CPipeEndpoint::Send(const void * message, size_t size)
{
if (!message || size != m_messageSize || !IsRunning() || !IsConnected())
@@ -340,13 +375,14 @@ HANDLE CPipeEndpoint::CreateServerPipe()
HANDLE pipe = CreateNamedPipeW(
m_pipeName.c_str(),
PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED | m_serverOpenMode,
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT |
m_serverPipeMode,
1,
bufferSize,
bufferSize,
0,
nullptr);
m_hasServerSecurity ? &m_serverSecurity : nullptr);
if (pipe == INVALID_HANDLE_VALUE)
DEBUG_ERROR_HR(GetLastError(), "Failed to create named pipe %ls", m_pipeName.c_str());
return pipe;
@@ -420,13 +456,79 @@ void CPipeEndpoint::RunServer()
continue;
}
if (!IsRunning())
break;
if (!IsRunning() ||
WaitForSingleObject(m_stopEvent, 0) == WAIT_FIRST_OBJECT_VALUE)
break;
bool authenticated = false;
if (m_handler && m_handler->PipeClientAuthenticationRequired())
{
std::vector<uint8_t> message(m_messageSize);
DWORD bytesRead = 0;
const PipeIoResult authResult = ReadMessage(
pipe,
ioEvent,
message.data(),
static_cast<DWORD>(message.size()),
&bytesRead,
AUTHENTICATION_TIMEOUT_MS);
if (authResult == PipeIoResult::Success &&
bytesRead != message.size())
{
DEBUG_WARN(
"Named pipe authentication frame has %lu bytes, expected %llu",
bytesRead,
static_cast<unsigned long long>(message.size()));
}
if (authResult != PipeIoResult::Success ||
bytesRead != message.size() ||
!m_handler->AuthenticatePipeClient(
pipe, message.data(), message.size()))
{
if (authResult == PipeIoResult::TimedOut)
DEBUG_WARN("Named pipe client authentication timed out");
else if (authResult == PipeIoResult::Success)
DEBUG_WARN("Named pipe client authentication failed");
if (!DisconnectNamedPipe(pipe))
{
const DWORD error = GetLastError();
if (error != ERROR_PIPE_NOT_CONNECTED)
{
DEBUG_WARN_HR(error,
"Failed to disconnect unauthenticated named pipe client");
ClosePipe(pipe);
pipe = INVALID_HANDLE_VALUE;
}
}
if (authResult == PipeIoResult::Stopped || !IsRunning())
break;
continue;
}
authenticated = true;
}
if (!IsRunning() ||
WaitForSingleObject(m_stopEvent, 0) == WAIT_FIRST_OBJECT_VALUE ||
(m_handler && !m_handler->PipeClientStillAuthorized(pipe)))
{
if (authenticated && m_handler)
m_handler->OnPipeDisconnected();
if (!DisconnectNamedPipe(pipe))
{
const DWORD error = GetLastError();
if (error != ERROR_PIPE_NOT_CONNECTED)
{
DEBUG_WARN_HR(error,
"Failed to disconnect unauthorized named pipe client");
ClosePipe(pipe);
pipe = INVALID_HANDLE_VALUE;
}
}
if (!IsRunning())
break;
continue;
}
Atomic::Store(m_connected, true);
DEBUG_INFO("Named pipe client connected: %ls", m_pipeName.c_str());
if (m_handler)
@@ -494,7 +596,8 @@ void CPipeEndpoint::RunClient()
DWORD mode = PIPE_READMODE_MESSAGE;
if (!SetNamedPipeHandleState(pipe, &mode, nullptr, nullptr))
{
DEBUG_WARN_HR(GetLastError(), "Failed to set named pipe message mode");
const DWORD error = GetLastError();
DEBUG_WARN_HR(error, "Failed to set named pipe message mode");
CloseHandle(pipe);
if (!WaitForRetry(retryDelay))
break;
@@ -502,6 +605,50 @@ void CPipeEndpoint::RunClient()
continue;
}
if (m_handler && !m_handler->PipeServerIsAuthorized(pipe))
{
DEBUG_WARN("Rejected unauthorized named pipe server: %ls",
m_pipeName.c_str());
CloseHandle(pipe);
if (!WaitForRetry(retryDelay))
break;
retryDelay = (std::min)(retryDelay * 2, CLIENT_RETRY_MAX_MS);
continue;
}
if (!IsRunning() ||
WaitForSingleObject(m_stopEvent, 0) == WAIT_FIRST_OBJECT_VALUE)
{
CloseHandle(pipe);
break;
}
if (m_handler && m_handler->PipeClientHelloRequired())
{
std::vector<uint8_t> hello(m_messageSize);
if (!m_handler->BuildPipeClientHello(hello.data(), hello.size()))
{
DEBUG_WARN("Failed to build named pipe client HELLO");
CloseHandle(pipe);
if (!WaitForRetry(retryDelay))
break;
retryDelay = (std::min)(retryDelay * 2, CLIENT_RETRY_MAX_MS);
continue;
}
const PipeIoResult helloResult = WriteMessage(
pipe, hello.data(), static_cast<DWORD>(hello.size()));
if (helloResult != PipeIoResult::Success)
{
DEBUG_WARN("Failed to send named pipe client HELLO");
CloseHandle(pipe);
if (!WaitForRetry(retryDelay))
break;
retryDelay = (std::min)(retryDelay * 2, CLIENT_RETRY_MAX_MS);
continue;
}
}
if (!IsRunning() ||
WaitForSingleObject(m_stopEvent, 0) == WAIT_FIRST_OBJECT_VALUE)
{
@@ -549,7 +696,18 @@ bool CPipeEndpoint::ReadMessages(HANDLE pipe)
ioEvent,
message.data(),
static_cast<DWORD>(message.size()),
&bytesRead);
&bytesRead,
m_handler && m_handler->PipeClientAuthenticationRequired() ?
AUTHORIZATION_POLL_MS : INFINITE);
if (result == PipeIoResult::TimedOut)
{
if (m_handler && !m_handler->PipeClientStillAuthorized(pipe))
{
success = false;
break;
}
continue;
}
if (result != PipeIoResult::Success)
{
success = result == PipeIoResult::Disconnected ||
@@ -571,6 +729,12 @@ bool CPipeEndpoint::ReadMessages(HANDLE pipe)
WaitForSingleObject(m_stopEvent, 0) == WAIT_FIRST_OBJECT_VALUE)
break;
if (m_handler && !m_handler->PipeClientStillAuthorized(pipe))
{
success = false;
break;
}
if (m_handler && !m_handler->OnPipeMessage(
message.data(), message.size()))
{

View File

@@ -36,6 +36,36 @@ public:
virtual void OnPipeConnected() {}
virtual void OnPipeDisconnected() {}
virtual bool ShouldReconnect() { return true; }
virtual bool PipeServerIsAuthorized(_In_ HANDLE pipe)
{
(void) pipe;
return true;
}
virtual bool PipeClientHelloRequired() const { return false; }
virtual bool BuildPipeClientHello(
_Out_writes_bytes_(size) void * message,
_In_ size_t size)
{
(void) message;
(void) size;
return true;
}
virtual bool PipeClientAuthenticationRequired() const { return false; }
virtual bool AuthenticatePipeClient(
_In_ HANDLE pipe,
_In_reads_bytes_(size) const void * message,
_In_ size_t size)
{
(void) pipe;
(void) message;
(void) size;
return true;
}
virtual bool PipeClientStillAuthorized(_In_ HANDLE pipe)
{
(void) pipe;
return true;
}
virtual bool OnPipeMessage(
_In_reads_bytes_(size) const void * message,
_In_ size_t size) = 0;
@@ -59,8 +89,12 @@ public:
bool Start(
_In_z_ const wchar_t * pipeName,
_In_ Mode mode,
_In_ size_t messageSize);
_In_ size_t messageSize,
_In_opt_ const SECURITY_ATTRIBUTES * serverSecurity = nullptr,
_In_ DWORD serverOpenMode = 0,
_In_ DWORD serverPipeMode = 0);
void Stop();
void DisconnectClient();
bool Send(
_In_reads_bytes_(size) const void * message,
@@ -82,12 +116,15 @@ private:
Success,
Disconnected,
Stopped,
TimedOut,
Error,
};
static const DWORD CLIENT_RETRY_INITIAL_MS;
static const DWORD CLIENT_RETRY_MAX_MS;
static const DWORD SERVER_RETRY_MS;
static const DWORD AUTHENTICATION_TIMEOUT_MS;
static const DWORD AUTHORIZATION_POLL_MS;
static const DWORD WRITE_TIMEOUT_MS;
static const DWORD WAIT_FIRST_OBJECT_VALUE;
@@ -103,7 +140,8 @@ private:
_In_ HANDLE ioEvent,
_Out_writes_bytes_(messageSize) void * message,
_In_ DWORD messageSize,
_Out_ DWORD * bytesRead);
_Out_ DWORD * bytesRead,
_In_ DWORD timeoutMs = INFINITE);
PipeIoResult WriteMessage(
_In_ HANDLE pipe,
_In_reads_bytes_(messageSize) const void * message,
@@ -120,10 +158,14 @@ private:
void PublishPipe(_In_ HANDLE pipe);
void ClosePipe(_In_ HANDLE pipe);
std::wstring m_pipeName;
size_t m_messageSize = 0;
Mode m_mode = Mode::Client;
IPipeEndpointHandler * m_handler = nullptr;
std::wstring m_pipeName;
size_t m_messageSize = 0;
Mode m_mode = Mode::Client;
IPipeEndpointHandler * m_handler = nullptr;
SECURITY_ATTRIBUTES m_serverSecurity = {};
bool m_hasServerSecurity = false;
DWORD m_serverOpenMode = 0;
DWORD m_serverPipeMode = 0;
std::atomic<bool> m_running { false };
std::atomic<bool> m_connected { false };

View File

@@ -61,6 +61,7 @@ public:
if (!m_lock)
return;
_Analysis_assume_lock_acquired_(*m_lock);
ReleaseSRWLockShared(m_lock);
m_lock = nullptr;
}
@@ -114,6 +115,7 @@ public:
if (!m_lock)
return;
_Analysis_assume_lock_acquired_(*m_lock);
ReleaseSRWLockExclusive(m_lock);
m_lock = nullptr;
}

View File

@@ -26,7 +26,7 @@
#include <stdint.h>
static constexpr uint32_t LG_CLIPBOARD_MAPPING_MAGIC = 0x4c474342U;
static constexpr uint32_t LG_CLIPBOARD_MAPPING_VERSION = 3U;
static constexpr uint32_t LG_CLIPBOARD_MAPPING_VERSION = 4U;
struct ClipboardRingSlot
{
@@ -51,7 +51,8 @@ struct alignas(64) ClipboardMapping
uint32_t slotCount;
uint32_t reserved0;
uint64_t epoch;
uint8_t reserved1[32];
uint64_t authorityId[2];
uint8_t reserved1[16];
ClipboardRing helperToIdd;
ClipboardRing iddToHelper;
};

View File

@@ -81,6 +81,7 @@
<ClInclude Include="CSRWLock.h" />
<ClInclude Include="DefaultDisplayModes.h" />
<ClInclude Include="InputPipeProtocol.h" />
<ClInclude Include="LGIddAuthority.h" />
<ClInclude Include="PipeMsg.h" />
<ClInclude Include="RefreshRate.h" />
<ClInclude Include="Seq.h" />

View File

@@ -56,6 +56,9 @@
<ClInclude Include="InputPipeProtocol.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="LGIddAuthority.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PipeMsg.h">
<Filter>Header Files</Filter>
</ClInclude>

View File

@@ -0,0 +1,76 @@
/**
* Looking Glass
* Copyright © 2017-2026 The Looking Glass Authors
* https://looking-glass.io
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 59
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#pragma once
#include <Windows.h>
#include <winioctl.h>
#include <stdint.h>
static const GUID GUID_DEVINTERFACE_LGIdd =
{ 0x997b0b66, 0xb74c, 0x4017,
{ 0x9a, 0x89, 0xe4, 0xaa, 0xd4, 0x1d, 0x37, 0x80 } };
static constexpr uint32_t LG_IDD_AUTHORITY_VERSION = 1U;
static constexpr DWORD IOCTL_LG_IDD_AUTHORITY_GET_HOST =
CTL_CODE(FILE_DEVICE_UNKNOWN, 0x800, METHOD_BUFFERED,
FILE_READ_ACCESS | FILE_WRITE_ACCESS);
static constexpr DWORD IOCTL_LG_IDD_AUTHORITY_REGISTER =
CTL_CODE(FILE_DEVICE_UNKNOWN, 0x801, METHOD_BUFFERED,
FILE_READ_ACCESS | FILE_WRITE_ACCESS);
static constexpr DWORD IOCTL_LG_IDD_AUTHORITY_CLEAR =
CTL_CODE(FILE_DEVICE_UNKNOWN, 0x802, METHOD_BUFFERED,
FILE_READ_ACCESS | FILE_WRITE_ACCESS);
struct LGIddAuthorityHost
{
uint32_t size;
uint32_t version;
uint32_t processId;
uint32_t reserved;
uint64_t processCreated;
uint64_t instanceId[2];
};
struct LGIddAuthorityRegistration
{
uint32_t size;
uint32_t version;
uint32_t session;
uint32_t reserved;
uint64_t instanceId[2];
uint64_t mappingId[2];
uint64_t mappingHandle;
};
struct LGIddAuthorityClear
{
uint32_t size;
uint32_t version;
uint64_t instanceId[2];
};
static_assert(sizeof(LGIddAuthorityHost) == 40,
"LGIdd authority host layout changed");
static_assert(sizeof(LGIddAuthorityRegistration) == 56,
"LGIdd authority registration layout changed");
static_assert(sizeof(LGIddAuthorityClear) == 24,
"LGIdd authority clear layout changed");

View File

@@ -43,13 +43,15 @@ struct LGPipeMsg
CLIPBOARD_SETUP,
CLIPBOARD_READY,
CLIPBOARD_KICK,
CLIPBOARD_RESET
CLIPBOARD_RESET,
HELLO
}
type;
enum : uint32_t
{
RECOVERY_ACTIVE = 0x1U
RECOVERY_ACTIVE = 0x1U,
PROTOCOL_VERSION = 2U
};
union
@@ -92,6 +94,7 @@ struct LGPipeMsg
struct
{
// Legacy setup carries a handle already duplicated into the receiver.
uint64_t handle;
uint32_t bytes;
}
@@ -117,8 +120,15 @@ struct LGPipeMsg
uint32_t reason;
}
clipboardReset;
struct
{
uint32_t version;
uint64_t authorityId[2];
}
hello;
};
};
#pragma pack(pop)
static_assert(sizeof(LGPipeMsg) == 20, "LGPipeMsg wire layout changed");
static_assert(sizeof(LGPipeMsg) == 28, "LGPipeMsg wire layout changed");