forked from youbl/Beinet.cn.Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainForm.cs
362 lines (328 loc) · 12.6 KB
/
MainForm.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
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
namespace Beinet.cn.Tools
{
public partial class MainForm : Form
{
public MainForm()
: this(-1)
{
}
public MainForm(int tabIndex)
{
InitializeComponent();
string netVer = GetNetVersion();
if(!string.IsNullOrEmpty(netVer))
{
textBox1.Text = "本机安装的.Net FrameWork版本清单:\r\n" + netVer;
}
// 设置默认显示标签页
int idx = tabIndex;
if (tabIndex <= -1)
{
string tmp = ConfigurationManager.AppSettings["StartIndex"] ?? "";
if(!int.TryParse(tmp, out idx))
{
idx = -1;
}
}
if (idx < tabControl1.TabPages.Count && idx >= 0)
{
tabControl1.SelectedIndex = idx;
tabControl1_SelectedIndexChanged(tabControl1, null);
}
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Multiselect = true;
var result = ofd.ShowDialog(this);
// MessageBox.Show(result.ToString());
if (result != DialogResult.OK)
{
return;
}
ShowFilesInfo(ofd.FileNames);
}
void ShowFilesInfo(IEnumerable<string> files)
{
bool isBit = rad1Bit.Checked;
StringBuilder sb32 = new StringBuilder();
StringBuilder sb64 = new StringBuilder();
StringBuilder sb0 = new StringBuilder();
ShowDirInfo(files, isBit, sb32, sb64, sb0);
textBox1.Text = sb32.ToString();
textBox2.Text = sb64.ToString();
textBox3.Text = sb0.ToString();
}
void ShowDirInfo(IEnumerable<string> files, bool isBit, StringBuilder sb32, StringBuilder sb64, StringBuilder sb0)
{
foreach (string fileName in files)
{
if (File.Exists(fileName))
{
string ver = GetVerInfo(fileName);
ushort t2 = GetPEArchitecture(fileName);
string bit;
if (t2 == 0x10b)
{
bit = "32位";
if (isBit)
{
sb32.AppendFormat("32位\t{0}\r\n\t{1}\r\n\r\n", fileName, ver);
}
}
else if (t2 == 0x20b)
{
bit = "64位";
if (isBit)
sb64.AppendFormat("64位\t{0}\r\n\t{1}\r\n\r\n", fileName, ver);
}
else
{
bit = "未知";
if (isBit)
sb0.AppendFormat("未知\t{0}\r\n\t{1}\r\n\r\n", fileName, ver);
}
if (!isBit)
{
if (ver.Contains("Debug版本"))
{
sb32.AppendFormat("{2}\t{0}\r\n\t{1}\r\n\r\n", fileName, ver, bit);
}
else if (ver.Contains("Release版本"))
{
sb64.AppendFormat("{2}\t{0}\r\n\t{1}\r\n\r\n", fileName, ver, bit);
}
else
{
sb0.AppendFormat("{2}\t{0}\r\n\t{1}\r\n\r\n", fileName, ver, bit);
}
}
}
else if (Directory.Exists(fileName))
{
ShowDirInfo(Directory.GetFiles(fileName), isBit, sb32, sb64, sb0);
ShowDirInfo(Directory.GetDirectories(fileName), isBit, sb32, sb64, sb0);
}
}
}
static string GetVerInfo(string filename)
{
try
{
using (FileStream stream = new FileStream(filename, FileMode.Open))
using (MemoryStream memStream = new MemoryStream())
{
byte[] b = new byte[4096];
while (stream.Read(b, 0, b.Length) > 0)
{
memStream.Write(b, 0, b.Length);
}
Assembly asms = Assembly.Load(memStream.ToArray());//ReflectionOnlyLoad
object[] debugAtt = asms.GetCustomAttributes(typeof(DebuggableAttribute), false);
string ret = string.Empty;
if (debugAtt.Length >= 1)
{
if (((DebuggableAttribute)debugAtt[0]).IsJITTrackingEnabled)
ret += "Debug版本,基于.Net " + asms.ImageRuntimeVersion;
else
ret += "Release版本,基于.Net " + asms.ImageRuntimeVersion;
}
else
{
ret += "未知版本,基于.Net " + asms.ImageRuntimeVersion;
}
ret = asms.FullName + "\r\n\t" + ret;
return ret;
}
}
catch (Exception exp)
{
return exp.Message;//.ToString();
}
}
public static ushort GetPEArchitecture(string pFilePath)
{
ushort architecture = 0;
try
{
using (System.IO.FileStream fStream = new System.IO.FileStream(pFilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read))
{
using (System.IO.BinaryReader bReader = new System.IO.BinaryReader(fStream))
{
if (bReader.ReadUInt16() == 23117) //check the MZ signature
{
fStream.Seek(0x3A, System.IO.SeekOrigin.Current); //seek to e_lfanew.
fStream.Seek(bReader.ReadUInt32(), System.IO.SeekOrigin.Begin); //seek to the start of the NT header.
if (bReader.ReadUInt32() == 17744) //check the PE\0\0 signature.
{
fStream.Seek(20, System.IO.SeekOrigin.Current); //seek past the file header,
architecture = bReader.ReadUInt16(); //read the magic number of the optional header.
}
}
}
}
}
catch (Exception)
{
return 0;
}
//if architecture returns 0, there has been an error.
return architecture;
}
#region 文件拖拽进来的处理,要先设置Form.AllowDrop为true
private void Form1_DragDrop(object sender, DragEventArgs e)
{
var obj = e.Data.GetData(DataFormats.FileDrop);
if (obj == null)
{
return;
}
//MessageBox.Show(obj.ToString());
string[] files = obj as string[];
if (files == null)
{
return;
}
ShowFilesInfo(files);
}
/// <summary>
/// 拖拽文件进来时,才允许
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form1_DragEnter(object sender, DragEventArgs e)
{
if (tabDllAnlyse.TabIndex == tabControl1.SelectedIndex && e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.Link;
}
else
{
e.Effect = DragDropEffects.None;
}
}
#endregion
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
TabPage page = tabControl1.SelectedTab;
if (page == tabGZip)
{
AddFormControl<GzipTest>(page);
}
else if (tabControl1.SelectedTab == tabMd5File)
{
AddFormControl<FileHash>(page);
}
else if (tabControl1.SelectedTab == tabSqlInject)
{
AddFormControl<SqlInjectForm.SqlInject>(page);
}
else if (tabControl1.SelectedTab == tabLvs)
{
AddFormControl<LvsManager.LVSControl>(page);
}
else if (tabControl1.SelectedTab == tabEncrypt)
{
AddFormControl<CryptTool>(page);
}
else if (tabControl1.SelectedTab == tabRegex)
{
AddFormControl<RegexTool.MainForm>(page);
}
else if (tabControl1.SelectedTab == tabDataSync)
{
AddFormControl<DataSync.MainForm>(page);
}
}
static void AddFormControl<T>(Control parent) where T : Form, new()
{
if (parent.Controls.Count <= 0)
{
T frm = new T();
frm.FormBorderStyle = FormBorderStyle.None;
frm.Dock = DockStyle.Fill;
frm.TopLevel = false;
parent.Controls.Clear();
parent.Controls.Add(frm);
frm.Show();
}
}
// 获取本机安装的net版本清单
public static string GetNetVersion()
{
StringBuilder sb = new StringBuilder();
using (RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\"))
{
if (registryKey == null)
{
return null;
}
string[] subKeyNames = registryKey.GetSubKeyNames();
foreach (string verKey in subKeyNames)
{
if (verKey[0] != 'v')
{
continue;
}
RegistryKey registryKey2 = registryKey.OpenSubKey(verKey);
if (registryKey2 == null)
{
continue;
}
string ver = Convert.ToString(registryKey2.GetValue("Version", ""));
string sp = Convert.ToString(registryKey2.GetValue("SP", ""));
string install = Convert.ToString(registryKey2.GetValue("Install", ""));
if (string.IsNullOrEmpty(install))
{
sb.AppendFormat("{0}{1}\r\n", verKey.PadRight(12), ver);
}
else if (!string.IsNullOrEmpty(sp) && install == "1")
{
sb.AppendFormat("{0}{1} SP{2}\r\n", verKey.PadRight(12), ver, sp);
}
if (!string.IsNullOrEmpty(ver))
{
continue;
}
string[] subKeyNames2 = registryKey2.GetSubKeyNames();
foreach (string text4 in subKeyNames2)
{
RegistryKey registryKey3 = registryKey2.OpenSubKey(text4);
if (registryKey3 == null)
{
continue;
}
ver = Convert.ToString(registryKey3.GetValue("Version", ""));
if (ver != "")
{
sp = Convert.ToString(registryKey3.GetValue("SP", ""));
}
install = Convert.ToString(registryKey3.GetValue("Install", ""));
if (install == "")
{
sb.AppendFormat("{0}{1}\r\n", verKey.PadRight(12), ver);
}
else if (sp != "" && install == "1")
{
sb.AppendFormat(" {0} {1} SP{2}\r\n", text4, ver, sp);
}
else if (install == "1")
{
sb.AppendFormat(" {0} {1}\r\n", text4, ver);
}
}
}
}
return sb.ToString();
}
}
}