Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using CoreAudioApi;
- using Microsoft.Win32;
- using MSI.CommandCenter.Exceptions;
- using MSI.CommandCenter.Properties;
- using System;
- using System.Collections.Specialized;
- using System.Diagnostics;
- using System.Drawing;
- using System.Globalization;
- using System.IO;
- using System.Net;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading;
- using System.Web;
- using System.Windows.Forms;
- using System.Xml;
- using System.Xml.Serialization;
- namespace MSI.CommandCenter.RemoteServer
- {
- internal class MCCRSListener
- {
- private volatile bool shouldListen = true;
- private string FN_NAME = "BACKSPACE TAB ENTER SHIFT CTRL ALT ESC SPACEBAR PAGEUP PAGEDOWN END HOME LEFT UP RIGHT DOWN INSERT DELETE 0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z WINDOW * + - . / F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 ";
- private string FN_ID = "8 9 13 16 17 18 27 32 33 34 35 36 37 38 39 40 45 46 48 49 50 51 52 53 54 55 56 57 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 106 107 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123";
- private const int RequestThreadAbortedException = 995;
- private const string DEFAULT = "default";
- private const string AUTO = "auto";
- private const string ERR_INVALID_ARGS = "Invalid Arguments";
- private const string ERR_EMPTY_POST_REQUEST = "The server request is empty, no actions will be performed";
- private const string ERR_UNKNOWN_COMMAND = "Unknown Command";
- private const string ERR_ACCESS_DENIED = "Access denied";
- private const string SETTINGS_SUCCESSFUL = "Successfully applied new settings";
- private const string SETTINGS_FAILED = "Failed to apply new settings on host";
- private const string SETTINGS_SUCCESSFUL_RESTART = "Successfully applied new settings - Restart Required";
- private const string PROCESS_ABORTED = "Command could not complete successfully. Process aborted.";
- private const string UNKNOWN_STATE = "Press Refresh to get the latest values.";
- private const string COMMAND_PROCESSED = "Command successfully sent to host";
- private const string RESET_APPLIED = "Values successfully reset";
- private const string CONTROLCENTER_RUNNING = "Control Center is already running";
- private const string CONTROLCENTER_STARTING = "Starting Control Center on host PC";
- private const string CONTROLCENTER_ERROR_STARTING = "Could not start Control Center on host PC";
- private const string COMMANDCENTER_RUNNING = "Command Center is already running";
- private const string COMMANDCENTER_STARTING = "Starting Command Center on host PC";
- private const string COMMANDCENTER_ERROR_STARTING = "Could not start Command Center on host PC";
- private const string MUTE_TRUE = "Mute true";
- private const string MUTE_FALSE = "Mute false";
- private const string NO_AUDIO_DEVICE = "No Audio Device";
- private const string KBMOUSE_SUCCESSFUL = "Send Successfully";
- private const int WM_KEYDOWN = 256;
- private const int WM_KEYUP = 257;
- private const int WM_SETTEXT = 12;
- private const int MOUSEEVENTF_MOVE = 1;
- private const int MOUSEEVENTF_LEFTDOWN = 2;
- private const int MOUSEEVENTF_LEFTUP = 4;
- private const int MOUSEEVENTF_RIGHTDOWN = 8;
- private const int MOUSEEVENTF_RIGHTUP = 16;
- private const int MOUSEEVENTF_MIDDLEDOWN = 32;
- private const int MOUSEEVENTF_MIDDLEUP = 64;
- private const int MOUSEEVENTF_ABSOLUTE = 32768;
- private const uint KEYEVENTF_EXTENDEDKEY = 1;
- private const uint KEYEVENTF_KEYUP = 2;
- private MSICommandCenterRemoteServer systray;
- private HttpListener server;
- private int port;
- private bool iTunes_Repeat;
- private string[] FN_NAME_Array;
- private string[] FN_ID_Array;
- public int Port
- {
- get
- {
- return this.port;
- }
- }
- public MCCRSListener(MSICommandCenterRemoteServer mainForm)
- {
- this.systray = mainForm;
- this.FN_NAME_Array = this.FN_NAME.Split(' ');
- this.FN_ID_Array = this.FN_ID.Split(' ');
- }
- [DllImport("user32.dll")]
- private static extern int GetForegroundWindow();
- [DllImport("user32.dll")]
- private static extern int GetWindowText(int hWnd, StringBuilder lpsb, int count);
- [DllImport("User32.dll")]
- private static extern int SendMessage(int hWnd, int Msg, int wParam, string lParam);
- [DllImport("user32")]
- private static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
- [DllImport("user32")]
- private static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, uint dwExtraInfo);
- [DllImport("User32")]
- public static extern void SetCursorPos(int x, int y);
- [DllImport("User32")]
- public static extern bool GetCursorPos(out Point p);
- public void StartListening()
- {
- string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
- string ipAddress = Settings.Default.IPAddress;
- if (ipAddress != "*")
- {
- try
- {
- ipAddress = IPAddress.Parse(Settings.Default.IPAddress).ToString();
- MCCRSLogger.LogMessage("localaddress: " + ipAddress);
- }
- catch (FormatException ex)
- {
- this.systray.notifyIcon.ShowBalloonTip(100, Application.ProductName, "Error starting server: " + ex.Message, ToolTipIcon.Error);
- MCCRSLogger.LogError((Exception) ex, "Error starting server");
- return;
- }
- catch (Exception ex)
- {
- this.systray.notifyIcon.ShowBalloonTip(100, Application.ProductName, "An error occured: " + ex.Message, ToolTipIcon.Error);
- MCCRSLogger.LogError(ex, "An error occured");
- return;
- }
- }
- else
- MCCRSLogger.LogMessage("localaddress: *");
- try
- {
- this.port = Settings.Default.Port;
- }
- catch
- {
- this.port = 80;
- }
- MCCRSLogger.LogMessage("Checking Windows firewall for an exception for port: " + this.port.ToString());
- this.OpenFirewall(this.port);
- this.server = new HttpListener();
- this.server.Prefixes.Add("http://" + ipAddress + ":" + this.port.ToString() + "/");
- try
- {
- this.server.Start();
- this.server.AuthenticationSchemes = AuthenticationSchemes.Basic;
- this.server.IgnoreWriteExceptions = true;
- }
- catch (Exception ex)
- {
- this.systray.notifyIcon.ShowBalloonTip(100, Application.ProductName, "Error starting server: " + ex.Message, ToolTipIcon.Error);
- MCCRSLogger.LogError(ex, "Error starting server");
- this.shouldListen = false;
- return;
- }
- while (this.shouldListen)
- {
- try
- {
- HttpListenerContext context = this.server.GetContext();
- try
- {
- HttpListenerRequest request = context.Request;
- HttpListenerResponse response = context.Response;
- HttpListenerBasicIdentity identity = (HttpListenerBasicIdentity) context.User.Identity;
- if (identity.Name == "MSICommandCenter" && identity.Password == Settings.Default.Key)
- {
- this.ProcessRequestData(request, response);
- }
- else
- {
- string str = this.sendError("Access denied");
- this.setResponseStatus(response, HttpStatusCode.Unauthorized, str);
- byte[] bytes = Encoding.UTF8.GetBytes(str);
- response.ContentLength64 = (long) bytes.Length;
- Stream outputStream = response.OutputStream;
- outputStream.Write(bytes, 0, bytes.Length);
- outputStream.Close();
- }
- try
- {
- context.Response.Close();
- }
- catch
- {
- }
- }
- catch (HttpListenerException ex)
- {
- if (ex.ErrorCode != 995)
- MCCRSLogger.LogError((Exception) ex, "Error processing request");
- }
- catch (ThreadAbortException ex)
- {
- }
- catch (ArgumentException ex)
- {
- }
- catch (Exception ex)
- {
- this.systray.notifyIcon.ShowBalloonTip(100, Application.ProductName, "Error processing request: " + ex.Message, ToolTipIcon.Error);
- MCCRSLogger.LogError(ex, "Error processing request");
- HttpListenerResponse response = context.Response;
- string str = this.sendError(ex);
- this.setResponseStatus(response, HttpStatusCode.InternalServerError, str);
- byte[] bytes = Encoding.UTF8.GetBytes(str);
- response.ContentLength64 = (long) bytes.Length;
- Stream outputStream = response.OutputStream;
- outputStream.Write(bytes, 0, bytes.Length);
- outputStream.Close();
- }
- }
- catch (HttpListenerException ex)
- {
- if (ex.ErrorCode == 995)
- this.shouldListen = false;
- else
- MCCRSLogger.LogError((Exception) ex);
- }
- catch (ThreadAbortException ex)
- {
- }
- catch (Exception ex)
- {
- this.shouldListen = false;
- MCCRSLogger.LogError(ex);
- }
- }
- }
- public void Restart()
- {
- this.systray.notifyIcon.ShowBalloonTip(100, Application.ProductName, "Restarting server", ToolTipIcon.Info);
- if (this.server != null)
- {
- this.server.Stop();
- this.server = (HttpListener) null;
- }
- this.shouldListen = true;
- this.StartListening();
- }
- public void StopListening()
- {
- this.shouldListen = false;
- if (this.server == null)
- return;
- try
- {
- this.server.Stop();
- this.server.Abort();
- this.server.Close();
- }
- finally
- {
- this.server = (HttpListener) null;
- }
- }
- public string GetPrefixes()
- {
- if (this.server == null)
- return "Not Available";
- string str = "";
- foreach (string prefix in this.server.Prefixes)
- str += prefix;
- return str;
- }
- private void ProcessRequestData(HttpListenerRequest request, HttpListenerResponse response)
- {
- string str1 = "";
- MCCHM mcchm = (MCCHM) null;
- MCCOCSharedMemory mccocSharedMemory = (MCCOCSharedMemory) null;
- NameValueCollection queryString1 = request.QueryString;
- string localPath = request.Url.LocalPath;
- if (localPath.IndexOf("@@") > 0)
- {
- int num = localPath.IndexOf("@@", 3);
- string str2 = localPath.Substring(3, num - 3);
- string keys = localPath.Substring(num + 2, localPath.Length - 2 - num);
- switch (str2)
- {
- case "STR":
- SendKeys.SendWait(keys);
- break;
- case "FNKEY":
- int int32_1 = Convert.ToInt32(keys.Substring(0, 1));
- int int32_2 = Convert.ToInt32(keys.Substring(1, 1));
- int int32_3 = Convert.ToInt32(keys.Substring(2, 1));
- int int32_4 = Convert.ToInt32(keys.Substring(3, 1));
- string upper = keys.Substring(5, keys.Length - 5).ToUpper();
- for (int index = 0; index < this.FN_NAME.Length; ++index)
- {
- if (upper.Equals(this.FN_NAME_Array[index]))
- {
- if (int32_1 == 1)
- MCCRSListener.keybd_event((byte) 10, (byte) 0, 0U, 0U);
- if (int32_2 == 1)
- MCCRSListener.keybd_event((byte) 17, (byte) 0, 0U, 0U);
- if (int32_3 == 1)
- MCCRSListener.keybd_event((byte) 91, (byte) 0, 0U, 0U);
- if (int32_4 == 1)
- MCCRSListener.keybd_event((byte) 18, (byte) 0, 0U, 0U);
- MCCRSListener.keybd_event(byte.Parse(this.FN_ID_Array[index]), (byte) 0, 0U, 0U);
- if (int32_1 == 1)
- MCCRSListener.keybd_event((byte) 10, (byte) 0, 2U, 0U);
- if (int32_2 == 1)
- MCCRSListener.keybd_event((byte) 17, (byte) 0, 2U, 0U);
- if (int32_3 == 1)
- MCCRSListener.keybd_event((byte) 91, (byte) 0, 2U, 0U);
- if (int32_4 == 1)
- MCCRSListener.keybd_event((byte) 18, (byte) 0, 2U, 0U);
- MCCRSListener.keybd_event(byte.Parse(this.FN_ID_Array[index]), (byte) 0, 2U, 0U);
- break;
- }
- }
- break;
- case "SCROLL":
- if (keys.Equals("UP"))
- {
- MCCRSListener.keybd_event((byte) 38, (byte) 0, 0U, 0U);
- MCCRSListener.keybd_event((byte) 38, (byte) 0, 2U, 0U);
- break;
- }
- if (keys.Equals("DOWN"))
- {
- MCCRSListener.keybd_event((byte) 40, (byte) 0, 0U, 0U);
- MCCRSListener.keybd_event((byte) 40, (byte) 0, 2U, 0U);
- break;
- }
- break;
- }
- str1 = this.sendMessage("Send Successfully");
- }
- else
- {
- StringBuilder lpsb = new StringBuilder(256);
- int foregroundWindow = MCCRSListener.GetForegroundWindow();
- Process process1 = new Process();
- string path1 = Environment.GetEnvironmentVariable("WinDir") + "\\ehome\\ehshell.exe";
- string path2 = !Environment.Is64BitOperatingSystem ? Environment.GetEnvironmentVariable("ProgramFiles") + "\\Windows Media Player\\wmplayer.exe" : Environment.GetEnvironmentVariable("ProgramFiles(x86)") + "\\Windows Media Player\\wmplayer.exe";
- switch (localPath)
- {
- case "/detect":
- str1 = "Online.";
- break;
- case "/mcchm":
- try
- {
- mcchm = new MCCHM();
- XmlSerializer xmlSerializer = new XmlSerializer(typeof (MCCHM));
- MemoryStream memoryStream = new MemoryStream();
- XmlTextWriter xmlTextWriter = new XmlTextWriter((Stream) memoryStream, Encoding.UTF8);
- xmlSerializer.Serialize((XmlWriter) xmlTextWriter, (object) mcchm);
- xmlTextWriter.Close();
- memoryStream.Close();
- str1 = this.formatResponse(Encoding.UTF8.GetString(memoryStream.GetBuffer()));
- break;
- }
- catch (SharedMemoryNotFound ex)
- {
- str1 = this.sendError((Exception) ex);
- this.setResponseStatus(response, HttpStatusCode.ServiceUnavailable, str1);
- break;
- }
- catch (Exception ex)
- {
- str1 = this.sendError(ex);
- this.setResponseStatus(response, HttpStatusCode.InternalServerError, str1);
- break;
- }
- case "/mcchmheader":
- try
- {
- mcchm = new MCCHM();
- XmlSerializer xmlSerializer = new XmlSerializer(typeof (MCCHMHeader));
- MemoryStream memoryStream = new MemoryStream();
- XmlTextWriter xmlTextWriter = new XmlTextWriter((Stream) memoryStream, Encoding.UTF8);
- xmlSerializer.Serialize((XmlWriter) xmlTextWriter, (object) mcchm.Header);
- xmlTextWriter.Close();
- memoryStream.Close();
- str1 = this.formatResponse(Encoding.UTF8.GetString(memoryStream.GetBuffer()));
- break;
- }
- catch (SharedMemoryNotFound ex)
- {
- str1 = this.sendError((Exception) ex);
- this.setResponseStatus(response, HttpStatusCode.ServiceUnavailable, str1);
- break;
- }
- catch (Exception ex)
- {
- str1 = this.sendError(ex);
- this.setResponseStatus(response, HttpStatusCode.InternalServerError, str1);
- break;
- }
- case "/ocov":
- try
- {
- if (Settings.Default.MonitorOnly)
- {
- str1 = this.sendError("Access denied");
- this.setResponseStatus(response, HttpStatusCode.Forbidden, str1);
- break;
- }
- mcchm = new MCCHM();
- MCCHMOCOVEntries mcchmocovEntries = new MCCHMOCOVEntries();
- mcchmocovEntries.OCOVEntries = mcchm.OCOVEntries;
- XmlSerializer xmlSerializer = new XmlSerializer(typeof (MCCHMOCOVEntries));
- MemoryStream memoryStream = new MemoryStream();
- XmlTextWriter xmlTextWriter = new XmlTextWriter((Stream) memoryStream, Encoding.UTF8);
- xmlSerializer.Serialize((XmlWriter) xmlTextWriter, (object) mcchmocovEntries);
- xmlTextWriter.Close();
- memoryStream.Close();
- str1 = this.formatResponse(Encoding.UTF8.GetString(memoryStream.GetBuffer()));
- break;
- }
- catch (SharedMemoryNotFound ex)
- {
- str1 = this.sendError((Exception) ex);
- this.setResponseStatus(response, HttpStatusCode.ServiceUnavailable, str1);
- break;
- }
- catch (Exception ex)
- {
- MCCRSLogger.LogMessage(ex.ToString());
- str1 = this.sendError(ex);
- this.setResponseStatus(response, HttpStatusCode.InternalServerError, str1);
- break;
- }
- case "/monitor":
- try
- {
- mcchm = new MCCHM();
- MCCHMMonitorEntries mcchmMonitorEntries = new MCCHMMonitorEntries();
- mcchmMonitorEntries.MonitorEntries = mcchm.MonitorEntries;
- XmlSerializer xmlSerializer = new XmlSerializer(typeof (MCCHMMonitorEntries));
- MemoryStream memoryStream = new MemoryStream();
- XmlTextWriter xmlTextWriter = new XmlTextWriter((Stream) memoryStream, Encoding.UTF8);
- xmlSerializer.Serialize((XmlWriter) xmlTextWriter, (object) mcchmMonitorEntries);
- xmlTextWriter.Close();
- memoryStream.Close();
- str1 = this.formatResponse(Encoding.UTF8.GetString(memoryStream.GetBuffer()));
- break;
- }
- catch (SharedMemoryNotFound ex)
- {
- str1 = this.sendError((Exception) ex);
- this.setResponseStatus(response, HttpStatusCode.ServiceUnavailable, str1);
- break;
- }
- catch (Exception ex)
- {
- MCCRSLogger.LogMessage(ex.ToString());
- str1 = this.sendError(ex);
- this.setResponseStatus(response, HttpStatusCode.InternalServerError, str1);
- break;
- }
- case "/info":
- try
- {
- mcchm = new MCCHM();
- MCCHMInfoEntries mcchmInfoEntries = new MCCHMInfoEntries();
- mcchmInfoEntries.InfoEntries = mcchm.InfoEntries;
- XmlSerializer xmlSerializer = new XmlSerializer(typeof (MCCHMInfoEntries));
- MemoryStream memoryStream = new MemoryStream();
- XmlTextWriter xmlTextWriter = new XmlTextWriter((Stream) memoryStream, Encoding.UTF8);
- xmlSerializer.Serialize((XmlWriter) xmlTextWriter, (object) mcchmInfoEntries);
- xmlTextWriter.Close();
- memoryStream.Close();
- str1 = this.formatResponse(Encoding.UTF8.GetString(memoryStream.GetBuffer()));
- break;
- }
- catch (SharedMemoryNotFound ex)
- {
- str1 = this.sendError((Exception) ex);
- this.setResponseStatus(response, HttpStatusCode.ServiceUnavailable, str1);
- break;
- }
- catch (Exception ex)
- {
- MCCRSLogger.LogMessage(ex.ToString());
- str1 = this.sendError(ex);
- this.setResponseStatus(response, HttpStatusCode.ServiceUnavailable, str1);
- break;
- }
- case "/draminfo":
- try
- {
- mcchm = new MCCHM();
- MCCHMDRAMEntries mcchmdramEntries = new MCCHMDRAMEntries();
- mcchmdramEntries.DRAMEntries = mcchm.DRAMEntries;
- XmlSerializer xmlSerializer = new XmlSerializer(typeof (MCCHMDRAMEntries));
- MemoryStream memoryStream = new MemoryStream();
- XmlTextWriter xmlTextWriter = new XmlTextWriter((Stream) memoryStream, Encoding.UTF8);
- xmlSerializer.Serialize((XmlWriter) xmlTextWriter, (object) mcchmdramEntries);
- xmlTextWriter.Close();
- memoryStream.Close();
- str1 = this.formatResponse(Encoding.UTF8.GetString(memoryStream.GetBuffer()));
- break;
- }
- catch (SharedMemoryNotFound ex)
- {
- str1 = this.sendError((Exception) ex);
- this.setResponseStatus(response, HttpStatusCode.ServiceUnavailable, str1);
- break;
- }
- catch (Exception ex)
- {
- MCCRSLogger.LogMessage(ex.ToString());
- str1 = this.sendError(ex);
- this.setResponseStatus(response, HttpStatusCode.InternalServerError, str1);
- break;
- }
- case "/allinfo":
- try
- {
- mcchm = new MCCHM();
- MemoryStream memoryStream = new MemoryStream();
- XmlTextWriter xmlTextWriter = new XmlTextWriter((Stream) memoryStream, Encoding.UTF8);
- xmlTextWriter.WriteStartDocument();
- xmlTextWriter.WriteStartElement("AllInfoEntries");
- new XmlSerializer(typeof (MCCHMInfoEntries)).Serialize((XmlWriter) xmlTextWriter, (object) new MCCHMInfoEntries()
- {
- InfoEntries = mcchm.InfoEntries
- });
- new XmlSerializer(typeof (MCCHMDRAMEntries)).Serialize((XmlWriter) xmlTextWriter, (object) new MCCHMDRAMEntries()
- {
- DRAMEntries = mcchm.DRAMEntries
- });
- xmlTextWriter.WriteEndElement();
- xmlTextWriter.Close();
- memoryStream.Close();
- str1 = this.formatResponse(Encoding.UTF8.GetString(memoryStream.GetBuffer()));
- break;
- }
- catch (SharedMemoryNotFound ex)
- {
- str1 = this.sendError((Exception) ex);
- this.setResponseStatus(response, HttpStatusCode.ServiceUnavailable, str1);
- break;
- }
- catch (Exception ex)
- {
- MCCRSLogger.LogMessage(ex.ToString());
- str1 = this.sendError(ex);
- this.setResponseStatus(response, HttpStatusCode.InternalServerError, str1);
- break;
- }
- case "/startcchost":
- try
- {
- mcchm = new MCCHM();
- str1 = !this.systray.ControlCenter ? "Command Center is already running" : "Control Center is already running";
- break;
- }
- catch (SharedMemoryNotFound ex)
- {
- if (this.launchControlCenter())
- {
- str1 = !this.systray.ControlCenter ? "Starting Command Center on host PC" : "Starting Control Center on host PC";
- break;
- }
- str1 = !this.systray.ControlCenter ? "Could not start Command Center on host PC" : "Could not start Control Center on host PC";
- this.setResponseStatus(response, HttpStatusCode.InternalServerError, str1);
- break;
- }
- catch (Exception ex)
- {
- str1 = this.sendError(ex);
- this.setResponseStatus(response, HttpStatusCode.InternalServerError, str1);
- break;
- }
- case "/applyOCOV":
- if (Settings.Default.MonitorOnly)
- {
- str1 = this.sendError("Access denied");
- this.setResponseStatus(response, HttpStatusCode.Forbidden, str1);
- }
- else
- {
- try
- {
- mccocSharedMemory = new MCCOCSharedMemory();
- if (mccocSharedMemory == null)
- {
- str1 = this.sendMessage("Command could not complete successfully. Process aborted.");
- this.setResponseStatus(response, HttpStatusCode.InternalServerError, str1);
- }
- else
- {
- bool flag = false;
- string end = new StreamReader(request.InputStream).ReadToEnd();
- MCCRSLogger.LogMessage(request.RemoteEndPoint.ToString() + " Apply OC/OV: " + end);
- NameValueCollection queryString2 = HttpUtility.ParseQueryString(end);
- if (queryString2.Count < 1)
- {
- str1 = this.sendMessage("The server request is empty, no actions will be performed");
- this.setResponseStatus(response, HttpStatusCode.BadRequest, str1);
- break;
- }
- for (int index = 0; index < queryString2.Count; ++index)
- {
- string key = queryString2.GetKey(index);
- string s = key.Substring(2, key.Length - 2);
- if (int.Parse(s) == 35)
- flag = true;
- mccocSharedMemory.SetEntryValue(int.Parse(s), float.Parse(queryString2.GetValues(index)[0], (IFormatProvider) CultureInfo.InvariantCulture));
- }
- mccocSharedMemory.CommitChanges();
- mccocSharedMemory.LoadSharedMemory();
- str1 = this.sendMessage("Press Refresh to get the latest values.");
- int num = 0;
- while (num < 8)
- {
- try
- {
- uint updatedStatus = mccocSharedMemory.getUpdatedStatus();
- mccocSharedMemory.LoadSharedMemory();
- switch (updatedStatus)
- {
- case 1:
- str1 = !flag ? this.sendMessage("Successfully applied new settings") : "";
- num = 99;
- continue;
- case 2:
- str1 = this.sendMessage("Failed to apply new settings on host");
- num = 99;
- continue;
- case 3:
- str1 = this.sendMessage("Successfully applied new settings - Restart Required");
- num = 99;
- continue;
- default:
- continue;
- }
- }
- catch (Exception ex)
- {
- str1 = this.sendMessage(ex.Message);
- this.setResponseStatus(response, HttpStatusCode.InternalServerError, str1);
- }
- finally
- {
- Thread.Sleep(1000);
- ++num;
- }
- }
- }
- }
- catch (Exception ex)
- {
- MCCRSLogger.LogMessage(ex.ToString());
- str1 = this.sendError(ex);
- this.setResponseStatus(response, HttpStatusCode.InternalServerError, str1);
- }
- }
- if (mccocSharedMemory != null)
- {
- mccocSharedMemory.clearStatus();
- break;
- }
- break;
- case "/PLAY":
- MCCRSListener.keybd_event((byte) 179, (byte) 0, 0U, 0U);
- MCCRSListener.keybd_event((byte) 179, (byte) 0, 2U, 0U);
- str1 = this.sendMessage("Successfully applied new settings");
- break;
- case "/STOP":
- MCCRSListener.keybd_event((byte) 178, (byte) 0, 0U, 0U);
- MCCRSListener.keybd_event((byte) 178, (byte) 0, 2U, 0U);
- str1 = this.sendMessage("Successfully applied new settings");
- break;
- case "/PAUSE":
- MCCRSListener.keybd_event((byte) 179, (byte) 0, 0U, 0U);
- MCCRSListener.keybd_event((byte) 179, (byte) 0, 2U, 0U);
- str1 = this.sendMessage("Successfully applied new settings");
- break;
- case "/PREVIOUSSECTION":
- MCCRSListener.keybd_event((byte) 177, (byte) 0, 0U, 0U);
- MCCRSListener.keybd_event((byte) 177, (byte) 0, 2U, 0U);
- str1 = this.sendMessage("Successfully applied new settings");
- break;
- case "/NEXTSECTION":
- MCCRSListener.keybd_event((byte) 176, (byte) 0, 0U, 0U);
- MCCRSListener.keybd_event((byte) 176, (byte) 0, 2U, 0U);
- str1 = this.sendMessage("Successfully applied new settings");
- break;
- case "/VOLUMEUP":
- MCCRSListener.keybd_event((byte) 175, (byte) 0, 0U, 0U);
- MCCRSListener.keybd_event((byte) 175, (byte) 0, 2U, 0U);
- str1 = this.sendMessage("Successfully applied new settings");
- break;
- case "/VOLUMEDOWN":
- MCCRSListener.keybd_event((byte) 174, (byte) 0, 0U, 0U);
- MCCRSListener.keybd_event((byte) 174, (byte) 0, 2U, 0U);
- str1 = this.sendMessage("Successfully applied new settings");
- break;
- case "/GETMUTESTATUS":
- try
- {
- str1 = !new MMDeviceEnumerator().GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia).AudioEndpointVolume.Mute ? this.sendMessage("Mute false") : this.sendMessage("Mute true");
- break;
- }
- catch (Exception ex)
- {
- str1 = this.sendMessage("No Audio Device");
- break;
- }
- case "/MUTE":
- MCCRSListener.keybd_event((byte) 173, (byte) 0, 0U, 0U);
- MCCRSListener.keybd_event((byte) 173, (byte) 0, 2U, 0U);
- str1 = this.sendMessage("Successfully applied new settings");
- break;
- case "/REPEAT":
- MCCRSListener.GetWindowText(foregroundWindow, lpsb, lpsb.Capacity);
- string str2 = lpsb.ToString();
- if (str2.Equals("iTunes"))
- {
- MCCRSListener.keybd_event((byte) 18, (byte) 0, 0U, 0U);
- MCCRSListener.keybd_event((byte) 67, (byte) 0, 0U, 0U);
- MCCRSListener.keybd_event((byte) 67, (byte) 0, 2U, 0U);
- MCCRSListener.keybd_event((byte) 18, (byte) 0, 2U, 0U);
- MCCRSListener.keybd_event((byte) 82, (byte) 0, 0U, 0U);
- MCCRSListener.keybd_event((byte) 82, (byte) 0, 2U, 0U);
- if (this.iTunes_Repeat)
- {
- this.iTunes_Repeat = false;
- MCCRSListener.keybd_event((byte) 65, (byte) 0, 0U, 0U);
- MCCRSListener.keybd_event((byte) 65, (byte) 0, 2U, 0U);
- }
- else
- {
- this.iTunes_Repeat = true;
- MCCRSListener.keybd_event((byte) 79, (byte) 0, 0U, 0U);
- MCCRSListener.keybd_event((byte) 79, (byte) 0, 2U, 0U);
- }
- }
- else if (str2.Equals("Windows Media Player"))
- {
- MCCRSListener.keybd_event((byte) 17, (byte) 0, 0U, 0U);
- MCCRSListener.keybd_event((byte) 84, (byte) 0, 0U, 0U);
- MCCRSListener.keybd_event((byte) 17, (byte) 0, 2U, 0U);
- MCCRSListener.keybd_event((byte) 84, (byte) 0, 2U, 0U);
- }
- str1 = this.sendMessage("Successfully applied new settings");
- break;
- case "/SHUFFLE":
- MCCRSListener.GetWindowText(foregroundWindow, lpsb, lpsb.Capacity);
- string str3 = lpsb.ToString();
- if (str3.Equals("iTunes"))
- {
- MCCRSListener.keybd_event((byte) 18, (byte) 0, 0U, 0U);
- MCCRSListener.keybd_event((byte) 67, (byte) 0, 0U, 0U);
- MCCRSListener.keybd_event((byte) 67, (byte) 0, 2U, 0U);
- MCCRSListener.keybd_event((byte) 18, (byte) 0, 2U, 0U);
- MCCRSListener.keybd_event((byte) 83, (byte) 0, 0U, 0U);
- MCCRSListener.keybd_event((byte) 83, (byte) 0, 2U, 0U);
- MCCRSListener.keybd_event((byte) 84, (byte) 0, 0U, 0U);
- MCCRSListener.keybd_event((byte) 84, (byte) 0, 2U, 0U);
- }
- else if (str3.Equals("Windows Media Player"))
- {
- MCCRSListener.keybd_event((byte) 17, (byte) 0, 0U, 0U);
- MCCRSListener.keybd_event((byte) 72, (byte) 0, 0U, 0U);
- MCCRSListener.keybd_event((byte) 17, (byte) 0, 2U, 0U);
- MCCRSListener.keybd_event((byte) 72, (byte) 0, 2U, 0U);
- }
- str1 = this.sendMessage("Successfully applied new settings");
- break;
- case "/UP":
- MCCRSListener.keybd_event((byte) 38, (byte) 0, 0U, 0U);
- MCCRSListener.keybd_event((byte) 38, (byte) 0, 2U, 0U);
- str1 = this.sendMessage("Successfully applied new settings");
- break;
- case "/DOWN":
- MCCRSListener.keybd_event((byte) 40, (byte) 0, 0U, 0U);
- MCCRSListener.keybd_event((byte) 40, (byte) 0, 2U, 0U);
- str1 = this.sendMessage("Successfully applied new settings");
- break;
- case "/LEFT":
- MCCRSListener.keybd_event((byte) 37, (byte) 0, 0U, 0U);
- MCCRSListener.keybd_event((byte) 37, (byte) 0, 2U, 0U);
- str1 = this.sendMessage("Successfully applied new settings");
- break;
- case "/RIGHT":
- MCCRSListener.keybd_event((byte) 39, (byte) 0, 0U, 0U);
- MCCRSListener.keybd_event((byte) 39, (byte) 0, 2U, 0U);
- str1 = this.sendMessage("Successfully applied new settings");
- break;
- case "/ENTER":
- MCCRSListener.keybd_event((byte) 13, (byte) 0, 0U, 0U);
- MCCRSListener.keybd_event((byte) 13, (byte) 0, 2U, 0U);
- str1 = this.sendMessage("Successfully applied new settings");
- break;
- case "/BACK":
- MCCRSListener.GetWindowText(foregroundWindow, lpsb, lpsb.Capacity);
- string str4 = lpsb.ToString();
- if (str4.Equals("Windows Media Center"))
- {
- MCCRSListener.keybd_event((byte) 8, (byte) 0, 0U, 0U);
- MCCRSListener.keybd_event((byte) 8, (byte) 0, 2U, 0U);
- }
- else if (str4.Equals("Windows Media Player"))
- {
- MCCRSListener.keybd_event((byte) 18, (byte) 0, 0U, 0U);
- MCCRSListener.keybd_event((byte) 37, (byte) 0, 0U, 0U);
- MCCRSListener.keybd_event((byte) 18, (byte) 0, 2U, 0U);
- MCCRSListener.keybd_event((byte) 37, (byte) 0, 2U, 0U);
- }
- str1 = this.sendMessage("Successfully applied new settings");
- break;
- case "/OPENMEDIACENTER":
- bool flag1 = false;
- ProcessStartInfo processStartInfo = new ProcessStartInfo();
- string str5;
- if (System.IO.File.Exists(path1))
- {
- foreach (Process process2 in Process.GetProcessesByName("ehshell"))
- {
- try
- {
- flag1 = true;
- process2.Kill();
- }
- catch (Exception ex)
- {
- }
- }
- if (!flag1)
- {
- if (this.systray.ControlCenter)
- str5 = this.processMediaCommand(this.systray.CurrentWorkDirectory, "/OPENMEDIACENTER");
- else
- this.StartMedia();
- }
- }
- else if (System.IO.File.Exists(path2))
- {
- bool flag2 = false;
- foreach (Process process2 in Process.GetProcessesByName("wmplayer"))
- {
- try
- {
- flag2 = true;
- process2.Kill();
- }
- catch (Exception ex)
- {
- }
- }
- if (!flag2)
- {
- if (this.systray.ControlCenter)
- str5 = this.processMediaCommand(this.systray.CurrentWorkDirectory, "/OPENMEDIACENTER");
- else
- this.StartMedia();
- }
- }
- str1 = this.sendMessage("Successfully applied new settings");
- break;
- case "/SHUTDOWN":
- try
- {
- new Process()
- {
- StartInfo = {
- FileName = "shutdown.exe",
- Arguments = "-s -f -t 0"
- }
- }.Start();
- }
- catch (Exception ex)
- {
- }
- str1 = this.sendMessage("Successfully applied new settings");
- break;
- case "/REBOOT":
- try
- {
- new Process()
- {
- StartInfo = {
- FileName = "shutdown.exe",
- Arguments = "-r -f -t 0"
- }
- }.Start();
- }
- catch (Exception ex)
- {
- }
- str1 = this.sendMessage("Successfully applied new settings");
- break;
- case "/CLEARCMOS":
- str1 = !this.systray.ControlCenter ? this.processMediaCommand("", "/CLEARCMOS") : this.processMediaCommand(this.systray.CurrentWorkDirectory, "/CLEARCMOS");
- break;
- case "/CTRLALTDELETE":
- this.CTRLALTDELETE();
- break;
- default:
- str1 = this.sendError("Unknown Command");
- this.setResponseStatus(response, HttpStatusCode.NotFound, str1);
- break;
- }
- }
- byte[] bytes = Encoding.UTF8.GetBytes(str1);
- response.ContentLength64 = (long) bytes.Length;
- Stream outputStream = response.OutputStream;
- outputStream.Write(bytes, 0, bytes.Length);
- outputStream.Close();
- response.Close();
- if (mcchm == null)
- return;
- mcchm.Disconnect();
- }
- private void OpenFirewall(int port)
- {
- string str1 = Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\";
- string str2 = !this.systray.ControlCenter ? "MSI Command Center Remote Server" : "MSI Command Center Remote Server";
- Process process = new Process();
- process.StartInfo.FileName = str1 + "netsh.exe";
- process.StartInfo.Arguments = "advfirewall firewall del rule name=\"" + str2 + "\"";
- process.StartInfo.UseShellExecute = false;
- process.StartInfo.CreateNoWindow = true;
- process.Start();
- process.WaitForExit();
- process.StartInfo.Arguments = "advfirewall firewall add rule name=\"" + str2 + "\" dir=in protocol=tcp localport=" + port.ToString() + " action=allow";
- process.StartInfo.UseShellExecute = false;
- process.StartInfo.CreateNoWindow = true;
- process.Start();
- process.WaitForExit();
- process.StartInfo.Arguments = "advfirewall firewall add rule name=\"" + str2 + "\" dir=in protocol=udp localport=26820 action=allow";
- process.StartInfo.UseShellExecute = false;
- process.StartInfo.CreateNoWindow = true;
- process.Start();
- process.WaitForExit();
- }
- private string formatResponse(string responseString)
- {
- responseString = responseString.Substring(responseString.IndexOf(Convert.ToChar(60)));
- return responseString.Substring(0, responseString.LastIndexOf(Convert.ToChar(62)) + 1);
- }
- private void setResponseStatus(HttpListenerResponse response, HttpStatusCode statusCode, string description)
- {
- response.StatusCode = (int) statusCode;
- switch (statusCode)
- {
- case HttpStatusCode.Unauthorized:
- response.StatusDescription = "401 Unauthorized";
- break;
- case HttpStatusCode.Forbidden:
- response.StatusDescription = "403 Forbidden";
- break;
- case HttpStatusCode.ServiceUnavailable:
- response.StatusDescription = "503 Service unavailable";
- break;
- default:
- response.StatusDescription = ((int) statusCode).ToString() + " Unknown Error";
- break;
- }
- }
- private string sendError(Exception ex)
- {
- MemoryStream memoryStream = new MemoryStream();
- XmlTextWriter xmlTextWriter = new XmlTextWriter((Stream) memoryStream, Encoding.UTF8);
- xmlTextWriter.WriteStartDocument();
- xmlTextWriter.WriteStartElement("error");
- if (this.systray.ControlCenter)
- xmlTextWriter.WriteElementString("message", "ControlCenter : " + ex.Message);
- else
- xmlTextWriter.WriteElementString("message", "CommandCenter : " + ex.Message);
- if (ex.InnerException != null)
- xmlTextWriter.WriteElementString("innerMessage", ex.InnerException.Message);
- xmlTextWriter.WriteEndElement();
- xmlTextWriter.Flush();
- StreamReader streamReader = new StreamReader((Stream) memoryStream, Encoding.UTF8, true);
- memoryStream.Seek(0L, SeekOrigin.Begin);
- return streamReader.ReadToEnd();
- }
- private string sendError(string errorMessage)
- {
- MemoryStream memoryStream = new MemoryStream();
- XmlTextWriter xmlTextWriter = new XmlTextWriter((Stream) memoryStream, Encoding.UTF8);
- xmlTextWriter.WriteStartDocument();
- xmlTextWriter.WriteStartElement("error");
- xmlTextWriter.WriteElementString("message", errorMessage);
- xmlTextWriter.WriteEndElement();
- xmlTextWriter.Flush();
- StreamReader streamReader = new StreamReader((Stream) memoryStream, Encoding.UTF8, true);
- memoryStream.Seek(0L, SeekOrigin.Begin);
- return streamReader.ReadToEnd();
- }
- private string sendMessage(string message)
- {
- MemoryStream memoryStream = new MemoryStream();
- XmlTextWriter xmlTextWriter = new XmlTextWriter((Stream) memoryStream, Encoding.UTF8);
- xmlTextWriter.WriteStartDocument();
- xmlTextWriter.WriteStartElement("info");
- xmlTextWriter.WriteElementString("message", message);
- xmlTextWriter.WriteEndElement();
- xmlTextWriter.Flush();
- StreamReader streamReader = new StreamReader((Stream) memoryStream, Encoding.UTF8, true);
- memoryStream.Seek(0L, SeekOrigin.Begin);
- return streamReader.ReadToEnd();
- }
- private string normalizeXML(string XML)
- {
- try
- {
- XmlDocument xmlDocument = new XmlDocument();
- xmlDocument.LoadXml(XML);
- this.replaceInnerXMLText(xmlDocument.SelectNodes("descendant::HardwareMonitorEntry/srcUnits"), "°C", "C");
- this.replaceInnerXMLText(xmlDocument.SelectNodes("descendant::HardwareMonitorEntry/localizedSrcUnits"), "°C", "C");
- this.replaceInnerXMLText(xmlDocument.SelectNodes("descendant::HardwareMonitorEntry/data"), ",", ".");
- return xmlDocument.OuterXml;
- }
- catch
- {
- return XML;
- }
- }
- private void replaceInnerXMLText(XmlNodeList nodes, string find, string replace)
- {
- foreach (XmlNode node in nodes)
- {
- if (node.InnerText.Contains(find))
- node.InnerText = node.InnerText.Replace(find, replace);
- }
- }
- private string processMediaCommand(string Path, string command)
- {
- try
- {
- if (Path.Equals(""))
- Process.Start("C:\\MSIServiceCfg_CC\\function.exe", command);
- else
- Process.Start(Path + "function.exe", command);
- return this.sendMessage("Command successfully sent to host");
- }
- catch (Exception ex)
- {
- return this.sendError(ex);
- }
- }
- private bool launchControlCenter()
- {
- if (this.systray.ControlCenter)
- {
- try
- {
- Process process = new Process();
- process.StartInfo.CreateNoWindow = true;
- process.StartInfo.FileName = this.systray.CurrentWorkDirectory + "controlcenter.exe";
- process.StartInfo.UseShellExecute = true;
- bool flag = process.Start();
- process.WaitForExit();
- return flag;
- }
- catch (Exception ex)
- {
- MCCRSLogger.LogError(ex);
- return false;
- }
- }
- else
- {
- try
- {
- Process process = new Process();
- process.StartInfo.CreateNoWindow = true;
- process.StartInfo.FileName = Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\SC.exe";
- process.StartInfo.Arguments = "control MSICTL_CC 151";
- process.StartInfo.UseShellExecute = false;
- bool flag = process.Start();
- process.WaitForExit();
- return flag;
- }
- catch (Exception ex)
- {
- MCCRSLogger.LogError(ex);
- return false;
- }
- }
- }
- private void CTRLALTDELETE()
- {
- try
- {
- Process process = new Process();
- process.StartInfo.CreateNoWindow = true;
- process.StartInfo.FileName = Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\SC.exe";
- process.StartInfo.Arguments = "control MSICTL_CC 152";
- process.StartInfo.UseShellExecute = false;
- process.Start();
- process.WaitForExit();
- }
- catch (Exception ex)
- {
- MCCRSLogger.LogError(ex);
- }
- }
- private void StartMedia()
- {
- if (Registry.LocalMachine.OpenSubKey("SOFTWARE\\MSI\\CommandCenter") == null)
- Registry.LocalMachine.CreateSubKey("SOFTWARE\\MSI\\CommandCenter");
- RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\MSI\\CommandCenter", true);
- try
- {
- registryKey.SetValue("DateTime", (object) DateTime.Now.ToString());
- }
- catch (Exception ex)
- {
- }
- registryKey.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement