|
|
1.1 root 1: /* 1.1.1.8 ! root 2: Copyright (c) 2007-2008 TrueCrypt Developers Association. All rights reserved. 1.1 root 3: 1.1.1.8 ! root 4: Governed by the TrueCrypt License 2.8 the full text of which is contained in ! 5: the file License.txt included in TrueCrypt binary and source code distribution ! 6: packages. 1.1 root 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" 1.1.1.4 root 16: #include "Registry.h" 1.1 root 17: 1.1.1.3 root 18: using namespace TrueCrypt; 1.1 root 19: 20: HRESULT CreateElevatedComObject (HWND hwnd, REFGUID guid, REFIID iid, void **ppv) 21: { 1.1.1.2 root 22: WCHAR monikerName[1024]; 23: WCHAR clsid[1024]; 1.1 root 24: BIND_OPTS3 bo; 25: 1.1.1.2 root 26: StringFromGUID2 (guid, clsid, sizeof (clsid) / 2); 27: swprintf_s (monikerName, sizeof (monikerName) / 2, L"Elevation:Administrator!new:%s", clsid); 1.1 root 28: 29: memset (&bo, 0, sizeof (bo)); 30: bo.cbStruct = sizeof (bo); 31: bo.hwnd = hwnd; 32: bo.dwClassContext = CLSCTX_LOCAL_SERVER; 33: 1.1.1.3 root 34: // Prevent the GUI from being half-rendered when the UAC prompt "freezes" it 35: MSG paintMsg; 36: int MsgCounter = 5000; // Avoid endless processing of paint messages 37: while (PeekMessage (&paintMsg, hwnd, 0, 0, PM_REMOVE | PM_QS_PAINT) != 0 && --MsgCounter > 0) 38: { 39: DispatchMessage (&paintMsg); 40: } 41: 1.1.1.2 root 42: return CoGetObject (monikerName, &bo, iid, ppv); 1.1 root 43: } 44: 45: 46: BOOL ComGetInstanceBase (HWND hWnd, REFCLSID clsid, REFIID iid, void **tcServer) 47: { 48: BOOL r; 49: 50: if (IsUacSupported ()) 51: r = CreateElevatedComObject (hWnd, clsid, iid, tcServer) == S_OK; 52: else 53: r = CoCreateInstance (clsid, NULL, CLSCTX_LOCAL_SERVER, iid, tcServer) == S_OK; 54: 55: if (!r) 56: Error ("UAC_INIT_ERROR"); 57: 58: return r; 59: } 60: 1.1.1.3 root 61: 62: DWORD BaseCom::CallDriver (DWORD ioctl, BSTR input, BSTR *output) 63: { 64: try 65: { 66: BootEncryption bootEnc (NULL); 67: bootEnc.CallDriver (ioctl, 68: (BYTE *) input, !(BYTE *) input ? 0 : ((DWORD *) ((BYTE *) input))[-1], 69: (BYTE *) *output, !(BYTE *) *output ? 0 : ((DWORD *) ((BYTE *) *output))[-1]); 70: } 71: catch (SystemException &) 72: { 73: return GetLastError(); 74: } 75: catch (Exception &e) 76: { 77: e.Show (NULL); 78: return ERROR_EXCEPTION_IN_SERVICE; 79: } 80: catch (...) 81: { 82: return ERROR_EXCEPTION_IN_SERVICE; 83: } 84: 85: return ERROR_SUCCESS; 86: } 87: 88: 1.1.1.7 root 89: DWORD BaseCom::CopyFile (BSTR sourceFile, BSTR destinationFile) 90: { 91: USES_CONVERSION; 92: 93: if (!::CopyFile (CW2A (sourceFile), CW2A (destinationFile), FALSE)) 94: return GetLastError(); 95: 96: return ERROR_SUCCESS; 97: } 98: 99: 100: DWORD BaseCom::DeleteFile (BSTR file) 101: { 102: USES_CONVERSION; 103: 104: if (!::DeleteFile (CW2A (file))) 105: return GetLastError(); 106: 107: return ERROR_SUCCESS; 108: } 109: 110: 1.1.1.5 root 111: BOOL BaseCom::IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly) 1.1.1.4 root 112: { 1.1.1.5 root 113: return ::IsPagingFileActive (checkNonWindowsPartitionsOnly); 1.1.1.4 root 114: } 115: 116: 1.1.1.3 root 117: DWORD BaseCom::ReadWriteFile (BOOL write, BOOL device, BSTR filePath, BSTR *bufferBstr, unsigned __int64 offset, unsigned __int32 size, DWORD *sizeDone) 118: { 119: USES_CONVERSION; 120: 121: try 122: { 123: auto_ptr <File> file (device ? new Device (string (CW2A (filePath)), !write) : new File (string (CW2A (filePath)), !write)); 124: file->SeekAt (offset); 125: 126: if (write) 127: { 128: file->Write ((BYTE *) *bufferBstr, size); 129: *sizeDone = size; 130: } 131: else 132: { 133: *sizeDone = file->Read ((BYTE *) *bufferBstr, size); 134: } 135: } 136: catch (SystemException &) 137: { 138: return GetLastError(); 139: } 140: catch (Exception &e) 141: { 142: e.Show (NULL); 143: return ERROR_EXCEPTION_IN_SERVICE; 144: } 145: catch (...) 146: { 147: return ERROR_EXCEPTION_IN_SERVICE; 148: } 149: 150: return ERROR_SUCCESS; 151: } 152: 153: 1.1.1.4 root 154: DWORD BaseCom::RegisterFilterDriver (BOOL registerDriver, BOOL volumeClass) 1.1.1.3 root 155: { 156: try 157: { 158: BootEncryption bootEnc (NULL); 1.1.1.4 root 159: bootEnc.RegisterFilterDriver (registerDriver ? true : false, volumeClass ? true : false); 1.1.1.3 root 160: } 161: catch (SystemException &) 162: { 163: return GetLastError(); 164: } 165: catch (Exception &e) 166: { 167: e.Show (NULL); 168: return ERROR_EXCEPTION_IN_SERVICE; 169: } 170: catch (...) 171: { 172: return ERROR_EXCEPTION_IN_SERVICE; 173: } 174: 175: return ERROR_SUCCESS; 176: } 177: 178: 1.1.1.7 root 179: DWORD BaseCom::RegisterSystemFavoritesService (BOOL registerService) 180: { 181: try 182: { 183: BootEncryption bootEnc (NULL); 184: bootEnc.RegisterSystemFavoritesService (registerService); 185: } 186: catch (SystemException &) 187: { 188: return GetLastError(); 189: } 190: catch (Exception &e) 191: { 192: e.Show (NULL); 193: return ERROR_EXCEPTION_IN_SERVICE; 194: } 195: catch (...) 196: { 197: return ERROR_EXCEPTION_IN_SERVICE; 198: } 199: 200: return ERROR_SUCCESS; 201: } 202: 203: 1.1.1.3 root 204: DWORD BaseCom::SetDriverServiceStartType (DWORD startType) 205: { 206: try 207: { 208: BootEncryption bootEnc (NULL); 209: bootEnc.SetDriverServiceStartType (startType); 210: } 211: catch (SystemException &) 212: { 213: return GetLastError(); 214: } 215: catch (Exception &e) 216: { 217: e.Show (NULL); 218: return ERROR_EXCEPTION_IN_SERVICE; 219: } 220: catch (...) 221: { 222: return ERROR_EXCEPTION_IN_SERVICE; 223: } 224: 225: return ERROR_SUCCESS; 226: } 1.1.1.4 root 227: 228: 229: DWORD BaseCom::WriteLocalMachineRegistryDwordValue (BSTR keyPath, BSTR valueName, DWORD value) 230: { 231: USES_CONVERSION; 232: if (!::WriteLocalMachineRegistryDword (CW2A (keyPath), CW2A (valueName), value)) 233: return GetLastError(); 234: 235: return ERROR_SUCCESS; 236: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.