Left: | ||
Right: |
OLD | NEW |
---|---|
1 #include "PluginStdAfx.h" | 1 #include "PluginStdAfx.h" |
2 | |
3 #include "PluginSettings.h" | 2 #include "PluginSettings.h" |
4 #include "PluginSystem.h" | 3 #include "PluginSystem.h" |
5 #include "PluginFilter.h" | 4 #include "PluginFilter.h" |
6 #include "PluginClientFactory.h" | 5 #include "PluginClientFactory.h" |
7 #include "PluginMutex.h" | 6 #include "PluginMutex.h" |
8 #include "PluginClass.h" | 7 #include "PluginClass.h" |
9 | 8 |
10 #include "AdblockPlusClient.h" | 9 #include "AdblockPlusClient.h" |
11 | 10 |
12 #include "../shared/Utils.h" | 11 #include "../shared/Utils.h" |
13 | 12 |
14 namespace | 13 namespace |
15 { | 14 { |
16 void SpawnAdblockPlusEngine() | 15 void SpawnAdblockPlusEngine() |
17 { | 16 { |
18 std::wstring engineExecutablePath = GetDllDir() + L"AdblockPlusEngine.exe"; | 17 std::wstring engineExecutablePath = GetDllDir() + L"AdblockPlusEngine.exe"; |
19 CString params = L"AdblockPlusEngine.exe " + CPluginSystem::GetInstance()->G etBrowserLanguage(); | 18 CString params = L"AdblockPlusEngine.exe " + CPluginSystem::GetInstance()->G etBrowserLanguage(); |
20 | 19 |
21 STARTUPINFO startupInfo = {}; | 20 STARTUPINFO startupInfo = {}; |
22 PROCESS_INFORMATION processInformation = {}; | 21 PROCESS_INFORMATION processInformation = {}; |
23 | 22 |
24 HANDLE token; | 23 HANDLE token; |
25 OpenProcessToken(GetCurrentProcess(), TOKEN_DUPLICATE | TOKEN_ADJUST_DEFAULT | TOKEN_QUERY | TOKEN_ASSIGN_PRIMARY, &token); | 24 OpenProcessToken(GetCurrentProcess(), TOKEN_DUPLICATE | TOKEN_ADJUST_DEFAULT | TOKEN_QUERY | TOKEN_ASSIGN_PRIMARY, &token); |
26 HANDLE newToken; | |
27 DuplicateTokenEx(token, 0, 0, SecurityImpersonation, TokenPrimary, &newToken ); | |
28 | 25 |
29 if (!CreateProcessAsUserW(newToken, engineExecutablePath.c_str(), | 26 TOKEN_APPCONTAINER_INFORMATION *acSid = NULL; |
Wladimir Palant
2013/09/17 07:53:48
Nit: that variable name also uses the Hungarian no
| |
30 params.GetBuffer(params.GetLength() + 1), | 27 DWORD length = 0; |
31 0, 0, 0, 0, 0, 0, &startupInfo, &processInformatio n)) | 28 |
29 // Get AppContainer SID | |
30 if (!GetTokenInformation(token, TokenAppContainerSid, acSid, 0, &length) && GetLastError() == ERROR_INSUFFICIENT_BUFFER) | |
32 { | 31 { |
33 DWORD error = GetLastError(); | 32 acSid = (TOKEN_APPCONTAINER_INFORMATION*) HeapAlloc(GetProcessHeap(), HE AP_ZERO_MEMORY, length); |
33 if (acSid != NULL) | |
34 { | |
35 GetTokenInformation(token, TokenAppContainerSid, acSid, length, &lengt h); | |
36 } | |
37 else | |
38 { | |
39 throw std::runtime_error("Out of memory"); | |
40 } | |
41 } | |
42 | |
43 BOOL createProcRes = 0; | |
44 // Running inside AppContainer? | |
45 if (acSid != NULL && acSid->TokenAppContainer != NULL) | |
46 { | |
47 // Launch with default security. Registry entry will eat the user prompt | |
48 // See http://msdn.microsoft.com/en-us/library/bb250462(v=vs.85).aspx#wpm_ elebp | |
49 LPWSTR stringSid; | |
50 ConvertSidToStringSidW(acSid->TokenAppContainer, &stringSid); | |
51 params.Append(L" "); | |
52 params.Append(stringSid); | |
53 LocalFree(stringSid); | |
54 createProcRes = CreateProcessW(engineExecutablePath.c_str(), params.GetBuf fer(params.GetLength() + 1), | |
55 0, 0, false, 0, 0, 0, (STARTUPINFOW*)&startupInfo, &processInformation); | |
56 } | |
57 else | |
58 { | |
59 // Launch with the same security token (Low Integrity) explicitly | |
60 HANDLE newToken; | |
61 DuplicateTokenEx(token, 0, 0, SecurityImpersonation, TokenPrimary, &newTok en); | |
62 | |
63 createProcRes = CreateProcessAsUser(newToken, engineExecutablePath.c_str() , params.GetBuffer(params.GetLength() + 1), | |
Wladimir Palant
2013/09/17 07:53:48
Nit: This should be changed into CreateProcessAsUs
| |
64 0, 0, false, 0, 0, 0, (STARTUPINFOW*)&startupInfo, &processInformation); | |
65 } | |
66 | |
67 if (!createProcRes) | |
68 { | |
34 throw std::runtime_error("Failed to start Adblock Plus Engine"); | 69 throw std::runtime_error("Failed to start Adblock Plus Engine"); |
35 } | 70 } |
36 | 71 |
37 CloseHandle(processInformation.hProcess); | 72 CloseHandle(processInformation.hProcess); |
38 CloseHandle(processInformation.hThread); | 73 CloseHandle(processInformation.hThread); |
39 } | 74 } |
40 | 75 |
41 Communication::Pipe* OpenEnginePipe() | 76 Communication::Pipe* OpenEnginePipe() |
42 { | 77 { |
43 try | 78 try |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
460 bool CAdblockPlusClient::TogglePluginEnabled() | 495 bool CAdblockPlusClient::TogglePluginEnabled() |
461 { | 496 { |
462 DEBUG_GENERAL("TogglePluginEnabled"); | 497 DEBUG_GENERAL("TogglePluginEnabled"); |
463 Communication::InputBuffer response; | 498 Communication::InputBuffer response; |
464 if (!CallEngine(Communication::PROC_TOGGLE_PLUGIN_ENABLED, response)) | 499 if (!CallEngine(Communication::PROC_TOGGLE_PLUGIN_ENABLED, response)) |
465 return false; | 500 return false; |
466 bool currentEnabledState; | 501 bool currentEnabledState; |
467 response >> currentEnabledState; | 502 response >> currentEnabledState; |
468 return currentEnabledState; | 503 return currentEnabledState; |
469 } | 504 } |
OLD | NEW |