-
Notifications
You must be signed in to change notification settings - Fork 30
/
Form1.cs
400 lines (365 loc) · 15.7 KB
/
Form1.cs
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
using Ressy;
using Ressy.HighLevel.Versions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Toolbelt.Drawing;
using Vestris.ResourceLib;
using static Vestris.ResourceLib.Winver;
namespace SharpThief
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
SelectFile.AllowDrop = true;
SelectFile.DragEnter += new DragEventHandler(SelectFile_DragDrop);
SelectFile.DragDrop += new DragEventHandler(SelectFile_DragEnter);
}
private void btnClone_Click(object sender, EventArgs e)
{
using (var openFileDialog = new OpenFileDialog())
{
openFileDialog.Filter = "Executable (*.exe)|*.exe";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
var fileVersionInfo = FileVersionInfo.GetVersionInfo(openFileDialog.FileName);
FileInfo fileInfo = new FileInfo(openFileDialog.FileName);
txtOriginalFilename.Text = fileVersionInfo.InternalName ?? string.Empty;
txtDescription.Text = fileVersionInfo.FileDescription ?? string.Empty;
txtCompany.Text = fileVersionInfo.CompanyName ?? string.Empty;
txtProduct.Text = fileVersionInfo.ProductName ?? string.Empty;
txtCopyright.Text = fileVersionInfo.LegalCopyright ?? string.Empty;
txtTrademarks.Text = fileVersionInfo.LegalTrademarks ?? string.Empty;
txtchangetime.Text = fileInfo.LastWriteTime.ToString();
var version = fileVersionInfo.FileMajorPart;
txtFileVersion.Text = $"{fileVersionInfo.FileMajorPart.ToString()}.{fileVersionInfo.FileMinorPart.ToString()}.{fileVersionInfo.FileBuildPart.ToString()}.{fileVersionInfo.FilePrivatePart.ToString()}";
txtProductVersion.Text = $"{fileVersionInfo.FileMajorPart.ToString()}.{fileVersionInfo.FileMinorPart.ToString()}.{fileVersionInfo.FileBuildPart.ToString()}.{fileVersionInfo.FilePrivatePart.ToString()}";
}
}
}
private void btnIcon_Click(object sender, EventArgs e)
{
using (OpenFileDialog ofd = new OpenFileDialog())
{
ofd.Title = "Choose Icon";
ofd.Filter = "Icons Files(*.exe;*.ico;)|*.exe;*.ico";
ofd.Multiselect = false;
if (ofd.ShowDialog() == DialogResult.OK)
{
if (ofd.FileName.ToLower().EndsWith(".exe"))
{
string ico = GetIcon(ofd.FileName);
//txtIcon.Text = ico;
toolStrip1.Text = ico;
toolStrip1.ForeColor = Color.DarkGreen;
picIcon.ImageLocation = ico;
MessageBox.Show(picIcon.ImageLocation);
}
else
{
//txtIcon.Text = ofd.FileName;
toolStrip1.Text = ofd.FileName;
toolStrip1.ForeColor = Color.DarkGreen;
picIcon.ImageLocation = ofd.FileName;
}
}
}
}
private void chkIcon_CheckedChanged(object sender, EventArgs e)
{
if (chkIcon.Checked)
{
//txtIcon.Enabled = true;
btnIcon.Enabled = true;
}
else
{
//txtIcon.Enabled = false;
btnIcon.Enabled = false;
}
}
private string GetIcon(string path)
{
try
{
string tempFile = Path.GetTempFileName() + ".ico";
using (FileStream fs = new FileStream(tempFile, FileMode.Create))
{
IconExtractor.Extract1stIconTo(path, fs);
}
return tempFile;
}
catch { }
return "";
}
private void Form1_Load(object sender, EventArgs e)
{
Language();
}
private void button1_Click(object sender, EventArgs e)
{
using (OpenFileDialog ofd = new OpenFileDialog())
{
ofd.Title = "Choose Icon";
ofd.Filter = "Icons Files(*.exe;)|*.exe;";
ofd.Multiselect = false;
if (ofd.ShowDialog() == DialogResult.OK)
{
SelectFile.Tag = ofd.FileName;
SelectFile.Text = Path.GetFileName(ofd.FileName);
SelectFile.ForeColor = Color.Red;
}
}
}
private void WriteAssembly(string filename)
{
try
{
var portableExecutable = new PortableExecutable(filename);
string[] Pdversion = txtProductVersion.Text.Split('.');
string[] Flversion = txtFileVersion.Text.Split('.');
var versionInfo = new VersionInfoBuilder()
.SetFileVersion(new Version(Convert.ToInt32(Flversion[0]), Convert.ToInt32(Flversion[1]), Convert.ToInt32(Flversion[2]), Convert.ToInt32(Flversion[3])))
.SetProductVersion(new Version(Convert.ToInt32(Pdversion[0]), Convert.ToInt32(Pdversion[1]), Convert.ToInt32(Pdversion[2]), Convert.ToInt32(Pdversion[3])))
.SetFileType(Ressy.HighLevel.Versions.FileType.Application)
.SetAttribute(VersionAttributeName.FileDescription, txtDescription.Text)
.SetAttribute(VersionAttributeName.CompanyName, txtCompany.Text)
// .SetAttribute(VersionAttributeName.LegalTrademark, txtTrademarks.Text)
.SetAttribute(VersionAttributeName.OriginalFilename, txtOriginalFilename.Text)
.SetAttribute(VersionAttributeName.ProductName, txtProduct.Text)
.SetAttribute(VersionAttributeName.LegalCopyright, txtCopyright.Text)
.SetFileOperatingSystem(FileOperatingSystem.WindowsNT)
.SetFileSubType(Ressy.HighLevel.Versions.FileSubType.Unknown)
.Build();
portableExecutable.SetVersionInfo(versionInfo);
}
catch (Exception ex)
{
throw new ArgumentException("Assembly: " + ex.Message);
}
}
private void button2_Click(object sender, EventArgs e)
{
try
{
string tempPath = Path.GetTempPath();
string randomFileName = Path.GetRandomFileName() + ".exe";
string fullPath = Path.Combine(tempPath, randomFileName);
if (SelectFile.Text != "选择文件" && SelectFile.Text != "SelectFile")
{
File.WriteAllBytes(fullPath, File.ReadAllBytes(SelectFile.Tag.ToString()));
using (SaveFileDialog saveFileDialog1 = new SaveFileDialog())
{
saveFileDialog1.Filter = ".exe (*.exe)|*.exe";
saveFileDialog1.InitialDirectory = Application.StartupPath;
saveFileDialog1.OverwritePrompt = false;
saveFileDialog1.FileName = "Client";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
if (chkIcon.Checked && !string.IsNullOrEmpty(toolStrip1.Text))
{
IconInjector.InjectIcon(fullPath, toolStrip1.Text);
}
Thread.Sleep(500);
if (btnAssembly.Checked)
{
WriteAssembly(fullPath);
}
Thread.Sleep(500);
if (checkBox1.Checked)
{
var cert = new PEFileInfo().CopyCert(signatureFile.Tag.ToString());
new PEFileInfo().WriteCert(cert, fullPath, saveFileDialog1.FileName);
}
if (txtchangetime.Text.Length > 0)
{
string[] Time = txtchangetime.Text.Split(new char[] { ' ' }, StringSplitOptions.None);
new ChangeTime().changeTime(saveFileDialog1.FileName, Time[0], Time[1]);
}
if (File.Exists(saveFileDialog1.FileName))
{
MessageBox.Show("Build sucessfully!", "Builder", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Build Error!", "Builder", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
File.Delete(fullPath);
}
}
}
}
catch (Exception ex) { MessageBox.Show(ex.Message); }
}
private void btnAssembly_CheckedChanged(object sender, EventArgs e)
{
if (btnAssembly.Checked)
{
btnClone.Enabled = true;
txtProduct.Enabled = true;
txtDescription.Enabled = true;
txtCompany.Enabled = true;
txtCopyright.Enabled = true;
txtTrademarks.Enabled = true;
txtOriginalFilename.Enabled = true;
txtOriginalFilename.Enabled = true;
txtProductVersion.Enabled = true;
txtFileVersion.Enabled = true;
txtchangetime.Enabled = true;
}
else
{
btnClone.Enabled = false;
txtProduct.Enabled = false;
txtDescription.Enabled = false;
txtCompany.Enabled = false;
txtCopyright.Enabled = false;
txtTrademarks.Enabled = false;
txtOriginalFilename.Enabled = false;
txtOriginalFilename.Enabled = false;
txtProductVersion.Enabled = false;
txtFileVersion.Enabled = false;
txtchangetime.Enabled = false;
}
}
private void button3_Click(object sender, EventArgs e)
{
using (OpenFileDialog ofd = new OpenFileDialog())
{
ofd.Title = "Choose Icon";
ofd.Filter = "Icons Files(*.exe;)|*.exe;";
ofd.Multiselect = false;
if (ofd.ShowDialog() == DialogResult.OK)
{
//string ico = GetIcon(ofd.FileName);
//txtIcon.Text = ico;
signatureFile.Tag = ofd.FileName;
signatureFile.Text = Path.GetFileName(ofd.FileName);
signatureFile.ForeColor = Color.DarkGreen;
}
}
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
signatureFile.Enabled = true;
}
else
{
signatureFile.Enabled = false;
}
}
public void Language()
{
switch (Properties.Settings.Default.Language)
{
case "en-US":
{
chkIcon.Text = "Icon";
btnIcon.Text = "Select Icon";
checkBox1.Text = "SigThief";
signatureFile.Text = "Sig File";
SelectFile.Text = "SelectFile";
Build.Text = "Build";
btnAssembly.Text = "Build Info";
label8.Text = "Product:";
label7.Text = "Description:";
label9.Text = "Company:";
label10.Text = "Copyright:";
label11.Text = "Trademark:";
label12.Text = "Original:";
label13.Text = "ProductVersion:";
label14.Text = "FileVersion:";
btnClone.Text = "Clone";
txtchangetime.Text = "ChangeTime";
Properties.Settings.Default.Save();
break;
}
case "en-CN":
{
chkIcon.Text = "图标";
btnIcon.Text = "选择图标";
checkBox1.Text = "窃取签名";
signatureFile.Text = "签名文件";
SelectFile.Text = "选择文件";
Build.Text = "生成";
btnAssembly.Text = "生成程序信息";
label8.Text = "产品:";
label7.Text = "描述:";
label9.Text = "公司:";
label10.Text = "版权:";
label11.Text = "商标:";
label12.Text = "原始文件名:";
label13.Text = "产品版本号:";
label14.Text = "文件版本号:";
btnClone.Text = "克隆";
txtchangetime.Text = "修改时间";
Properties.Settings.Default.Save();
break;
}
}
}
private void chineseToolStripMenuItem_Click(object sender, EventArgs e)
{
Properties.Settings.Default.Language = "en-CN";
Language();
Properties.Settings.Default.Save();
}
private void englishToolStripMenuItem_Click(object sender, EventArgs e)
{
Properties.Settings.Default.Language = "en-US";
Language();
Properties.Settings.Default.Save();
}
private void SelectFile_DragDrop(object sender, DragEventArgs e)
{
try
{
//MessageBox.Show("calc");
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (string file in files)
{
SelectFile.Text = Path.GetFileName(file);
SelectFile.Tag = file;
SelectFile.ForeColor = Color.Red;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void SelectFile_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.Copy;
}
}
private void button1_Click_1(object sender, EventArgs e)
{
if (picIcon.ImageLocation != null && !string.IsNullOrEmpty(picIcon.ImageLocation))
{
File.Copy(picIcon.ImageLocation, Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + $"\\{Path.GetFileName(picIcon.ImageLocation)}");
MessageBox.Show("Buid Successful!");
}
else
{
MessageBox.Show("Please select an icon first");
}
}
}
}