EaseFilter Demo Project
CPlusPlusDemo.cpp
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 // CPlusPlusDemo.cpp : Defines the entry point for the console application.
12 //
13 
14 #include "stdafx.h"
15 #include "Tools.h"
16 #include "FilterAPI.h"
17 #include "UnitTest.h"
18 #include "AESEncryption.h"
19 #include "WindowsService.h"
20 #include "FilterWorker.h"
21 #include <Sddl.h>
22 
23 #define MAX_ERROR_MESSAGE_SIZE 1024
24 
25 #define PrintMessage wprintf //ToDebugger
26 
27 
28 VOID
30  VOID
31  )
32 /*++
33 
34 Routine Description
35 
36  Prints usage
37 
38 Arguments
39 
40  None
41 
42 Return Value
43 
44  None
45 
46 --*/
47 {
48  WCHAR computerId[26];
49  ULONG bufferLength = sizeof(computerId);
50 
51  if( GetUniqueComputerId((BYTE*)computerId,&bufferLength) )
52  {
53  wprintf(L"\nComputerId:%ws\n\n\n",computerId );
54  }
55  else
56  {
57  PrintLastErrorMessage( L"GetUniqueComputerId failed.");
58  printf( "\n\n" );
59  }
60 
61  printf( "\nUsage: EaseFltCPPDemo [command] <FilterFolder> <IoRegistration> <AccessFlag>\n" );
62  printf( "\nCommands:\n" );
63  printf( " i ----- Install Driver\n" );
64  printf( " u ----- UnInstall Driver\n" );
65  printf( " t ----- Driver UnitTest\n" );
66  printf( " m ----- Start monitor filter,require FilterFolder,IoRgistration, if it is empty,it will use default value.\n" );
67  printf( " c ----- Start control filter,require FilterFolder,IoRgistration,AccessFlag if it is empty,it will use default value.\n" );
68  printf( " e ----- Start encryption filter driver test,require FilterFolder,if it is empty,it will use default value.\n" );
69  printf( "\n [FilterFolder]---- the folder mask which will be monitored. By default is c:\\filterTest\\*\n" );
70  printf( " [IoRegistration]---- the I/O requests register to filter. By default is all post I/O.\n" );
71  printf( " [AccessFlag]---- the I/O access flag,only affect control filter. By default is ALLOW_MAX_RIGHT_ACCESS.\n" );
72  printf( "\r\nExample: EaseFltCPPDemo i ----- Install Driver\r\n" );
73  printf( "EaseFltCPPDemo u ----- UnInstall Driver\r\n" );
74  printf( "EaseFltCPPDemo t ----- Driver UnitTest\r\n" );
75  printf( "EaseFltCPPDemo m c:\\filterTest\\* ----- run the monitor filter driver\r\n" );
76 
77 }
78 
79 
80 int _tmain(int argc, _TCHAR* argv[])
81 {
82  DWORD threadCount = 5;
83  ULONG filterType = FILE_SYSTEM_MONITOR;
84  BOOL ret = FALSE;
85 
86  //Purchase a license key with the link: http://www.EaseFilter.com/Order.htm
87  //Email us to request a trial key: info@EaseFilter.com //free email is not accepted.
88  #define registerKey "************************"
89 
90  if(argc <= 1)
91  {
92  Usage();
93  return 1;
94  }
95 
96  TCHAR op = *argv[1];
97 
98  switch(op)
99  {
100 
101  /*How to run as windows service, do the following steps:
102  1.Create windows service: sc create filterService binpath= c:\easefilter\x64\cplusplusdemo.exe w,
103  replace the path with your own path,Note: binpath=(space)binarypath
104  2. cplusplusdemo.exe i //install the driver manully.
105  3. Sc start easefilter //start the windows service.
106  */
107  case 'w': //start windows service for the monitor filter
108  {
110  break;
111  }
112 
113  case 'i': //install driver
114  {
115  //Install the driver only once.
116  //After the installation, you can use command "fltmc unload EaseFlt" to unload the driver
117  //or "fltmc load EaseFlt" to load the driver, or "fltmc" to check the status of the driver.
118  ret = InstallDriver();
119  if( !ret )
120  {
121  PrintLastErrorMessage( L"InstallDriver failed.");
122  return 1;
123  }
124  break;
125  }
126 
127  case 'u': //uninstall driver
128  {
129  ret = UnInstallDriver();
130  if( !ret )
131  {
132  PrintLastErrorMessage( L"UnInstallDriver failed.");
133  return 1;
134  }
135 
136  break;
137 
138  }
139 
140  case 't': //driver unit test
141  {
142  ret = SetRegistrationKey(registerKey);
143  if( !ret )
144  {
145  PrintLastErrorMessage( L"SetRegistrationKey failed.");
146  return 1;
147  }
148 
149  ret = RegisterMessageCallback(threadCount,MessageCallback,DisconnectCallback);
150 
151  if( !ret )
152  {
153  PrintLastErrorMessage( L"RegisterMessageCallback failed.");
154  return 1;
155  }
156 
157  //this the demo how to use the control filter driver SDK.
159 
160 
161  Disconnect();
162 
163  break;
164 
165  }
166 
167  case 'c': filterType = FILE_SYSTEM_CONTROL; //start control filter
168  case 'm':
169  {
170 
171  /*ret = InstallDriver();
172  if( !ret )
173  {
174  PrintLastErrorMessage( L"InstallDriver failed.");
175  return 1;
176  }*/
177 
178  TCHAR* filterFolder = GetFilterMask();
179  ULONG ioRegistration = 0;
180  ULONG accessFlag = ALLOW_MAX_RIGHT_ACCESS;
181 
182  if( argc >= 3 )
183  {
184  filterFolder = argv[2];
185  }
186 
187  if( argc >= 4 )
188  {
189  ioRegistration = _ttoi(argv[3]);
190  }
191  else
192  {
193  //Register the I/O request,which will be monitored or will be called back from filter.
194  for (int i = 0; i < MAX_REQUEST_TYPE; i++ )
195  {
196  //register all post request
197  if( (double)i/2 != i/2 )
198  {
199  ioRegistration |= 1<<i;
200  }
201  }
202  }
203 
204  if( argc >= 5 )
205  {
206  accessFlag = _ttoi(argv[4]);
207  }
208 
209 
210  _tprintf(_T("Start Monitor %s ioregistration:0X%0X accessFlag:0X%0X\n\n Press any key to stop.\n"),filterFolder,ioRegistration,accessFlag);
211 
212  //Reset all filter confing setting.
213  ResetConfigData();
214 
215  ret = SetRegistrationKey(registerKey);
216  if( !ret )
217  {
218  PrintLastErrorMessage( L"SetRegistrationKey failed.");
219  return 1;
220  }
221 
222  ret = RegisterMessageCallback(threadCount,MessageCallback,DisconnectCallback);
223 
224  if( !ret )
225  {
226  PrintLastErrorMessage( L"RegisterMessageCallback failed.");
227  return 1;
228  }
229 
230  //this the demo how to use the control filter.
231  SendConfigInfoToFilter(filterType,filterFolder,ioRegistration,accessFlag);
232 
233  //prevent the current process from being terminated.
234  AddProtectedProcessId(GetCurrentProcessId());
235 
236  system("pause");
237 
238  //the process can be termiated now.
239  RemoveProtectedProcessId(GetCurrentProcessId());
240 
241 
242 
243  Disconnect();
244 
245  break;
246 
247  }
248  case 'e': //encryption filter driver test
249  {
250 
251  UnInstallDriver();
252 
253  ret = InstallDriver();
254  if( !ret )
255  {
256  PrintLastErrorMessage( L"InstallDriver failed.");
257  return 1;
258  }
259 
260  TCHAR* filterFolder = GetFilterMask();
261  ULONG ioRegistration = 0;
262  ULONG accessFlag = ALLOW_MAX_RIGHT_ACCESS|FILE_ENCRYPTION_RULE;
263 
264  filterType = FILE_SYSTEM_ENCRYPTION;
265 
266  if( argc >= 3 )
267  {
268  filterFolder = argv[2];
269  }
270 
271  //Reset all filter confing setting.
272  ResetConfigData();
273 
274  ret = SetRegistrationKey(registerKey);
275  if( !ret )
276  {
277  PrintLastErrorMessage( L"SetRegistrationKey failed.");
278  return 1;
279  }
280 
281  ret = RegisterMessageCallback(threadCount,MessageCallback,DisconnectCallback);
282 
283  if( !ret )
284  {
285  PrintLastErrorMessage( L"RegisterMessageCallback failed.");
286  return 1;
287  }
288 
289  //prevent the current process from being terminated.
290  //AddProtectedProcessId(GetCurrentProcessId());
291 
292  // 32bytes encrytpion key
293  UCHAR key[] = {0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4};
294 
295  //this the demo how to use the control filter.
296  SendConfigInfoToFilter(filterType,filterFolder,ioRegistration,accessFlag,key,sizeof(key));
297 
298  //this the demo how to use the control filter.
300 
301  _tprintf(_T("\n\nStart Encryption for folder %s,\r\nAll new created files in this folder will be encrypted by filter driver. When filter driver is stopped, the encrypted files can't be read. \n\n Press any key to stop the filter driver.\n"),filterFolder);
302  system("pause");
303 
304  //the process can be termiated now.
305  //RemoveProtectedProcessId(GetCurrentProcessId());
306 
307  Disconnect();
308 
309  break;
310 
311  }
312  default:
313  {
314  Usage();
315  return 1;
316  }
317 
318 
319  }
320 
321 
322  return 0;
323 }
324 
unsigned char key[]
BYTE ULONG bufferLength
Definition: FilterAPI.h:812
#define MAX_REQUEST_TYPE
Definition: FilterAPI.h:133
WCHAR * GetFilterMask()
Definition: FeatureDemo.cpp:56
int _tmain(int argc, _TCHAR *argv[])
int StartWindowsService()
Proto_Message_Callback Proto_Disconnect_Callback DisconnectCallback
Definition: FilterAPI.h:508
void ControlFilterUnitTest()
Definition: UnitTest.cpp:1246
void PrintLastErrorMessage(WCHAR *message)
Definition: Tools.cpp:49
Proto_Message_Callback MessageCallback
Definition: FilterAPI.h:508
void SendConfigInfoToFilter(ULONG FilterType, WCHAR *FilterFolder, ULONG IoRegistration, ULONG AccessFlag, UCHAR *encryptionKey, ULONG keyLength)
VOID Usage(VOID)
#define registerKey
VOID EncryptionUnitTest()

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