public static bool Attach(uint pid, OptionsData options, bool isRazor, out int index) { lock (myLock) { Process p = null; index = -1; try { Thread.Sleep(2000); p = Process.GetProcessById((int)pid); p.EnableRaisingEvents = true; p.Exited += new EventHandler(UOM.OnClientExit); ClientInfo ci = new ClientInfo(p); Memory.MemoryInit(ci); if (ci.IsValid) { ci.InstallMacroHook(); } else { return(false); } if (!isRazor && options.PatchClientEncryptionUOM) { if (!ClientPatcher.PatchEncryption(p.Handle)) { MessageBox.Show(Strings.Errorpatchingclientencryption, Strings.Error); } } if (ci.DateStamp < 0x4AA52CC4 && options.PatchStaminaCheck) { if (!ClientPatcher.PatchStaminaCheck(p.Handle)) { MessageBox.Show(Strings.Errorpatchingstaminacheck, Strings.Error); } } if (options.PatchAlwaysLight) { if (!ClientPatcher.PatchLight(p.Handle)) { MessageBox.Show(Strings.Errorwithalwayslightpatch, Strings.Error); } } if (options.PatchGameSize) { if (!ClientPatcher.SetGameSize(p.Handle, options.PatchGameSizeWidth, options.PatchGameSizeHeight)) { //Silently fail for now as this will fail on UOSteam. //MessageBox.Show(Strings.Errorsettinggamewindowsize); } } int instance; if (!ClientInfoCollection.AddClient(ci, out instance)) { throw new ApplicationException(String.Concat(Strings.Unknownerror, ": ClientInfoCollection.Add.")); } ci.Instance = instance; index = instance; Macros.Macro.ChangeServer(instance, options.Server, options.Port); Thread.Sleep(500); RemoteHooking.Inject(p.Id, Path.Combine(UOM.StartupPath, "clienthook.dll"), Path.Combine(UOM.StartupPath, "clienthook.dll"), UOM.ServerName); } catch (Exception e) { Utility.Log.LogMessage(e); MessageBox.Show(Strings.Errorinjectingdll, Strings.Error); try { if (p != null) { p.Kill(); } } catch (Win32Exception) { } catch (InvalidOperationException) { } return(false); } UOM.SetStatusLabel(Strings.Attachedtoclient); return(true); } }
public static bool Attach(uint pid, OptionsData options, bool isRazor, out int index) { lock (myLock) { Process p = null; index = -1; try { Thread.Sleep(2000); p = Process.GetProcessById((int)pid); p.EnableRaisingEvents = true; p.Exited += new EventHandler(UOM.OnClientExit); ClientInfo ci = new ClientInfo(p); Memory.MemoryInit(ci); if (ci.IsValid) { ci.InstallMacroHook(); } else { return(false); } if (!isRazor && options.PatchClientEncryptionUOM) { if (!ClientPatcher.PatchEncryption(p.Handle)) { MessageBox.Show("Error patching client encryption!", "Error"); } } if (ci.DateStamp < 0x4AA52CC4 && options.PatchStaminaCheck) { if (!ClientPatcher.PatchStaminaCheck(p.Handle)) { MessageBox.Show("Error patching stamina check!", "Error"); } } if (options.PatchAlwaysLight) { if (!ClientPatcher.PatchLight(p.Handle)) { MessageBox.Show("Error with always light patch!", "Error"); } } int instance; if (!ClientInfoCollection.AddClient(ci, out instance)) { throw new ApplicationException("Unknown error at ClientInfoCollection.Add."); } ci.Instance = instance; index = instance; Macros.Macro.ChangeServer(instance, options.Server, options.Port); Thread.Sleep(500); RemoteHooking.Inject(p.Id, Path.Combine(UOM.StartupPath, "clienthook.dll"), Path.Combine(UOM.StartupPath, "clienthook.dll"), UOM.ServerName); } catch (Exception e) { Utility.Log.LogMessage(e); MessageBox.Show("Error injecting ClientHook.dll into target process. Please try again.", "Error"); try { if (p != null) { p.Kill(); } } catch (Win32Exception) { } catch (InvalidOperationException) { } return(false); } UOM.SetStatusLabel("Status: Attached to client"); return(true); } }
public string Start(string path) { Process clientProcess = null; try { ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.WorkingDirectory = path; startInfo.FileName = Path.Combine(path, "client.exe"); UOMachine.NativeMethods.SafeProcessHandle hProcess; UOMachine.NativeMethods.SafeThreadHandle hThread; uint pid, tid; if (UOMachine.NativeMethods.CreateProcess(startInfo, true, out hProcess, out hThread, out pid, out tid)) { ClientPatcher.MultiPatch(hProcess.DangerousGetHandle()); bool result = false; m_AddressLock = new object(); clientProcess = Process.GetProcessById((int)pid); UOMachine.IPC.Network.Initialize(); UOMachine.Utility.Log.Initialize("UnitTests" + DateTime.Now.ToString("[MM - dd - yyyy HH.mm.ss] ") + ".txt"); InternalEventHandler.IPCHandler.Initialize(); UOMachine.NativeMethods.ResumeThread(hThread.DangerousGetHandle()); ClientInfo ci = new ClientInfo(clientProcess); int instance = 0; ClientInfoCollection.ClientList[instance] = ci; ClientInfoCollection.Count = 1; ulong len = (ulong)ci.EntryPoint - (ulong)ci.BaseAddress; UOMachine.NativeMethods.GainMemoryAccessEx(ci.Handle, ci.BaseAddress, len); string channelName = null; RemoteHooking.IpcCreateServer<LoginServerTest>(ref channelName, System.Runtime.Remoting.WellKnownObjectMode.SingleCall); RemoteHooking.Inject(clientProcess.Id, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "UnitTests.dll"), null, channelName); ci.InstallMacroHook(); Macro.ChangeServer(instance, "127.0.0.1", 2593); Thread.Sleep(10000); lock (m_AddressLock) { GumpInfo[] gi = Macro.GetGumpList(instance); foreach (GumpInfo g in gi) { if (g.Type == "MainMenu gump") { foreach (GumpInfo g2 in g.SubGumps) { if (g2.Type == "AcctLogin gump") { if (ci.DateStamp > 0x43A06A35) g2.CallFunction(26); else g2.CallFunction(23); } } } } result = Monitor.Wait(m_AddressLock, 60000); } UOMachine.IPC.Network.Dispose(); Log.Dispose(); UOMachine.NativeMethods.TerminateProcess(Process.GetProcessById(clientProcess.Id).Handle, 0); return m_Address; } } catch (Exception) { UOMachine.IPC.Network.Dispose(); Log.Dispose(); UOMachine.NativeMethods.TerminateProcess(Process.GetProcessById(clientProcess.Id).Handle, 0); throw; } return null; }
public static bool Attach( uint pid, OptionsData options, bool isRazor, out int index ) { lock (myLock) { Process p = null; index = -1; try { Thread.Sleep( 2000 ); p = Process.GetProcessById( (int)pid ); p.EnableRaisingEvents = true; p.Exited += new EventHandler( UOM.OnClientExit ); ClientInfo ci = new ClientInfo( p ); Memory.MemoryInit( ci ); if (ci.IsValid) ci.InstallMacroHook(); else return false; if (!isRazor && options.PatchClientEncryptionUOM) { if (!ClientPatcher.PatchEncryption( p.Handle )) { MessageBox.Show( Strings.Errorpatchingclientencryption, Strings.Error ); } } if (ci.DateStamp < 0x4AA52CC4 && options.PatchStaminaCheck) { if (!ClientPatcher.PatchStaminaCheck( p.Handle )) { MessageBox.Show( Strings.Errorpatchingstaminacheck, Strings.Error ); } } if (options.PatchAlwaysLight) { if (!ClientPatcher.PatchLight( p.Handle )) { MessageBox.Show( Strings.Errorwithalwayslightpatch, Strings.Error ); } } if (options.PatchGameSize) { if (!ClientPatcher.SetGameSize( p.Handle, options.PatchGameSizeWidth, options.PatchGameSizeHeight )) { //Silently fail for now as this will fail on UOSteam. //MessageBox.Show(Strings.Errorsettinggamewindowsize); } } int instance; if (!ClientInfoCollection.AddClient( ci, out instance )) throw new ApplicationException( String.Concat( Strings.Unknownerror, ": ClientInfoCollection.Add." ) ); ci.Instance = instance; index = instance; Macros.Macro.ChangeServer( instance, options.Server, options.Port ); Thread.Sleep( 500 ); RemoteHooking.Inject( p.Id, Path.Combine( UOM.StartupPath, "clienthook.dll" ), Path.Combine( UOM.StartupPath, "clienthook.dll" ), UOM.ServerName ); } catch (Exception e) { Utility.Log.LogMessage( e ); MessageBox.Show( Strings.Errorinjectingdll, Strings.Error ); try { if (p != null) p.Kill(); } catch (Win32Exception) { } catch (InvalidOperationException) { } return false; } UOM.SetStatusLabel( Strings.Attachedtoclient ); return true; } }