ChuckHearthstone/SilverFish

GetMemory of process

Opened this issue · 5 comments

// Triton.Game.TritonHs
// Token: 0x0600192F RID: 6447 RVA: 0x000D8FC8 File Offset: 0x000D71C8
internal static bool smethod_0(Process process_0, TritonHs.Delegate6 delegate6_0, out string string_0)
{
	if (TritonHs.Initialized)
	{
		string_0 = "SmartInitialize has already been called.";
		return false;
	}
	if (process_0 == null)
	{
		string_0 = "process == null";
		return false;
	}
	if (delegate6_0 == null)
	{
		string_0 = "getOffsetsDelegate == null";
		return false;
	}
	if (Class247.smethod_1(process_0.MainModule.FileName) == Class247.UInt32_0)
	{
		string_0 = "This client version is unsupported.";
		return false;
	}
	if (delegate6_0(TritonHs.String_0, out string_0) != null)
	{
		if (!string.IsNullOrEmpty(string_0))
		{
			string_0 = string.Format("The data required to run the bot was not successfully obtained. Please make sure your key is still valid at the Buddy Auth Portal: http://buddyauth.com/User/Keys {0}{0}For any further assistance, please contact support: https://bosslandgmbh.zendesk.com/home", Environment.NewLine);
		}
		return false;
	}
	try
	{
		ExternalProcessMemoryInitParams externalProcessMemoryInitParams = new ExternalProcessMemoryInitParams
		{
			Process = process_0,
			StartupRasm = false,
			DefaultCacheValue = true,
			Executor = ExecutorInitParams.DX9()
		};
		externalProcessMemoryInitParams.Executor.MinSkipBytes = 8;
		try
		{
			TritonHs.externalProcessMemory_0 = new ExternalProcessMemory(externalProcessMemoryInitParams);
		}
		catch (Exception ex)
		{
			if (!ex.Message.Equals("Could not find DX9 in process!"))
			{
				throw;
			}
			TritonHs.ilog_0.Info("Process is not using DX9, now trying DX11...");
			externalProcessMemoryInitParams = new ExternalProcessMemoryInitParams
			{
				Process = process_0,
				StartupRasm = false,
				DefaultCacheValue = true,
				Executor = ExecutorInitParams.DX11()
			};
			externalProcessMemoryInitParams.Executor.MinSkipBytes = 8;
			TritonHs.externalProcessMemory_0 = new ExternalProcessMemory(externalProcessMemoryInitParams);
		}
		TritonHs.externalProcessMemory_0.ProcessExited += TritonHs.Class246.ChuckInstance9.method_0;
		TritonHs.class276_0 = new Class276(TritonHs.externalProcessMemory_0);
		using (TritonHs.AcquireFrame())
		{
			TritonHs.intptr_1 = TritonHs.Class276_0.method_2();
		}
		ProcessHookManager.smethod_3();
		Hotkeys.Initialize(TritonHs.ClientWindowHandle);
		Input.DebugMouseCursorPos = false;
		TritonHs.Initialized = true;
		TritonHs.bool_0 = false;
	}
	catch (Exception ex2)
	{
		string_0 = ex2.ToString();
		return false;
	}
	string_0 = string.Empty;
	return true;
}
// Hearthbuddy.Windows.MainWindow
// Token: 0x0600020F RID: 527 RVA: 0x00003CED File Offset: 0x00001EED
private void method_3()
{
	ThreadPool.QueueUserWorkItem(new WaitCallback(this.method_21));
}

