Advertisement
Guest User

Untitled

a guest
Dec 4th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.98 KB | None | 0 0
  1. using System;
  2. using System.ComponentModel;
  3. using System.Diagnostics;
  4. using System.Drawing;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Runtime.InteropServices;
  8. using System.Runtime.Serialization.Formatters.Binary;
  9. using System.Threading;
  10. using System.Windows.Forms;
  11.  
  12. namespace WindowsFormsApp1
  13. {
  14. public class Form1 : Form
  15. {
  16. private IContainer components = null;
  17.  
  18. private Button button1;
  19.  
  20. private TextBox textBox1;
  21.  
  22. private TextBox textBox2;
  23.  
  24. private Label label1;
  25.  
  26. private TextBox textBox3;
  27.  
  28. private Label label2;
  29.  
  30. private Label label3;
  31.  
  32. private Label label4;
  33.  
  34. public Form1()
  35. {
  36. InitializeComponent();
  37. }
  38.  
  39. [DllImport("kernel32.dll")]
  40. public static extern int OpenProcess(uint dwDesiredAccess, bool bInheritHandle, int dwProcessId);
  41.  
  42. [DllImport("kernel32")]
  43. public static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, UIntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, out IntPtr lpThreadId);
  44.  
  45. [DllImport("kernel32.dll")]
  46. public static extern IntPtr OpenProcess(uint dwDesiredAccess, int bInheritHandle, int dwProcessId);
  47.  
  48. [DllImport("kernel32.dll")]
  49. public static extern int CloseHandle(IntPtr hObject);
  50.  
  51. [DllImport("kernel32.dll", ExactSpelling = true, SetLastError = true)]
  52. private static extern bool VirtualFreeEx(IntPtr hProcess, IntPtr lpAddress, UIntPtr dwSize, uint dwFreeType);
  53.  
  54. [DllImport("kernel32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
  55. public static extern UIntPtr GetProcAddress(IntPtr hModule, string procName);
  56.  
  57. [DllImport("kernel32.dll", ExactSpelling = true, SetLastError = true)]
  58. private static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);
  59.  
  60. [DllImport("kernel32.dll")]
  61. private static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, string lpBuffer, UIntPtr nSize, out IntPtr lpNumberOfBytesWritten);
  62.  
  63. [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
  64. public static extern IntPtr GetModuleHandle(string lpModuleName);
  65.  
  66. [DllImport("kernel32", ExactSpelling = true, SetLastError = true)]
  67. internal static extern int WaitForSingleObject(IntPtr handle, int milliseconds);
  68.  
  69. [DllImport("kernel32.dll")]
  70. public static extern bool ReadProcessMemory(int hProcess, long lpBaseAddress, byte[] buffer, int size, int lpNumberOfBytesRead);
  71.  
  72. [DllImport("kernel32.dll")]
  73. public static extern bool WriteProcessMemory(int hProcess, long lpBaseAddress, byte[] buffer, int size, int lpNumberOfBytesWritten);
  74.  
  75. public int GetProcessId(string proc)
  76. {
  77. Process[] processesByName = Process.GetProcessesByName(proc);
  78. return processesByName[0].Id;
  79. }
  80.  
  81. public static byte[] ReadProcessMemory(long adress, int processSize, int processHandle)
  82. {
  83. byte[] array = new byte[processSize];
  84. ReadProcessMemory(processHandle, adress, array, processSize, 0);
  85. return array;
  86. }
  87.  
  88. public static void WriteProcessMemory(long adress, byte[] processBytes, int processHandle)
  89. {
  90. WriteProcessMemory(processHandle, adress, processBytes, processBytes.Length, 0);
  91. }
  92.  
  93. public static int GetObjectSize(object TestObject)
  94. {
  95. BinaryFormatter binaryFormatter = new BinaryFormatter();
  96. MemoryStream memoryStream = new MemoryStream();
  97. binaryFormatter.Serialize(memoryStream, TestObject);
  98. byte[] array = memoryStream.ToArray();
  99. return array.Length;
  100. }
  101.  
  102. public static string ConvertStringToHex(string asciiString)
  103. {
  104. string text = "";
  105. foreach (char c in asciiString)
  106. {
  107. int num = c;
  108. text += $"{Convert.ToUInt32(num.ToString()):x2}";
  109. }
  110. return text;
  111. }
  112.  
  113. public static byte[] StringToByteArray(string hex)
  114. {
  115. return (from x in Enumerable.Range(0, hex.Length)
  116. where x % 2 == 0
  117. select Convert.ToByte(hex.Substring(x, 2), 16)).ToArray();
  118. }
  119.  
  120. public void InjectDLL(IntPtr hProcess, string strDLLName)
  121. {
  122. int num = strDLLName.Length + 1;
  123. IntPtr intPtr = VirtualAllocEx(hProcess, (IntPtr)null, (uint)num, 12288u, 4u);
  124. WriteProcessMemory(hProcess, intPtr, strDLLName, (UIntPtr)(ulong)num, out IntPtr intPtr2);
  125. UIntPtr procAddress = GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");
  126. bool flag = false;
  127. IntPtr intPtr3 = CreateRemoteThread(hProcess, (IntPtr)null, 0u, procAddress, intPtr, 0u, out intPtr2);
  128. bool flag2 = false;
  129. int num2 = WaitForSingleObject(intPtr3, 10000);
  130. if ((long)num2 == 128 || (long)num2 == 258 || num2 == uint.MaxValue)
  131. {
  132. MessageBox.Show(" hThread [ 2 ] Error! \n ");
  133. bool flag3 = true;
  134. CloseHandle(intPtr3);
  135. }
  136. else
  137. {
  138. Thread.Sleep(1000);
  139. VirtualFreeEx(hProcess, intPtr, (UIntPtr)0uL, 32768u);
  140. bool flag4 = true;
  141. CloseHandle(intPtr3);
  142. }
  143. }
  144.  
  145. private void button1_Click(object sender, EventArgs e)
  146. {
  147. string text = textBox1.Text;
  148. string text2 = textBox2.Text;
  149. try
  150. {
  151. Process.Start("BlackDesert64.exe", (textBox1.Text + "," + textBox2.Text) ?? "");
  152. }
  153. catch
  154. {
  155. MessageBox.Show("Cannot find BlackDesert64.exe, make sure the launcher is in the bin64 folder.", "Error!");
  156. return;
  157. }
  158. Thread.Sleep(1500);
  159. string strDLLName = "steam_api64.dll";
  160. string proc = "BlackDesert64";
  161. int processId = GetProcessId(proc);
  162. if (processId >= 0)
  163. {
  164. IntPtr hProcess = OpenProcess(2035711u, 1, processId);
  165. bool flag = false;
  166. InjectDLL(hProcess, strDLLName);
  167. Thread.Sleep(500);
  168. Process[] processesByName = Process.GetProcessesByName("BlackDesert64");
  169. uint num = 65536u;
  170. uint num2 = 131072u;
  171. uint num3 = 262144u;
  172. uint num4 = 524288u;
  173. uint num5 = 1048576u;
  174. uint num6 = 4095u;
  175. uint dwDesiredAccess = num | num2 | num3 | num4 | num5 | num6;
  176. int processHandle = OpenProcess(dwDesiredAccess, false, processesByName[0].Id);
  177. IntPtr baseAddress = processesByName[0].MainModule.BaseAddress;
  178. ReadProcessMemory(baseAddress.ToInt64() + 43055736, 11, processHandle);
  179. if (textBox3.Text == null)
  180. {
  181. string hex = ConvertStringToHex("127.0.0.1");
  182. baseAddress = processesByName[0].MainModule.BaseAddress;
  183. WriteProcessMemory(baseAddress.ToInt64() + 43055736, StringToByteArray(hex), processHandle);
  184. }
  185. else
  186. {
  187. string hex2 = ConvertStringToHex(textBox3.Text);
  188. baseAddress = processesByName[0].MainModule.BaseAddress;
  189. WriteProcessMemory(baseAddress.ToInt64() + 43055736, StringToByteArray(hex2), processHandle);
  190. }
  191. }
  192. Application.Exit();
  193. }
  194.  
  195. protected override void Dispose(bool disposing)
  196. {
  197. if (disposing && components != null)
  198. {
  199. components.Dispose();
  200. }
  201. base.Dispose(disposing);
  202. }
  203.  
  204. private void InitializeComponent()
  205. {
  206. this.button1 = new System.Windows.Forms.Button();
  207. this.textBox1 = new System.Windows.Forms.TextBox();
  208. this.textBox2 = new System.Windows.Forms.TextBox();
  209. this.label1 = new System.Windows.Forms.Label();
  210. this.textBox3 = new System.Windows.Forms.TextBox();
  211. this.label2 = new System.Windows.Forms.Label();
  212. this.label3 = new System.Windows.Forms.Label();
  213. this.label4 = new System.Windows.Forms.Label();
  214. this.SuspendLayout();
  215. //
  216. // button1
  217. //
  218. this.button1.Location = new System.Drawing.Point(19, 122);
  219. this.button1.Name = "button1";
  220. this.button1.Size = new System.Drawing.Size(75, 23);
  221. this.button1.TabIndex = 0;
  222. this.button1.Text = "Start Game";
  223. this.button1.UseVisualStyleBackColor = true;
  224. this.button1.Click += new System.EventHandler(this.button1_Click_1);
  225. //
  226. // textBox1
  227. //
  228. this.textBox1.Location = new System.Drawing.Point(76, 29);
  229. this.textBox1.Name = "textBox1";
  230. this.textBox1.Size = new System.Drawing.Size(100, 20);
  231. this.textBox1.TabIndex = 1;
  232. //
  233. // textBox2
  234. //
  235. this.textBox2.Location = new System.Drawing.Point(76, 55);
  236. this.textBox2.Name = "textBox2";
  237. this.textBox2.Size = new System.Drawing.Size(100, 20);
  238. this.textBox2.TabIndex = 2;
  239. //
  240. // label1
  241. //
  242. this.label1.AutoSize = true;
  243. this.label1.Location = new System.Drawing.Point(18, 32);
  244. this.label1.Name = "label1";
  245. this.label1.Size = new System.Drawing.Size(58, 13);
  246. this.label1.TabIndex = 3;
  247. this.label1.Text = "Username:";
  248. this.label1.Click += new System.EventHandler(this.label1_Click);
  249. //
  250. // textBox3
  251. //
  252. this.textBox3.Location = new System.Drawing.Point(76, 96);
  253. this.textBox3.Name = "textBox3";
  254. this.textBox3.Size = new System.Drawing.Size(100, 20);
  255. this.textBox3.TabIndex = 4;
  256. //
  257. // label2
  258. //
  259. this.label2.AutoSize = true;
  260. this.label2.Location = new System.Drawing.Point(18, 99);
  261. this.label2.Name = "label2";
  262. this.label2.Size = new System.Drawing.Size(54, 13);
  263. this.label2.TabIndex = 5;
  264. this.label2.Text = "Server IP:";
  265. //
  266. // label3
  267. //
  268. this.label3.AutoSize = true;
  269. this.label3.Location = new System.Drawing.Point(18, 58);
  270. this.label3.Name = "label3";
  271. this.label3.Size = new System.Drawing.Size(56, 13);
  272. this.label3.TabIndex = 6;
  273. this.label3.Text = "Password:";
  274. //
  275. // label4
  276. //
  277. this.label4.AutoSize = true;
  278. this.label4.Location = new System.Drawing.Point(43, 9);
  279. this.label4.Name = "label4";
  280. this.label4.Size = new System.Drawing.Size(124, 13);
  281. this.label4.TabIndex = 7;
  282. this.label4.Text = "bdoEmu - Test Launcher";
  283. //
  284. // Form1
  285. //
  286. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
  287. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  288. this.ClientSize = new System.Drawing.Size(496, 218);
  289. this.Controls.Add(this.label4);
  290. this.Controls.Add(this.label3);
  291. this.Controls.Add(this.label2);
  292. this.Controls.Add(this.textBox3);
  293. this.Controls.Add(this.label1);
  294. this.Controls.Add(this.textBox2);
  295. this.Controls.Add(this.textBox1);
  296. this.Controls.Add(this.button1);
  297. this.Name = "Form1";
  298. this.Text = "bdoEmu";
  299. this.ResumeLayout(false);
  300. this.PerformLayout();
  301.  
  302. }
  303.  
  304. private void label1_Click(object sender, EventArgs e)
  305. {
  306.  
  307. }
  308.  
  309. private void button1_Click_1(object sender, EventArgs e)
  310. {
  311.  
  312. }
  313. }
  314. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement