public static bool KillMutex(Process process, string mutexName) { bool killed = false; for (int i = 1; i < 3; i++) { var handles = Win32Processes.GetHandles(process, "Mutant", "\\Sessions\\" + i + "\\BaseNamedObjects\\" + mutexName); if (handles.Count == 0) { continue; } foreach (var handle in handles) { IntPtr ipHandle = IntPtr.Zero; if (!Win32API.DuplicateHandle(Process.GetProcessById(handle.ProcessID).Handle, handle.Handle, Win32API.GetCurrentProcess(), out ipHandle, 0, false, Win32API.DUPLICATE_CLOSE_SOURCE)) { Debug.WriteLine("DuplicateHandle() failed, error = {0}", Marshal.GetLastWin32Error()); } Debug.WriteLine("Mutex was killed"); killed = true; } } return(killed); }
public static bool KillMutex(Process process, string mutexName) { // 4 tries for (int i = 1; i < 4; i++) { Console.WriteLine("Loop " + i); var handles = Win32Processes.GetHandles(process, "Mutant", "\\Sessions\\", mutexName); if (handles.Count == 0) { continue; } foreach (var handle in handles) { IntPtr ipHandle = IntPtr.Zero; if (!Win32API.DuplicateHandle(Process.GetProcessById(handle.ProcessID).Handle, handle.Handle, Win32API.GetCurrentProcess(), out ipHandle, 0, false, Win32API.DUPLICATE_CLOSE_SOURCE)) { Console.WriteLine("DuplicateHandle() failed, error = {0}", Marshal.GetLastWin32Error()); } return(true); } } return(false); }
public static bool MutexExists(Process process, string mutexType, string mutexName, bool partial) { Log(string.Format("Checking if mutex '{0}' of type '{1}' exists in process '{2} (pid {3})'", mutexName, mutexType, process.MainWindowTitle, process.Id)); // 4 tries for (int i = 0; i < 4; i++) { try { var handles = Win32Processes.GetHandles(process, mutexType, "", mutexName); if (partial) { bool foundHandle = false; foreach (var handle in handles) { string strObjectName = Win32Processes.getObjectName(handle, Process.GetProcessById(handle.ProcessID)); if (!string.IsNullOrWhiteSpace(strObjectName) && strObjectName.Contains(mutexName)) { Log(string.Format("Found mutex that contains search criteria. Located at {0}", strObjectName)); if (!foundHandle) { foundHandle = true; } } } return(foundHandle); } else { if (handles.Count > 0) { Log("Found the following mutexes:"); foreach (var handle in handles) { string strObjectName = Win32Processes.getObjectName(handle, Process.GetProcessById(handle.ProcessID)); Log(strObjectName); } return(true); } } } catch (IndexOutOfRangeException) { Log(string.Format("The process name '{0}' is not currently running", process.MainWindowTitle)); } catch (ArgumentException) { Log(string.Format("The mutex '{0}' was not found in the process '{1}'", mutexName, process.MainWindowTitle)); } } return(false); }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { // IF THIS DOESNT WORK FOR YOU THEN THIS IS THE PROBLEM // var handles = Win32Processes.GetHandles(p, "Mutant", "\\Sessions\\4\\BaseNamedObjects\\" + MutexToRemove); // SEE WHERE IT SAYS 4, THIS IS NOT MATCHING THE NUMBER ON YOUR COMPUTER // YOU CAN FIND THIS NUMBER USING PROCESS EXPLORER, CHOOSING GAME.BIN, CLICKING CTRL+H AND SCROLLING DOWN A BIT // TODO: AUTOMAGICALLY FETCH THE CORRECT SESSION NUMBER XD // UPDATE: USE FUNCTION 'determineSession' to automagically get the right string to work with String MutexToRemove = "FFClientTag"; Process[] activeP; while (_started == true) { activeP = Process.GetProcessesByName("game.bin"); foreach (Process p in activeP) { var handles = Win32Processes.GetHandles(p, "Mutant", "\\Sessions\\4\\BaseNamedObjects\\" + MutexToRemove); if (handles.Count < 1) { // ignore // SIMPLY IGNORE OUR PROBLEMS } else { foreach (var handle in handles) { try { IntPtr ipHandle = IntPtr.Zero; if (!Win32API.DuplicateHandle(Process.GetProcessById(handle.ProcessID).Handle, handle.Handle, Win32API.GetCurrentProcess(), out ipHandle, 0, false, Win32API.DUPLICATE_CLOSE_SOURCE)) { Console.WriteLine("DuplicateHandle() failed, error = {0}", Marshal.GetLastWin32Error()); continue; } //Console.WriteLine(String.Format("Mutex {0} was removed from process '{1}' with PID {2}.\n", MutexToRemove, p.ProcessName, p.Id)); listBox1.Items.Add(String.Format("Mutex {0} was removed from process '{1}' with PID {2}.\n", MutexToRemove, p.ProcessName, p.Id)); } catch (Exception) { // do nothing // SHITTY ERROR HANDLING } } } } System.Threading.Thread.Sleep(500); // lets let this bitch rest sum xDDD } // END WHILE }
string determineSession() { String foundSession; Process p = Process.GetProcessesByName("game.bin")[0]; for (int i = 0; i < 11; i++) // you can make it check for a million session ids, but its probably not gonna be more than 10 xd { var handles = Win32Processes.GetHandles(p, "Directory", "\\Sessions\\" + i + "\\BaseNamedObjects"); if (handles.Count > 0) { foundSession = "\\Sessions\\" + i + "\\BaseNamedObjects\\"; return(foundSession); } } return("n/a"); }
public static bool MutexExists(Process process, string mutexName) { // 4 tries for (int i = 0; i < 4; i++) { try { var handles = Win32Processes.GetHandles(process, "Mutant", "\\Sessions\\", mutexName); if (handles.Count > 0) { return(true); } } catch (IndexOutOfRangeException) { } catch (ArgumentException) { } } return(false); }
public static bool MutexExists(Process process, string mutexName) { #if WINDOWS // 4 tries for (int i = 0; i < 4; i++) { try { var handles = Win32Processes.GetHandles(process, "Mutant", "\\Sessions\\", mutexName); if (handles.Count > 0) { return(true); } } catch (IndexOutOfRangeException) { } catch (ArgumentException) { } } return(false); #else throw new PlatformNotSupportedException(); #endif }
public static bool KillMutex(Process process, string mutexName) { var handles = Win32Processes.GetHandles(process, "Mutant", "\\Sessions\\", mutexName); if (handles.Count == 0) { return(false); } foreach (Win32API.SYSTEM_HANDLE_INFORMATION handle in handles) { IntPtr ipHandle = IntPtr.Zero; if (!Win32API.DuplicateHandle(Process.GetProcessById(handle.ProcessID).Handle, (IntPtr)handle.Handle, Win32API.GetCurrentProcess(), out ipHandle, 0, false, Win32API.DUPLICATE_CLOSE_SOURCE)) { Console.WriteLine("DuplicateHandle() failed, error = {0}", Marshal.GetLastWin32Error()); } return(true); } return(false); }
public static bool MutexExists(Process process, string mutexName) { // TODO: Does only 1-3 exist? I've only seen these values in the Sessions for (int i = 1; i < 3; i++) { try { var handles = Win32Processes.GetHandles(process, "Mutant", "\\Sessions\\", mutexName); if (handles.Count > 0) { return(true); } } catch (IndexOutOfRangeException) { } catch (ArgumentException) { } } return(false); }
public static bool KillMutex(Process process, string mutexName) { // session can change ?!?!?! wtf, can have value of 1 or 2 bool killed = false; for (int i = 1; i < 3; i++) { try { var handles = Win32Processes.GetHandles(process, "Mutant", "\\Sessions\\" + i + "\\BaseNamedObjects\\" + mutexName); if (handles.Count == 0) { throw new System.ArgumentException("NoMutex", "original"); } foreach (var handle in handles) { IntPtr ipHandle = IntPtr.Zero; if (!Win32API.DuplicateHandle(Process.GetProcessById(handle.ProcessID).Handle, handle.Handle, Win32API.GetCurrentProcess(), out ipHandle, 0, false, Win32API.DUPLICATE_CLOSE_SOURCE)) { Debug.WriteLine("DuplicateHandle() failed, error = {0}", Marshal.GetLastWin32Error()); } Debug.WriteLine("Mutex was killed"); killed = true; } } catch (IndexOutOfRangeException) { } catch (ArgumentException) { } } return(killed); }
public static bool KillMutex(Process process, string mutexType, string mutexName, bool partial) { Log(string.Format("Attempting to kill mutex")); // 4 tries for (int i = 1; i < 4; i++) { Log("Attempt #" + i); Console.WriteLine("Loop " + i); if (partial) { var handles = Win32Processes.GetHandles(process, mutexType); foreach (var handle in handles) { string strObjectName = Win32Processes.getObjectName(handle, Process.GetProcessById(handle.ProcessID)); if (!string.IsNullOrWhiteSpace(strObjectName) && strObjectName.Contains(mutexName)) { Log(string.Format("Killing mutex located at '{0}'", strObjectName)); IntPtr ipHandle = IntPtr.Zero; if (!Win32API.DuplicateHandle(Process.GetProcessById(handle.ProcessID).Handle, handle.Handle, Win32API.GetCurrentProcess(), out ipHandle, 0, false, Win32API.DUPLICATE_CLOSE_SOURCE)) { Log(string.Format("DuplicateHandle() failed, error = {0}", Marshal.GetLastWin32Error())); Console.WriteLine("DuplicateHandle() failed, error = {0}", Marshal.GetLastWin32Error()); } else { Log("Mutex was killed successfully"); return(true); } } //Log("----------------END-----------------"); } return(true); } else { var handles = Win32Processes.GetHandles(process, mutexType, "", mutexName); if (handles.Count == 0) { Log(string.Format("{0} not found in process handles", mutexName)); continue; } foreach (var handle in handles) { string strObjectName = Win32Processes.getObjectName(handle, Process.GetProcessById(handle.ProcessID)); Log(string.Format("Killing mutex {0}", strObjectName)); if (!string.IsNullOrWhiteSpace(strObjectName) && strObjectName.EndsWith(mutexName)) { IntPtr ipHandle = IntPtr.Zero; if (!Win32API.DuplicateHandle(Process.GetProcessById(handle.ProcessID).Handle, handle.Handle, Win32API.GetCurrentProcess(), out ipHandle, 0, false, Win32API.DUPLICATE_CLOSE_SOURCE)) { Console.WriteLine("DuplicateHandle() failed, error = {0}", Marshal.GetLastWin32Error()); } else { Log("Mutex was killed successfully"); return(true); } } } } } Log("Mutex was not killed"); //Log("----------------END-----------------"); return(false); }
public ToolsViewModel() { InitThings(); this.BuyCommand = new RelayCommand <MallThing>( (t) => this.Buy(t), (t) => t != null && SoftContext.Role != null); this.StopCommand = new RelayCommand(() => { SoftContext.TaskEngine.Stop(); }); this.OpenCommand = new RelayCommand(() => { try { Process[] all = Process.GetProcessesByName("DragonNest"); if (all != null) { if (all.Length == 0) { SoftContext.MainWindow.ShowMessageAsync("多开失败", "没有找到游戏进程"); return; } foreach (Process process in all) { var handles = Win32Processes.GetHandles(process, "Mutant", "\\BaseNamedObjects\\MutexDragonNest"); if (handles.Count == 0) { continue; } foreach (var handle in handles) { IntPtr ipHandle = IntPtr.Zero; if (!MutexCloseHelper.DuplicateHandle(Process.GetProcessById(handle.ProcessID).Handle, handle.Handle, MutexCloseHelper.GetCurrentProcess(), out ipHandle, 0, false, MutexCloseHelper.DUPLICATE_CLOSE_SOURCE)) { // richTextBox1.AppendText("DuplicateHandle() failed, error =" + Marshal.GetLastWin32Error() + Environment.NewLine); } else { MutexCloseHelper.CloseHandle(ipHandle); SoftContext.MainWindow.ShowMessageAsync("多开成功", "进程[" + handle.ProcessID + "]的互斥体句柄关闭成功"); } } } } else { SoftContext.MainWindow.ShowMessageAsync("多开失败", "没有找到游戏进程"); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } }); this.BeginBagClearCommand = new RelayCommand(() => { TaskContext context = new TaskContext(SoftContext.Role); /// 任务设置,可用属性为:.Thing .Num .UseLB context.Settings.BeginPage = BeginPage; context.Settings.BeginItem = BeginItem; context.Settings.StopPage = StopPage; context.Settings.StopItem = StopItem; TaskBase task = new BagClearTask(context); task.Name = "清理背包"; SoftContext.TaskEngine.Start(task); }, () => SoftContext.Role != null); this.AutoOpenEggCommand = new RelayCommand(() => { TaskContext context = new TaskContext(SoftContext.Role); TaskBase task = new ZidongkaidanTask(context); task.Name = "自动开蛋"; SoftContext.TaskEngine.Start(task); }, () => SoftContext.Role != null); this.StopBagClearCommand = new RelayCommand(() => { SoftContext.TaskEngine.Stop(); }); }