// Hearthbuddy.Windows.MainWindow
// Token: 0x0600023F RID: 575 RVA: 0x0008BC00 File Offset: 0x00089E00
[CompilerGenerated]
private void method_21(object object_0)
{
	try
	{
		base.Dispatcher.Invoke(new Action(this.method_22));
		string text;
		if (this.process_0 == null)
		{
			base.Dispatcher.BeginInvoke(new Action(base.Close), Array.Empty<object>());
		}
		else if (!TritonHs.smethod_0(this.process_0, new TritonHs.Delegate6(Class12.smethod_4), out text))
		{
			MainWindow.ilog_0.Error(text);
			System.Windows.MessageBox.Show(text, "Error", MessageBoxButton.OK, MessageBoxImage.Hand);
			base.Dispatcher.BeginInvoke(new Action(base.Close), Array.Empty<object>());
		}
		else
		{
			TritonHs.Memory.ProcessExited += MainWindow.Class25.ChuckInstance9.method_1;
			TritonHs.Memory.Executor.FrameDropWaitTime = 15000u;
			TritonHs.Memory.Executor.ExecuteWaitTime = 15000;
			TritonHs.Memory.DisableCache();
			TritonHs.Memory.ClearCache();
			int version;
			int clientChangelist;
			using (TritonHs.AcquireFrame())
			{
				version = Triton.Game.Mapping.Version.version;
				clientChangelist = Triton.Game.Mapping.Version.clientChangelist;
			}
			if ((long)version != (long)((ulong)Class247.UInt32_1) && (long)clientChangelist != (long)((ulong)Class247.UInt32_2))
			{
				MainWindow.ilog_0.InfoFormat("Hearthstone client version ({0}, {1})", version, clientChangelist);
				new Coroutine(new Func<Task>(MainWindow.Class25.ChuckInstance9.method_2));
				Configuration.Instance.AddSettings(MainSettings.Instance);
				Configuration.Instance.AddSettings(DevSettings.Instance);
				Configuration.Instance.SaveAll();
				base.Dispatcher.Invoke(new Action(this.method_23));
				BotManager.PreStart += this.method_11;
				BotManager.PostStop += this.method_10;
				BotManager.Load();
				base.Dispatcher.Invoke(new Action(this.method_24));
				this.comboBox_0.Dispatcher.BeginInvoke(new Action(this.method_25), Array.Empty<object>());
				BotManager.OnBotChanged += this.method_6;
				RoutineManager.Load();
				base.Dispatcher.Invoke(new Action(this.method_26));
				this.comboBox_1.Dispatcher.BeginInvoke(new Action(this.method_27), Array.Empty<object>());
				RoutineManager.OnRoutineChanged += this.method_7;
				PluginManager.Load();
				foreach (IPlugin plugin in PluginManager.Plugins)
				{
					if (MainSettings.Instance.EnabledPlugins.Contains(plugin.Name))
					{
						using (TritonHs.AcquireFrame())
						{
							PluginManager.Enable(plugin);
						}
						Thread.Sleep(20);
					}
					else
					{
						using (TritonHs.AcquireFrame())
						{
							PluginManager.Disable(plugin);
						}
						Thread.Sleep(20);
					}
				}
				this.listBox_0.Dispatcher.Invoke<IEnumerable>(new Func<IEnumerable>(this.method_28), DispatcherPriority.Normal);
				base.Dispatcher.Invoke(new Action(this.method_29));
				PluginManager.PluginEnabled += this.method_5;
				PluginManager.PluginDisabled += this.method_4;
				MainWindow.ilog_0.ErrorFormat("{0}Please read the following guide before using this program:{0}https://github.com/ChuckHearthBuddy/SilverFish/blob/master/ReadMe.md", Environment.NewLine);
				base.Dispatcher.Invoke(new Action(this.method_30));
				base.Dispatcher.Invoke(new Action(this.method_31));
				this.stopwatch_0.Restart();
				RoutineManager.OnRoutineChanged += this.method_7;
				BotManager.OnBotChanged += this.method_6;
				TritonHs.IsBotFullyLoaded = true;
				Hotkeys.Register("BotManager.StartStop", Keys.S, ModifierKeys.Alt | ModifierKeys.Shift, new Action<Hotkey>(MainWindow.Class25.ChuckInstance9.method_3));
				if (CommandLine.Arguments.Exists("autostart"))
				{
					BotManager.Start();
				}
			}
			else
			{
				text = string.Format("This client version ({0}, {1}) is unsupported. Hearthbuddy currently supports client version ({2}, {3}). Please check the forums for more information: https://www.thebuddyforum.com/hearthbuddy-forum/", new object[]
				{
					version,
					clientChangelist,
					Class247.UInt32_1,
					Class247.UInt32_2
				});
				MainWindow.ilog_0.ErrorFormat(text, Array.Empty<object>());
				System.Windows.MessageBox.Show(text, "Error", MessageBoxButton.OK, MessageBoxImage.Hand);
				base.Dispatcher.BeginInvoke(new Action(base.Close), Array.Empty<object>());
			}
		}
	}
	catch (Exception exception)
	{
		MainWindow.ilog_0.Error("[OnStartup] A top-level exception has been caught.", exception);
	}
}
// Hearthbuddy.Windows.MainWindow
// Token: 0x06000240 RID: 576 RVA: 0x0008C108 File Offset: 0x0008A308
[CompilerGenerated]
private void method_22()
{
	if (!Class9.smethod_4(out this.mutex_0, out this.process_0))
	{
		MainWindow.ilog_0.Error("Could not attach to a Hearthstone process. Please make sure an available Hearthstone process is running.");
		MessageBox.Show(string.Format("Could not attach to a Hearthstone process. Please make sure an available Hearthstone process is running.{0}{0}Hearthbuddy will now close.", Environment.NewLine), "Hearthbuddy", MessageBoxButton.OK, MessageBoxImage.Hand);
		return;
	}
	this.dispatcherTimer_0 = new DispatcherTimer(TimeSpan.FromSeconds(1.0), DispatcherPriority.Normal, new EventHandler(this.method_9), base.Dispatcher);
	this.dispatcherTimer_0.Start();
}
// ns3.Class9
// Token: 0x06000116 RID: 278 RVA: 0x000033A1 File Offset: 0x000015A1
internal static bool smethod_4(out Mutex mutex_0, out Process process_0)
{
	if (!Class9.smethod_5(out mutex_0, out process_0))
	{
		return false;
	}
	Path.Combine(Path.GetDirectoryName(process_0.MainModule.FileName), "Hearthstone_Data", "Mono");
	return true;
}

