EaseFilter Demo Project
OptionForm.cs
Go to the documentation of this file.
1 //
3 // (C) Copyright 2011 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.Text;
17 using System.Windows.Forms;
18 using System.Diagnostics;
19 using System.Globalization;
20 
21 namespace EaseFilter.CommonObjects
22 {
23  public partial class OptionForm : Form
24  {
25  OptionType optionType = OptionType.Register_Request;
26  string value = string.Empty;
27 
28  uint requestRegistration = 0;
29  string processId = "0";
30  uint accessFlags = 0;
31  uint debugModules = 0xffff;
32  uint filterStatus = 0;
33  uint returnStatus = 0;
34  uint eventNotification = 0;
35  uint shareAccessFlags = 0;
36 
37  public bool isMonitorFilter = false;
38 
39  public enum OptionType
40  {
41  Register_Request = 0,
42  ProccessId,
43  Access_Flag,
44  Filter_Status,
45  Return_Status,
46  EventNotification,
47  ShareAccessOption,
48  }
49 
50  public OptionForm(OptionType formType, string defaultValue, bool _isMoitorFilter)
51  {
52  this.optionType = formType;
53  this.value = defaultValue;
54  this.isMonitorFilter = _isMoitorFilter;
55 
56  InitializeComponent();
57  InitForm();
58  }
59 
60  public OptionForm(OptionType formType,string defaultValue)
61  {
62  this.optionType = formType;
63  this.value = defaultValue;
64 
65  InitializeComponent();
66  InitForm();
67  }
68 
69  public uint ShareAccessFlags
70  {
71  get { return shareAccessFlags; }
72  }
73 
74  public uint EventNotification
75  {
76  get { return eventNotification; }
77  }
78 
79  public uint FilterStatus
80  {
81  get { return filterStatus; }
82  }
83  public uint ReturnStatus
84  {
85  get { return returnStatus; }
86  }
87 
88  public uint RequestRegistration
89  {
90  get { return requestRegistration; }
91  }
92 
93  public string ProcessId
94  {
95  get { return processId; }
96  }
97 
98 
99  public uint AccessFlags
100  {
101  get { return accessFlags; }
102  }
103 
104  public uint DebugModules
105  {
106  get { return debugModules; }
107  }
108 
109 
110  void InitForm()
111  {
112  this.Text = optionType.ToString();
113 
114  switch (optionType)
115  {
116  case OptionType.EventNotification:
117  {
118  listView1.Clear(); //clear control
119  //create column header for ListView
120  listView1.Columns.Add("Select file event type", 200, System.Windows.Forms.HorizontalAlignment.Left);
121 
122  eventNotification = uint.Parse(value);
123 
124  foreach (FilterAPI.EVENTTYPE eventType in Enum.GetValues(typeof(FilterAPI.EVENTTYPE)))
125  {
126 
127  if (eventType == FilterAPI.EVENTTYPE.NONE)
128  {
129  continue;
130  }
131 
132  string item = eventType.ToString();
133 
134  ListViewItem lvItem = new ListViewItem(item, 0);
135  lvItem.Tag = eventType;
136 
137  if ((eventNotification & (uint)eventType) > 0)
138  {
139  lvItem.Checked = true;
140  }
141 
142  listView1.Items.Add(lvItem);
143  }
144 
145  break;
146  }
147 
148  case OptionType.Register_Request:
149  {
150  listView1.Clear(); //clear control
151  //create column header for ListView
152  listView1.Columns.Add("Select Register I/O type", 400, System.Windows.Forms.HorizontalAlignment.Left);
153 
154  requestRegistration = uint.Parse(value);
155 
156  foreach (FilterAPI.MessageType messageType in Enum.GetValues(typeof(FilterAPI.MessageType)))
157  {
158  string item = messageType.ToString();
159 
160  if (item.ToLower().StartsWith("pre") && isMonitorFilter)
161  {
162  //for monitor filter, it only can register the post I/O request notification.
163  continue;
164  }
165 
166  ListViewItem lvItem = new ListViewItem(item, 0);
167  lvItem.Tag = messageType;
168 
169  if ((requestRegistration & (uint)messageType) > 0)
170  {
171  lvItem.Checked = true;
172  }
173 
174  listView1.Items.Add(lvItem);
175  }
176 
177  break;
178  }
179 
180  case OptionType.ProccessId:
181  {
182  Process[] processlist = Process.GetProcesses();
183 
184  listView1.Clear(); //clear control
185  //create column header for ListView
186  listView1.Columns.Add("Process Id", 100, System.Windows.Forms.HorizontalAlignment.Left);
187  listView1.Columns.Add("Process Name", 300, System.Windows.Forms.HorizontalAlignment.Left);
188 
189  List<uint> pidList = new List<uint>();
190 
191  string[] pids = value.Split(';');
192  foreach (string pid in pids)
193  {
194  if (!string.IsNullOrEmpty(pid))
195  {
196  pidList.Add(uint.Parse(pid));
197  }
198  }
199 
200 
201  for (int i = 0; i < processlist.Length; i++)
202  {
203  string[] item = new string[2];
204  item[0] = processlist[i].Id.ToString();
205  item[1] = processlist[i].ProcessName;
206 
207  ListViewItem lvItem = new ListViewItem(item, 0);
208 
209  lvItem.Tag = processlist[i].Id;
210 
211  if (pidList.Contains((uint)(processlist[i].Id)))
212  {
213  lvItem.Checked = true;
214  }
215 
216  listView1.Items.Add(lvItem);
217 
218  }
219 
220  break;
221  }
222 
223  case OptionType.Access_Flag:
224  {
225  listView1.Clear(); //clear control
226  //create column header for ListView
227  listView1.Columns.Add("Select AccessFlag", 400, System.Windows.Forms.HorizontalAlignment.Left);
228 
229  accessFlags = uint.Parse(value);
230 
231  foreach (FilterAPI.AccessFlag accessFlag in Enum.GetValues(typeof(FilterAPI.AccessFlag)))
232  {
233  if (accessFlag < FilterAPI.AccessFlag.FILE_ENCRYPTION_RULE )
234  {
235  //this is special usage for the filter
236  continue;
237  }
238 
239  string item = accessFlag.ToString();
240  ListViewItem lvItem = new ListViewItem(item, 0);
241  lvItem.Tag = accessFlag;
242 
243  if (((uint)accessFlag & accessFlags) > 0)
244  {
245  lvItem.Checked = true;
246  }
247 
248  listView1.Items.Add(lvItem);
249  }
250 
251  break;
252  }
253 
254  case OptionType.ShareAccessOption:
255  {
256  listView1.Clear(); //clear control
257  //create column header for ListView
258  listView1.Columns.Add("Select AccessFlag", 400, System.Windows.Forms.HorizontalAlignment.Left);
259 
260  shareAccessFlags = uint.Parse(value);
261 
262  foreach (FilterAPI.SecureFileAccessRights accessFlag in Enum.GetValues(typeof(FilterAPI.SecureFileAccessRights)))
263  {
264  string item = accessFlag.ToString();
265  ListViewItem lvItem = new ListViewItem(item, 0);
266  lvItem.Tag = accessFlag;
267 
268  if (((uint)accessFlag & shareAccessFlags) > 0)
269  {
270  lvItem.Checked = true;
271  }
272 
273  listView1.Items.Add(lvItem);
274  }
275 
276  break;
277  }
278 
279 
280  case OptionType.Filter_Status:
281  {
282  listView1.Clear(); //clear control
283  //create column header for ListView
284  listView1.Columns.Add("Select Filter Status", 400, System.Windows.Forms.HorizontalAlignment.Left);
285 
286  filterStatus = uint.Parse(value);
287 
288  foreach (FilterAPI.FilterStatus status in Enum.GetValues(typeof(FilterAPI.FilterStatus)))
289  {
290  string item = status.ToString();
291  ListViewItem lvItem = new ListViewItem(item, 0);
292  lvItem.Tag = status;
293 
294  if (((uint)status & filterStatus) > 0)
295  {
296  lvItem.Checked = true;
297  }
298 
299  listView1.Items.Add(lvItem);
300  }
301 
302  break;
303  }
304 
305  case OptionType.Return_Status:
306  {
307  listView1.Clear(); //clear control
308  //create column header for ListView
309  listView1.Columns.Add("Select Only One Status", 400, System.Windows.Forms.HorizontalAlignment.Left);
310 
311  returnStatus = uint.Parse(value);
312 
313  foreach (NtStatus.Status status in Enum.GetValues(typeof(NtStatus.Status)))
314  {
315  string item = status.ToString();
316  ListViewItem lvItem = new ListViewItem(item, 0);
317  lvItem.Tag = status;
318 
319  if (((uint)status & filterStatus) > 0)
320  {
321  lvItem.Checked = true;
322  }
323 
324  listView1.Items.Add(lvItem);
325  }
326 
327  break;
328  }
329  }
330  }
331 
332  private void button_Ok_Click(object sender, EventArgs e)
333  {
334  requestRegistration = 0;
335  processId = string.Empty;
336  accessFlags = 0;
337  debugModules = 0;
338  eventNotification = 0;
339  shareAccessFlags = 0;
340 
341  foreach (ListViewItem item in listView1.CheckedItems)
342  {
343  switch (optionType)
344  {
345  case OptionType.EventNotification:
346  eventNotification |= (uint)item.Tag;
347  break;
348 
349  case OptionType.Register_Request:
350  requestRegistration |= (uint)item.Tag;
351  break;
352  case OptionType.ProccessId:
353  int pid = (int)item.Tag;
354  processId += pid.ToString() + ";";
355  break;
356 
357  case OptionType.Access_Flag:
358  accessFlags |= (uint)item.Tag;
359  break;
360 
361  case OptionType.ShareAccessOption:
362  shareAccessFlags |= (uint)item.Tag;
363  break;
364 
365  case OptionType.Filter_Status:
366  filterStatus |= (uint)item.Tag;
367  break;
368 
369  case OptionType.Return_Status:
370  returnStatus |= (uint)item.Tag;
371  return;
372  }
373  }
374 
375  }
376 
377  private void button_SelectAll_Click(object sender, EventArgs e)
378  {
379  foreach (ListViewItem item in listView1.Items)
380  {
381  item.Checked = true;
382  }
383  }
384 
385  private void button_ClearAll_Click(object sender, EventArgs e)
386  {
387  foreach (ListViewItem item in listView1.Items)
388  {
389  item.Checked = false;
390  }
391  }
392 
393 
394  }
395 }
OptionForm(OptionType formType, string defaultValue, bool _isMoitorFilter)
Definition: OptionForm.cs:50
enum _FilterStatus FilterStatus
Status
A NT status value.
Definition: NtStatus.cs:23
ULONG eventType
Definition: FilterAPI.h:584
OptionForm(OptionType formType, string defaultValue)
Definition: OptionForm.cs:60

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