From 25409db22de65a9e4e034edccf4b6afcf2713587 Mon Sep 17 00:00:00 2001 From: Andy Sterland Date: Tue, 26 Apr 2016 10:13:27 -0700 Subject: [PATCH] Calling enable/disable debug on the Edge pacakge which should hopefully stop the plm from reclaiming the tab. --- Common/Helpers.cpp | 39 +++++++++++++ Common/Helpers.h | 3 + EdgeDiagnosticsAdapter/WebSocketHandler.cpp | 1 - EdgeDiagnosticsAdapter/main.cpp | 61 ++++++++++++++++++--- 4 files changed, 94 insertions(+), 10 deletions(-) diff --git a/Common/Helpers.cpp b/Common/Helpers.cpp index 51a1860..68e1b23 100644 --- a/Common/Helpers.cpp +++ b/Common/Helpers.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #define IDM_STARTDIAGNOSTICSMODE 3802 #define CP_AUTO 50001 @@ -434,4 +435,42 @@ namespace Helpers return S_OK; } + + HRESULT GetEdgePackageFamilyName(_Out_ CString& packageFullName) + { + LONG result = ERROR_SUCCESS; + CString edgeFamilyName = L"Microsoft.MicrosoftEdge_8wekyb3d8bbwe"; + + UINT32 packageCount = 0; + UINT32 packageNamesBufferLength = 0; + result = FindPackagesByPackageFamily(edgeFamilyName, PACKAGE_FILTER_HEAD | PACKAGE_INFORMATION_BASIC, &packageCount, nullptr, &packageNamesBufferLength, nullptr, nullptr); + + if (result != ERROR_SUCCESS) + { + return E_FAIL; + } + + if (packageCount <= 0) + { + return E_FAIL; + } + + //unique_ptr packageNames(new PWSTR[packageCount]); + vector packageNames; + packageNames.resize(packageCount); + //unique_ptr buffer(new wchar_t[packageNamesBufferLength]); + CString buffer; + + result = FindPackagesByPackageFamily(edgeFamilyName, PACKAGE_FILTER_HEAD | PACKAGE_INFORMATION_BASIC, &packageCount, packageNames.data(), &packageNamesBufferLength, buffer.GetBufferSetLength(packageNamesBufferLength), nullptr); + buffer.ReleaseBufferSetLength(packageNamesBufferLength); + + if (result != ERROR_SUCCESS) + { + return E_FAIL; + } + + packageFullName = packageNames[0]; + + return S_OK; + } } \ No newline at end of file diff --git a/Common/Helpers.h b/Common/Helpers.h index 6a6d131..b391b67 100644 --- a/Common/Helpers.h +++ b/Common/Helpers.h @@ -39,4 +39,7 @@ namespace Helpers HRESULT OpenUrlInMicrosoftEdge(_In_ PCWSTR url); HRESULT KillAllProcessByExe(const wchar_t *filename); + + HRESULT GetEdgePackageFamilyName(_Out_ CString& packageFullName); + HRESULT SetEdgeForDebugging(bool enable); } \ No newline at end of file diff --git a/EdgeDiagnosticsAdapter/WebSocketHandler.cpp b/EdgeDiagnosticsAdapter/WebSocketHandler.cpp index 6ce6c04..a3c5ee3 100644 --- a/EdgeDiagnosticsAdapter/WebSocketHandler.cpp +++ b/EdgeDiagnosticsAdapter/WebSocketHandler.cpp @@ -53,7 +53,6 @@ WebSocketHandler::WebSocketHandler(_In_ LPCWSTR rootPath, _In_ HWND adapterhWnd, this->IsServerListening = false; std::wcout << L"Error: Starting websocket handler: " << e.what(); } - } // WebSocket Callbacks diff --git a/EdgeDiagnosticsAdapter/main.cpp b/EdgeDiagnosticsAdapter/main.cpp index a09272d..b0f1058 100644 --- a/EdgeDiagnosticsAdapter/main.cpp +++ b/EdgeDiagnosticsAdapter/main.cpp @@ -14,15 +14,6 @@ CHandle hChromeProcess; namespace po = boost::program_options; -BOOL WINAPI OnClose(DWORD reason) -{ - if (hChromeProcess.m_h) - { - ::TerminateProcess(hChromeProcess.m_h, 0); - } - return TRUE; -} - CString getPathToCurrentExeContainer() { // Get the current path that we are running from @@ -99,6 +90,54 @@ void setSecurityACLs() } } +HRESULT setEdgeForDebugging(bool enable) +{ + HRESULT hrResult = E_FAIL; + + CString edgePackageFamilyName; + hrResult = Helpers::GetEdgePackageFamilyName(edgePackageFamilyName); + + if (!SUCCEEDED(hrResult)) + { + std::cerr << "Failed to get the full package name of Edge." << std::endl; + std::cerr << "HR Code: " << hrResult << std::endl; + return hrResult; + } + + CComPtr spPackageDebugSettings; + hrResult = CoCreateInstance(CLSID_PackageDebugSettings, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&spPackageDebugSettings)); + + if (!SUCCEEDED(hrResult)) + { + std::cerr << "Failed to CoCreateInstance of CLSID_PackageDebugSettings." << std::endl; + std::cerr << "HR Code: " << hrResult << std::endl; + return hrResult; + } + + if (enable) + { + hrResult = spPackageDebugSettings->EnableDebugging(edgePackageFamilyName, NULL, NULL); + } + else + { + hrResult = spPackageDebugSettings->DisableDebugging(edgePackageFamilyName); + } + + return hrResult; +} + +BOOL WINAPI OnClose(DWORD reason) +{ + if (hChromeProcess.m_h) + { + ::TerminateProcess(hChromeProcess.m_h, 0); + } + + setEdgeForDebugging(false); + + return TRUE; +} + int wmain(int argc, wchar_t* argv[]) { //::MessageBox(NULL, L"Stop here", L"STOP!", MB_ICONWARNING | MB_CANCELTRYCONTINUE | MB_DEFBUTTON3); @@ -244,8 +283,12 @@ int wmain(int argc, wchar_t* argv[]) port = vm["port"].as(); } + // We don't care if this fails as the developer can set it manually. setSecurityACLs(); + // We don't care if this fails or not as maybe the developer wants to do something that won't hit the PLM. In case errors went to the console. + setEdgeForDebugging(true); + // Load the proxy server EdgeDiagnosticsAdapter proxy(getPathToCurrentExeContainer(), port);