-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
102 lines (88 loc) · 3.61 KB
/
MainWindow.xaml.cs
File metadata and controls
102 lines (88 loc) · 3.61 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
using Microsoft.Win32;
using System;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls.Primitives;
namespace Disassembler
{
public partial class MainWindow : Window
{
private byte[] currentFileData;
public MainWindow()
{
InitializeComponent();
}
private void Browse_Click(object sender, RoutedEventArgs e)
{
DisassemblerBtn.IsEnabled = false;
OpenFileDialog dialog = new OpenFileDialog
{
Filter = "Все файлы (*.*)|*.*"
};
if (dialog.ShowDialog() == true)
{
FilePathBox.Text = dialog.FileName;
ResultText.Text = "";
}
}
private async void Check_Click(object sender, RoutedEventArgs e)
{
string path = FilePathBox.Text;
FileInfo fileInfo = new FileInfo(path);
if (string.IsNullOrEmpty(path) || !File.Exists(path))
{
ResultText.Foreground = System.Windows.Media.Brushes.OrangeRed;
ResultText.Text = "Файл не найден";
return;
}
ResultText.Foreground = System.Windows.Media.Brushes.LightGray;
ResultText.Text = "Проверяю...";
try
{
currentFileData = await Task.Run(() => File.ReadAllBytes(path));
(bool found, string details) result = await Task.Run(() =>
{
bool found = PEChecker.FindMZandPE(currentFileData, out string details);
return (found, details);
});
if (result.found)
{
ResultText.Foreground = System.Windows.Media.Brushes.LightGreen;
ResultText.Text = $"EXE файл найден\n{result.details}\nИмя файла: {fileInfo.Name}\n" +
$"Путь: {path}\nВремя создания: {fileInfo.CreationTime}\nРазмер: {fileInfo.Length} байт";
DisassemblerBtn.IsEnabled = true;
}
else
{
ResultText.Foreground = System.Windows.Media.Brushes.OrangeRed;
ResultText.Text = $"Ошибка: {result.details}";
}
}
catch (Exception ex)
{
ResultText.Foreground = System.Windows.Media.Brushes.OrangeRed;
ResultText.Text = "Ошибка: " + ex.Message;
}
}
private void Disassembler_Click(object sender, EventArgs e)
{
SaveFileDialog saveFile = new SaveFileDialog()
{
Filter = "Все файлы (*.*)|*.*",
FileName = "результат дизассемблирования.txt",
DefaultExt = ".txt",
Title = "Сохранить результат дизассемблирования"
};
if (saveFile.ShowDialog() == true)
{
WorkWithCode disassembler = new WorkWithCode(currentFileData);
string result = disassembler.GetDisassemblyResult();
File.WriteAllText(saveFile.FileName, result, System.Text.Encoding.UTF8);
ResultText.Foreground = System.Windows.Media.Brushes.LightGreen;
ResultText.Text = $"Дизассемблирование завершено!\nРезультат сохранен в:\n{saveFile.FileName}";
}
}
}
}