111 lines
3.9 KiB
C#
111 lines
3.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
|
|
namespace ISphereWinHelper
|
|
{
|
|
internal static class Program
|
|
{
|
|
[STAThread]
|
|
private static int Main(string[] args)
|
|
{
|
|
if (ShouldRunLiveProbeRecorder(args))
|
|
{
|
|
return LiveProbeRecorder.Run(args);
|
|
}
|
|
|
|
string requestText = Console.In.ReadToEnd();
|
|
Dictionary<string, object> request;
|
|
string requestId = "";
|
|
string op = "";
|
|
|
|
if (!HelperProtocol.TryParseRequest(requestText, out request, out requestId, out op))
|
|
{
|
|
Console.WriteLine(HelperProtocol.ToJson(HelperProtocol.Failure(requestId, op, "INVALID_REQUEST", "request must be valid JSON object")));
|
|
return 0;
|
|
}
|
|
|
|
try
|
|
{
|
|
Dictionary<string, object> opArgs = HelperProtocol.GetObject(request, "args");
|
|
Dictionary<string, object> response;
|
|
|
|
switch (op)
|
|
{
|
|
case "version":
|
|
response = HelperProtocol.Success(requestId, op, VersionData());
|
|
break;
|
|
case "self_check":
|
|
response = HelperProtocol.Success(requestId, op, SelfCheckData());
|
|
break;
|
|
case "scan_windows":
|
|
response = HelperProtocol.Success(requestId, op, WindowScanner.Scan(opArgs));
|
|
break;
|
|
case "dump_uia":
|
|
response = UiaDumper.Dump(requestId, op, opArgs);
|
|
break;
|
|
case "probe_client_runtime":
|
|
response = HelperProtocol.Success(requestId, op, RuntimeProbe.ProbeClientRuntime(opArgs));
|
|
break;
|
|
default:
|
|
response = HelperProtocol.Failure(requestId, op, "UNSUPPORTED_OP", "unsupported op: " + op);
|
|
break;
|
|
}
|
|
|
|
Console.WriteLine(HelperProtocol.ToJson(response));
|
|
return 0;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.Error.WriteLine(ex.ToString());
|
|
Console.WriteLine(HelperProtocol.ToJson(HelperProtocol.Failure(requestId, op, "HELPER_FAILED", ex.Message)));
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
private static bool ShouldRunLiveProbeRecorder(string[] args)
|
|
{
|
|
foreach (string arg in args)
|
|
{
|
|
if (string.Equals(arg, "--record-live-probe", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
string exeName = Path.GetFileNameWithoutExtension(AppDomain.CurrentDomain.FriendlyName);
|
|
return exeName != null && exeName.IndexOf("LiveProbeRecorder", StringComparison.OrdinalIgnoreCase) >= 0;
|
|
}
|
|
|
|
private static Dictionary<string, object> VersionData()
|
|
{
|
|
return new Dictionary<string, object>
|
|
{
|
|
{ "helper_name", "ISphereWinHelper" },
|
|
{ "helper_version", "0.3.0" },
|
|
{ "protocol", HelperProtocol.Protocol },
|
|
{ "runtime", ".NET Framework " + Environment.Version }
|
|
};
|
|
}
|
|
|
|
private static Dictionary<string, object> SelfCheckData()
|
|
{
|
|
bool uiaAvailable;
|
|
try
|
|
{
|
|
uiaAvailable = System.Windows.Automation.AutomationElement.RootElement != null;
|
|
}
|
|
catch
|
|
{
|
|
uiaAvailable = false;
|
|
}
|
|
|
|
return new Dictionary<string, object>
|
|
{
|
|
{ "desktop_access", Environment.UserInteractive },
|
|
{ "uia_available", uiaAvailable }
|
|
};
|
|
}
|
|
}
|
|
}
|