forked from cedrozor/myrtille
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
115 lines (100 loc) · 3.52 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
using log4net.Config;
using Myrtille.Services.Contracts;
namespace Myrtille.RDP
{
public class Program
{
[DllImport("wfreerdp-client.dll")]
private static extern int StartRdpClient();
private static int Main(string[] args)
{
// enable the code below for debug; disable otherwise
//if (Environment.UserInteractive)
//{
// MessageBox.Show("Attach the .NET debugger to the 'RDP Debug' Myrtille.RDP.exe process now for debug. Click OK when ready...", "RDP Debug");
//}
//else
//{
// Thread.Sleep(10000);
//}
// logger
XmlConfigurator.Configure();
string argKeyValueSeparator = ":";
foreach (string arg in args)
{
var argParts = arg.Trim().Split(argKeyValueSeparator.ToCharArray(), 2);
parseCommandLineArg(argParts[0].ToLower(), (argParts.Length > 1 ? argParts[1] : ""));
}
if (!ValidConfig)
{
return (int)RemoteSessionExitCode.InvalidConfiguration;
}
int exitCode = (int)RemoteSessionExitCode.Success;
try
{
exitCode = StartRdpClient();
}
catch (Exception e)
{
if (ConsoleOutput)
{
Console.WriteLine(e.Message);
}
Trace.TraceError("RDP error, remote session {0} ({1})", RemoteSessionID, e);
exitCode = (int)RemoteSessionExitCode.Unknown;
}
return exitCode;
}
#region configuration
private static string RemoteSessionID { get; set; } // Myrtille session ID used for pipe messaging
private static bool LoggingEnabled { get; set; } // Myrtille logging parameter
private static bool ConsoleOutput { get; set; } // Output comms to console window
private static uint Height { get; set; } // Height of RDP session
private static uint Width { get; set; } // Width of RDP session
/// <summary>
/// Indicate all command line parameters for correct operation have been received.
/// </summary>
private static bool ValidConfig
{
get
{
if (string.IsNullOrEmpty(RemoteSessionID)) return false;
if (Height == 0) return false;
if (Width == 0) return false;
return true;
}
}
/// <summary>
/// Parse command line arguments
/// </summary>
/// <param name="arg"></param>
/// <param name="value"></param>
private static void parseCommandLineArg(string arg, string value)
{
switch (arg)
{
case "/myrtille-sid":
RemoteSessionID = value.Trim();
break;
case "/myrtille-window":
ConsoleOutput = true;
break;
case "/myrtille-log":
LoggingEnabled = true;
break;
case "/h":
Height = uint.Parse(value);
break;
case "/w":
Width = uint.Parse(value);
break;
}
}
#endregion
}
}