|
|
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.6 ! root 4: Governed by the TrueCrypt License 2.7 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"
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.5 root 89: BOOL BaseCom::IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly)
1.1.1.4 root 90: {
1.1.1.5 root 91: return ::IsPagingFileActive (checkNonWindowsPartitionsOnly);
1.1.1.4 root 92: }
93:
94:
1.1.1.3 root 95: DWORD BaseCom::ReadWriteFile (BOOL write, BOOL device, BSTR filePath, BSTR *bufferBstr, unsigned __int64 offset, unsigned __int32 size, DWORD *sizeDone)
96: {
97: USES_CONVERSION;
98:
99: try
100: {
101: auto_ptr <File> file (device ? new Device (string (CW2A (filePath)), !write) : new File (string (CW2A (filePath)), !write));
102: file->SeekAt (offset);
103:
104: if (write)
105: {
106: file->Write ((BYTE *) *bufferBstr, size);
107: *sizeDone = size;
108: }
109: else
110: {
111: *sizeDone = file->Read ((BYTE *) *bufferBstr, size);
112: }
113: }
114: catch (SystemException &)
115: {
116: return GetLastError();
117: }
118: catch (Exception &e)
119: {
120: e.Show (NULL);
121: return ERROR_EXCEPTION_IN_SERVICE;
122: }
123: catch (...)
124: {
125: return ERROR_EXCEPTION_IN_SERVICE;
126: }
127:
128: return ERROR_SUCCESS;
129: }
130:
131:
1.1.1.4 root 132: DWORD BaseCom::RegisterFilterDriver (BOOL registerDriver, BOOL volumeClass)
1.1.1.3 root 133: {
134: try
135: {
136: BootEncryption bootEnc (NULL);
1.1.1.4 root 137: bootEnc.RegisterFilterDriver (registerDriver ? true : false, volumeClass ? true : false);
1.1.1.3 root 138: }
139: catch (SystemException &)
140: {
141: return GetLastError();
142: }
143: catch (Exception &e)
144: {
145: e.Show (NULL);
146: return ERROR_EXCEPTION_IN_SERVICE;
147: }
148: catch (...)
149: {
150: return ERROR_EXCEPTION_IN_SERVICE;
151: }
152:
153: return ERROR_SUCCESS;
154: }
155:
156:
157: DWORD BaseCom::SetDriverServiceStartType (DWORD startType)
158: {
159: try
160: {
161: BootEncryption bootEnc (NULL);
162: bootEnc.SetDriverServiceStartType (startType);
163: }
164: catch (SystemException &)
165: {
166: return GetLastError();
167: }
168: catch (Exception &e)
169: {
170: e.Show (NULL);
171: return ERROR_EXCEPTION_IN_SERVICE;
172: }
173: catch (...)
174: {
175: return ERROR_EXCEPTION_IN_SERVICE;
176: }
177:
178: return ERROR_SUCCESS;
179: }
1.1.1.4 root 180:
181:
182: DWORD BaseCom::WriteLocalMachineRegistryDwordValue (BSTR keyPath, BSTR valueName, DWORD value)
183: {
184: USES_CONVERSION;
185: if (!::WriteLocalMachineRegistryDword (CW2A (keyPath), CW2A (valueName), value))
186: return GetLastError();
187:
188: return ERROR_SUCCESS;
189: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.