-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
246 lines (217 loc) · 8.79 KB
/
MainWindow.xaml.cs
File metadata and controls
246 lines (217 loc) · 8.79 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
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
using System.Diagnostics;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using zrobts.Helpers;
using zrobts.Models;
namespace zrobts;
public partial class MainWindow : Window
{
private DriveInfoModel? _selectedDrive;
private List<DriveInfoModel> _drives = [];
public MainWindow()
{
InitializeComponent();
LoadDrives();
CheckAdminStatus();
}
private void LoadDrives()
{
try
{
_drives = DriveHelper.GetAllDrives();
DrivesList.ItemsSource = _drives;
if (_drives.Count == 0)
{
AppendOutput("Nenhum drive fixo encontrado no sistema.");
}
else
{
AppendOutput($"Encontrados {_drives.Count} drive(s) no sistema.");
foreach (var drive in _drives)
{
string type = drive.IsSSD ? "SSD" : "HDD";
AppendOutput($" • {drive.DisplayName} - {type} - {drive.FreeSpaceFormatted} livre");
}
}
}
catch (Exception ex)
{
AppendOutput($"[ERRO] Falha ao carregar drives: {ex.Message}");
}
}
private void CheckAdminStatus()
{
if (!DriveHelper.IsRunningAsAdmin())
{
AdminWarning.Visibility = Visibility.Visible;
AppendOutput("[AVISO] O aplicativo não está rodando como Administrador.");
}
}
private void DriveCard_Click(object sender, MouseButtonEventArgs e)
{
if (sender is Border border && border.Tag is string driveLetter)
{
_selectedDrive = _drives.FirstOrDefault(d => d.Letter == driveLetter);
if (_selectedDrive != null)
{
// Visual feedback - highlight selected card
AppendOutput($"Drive selecionado: {_selectedDrive.DisplayName}");
}
}
}
private async void StartButton_Click(object sender, RoutedEventArgs e)
{
if (_selectedDrive == null)
{
MessageBox.Show(
"Por favor, clique em um dos cards de drive acima para selecionar o disco que deseja limpar.",
"Selecione um Drive",
MessageBoxButton.OK,
MessageBoxImage.Information);
return;
}
// Alerta especial para SSD
if (_selectedDrive.IsSSD)
{
var ssdResult = MessageBox.Show(
$"⚠️ ATENÇÃO: O drive {_selectedDrive.DisplayName} é um SSD!\n\n" +
"A limpeza com cipher.exe pode não ser 100% eficaz em SSDs devido ao 'wear leveling'.\n\n" +
"Para SSDs, recomenda-se:\n" +
"• Usar o Secure Erase do fabricante\n" +
"• Criptografar o disco antes da limpeza\n" +
"• Considerar destruição física para dados sensíveis\n\n" +
"Deseja continuar mesmo assim?",
"Aviso de Segurança - SSD Detectado",
MessageBoxButton.YesNo,
MessageBoxImage.Warning);
if (ssdResult != MessageBoxResult.Yes)
{
AppendOutput("Operação cancelada pelo usuário (SSD).");
return;
}
}
// Confirmação final
var confirmResult = MessageBox.Show(
$"🛡️ CONFIRMAÇÃO DE LIMPEZA SEGURA\n\n" +
$"Drive: {_selectedDrive.DisplayName}\n" +
$"Tipo: {_selectedDrive.DriveType}\n" +
$"Espaço livre: {_selectedDrive.FreeSpaceFormatted}\n\n" +
"Este processo irá sobrescrever todo o espaço livre do disco com dados aleatórios.\n\n" +
"⏱️ O processo pode demorar bastante dependendo do tamanho do espaço livre.\n\n" +
"Deseja continuar?",
"Confirmar Limpeza Segura",
MessageBoxButton.YesNo,
MessageBoxImage.Question);
if (confirmResult != MessageBoxResult.Yes)
{
AppendOutput("Operação cancelada pelo usuário.");
return;
}
await ExecuteWipe(_selectedDrive.Letter);
}
private async Task ExecuteWipe(string driveLetter)
{
string arg = $"/w:{driveLetter}:";
StartButton.IsEnabled = false;
InfoButton.IsEnabled = false;
ProgressBar.Visibility = Visibility.Visible;
OutputBox.Text = "";
AppendOutput($"═══════════════════════════════════════════════════════");
AppendOutput($"Iniciando processo de apagamento seguro no drive {driveLetter}:");
AppendOutput($"═══════════════════════════════════════════════════════");
AppendOutput("");
await Task.Run(() =>
{
try
{
ProcessStartInfo psi = new()
{
FileName = "cipher.exe",
Arguments = arg,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
};
using Process proc = new();
proc.StartInfo = psi;
proc.OutputDataReceived += (s, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
AppendOutput(e.Data);
};
proc.ErrorDataReceived += (s, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
AppendOutput($"[ERRO] {e.Data}");
};
proc.Start();
proc.BeginOutputReadLine();
proc.BeginErrorReadLine();
proc.WaitForExit();
}
catch (Exception ex)
{
AppendOutput($"[ERRO] Ocorreu um erro durante a execução: {ex.Message}");
}
});
ProgressBar.Visibility = Visibility.Collapsed;
StartButton.IsEnabled = true;
InfoButton.IsEnabled = true;
AppendOutput("");
AppendOutput($"═══════════════════════════════════════════════════════");
AppendOutput("✅ Processo concluído!");
AppendOutput($"═══════════════════════════════════════════════════════");
}
private void LearnMore_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show(
"🛡️ COMO FUNCIONA A LIMPEZA SEGURA\n\n" +
"Este processo utiliza a ferramenta 'cipher.exe' do Windows para sobrescrever os espaços livres do disco selecionado.\n\n" +
"📋 O processo realiza 3 passagens:\n" +
" 1️⃣ Sobrescreve com zeros (0x00)\n" +
" 2️⃣ Sobrescreve com uns (0xFF)\n" +
" 3️⃣ Sobrescreve com dados aleatórios\n\n" +
"Isso impede que arquivos previamente apagados possam ser recuperados por softwares especializados.\n\n" +
"⚠️ LIMITAÇÕES:\n" +
"• Em SSDs, o 'wear leveling' pode manter cópias dos dados em blocos não acessíveis\n" +
"• O processo só limpa o espaço LIVRE, não afeta arquivos existentes\n" +
"• Laboratórios forenses avançados podem ter técnicas adicionais",
"Como Funciona?",
MessageBoxButton.OK,
MessageBoxImage.Information);
}
private void AppendOutput(string text)
{
Dispatcher.Invoke(() =>
{
string timestamp = DateTime.Now.ToString("HH:mm:ss");
OutputBox.AppendText($"[{timestamp}] {text}{Environment.NewLine}");
OutputBox.ScrollToEnd();
});
}
}
/// <summary>
/// Converter para calcular largura baseada em porcentagem
/// </summary>
public class PercentToWidthConverter : IMultiValueConverter
{
public static readonly PercentToWidthConverter Instance = new();
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values.Length == 2 &&
values[0] is double percent &&
values[1] is double width)
{
return width * (percent / 100.0);
}
return 0.0;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}