Advertisement
Hydrox

Untitled

Feb 24th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.86 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Runtime.InteropServices;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows.Forms;
  9.  
  10. namespace Hydrox_multi_V._2
  11. {
  12. class Mem
  13. {
  14. static public int pHandle;
  15. static public Process csgoProcess;
  16.  
  17. static public void AttachProcess(string ProcName)
  18. {
  19. try
  20. {
  21. csgoProcess = Process.GetProcessesByName(ProcName)[0];
  22. if (csgoProcess.ProcessName.Length > 0)
  23. {
  24. pHandle = (int)WinAPI.OpenProcess(2035711, false, csgoProcess.Id);
  25. }
  26. }
  27. catch
  28. {
  29. MessageBox.Show("Please Start CS:GO first.");
  30. Environment.Exit(0);
  31. }
  32. }
  33.  
  34. static public int GetDll(string DLLName)
  35. {
  36. int DLLaddress = 0;
  37. foreach (ProcessModule module in csgoProcess.Modules)
  38. {
  39. if (module.ModuleName.Equals(DLLName))
  40. {
  41. DLLaddress = (int)module.BaseAddress;
  42. }
  43. }
  44. return DLLaddress;
  45. }
  46.  
  47. static public int GetDllSize(string DLLName)
  48. {
  49. int DllSize = 0;
  50. foreach (ProcessModule module in csgoProcess.Modules)
  51. {
  52. if (module.ModuleName.Equals(DLLName))
  53. {
  54. DllSize = (int)module.ModuleMemorySize;
  55. }
  56. }
  57. return DllSize;
  58. }
  59.  
  60.  
  61. public static T Read<T>(int address) where T : struct
  62. {
  63. int out1;
  64. byte[] buffer = new byte[Marshal.SizeOf(typeof(T))];
  65. WinAPI.ReadProcessMemory(pHandle, address, buffer, buffer.Length, out out1);
  66.  
  67. GCHandle gcHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
  68. T value = (T)Marshal.PtrToStructure(gcHandle.AddrOfPinnedObject(), typeof(T));
  69. gcHandle.Free();
  70.  
  71. return value;
  72. }
  73.  
  74. public static void Write<T>(int address, T value) where T : struct
  75. {
  76. int br = 0;
  77. int sz = Marshal.SizeOf(typeof(T)); //Size of T
  78. byte[] result = new byte[sz]; //Create byte array which size is 'T' size
  79.  
  80. IntPtr buff = Marshal.AllocHGlobal(sz); //Allocates unamanged memory of the proccess
  81. Marshal.StructureToPtr(value, buff, false); //Converting Struct to Ptr
  82. Marshal.Copy(buff, result, 0, sz); //Copies object from unmanaged memory to array
  83. Marshal.FreeHGlobal(buff); //Releasing allocated unmanaged memory
  84.  
  85. WinAPI.WriteProcessMemory(pHandle, address, result, result.Length, br); //Writing memory
  86. }
  87.  
  88. static string CutString(string mystring)
  89. {
  90. char[] chArray = mystring.ToCharArray();
  91. string str = "";
  92. for (int i = 0; i < mystring.Length; i++)
  93. {
  94. if ((chArray[i] == ' ') && (chArray[i + 1] == ' '))
  95. {
  96. return str;
  97. }
  98. if (chArray[i] == '\0')
  99. {
  100. return str;
  101. }
  102. str = str + chArray[i].ToString();
  103. }
  104. return mystring.TrimEnd(new char[] { '0' });
  105. }
  106. public static string ReadString(int pOffset, int pSize)
  107. {
  108. return CutString(Encoding.Unicode.GetString(ReadMemory(pOffset, pSize)));
  109. }
  110.  
  111. static byte[] ReadMemory(int pOffset, int pSize)
  112. {
  113. int out1;
  114. byte[] buffer = new byte[pSize];
  115. WinAPI.ReadProcessMemory(pHandle, pOffset, buffer, pSize, out out1);
  116. return buffer;
  117. }
  118.  
  119. }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement