@@ -126,6 +126,7 @@ FlashProxyModule::FlashProxyModule():
126
126
m_encodeBuffer(),
127
127
m_identity(Identity::Unknown),
128
128
m_visibilityMask(0 ),
129
+ m_port(9999 ),
129
130
m_url(),
130
131
m_userDataFolder(),
131
132
m_aboutQuery(),
@@ -703,6 +704,27 @@ HRESULT STDMETHODCALLTYPE FlashProxyModule::put_Movie(BSTR pVal)
703
704
if (FAILED (burl.Append (pVal, length)))
704
705
return E_FAIL;
705
706
707
+ WCHAR scheme[10 ] = {0 };
708
+ WCHAR host[40 ] = {0 };
709
+ WCHAR path[1000 ] = {0 };
710
+ URL_COMPONENTS components;
711
+ ZeroMemory (&components, sizeof (components));
712
+ components.dwStructSize = sizeof (components);
713
+ components.lpszScheme = scheme;
714
+ components.dwSchemeLength = _countof (scheme);
715
+ components.lpszHostName = host;
716
+ components.dwHostNameLength = _countof (host);
717
+ components.lpszUrlPath = path;
718
+ components.dwUrlPathLength = _countof (path);
719
+
720
+ if (!InternetCrackUrl (burl, 0 , ICU_DECODE, &components))
721
+ return E_FAIL;
722
+
723
+ if (_wcsicmp (scheme, L" http" ) != 0 || components.nPort < 1024 )
724
+ return E_FAIL;
725
+
726
+ m_port = components.nPort ;
727
+
706
728
WCHAR *name = wcsrchr (burl, L' /' );
707
729
if (name != nullptr )
708
730
{
@@ -719,16 +741,19 @@ HRESULT STDMETHODCALLTYPE FlashProxyModule::put_Movie(BSTR pVal)
719
741
m_identity = Identity::MessageBar;
720
742
}
721
743
722
- if (_wcsnicmp (burl , L" http:// 127.0.0.1:9999/ " , 22 ) == 0 || _wcsnicmp (burl , L" http:// localhost:9999/ " , 22 ) == 0 )
744
+ if (_wcsicmp (host , L" 127.0.0.1" ) == 0 || _wcsicmp (host , L" localhost" ) == 0 )
723
745
{
724
- CComBSTR burl2 = burl + 22 ;
725
- if (FAILED (burl2.Append (L" 2.html" )))
726
- return E_FAIL;
727
-
728
- if (GetFileAttributes (burl2) != INVALID_FILE_ATTRIBUTES)
746
+ if (path[0 ] == L' /' )
729
747
{
730
- if (FAILED (burl.Append (L" 2" )))
748
+ CComBSTR bpath = path + 1 ;
749
+ if (FAILED (bpath.Append (L" 2.html" )))
731
750
return E_FAIL;
751
+
752
+ if (GetFileAttributes (bpath) != INVALID_FILE_ATTRIBUTES)
753
+ {
754
+ if (FAILED (burl.Append (L" 2" )))
755
+ return E_FAIL;
756
+ }
732
757
}
733
758
}
734
759
@@ -827,8 +852,11 @@ HRESULT STDMETHODCALLTYPE FlashProxyModule::Invoke(HRESULT errorCode, ICoreWebVi
827
852
hostObject.pdispVal = static_cast <IDispatch*>(this );
828
853
m_view->AddHostObjectToScript (L" client" , &hostObject);
829
854
830
- m_view->AddWebResourceRequestedFilter (L" http://127.0.0.1:9999/*" , COREWEBVIEW2_WEB_RESOURCE_CONTEXT_ALL);
831
- m_view->AddWebResourceRequestedFilter (L" http://localhost:9999/*" , COREWEBVIEW2_WEB_RESOURCE_CONTEXT_ALL);
855
+ WCHAR filterHost[40 ] = {0 };
856
+ _snwprintf_s (filterHost, _countof (filterHost), L" http://127.0.0.1:%u/*" , m_port);
857
+ m_view->AddWebResourceRequestedFilter (filterHost, COREWEBVIEW2_WEB_RESOURCE_CONTEXT_ALL);
858
+ _snwprintf_s (filterHost, _countof (filterHost), L" http://localhost:%u/*" , m_port);
859
+ m_view->AddWebResourceRequestedFilter (filterHost, COREWEBVIEW2_WEB_RESOURCE_CONTEXT_ALL);
832
860
833
861
m_view->add_WebMessageReceived (Callback<ICoreWebView2WebMessageReceivedEventHandler>(
834
862
[this ](ICoreWebView2 *sender, ICoreWebView2WebMessageReceivedEventArgs *args) -> HRESULT
@@ -955,10 +983,29 @@ HRESULT FlashProxyModule::OnWebResourceRequested(ICoreWebView2 *sender, ICoreWeb
955
983
CoTaskMemFree (url);
956
984
}
957
985
958
- if (_wcsnicmp (burl, L" http://127.0.0.1:9999/" , 22 ) != 0 && _wcsnicmp (burl, L" http://localhost:9999/" , 22 ) != 0 )
986
+ WCHAR scheme[10 ] = {0 };
987
+ WCHAR host[40 ] = {0 };
988
+ WCHAR path[1000 ] = {0 };
989
+ URL_COMPONENTS components;
990
+ ZeroMemory (&components, sizeof (components));
991
+ components.dwStructSize = sizeof (components);
992
+ components.lpszScheme = scheme;
993
+ components.dwSchemeLength = _countof (scheme);
994
+ components.lpszHostName = host;
995
+ components.dwHostNameLength = _countof (host);
996
+ components.lpszUrlPath = path;
997
+ components.dwUrlPathLength = _countof (path);
998
+
999
+ if (!InternetCrackUrl (burl, 0 , ICU_DECODE, &components))
1000
+ return E_FAIL;
1001
+
1002
+ if (_wcsicmp (scheme, L" http" ) != 0 || components.nPort != m_port)
1003
+ return S_FALSE;
1004
+
1005
+ if (_wcsicmp (host, L" 127.0.0.1" ) != 0 && _wcsicmp (host, L" localhost" ) != 0 )
959
1006
return S_FALSE;
960
1007
961
- if (wcscmp (burl + 22 , L" favicon.ico" ) == 0 )
1008
+ if (wcscmp (path , L" / favicon.ico" ) == 0 )
962
1009
{
963
1010
CComPtr<ICoreWebView2WebResourceResponse> response;
964
1011
if (FAILED (m_environment->CreateWebResourceResponse (nullptr , 404 , L" Not Found" , L" " , &response)) || response == nullptr )
0 commit comments