sl@0
|
1 |
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// f32test\virus\t_vshook.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include "t_vshook.h"
|
sl@0
|
19 |
#include <f32pluginutils.h>
|
sl@0
|
20 |
|
sl@0
|
21 |
|
sl@0
|
22 |
_LIT(KVirusScannerName, "This is a test virus scanner");
|
sl@0
|
23 |
|
sl@0
|
24 |
|
sl@0
|
25 |
/**
|
sl@0
|
26 |
Leaving New function for the plugin
|
sl@0
|
27 |
@internalComponent
|
sl@0
|
28 |
*/
|
sl@0
|
29 |
CTestVirusHook* CTestVirusHook::NewL()
|
sl@0
|
30 |
{
|
sl@0
|
31 |
return new(ELeave) CTestVirusHook;
|
sl@0
|
32 |
}
|
sl@0
|
33 |
|
sl@0
|
34 |
|
sl@0
|
35 |
/**
|
sl@0
|
36 |
Constructor for the plugin
|
sl@0
|
37 |
@internalComponent
|
sl@0
|
38 |
*/
|
sl@0
|
39 |
CTestVirusHook::CTestVirusHook()
|
sl@0
|
40 |
{
|
sl@0
|
41 |
// RDebug::Print(_L("EMaxClientOperations %d, size of CFsPlugin %d, iSignatureOffset %d"), EMaxClientOperations, sizeof(CFsPlugin), _FOFF(CTestVirusHook, iSignature));
|
sl@0
|
42 |
ASSERT(iSignature == 0);
|
sl@0
|
43 |
iSignature = 0x1234;
|
sl@0
|
44 |
}
|
sl@0
|
45 |
|
sl@0
|
46 |
|
sl@0
|
47 |
/**
|
sl@0
|
48 |
The destructor for the test virus scanner hook. This would
|
sl@0
|
49 |
not be a part of a normal virus scanner implementation as
|
sl@0
|
50 |
normal virus scanners cannot be unloaded - it must be
|
sl@0
|
51 |
provided in the test virus scanner server so that it can
|
sl@0
|
52 |
be tested with the F32 test suite.
|
sl@0
|
53 |
@internalComponent
|
sl@0
|
54 |
*/
|
sl@0
|
55 |
CTestVirusHook::~CTestVirusHook()
|
sl@0
|
56 |
{
|
sl@0
|
57 |
iFs.Close();
|
sl@0
|
58 |
|
sl@0
|
59 |
for (TInt i = 0; i < iSignaturesLoaded; i++)
|
sl@0
|
60 |
{
|
sl@0
|
61 |
if (iKnownSignatures[i])
|
sl@0
|
62 |
{
|
sl@0
|
63 |
delete iKnownSignatures[i];
|
sl@0
|
64 |
}
|
sl@0
|
65 |
}
|
sl@0
|
66 |
ASSERT(iSignature == 0x1234);
|
sl@0
|
67 |
}
|
sl@0
|
68 |
|
sl@0
|
69 |
/**
|
sl@0
|
70 |
Initialise the virus scanner.
|
sl@0
|
71 |
Reads the virus definition file and then waits for
|
sl@0
|
72 |
notification that files containing a virus have been
|
sl@0
|
73 |
detected.
|
sl@0
|
74 |
@internalComponent
|
sl@0
|
75 |
*/
|
sl@0
|
76 |
void CTestVirusHook::InitialiseL()
|
sl@0
|
77 |
{
|
sl@0
|
78 |
User::LeaveIfError(RegisterIntercept(EFsFileOpen, EPreIntercept));
|
sl@0
|
79 |
User::LeaveIfError(RegisterIntercept(EFsFileSubClose, EPostIntercept));
|
sl@0
|
80 |
User::LeaveIfError(RegisterIntercept(EFsFileRename, EPreIntercept));
|
sl@0
|
81 |
User::LeaveIfError(RegisterIntercept(EFsRename, EPreIntercept));
|
sl@0
|
82 |
User::LeaveIfError(RegisterIntercept(EFsDelete, EPreIntercept));
|
sl@0
|
83 |
User::LeaveIfError(RegisterIntercept(EFsReplace, EPreIntercept));
|
sl@0
|
84 |
User::LeaveIfError(RegisterIntercept(EFsReadFileSection, EPreIntercept));
|
sl@0
|
85 |
|
sl@0
|
86 |
ReadVirusDefinitionFile();
|
sl@0
|
87 |
}
|
sl@0
|
88 |
|
sl@0
|
89 |
/**
|
sl@0
|
90 |
Read the virus definition file C:\virusdef.txt and parse
|
sl@0
|
91 |
its contents. Any virus definitions found in that file
|
sl@0
|
92 |
are added to the KnownSignatures array so they can be
|
sl@0
|
93 |
used by the virus scanning hook.
|
sl@0
|
94 |
|
sl@0
|
95 |
@internalComponent
|
sl@0
|
96 |
|
sl@0
|
97 |
@return KErrNone if the file was read and parsed
|
sl@0
|
98 |
successfuly.
|
sl@0
|
99 |
*/
|
sl@0
|
100 |
TInt CTestVirusHook::ReadVirusDefinitionFile()
|
sl@0
|
101 |
{
|
sl@0
|
102 |
TInt r = iFs.Connect();
|
sl@0
|
103 |
if (r != KErrNone)
|
sl@0
|
104 |
return r;
|
sl@0
|
105 |
|
sl@0
|
106 |
r = iFs.SetNotifyChange(EFalse); // Disable change notifications
|
sl@0
|
107 |
if (r != KErrNone)
|
sl@0
|
108 |
return r;
|
sl@0
|
109 |
|
sl@0
|
110 |
//Open the virus definition file
|
sl@0
|
111 |
RFile vsDefFile;
|
sl@0
|
112 |
r = vsDefFile.Open(iFs, _L("C:\\virusdef.txt"), EFileShareAny);
|
sl@0
|
113 |
if (r != KErrNone)
|
sl@0
|
114 |
return r;
|
sl@0
|
115 |
|
sl@0
|
116 |
TInt fileSize=0;
|
sl@0
|
117 |
r = vsDefFile.Size(fileSize);
|
sl@0
|
118 |
if (r != KErrNone)
|
sl@0
|
119 |
{
|
sl@0
|
120 |
vsDefFile.Close();
|
sl@0
|
121 |
return r;
|
sl@0
|
122 |
}
|
sl@0
|
123 |
|
sl@0
|
124 |
HBufC8* defBuf=NULL;
|
sl@0
|
125 |
|
sl@0
|
126 |
TRAP(r,defBuf = HBufC8::NewL(fileSize));
|
sl@0
|
127 |
if (r != KErrNone)
|
sl@0
|
128 |
{
|
sl@0
|
129 |
vsDefFile.Close();
|
sl@0
|
130 |
return r;
|
sl@0
|
131 |
}
|
sl@0
|
132 |
|
sl@0
|
133 |
TPtr8 ptr(defBuf->Des());
|
sl@0
|
134 |
r = vsDefFile.Read(ptr);
|
sl@0
|
135 |
if (r != KErrNone)
|
sl@0
|
136 |
{
|
sl@0
|
137 |
delete defBuf;
|
sl@0
|
138 |
vsDefFile.Close();
|
sl@0
|
139 |
return r;
|
sl@0
|
140 |
}
|
sl@0
|
141 |
|
sl@0
|
142 |
//Now parse the definition file, putting the definitions into the hook's
|
sl@0
|
143 |
//array of known virus signatures.
|
sl@0
|
144 |
TInt bytesParsed = 0;
|
sl@0
|
145 |
TInt stringBeginPos = 0;
|
sl@0
|
146 |
TInt stringEndPos = 0;
|
sl@0
|
147 |
TInt stringLength = 0;
|
sl@0
|
148 |
HBufC8* signatureBuf = NULL;
|
sl@0
|
149 |
while (bytesParsed < fileSize)
|
sl@0
|
150 |
{
|
sl@0
|
151 |
ptr.Set(defBuf->Des());
|
sl@0
|
152 |
ptr.Set(&ptr[bytesParsed], fileSize-bytesParsed, fileSize-bytesParsed);
|
sl@0
|
153 |
stringBeginPos = ptr.MatchF(_L8("startdef:*:enddef*"));
|
sl@0
|
154 |
|
sl@0
|
155 |
if (stringBeginPos < 0)
|
sl@0
|
156 |
{
|
sl@0
|
157 |
break;
|
sl@0
|
158 |
}
|
sl@0
|
159 |
|
sl@0
|
160 |
stringBeginPos += 9; //stardef:
|
sl@0
|
161 |
stringBeginPos += bytesParsed;
|
sl@0
|
162 |
ptr.Set(defBuf->Des());
|
sl@0
|
163 |
ptr.Set(&ptr[stringBeginPos], fileSize-stringBeginPos, fileSize-stringBeginPos);
|
sl@0
|
164 |
stringEndPos = ptr.MatchF(_L8("*:enddef*"));
|
sl@0
|
165 |
|
sl@0
|
166 |
if (stringEndPos < 0)
|
sl@0
|
167 |
{
|
sl@0
|
168 |
break;
|
sl@0
|
169 |
}
|
sl@0
|
170 |
|
sl@0
|
171 |
stringEndPos += 9; //stardef:
|
sl@0
|
172 |
stringEndPos += bytesParsed;
|
sl@0
|
173 |
stringLength = stringEndPos - stringBeginPos;
|
sl@0
|
174 |
|
sl@0
|
175 |
ptr.Set(defBuf->Des());
|
sl@0
|
176 |
TRAP(r,signatureBuf = HBufC8::NewL(stringLength));
|
sl@0
|
177 |
|
sl@0
|
178 |
TPtrC8 actualSig(ptr.Mid(stringBeginPos, stringLength));
|
sl@0
|
179 |
|
sl@0
|
180 |
TPtr8 ptr2(signatureBuf->Des());
|
sl@0
|
181 |
ptr2.Append(actualSig);
|
sl@0
|
182 |
iKnownSignatures[iSignaturesLoaded] = signatureBuf;
|
sl@0
|
183 |
iSignaturesLoaded++;
|
sl@0
|
184 |
|
sl@0
|
185 |
bytesParsed += 9; //startdef:
|
sl@0
|
186 |
bytesParsed += stringLength;
|
sl@0
|
187 |
bytesParsed += 9; //:enddef\n
|
sl@0
|
188 |
}
|
sl@0
|
189 |
|
sl@0
|
190 |
//Cleanup
|
sl@0
|
191 |
delete defBuf;
|
sl@0
|
192 |
vsDefFile.Close();
|
sl@0
|
193 |
|
sl@0
|
194 |
return r;
|
sl@0
|
195 |
}
|
sl@0
|
196 |
|
sl@0
|
197 |
/**
|
sl@0
|
198 |
@internalComponent
|
sl@0
|
199 |
*/
|
sl@0
|
200 |
TInt CTestVirusHook::DoRequestL(TFsPluginRequest& aRequest)
|
sl@0
|
201 |
{
|
sl@0
|
202 |
TInt err = KErrNotSupported;
|
sl@0
|
203 |
|
sl@0
|
204 |
TInt function = aRequest.Function();
|
sl@0
|
205 |
|
sl@0
|
206 |
iDrvNumber = aRequest.DriveNumber();
|
sl@0
|
207 |
|
sl@0
|
208 |
switch(function)
|
sl@0
|
209 |
{
|
sl@0
|
210 |
case EFsFileOpen:
|
sl@0
|
211 |
err = VsFileOpen(aRequest);
|
sl@0
|
212 |
break;
|
sl@0
|
213 |
|
sl@0
|
214 |
case EFsFileSubClose:
|
sl@0
|
215 |
VsFileClose(aRequest);
|
sl@0
|
216 |
break;
|
sl@0
|
217 |
|
sl@0
|
218 |
case EFsFileRename:
|
sl@0
|
219 |
case EFsRename:
|
sl@0
|
220 |
case EFsReplace:
|
sl@0
|
221 |
err = VsFileRename(aRequest);
|
sl@0
|
222 |
break;
|
sl@0
|
223 |
|
sl@0
|
224 |
case EFsDelete:
|
sl@0
|
225 |
err = VsFileDelete(aRequest);
|
sl@0
|
226 |
break;
|
sl@0
|
227 |
|
sl@0
|
228 |
case EFsReadFileSection:
|
sl@0
|
229 |
err = VsReadFileSection(aRequest);
|
sl@0
|
230 |
break;
|
sl@0
|
231 |
|
sl@0
|
232 |
default:
|
sl@0
|
233 |
break;
|
sl@0
|
234 |
}
|
sl@0
|
235 |
|
sl@0
|
236 |
return err;
|
sl@0
|
237 |
}
|
sl@0
|
238 |
|
sl@0
|
239 |
|
sl@0
|
240 |
/**
|
sl@0
|
241 |
@internalComponent
|
sl@0
|
242 |
*/
|
sl@0
|
243 |
TInt CTestVirusHook::VsFileOpen(TFsPluginRequest& aRequest)
|
sl@0
|
244 |
{
|
sl@0
|
245 |
TFileName fileName;
|
sl@0
|
246 |
TInt err = ValidateRequest(aRequest, fileName);
|
sl@0
|
247 |
if (err == KErrNone)
|
sl@0
|
248 |
{
|
sl@0
|
249 |
err = ScanFile(fileName);
|
sl@0
|
250 |
if (err != KErrNone)
|
sl@0
|
251 |
{
|
sl@0
|
252 |
// Clean the infected file
|
sl@0
|
253 |
CleanFile(fileName, EFileOpen);
|
sl@0
|
254 |
}
|
sl@0
|
255 |
}
|
sl@0
|
256 |
|
sl@0
|
257 |
return err;
|
sl@0
|
258 |
}
|
sl@0
|
259 |
|
sl@0
|
260 |
/**
|
sl@0
|
261 |
@internalComponent
|
sl@0
|
262 |
*/
|
sl@0
|
263 |
void CTestVirusHook::VsFileClose(TFsPluginRequest& aRequest)
|
sl@0
|
264 |
{
|
sl@0
|
265 |
TFileName fileName;
|
sl@0
|
266 |
TInt err = GetName(&aRequest, fileName);
|
sl@0
|
267 |
if(err == KErrNone)
|
sl@0
|
268 |
{
|
sl@0
|
269 |
err = ScanFile(fileName);
|
sl@0
|
270 |
if (err != KErrNone)
|
sl@0
|
271 |
{
|
sl@0
|
272 |
// Clean the infected file
|
sl@0
|
273 |
CleanFile(fileName, EFileClose);
|
sl@0
|
274 |
}
|
sl@0
|
275 |
}
|
sl@0
|
276 |
}
|
sl@0
|
277 |
|
sl@0
|
278 |
/**
|
sl@0
|
279 |
@internalComponent
|
sl@0
|
280 |
*/
|
sl@0
|
281 |
TInt CTestVirusHook::VsFileRename(TFsPluginRequest& aRequest)
|
sl@0
|
282 |
{
|
sl@0
|
283 |
|
sl@0
|
284 |
TInt err = VsDirRename(aRequest);
|
sl@0
|
285 |
if(err != KErrAccessDenied)
|
sl@0
|
286 |
{
|
sl@0
|
287 |
TFileName fileName;
|
sl@0
|
288 |
err = ValidateRequest(aRequest, fileName);
|
sl@0
|
289 |
if (err == KErrNone)
|
sl@0
|
290 |
{
|
sl@0
|
291 |
err = ScanFile(fileName);
|
sl@0
|
292 |
if (err != KErrNone)
|
sl@0
|
293 |
{
|
sl@0
|
294 |
// Clean the infected file
|
sl@0
|
295 |
CleanFile(fileName, EFileRename);
|
sl@0
|
296 |
}
|
sl@0
|
297 |
}
|
sl@0
|
298 |
}
|
sl@0
|
299 |
|
sl@0
|
300 |
return err;
|
sl@0
|
301 |
}
|
sl@0
|
302 |
|
sl@0
|
303 |
/**
|
sl@0
|
304 |
@internalComponent
|
sl@0
|
305 |
*/
|
sl@0
|
306 |
TInt CTestVirusHook::VsDirRename(TFsPluginRequest& aRequest)
|
sl@0
|
307 |
{
|
sl@0
|
308 |
|
sl@0
|
309 |
TFileName fileName;
|
sl@0
|
310 |
TInt err = GetName(&aRequest, fileName);
|
sl@0
|
311 |
if(err != KErrNone)
|
sl@0
|
312 |
return(err);
|
sl@0
|
313 |
|
sl@0
|
314 |
err = fileName.Find(_L("\\system\\lib\\"));
|
sl@0
|
315 |
if (err != KErrNotFound)
|
sl@0
|
316 |
{
|
sl@0
|
317 |
//Don't allow sys\bin to be ever renamed
|
sl@0
|
318 |
return KErrAccessDenied;
|
sl@0
|
319 |
}
|
sl@0
|
320 |
err = fileName.Find(_L("\\sys\\bin\\"));
|
sl@0
|
321 |
if (err != KErrNotFound)
|
sl@0
|
322 |
{
|
sl@0
|
323 |
//Don't allow sys\bin to be ever renamed
|
sl@0
|
324 |
return KErrAccessDenied;
|
sl@0
|
325 |
}
|
sl@0
|
326 |
|
sl@0
|
327 |
return err;
|
sl@0
|
328 |
}
|
sl@0
|
329 |
|
sl@0
|
330 |
/**
|
sl@0
|
331 |
@internalComponent
|
sl@0
|
332 |
*/
|
sl@0
|
333 |
TInt CTestVirusHook::VsFileDelete(TFsPluginRequest& aRequest)
|
sl@0
|
334 |
{
|
sl@0
|
335 |
|
sl@0
|
336 |
TFileName fileName;
|
sl@0
|
337 |
TInt err = ValidateRequest(aRequest, fileName);
|
sl@0
|
338 |
return err;
|
sl@0
|
339 |
}
|
sl@0
|
340 |
|
sl@0
|
341 |
/**
|
sl@0
|
342 |
@internalComponent
|
sl@0
|
343 |
*/
|
sl@0
|
344 |
TInt CTestVirusHook::VsReadFileSection(TFsPluginRequest& aRequest)
|
sl@0
|
345 |
{
|
sl@0
|
346 |
|
sl@0
|
347 |
// The t_virus test uses a filename clean.txt, a read length of 8 and a read position of 0.
|
sl@0
|
348 |
TFileName fileName;
|
sl@0
|
349 |
TInt len;
|
sl@0
|
350 |
TInt pos;
|
sl@0
|
351 |
|
sl@0
|
352 |
// test getting name on read file section intercept
|
sl@0
|
353 |
TInt err = GetName(&aRequest, fileName);
|
sl@0
|
354 |
if(err != KErrNone)
|
sl@0
|
355 |
{
|
sl@0
|
356 |
return(err);
|
sl@0
|
357 |
}
|
sl@0
|
358 |
TParse parse;
|
sl@0
|
359 |
parse.Set(fileName,NULL,NULL);
|
sl@0
|
360 |
TPtrC name = parse.Name();
|
sl@0
|
361 |
if(name.CompareF(_L("clean"))!=0)
|
sl@0
|
362 |
{
|
sl@0
|
363 |
return(KErrGeneral);
|
sl@0
|
364 |
}
|
sl@0
|
365 |
TPtrC ext = parse.Ext();
|
sl@0
|
366 |
if(ext.CompareF(_L(".txt"))!=0)
|
sl@0
|
367 |
{
|
sl@0
|
368 |
return(KErrGeneral);
|
sl@0
|
369 |
}
|
sl@0
|
370 |
|
sl@0
|
371 |
// test getting read length and required file position on read file section intercept
|
sl@0
|
372 |
err = GetFileAccessInfo(&aRequest, len, pos);
|
sl@0
|
373 |
if(err != KErrNone)
|
sl@0
|
374 |
{
|
sl@0
|
375 |
return(err);
|
sl@0
|
376 |
}
|
sl@0
|
377 |
if ((len != 8) || (pos != 0))
|
sl@0
|
378 |
{
|
sl@0
|
379 |
return(KErrGeneral);
|
sl@0
|
380 |
}
|
sl@0
|
381 |
|
sl@0
|
382 |
return KErrNone;
|
sl@0
|
383 |
}
|
sl@0
|
384 |
|
sl@0
|
385 |
|
sl@0
|
386 |
/**
|
sl@0
|
387 |
@internalComponent
|
sl@0
|
388 |
*/
|
sl@0
|
389 |
TInt CTestVirusHook::VirusScannerName(TDes& aName)
|
sl@0
|
390 |
{
|
sl@0
|
391 |
aName = KVirusScannerName;
|
sl@0
|
392 |
return KErrNone;
|
sl@0
|
393 |
}
|
sl@0
|
394 |
|
sl@0
|
395 |
/**
|
sl@0
|
396 |
Reads the contents of the file passed in and checks
|
sl@0
|
397 |
whether it contains any of the specified virus
|
sl@0
|
398 |
signatures
|
sl@0
|
399 |
|
sl@0
|
400 |
@return A value depending on whether a known virus is
|
sl@0
|
401 |
found within the file.
|
sl@0
|
402 |
|
sl@0
|
403 |
@param aFile A CFileCB object which can be used to read the file.
|
sl@0
|
404 |
@internalComponent
|
sl@0
|
405 |
*/
|
sl@0
|
406 |
TInt CTestVirusHook::ScanFile(const TDesC& aName)
|
sl@0
|
407 |
{
|
sl@0
|
408 |
|
sl@0
|
409 |
TInt r = KErrNone;
|
sl@0
|
410 |
TInt pos = 0;
|
sl@0
|
411 |
TInt size = 0;
|
sl@0
|
412 |
|
sl@0
|
413 |
// Rename the file
|
sl@0
|
414 |
TPtrC tmpFile = _L("VS_RENAMED.VSH");
|
sl@0
|
415 |
TParse parse;
|
sl@0
|
416 |
parse.Set(aName, NULL, NULL);
|
sl@0
|
417 |
parse.Set(parse.DriveAndPath(), &tmpFile, NULL);
|
sl@0
|
418 |
|
sl@0
|
419 |
r = iFs.Rename(aName, parse.FullName());
|
sl@0
|
420 |
if(r != KErrNone)
|
sl@0
|
421 |
return r;
|
sl@0
|
422 |
|
sl@0
|
423 |
RFile file;
|
sl@0
|
424 |
r = file.Open(iFs, parse.FullName(), EFileRead);
|
sl@0
|
425 |
if(r == KErrNone)
|
sl@0
|
426 |
{
|
sl@0
|
427 |
r = file.Size(size);
|
sl@0
|
428 |
}
|
sl@0
|
429 |
|
sl@0
|
430 |
//If the file size is 0, then the file
|
sl@0
|
431 |
//has just been created - so it can't contain
|
sl@0
|
432 |
//a virus.
|
sl@0
|
433 |
if(r != KErrNone || size == 0)
|
sl@0
|
434 |
{
|
sl@0
|
435 |
file.Close();
|
sl@0
|
436 |
|
sl@0
|
437 |
// Rename the file back
|
sl@0
|
438 |
TInt err = iFs.Rename(parse.FullName(), aName);
|
sl@0
|
439 |
if(err != KErrNone)
|
sl@0
|
440 |
return err;
|
sl@0
|
441 |
|
sl@0
|
442 |
return r;
|
sl@0
|
443 |
}
|
sl@0
|
444 |
|
sl@0
|
445 |
do
|
sl@0
|
446 |
{
|
sl@0
|
447 |
r = file.Read(pos, iScanBuf);
|
sl@0
|
448 |
|
sl@0
|
449 |
if (r != KErrNone)
|
sl@0
|
450 |
{
|
sl@0
|
451 |
break;
|
sl@0
|
452 |
}
|
sl@0
|
453 |
|
sl@0
|
454 |
r = ScanBuffer();
|
sl@0
|
455 |
pos += iScanBuf.Length();
|
sl@0
|
456 |
} while ((r == KErrNotFound) && (iScanBuf.Length() == iScanBuf.MaxLength()));
|
sl@0
|
457 |
|
sl@0
|
458 |
file.Close();
|
sl@0
|
459 |
|
sl@0
|
460 |
// Rename the file back
|
sl@0
|
461 |
TInt err = iFs.Rename(parse.FullName(), aName);
|
sl@0
|
462 |
if(err != KErrNone)
|
sl@0
|
463 |
return err;
|
sl@0
|
464 |
|
sl@0
|
465 |
if (r > 0)
|
sl@0
|
466 |
{
|
sl@0
|
467 |
//We've found an infection
|
sl@0
|
468 |
return KErrAccessDenied;
|
sl@0
|
469 |
}
|
sl@0
|
470 |
else
|
sl@0
|
471 |
{
|
sl@0
|
472 |
return KErrNone;
|
sl@0
|
473 |
}
|
sl@0
|
474 |
}
|
sl@0
|
475 |
|
sl@0
|
476 |
/**
|
sl@0
|
477 |
Scans the internal buffer which has been loaded with fresh
|
sl@0
|
478 |
file contents, to see if it contains any known virus
|
sl@0
|
479 |
signatures.
|
sl@0
|
480 |
|
sl@0
|
481 |
@return A value depending on whether a known virus signature
|
sl@0
|
482 |
is found within the buffer.
|
sl@0
|
483 |
|
sl@0
|
484 |
@internalComponent
|
sl@0
|
485 |
*/
|
sl@0
|
486 |
TInt CTestVirusHook::ScanBuffer()
|
sl@0
|
487 |
{
|
sl@0
|
488 |
//Look through the internal buffer for all known virus signatures.
|
sl@0
|
489 |
|
sl@0
|
490 |
TInt r;
|
sl@0
|
491 |
for (TInt i = 0; i < iSignaturesLoaded; i++)
|
sl@0
|
492 |
{
|
sl@0
|
493 |
r = iScanBuf.Find(iKnownSignatures[i]->Des());
|
sl@0
|
494 |
|
sl@0
|
495 |
if (r != KErrNotFound)
|
sl@0
|
496 |
{
|
sl@0
|
497 |
return r;
|
sl@0
|
498 |
}
|
sl@0
|
499 |
}
|
sl@0
|
500 |
return KErrNone;
|
sl@0
|
501 |
}
|
sl@0
|
502 |
|
sl@0
|
503 |
/**
|
sl@0
|
504 |
Validate that nobody is trying to touch the virus scanner files.
|
sl@0
|
505 |
|
sl@0
|
506 |
@internalComponent
|
sl@0
|
507 |
|
sl@0
|
508 |
@return A value depending on whethe the virus scanner files are
|
sl@0
|
509 |
being fiddled with.
|
sl@0
|
510 |
|
sl@0
|
511 |
@param aDriveNum The drive number of the request which called into
|
sl@0
|
512 |
the test virus scanning hook.
|
sl@0
|
513 |
|
sl@0
|
514 |
@param aName The full pathname of the file being accessed by the
|
sl@0
|
515 |
request to the file server hook.
|
sl@0
|
516 |
*/
|
sl@0
|
517 |
TInt CTestVirusHook::ValidateRequest(TFsPluginRequest& aRequest, TFileName& aFileName)
|
sl@0
|
518 |
{
|
sl@0
|
519 |
TInt driveNumber = aRequest.DriveNumber();
|
sl@0
|
520 |
|
sl@0
|
521 |
TInt err = GetName(&aRequest, aFileName);
|
sl@0
|
522 |
if(err != KErrNone)
|
sl@0
|
523 |
return(err);
|
sl@0
|
524 |
|
sl@0
|
525 |
if (driveNumber == EDriveC)
|
sl@0
|
526 |
{
|
sl@0
|
527 |
TInt r = aFileName.Find(_L("\\virusdef.txt"));
|
sl@0
|
528 |
|
sl@0
|
529 |
if (r != KErrNotFound)
|
sl@0
|
530 |
{
|
sl@0
|
531 |
//Do not allow the deletion of the virus definition file.
|
sl@0
|
532 |
return KErrAccessDenied;
|
sl@0
|
533 |
}
|
sl@0
|
534 |
|
sl@0
|
535 |
r = aFileName.Find(_L("\\system\\libs\\t_vshook.pxt"));
|
sl@0
|
536 |
if (r != KErrNotFound)
|
sl@0
|
537 |
{
|
sl@0
|
538 |
//Do not allow the deletion of the this dll
|
sl@0
|
539 |
return KErrAccessDenied;
|
sl@0
|
540 |
}
|
sl@0
|
541 |
r = aFileName.Find(_L("\\sys\\bin\\t_vshook.pxt"));
|
sl@0
|
542 |
if (r != KErrNotFound)
|
sl@0
|
543 |
{
|
sl@0
|
544 |
//Do not allow the deletion of the this dll
|
sl@0
|
545 |
return KErrAccessDenied;
|
sl@0
|
546 |
}
|
sl@0
|
547 |
}
|
sl@0
|
548 |
return KErrNone;
|
sl@0
|
549 |
}
|
sl@0
|
550 |
|
sl@0
|
551 |
/**
|
sl@0
|
552 |
Processes a message which describes the detection of an
|
sl@0
|
553 |
infected file. Appends the relevant text at the end of the
|
sl@0
|
554 |
file to say that it has been "cleaned". This allows the virus
|
sl@0
|
555 |
test program to confirm that the test virus scanner is
|
sl@0
|
556 |
behaving as expected.
|
sl@0
|
557 |
|
sl@0
|
558 |
@internalComponent
|
sl@0
|
559 |
@param aMessage The message to be processed.
|
sl@0
|
560 |
*/
|
sl@0
|
561 |
void CTestVirusHook::CleanFile(const TDesC& aName, TInt aOperation)
|
sl@0
|
562 |
{
|
sl@0
|
563 |
|
sl@0
|
564 |
RFile infectedFile;
|
sl@0
|
565 |
TBool bChangedToRw=EFalse;
|
sl@0
|
566 |
TInt pos=0;
|
sl@0
|
567 |
|
sl@0
|
568 |
TUint fileAtt;
|
sl@0
|
569 |
TInt r = iFs.Att(aName, fileAtt);
|
sl@0
|
570 |
if (r != KErrNone)
|
sl@0
|
571 |
{
|
sl@0
|
572 |
return;
|
sl@0
|
573 |
}
|
sl@0
|
574 |
|
sl@0
|
575 |
if (fileAtt & KEntryAttReadOnly)
|
sl@0
|
576 |
{
|
sl@0
|
577 |
bChangedToRw = ETrue;
|
sl@0
|
578 |
r = iFs.SetAtt(aName, 0, KEntryAttReadOnly);
|
sl@0
|
579 |
}
|
sl@0
|
580 |
|
sl@0
|
581 |
r = infectedFile.Open(iFs, aName, EFileShareAny | EFileWrite);
|
sl@0
|
582 |
|
sl@0
|
583 |
if (r != KErrNone)
|
sl@0
|
584 |
{
|
sl@0
|
585 |
return;
|
sl@0
|
586 |
}
|
sl@0
|
587 |
|
sl@0
|
588 |
//To show we've fixed the file, append "Infection deleted" to the end of it.
|
sl@0
|
589 |
infectedFile.Seek(ESeekEnd, pos);
|
sl@0
|
590 |
switch (aOperation)
|
sl@0
|
591 |
{
|
sl@0
|
592 |
case EFileOpen:
|
sl@0
|
593 |
infectedFile.Write(_L8("infection detected - file open\\n"));
|
sl@0
|
594 |
break;
|
sl@0
|
595 |
case EFileDelete:
|
sl@0
|
596 |
infectedFile.Write(_L8("infection detected - file delete\\n"));
|
sl@0
|
597 |
break;
|
sl@0
|
598 |
case EFileRename:
|
sl@0
|
599 |
infectedFile.Write(_L8("infection detected - file rename\\n"));
|
sl@0
|
600 |
break;
|
sl@0
|
601 |
case EFileClose:
|
sl@0
|
602 |
infectedFile.Write(_L8("infection detected - file close\\n"));
|
sl@0
|
603 |
break;
|
sl@0
|
604 |
}
|
sl@0
|
605 |
|
sl@0
|
606 |
infectedFile.Close();
|
sl@0
|
607 |
|
sl@0
|
608 |
if (bChangedToRw)
|
sl@0
|
609 |
{
|
sl@0
|
610 |
iFs.SetAtt(aName, KEntryAttReadOnly,0);
|
sl@0
|
611 |
}
|
sl@0
|
612 |
}
|
sl@0
|
613 |
|
sl@0
|
614 |
//factory functions
|
sl@0
|
615 |
|
sl@0
|
616 |
class CVsHookFactory : public CFsPluginFactory
|
sl@0
|
617 |
{
|
sl@0
|
618 |
public:
|
sl@0
|
619 |
CVsHookFactory();
|
sl@0
|
620 |
virtual TInt Install();
|
sl@0
|
621 |
virtual CFsPlugin* NewPluginL();
|
sl@0
|
622 |
virtual CFsPlugin* NewPluginConnL();
|
sl@0
|
623 |
virtual TInt UniquePosition();
|
sl@0
|
624 |
};
|
sl@0
|
625 |
|
sl@0
|
626 |
/**
|
sl@0
|
627 |
Constructor for the plugin factory
|
sl@0
|
628 |
@internalComponent
|
sl@0
|
629 |
*/
|
sl@0
|
630 |
CVsHookFactory::CVsHookFactory()
|
sl@0
|
631 |
{
|
sl@0
|
632 |
}
|
sl@0
|
633 |
|
sl@0
|
634 |
/**
|
sl@0
|
635 |
Install function for the plugin factory
|
sl@0
|
636 |
@internalComponent
|
sl@0
|
637 |
*/
|
sl@0
|
638 |
TInt CVsHookFactory::Install()
|
sl@0
|
639 |
{
|
sl@0
|
640 |
iSupportedDrives = KPluginAutoAttach;
|
sl@0
|
641 |
|
sl@0
|
642 |
_LIT(KVsHookName,"VsHook");
|
sl@0
|
643 |
return(SetName(&KVsHookName));
|
sl@0
|
644 |
}
|
sl@0
|
645 |
|
sl@0
|
646 |
/**
|
sl@0
|
647 |
@internalComponent
|
sl@0
|
648 |
*/
|
sl@0
|
649 |
TInt CVsHookFactory::UniquePosition()
|
sl@0
|
650 |
{
|
sl@0
|
651 |
return(0x3EC);
|
sl@0
|
652 |
}
|
sl@0
|
653 |
|
sl@0
|
654 |
/**
|
sl@0
|
655 |
Plugin factory function
|
sl@0
|
656 |
@internalComponent
|
sl@0
|
657 |
*/
|
sl@0
|
658 |
CFsPlugin* CVsHookFactory::NewPluginL()
|
sl@0
|
659 |
|
sl@0
|
660 |
{
|
sl@0
|
661 |
return CTestVirusHook::NewL();
|
sl@0
|
662 |
}
|
sl@0
|
663 |
|
sl@0
|
664 |
/**
|
sl@0
|
665 |
Plugin factory function
|
sl@0
|
666 |
@internalComponent
|
sl@0
|
667 |
*/
|
sl@0
|
668 |
CFsPlugin* CVsHookFactory::NewPluginConnL()
|
sl@0
|
669 |
|
sl@0
|
670 |
{
|
sl@0
|
671 |
return CTestVirusHook::NewL();
|
sl@0
|
672 |
}
|
sl@0
|
673 |
|
sl@0
|
674 |
/**
|
sl@0
|
675 |
Create a new Plugin
|
sl@0
|
676 |
@internalComponent
|
sl@0
|
677 |
*/
|
sl@0
|
678 |
extern "C" {
|
sl@0
|
679 |
|
sl@0
|
680 |
EXPORT_C CFsPluginFactory* CreateFileSystem()
|
sl@0
|
681 |
{
|
sl@0
|
682 |
return(new CVsHookFactory());
|
sl@0
|
683 |
}
|
sl@0
|
684 |
}
|
sl@0
|
685 |
|