be4554ccee
Probe the ExecuteR-Screen sidecar at start and report the capability; on open settle consent (Notify, Ask First via WTSSendMessage, unattended, WinPE), start the host as SYSTEM in the active console session from a session-0 service (duplicated token, winsta0\default, handle-listed anonymous pipes, kill-on-close job), relay stdio with backpressure, end on close, idle, console session switch and shutdown. Policy comes from AllowRemoteView and RemoteView* registry/GPO values. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
83 lines
2.6 KiB
C#
83 lines
2.6 KiB
C#
// Fake ExecuteR-Screen: `probe` prints one JSON line; `serve --stdio [...]` reports
|
|
// ready and its state on stderr, echoes stdin to stdout (so tests see bytes go both
|
|
// ways) and exits at stdin EOF with a closed event. `--flood <bytes>` writes that many
|
|
// bytes to stdout first (backpressure tests); `--exit <code>` exits at once with that
|
|
// code (capture unavailable is 2). It records its arguments in FAKE_SCREEN_ARGS_FILE.
|
|
using System.Globalization;
|
|
|
|
var arguments = args.ToList();
|
|
var error = Console.Error;
|
|
|
|
if (Environment.GetEnvironmentVariable("FAKE_SCREEN_ARGS_FILE") is { Length: > 0 } argsFile)
|
|
{
|
|
File.AppendAllText(argsFile, string.Join(' ', arguments) + Environment.NewLine);
|
|
}
|
|
|
|
if (arguments.Contains("probe"))
|
|
{
|
|
Console.Out.WriteLine("""{"version":"0.0.0-fake","capture":true,"input":true,"monitors":[{"index":0,"name":"FAKE1","x":0,"y":0,"width":1280,"height":720,"primary":true}],"desktop":"default","winpe":false,"platform":"windows","reason":null}""");
|
|
return 0;
|
|
}
|
|
|
|
if (!arguments.Contains("serve") || !arguments.Contains("--stdio"))
|
|
{
|
|
error.WriteLine("usage: serve --stdio");
|
|
return 3;
|
|
}
|
|
|
|
if (Value("--exit") is { } exit)
|
|
{
|
|
error.WriteLine("fake: exiting early");
|
|
return int.Parse(exit, CultureInfo.InvariantCulture);
|
|
}
|
|
|
|
var viewOnly = arguments.Contains("--view-only");
|
|
error.WriteLine("fake: starting");
|
|
error.WriteLine("@event {\"type\":\"ready\"}");
|
|
error.WriteLine("@event {\"type\":\"state\",\"monitors\":[{\"index\":0,\"name\":\"FAKE1\",\"x\":0,\"y\":0,\"width\":1280,\"height\":720,\"primary\":true}],\"desktop\":\"default\",\"viewOnly\":"
|
|
+ (viewOnly ? "true" : "false") + ",\"winpe\":false}");
|
|
error.Flush();
|
|
|
|
using var stdin = Console.OpenStandardInput();
|
|
using var stdout = Console.OpenStandardOutput();
|
|
|
|
if (Value("--flood") is { } flood)
|
|
{
|
|
var remaining = long.Parse(flood, CultureInfo.InvariantCulture);
|
|
var block = new byte[16 * 1024];
|
|
while (remaining > 0)
|
|
{
|
|
var count = (int)Math.Min(block.Length, remaining);
|
|
stdout.Write(block, 0, count);
|
|
remaining -= count;
|
|
}
|
|
|
|
stdout.Flush();
|
|
}
|
|
|
|
var buffer = new byte[64 * 1024];
|
|
int read;
|
|
var connected = false;
|
|
while ((read = stdin.Read(buffer, 0, buffer.Length)) > 0)
|
|
{
|
|
if (!connected)
|
|
{
|
|
connected = true;
|
|
error.WriteLine("@event {\"type\":\"connected\"}");
|
|
error.Flush();
|
|
}
|
|
|
|
stdout.Write(buffer, 0, read);
|
|
stdout.Flush();
|
|
}
|
|
|
|
error.WriteLine("@event {\"type\":\"closed\",\"reason\":\"fake: input ended\"}");
|
|
error.Flush();
|
|
return 0;
|
|
|
|
string? Value(string name)
|
|
{
|
|
var index = arguments.IndexOf(name);
|
|
return index >= 0 && index + 1 < arguments.Count ? arguments[index + 1] : null;
|
|
}
|