Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Hydrox_multi_V._2
- {
- class Mem
- {
- static public int pHandle;
- static public Process csgoProcess;
- static public void AttachProcess(string ProcName)
- {
- try
- {
- csgoProcess = Process.GetProcessesByName(ProcName)[0];
- if (csgoProcess.ProcessName.Length > 0)
- {
- pHandle = (int)WinAPI.OpenProcess(2035711, false, csgoProcess.Id);
- }
- }
- catch
- {
- MessageBox.Show("Please Start CS:GO first.");
- Environment.Exit(0);
- }
- }
- static public int GetDll(string DLLName)
- {
- int DLLaddress = 0;
- foreach (ProcessModule module in csgoProcess.Modules)
- {
- if (module.ModuleName.Equals(DLLName))
- {
- DLLaddress = (int)module.BaseAddress;
- }
- }
- return DLLaddress;
- }
- static public int GetDllSize(string DLLName)
- {
- int DllSize = 0;
- foreach (ProcessModule module in csgoProcess.Modules)
- {
- if (module.ModuleName.Equals(DLLName))
- {
- DllSize = (int)module.ModuleMemorySize;
- }
- }
- return DllSize;
- }
- public static T Read<T>(int address) where T : struct
- {
- int out1;
- byte[] buffer = new byte[Marshal.SizeOf(typeof(T))];
- WinAPI.ReadProcessMemory(pHandle, address, buffer, buffer.Length, out out1);
- GCHandle gcHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
- T value = (T)Marshal.PtrToStructure(gcHandle.AddrOfPinnedObject(), typeof(T));
- gcHandle.Free();
- return value;
- }
- public static void Write<T>(int address, T value) where T : struct
- {
- int br = 0;
- int sz = Marshal.SizeOf(typeof(T)); //Size of T
- byte[] result = new byte[sz]; //Create byte array which size is 'T' size
- IntPtr buff = Marshal.AllocHGlobal(sz); //Allocates unamanged memory of the proccess
- Marshal.StructureToPtr(value, buff, false); //Converting Struct to Ptr
- Marshal.Copy(buff, result, 0, sz); //Copies object from unmanaged memory to array
- Marshal.FreeHGlobal(buff); //Releasing allocated unmanaged memory
- WinAPI.WriteProcessMemory(pHandle, address, result, result.Length, br); //Writing memory
- }
- static string CutString(string mystring)
- {
- char[] chArray = mystring.ToCharArray();
- string str = "";
- for (int i = 0; i < mystring.Length; i++)
- {
- if ((chArray[i] == ' ') && (chArray[i + 1] == ' '))
- {
- return str;
- }
- if (chArray[i] == '\0')
- {
- return str;
- }
- str = str + chArray[i].ToString();
- }
- return mystring.TrimEnd(new char[] { '0' });
- }
- public static string ReadString(int pOffset, int pSize)
- {
- return CutString(Encoding.Unicode.GetString(ReadMemory(pOffset, pSize)));
- }
- static byte[] ReadMemory(int pOffset, int pSize)
- {
- int out1;
- byte[] buffer = new byte[pSize];
- WinAPI.ReadProcessMemory(pHandle, pOffset, buffer, pSize, out out1);
- return buffer;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement