vrsprov.cpp
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 2k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. #include "..vrsscan.h"
  2. #include "util.h"
  3. #include "vrsprov.h"
  4. #include "provmn.h"
  5. CVirusProvider1::CVirusProvider1(IUnknown *punkOut, IUnknown **punkRet) 
  6. {
  7.    cObjRef = 0;
  8.    
  9.    if(punkOut == NULL)
  10.       *punkRet = (IVirusScanEngine *)this;
  11.    else
  12.       *punkRet = NULL;
  13.    
  14.    AddRef();
  15. }
  16. //QueryInterface
  17. STDMETHODIMP CVirusProvider1::QueryInterface(REFIID riid, void **ppv)
  18. {
  19.    *ppv = NULL;
  20.    //IUnknown
  21.    if((riid == IID_IUnknown) || (riid == IID_IVirusScanEngine))
  22.       *ppv = (IVirusScanEngine *)this;
  23.    // Sorry...
  24.    if(*ppv == NULL)
  25.       return ResultFromScode(E_NOINTERFACE);
  26.    ((IUnknown *) *ppv)->AddRef();
  27.    return NOERROR; 
  28. }
  29. // AddRef - pretty boring
  30. STDMETHODIMP_(ULONG) CVirusProvider1::AddRef(void)
  31. {
  32.    cObjRef++;
  33.    return cObjRef;
  34. }
  35. // Release - pretty boring as is
  36. // a provider may want to do delayed unloading here
  37. STDMETHODIMP_(ULONG) CVirusProvider1::Release(void)
  38. {
  39.    cObjRef--;
  40.    if(cObjRef != 0)
  41.       return cObjRef;
  42.    delete this;
  43.    return 0;
  44. }
  45. // Silly, trivial implementation of scan for virus.
  46. // Probably call off into existing entry point that does some work.
  47. STDMETHODIMP CVirusProvider1::ScanForVirus(STGMEDIUM *pstgMedium, DWORD dwFlags, LPVIRUSINFO pvrsinfo)
  48. {
  49.    if(MessageBox(NULL, TEXT("Do you want to report a virus?"), TEXT("Microsoft VSEngine Test Driver"), MB_YESNO | MB_ICONQUESTION | MB_APPLMODAL) == IDYES)
  50.    {
  51.        if(pvrsinfo != NULL)
  52.        {
  53.           CopyWideStr((pvrsinfo)->wszVirusName, L"Ebola Virus");
  54.           CopyWideStr((pvrsinfo)->wszVirusDescription, L"A nasty little virus");
  55.        }
  56.        return S_FALSE;
  57.    }
  58.    else
  59.       return S_OK;
  60. }
  61. STDMETHODIMP CVirusProvider1::DisplayCustomInfo(void) 
  62. {
  63.     MessageBox(NULL, TEXT("This is a fake driver that simulates the functionality of a virus scanner."),
  64.                      TEXT("Microsoft VSEngine Test Driver"), MB_OK);
  65.     return S_OK;
  66. }