public void LoggingThread(iosSyslogger form, loggerTool tool, string uuid) //Creating thread for Logger { Thread loggingThread = new Thread(() => tool.readLog(form, uuid)); loggingThread.IsBackground = true; lstThreads.Add(loggingThread); }
public void deviceInfoThread(iosSyslogger form, loggerTool tool, string uuid) //Create thread for Device info reader { Thread deviceInfoThread = new Thread(() => tool.readDeviceinfo(form, uuid)); deviceInfoThread.IsBackground = true; lstThreads.Add(deviceInfoThread); }
static void Main() { string currentPath = System.Environment.CurrentDirectory; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); iosSyslogger LoggerWindow = new iosSyslogger(); loggerTool tool = new loggerTool(); WqlEventQuery insertQuery = new WqlEventQuery("SELECT * FROM Win32_DeviceChangeEvent WHERE EventType = 2"); //Checking USB device insertion ManagementEventWatcher insertWatcher = new ManagementEventWatcher(insertQuery); WqlEventQuery removeQuery = new WqlEventQuery("SELECT * FROM __InstanceDeletionEvent WITHIN 2 WHERE TargetInstance ISA 'Win32_USBHub'"); //Checking USB removal ManagementEventWatcher removeWatcher = new ManagementEventWatcher(removeQuery); insertWatcher.EventArrived += new EventArrivedEventHandler((source, e) => DeviceInsertedEvent(source, e, LoggerWindow, tool)); insertWatcher.Start(); removeWatcher.EventArrived += new EventArrivedEventHandler((source, e) => DeviceRemovedEvent(source, e, LoggerWindow, tool)); removeWatcher.Start(); Thread loggerParentThread = new Thread(() => tool.readDeviceUUID(LoggerWindow, tool)); //Parent thread for Syslogger loggerParentThread.Start(); Application.Run(LoggerWindow); AppDomain.CurrentDomain.ProcessExit += new EventHandler(OnProcessExit); }
static void Main() { string currentPath = System.Environment.CurrentDirectory; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); iosSyslogger LoggerWindow = new iosSyslogger(); loggerTool tool = new loggerTool(); WqlEventQuery insertQuery = new WqlEventQuery("SELECT * FROM Win32_DeviceChangeEvent WHERE EventType = 2"); //Checking USB device insertion ManagementEventWatcher insertWatcher = new ManagementEventWatcher(insertQuery); WqlEventQuery removeQuery = new WqlEventQuery("SELECT * FROM __InstanceDeletionEvent WITHIN 2 WHERE TargetInstance ISA 'Win32_USBHub'"); //Checking USB removal ManagementEventWatcher removeWatcher = new ManagementEventWatcher(removeQuery); insertWatcher.EventArrived += new EventArrivedEventHandler((source, e) => DeviceInsertedEvent(source, e, LoggerWindow, tool)); insertWatcher.Start(); removeWatcher.EventArrived += new EventArrivedEventHandler((source, e) => DeviceRemovedEvent(source, e, LoggerWindow, tool)); removeWatcher.Start(); Thread loggerParentThread = new Thread(() => tool.readDeviceUUID(LoggerWindow, tool)); //Parent thread for Syslogger loggerParentThread.Start(); Application.Run(LoggerWindow); AppDomain.CurrentDomain.ProcessExit += new EventHandler(OnProcessExit); }
static void DeviceRemovedEvent(object sender, EventArrivedEventArgs e, iosSyslogger window, loggerTool tool) { GlobalData.usbInserted = false; if (GlobalData.usbRemoved == true) return; else { GlobalData.usbRemoved = true; tool.readDeviceUUID(window, tool); } }
static void DeviceInsertedEvent(object sender, EventArgs e,iosSyslogger window, loggerTool tool) { if (GlobalData.usbInserted == true) //If this is true, new iOS Device has already been processed { return; } else { GlobalData.usbInserted = true; tool.readDeviceUUID(window, tool); } }
public void readDeviceUUID(iosSyslogger form, loggerTool tool) { string currentPath = System.Environment.CurrentDirectory; Process process = new Process(); process.StartInfo.FileName = currentPath + @"\deviceid.exe"; process.StartInfo.Arguments = "-l"; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.OutputDataReceived += new DataReceivedEventHandler((source, e) => uuidinfoHandler(source, e, form)); //* Start process and handlers process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); if (Program.GlobalData.usbRemoved == true) //Called after usb waas removed { foreach (string uuidt in Program.GlobalData.uuid) { Process test = new Process(); if (!(crProcess.TryGetValue(uuidt, out test))) { continue; } if (!Program.GlobalData.tempuuid.Contains(uuidt) && uuidt != null && crProcess[uuidt] != null) { crProcess[uuidt].Kill(); crProcess.Remove(uuidt); } } Program.GlobalData.uuid.Clear(); Program.GlobalData.uuid.AddRange(Program.GlobalData.tempuuid); foreach (string uuidstring in Program.GlobalData.uuid) { Thread loggingThread = new Thread(() => tool.readDeviceinfo(form, uuidstring)); loggingThread.IsBackground = true; loggingThread.Start(); } Program.GlobalData.usbRemoved = false; return; } else if (Program.GlobalData.usbInserted == true) //Called after usb was inserted { if (Program.GlobalData.uuid[Program.GlobalData.uuid.Count - 1] == null) { return; } else { deviceInfoThread(form, tool, Program.GlobalData.uuid[Program.GlobalData.uuid.Count - 1]); LoggingThread(form, tool, Program.GlobalData.uuid[Program.GlobalData.uuid.Count - 1]); lstThreads[lstThreads.Count - 2].Start(); lstThreads[lstThreads.Count - 1].Start(); Program.GlobalData.notInit = true; return; } } else if (Program.GlobalData.usbInserted != true) //First time initiated { if (Program.GlobalData.usbInserted == true) { return; } foreach (string uuid in Program.GlobalData.uuid) { deviceInfoThread(form, tool, uuid); LoggingThread(form, tool, uuid); } foreach (Thread th in lstThreads) { th.Start(); } return; } else { return; } }
static void DeviceRemovedEvent(object sender, EventArrivedEventArgs e, iosSyslogger window, loggerTool tool) { GlobalData.usbInserted = false; if (GlobalData.usbRemoved == true) { return; } else { GlobalData.usbRemoved = true; tool.readDeviceUUID(window, tool); } }
static void DeviceInsertedEvent(object sender, EventArgs e, iosSyslogger window, loggerTool tool) { if (GlobalData.usbInserted == true) //If this is true, new iOS Device has already been processed { return; } else { GlobalData.usbInserted = true; tool.readDeviceUUID(window, tool); } }
public void readDeviceUUID(iosSyslogger form, loggerTool tool) { string currentPath = System.Environment.CurrentDirectory; Process process = new Process(); process.StartInfo.FileName = currentPath + @"\deviceid.exe"; process.StartInfo.Arguments = "-l"; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.OutputDataReceived += new DataReceivedEventHandler((source, e) => uuidinfoHandler(source, e, form)); //* Start process and handlers process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); if (Program.GlobalData.usbRemoved == true) //Called after usb waas removed { foreach (string uuidt in Program.GlobalData.uuid) { Process test = new Process(); if (!(crProcess.TryGetValue(uuidt, out test))) { continue; } if (!Program.GlobalData.tempuuid.Contains(uuidt) && uuidt != null && crProcess[uuidt] != null) { crProcess[uuidt].Kill(); crProcess.Remove(uuidt); } } Program.GlobalData.uuid.Clear(); Program.GlobalData.uuid.AddRange(Program.GlobalData.tempuuid); foreach (string uuidstring in Program.GlobalData.uuid) { Thread loggingThread = new Thread(() => tool.readDeviceinfo(form, uuidstring)); loggingThread.IsBackground = true; loggingThread.Start(); } Program.GlobalData.usbRemoved = false; return; } else if (Program.GlobalData.usbInserted == true) //Called after usb was inserted { if (Program.GlobalData.uuid[Program.GlobalData.uuid.Count - 1] == null) return; else { deviceInfoThread(form, tool, Program.GlobalData.uuid[Program.GlobalData.uuid.Count - 1]); LoggingThread(form, tool, Program.GlobalData.uuid[Program.GlobalData.uuid.Count - 1]); lstThreads[lstThreads.Count - 2].Start(); lstThreads[lstThreads.Count - 1].Start(); Program.GlobalData.notInit = true; return; } } else if (Program.GlobalData.usbInserted!=true) //First time initiated { if (Program.GlobalData.usbInserted == true) return; foreach (string uuid in Program.GlobalData.uuid) { deviceInfoThread(form, tool, uuid); LoggingThread(form, tool, uuid); } foreach (Thread th in lstThreads) { th.Start(); } return; } else return; }
//Creating thread for Logger public void LoggingThread(iosSyslogger form, loggerTool tool,string uuid) { Thread loggingThread = new Thread(() => tool.readLog(form,uuid)); loggingThread.IsBackground = true; lstThreads.Add(loggingThread); }
//Create thread for Device info reader public void deviceInfoThread(iosSyslogger form, loggerTool tool, string uuid) { Thread deviceInfoThread = new Thread(() => tool.readDeviceinfo(form,uuid)); deviceInfoThread.IsBackground = true; lstThreads.Add(deviceInfoThread); }