-
Notifications
You must be signed in to change notification settings - Fork 20
/
AnalyseProgress.cs
87 lines (78 loc) · 3 KB
/
AnalyseProgress.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
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;
using System.Threading;
using System.IO;
namespace Analyzer
{
public partial class AnalyseProgress : Form
{
private IdaHandler idaHandler;
private List<String> filenames;
private String baseDir;
private String output;
public AnalyseProgress()
{
InitializeComponent();
filenames = new List<string>();
}
private bool addFile(List<String> fileList, String filename)
{
byte[] buff = null;
FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
buff = br.ReadBytes(2);
br.Close();
fs.Close();
if (buff.Length < 2 || buff[0] != 'M' || buff[1] != 'Z')
return false;
fileList.Add(filename);
return true;
}
private void addDirectory(List<String> fileList, String dirname)
{
Invoke(new Action(() => { txtLog.AppendText(" " + dirname + "\r\n" ); }));
foreach (string f in Directory.GetFiles(dirname))
{
addFile(fileList, f);
}
foreach (string d in Directory.GetDirectories(dirname))
{
addDirectory(fileList, d);
}
}
public void startAnalysing(String IdaLocation, String baseDirIn, String outputIn)
{
idaHandler = new IdaHandler(IdaLocation);
baseDir = baseDirIn;
output = outputIn;
Thread monitor = new Thread(new ThreadStart(start));
monitor.Start();
}
protected void start()
{
Invoke(new Action(() => { progress.Text = "SEARCHING ALL THE FILES"; }));
Invoke(new Action(() => { txtLog.AppendText("SEARCHING THROUGH ALL DIRECTORIES\r\n"); }));
Invoke(new Action(() => { currentFile.Text = ""; }));
addDirectory(filenames, baseDir);
Invoke(new Action(() => { txtLog.AppendText("ALL FILES FOUND\r\n"); }));
for (int x = 0; x<filenames.Count; x++)
{
Invoke(new Action(() => { progress.Text = "ANALYSING " + (x+1) + "/" + filenames.Count; }));
Invoke(new Action(() => { currentFile.Text = filenames[x]; }));
Invoke(new Action(() => { txtLog.AppendText("Analysing " + filenames[x] + "\r\n"); }));
DateTime begin = DateTime.UtcNow;
idaHandler.startAnalysis(filenames[x], baseDir, output);
DateTime end = DateTime.UtcNow;
Invoke(new Action(() => { txtLog.AppendText(" took " + end.Subtract(begin) + " seconds\r\n"); }));
}
Invoke(new Action(() => { progress.Text = "DONE"; }));
}
}
}