EaseFilter Demo Project
SettingsForm.cs
Go to the documentation of this file.
1 //
3 // (C) Copyright 2012 EaseFilter Technologies Inc.
4 // All Rights Reserved
5 //
6 // This software is part of a licensed software product and may
7 // only be used or copied in accordance with the terms of that license.
8 //
10 
11 using System;
12 using System.Collections.Generic;
13 using System.ComponentModel;
14 using System.Data;
15 using System.Drawing;
16 using System.Linq;
17 using System.Text;
18 using System.Windows.Forms;
19 
20 namespace EaseFilter.CommonObjects
21 {
22  public partial class SettingsForm : Form
23  {
24  public SettingsForm()
25  {
26  InitializeComponent();
27  InitOptionForm();
28  }
29 
30  private void InitOptionForm()
31  {
32  try
33  {
34  comboBox_EventLevel.Items.Clear();
35 
36  //General infomation
37  foreach (EventLevel item in Enum.GetValues(typeof(EventLevel)))
38  {
39  comboBox_EventLevel.Items.Add(item.ToString());
40 
41  if ((uint)item == (uint)GlobalConfig.EventLevel)
42  {
43  comboBox_EventLevel.SelectedItem = item.ToString();
44  }
45  }
46 
47  textBox_RequestRegistration.Text = GlobalConfig.RequestIORegistration.ToString();
48  textBox_MaximumFilterMessage.Text = GlobalConfig.MaximumFilterMessages.ToString();
49  textBox_TransactionLog.Text = GlobalConfig.FilterMessageLogName;
50  textBox_LogSize.Text = (GlobalConfig.FilterMessageLogFileSize/1024).ToString();
51  checkBox_TransactionLog.Checked = GlobalConfig.EnableLogTransaction;
52  checkBox_OutputMessageToConsole.Checked = GlobalConfig.OutputMessageToConsole;
53  checkBox_EnableNotification.Checked = GlobalConfig.EnableNotification;
54 
55  foreach (uint pid in GlobalConfig.IncludePidList)
56  {
57  if (textBox_IncludePID.Text.Length > 0)
58  {
59  textBox_IncludePID.Text += ";";
60  }
61 
62  textBox_IncludePID.Text += pid.ToString();
63  }
64 
65  foreach (uint pid in GlobalConfig.ExcludePidList)
66  {
67  if (textBox_ExcludePID.Text.Length > 0)
68  {
69  textBox_ExcludePID.Text += ";";
70  }
71 
72  textBox_ExcludePID.Text += pid.ToString();
73  }
74 
75  foreach (uint pid in GlobalConfig.ProtectPidList)
76  {
77  if (textBox_ProtectedPID.Text.Length > 0)
78  {
79  textBox_ProtectedPID.Text += ";";
80  }
81 
82  textBox_ProtectedPID.Text += pid.ToString();
83  }
84 
85  InitListView();
86 
87  }
88  catch (Exception ex)
89  {
90  MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
91  MessageBox.Show("Initialize the option form failed with error " + ex.Message, "Init options.", MessageBoxButtons.OK, MessageBoxIcon.Error);
92  }
93  }
94 
95  public void InitListView()
96  {
97  //init ListView control
98  listView_FilterRules.Clear(); //clear control
99  //create column header for ListView
100  listView_FilterRules.Columns.Add("#", 20, System.Windows.Forms.HorizontalAlignment.Left);
101  listView_FilterRules.Columns.Add("InlcudeFilterMask", 150, System.Windows.Forms.HorizontalAlignment.Left);
102  listView_FilterRules.Columns.Add("ExcludeFilterMask", 200, System.Windows.Forms.HorizontalAlignment.Left);
103  listView_FilterRules.Columns.Add("AccessFlags", 100, System.Windows.Forms.HorizontalAlignment.Left);
104 
105  foreach (FilterRule rule in GlobalConfig.FilterRules.Values)
106  {
107  AddItem(rule);
108  }
109 
110  }
111 
112  private void AddItem(FilterRule newRule)
113  {
114  string[] itemStr = new string[listView_FilterRules.Columns.Count];
115  itemStr[0] = listView_FilterRules.Items.Count.ToString();
116  itemStr[1] = newRule.IncludeFileFilterMask;
117  itemStr[2] = newRule.ExcludeFileFilterMasks;
118  itemStr[3] = newRule.AccessFlag.ToString();
119  ListViewItem item = new ListViewItem(itemStr, 0);
120  item.Tag = newRule;
121  listView_FilterRules.Items.Add(item);
122  }
123 
124  private void button_AddFilter_Click(object sender, EventArgs e)
125  {
126  string defaultAccessFlags = ((uint)FilterAPI.ALLOW_MAX_RIGHT_ACCESS ).ToString();
127  FilterRule filterRule = new FilterRule();
128  filterRule.IncludeFileFilterMask = "c:\\test\\*";
129  filterRule.ExcludeFileFilterMasks = "*.dll;*.exe";
130  filterRule.EventType = (uint)(FilterAPI.EVENTTYPE.CREATED|FilterAPI.EVENTTYPE.DELETED|FilterAPI.EVENTTYPE.RENAMED|FilterAPI.EVENTTYPE.WRITTEN);
131 
132  filterRule.MonitorIO = 2863311530;
133  filterRule.ControlIO = 2863311530;
134  filterRule.AccessFlag = (uint)FilterAPI.ALLOW_MAX_RIGHT_ACCESS ;
135 
136  FilterRuleForm filterRuleForm = new FilterRuleForm(filterRule);
137  filterRuleForm.StartPosition = FormStartPosition.CenterParent;
138  filterRuleForm.ShowDialog();
139 
140  InitListView();
141  }
142 
143  private void button_EditFilterRule_Click(object sender, EventArgs e)
144  {
145  if (listView_FilterRules.SelectedItems.Count != 1)
146  {
147  MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
148  MessageBox.Show("Please select one filter rule to edit.", "Edit Filter Rule", MessageBoxButtons.OK, MessageBoxIcon.Error);
149  return;
150  }
151 
152  System.Windows.Forms.ListViewItem item = listView_FilterRules.SelectedItems[0];
153  FilterRule filterRule = (FilterRule)item.Tag;
154 
155  FilterRuleForm filterRuleForm = new FilterRuleForm(filterRule);
156  filterRuleForm.StartPosition = FormStartPosition.CenterParent;
157  filterRuleForm.ShowDialog();
158 
159  InitListView();
160  }
161 
162  private void button_DeleteFilter_Click(object sender, EventArgs e)
163  {
164  if (listView_FilterRules.SelectedItems.Count == 0)
165  {
166  MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
167  MessageBox.Show("There are no filter rule selected.", "Delete Filter Rule", MessageBoxButtons.OK, MessageBoxIcon.Error);
168  return;
169  }
170 
171  foreach (System.Windows.Forms.ListViewItem item in listView_FilterRules.SelectedItems)
172  {
173  FilterRule filterRule = (FilterRule)item.Tag;
175  }
176 
177  InitListView();
178  }
179 
180 
181  private void button_ApplyOptions_Click(object sender, EventArgs e)
182  {
183  try
184  {
185 
186  GlobalConfig.RequestIORegistration = uint.Parse(textBox_RequestRegistration.Text);
187  GlobalConfig.MaximumFilterMessages = int.Parse(textBox_MaximumFilterMessage.Text);
188  GlobalConfig.EnableLogTransaction = checkBox_TransactionLog.Checked;
189  GlobalConfig.OutputMessageToConsole = checkBox_OutputMessageToConsole.Checked;
190  GlobalConfig.EnableNotification = checkBox_EnableNotification.Checked;
191  GlobalConfig.FilterMessageLogName = textBox_TransactionLog.Text;
192  GlobalConfig.FilterMessageLogFileSize = long.Parse(textBox_LogSize.Text) * 1024;
193  GlobalConfig.EventLevel = (EventLevel)comboBox_EventLevel.SelectedIndex;
194 
195  List<uint> inPids = new List<uint>();
196  if (textBox_IncludePID.Text.Length > 0)
197  {
198  if (textBox_IncludePID.Text.EndsWith(";"))
199  {
200  textBox_IncludePID.Text = textBox_IncludePID.Text.Remove(textBox_IncludePID.Text.Length - 1);
201  }
202 
203  string[] pids = textBox_IncludePID.Text.Split(new char[] { ';' });
204  for (int i = 0; i < pids.Length; i++)
205  {
206  inPids.Add(uint.Parse(pids[i].Trim()));
207  }
208  }
209 
210  GlobalConfig.IncludePidList = inPids;
211 
212  List<uint> exPids = new List<uint>();
213  if (textBox_ExcludePID.Text.Length > 0)
214  {
215  if (textBox_ExcludePID.Text.EndsWith(";"))
216  {
217  textBox_ExcludePID.Text = textBox_ExcludePID.Text.Remove(textBox_ExcludePID.Text.Length - 1);
218  }
219 
220  string[] pids = textBox_ExcludePID.Text.Split(new char[] { ';' });
221  for (int i = 0; i < pids.Length; i++)
222  {
223  exPids.Add(uint.Parse(pids[i].Trim()));
224  }
225  }
226  GlobalConfig.ExcludePidList = exPids;
227 
228  List<uint> protectPids = new List<uint>();
229  if (textBox_ProtectedPID.Text.Trim().Length > 0)
230  {
231  if (textBox_ProtectedPID.Text.EndsWith(";"))
232  {
233  textBox_ProtectedPID.Text = textBox_ProtectedPID.Text.Remove(textBox_ProtectedPID.Text.Length - 1);
234  }
235 
236  string[] pids = textBox_ProtectedPID.Text.Split(new char[] { ';' });
237  for (int i = 0; i < pids.Length; i++)
238  {
239  protectPids.Add(uint.Parse(pids[i].Trim()));
240  }
241  }
242 
243  GlobalConfig.ProtectPidList = protectPids;
244 
245  if (GlobalConfig.FilterRules.Count == 0)
246  {
247  MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
248  MessageBox.Show("There are no one filter rule added, the filter driver won't monitor any file.", "Filter Rule", MessageBoxButtons.OK, MessageBoxIcon.Warning);
249  }
250 
252 
253  this.Close();
254 
255  }
256  catch (Exception ex)
257  {
258  MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
259  MessageBox.Show("Save options failed with error " + ex.Message, "Save options.", MessageBoxButtons.OK, MessageBoxIcon.Error);
260  }
261  }
262 
263  private void button_SelectIncludePID_Click(object sender, EventArgs e)
264  {
265 
266  OptionForm optionForm = new OptionForm(OptionForm.OptionType.ProccessId, textBox_IncludePID.Text);
267 
268  if (optionForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
269  {
270  textBox_IncludePID.Text = optionForm.ProcessId;
271  }
272  }
273 
274  private void button_SelectExcludePID_Click(object sender, EventArgs e)
275  {
276 
277  OptionForm optionForm = new OptionForm(OptionForm.OptionType.ProccessId, textBox_ExcludePID.Text);
278 
279  if (optionForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
280  {
281  textBox_ExcludePID.Text = optionForm.ProcessId;
282  }
283  }
284 
285  private void button_RequestRegistration_Click(object sender, EventArgs e)
286  {
287  bool isMonitorFilter = false;
288  if (GlobalConfig.filterType == FilterAPI.FilterType.FILE_SYSTEM_MONITOR)
289  {
290  isMonitorFilter = true;
291  }
292 
293  OptionForm optionForm = new OptionForm(OptionForm.OptionType.Register_Request, GlobalConfig.RequestIORegistration.ToString(), isMonitorFilter);
294 
295  if (optionForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
296  {
297  textBox_RequestRegistration.Text = optionForm.RequestRegistration.ToString();
298  }
299  }
300 
301  private void button_SelectProtectPID_Click(object sender, EventArgs e)
302  {
303  OptionForm optionForm = new OptionForm(OptionForm.OptionType.ProccessId, textBox_ProtectedPID.Text);
304 
305  if (optionForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
306  {
307  textBox_ProtectedPID.Text = optionForm.ProcessId;
308  }
309  }
310 
311 
312 
313  }
314 }
static void RemoveFilterRule(string includeFilterMask)
uint EventType
The register the file I/O events
uint ControlIO
register control I/O requests, the filter driver will block and wait for the response.
static Dictionary< string, FilterRule > FilterRules
static FilterAPI.FilterType filterType
Definition: GlobalConfig.cs:79
uint MonitorIO
register monitor I/O requests

Social Network


Services Overview

Architect, implement and test file system filter drivers for a wide range of functionality. We can offer several levels of assistance to meet your specific.

Contact Us

You are welcome to contact us for salse or partnership.

Sales: sales@easefilter.com
Support: support@easefilter.com
Info: info@easefilter.com