-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontactsform.cs
More file actions
148 lines (126 loc) · 4.85 KB
/
Copy pathcontactsform.cs
File metadata and controls
148 lines (126 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace qıRAT
{
public partial class contactsform : Form
{
private string deviceName;
private string jsonFilePath;
public contactsform(string devName, string jsonPath)
{
InitializeComponent();
InitializeContextMenu();
this.MaximizeBox = false;
this.deviceName = devName;
this.jsonFilePath = jsonPath;
this.Load += contactsform_Load;
}
public contactsform()
{
InitializeComponent();
InitializeContextMenu();
this.Load += contactsform_Load;
}
private void contactsform_Load(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(deviceName))
{
this.Text = "Contacts Manager - " + deviceName;
}
else
{
this.Text = "Contacts Manager";
}
listViewcontacts.View = View.Details;
listViewcontacts.GridLines = true;
listViewcontacts.FullRowSelect = true;
listViewcontacts.Columns.Clear();
listViewcontacts.Columns.Add("Name", 200);
listViewcontacts.Columns.Add("Number", 150);
if (!string.IsNullOrEmpty(jsonFilePath))
{
LoadContactsData();
}
}
private void InitializeContextMenu()
{
ContextMenuStrip menu = new ContextMenuStrip();
ToolStripMenuItem copyNumberItem = new ToolStripMenuItem("Copy Number");
copyNumberItem.Click += (s, e) =>
{
if (listViewcontacts.SelectedItems.Count > 0)
{
string number = listViewcontacts.SelectedItems[0].SubItems.Count > 1
? listViewcontacts.SelectedItems[0].SubItems[1].Text
: listViewcontacts.SelectedItems[0].Text;
if (!string.IsNullOrEmpty(number))
{
Clipboard.SetText(number);
}
}
};
menu.Items.Add(copyNumberItem);
ToolStripMenuItem copyNameItem = new ToolStripMenuItem("Copy Name");
copyNameItem.Click += (s, e) =>
{
if (listViewcontacts.SelectedItems.Count > 0)
{
string name = listViewcontacts.SelectedItems[0].Text;
if (!string.IsNullOrEmpty(name))
{
Clipboard.SetText(name);
}
}
};
menu.Items.Add(copyNameItem);
listViewcontacts.ContextMenuStrip = menu;
}
private void LoadContactsData()
{
try
{
if (!System.IO.File.Exists(jsonFilePath)) return;
string json = System.IO.File.ReadAllText(jsonFilePath);
listViewcontacts.BeginUpdate();
listViewcontacts.Items.Clear();
var matches = System.Text.RegularExpressions.Regex.Matches(json, "\\{(.*?)\\}");
foreach (System.Text.RegularExpressions.Match match in matches)
{
string content = match.Groups[1].Value;
if (content.Contains("\"contactsList\":[")) continue;
string name = ExtractJsonValue(content, "name");
string number = ExtractJsonValue(content, "phoneNo");
if (string.IsNullOrEmpty(name) && string.IsNullOrEmpty(number)) continue;
ListViewItem item = new ListViewItem(unescape(name));
item.SubItems.Add(number);
listViewcontacts.Items.Add(item);
}
listViewcontacts.EndUpdate();
}
catch (Exception ex)
{
MessageBox.Show("Error reading contacts data: " + ex.Message);
}
}
private string ExtractJsonValue(string content, string key)
{
var match = System.Text.RegularExpressions.Regex.Match(content, "\"" + key + "\":\"(.*?)\"");
if (match.Success) return match.Groups[1].Value;
match = System.Text.RegularExpressions.Regex.Match(content, "\"" + key + "\":([^,}\"]+)");
return match.Success ? match.Groups[1].Value : "";
}
private string unescape(string str)
{
if (str == null) return "";
string clean = str.Replace("\\n", "\n").Replace("\\r", "\r").Replace("\\t", "\t").Replace("\\\"", "\"").Replace("\\/", "/");
return clean;
}
}
}