@sipher.dev/connector-win32-x64 0.6.31 → 0.6.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/agents-connector.exe +2 -2
- package/bin/machine-indicator.ps1 +646 -28
- package/package.json +1 -1
- package/release-manifest.json +1 -1
- package/release-manifest.sig +1 -1
- package/release-trust-anchor.json +3 -3
package/bin/agents-connector.exe
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
[diffend] Oversized file quarantined before diffing.
|
|
2
2
|
name: package/bin/agents-connector.exe
|
|
3
|
-
size:
|
|
4
|
-
sha256:
|
|
3
|
+
size: 99126272 bytes
|
|
4
|
+
sha256: e8ae5955b05f5835a656151d90fdf8ba247341d6734ab79a22e5d2c8d489560c
|
|
@@ -6,6 +6,8 @@ using System;
|
|
|
6
6
|
using System.Collections.Generic;
|
|
7
7
|
using System.Diagnostics;
|
|
8
8
|
using System.Drawing;
|
|
9
|
+
using System.Globalization;
|
|
10
|
+
using System.IO;
|
|
9
11
|
using System.Runtime.InteropServices;
|
|
10
12
|
using System.Text;
|
|
11
13
|
using System.Threading;
|
|
@@ -65,6 +67,25 @@ internal static class IndicatorNative
|
|
|
65
67
|
private static extern IntPtr MonitorFromPoint(Point point, uint flags);
|
|
66
68
|
[DllImport("shcore.dll")]
|
|
67
69
|
private static extern int GetDpiForMonitor(IntPtr monitor, int type, out uint horizontal, out uint vertical);
|
|
70
|
+
[DllImport("user32.dll")]
|
|
71
|
+
private static extern bool GetLastInputInfo(ref LastInput info);
|
|
72
|
+
|
|
73
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
74
|
+
private struct LastInput
|
|
75
|
+
{
|
|
76
|
+
public uint Size;
|
|
77
|
+
public uint Time;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
[ComImport, Guid("a5cd92ff-29be-454c-8d04-d82879fb3f1b"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
|
81
|
+
private interface IVirtualDesktopManager
|
|
82
|
+
{
|
|
83
|
+
[PreserveSig]
|
|
84
|
+
int IsWindowOnCurrentVirtualDesktop(IntPtr window, [MarshalAs(UnmanagedType.Bool)] out bool onCurrent);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private static IVirtualDesktopManager desktops;
|
|
88
|
+
private static bool desktopsUnavailable;
|
|
68
89
|
|
|
69
90
|
internal static bool InteractiveStation()
|
|
70
91
|
{
|
|
@@ -111,6 +132,39 @@ internal static class IndicatorNative
|
|
|
111
132
|
throw new InvalidOperationException("Cannot size machine indicator.");
|
|
112
133
|
}
|
|
113
134
|
|
|
135
|
+
// Keeps a cover over its whole screen and above other windows, without taking the focus.
|
|
136
|
+
internal static void Hold(IntPtr window, Rectangle bounds)
|
|
137
|
+
{
|
|
138
|
+
SetWindowPos(window, new IntPtr(-1), bounds.Left, bounds.Top, bounds.Width, bounds.Height, 0x10);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// False only when Windows says the window sits on another virtual desktop.
|
|
142
|
+
internal static bool OnCurrentDesktop(IntPtr window)
|
|
143
|
+
{
|
|
144
|
+
if (desktopsUnavailable) return true;
|
|
145
|
+
try
|
|
146
|
+
{
|
|
147
|
+
if (desktops == null)
|
|
148
|
+
desktops = (IVirtualDesktopManager)Activator.CreateInstance(
|
|
149
|
+
Type.GetTypeFromCLSID(new Guid("aa509086-5ca9-4c25-8f95-589d3c07b48a")));
|
|
150
|
+
bool onCurrent;
|
|
151
|
+
return desktops.IsWindowOnCurrentVirtualDesktop(window, out onCurrent) != 0 || onCurrent;
|
|
152
|
+
}
|
|
153
|
+
catch (Exception)
|
|
154
|
+
{
|
|
155
|
+
desktopsUnavailable = true;
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Time since the last keyboard or mouse input in this Windows session.
|
|
161
|
+
internal static uint IdleMilliseconds()
|
|
162
|
+
{
|
|
163
|
+
LastInput info = new LastInput();
|
|
164
|
+
info.Size = (uint)Marshal.SizeOf(typeof(LastInput));
|
|
165
|
+
return GetLastInputInfo(ref info) ? unchecked((uint)Environment.TickCount - info.Time) : 0;
|
|
166
|
+
}
|
|
167
|
+
|
|
114
168
|
internal static void EnableDpi()
|
|
115
169
|
{
|
|
116
170
|
try { SetProcessDpiAwareness(2); }
|
|
@@ -211,10 +265,451 @@ internal sealed class IndicatorWindow : Form
|
|
|
211
265
|
}
|
|
212
266
|
}
|
|
213
267
|
|
|
268
|
+
internal sealed class IndicatorView
|
|
269
|
+
{
|
|
270
|
+
internal string Edges;
|
|
271
|
+
internal string Panel;
|
|
272
|
+
internal string Agents;
|
|
273
|
+
internal int IdleSeconds;
|
|
274
|
+
internal string MachineName;
|
|
275
|
+
internal string ByName;
|
|
276
|
+
internal string UnlockUrl;
|
|
277
|
+
internal string[] Qr;
|
|
278
|
+
|
|
279
|
+
internal static IndicatorView Parse(byte[] line, int length)
|
|
280
|
+
{
|
|
281
|
+
if (length > 0 && line[length - 1] == '\r') length--;
|
|
282
|
+
string[] fields = new UTF8Encoding(false).GetString(line, 0, length).Split('\t');
|
|
283
|
+
IndicatorView view = new IndicatorView();
|
|
284
|
+
if (fields.Length != 9 || fields[0] != "v2" ||
|
|
285
|
+
!OneOf(fields[1], "held", "windowOpen", "hidden") ||
|
|
286
|
+
!OneOf(fields[2], "none", "cover", "bar_in_use") ||
|
|
287
|
+
!OneOf(fields[3], "running", "stopped", "-") ||
|
|
288
|
+
!int.TryParse(fields[4], NumberStyles.None, CultureInfo.InvariantCulture, out view.IdleSeconds) ||
|
|
289
|
+
!ValidQr(fields[8]))
|
|
290
|
+
throw new InvalidOperationException("Invalid machine indicator state.");
|
|
291
|
+
view.Edges = fields[1];
|
|
292
|
+
view.Panel = fields[2];
|
|
293
|
+
view.Agents = fields[3];
|
|
294
|
+
view.MachineName = Absent(fields[5]);
|
|
295
|
+
view.ByName = Absent(fields[6]);
|
|
296
|
+
view.UnlockUrl = Absent(fields[7]);
|
|
297
|
+
view.Qr = fields[8] == "-" ? null : fields[8].Split('/');
|
|
298
|
+
return view;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
private static bool OneOf(string value, params string[] allowed)
|
|
302
|
+
{
|
|
303
|
+
return Array.IndexOf(allowed, value) >= 0;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
private static string Absent(string value)
|
|
307
|
+
{
|
|
308
|
+
return value == "-" ? null : value;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
private static bool ValidQr(string value)
|
|
312
|
+
{
|
|
313
|
+
if (value == "-") return true;
|
|
314
|
+
string[] rows = value.Split('/');
|
|
315
|
+
foreach (string row in rows)
|
|
316
|
+
{
|
|
317
|
+
if (row.Length != rows.Length) return false;
|
|
318
|
+
foreach (char module in row)
|
|
319
|
+
if (module != '0' && module != '1') return false;
|
|
320
|
+
}
|
|
321
|
+
return true;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// Drops the keys a person presses while the cover is up; keys sent by a program pass.
|
|
326
|
+
internal static class KeyboardBlock
|
|
327
|
+
{
|
|
328
|
+
private delegate IntPtr HookProc(int code, IntPtr wParam, IntPtr lParam);
|
|
329
|
+
|
|
330
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
331
|
+
private struct ThreadMessage
|
|
332
|
+
{
|
|
333
|
+
public IntPtr Window;
|
|
334
|
+
public uint Id;
|
|
335
|
+
public IntPtr WParam;
|
|
336
|
+
public IntPtr LParam;
|
|
337
|
+
public uint Time;
|
|
338
|
+
public int X;
|
|
339
|
+
public int Y;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
[DllImport("user32.dll")]
|
|
343
|
+
private static extern IntPtr SetWindowsHookEx(int kind, HookProc callback, IntPtr module, uint threadId);
|
|
344
|
+
[DllImport("user32.dll")]
|
|
345
|
+
private static extern bool UnhookWindowsHookEx(IntPtr hook);
|
|
346
|
+
[DllImport("user32.dll")]
|
|
347
|
+
private static extern IntPtr CallNextHookEx(IntPtr hook, int code, IntPtr wParam, IntPtr lParam);
|
|
348
|
+
[DllImport("user32.dll")]
|
|
349
|
+
private static extern int GetMessage(out ThreadMessage message, IntPtr window, uint first, uint last);
|
|
350
|
+
[DllImport("user32.dll")]
|
|
351
|
+
private static extern bool PostThreadMessage(uint threadId, uint message, IntPtr wParam, IntPtr lParam);
|
|
352
|
+
[DllImport("user32.dll")]
|
|
353
|
+
private static extern IntPtr SetTimer(IntPtr window, IntPtr id, uint milliseconds, IntPtr callback);
|
|
354
|
+
[DllImport("user32.dll")]
|
|
355
|
+
private static extern bool KillTimer(IntPtr window, IntPtr id);
|
|
356
|
+
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
|
|
357
|
+
private static extern IntPtr GetModuleHandle(string name);
|
|
358
|
+
[DllImport("kernel32.dll")]
|
|
359
|
+
private static extern uint GetCurrentThreadId();
|
|
360
|
+
|
|
361
|
+
// Held in a static field so the garbage collector never frees a delegate Windows still calls.
|
|
362
|
+
private static readonly HookProc callback = Callback;
|
|
363
|
+
private static Thread thread;
|
|
364
|
+
private static uint threadId;
|
|
365
|
+
private static bool failureLogged;
|
|
366
|
+
|
|
367
|
+
internal static void Start()
|
|
368
|
+
{
|
|
369
|
+
if (thread != null) return;
|
|
370
|
+
using (ManualResetEvent started = new ManualResetEvent(false))
|
|
371
|
+
{
|
|
372
|
+
thread = new Thread(Loop);
|
|
373
|
+
thread.IsBackground = true;
|
|
374
|
+
thread.Start(started);
|
|
375
|
+
started.WaitOne();
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
internal static void Stop()
|
|
380
|
+
{
|
|
381
|
+
if (thread == null) return;
|
|
382
|
+
PostThreadMessage(threadId, 0x12, IntPtr.Zero, IntPtr.Zero);
|
|
383
|
+
thread.Join(2000);
|
|
384
|
+
thread = null;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// The hook has its own thread and message loop so a slow repaint cannot delay it.
|
|
388
|
+
private static void Loop(object started)
|
|
389
|
+
{
|
|
390
|
+
threadId = GetCurrentThreadId();
|
|
391
|
+
IntPtr hook = Install();
|
|
392
|
+
IntPtr timer = SetTimer(IntPtr.Zero, IntPtr.Zero, 30000, IntPtr.Zero);
|
|
393
|
+
((ManualResetEvent)started).Set();
|
|
394
|
+
try
|
|
395
|
+
{
|
|
396
|
+
ThreadMessage message;
|
|
397
|
+
while (GetMessage(out message, IntPtr.Zero, 0, 0) > 0)
|
|
398
|
+
{
|
|
399
|
+
// Windows silently removes a hook that answered too slowly, so install it again.
|
|
400
|
+
if (message.Id != 0x113) continue;
|
|
401
|
+
if (hook != IntPtr.Zero) UnhookWindowsHookEx(hook);
|
|
402
|
+
hook = Install();
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
finally
|
|
406
|
+
{
|
|
407
|
+
KillTimer(IntPtr.Zero, timer);
|
|
408
|
+
if (hook != IntPtr.Zero) UnhookWindowsHookEx(hook);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
private static IntPtr Install()
|
|
413
|
+
{
|
|
414
|
+
IntPtr hook = SetWindowsHookEx(13, callback, GetModuleHandle(null), 0);
|
|
415
|
+
if (hook == IntPtr.Zero && !failureLogged)
|
|
416
|
+
{
|
|
417
|
+
Console.Error.WriteLine("Machine indicator cannot block the keyboard; the cover is still shown.");
|
|
418
|
+
failureLogged = true;
|
|
419
|
+
}
|
|
420
|
+
return hook;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
private static IntPtr Callback(int code, IntPtr wParam, IntPtr lParam)
|
|
424
|
+
{
|
|
425
|
+
if (code >= 0 && (Marshal.ReadInt32(lParam, 8) & 0x10) == 0) return new IntPtr(1);
|
|
426
|
+
return CallNextHookEx(IntPtr.Zero, code, wParam, lParam);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
internal sealed class CoverWindow : Form
|
|
431
|
+
{
|
|
432
|
+
private static bool captureLogged;
|
|
433
|
+
private readonly Rectangle bounds;
|
|
434
|
+
private readonly bool primary;
|
|
435
|
+
private readonly float scale;
|
|
436
|
+
private IndicatorView view;
|
|
437
|
+
|
|
438
|
+
internal CoverWindow(Rectangle bounds, bool primary, float scale, IndicatorView view)
|
|
439
|
+
{
|
|
440
|
+
this.bounds = bounds;
|
|
441
|
+
this.primary = primary;
|
|
442
|
+
this.scale = scale;
|
|
443
|
+
this.view = view;
|
|
444
|
+
AutoScaleMode = AutoScaleMode.None;
|
|
445
|
+
FormBorderStyle = FormBorderStyle.None;
|
|
446
|
+
ShowInTaskbar = false;
|
|
447
|
+
StartPosition = FormStartPosition.Manual;
|
|
448
|
+
Bounds = bounds;
|
|
449
|
+
TopMost = true;
|
|
450
|
+
DoubleBuffered = true;
|
|
451
|
+
BackColor = Color.FromArgb(17, 19, 24);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
protected override bool ShowWithoutActivation { get { return true; } }
|
|
455
|
+
|
|
456
|
+
protected override CreateParams CreateParams
|
|
457
|
+
{
|
|
458
|
+
get
|
|
459
|
+
{
|
|
460
|
+
CreateParams parameters = base.CreateParams;
|
|
461
|
+
parameters.ExStyle |= 0x08000088;
|
|
462
|
+
return parameters;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
protected override void OnHandleCreated(EventArgs args)
|
|
467
|
+
{
|
|
468
|
+
base.OnHandleCreated(args);
|
|
469
|
+
// Covering wins over capturing: a cover that cannot be left out of captures is still drawn.
|
|
470
|
+
if (!IndicatorNative.Exclude(Handle) && !captureLogged)
|
|
471
|
+
{
|
|
472
|
+
Console.Error.WriteLine("Machine cover capture exclusion unavailable; the cover is visible in captures.");
|
|
473
|
+
captureLogged = true;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
protected override void OnShown(EventArgs args)
|
|
478
|
+
{
|
|
479
|
+
base.OnShown(args);
|
|
480
|
+
Hold();
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
protected override void OnFormClosing(FormClosingEventArgs args)
|
|
484
|
+
{
|
|
485
|
+
if (args.CloseReason == CloseReason.UserClosing) args.Cancel = true;
|
|
486
|
+
base.OnFormClosing(args);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
protected override void WndProc(ref Message message)
|
|
490
|
+
{
|
|
491
|
+
// A click on the cover is discarded: it reaches no program behind it and moves no focus.
|
|
492
|
+
if (message.Msg == 0x21) { message.Result = new IntPtr(4); return; }
|
|
493
|
+
if (message.Msg >= 0x201 && message.Msg <= 0x20E) { message.Result = IntPtr.Zero; return; }
|
|
494
|
+
base.WndProc(ref message);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
internal void Hold()
|
|
498
|
+
{
|
|
499
|
+
IndicatorNative.Hold(Handle, bounds);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
internal void SetView(IndicatorView next)
|
|
503
|
+
{
|
|
504
|
+
if (ReferenceEquals(view, next)) return;
|
|
505
|
+
view = next;
|
|
506
|
+
Invalidate();
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
protected override void OnPaint(PaintEventArgs args)
|
|
510
|
+
{
|
|
511
|
+
args.Graphics.Clear(BackColor);
|
|
512
|
+
if (!primary) return;
|
|
513
|
+
using (Font title = new Font("Segoe UI", 30 * scale, FontStyle.Bold, GraphicsUnit.Pixel))
|
|
514
|
+
using (Font body = new Font("Segoe UI", 18 * scale, FontStyle.Regular, GraphicsUnit.Pixel))
|
|
515
|
+
using (Font link = new Font("Segoe UI", 14 * scale, FontStyle.Regular, GraphicsUnit.Pixel))
|
|
516
|
+
{
|
|
517
|
+
int height = Stack(args.Graphics, 0, false, title, body, link);
|
|
518
|
+
Stack(args.Graphics, Math.Max(0, (ClientSize.Height - height) / 2), true, title, body, link);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// Stacks the cover's content from top down and returns its height; draws only when asked.
|
|
523
|
+
private int Stack(Graphics graphics, int top, bool draw, Font title, Font body, Font link)
|
|
524
|
+
{
|
|
525
|
+
int gap = (int)(16 * scale);
|
|
526
|
+
int y = top;
|
|
527
|
+
y += Line(graphics, view.MachineName, title, Color.White, y, draw) + gap;
|
|
528
|
+
y += Line(graphics, "This PC works for agents.", body, Color.FromArgb(214, 218, 226), y, draw);
|
|
529
|
+
y += Line(graphics, "Scan the code to unlock it in Vesper.", body, Color.FromArgb(214, 218, 226), y, draw) + gap;
|
|
530
|
+
if (view.Qr != null)
|
|
531
|
+
{
|
|
532
|
+
int modules = view.Qr.Length + 8;
|
|
533
|
+
int module = Math.Max((int)Math.Ceiling(4 * scale), (int)(260 * scale) / modules);
|
|
534
|
+
int side = module * modules;
|
|
535
|
+
int left = (ClientSize.Width - side) / 2;
|
|
536
|
+
if (draw)
|
|
537
|
+
{
|
|
538
|
+
graphics.FillRectangle(Brushes.White, left, y, side, side);
|
|
539
|
+
for (int row = 0; row < view.Qr.Length; row++)
|
|
540
|
+
for (int column = 0; column < view.Qr.Length; column++)
|
|
541
|
+
if (view.Qr[row][column] == '1')
|
|
542
|
+
graphics.FillRectangle(Brushes.Black, left + (column + 4) * module, y + (row + 4) * module, module, module);
|
|
543
|
+
}
|
|
544
|
+
y += side + gap;
|
|
545
|
+
}
|
|
546
|
+
y += Line(graphics, view.UnlockUrl, link, Color.FromArgb(160, 166, 178), y, draw);
|
|
547
|
+
return y - top;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
private int Line(Graphics graphics, string text, Font font, Color color, int top, bool draw)
|
|
551
|
+
{
|
|
552
|
+
if (string.IsNullOrEmpty(text)) return 0;
|
|
553
|
+
TextFormatFlags flags = TextFormatFlags.HorizontalCenter | TextFormatFlags.WordBreak |
|
|
554
|
+
TextFormatFlags.TextBoxControl | TextFormatFlags.NoPrefix;
|
|
555
|
+
int width = Math.Max(1, Math.Min(ClientSize.Width - (int)(96 * scale), (int)(760 * scale)));
|
|
556
|
+
int height = TextRenderer.MeasureText(graphics, text, font, new Size(width, int.MaxValue), flags).Height;
|
|
557
|
+
if (draw)
|
|
558
|
+
TextRenderer.DrawText(graphics, text, font,
|
|
559
|
+
new Rectangle((ClientSize.Width - width) / 2, top, width, height), color, flags);
|
|
560
|
+
return height;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
// The bar: a label and buttons that take clicks without taking the focus from the program in front.
|
|
565
|
+
internal sealed class BarWindow : Form
|
|
566
|
+
{
|
|
567
|
+
internal readonly Rectangle Area;
|
|
568
|
+
private const TextFormatFlags Flags = TextFormatFlags.SingleLine | TextFormatFlags.NoPrefix |
|
|
569
|
+
TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter;
|
|
570
|
+
private readonly string text;
|
|
571
|
+
private readonly string[] buttons;
|
|
572
|
+
private readonly Rectangle[] hit;
|
|
573
|
+
private readonly Action<int> click;
|
|
574
|
+
private readonly Font font;
|
|
575
|
+
private Rectangle textBox;
|
|
576
|
+
private int hot = -1;
|
|
577
|
+
private int pressed = -1;
|
|
578
|
+
|
|
579
|
+
// The corner is where the window's bottom-right corner goes.
|
|
580
|
+
internal BarWindow(Point corner, float scale, string text, string[] buttons, Action<int> click)
|
|
581
|
+
{
|
|
582
|
+
this.text = text;
|
|
583
|
+
this.buttons = buttons;
|
|
584
|
+
this.click = click;
|
|
585
|
+
font = new Font("Segoe UI", 13 * scale, FontStyle.Regular, GraphicsUnit.Pixel);
|
|
586
|
+
hit = new Rectangle[buttons.Length];
|
|
587
|
+
int pad = (int)(12 * scale);
|
|
588
|
+
int gap = (int)(8 * scale);
|
|
589
|
+
int inset = (int)(6 * scale);
|
|
590
|
+
int height = (int)(44 * scale);
|
|
591
|
+
int x = pad;
|
|
592
|
+
textBox = new Rectangle(x, 0, Measure(text), height);
|
|
593
|
+
x = textBox.Right + gap;
|
|
594
|
+
for (int index = 0; index < buttons.Length; index++)
|
|
595
|
+
{
|
|
596
|
+
hit[index] = new Rectangle(x, inset, Measure(buttons[index]) + pad * 2, height - inset * 2);
|
|
597
|
+
x = hit[index].Right + gap;
|
|
598
|
+
}
|
|
599
|
+
Size size = new Size(x - gap + pad, height);
|
|
600
|
+
Area = new Rectangle(corner.X - size.Width, corner.Y - size.Height, size.Width, size.Height);
|
|
601
|
+
AutoScaleMode = AutoScaleMode.None;
|
|
602
|
+
FormBorderStyle = FormBorderStyle.None;
|
|
603
|
+
ShowInTaskbar = false;
|
|
604
|
+
StartPosition = FormStartPosition.Manual;
|
|
605
|
+
Bounds = Area;
|
|
606
|
+
TopMost = true;
|
|
607
|
+
DoubleBuffered = true;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
protected override bool ShowWithoutActivation { get { return true; } }
|
|
611
|
+
|
|
612
|
+
protected override CreateParams CreateParams
|
|
613
|
+
{
|
|
614
|
+
get
|
|
615
|
+
{
|
|
616
|
+
CreateParams parameters = base.CreateParams;
|
|
617
|
+
parameters.ExStyle |= 0x08000088;
|
|
618
|
+
return parameters;
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
protected override void OnHandleCreated(EventArgs args)
|
|
623
|
+
{
|
|
624
|
+
base.OnHandleCreated(args);
|
|
625
|
+
// Left out of screen captures when Windows allows it; drawn either way.
|
|
626
|
+
IndicatorNative.Exclude(Handle);
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
protected override void OnShown(EventArgs args)
|
|
630
|
+
{
|
|
631
|
+
base.OnShown(args);
|
|
632
|
+
IndicatorNative.SetBounds(Handle, Area);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
protected override void WndProc(ref Message message)
|
|
636
|
+
{
|
|
637
|
+
if (message.Msg == 0x21) { message.Result = new IntPtr(3); return; }
|
|
638
|
+
base.WndProc(ref message);
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
private int Measure(string value)
|
|
642
|
+
{
|
|
643
|
+
return TextRenderer.MeasureText(value, font, new Size(int.MaxValue, int.MaxValue), Flags).Width;
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
private int Hit(Point point)
|
|
647
|
+
{
|
|
648
|
+
for (int index = 0; index < hit.Length; index++)
|
|
649
|
+
if (hit[index].Contains(point)) return index;
|
|
650
|
+
return -1;
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
protected override void OnMouseMove(MouseEventArgs args)
|
|
654
|
+
{
|
|
655
|
+
base.OnMouseMove(args);
|
|
656
|
+
int next = Hit(args.Location);
|
|
657
|
+
if (next == hot) return;
|
|
658
|
+
hot = next;
|
|
659
|
+
Invalidate();
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
protected override void OnMouseLeave(EventArgs args)
|
|
663
|
+
{
|
|
664
|
+
base.OnMouseLeave(args);
|
|
665
|
+
hot = -1;
|
|
666
|
+
Invalidate();
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
protected override void OnMouseDown(MouseEventArgs args)
|
|
670
|
+
{
|
|
671
|
+
base.OnMouseDown(args);
|
|
672
|
+
if (args.Button == MouseButtons.Left) pressed = Hit(args.Location);
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
protected override void OnMouseUp(MouseEventArgs args)
|
|
676
|
+
{
|
|
677
|
+
base.OnMouseUp(args);
|
|
678
|
+
if (args.Button != MouseButtons.Left) return;
|
|
679
|
+
int index = pressed;
|
|
680
|
+
pressed = -1;
|
|
681
|
+
// Posted, so a click that closes this window runs after its mouse message is done.
|
|
682
|
+
if (index >= 0 && index == Hit(args.Location)) BeginInvoke(click, index);
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
protected override void OnPaint(PaintEventArgs args)
|
|
686
|
+
{
|
|
687
|
+
Graphics graphics = args.Graphics;
|
|
688
|
+
graphics.Clear(Color.FromArgb(28, 30, 36));
|
|
689
|
+
TextRenderer.DrawText(graphics, text, font, textBox, Color.FromArgb(230, 232, 236), Flags);
|
|
690
|
+
for (int index = 0; index < buttons.Length; index++)
|
|
691
|
+
{
|
|
692
|
+
using (Brush fill = new SolidBrush(index == hot ? Color.FromArgb(84, 90, 104) : Color.FromArgb(58, 62, 72)))
|
|
693
|
+
graphics.FillRectangle(fill, hit[index]);
|
|
694
|
+
TextRenderer.DrawText(graphics, buttons[index], font, hit[index], Color.White, Flags);
|
|
695
|
+
}
|
|
696
|
+
using (Pen border = new Pen(Color.FromArgb(78, 82, 94)))
|
|
697
|
+
graphics.DrawRectangle(border, 0, 0, ClientSize.Width - 1, ClientSize.Height - 1);
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
protected override void Dispose(bool disposing)
|
|
701
|
+
{
|
|
702
|
+
if (disposing) font.Dispose();
|
|
703
|
+
base.Dispose(disposing);
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
|
|
214
707
|
public sealed class VesperMachineIndicator : ApplicationContext
|
|
215
708
|
{
|
|
709
|
+
private static readonly Stream output = Console.OpenStandardOutput();
|
|
216
710
|
private readonly object gate = new object();
|
|
217
|
-
private
|
|
711
|
+
private IndicatorView view;
|
|
712
|
+
private int serial;
|
|
218
713
|
private long received = Stopwatch.GetTimestamp();
|
|
219
714
|
private bool inputClosed;
|
|
220
715
|
private string displayed = "hidden";
|
|
@@ -222,6 +717,14 @@ public sealed class VesperMachineIndicator : ApplicationContext
|
|
|
222
717
|
private bool fallback;
|
|
223
718
|
private bool fallbackLogged;
|
|
224
719
|
private readonly List<IndicatorWindow> windows = new List<IndicatorWindow>();
|
|
720
|
+
private readonly List<CoverWindow> covers = new List<CoverWindow>();
|
|
721
|
+
private CoverWindow primaryCover;
|
|
722
|
+
private BarWindow bar;
|
|
723
|
+
private string panelKey = "none";
|
|
724
|
+
private string panelLayout = "";
|
|
725
|
+
private string readyPanel;
|
|
726
|
+
private int idleLine;
|
|
727
|
+
private long inUseSince;
|
|
225
728
|
private readonly System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
|
|
226
729
|
|
|
227
730
|
private VesperMachineIndicator()
|
|
@@ -238,25 +741,27 @@ public sealed class VesperMachineIndicator : ApplicationContext
|
|
|
238
741
|
{
|
|
239
742
|
try
|
|
240
743
|
{
|
|
241
|
-
|
|
744
|
+
Stream input = Console.OpenStandardInput();
|
|
745
|
+
byte[] chunk = new byte[4096];
|
|
746
|
+
byte[] line = new byte[8192];
|
|
242
747
|
int length = 0;
|
|
243
748
|
for (;;)
|
|
244
749
|
{
|
|
245
|
-
int
|
|
246
|
-
if (
|
|
247
|
-
|
|
248
|
-
{
|
|
249
|
-
int count = length > 0 && line[length - 1] == '\r' ? length - 1 : length;
|
|
250
|
-
string next = new string(line, 0, count);
|
|
251
|
-
if (next != "held" && next != "windowOpen" && next != "hidden")
|
|
252
|
-
throw new InvalidOperationException("Invalid machine indicator state.");
|
|
253
|
-
lock (gate) { state = next; received = Stopwatch.GetTimestamp(); }
|
|
254
|
-
length = 0;
|
|
255
|
-
}
|
|
256
|
-
else
|
|
750
|
+
int read = input.Read(chunk, 0, chunk.Length);
|
|
751
|
+
if (read <= 0) break;
|
|
752
|
+
for (int index = 0; index < read; index++)
|
|
257
753
|
{
|
|
258
|
-
if (
|
|
259
|
-
|
|
754
|
+
if (chunk[index] == '\n')
|
|
755
|
+
{
|
|
756
|
+
IndicatorView next = IndicatorView.Parse(line, length);
|
|
757
|
+
lock (gate) { view = next; serial++; received = Stopwatch.GetTimestamp(); }
|
|
758
|
+
length = 0;
|
|
759
|
+
}
|
|
760
|
+
else
|
|
761
|
+
{
|
|
762
|
+
if (length == line.Length) throw new InvalidOperationException("Machine indicator state too long.");
|
|
763
|
+
line[length++] = chunk[index];
|
|
764
|
+
}
|
|
260
765
|
}
|
|
261
766
|
}
|
|
262
767
|
}
|
|
@@ -264,32 +769,86 @@ public sealed class VesperMachineIndicator : ApplicationContext
|
|
|
264
769
|
finally { lock (gate) { inputClosed = true; } }
|
|
265
770
|
}
|
|
266
771
|
|
|
772
|
+
private static void Emit(string line)
|
|
773
|
+
{
|
|
774
|
+
try
|
|
775
|
+
{
|
|
776
|
+
byte[] bytes = Encoding.ASCII.GetBytes(line + "\n");
|
|
777
|
+
output.Write(bytes, 0, bytes.Length);
|
|
778
|
+
output.Flush();
|
|
779
|
+
}
|
|
780
|
+
catch (IOException) { }
|
|
781
|
+
}
|
|
782
|
+
|
|
267
783
|
private void Tick(object sender, EventArgs args)
|
|
268
784
|
{
|
|
269
|
-
|
|
785
|
+
IndicatorView next;
|
|
786
|
+
int line;
|
|
270
787
|
bool closed;
|
|
788
|
+
bool silent;
|
|
271
789
|
lock (gate)
|
|
272
790
|
{
|
|
273
791
|
closed = inputClosed;
|
|
274
|
-
next =
|
|
792
|
+
next = view;
|
|
793
|
+
line = serial;
|
|
794
|
+
silent = (Stopwatch.GetTimestamp() - received) / (double)Stopwatch.Frequency >= 150;
|
|
275
795
|
}
|
|
276
796
|
if (closed) { ExitThread(); return; }
|
|
277
|
-
if (
|
|
797
|
+
if (next == null) return;
|
|
798
|
+
// A cover stays up when the connector goes silent; everything else is removed.
|
|
799
|
+
bool shown = next.Panel == "cover" || !silent;
|
|
800
|
+
string edges = shown ? next.Edges : "hidden";
|
|
801
|
+
string panel = shown ? next.Panel : "none";
|
|
802
|
+
// A repeated in-use line keeps the time the panel first became in use.
|
|
803
|
+
if (panel != "bar_in_use") inUseSince = 0;
|
|
804
|
+
else if (inUseSince == 0) inUseSince = Stopwatch.GetTimestamp();
|
|
805
|
+
if (panel == "cover") KeyboardBlock.Start();
|
|
806
|
+
else KeyboardBlock.Stop();
|
|
807
|
+
if (IndicatorNative.InputDesktop())
|
|
808
|
+
{
|
|
809
|
+
Screen[] screens = Screen.AllScreens;
|
|
810
|
+
StringBuilder signature = new StringBuilder();
|
|
811
|
+
foreach (Screen screen in screens)
|
|
812
|
+
signature.Append(screen.DeviceName).Append(screen.Bounds).Append(screen.WorkingArea).Append(IndicatorNative.Scale(screen));
|
|
813
|
+
ShowEdges(edges, screens, signature.ToString());
|
|
814
|
+
ShowPanel(next, panel, screens, signature.ToString());
|
|
815
|
+
if (shown && next.Panel != readyPanel)
|
|
816
|
+
{
|
|
817
|
+
readyPanel = next.Panel;
|
|
818
|
+
Emit("ready");
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
else
|
|
822
|
+
{
|
|
823
|
+
ClearWindows();
|
|
824
|
+
displayed = "hidden";
|
|
825
|
+
ClearPanel();
|
|
826
|
+
}
|
|
827
|
+
// Once per state line.
|
|
828
|
+
// Idle counts from the last input or from the take-over, whichever is later, so a person
|
|
829
|
+
// who unlocks from a phone gets the full time to reach a PC nobody has touched for an hour.
|
|
830
|
+
if (panel == "bar_in_use" && next.IdleSeconds > 0 && line != idleLine &&
|
|
831
|
+
Math.Min(IndicatorNative.IdleMilliseconds(),
|
|
832
|
+
(Stopwatch.GetTimestamp() - inUseSince) * 1000.0 / Stopwatch.Frequency) >= next.IdleSeconds * 1000L)
|
|
833
|
+
{
|
|
834
|
+
idleLine = line;
|
|
835
|
+
Emit("idle");
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
private void ShowEdges(string next, Screen[] screens, string signature)
|
|
840
|
+
{
|
|
278
841
|
if (next == "hidden")
|
|
279
842
|
{
|
|
280
843
|
ClearWindows();
|
|
281
844
|
displayed = "hidden";
|
|
282
845
|
return;
|
|
283
846
|
}
|
|
284
|
-
Screen[] screens = Screen.AllScreens;
|
|
285
|
-
StringBuilder signature = new StringBuilder();
|
|
286
|
-
foreach (Screen screen in screens)
|
|
287
|
-
signature.Append(screen.DeviceName).Append(screen.Bounds).Append(screen.WorkingArea).Append(IndicatorNative.Scale(screen));
|
|
288
847
|
bool failed = !fallback && windows.Exists(delegate(IndicatorWindow window) { return !window.CaptureExcluded; });
|
|
289
|
-
if (windows.Count == 0 || signature
|
|
848
|
+
if (windows.Count == 0 || signature != layout || failed)
|
|
290
849
|
{
|
|
291
850
|
ClearWindows();
|
|
292
|
-
layout = signature
|
|
851
|
+
layout = signature;
|
|
293
852
|
fallback = !IndicatorNative.CaptureExclusionAvailable() || failed;
|
|
294
853
|
if (!fallback)
|
|
295
854
|
{
|
|
@@ -323,6 +882,59 @@ public sealed class VesperMachineIndicator : ApplicationContext
|
|
|
323
882
|
displayed = next;
|
|
324
883
|
}
|
|
325
884
|
|
|
885
|
+
private void ShowPanel(IndicatorView next, string panel, Screen[] screens, string signature)
|
|
886
|
+
{
|
|
887
|
+
string key = panel == "bar_in_use" ? panel + "\t" + next.Agents + "\t" + next.ByName : panel;
|
|
888
|
+
// A touchpad gesture can change the virtual desktop and leave the cover behind.
|
|
889
|
+
bool left = primaryCover != null && !IndicatorNative.OnCurrentDesktop(primaryCover.Handle);
|
|
890
|
+
if (key != panelKey || signature != panelLayout || left)
|
|
891
|
+
{
|
|
892
|
+
ClearPanel();
|
|
893
|
+
panelKey = key;
|
|
894
|
+
panelLayout = signature;
|
|
895
|
+
if (panel == "cover")
|
|
896
|
+
{
|
|
897
|
+
foreach (Screen screen in screens)
|
|
898
|
+
{
|
|
899
|
+
CoverWindow cover = new CoverWindow(screen.Bounds, screen.Primary, IndicatorNative.Scale(screen), next);
|
|
900
|
+
covers.Add(cover);
|
|
901
|
+
if (screen.Primary) primaryCover = cover;
|
|
902
|
+
cover.Show();
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
else if (panel != "none") CreateBar(next);
|
|
906
|
+
}
|
|
907
|
+
foreach (CoverWindow cover in covers)
|
|
908
|
+
{
|
|
909
|
+
cover.SetView(next);
|
|
910
|
+
cover.Hold();
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
private void CreateBar(IndicatorView next)
|
|
915
|
+
{
|
|
916
|
+
Screen screen = Screen.PrimaryScreen;
|
|
917
|
+
float scale = IndicatorNative.Scale(screen);
|
|
918
|
+
int margin = (int)(8 * scale);
|
|
919
|
+
Point corner = new Point(screen.WorkingArea.Right - margin, screen.WorkingArea.Bottom - margin);
|
|
920
|
+
bool stopped = next.Agents == "stopped";
|
|
921
|
+
bar = new BarWindow(corner, scale,
|
|
922
|
+
"In use by " + (next.ByName ?? "you") + " \u00B7 Agents " + (stopped ? "stopped" : "running"),
|
|
923
|
+
new string[] { stopped ? "Resume agents" : "Stop agents", "Give back" },
|
|
924
|
+
delegate(int index) { Emit(index == 1 ? "giveback" : stopped ? "agents\trunning" : "agents\tstopped"); });
|
|
925
|
+
bar.Show();
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
private void ClearPanel()
|
|
929
|
+
{
|
|
930
|
+
foreach (CoverWindow cover in covers) cover.Dispose();
|
|
931
|
+
covers.Clear();
|
|
932
|
+
primaryCover = null;
|
|
933
|
+
if (bar != null) bar.Dispose();
|
|
934
|
+
bar = null;
|
|
935
|
+
panelKey = "none";
|
|
936
|
+
}
|
|
937
|
+
|
|
326
938
|
private bool CreateEdges(Screen screen, string next)
|
|
327
939
|
{
|
|
328
940
|
float scale = IndicatorNative.Scale(screen);
|
|
@@ -358,12 +970,14 @@ public sealed class VesperMachineIndicator : ApplicationContext
|
|
|
358
970
|
{
|
|
359
971
|
timer.Stop();
|
|
360
972
|
ClearWindows();
|
|
973
|
+
ClearPanel();
|
|
974
|
+
KeyboardBlock.Stop();
|
|
361
975
|
base.ExitThreadCore();
|
|
362
976
|
}
|
|
363
977
|
|
|
364
978
|
protected override void Dispose(bool disposing)
|
|
365
979
|
{
|
|
366
|
-
if (disposing) { timer.Dispose(); ClearWindows(); }
|
|
980
|
+
if (disposing) { timer.Dispose(); ClearWindows(); ClearPanel(); }
|
|
367
981
|
base.Dispose(disposing);
|
|
368
982
|
}
|
|
369
983
|
|
|
@@ -373,8 +987,12 @@ public sealed class VesperMachineIndicator : ApplicationContext
|
|
|
373
987
|
throw new InvalidOperationException("Machine indicator requires an interactive window station outside session 0.");
|
|
374
988
|
IndicatorNative.EnableDpi();
|
|
375
989
|
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);
|
|
376
|
-
|
|
377
|
-
|
|
990
|
+
try
|
|
991
|
+
{
|
|
992
|
+
using (VesperMachineIndicator indicator = new VesperMachineIndicator())
|
|
993
|
+
Application.Run(indicator);
|
|
994
|
+
}
|
|
995
|
+
finally { KeyboardBlock.Stop(); }
|
|
378
996
|
}
|
|
379
997
|
}
|
|
380
998
|
'@
|
package/package.json
CHANGED
package/release-manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"schemaVersion":1,"releaseId":"
|
|
1
|
+
{"schemaVersion":1,"releaseId":"78417ce9-35c1-487e-9d71-54dc1707b898","runtimeVersion":"0.6.33","bunVersion":"1.4.0","packageName":"@sipher.dev/connector-win32-x64","platform":"win32","arch":"x64","protocol":{"min":3,"max":3},"rescue":{"min":1,"max":1},"launcherSchemaVersion":2,"executable":"bin/agents-connector.exe","files":[{"path":"bin/agents-connector.exe","type":"file","size":99126272,"mode":493,"sha256":"e8ae5955b05f5835a656151d90fdf8ba247341d6734ab79a22e5d2c8d489560c"},{"path":"bin/machine-indicator.ps1","type":"file","size":38060,"mode":420,"sha256":"6e0e8a5b4a754db023e80893f07fd1543ec6d88348ed6887e02e1ae90335347b"},{"path":"package.json","type":"file","size":415,"mode":420,"sha256":"a89b9f0673938bd51aa2a00a477b40f28a41e84062e76ebb0e576b1b779d8f53"},{"path":"release-trust-anchor.json","type":"file","size":420,"mode":420,"sha256":"42123e58eb1ea98ee1a000d1331e0a74c5d0f82309b71ade58da79964db2edda"}]}
|
package/release-manifest.sig
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
TUYB5HaHRcc314e5gJKKlGtR1yvAGjKo4cEBsBP6P38NFFJ1j28Dnbi2ah3/iML6M6X2h+b6zHbMaDK9hLTaBQ==
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
"npmRegistryOrigin": "https://registry.npmjs.org",
|
|
5
5
|
"publicKey": "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAOjoSJrN1tu1cMZp/biuSMAdqsIGshWkyttGYtlmcDSs=\n-----END PUBLIC KEY-----\n",
|
|
6
6
|
"latest": {
|
|
7
|
-
"sequence":
|
|
8
|
-
"indexVersion": "0.6.
|
|
9
|
-
"digest": "
|
|
7
|
+
"sequence": 52,
|
|
8
|
+
"indexVersion": "0.6.32",
|
|
9
|
+
"digest": "a75ef8e2599bff366caa15d76cef256bf169375f68aa58c12dea7a46a2423486"
|
|
10
10
|
}
|
|
11
11
|
}
|