Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 38.14 KB | None | 0 0
  1. // Decompiled with JetBrains decompiler
  2. // Type: Replacement_Launcher.Form1
  3. // Assembly: Replacement Launcher, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
  4. // MVID: C076B7EB-FF47-4A35-99E6-90CB4ED145F4
  5. // Assembly location: C:\Users\Michele\Downloads\Replacement_Launcher_1\Replacement_Launcher (1).exe
  6.  
  7. using Microsoft.Win32;
  8. using Mono.Math;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.ComponentModel;
  12. using System.Configuration;
  13. using System.Diagnostics;
  14. using System.Drawing;
  15. using System.IO;
  16. using System.Net;
  17. using System.Net.Sockets;
  18. using System.Security.Cryptography;
  19. using System.Text;
  20. using System.Text.RegularExpressions;
  21. using System.Web.Security;
  22. using System.Windows.Forms;
  23. using System.Xml;
  24.  
  25. namespace Replacement_Launcher
  26. {
  27. public class Form1 : Form
  28. {
  29. public static BigInteger N = new BigInteger("E306EBC02F1DC69F5B437683FE3851FD9AAA6E97F4CBD42FC06C72053CBCED68EC570E6666F529C58518CF7B299B5582495DB169ADF48ECEB6D65461B4D7C75DD1DA89601D5C498EE48BB950E2D8D5E0E0C692D613483B38D381EA9674DF74D67665259C4C31A29E0B3CFF7587617260E8C58FFA0AF8339CD68DB3ADB90AAFEE");
  30. public static BigInteger P = new BigInteger("7A39FF57BCBFAA521DCE9C7DEFAB520640AC493E1B6024B95A28390E8F05787D");
  31. public static byte[] staticKey = Conversions.HexStr2Bytes("AC34F3070DC0E52302C2E8DA0E3F7B3E63223697555DF54E7122A14DBC99A3E8");
  32. public static BigInteger Two = new BigInteger(2U);
  33. private string args = "/launchbylauncher /sesskey -lang:english /CompanyID:\"12\" /ChannelGroupIndex:\"-1\" /AuthnToken:\"{0}\" /AuthProviderCode:\"np\" -lang:English -lite:2 -region:{1}{2}{3}{4}";
  34. private string Protect = "Basic Enc";
  35. private List<Form1.region> regions = new List<Form1.region>();
  36. private BigInteger exchangeKey = Form1.Two;
  37. private SHA256 sha = SHA256.Create();
  38. private bool Debugging;
  39. private BackgroundWorker worker;
  40. private string username;
  41. private string password;
  42. private string epoch;
  43. private string pid;
  44. private string localIP;
  45. private string token;
  46. private string clientPath;
  47. private string LoginIp;
  48. private string LoginProgramid;
  49. private int LoginPort;
  50. private int counter;
  51. private Form1.BNSXorEncryption xor;
  52. private string currentAppId;
  53. private string currentValue;
  54. private BigInteger privateKey;
  55. private BigInteger exchangeKeyServer;
  56. private BigInteger session;
  57. private BigInteger validate;
  58. private byte[] key;
  59. private TcpClient LoginServer;
  60. private IContainer components;
  61. private TextBox usernameTB;
  62. private TextBox passwordTB;
  63. private Button button1;
  64. private Label label1;
  65. private Label label2;
  66. private Button button2;
  67. private Label label3;
  68. private ComboBox RegionCB;
  69. private CheckBox use64;
  70. private CheckBox disableText;
  71. private CheckBox unattended;
  72. private CheckBox allCpu;
  73.  
  74. public Form1()
  75. {
  76. this.InitializeComponent();
  77. }
  78.  
  79. private BigInteger GetKeyExchange()
  80. {
  81. if (BigInteger.op_Equality(this.exchangeKey, Form1.Two))
  82. this.exchangeKey = Form1.Two.modPow(this.privateKey, Form1.N);
  83. return this.exchangeKey;
  84. }
  85.  
  86. private BigInteger SHA256Hash2ArrayInverse(byte[] tmp1, byte[] tmp2)
  87. {
  88. byte[] buffer = new byte[tmp1.Length + tmp2.Length];
  89. tmp1.CopyTo((Array) buffer, 0);
  90. tmp2.CopyTo((Array) buffer, tmp1.Length);
  91. return new BigInteger(this.IntegerReverse(this.sha.ComputeHash(buffer)));
  92. }
  93.  
  94. private unsafe byte[] IntegerReverse(byte[] buf)
  95. {
  96. byte[] numArray = new byte[buf.Length];
  97. for (int index = 0; index < numArray.Length / 4; ++index)
  98. {
  99. fixed (byte* numPtr1 = buf)
  100. fixed (byte* numPtr2 = numArray)
  101. {
  102. int* numPtr3 = (int*) numPtr1;
  103. *(int*) (numPtr2 + ((IntPtr) index * 4).ToInt64()) = numPtr3[numArray.Length / 4 - 1 - index];
  104. }
  105. }
  106. return numArray;
  107. }
  108.  
  109. private byte[] GenerateEncryptionKeyRoot(byte[] src)
  110. {
  111. int length = src.Length;
  112. int index1 = 0;
  113. byte[] numArray = new byte[64];
  114. if (src.Length > 4)
  115. {
  116. while (src[index1] != (byte) 0)
  117. {
  118. --length;
  119. ++index1;
  120. if (length <= 4)
  121. break;
  122. }
  123. }
  124. int count = length >> 1;
  125. byte[] buffer = new byte[count];
  126. if (count > 0)
  127. {
  128. int index2 = index1 + length - 1;
  129. for (int index3 = 0; index3 < count; ++index3)
  130. {
  131. buffer[index3] = src[index2];
  132. index2 -= 2;
  133. }
  134. }
  135. byte[] hash1 = this.sha.ComputeHash(buffer, 0, count);
  136. for (int index2 = 0; index2 < 32; ++index2)
  137. numArray[2 * index2] = hash1[index2];
  138. if (count > 0)
  139. {
  140. int index2 = index1 + length - 2;
  141. for (int index3 = 0; index3 < count; ++index3)
  142. {
  143. buffer[index3] = src[index2];
  144. index2 -= 2;
  145. }
  146. }
  147. byte[] hash2 = this.sha.ComputeHash(buffer, 0, count);
  148. for (int index2 = 0; index2 < 32; ++index2)
  149. numArray[2 * index2 + 1] = hash2[index2];
  150. return numArray;
  151. }
  152.  
  153. private byte[] CombineBuffers(params byte[][] buffers)
  154. {
  155. int length = 0;
  156. foreach (byte[] buffer in buffers)
  157. length += buffer.Length;
  158. byte[] numArray = new byte[length];
  159. int index = 0;
  160. foreach (byte[] buffer in buffers)
  161. {
  162. buffer.CopyTo((Array) numArray, index);
  163. index += buffer.Length;
  164. }
  165. return numArray;
  166. }
  167.  
  168. private byte[] Generate256BytesKey(byte[] src)
  169. {
  170. int index1 = 1;
  171. byte[] numArray = new byte[256];
  172. for (int index2 = 0; index2 < 256; ++index2)
  173. numArray[index2] = (byte) index2;
  174. int index3 = 0;
  175. int index4 = 0;
  176. for (int index2 = 64; index2 > 0; --index2)
  177. {
  178. int index5 = index3 + (int) src[index4] + (int) numArray[index1 - 1] & (int) byte.MaxValue;
  179. int num1 = (int) numArray[index1 - 1];
  180. numArray[index1 - 1] = numArray[index5];
  181. int index6 = index4 + 1;
  182. numArray[index5] = (byte) num1;
  183. if (index6 == src.Length)
  184. index6 = 0;
  185. int num2 = index5 + (int) src[index6];
  186. int index7 = index6 + 1;
  187. int num3 = num2 + (int) numArray[index1];
  188. int num4 = (int) numArray[index1];
  189. int index8 = (int) (byte) num3;
  190. numArray[index1] = numArray[index8];
  191. numArray[index8] = (byte) num4;
  192. if (index7 == src.Length)
  193. index7 = 0;
  194. int index9 = index8 + (int) src[index7] + (int) numArray[index1 + 1] & (int) byte.MaxValue;
  195. int num5 = (int) numArray[index1 + 1];
  196. numArray[index1 + 1] = numArray[index9];
  197. int index10 = index7 + 1;
  198. numArray[index9] = (byte) num5;
  199. if (index10 == src.Length)
  200. index10 = 0;
  201. int num6 = index9 + (int) src[index10];
  202. int num7 = (int) numArray[index1 + 2];
  203. index3 = num6 + (int) numArray[index1 + 2] & (int) byte.MaxValue;
  204. index4 = index10 + 1;
  205. numArray[index1 + 2] = numArray[index3];
  206. numArray[index3] = (byte) num7;
  207. if (index4 == src.Length)
  208. index4 = 0;
  209. index1 += 4;
  210. }
  211. return numArray;
  212. }
  213.  
  214. public byte[][] GenerateKeyClient(BigInteger exchangeKey)
  215. {
  216. byte[] hash1 = this.sha.ComputeHash(Encoding.UTF8.GetBytes(this.username + ":" + this.password));
  217. BigInteger bigInteger1 = this.SHA256Hash2ArrayInverse(this.GetKeyExchange().getBytes(), exchangeKey.getBytes());
  218. BigInteger bigInteger2 = this.SHA256Hash2ArrayInverse(this.session.getBytes(), hash1);
  219. BigInteger bigInteger3 = new BigInteger(exchangeKey.getBytes());
  220. BigInteger bigInteger4 = BigInteger.op_Modulus(BigInteger.op_Multiply(Form1.Two.modPow(bigInteger2, Form1.N), Form1.P), Form1.N);
  221. while (BigInteger.op_LessThan(bigInteger3, bigInteger4))
  222. bigInteger3 = BigInteger.op_Addition(bigInteger3, Form1.N);
  223. this.key = this.GenerateEncryptionKeyRoot(BigInteger.op_Subtraction(bigInteger3, bigInteger4).modPow(BigInteger.op_Modulus(BigInteger.op_Addition(BigInteger.op_Multiply(bigInteger1, bigInteger2), this.privateKey), Form1.N), Form1.N).getBytes());
  224. byte[] hash2 = this.sha.ComputeHash(this.CombineBuffers(Form1.staticKey, this.sha.ComputeHash(Encoding.ASCII.GetBytes(this.username)), this.session.getBytes(), this.GetKeyExchange().getBytes(), exchangeKey.getBytes(), this.key));
  225. byte[] hash3 = this.sha.ComputeHash(this.CombineBuffers(this.GetKeyExchange().getBytes(), hash2, this.key));
  226. this.key = this.Generate256BytesKey(this.key);
  227. return new byte[2][]{ hash2, hash3 };
  228. }
  229.  
  230. private bool LauncherInfo()
  231. {
  232. try
  233. {
  234. string hostname = "updater.nclauncher.ncsoft.com";
  235. string s = "BnS";
  236. int port = 27500;
  237. MemoryStream memoryStream1 = new MemoryStream();
  238. BinaryWriter binaryWriter = new BinaryWriter((Stream) memoryStream1);
  239. binaryWriter.Write((short) 0);
  240. binaryWriter.Write((short) 4);
  241. binaryWriter.Write((byte) 10);
  242. binaryWriter.Write((byte) s.Length);
  243. binaryWriter.Write(Encoding.ASCII.GetBytes(s));
  244. binaryWriter.BaseStream.Position = 0L;
  245. binaryWriter.Write((short) memoryStream1.Length);
  246. NetworkStream stream = new TcpClient(hostname, port).GetStream();
  247. stream.Write(memoryStream1.ToArray(), 0, (int) memoryStream1.Length);
  248. binaryWriter.Close();
  249. memoryStream1.Close();
  250. MemoryStream memoryStream2 = new MemoryStream();
  251. BinaryReader binaryReader = new BinaryReader((Stream) memoryStream2);
  252. byte[] buffer = new byte[1024];
  253. int count;
  254. do
  255. {
  256. count = stream.Read(buffer, 0, buffer.Length);
  257. if (count > 0)
  258. memoryStream2.Write(buffer, 0, count);
  259. }
  260. while (count == buffer.Length);
  261. memoryStream2.Position = 9L;
  262. binaryReader.ReadBytes((int) binaryReader.ReadByte() + 1);
  263. bool flag = binaryReader.ReadBoolean();
  264. stream.Close();
  265. binaryReader.Close();
  266. memoryStream2.Close();
  267. if (!flag)
  268. {
  269. if (!this.Debugging)
  270. {
  271. int num = (int) MessageBox.Show("The Game Server is currently in Maintentance, please try again later.");
  272. return false;
  273. }
  274. }
  275. }
  276. catch
  277. {
  278. int num = (int) MessageBox.Show("There was an error connecting to the Login Server, please make sure there isn't a maintenance.");
  279. return false;
  280. }
  281. try
  282. {
  283. string hostname = "updater.nclauncher.ncsoft.com";
  284. string s = "BnS";
  285. int port = 27500;
  286. MemoryStream memoryStream1 = new MemoryStream();
  287. BinaryWriter binaryWriter = new BinaryWriter((Stream) memoryStream1);
  288. binaryWriter.Write((short) 0);
  289. binaryWriter.Write((short) 8);
  290. binaryWriter.Write((byte) 10);
  291. binaryWriter.Write((byte) s.Length);
  292. binaryWriter.Write(Encoding.ASCII.GetBytes(s));
  293. binaryWriter.BaseStream.Position = 0L;
  294. binaryWriter.Write((short) memoryStream1.Length);
  295. TcpClient tcpClient = new TcpClient(hostname, port);
  296. this.localIP = ((IPEndPoint) tcpClient.Client.LocalEndPoint).Address.ToString();
  297. NetworkStream stream = tcpClient.GetStream();
  298. stream.Write(memoryStream1.ToArray(), 0, (int) memoryStream1.Length);
  299. binaryWriter.Close();
  300. memoryStream1.Close();
  301. MemoryStream memoryStream2 = new MemoryStream();
  302. BinaryReader binaryReader = new BinaryReader((Stream) memoryStream2);
  303. byte[] buffer = new byte[1024];
  304. int count;
  305. do
  306. {
  307. count = stream.Read(buffer, 0, buffer.Length);
  308. if (count > 0)
  309. memoryStream2.Write(buffer, 0, count);
  310. }
  311. while (count == buffer.Length);
  312. memoryStream2.Position = 9L;
  313. binaryReader.ReadBytes((int) binaryReader.ReadByte() + 1);
  314. string str1 = Encoding.UTF8.GetString(binaryReader.ReadBytes((int) binaryReader.ReadByte() + 128 * ((int) binaryReader.ReadByte() - 1)));
  315. stream.Close();
  316. binaryReader.Close();
  317. memoryStream2.Close();
  318. string str2 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<Settings>" + str1.Replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "").Replace(" ", "\r\n") + "\r\n</Settings>";
  319. this.LoginIp = Regex.Match(str2, "ip=\"([^\"]*)\"", RegexOptions.IgnoreCase).Groups[1].Value;
  320. this.LoginPort = int.Parse(Regex.Match(str2, "port=\"([^\"]*)\"", RegexOptions.IgnoreCase).Groups[1].Value);
  321. this.LoginProgramid = Regex.Match(str2, "programid=\"([^\"]*)\"", RegexOptions.IgnoreCase).Groups[1].Value;
  322. XmlDocument xmlDocument = new XmlDocument();
  323. xmlDocument.LoadXml(str2);
  324. foreach (XmlElement selectNode in xmlDocument.SelectNodes("//region"))
  325. this.regions.Add(new Form1.region(selectNode.Attributes["name"].Value, selectNode.Attributes["value"].Value, selectNode.Attributes["appid"].Value));
  326. }
  327. catch (Exception ex)
  328. {
  329. int num1 = (int) MessageBox.Show("There was an error connecting to the Login Server, please make sure there isn't a maintenance.");
  330. if (this.Debugging)
  331. {
  332. int num2 = (int) MessageBox.Show(ex.ToString());
  333. }
  334. return false;
  335. }
  336. return true;
  337. }
  338.  
  339. private void button1_Click(object sender, EventArgs e)
  340. {
  341. this.button2.Enabled = false;
  342. if (this.worker != null && this.worker.IsBusy)
  343. {
  344. this.LoginServer.Close();
  345. this.worker.CancelAsync();
  346. }
  347. this.currentAppId = ((Form1.region) this.RegionCB.SelectedValue).appId;
  348. this.currentValue = ((Form1.region) this.RegionCB.SelectedValue).value;
  349. this.epoch = ((long) (DateTime.UtcNow - new DateTime(2001, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds).ToString();
  350. this.username = this.usernameTB.Text.ToLower();
  351. this.password = this.passwordTB.Text;
  352. this.pid = Process.GetCurrentProcess().Id.ToString();
  353. this.privateKey = new BigInteger(this.sha.ComputeHash(BigInteger.genRandom(6).getBytes()));
  354. this.exchangeKey = Form1.Two;
  355. this.counter = 0;
  356. this.worker = new BackgroundWorker();
  357. this.worker.WorkerSupportsCancellation = true;
  358. this.worker.DoWork += new DoWorkEventHandler(this.Try_Connection);
  359. this.worker.RunWorkerAsync();
  360. }
  361.  
  362. private string Builder(string nameSpace, string function)
  363. {
  364. ++this.counter;
  365. switch (nameSpace)
  366. {
  367. case "Sts":
  368. switch (function)
  369. {
  370. case "Connect":
  371. string str1 = string.Format("<Connect>\n<ConnType>400</ConnType>\n<Address>{0}</Address>\n<ProductType>0</ProductType>\n<AppIndex>1</AppIndex>\n<Epoch>{1}</Epoch>\n<Program>{2}</Program>\n<Build>1001</Build>\n<Process>{3}</Process>\n</Connect>\n", (object) this.localIP, (object) this.epoch, (object) this.LoginProgramid, (object) this.pid);
  372. return string.Format("POST /Sts/Connect STS/1.0\r\nl:{0}\r\n\r\n{1}", (object) str1.Length, (object) str1);
  373. case "Ping":
  374. return "POST /Sts/Ping STS/1.0\r\nl:0\r\n\r\n";
  375. }
  376. case "Auth":
  377. switch (function)
  378. {
  379. case "LoginStart":
  380. string str2 = string.Format("<Request>\n<LoginName>{0}</LoginName>\n</Request>\n", (object) this.username);
  381. return string.Format("POST /Auth/LoginStart STS/1.0\r\ns:{4}\r\np:*{0} 0 1 0 {1}\r\nl:{2}\r\n\r\n{3}", (object) this.localIP, (object) this.epoch, (object) str2.Length, (object) str2, (object) this.counter);
  382. case "KeyData":
  383. byte[][] keyClient = this.GenerateKeyClient(this.exchangeKeyServer);
  384. MemoryStream memoryStream = new MemoryStream();
  385. BinaryWriter binaryWriter = new BinaryWriter((Stream) memoryStream);
  386. binaryWriter.Write(this.exchangeKey.getBytes().Length);
  387. binaryWriter.Write(this.exchangeKey.getBytes());
  388. binaryWriter.Write(keyClient[0].Length);
  389. binaryWriter.Write(keyClient[0]);
  390. this.validate = new BigInteger(keyClient[1]);
  391. string str3 = string.Format("<Request>\n<KeyData>{0}</KeyData>\n</Request>\n", (object) Convert.ToBase64String(memoryStream.ToArray()));
  392. binaryWriter.Close();
  393. memoryStream.Close();
  394. return string.Format("POST /Auth/KeyData STS/1.0\r\ns:{4}\r\np:*{0} 0 1 0 {1}\r\nl:{2}\r\n\r\n{3}", (object) this.localIP, (object) this.epoch, (object) str3.Length, (object) str3, (object) this.counter);
  395. case "LoginFinish":
  396. string str4 = "<Request>\n<Language>1</Language>\n</Request>\n";
  397. return string.Format("POST /Auth/LoginFinish STS/1.0\r\ns:{2}\r\nl:{0}\r\n\r\n{1}", (object) str4.Length, (object) str4, (object) this.counter);
  398. case "RequestToken":
  399. string str5 = string.Format("<Request>\n<AppId>{0}</AppId>\n</Request>\n", (object) this.currentAppId);
  400. return string.Format("POST /Auth/RequestToken STS/1.0\r\ns:{2}\r\nl:{0}\r\n\r\n{1}", (object) str5.Length, (object) str5, (object) this.counter);
  401. }
  402. }
  403. return (string) null;
  404. }
  405.  
  406. private void Try_Connection(object sender, DoWorkEventArgs e)
  407. {
  408. try
  409. {
  410. this.LoginServer = new TcpClient(this.LoginIp, this.LoginPort);
  411. this.LoginServer.ReceiveBufferSize = 1024;
  412. NetworkStream stream = this.LoginServer.GetStream();
  413. stream.ReadTimeout = 60000;
  414. stream.ReadTimeout = 60000;
  415. DateTime now = DateTime.Now;
  416. int num1 = 30;
  417. string s1 = this.Builder("Sts", "Connect");
  418. stream.Write(Encoding.ASCII.GetBytes(s1), 0, s1.Length);
  419. string s2 = this.Builder("Auth", "LoginStart");
  420. stream.Write(Encoding.ASCII.GetBytes(s2), 0, s2.Length);
  421. MemoryStream memoryStream1 = new MemoryStream();
  422. byte[] buffer1 = new byte[1024];
  423. int count1;
  424. do
  425. {
  426. count1 = stream.Read(buffer1, 0, buffer1.Length);
  427. if (count1 > 0)
  428. memoryStream1.Write(buffer1, 0, count1);
  429. }
  430. while (count1 == buffer1.Length);
  431. switch (Encoding.ASCII.GetString(memoryStream1.ToArray()).Split('\r')[0].Split(' ')[2])
  432. {
  433. case "OK":
  434. memoryStream1.Close();
  435. MemoryStream memoryStream2 = new MemoryStream();
  436. int count2;
  437. do
  438. {
  439. count2 = stream.Read(buffer1, 0, buffer1.Length);
  440. if (count2 > 0)
  441. memoryStream2.Write(buffer1, 0, count2);
  442. }
  443. while (count2 == buffer1.Length);
  444. string input1 = Encoding.ASCII.GetString(memoryStream2.ToArray());
  445. memoryStream2.Close();
  446. MemoryStream memoryStream3 = new MemoryStream(Convert.FromBase64String(Regex.Match(input1, "<KeyData>([^<]*)</KeyData>", RegexOptions.IgnoreCase).Groups[1].Value));
  447. BinaryReader binaryReader1 = new BinaryReader((Stream) memoryStream3);
  448. this.session = new BigInteger(binaryReader1.ReadBytes(binaryReader1.ReadInt32()));
  449. this.exchangeKeyServer = new BigInteger(binaryReader1.ReadBytes(binaryReader1.ReadInt32()));
  450. binaryReader1.Close();
  451. memoryStream3.Close();
  452. string s3 = this.Builder("Auth", "KeyData");
  453. stream.Write(Encoding.ASCII.GetBytes(s3), 0, s3.Length);
  454. MemoryStream memoryStream4 = new MemoryStream();
  455. int count3;
  456. do
  457. {
  458. count3 = stream.Read(buffer1, 0, buffer1.Length);
  459. if (count3 > 0)
  460. memoryStream4.Write(buffer1, 0, count3);
  461. }
  462. while (count3 == buffer1.Length);
  463. string str = Encoding.ASCII.GetString(memoryStream4.ToArray()).Split('\r')[0].Split(' ')[2];
  464. switch (str)
  465. {
  466. case "OK":
  467. memoryStream4.Close();
  468. MemoryStream memoryStream5 = new MemoryStream();
  469. int count4;
  470. do
  471. {
  472. count4 = stream.Read(buffer1, 0, buffer1.Length);
  473. if (count4 > 0)
  474. memoryStream5.Write(buffer1, 0, count4);
  475. }
  476. while (count4 == buffer1.Length);
  477. string input2 = Encoding.ASCII.GetString(memoryStream5.ToArray());
  478. memoryStream5.Close();
  479. BinaryReader binaryReader2 = new BinaryReader((Stream) new MemoryStream(Convert.FromBase64String(Regex.Match(input2, "<KeyData>([^<]*)</KeyData>", RegexOptions.IgnoreCase).Groups[1].Value)));
  480. if (BigInteger.op_Equality(new BigInteger(binaryReader2.ReadBytes(binaryReader2.ReadInt32())), this.validate))
  481. {
  482. this.xor = new Form1.BNSXorEncryption(this.key);
  483. byte[] bytes1 = Encoding.ASCII.GetBytes(this.Builder("Auth", "LoginFinish"));
  484. byte[] buffer2 = this.xor.Encrypt(bytes1, 0, bytes1.Length);
  485. stream.Write(buffer2, 0, buffer2.Length);
  486. byte[] buffer3 = new byte[1024];
  487. MemoryStream memoryStream6 = new MemoryStream();
  488. int count5;
  489. do
  490. {
  491. count5 = stream.Read(buffer3, 0, buffer3.Length);
  492. if (count5 > 0)
  493. memoryStream6.Write(buffer3, 0, count5);
  494. }
  495. while (count5 == buffer3.Length);
  496. byte[] array1 = memoryStream6.ToArray();
  497. string text = Encoding.ASCII.GetString(this.xor.Decrypt(array1, 0, array1.Length));
  498. if (this.Debugging)
  499. {
  500. int num2 = (int) MessageBox.Show(text);
  501. }
  502. if (text.Contains("<AuthType>8</AuthType>"))
  503. {
  504. int num3 = (int) MessageBox.Show("This launcher doesn't support IP Verification, please do so on the website or official launcher then try again");
  505. return;
  506. }
  507. memoryStream6.Close();
  508. byte[] buffer4 = new byte[1024];
  509. MemoryStream memoryStream7 = new MemoryStream();
  510. int count6;
  511. do
  512. {
  513. count6 = stream.Read(buffer4, 0, buffer4.Length);
  514. if (count6 > 0)
  515. memoryStream7.Write(buffer4, 0, count6);
  516. }
  517. while (count6 == buffer4.Length);
  518. byte[] array2 = memoryStream7.ToArray();
  519. byte[] bytes2 = this.xor.Decrypt(array2, 0, array2.Length);
  520. if (this.Debugging)
  521. {
  522. int num4 = (int) MessageBox.Show(Encoding.ASCII.GetString(bytes2));
  523. }
  524. memoryStream7.Close();
  525. byte[] bytes3 = Encoding.ASCII.GetBytes(this.Builder("Auth", "RequestToken"));
  526. byte[] buffer5 = this.xor.Encrypt(bytes3, 0, bytes3.Length);
  527. stream.Write(buffer5, 0, buffer5.Length);
  528. byte[] buffer6 = new byte[1024];
  529. MemoryStream memoryStream8 = new MemoryStream();
  530. int count7;
  531. do
  532. {
  533. count7 = stream.Read(buffer6, 0, buffer6.Length);
  534. if (count7 > 0)
  535. memoryStream8.Write(buffer6, 0, count7);
  536. }
  537. while (count7 == buffer6.Length);
  538. byte[] array3 = memoryStream8.ToArray();
  539. byte[] bytes4 = this.xor.Decrypt(array3, 0, array3.Length);
  540. memoryStream8.Close();
  541. this.token = Regex.Match(Encoding.ASCII.GetString(bytes4), "<AuthnToken>([^<]*)</AuthnToken>", RegexOptions.IgnoreCase).Groups[1].Value;
  542. this.Invoke((Delegate) new Action<bool>(this.login_enable), (object) true);
  543. }
  544. else
  545. {
  546. int num2 = (int) MessageBox.Show("Negotiation Failed, please try again.");
  547. this.key = (byte[]) null;
  548. }
  549. while (this.LoginServer.Connected)
  550. {
  551. if (DateTime.Now >= now.AddSeconds((double) num1))
  552. {
  553. byte[] numArray = Encoding.ASCII.GetBytes(this.Builder("Sts", "Ping"));
  554. if (this.key != null)
  555. numArray = this.xor.Encrypt(numArray, 0, numArray.Length);
  556. stream.Write(numArray, 0, numArray.Length);
  557. now = DateTime.Now;
  558. }
  559. }
  560. return;
  561. case "ErrBadPasswd":
  562. int num5 = (int) MessageBox.Show("Wrong Password");
  563. return;
  564. case "ErrRiskMgmtDeclined":
  565. int num6 = (int) MessageBox.Show("You have exceeded the number of attempts allowed.\r\nFor security reasons, login is temporarily disabled.\r\nPlease try again later.");
  566. return;
  567. default:
  568. int num7 = (int) MessageBox.Show("Unknown Error: " + str);
  569. return;
  570. }
  571. case "ErrAccountNotFound":
  572. int num8 = (int) MessageBox.Show("The provided email address wasn't found");
  573. break;
  574. default:
  575. int num9 = (int) MessageBox.Show("Invalidly formated email");
  576. break;
  577. }
  578. }
  579. catch (Exception ex)
  580. {
  581. int num1 = (int) MessageBox.Show("Unknown Network Error");
  582. if (!this.Debugging)
  583. return;
  584. int num2 = (int) MessageBox.Show(ex.ToString());
  585. }
  586. }
  587.  
  588. private void login_enable(bool yes)
  589. {
  590. this.button2.Enabled = yes;
  591. }
  592.  
  593. private void button2_Click(object sender, EventArgs e)
  594. {
  595. string fileName = this.clientPath + (this.use64.Checked ? "\\bin64\\client.exe" : "\\bin\\client.exe");
  596. new Process()
  597. {
  598. StartInfo = new ProcessStartInfo()
  599. {
  600. FileName = fileName,
  601. WorkingDirectory = new FileInfo(fileName).Directory.ToString(),
  602. Arguments = string.Format(this.args, (object) this.token, (object) this.currentValue, this.disableText.Checked ? (object) " -NOTEXTURESTREAMING" : (object) "", this.allCpu.Checked ? (object) " -USEALLAVAILABLECORES " : (object) "", this.unattended.Checked ? (object) " -UNATTENDED " : (object) "")
  603. }
  604. }.Start();
  605. if (this.worker != null && this.worker.IsBusy)
  606. {
  607. this.LoginServer.Close();
  608. this.worker.CancelAsync();
  609. }
  610. this.button2.Enabled = false;
  611. }
  612.  
  613. private bool findInstall()
  614. {
  615. this.clientPath = (string) Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\NCWest\\BnS", "BaseDir", (object) "");
  616. return !string.IsNullOrWhiteSpace(this.clientPath);
  617. }
  618.  
  619. private void Form1_Load(object sender, EventArgs e)
  620. {
  621. try
  622. {
  623. if (ConfigurationManager.AppSettings["Username"] != null)
  624. this.usernameTB.Text = this.Dec(ConfigurationManager.AppSettings["Username"]);
  625. if (ConfigurationManager.AppSettings["Password"] != null)
  626. this.passwordTB.Text = this.Dec(ConfigurationManager.AppSettings["Password"]);
  627. }
  628. catch
  629. {
  630. }
  631. if (ConfigurationManager.AppSettings["Use64Bit"] != null)
  632. this.use64.Checked = ConfigurationManager.AppSettings["Use64Bit"].Equals("1");
  633. if (ConfigurationManager.AppSettings["DisableTextureStreaming"] != null)
  634. this.disableText.Checked = ConfigurationManager.AppSettings["DisableTextureStreaming"].Equals("1");
  635. if (ConfigurationManager.AppSettings["UseAllCPU"] != null)
  636. this.allCpu.Checked = ConfigurationManager.AppSettings["UseAllCPU"].Equals("1");
  637. if (ConfigurationManager.AppSettings["DisablePopUps"] != null)
  638. this.unattended.Checked = ConfigurationManager.AppSettings["DisablePopUps"].Equals("1");
  639. if (ConfigurationManager.AppSettings["Debug"] != null)
  640. this.Debugging = ConfigurationManager.AppSettings["Debug"].Equals("1");
  641. if (!this.LauncherInfo())
  642. this.Close();
  643. if (!this.findInstall())
  644. this.Close();
  645. this.RegionCB.DataSource = (object) this.regions;
  646. }
  647.  
  648. private string Enc(string s)
  649. {
  650. return Convert.ToBase64String(MachineKey.Protect(Encoding.UTF8.GetBytes(s), this.Protect));
  651. }
  652.  
  653. private string Dec(string s)
  654. {
  655. return Encoding.UTF8.GetString(MachineKey.Unprotect(Convert.FromBase64String(s), this.Protect));
  656. }
  657.  
  658. private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  659. {
  660. System.Configuration.Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  661. if (configuration.AppSettings.Settings["Username"] != null)
  662. configuration.AppSettings.Settings["Username"].Value = this.Enc(this.usernameTB.Text);
  663. else
  664. configuration.AppSettings.Settings.Add("Username", this.Enc(this.usernameTB.Text));
  665. if (configuration.AppSettings.Settings["Password"] != null)
  666. configuration.AppSettings.Settings["Password"].Value = this.Enc(this.passwordTB.Text);
  667. else
  668. configuration.AppSettings.Settings.Add("Password", this.Enc(this.passwordTB.Text));
  669. if (configuration.AppSettings.Settings["Use64Bit"] != null)
  670. configuration.AppSettings.Settings["Use64Bit"].Value = this.use64.Checked ? "1" : "0";
  671. else
  672. configuration.AppSettings.Settings.Add("Use64Bit", this.use64.Checked ? "1" : "0");
  673. if (configuration.AppSettings.Settings["DisableTextureStreaming"] != null)
  674. configuration.AppSettings.Settings["DisableTextureStreaming"].Value = this.disableText.Checked ? "1" : "0";
  675. else
  676. configuration.AppSettings.Settings.Add("DisableTextureStreaming", this.disableText.Checked ? "1" : "0");
  677. if (configuration.AppSettings.Settings["UseAllCPU"] != null)
  678. configuration.AppSettings.Settings["UseAllCPU"].Value = this.allCpu.Checked ? "1" : "0";
  679. else
  680. configuration.AppSettings.Settings.Add("UseAllCPU", this.allCpu.Checked ? "1" : "0");
  681. if (configuration.AppSettings.Settings["DisablePopUps"] != null)
  682. configuration.AppSettings.Settings["DisablePopUps"].Value = this.unattended.Checked ? "1" : "0";
  683. else
  684. configuration.AppSettings.Settings.Add("DisablePopUps", this.unattended.Checked ? "1" : "0");
  685. if (configuration.AppSettings.Settings["Debug"] != null)
  686. configuration.AppSettings.Settings["Debug"].Value = this.Debugging ? "1" : "0";
  687. else
  688. configuration.AppSettings.Settings.Add("Debug", this.Debugging ? "1" : "0");
  689. configuration.Save();
  690. }
  691.  
  692. protected override void Dispose(bool disposing)
  693. {
  694. if (disposing && this.components != null)
  695. this.components.Dispose();
  696. base.Dispose(disposing);
  697. }
  698.  
  699. private void InitializeComponent()
  700. {
  701. this.usernameTB = new TextBox();
  702. this.passwordTB = new TextBox();
  703. this.button1 = new Button();
  704. this.label1 = new Label();
  705. this.label2 = new Label();
  706. this.button2 = new Button();
  707. this.label3 = new Label();
  708. this.RegionCB = new ComboBox();
  709. this.use64 = new CheckBox();
  710. this.disableText = new CheckBox();
  711. this.unattended = new CheckBox();
  712. this.allCpu = new CheckBox();
  713. this.SuspendLayout();
  714. this.usernameTB.Location = new Point(76, 16);
  715. this.usernameTB.Name = "usernameTB";
  716. this.usernameTB.Size = new Size(274, 20);
  717. this.usernameTB.TabIndex = 0;
  718. this.passwordTB.Location = new Point(76, 57);
  719. this.passwordTB.MaxLength = 16;
  720. this.passwordTB.Name = "passwordTB";
  721. this.passwordTB.PasswordChar = '♠';
  722. this.passwordTB.Size = new Size(274, 20);
  723. this.passwordTB.TabIndex = 1;
  724. this.button1.Location = new Point(17, 200);
  725. this.button1.Name = "button1";
  726. this.button1.Size = new Size(75, 23);
  727. this.button1.TabIndex = 2;
  728. this.button1.Text = "Login";
  729. this.button1.UseVisualStyleBackColor = true;
  730. this.button1.Click += new EventHandler(this.button1_Click);
  731. this.label1.AutoSize = true;
  732. this.label1.Location = new Point(12, 19);
  733. this.label1.Name = "label1";
  734. this.label1.Size = new Size(58, 13);
  735. this.label1.TabIndex = 3;
  736. this.label1.Text = "Username:";
  737. this.label2.AutoSize = true;
  738. this.label2.Location = new Point(14, 60);
  739. this.label2.Name = "label2";
  740. this.label2.Size = new Size(56, 13);
  741. this.label2.TabIndex = 4;
  742. this.label2.Text = "Password:";
  743. this.button2.Enabled = false;
  744. this.button2.Location = new Point(197, 200);
  745. this.button2.Name = "button2";
  746. this.button2.Size = new Size(75, 23);
  747. this.button2.TabIndex = 5;
  748. this.button2.Text = "Launch";
  749. this.button2.UseVisualStyleBackColor = true;
  750. this.button2.Click += new EventHandler(this.button2_Click);
  751. this.label3.AutoSize = true;
  752. this.label3.Location = new Point(14, 101);
  753. this.label3.Name = "label3";
  754. this.label3.Size = new Size(44, 13);
  755. this.label3.TabIndex = 6;
  756. this.label3.Text = "Region:";
  757. this.RegionCB.DropDownStyle = ComboBoxStyle.DropDownList;
  758. this.RegionCB.FormattingEnabled = true;
  759. this.RegionCB.Location = new Point(76, 98);
  760. this.RegionCB.Name = "RegionCB";
  761. this.RegionCB.Size = new Size(274, 21);
  762. this.RegionCB.TabIndex = 7;
  763. this.use64.AutoSize = true;
  764. this.use64.Location = new Point(17, 134);
  765. this.use64.Name = "use64";
  766. this.use64.Size = new Size(103, 17);
  767. this.use64.TabIndex = 8;
  768. this.use64.Text = "Use 64-bit Client";
  769. this.use64.UseVisualStyleBackColor = true;
  770. this.disableText.AutoSize = true;
  771. this.disableText.Location = new Point(17, 166);
  772. this.disableText.Name = "disableText";
  773. this.disableText.Size = new Size(144, 17);
  774. this.disableText.TabIndex = 9;
  775. this.disableText.Text = "Disable texture streaming";
  776. this.disableText.UseVisualStyleBackColor = true;
  777. this.unattended.AutoSize = true;
  778. this.unattended.Location = new Point(197, 134);
  779. this.unattended.Name = "unattended";
  780. this.unattended.Size = new Size(137, 17);
  781. this.unattended.TabIndex = 10;
  782. this.unattended.Text = "Disable message boxes";
  783. this.unattended.UseVisualStyleBackColor = true;
  784. this.allCpu.AutoSize = true;
  785. this.allCpu.Location = new Point(197, 166);
  786. this.allCpu.Name = "allCpu";
  787. this.allCpu.Size = new Size(153, 17);
  788. this.allCpu.TabIndex = 11;
  789. this.allCpu.Text = "Use all available cpu cores";
  790. this.allCpu.UseVisualStyleBackColor = true;
  791. this.AutoScaleDimensions = new SizeF(6f, 13f);
  792. this.AutoScaleMode = AutoScaleMode.Font;
  793. this.ClientSize = new Size(380, 254);
  794. this.Controls.Add((Control) this.allCpu);
  795. this.Controls.Add((Control) this.unattended);
  796. this.Controls.Add((Control) this.disableText);
  797. this.Controls.Add((Control) this.use64);
  798. this.Controls.Add((Control) this.RegionCB);
  799. this.Controls.Add((Control) this.label3);
  800. this.Controls.Add((Control) this.button2);
  801. this.Controls.Add((Control) this.label2);
  802. this.Controls.Add((Control) this.label1);
  803. this.Controls.Add((Control) this.button1);
  804. this.Controls.Add((Control) this.passwordTB);
  805. this.Controls.Add((Control) this.usernameTB);
  806. this.Name = nameof (Form1);
  807. this.Text = "Replacement Launcher";
  808. this.FormClosing += new FormClosingEventHandler(this.Form1_FormClosing);
  809. this.Load += new EventHandler(this.Form1_Load);
  810. this.ResumeLayout(false);
  811. this.PerformLayout();
  812. }
  813.  
  814. private class region
  815. {
  816. public string name;
  817. public string value;
  818. public string appId;
  819.  
  820. public region(string n, string v, string a)
  821. {
  822. this.name = n;
  823. this.value = v;
  824. this.appId = a;
  825. }
  826.  
  827. public override string ToString()
  828. {
  829. return this.name;
  830. }
  831. }
  832.  
  833. public class BNSXorEncryption
  834. {
  835. private byte[] encKey;
  836. private byte[] decKey;
  837. private int encCounter;
  838. private int decCounter;
  839. private int encSum;
  840. private int decSum;
  841. private byte[] key;
  842.  
  843. public BNSXorEncryption(byte[] keyInt)
  844. {
  845. this.key = keyInt;
  846. }
  847.  
  848. public byte[] Encrypt(byte[] src, int offset, int len)
  849. {
  850. if (this.encKey == null)
  851. {
  852. if (this.key == null)
  853. return (byte[]) null;
  854. this.encKey = new byte[this.key.Length];
  855. this.key.CopyTo((Array) this.encKey, 0);
  856. this.encCounter = 0;
  857. }
  858. return this.BlockEncrypt(src, this.encKey, ref this.encCounter, ref this.encSum);
  859. }
  860.  
  861. public byte[] Decrypt(byte[] src, int offset, int len)
  862. {
  863. if (this.decKey == null)
  864. {
  865. if (this.key == null)
  866. return (byte[]) null;
  867. this.decKey = new byte[this.key.Length];
  868. this.key.CopyTo((Array) this.decKey, 0);
  869. this.decCounter = 0;
  870. }
  871. return this.BlockEncrypt(src, this.decKey, ref this.decCounter, ref this.decSum);
  872. }
  873.  
  874. private byte[] BlockEncrypt(byte[] src, byte[] key, ref int counter, ref int sum)
  875. {
  876. for (int index1 = 0; index1 < src.Length; ++index1)
  877. {
  878. int index2 = counter + 1 & (int) byte.MaxValue;
  879. counter = index2;
  880. int index3 = sum + (int) key[index2] & (int) byte.MaxValue;
  881. sum = index3;
  882. int num = (int) key[index2];
  883. key[index2] = key[index3];
  884. key[index3] = (byte) num;
  885. src[index1] = (byte) ((uint) src[index1] ^ (uint) key[(int) key[sum] + (int) key[counter] & (int) byte.MaxValue]);
  886. }
  887. return src;
  888. }
  889. }
  890. }
  891. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement