-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
361 lines (301 loc) · 13.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
using Microsoft.Win32;
using System;
using System.Windows.Forms;
namespace ImageFileOptionVisualizer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void IFEOEnableOnlyMode_CheckedChanged(object sender, EventArgs e)
{
if (IFEOEnabledOnlyMode.Checked)
{
AvastCleanupOnlyMode.Checked = false;
AnythingMode.Checked = false;
}
}
private void AvastCleanupOnlyMode_CheckedChanged(object sender, EventArgs e)
{
if (AvastCleanupOnlyMode.Checked)
{
IFEOEnabledOnlyMode.Checked = false;
AnythingMode.Checked = false;
}
}
private void AnythingMode_CheckedChanged(object sender, EventArgs e)
{
if (AnythingMode.Checked)
{
IFEOEnabledOnlyMode.Checked = false;
AvastCleanupOnlyMode.Checked = false;
}
}
private void RefreshTreeDisplay_Click(object sender, EventArgs e)
{
// Clear the TreeDisplay first
DisplayTreeView.Nodes.Clear();
// Load registry
RegistryKey IFEORoot;
try
{
IFEORoot = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options", false);
}
catch (System.Security.SecurityException _)
{
MessageBox.Show("Unable to open the LocalMachine registry\n" + _.ToString(), "Access Denied");
return;
}
if (IFEORoot == null)
{
MessageBox.Show("There are no Image File Execution Option Folder in the registry.");
return;
}
string[] IFEOApps = IFEORoot.GetSubKeyNames();
foreach (string key in IFEOApps)
{
bool IsFiltered = false;
// If avast only filter are enabled, set up default filtering.
if (AvastCleanupOnlyMode.Checked || IFEOEnabledOnlyMode.Checked)
{
IsFiltered = true;
}
TreeNode AppNode = new TreeNode
{
Text = key,
Tag = "AppNode"
};
RegistryKey IFEOPolicyRoot = null;
try
{
IFEOPolicyRoot = IFEORoot.OpenSubKey(key, false);
}
catch (System.Security.SecurityException)
{
DisplayTreeView.Nodes.Add(new TreeNode {
Text = "[ ACCESS DENIED ] - " + key
});
continue;
}
if (IFEOPolicyRoot == null)
{
MessageBox.Show("There are no IFEO Root in the registry.");
return;
}
string[] IFEOPolicies = IFEOPolicyRoot.GetSubKeyNames();
foreach (string Policy in IFEOPolicies)
{
TreeNode AppPolicyNode = new TreeNode
{
Text = Policy,
Tag = "AppPolicyNode"
};
RegistryKey PolicyValueRoot = null;
try
{
PolicyValueRoot = IFEOPolicyRoot.OpenSubKey(Policy, false);
}
catch (System.Security.SecurityException _)
{
MessageBox.Show("Unable to open the IFEO Policy\n" + _.ToString(), "Access Denied");
continue;
}
// Display a message if there is no IFEO Policy in the registry
if (PolicyValueRoot == null)
{
MessageBox.Show("There are no IFEO Policy in the registry.");
return;
}
string[] PolicyNames = PolicyValueRoot.GetValueNames();
foreach (string Names in PolicyNames)
{
if (IFEOEnabledOnlyMode.Checked)
{
IsFiltered = false;
}
TreeNode AppValueNode = new TreeNode
{
Text = Names,
Tag = "AppValueNode"
};
string NameValue = PolicyValueRoot.GetValue(Names).ToString();
if (NameValue == null)
{
continue;
}
else if (AvastCleanupOnlyMode.Checked && Names == "Debugger" && NameValue.Contains("Avast Software\\Cleanup"))
{
IsFiltered = false;
}
AppValueNode.Text += " : " + NameValue;
AppPolicyNode.Nodes.Add(AppValueNode);
}
if (PolicyValueRoot != null)
{
PolicyValueRoot.Close();
}
AppNode.Nodes.Add(AppPolicyNode);
}
if (IFEOPolicyRoot != null)
{
IFEOPolicyRoot.Close();
}
// If not filtered, then add it to the display
if (!IsFiltered)
{
DisplayTreeView.Nodes.Add(AppNode);
}
}
if (IFEORoot != null)
{
IFEORoot.Close();
}
// Display count detected
EntryCountDisplay.Text = "Entry Count : " + DisplayTreeView.Nodes.Count.ToString();
}
private void RemoveSelectedEntry_Click(object sender, EventArgs e)
{
RemoveSelectedEntry_Click(false);
RefreshTreeDisplay_Click(sender, e);
}
private bool RemoveSelectedEntry_Click(bool BypassSecurityQuestions)
{
if (DisplayTreeView.SelectedNode == null) { return false; }
TreeNode SelectedNode = DisplayTreeView.SelectedNode;
DialogResult UserResponse;
if (BypassSecurityQuestions) {
UserResponse = DialogResult.Yes;
}
else
{
UserResponse = MessageBox.Show("You sure that you want to remove the IFEO of\n " + SelectedNode.Text + "\n\nMake sure you know what you are doing, modifying registry is highly dangereous.\n\nDid you want to proceed removing ?", "Remove Selected IFEO Confirmation Dialog", MessageBoxButtons.YesNoCancel);
}
if (UserResponse == DialogResult.Yes)
{
// User want to proceed, try to remove the selected IFEO.
string NodeTag = SelectedNode.Tag.ToString();
// Do not continue if Policy Value was selected.
if (NodeTag == "AppValueNode")
{
MessageBox.Show("Sorry, you can't remove the IFEO value, try removing the policy root of this value instead.", "[ ERROR ] User is trying to remove Policy Value instead of Policy Root");
return false;
}
RegistryKey IFEORoot;
string PolicyPath;
if (NodeTag == "AppPolicyNode")
{
// Policy selected, get the parent first before appending the policy name
PolicyPath = SelectedNode.Parent.Text + @"\" + SelectedNode.Text + @"\";
}
else if (NodeTag == "AppNode")
{
// Whole app selected
PolicyPath = SelectedNode.Text + @"\";
}
else
{
MessageBox.Show("Sorry, there's an problem while trying to get your selected IFEO entries.", "[ ERROR ] Unknown type of Selected Policy");
return false;
}
try
{
// Open the root
IFEORoot = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\", true);
IFEORoot.OpenSubKey(NodeTag, true);
IFEORoot.Close();
IFEORoot = null;
IFEORoot = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\", true);
}
catch (System.Security.SecurityException _)
{
MessageBox.Show("Unable to open the IFEO\n" + _.ToString(), "[ ERROR ] OPEN IFEO ROOT Access Denied");
return false;
}
if (IFEORoot == null)
{
MessageBox.Show("The selected IFEO isn't found in the registry.");
return false;
}
DialogResult LastConfirmation;
if (BypassSecurityQuestions)
{
LastConfirmation = DialogResult.Yes;
}
else
{
string LastConfirmationDialogMessage = "This is the last confirmation, Are you sure you want to delete ";
if (NodeTag == "AppPolicyNode")
{
LastConfirmationDialogMessage += "the : \n " + SelectedNode.Text + "\nwhich is an IFEO policy of the app :\n " + SelectedNode.Parent.Text + "\n\n\nNO ONE IN THE WORLD ARE RESPONSIBLE IF THIS APPLICATION CAUSES ANY PROBLEM, BY CONTINUING YOU AGREE NOT TO HELD ANYONE IN THE WORLD RESPONSIBLE FOR THE PROBLEM CAUSED BY THIS APP USAGE.";
}
else if (NodeTag == "AppNode")
{
LastConfirmationDialogMessage += "all of the IFEO Policy for :\n " + SelectedNode.Text + "\n\n\nNO ONE IN THE WORLD ARE RESPONSIBLE IF THIS APPLICATION CAUSES ANY PROBLEM, BY CONTINUING YOU AGREE NOT TO HELD ANYONE IN THE WORLD RESPONSIBLE FOR THE PROBLEM CAUSED BY THIS APP USAGE.";
}
LastConfirmation = MessageBox.Show(LastConfirmationDialogMessage, "Remove Selected IFEO Last Confirmation Dialog", MessageBoxButtons.YesNoCancel);
}
if (LastConfirmation == DialogResult.Yes)
{
// Delete.
IFEORoot.DeleteSubKeyTree(PolicyPath);
IFEORoot.Flush();
RegistryKey DeleteChecker = IFEORoot.OpenSubKey(PolicyPath);
if (DeleteChecker != null)
{
MessageBox.Show("Unable to delete the " + PolicyPath + ", try checking registry permissions or running this app as administrator.", "IFEO EXIST AFTER DELETION ERROR");
}
else
{
MessageBox.Show("Sucessfully removed the " + PolicyPath + "\n\n You might need to restart the machine before the changes get applied.", "IFEO GONE DELETED");
// Close and flush changes if there is any.
IFEORoot.Close();
return true;
}
}
else
{
MessageBox.Show("Delete Action aborted, no change has been made to your registry.");
}
// Close and flush changes if there is any.
IFEORoot.Close();
return false;
}
else
{
// If not OK, then don't do anything.
return false;
}
}
private void RemoveEverything_Click(object sender, EventArgs e)
{
if (DisplayTreeView.Nodes.Count == 0)
{
MessageBox.Show("There are nothing to be removed in the display list, no change has been made to your registry.");
return;
}
DialogResult LastConfirmation = MessageBox.Show("You sure you want to remove all entries listed on the display ?\n\n\nNO ONE IN THE WORLD ARE RESPONSIBLE IF THIS APPLICATION CAUSES ANY PROBLEM, BY CONTINUING YOU AGREE NOT TO HELD ANYONE IN THE WORLD RESPONSIBLE FOR THE PROBLEM CAUSED BY THIS APP USAGE.", "Recursive IFEO Remover Last Confirmation Dialog", MessageBoxButtons.YesNoCancel);
if (LastConfirmation != DialogResult.Yes)
{
MessageBox.Show("Recursive Delete Action aborted, no change has been made to your registry.");
return;
}
else
{
foreach (TreeNode Nodes in DisplayTreeView.Nodes)
{
DisplayTreeView.SelectedNode = Nodes;
if (!RemoveSelectedEntry_Click(true))
{
// An error occured, break the loop.
MessageBox.Show("Unable to delete recursively, try checking registry permissions or running this app as administrator.", "RECURSIVE UPSTREAM ERROR");
return;
}
}
MessageBox.Show("Sucessfully removed the everything.\n\n You might need to restart the machine before the changes get applied.", "IFEO GONE DELETED");
RefreshTreeDisplay_Click(sender, e);
}
}
}
}