"Fossies" - the Fresh Open Source Software Archive

Member "src/Common/BaseCom.h" (10 Oct 2018, 3679 Bytes) of package /windows/misc/VeraCrypt_1.23-Hotfix-2_Source.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "BaseCom.h" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.22_Source_vs_1.23_Source.

    1 /*
    2  Derived from source code of TrueCrypt 7.1a, which is
    3  Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
    4  by the TrueCrypt License 3.0.
    5 
    6  Modifications and additions to the original source code (contained in this file) 
    7  and all other portions of this file are Copyright (c) 2013-2017 IDRIX
    8  and are governed by the Apache License 2.0 the full text of which is
    9  contained in the file License.txt included in VeraCrypt binary and source
   10  code distribution packages.
   11 */
   12 
   13 #ifndef TC_HEADER_BASE_COM
   14 #define TC_HEADER_BASE_COM
   15 
   16 #include <guiddef.h>
   17 
   18 template <class TClass>
   19 class TrueCryptFactory : public IClassFactory
   20 {
   21 
   22 public:
   23     TrueCryptFactory (DWORD messageThreadId) : 
   24         RefCount (1), ServerLockCount (0), MessageThreadId (messageThreadId) { }
   25 
   26     ~TrueCryptFactory () { }
   27     
   28     virtual ULONG STDMETHODCALLTYPE AddRef ()
   29     {
   30         return InterlockedIncrement (&RefCount) - 1;
   31     }
   32 
   33     virtual ULONG STDMETHODCALLTYPE Release ()
   34     {
   35         ULONG r = InterlockedDecrement (&RefCount) + 1;
   36 
   37         if (r == 0)
   38             delete this;
   39 
   40         return r;
   41     }
   42 
   43     virtual HRESULT STDMETHODCALLTYPE QueryInterface (REFIID riid, void **ppvObject)
   44     {
   45         if (riid == IID_IUnknown || riid == IID_IClassFactory)
   46             *ppvObject = this;
   47         else
   48         {
   49             *ppvObject = NULL;
   50             return E_NOINTERFACE;
   51         }
   52 
   53         AddRef ();
   54         return S_OK;
   55     }
   56         
   57     virtual HRESULT STDMETHODCALLTYPE CreateInstance (IUnknown *pUnkOuter, REFIID riid, void **ppvObject)
   58     {
   59         if (pUnkOuter != NULL)
   60             return CLASS_E_NOAGGREGATION;
   61 
   62         TClass *tc = new TClass (MessageThreadId);
   63         if (tc == NULL)
   64             return E_OUTOFMEMORY;
   65 
   66         HRESULT hr = tc->QueryInterface (riid, ppvObject);
   67 
   68         if (hr)
   69             delete tc;
   70 
   71         return hr;
   72     }
   73 
   74     virtual HRESULT STDMETHODCALLTYPE LockServer (BOOL fLock)
   75     {
   76         if (fLock)
   77         {
   78             InterlockedIncrement (&ServerLockCount);
   79         }
   80         else
   81         {
   82             if (!InterlockedDecrement (&ServerLockCount))
   83                 PostThreadMessage (MessageThreadId, WM_APP, 0, 0);
   84         }
   85 
   86         return S_OK;
   87     }
   88 
   89     virtual bool IsServerLocked ()
   90     {
   91         return ServerLockCount > 0;
   92     }
   93 
   94 protected:
   95     DWORD MessageThreadId;
   96     LONG RefCount;
   97     LONG ServerLockCount;
   98 };
   99 
  100 
  101 class BaseCom
  102 {
  103 public:
  104     static DWORD CallDriver (DWORD ioctl, BSTR input, BSTR *output);
  105     static DWORD CopyFile (BSTR sourceFile, BSTR destinationFile);
  106     static DWORD DeleteFile (BSTR file);
  107     static BOOL IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly);
  108     static DWORD ReadWriteFile (BOOL write, BOOL device, BSTR filePath, BSTR *bufferBstr, unsigned __int64 offset, unsigned __int32 size, DWORD *sizeDone);
  109     static DWORD RegisterFilterDriver (BOOL registerDriver, int filterType);
  110     static DWORD RegisterSystemFavoritesService (BOOL registerService);
  111     static DWORD SetDriverServiceStartType (DWORD startType);
  112     static DWORD WriteLocalMachineRegistryDwordValue (BSTR keyPath, BSTR valueName, DWORD value);
  113     static DWORD GetFileSize (BSTR filePath, unsigned __int64 *pSize);
  114     static DWORD DeviceIoControl (BOOL readOnly, BOOL device, BSTR filePath, DWORD dwIoControlCode, BSTR input, BSTR *output);
  115     static DWORD InstallEfiBootLoader (BOOL preserveUserConfig, BOOL hiddenOSCreation, int pim, int hashAlg);
  116     static DWORD BackupEfiSystemLoader ();
  117     static DWORD RestoreEfiSystemLoader ();
  118     static DWORD GetEfiBootDeviceNumber (BSTR* pSdn);
  119     static DWORD WriteEfiBootSectorUserConfig (DWORD userConfig, BSTR customUserMessage, int pim, int hashAlg);
  120     static DWORD UpdateSetupConfigFile (BOOL bForInstall);
  121     static DWORD GetSecureBootConfig (BOOL* pSecureBootEnabled, BOOL *pVeraCryptKeysLoaded);
  122 };
  123 
  124 
  125 BOOL ComGetInstanceBase (HWND hWnd, REFCLSID clsid, REFIID iid, void **tcServer);
  126 HRESULT CreateElevatedComObject (HWND hwnd, REFGUID guid, REFIID iid, void **ppv);
  127 
  128 #endif // TC_HEADER_BASE_COM