|
|
1.1 root 1: /* 1.1.1.3 ! root 2: Copyright (c) 2007-2008 TrueCrypt Foundation. All rights reserved. 1.1 root 3: 1.1.1.3 ! root 4: Governed by the TrueCrypt License 2.4 the full text of which is contained 1.1 root 5: in the file License.txt included in TrueCrypt binary and source code 6: distribution packages. 7: */ 8: 9: #include <atlcomcli.h> 1.1.1.3 ! root 10: #include <atlconv.h> ! 11: #include <comutil.h> 1.1 root 12: #include <windows.h> 13: #include "BaseCom.h" 1.1.1.3 ! root 14: #include "BootEncryption.h" 1.1 root 15: #include "Dlgcode.h" 16: 1.1.1.3 ! root 17: using namespace TrueCrypt; 1.1 root 18: 19: HRESULT CreateElevatedComObject (HWND hwnd, REFGUID guid, REFIID iid, void **ppv) 20: { 1.1.1.2 root 21: WCHAR monikerName[1024]; 22: WCHAR clsid[1024]; 1.1 root 23: BIND_OPTS3 bo; 24: 1.1.1.2 root 25: StringFromGUID2 (guid, clsid, sizeof (clsid) / 2); 26: swprintf_s (monikerName, sizeof (monikerName) / 2, L"Elevation:Administrator!new:%s", clsid); 1.1 root 27: 28: memset (&bo, 0, sizeof (bo)); 29: bo.cbStruct = sizeof (bo); 30: bo.hwnd = hwnd; 31: bo.dwClassContext = CLSCTX_LOCAL_SERVER; 32: 1.1.1.3 ! root 33: // Prevent the GUI from being half-rendered when the UAC prompt "freezes" it ! 34: MSG paintMsg; ! 35: int MsgCounter = 5000; // Avoid endless processing of paint messages ! 36: while (PeekMessage (&paintMsg, hwnd, 0, 0, PM_REMOVE | PM_QS_PAINT) != 0 && --MsgCounter > 0) ! 37: { ! 38: DispatchMessage (&paintMsg); ! 39: } ! 40: 1.1.1.2 root 41: return CoGetObject (monikerName, &bo, iid, ppv); 1.1 root 42: } 43: 44: 45: BOOL ComGetInstanceBase (HWND hWnd, REFCLSID clsid, REFIID iid, void **tcServer) 46: { 47: BOOL r; 48: 49: if (IsUacSupported ()) 50: r = CreateElevatedComObject (hWnd, clsid, iid, tcServer) == S_OK; 51: else 52: r = CoCreateInstance (clsid, NULL, CLSCTX_LOCAL_SERVER, iid, tcServer) == S_OK; 53: 54: if (!r) 55: Error ("UAC_INIT_ERROR"); 56: 57: return r; 58: } 59: 1.1.1.3 ! root 60: ! 61: DWORD BaseCom::CallDriver (DWORD ioctl, BSTR input, BSTR *output) ! 62: { ! 63: try ! 64: { ! 65: BootEncryption bootEnc (NULL); ! 66: bootEnc.CallDriver (ioctl, ! 67: (BYTE *) input, !(BYTE *) input ? 0 : ((DWORD *) ((BYTE *) input))[-1], ! 68: (BYTE *) *output, !(BYTE *) *output ? 0 : ((DWORD *) ((BYTE *) *output))[-1]); ! 69: } ! 70: catch (SystemException &) ! 71: { ! 72: return GetLastError(); ! 73: } ! 74: catch (Exception &e) ! 75: { ! 76: e.Show (NULL); ! 77: return ERROR_EXCEPTION_IN_SERVICE; ! 78: } ! 79: catch (...) ! 80: { ! 81: return ERROR_EXCEPTION_IN_SERVICE; ! 82: } ! 83: ! 84: return ERROR_SUCCESS; ! 85: } ! 86: ! 87: ! 88: DWORD BaseCom::ReadWriteFile (BOOL write, BOOL device, BSTR filePath, BSTR *bufferBstr, unsigned __int64 offset, unsigned __int32 size, DWORD *sizeDone) ! 89: { ! 90: USES_CONVERSION; ! 91: ! 92: try ! 93: { ! 94: auto_ptr <File> file (device ? new Device (string (CW2A (filePath)), !write) : new File (string (CW2A (filePath)), !write)); ! 95: file->SeekAt (offset); ! 96: ! 97: if (write) ! 98: { ! 99: file->Write ((BYTE *) *bufferBstr, size); ! 100: *sizeDone = size; ! 101: } ! 102: else ! 103: { ! 104: *sizeDone = file->Read ((BYTE *) *bufferBstr, size); ! 105: } ! 106: } ! 107: catch (SystemException &) ! 108: { ! 109: return GetLastError(); ! 110: } ! 111: catch (Exception &e) ! 112: { ! 113: e.Show (NULL); ! 114: return ERROR_EXCEPTION_IN_SERVICE; ! 115: } ! 116: catch (...) ! 117: { ! 118: return ERROR_EXCEPTION_IN_SERVICE; ! 119: } ! 120: ! 121: return ERROR_SUCCESS; ! 122: } ! 123: ! 124: ! 125: DWORD BaseCom::RegisterFilterDriver (BOOL registerDriver) ! 126: { ! 127: try ! 128: { ! 129: BootEncryption bootEnc (NULL); ! 130: bootEnc.RegisterFilterDriver (registerDriver ? true : false); ! 131: } ! 132: catch (SystemException &) ! 133: { ! 134: return GetLastError(); ! 135: } ! 136: catch (Exception &e) ! 137: { ! 138: e.Show (NULL); ! 139: return ERROR_EXCEPTION_IN_SERVICE; ! 140: } ! 141: catch (...) ! 142: { ! 143: return ERROR_EXCEPTION_IN_SERVICE; ! 144: } ! 145: ! 146: return ERROR_SUCCESS; ! 147: } ! 148: ! 149: ! 150: DWORD BaseCom::SetDriverServiceStartType (DWORD startType) ! 151: { ! 152: try ! 153: { ! 154: BootEncryption bootEnc (NULL); ! 155: bootEnc.SetDriverServiceStartType (startType); ! 156: } ! 157: catch (SystemException &) ! 158: { ! 159: return GetLastError(); ! 160: } ! 161: catch (Exception &e) ! 162: { ! 163: e.Show (NULL); ! 164: return ERROR_EXCEPTION_IN_SERVICE; ! 165: } ! 166: catch (...) ! 167: { ! 168: return ERROR_EXCEPTION_IN_SERVICE; ! 169: } ! 170: ! 171: return ERROR_SUCCESS; ! 172: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.