// ns3.Class9
// Token: 0x06000117 RID: 279 RVA: 0x000869A4 File Offset: 0x00084BA4
internal static bool smethod_5(out Mutex mutex_0, out Process process_0)
{
	mutex_0 = null;
	process_0 = null;
	Arguments arguments = CommandLine.Arguments;
	if (arguments.Exists("pid"))
	{
		try
		{
			int num = int.Parse(arguments.Single("pid"));
			process_0 = Process.GetProcessById(num);
			if (!Class9.smethod_6(process_0))
			{
				Class9.ilog_0.Error("Invalid PID specifier passed to the command line: " + arguments.Single("pid") + ". This process is not a Hearthstone client.");
				return false;
			}
			bool flag;
			mutex_0 = Class9.smethod_1(num, out flag);
			if (!flag)
			{
				mutex_0 = null;
				process_0 = null;
				Class9.ilog_0.Error("Invalid PID specifier passed to the command line: " + arguments.Single("pid") + ". This process has already been attached to.");
				return false;
			}
			return true;
		}
		catch
		{
			Class9.ilog_0.Error("Invalid PID specifier passed to the command line: " + arguments.Single("pid"));
			return false;
		}
	}
	bool result;
	if (arguments.Exists("pname"))
	{
		try
		{
			string processName = arguments.Single("pname");
			process_0 = Process.GetProcessesByName(processName).FirstOrDefault<Process>();
			if (process_0 != null && Class9.smethod_6(process_0))
			{
				bool flag2;
				mutex_0 = Class9.smethod_1(process_0.Id, out flag2);
				if (!flag2)
				{
					mutex_0 = null;
					process_0 = null;
					Class9.ilog_0.Error("Invalid PNAME specifier passed to the command line: " + arguments.Single("pname") + ". This process has already been attached to.");
					result = false;
				}
				else
				{
					result = true;
				}
			}
			else
			{
				Class9.ilog_0.Error("Invalid PNAME specifier passed to the command line: " + arguments.Single("pname") + ". This process is not a Hearthstone client.");
				result = false;
			}
		}
		catch
		{
			Class9.ilog_0.Error("Invalid PNAME specifier passed to the command line: " + arguments.Single("pname"));
			result = false;
		}
	}
	else
	{
		List<Process> list = Class9.smethod_7().ToList<Process>();
		if (list.Count == 0)
		{
			return false;
		}
		if (!arguments.Exists("noautoattach") && list.Count == 1)
		{
			bool flag3;
			mutex_0 = Class9.smethod_1(list[0].Id, out flag3);
			if (flag3)
			{
				process_0 = list[0];
				return true;
			}
			mutex_0.Dispose();
		}
		Dictionary<Process, string> dictionary = new Dictionary<Process, string>();
		foreach (Process process in list)
		{
			bool flag4;
			mutex_0 = Class9.smethod_1(process.Id, out flag4);
			if (flag4 && mutex_0 != null)
			{
				using (ExternalProcessMemory externalProcessMemory = new ExternalProcessMemory(process, false, false, false))
				{
					dictionary.Add(process, Class9.smethod_0(externalProcessMemory));
					mutex_0.ReleaseMutex();
					mutex_0.Dispose();
				}
			}
		}
		ProcessSelectorWindow processSelectorWindow = new ProcessSelectorWindow(dictionary)
		{
			Topmost = true
		};
		if (processSelectorWindow.ShowDialog() == true)
		{
			process_0 = processSelectorWindow.Selected;
			bool flag5;
			mutex_0 = Class9.smethod_1(process_0.Id, out flag5);
			return true;
		}
		return false;
	}
	return result;
}
// ns3.Class9
// Token: 0x06000118 RID: 280 RVA: 0x00086CB4 File Offset: 0x00084EB4
private static bool smethod_6(Process process_0)
{
	try
	{
		if (X509Certificate.CreateFromSignedFile(process_0.MainModule.FileName).Subject.Contains("Blizzard Entertainment, Inc.") && Directory.Exists(Path.Combine(Path.GetDirectoryName(process_0.MainModule.FileName), "Hearthstone_Data")))
		{
			return true;
		}
	}
	catch
	{
	}
	return false;
}
// ns3.Class9
// Token: 0x06000113 RID: 275 RVA: 0x00086830 File Offset: 0x00084A30
private static Mutex smethod_1(int int_0, out bool bool_0)
{
	return new Mutex(true, "Local\\" + (Environment.MachineName.GetHashCode() ^ int_0.GetHashCode() ^ TimeZone.CurrentTimeZone.StandardName.GetHashCode() ^ "Blizz_HS_BuddyTeam".GetHashCode() + 25), ref bool_0);
}