99
1010#include < intrin.h>
1111
12+ #include " MsRdpEx.h"
1213#include " TSObjects.h"
1314
1415extern " C" const GUID IID_ITSPropertySet;
1516
17+ extern MsRdpEx_mstscax g_mstscax;
18+ extern MsRdpEx_rdclientax g_rdclientax;
19+
1620static bool g_TSPropertySet_Hooked = false ;
1721
1822static ITSPropertySet_SetBoolProperty Real_ITSPropertySet_SetBoolProperty = NULL ;
@@ -129,8 +133,8 @@ static HRESULT Hook_ITSPropertySet_SetStringProperty(ITSPropertySet* This, const
129133 HRESULT hr;
130134
131135 char * propValueA = _com_util::ConvertBSTRToString ((BSTR) propValue);
132-
133136 MsRdpEx_LogPrint (TRACE, " ITSPropertySet::SetStringProperty(%s, \" %s\" )" , propName, propValueA);
137+ delete[] propValueA;
134138
135139 hr = Real_ITSPropertySet_SetStringProperty (This, propName, propValue);
136140
@@ -143,7 +147,14 @@ static HRESULT Hook_ITSPropertySet_GetStringProperty(ITSPropertySet* This, const
143147
144148 hr = Real_ITSPropertySet_GetStringProperty (This, propName, propValue);
145149
146- MsRdpEx_LogPrint (TRACE, " ITSPropertySet::GetStringProperty(%s)" , propName);
150+ if (SUCCEEDED (hr)) {
151+ char * propValueA = _com_util::ConvertBSTRToString ((BSTR)*propValue);
152+ MsRdpEx_LogPrint (TRACE, " ITSPropertySet::GetStringProperty(%s, \" %s\" )" , propName, propValueA);
153+ delete[] propValueA;
154+ }
155+ else {
156+ MsRdpEx_LogPrint (TRACE, " ITSPropertySet::GetStringProperty(%s), hr = 0x%08X" , propName, hr);
157+ }
147158
148159 return hr;
149160}
@@ -173,22 +184,39 @@ static HRESULT Hook_ITSPropertySet_GetSecureStringProperty(ITSPropertySet* This,
173184 return hr;
174185}
175186
176- static bool TSPropertySet_Hook (ITSPropertySet* pTSPropertySet)
187+ static bool TSPropertySet_Hook (ITSPropertySet* pTSPropertySet, ITSPropertySetVtbl30* vtbl30, ITSPropertySetVtbl32* vtbl32 )
177188{
178189 LONG error;
179190
191+ if (!pTSPropertySet || (!vtbl30 && !vtbl32))
192+ return false ;
193+
180194 DetourRestoreAfterWith ();
181195 DetourTransactionBegin ();
182196 DetourUpdateThread (GetCurrentThread ());
183197
184- Real_ITSPropertySet_SetBoolProperty = pTSPropertySet->vtbl ->SetBoolProperty ;
185- Real_ITSPropertySet_GetBoolProperty = pTSPropertySet->vtbl ->GetBoolProperty ;
186- Real_ITSPropertySet_SetIntProperty = pTSPropertySet->vtbl ->SetIntProperty ;
187- Real_ITSPropertySet_GetIntProperty = pTSPropertySet->vtbl ->GetIntProperty ;
188- Real_ITSPropertySet_SetStringProperty = pTSPropertySet->vtbl ->SetStringProperty ;
189- Real_ITSPropertySet_GetStringProperty = pTSPropertySet->vtbl ->GetStringProperty ;
190- Real_ITSPropertySet_SetSecureStringProperty = pTSPropertySet->vtbl ->SetSecureStringProperty ;
191- Real_ITSPropertySet_GetSecureStringProperty = pTSPropertySet->vtbl ->GetSecureStringProperty ;
198+ if (vtbl32)
199+ {
200+ Real_ITSPropertySet_SetBoolProperty = vtbl32->SetBoolProperty ;
201+ Real_ITSPropertySet_GetBoolProperty = vtbl32->GetBoolProperty ;
202+ Real_ITSPropertySet_SetIntProperty = vtbl32->SetIntProperty ;
203+ Real_ITSPropertySet_GetIntProperty = vtbl32->GetIntProperty ;
204+ Real_ITSPropertySet_SetStringProperty = vtbl32->SetStringProperty ;
205+ Real_ITSPropertySet_GetStringProperty = vtbl32->GetStringProperty ;
206+ Real_ITSPropertySet_SetSecureStringProperty = vtbl32->SetSecureStringProperty ;
207+ Real_ITSPropertySet_GetSecureStringProperty = vtbl32->GetSecureStringProperty ;
208+ }
209+ else if (vtbl30)
210+ {
211+ Real_ITSPropertySet_SetBoolProperty = vtbl30->SetBoolProperty ;
212+ Real_ITSPropertySet_GetBoolProperty = vtbl30->GetBoolProperty ;
213+ Real_ITSPropertySet_SetIntProperty = vtbl30->SetIntProperty ;
214+ Real_ITSPropertySet_GetIntProperty = vtbl30->GetIntProperty ;
215+ Real_ITSPropertySet_SetStringProperty = vtbl30->SetStringProperty ;
216+ Real_ITSPropertySet_GetStringProperty = vtbl30->GetStringProperty ;
217+ Real_ITSPropertySet_SetSecureStringProperty = vtbl30->SetSecureStringProperty ;
218+ Real_ITSPropertySet_GetSecureStringProperty = vtbl30->GetSecureStringProperty ;
219+ }
192220
193221 DetourAttach ((PVOID*)(&Real_ITSPropertySet_SetBoolProperty), Hook_ITSPropertySet_SetBoolProperty);
194222 DetourAttach ((PVOID*)(&Real_ITSPropertySet_GetBoolProperty), Hook_ITSPropertySet_GetBoolProperty);
@@ -212,9 +240,27 @@ class CMsRdpPropertySet : public IMsRdpExtendedSettings
212240 m_pUnknown = pUnknown;
213241 pUnknown->QueryInterface (IID_ITSPropertySet, (LPVOID*)&m_pTSPropertySet);
214242
215- if (!g_TSPropertySet_Hooked) {
216- TSPropertySet_Hook (m_pTSPropertySet);
217- g_TSPropertySet_Hooked = true ;
243+ if (m_pTSPropertySet)
244+ {
245+ if (MsRdpEx_IsAddressInRdclientAxModule (m_pTSPropertySet->vtbl ))
246+ {
247+ DWORD version = g_rdclientax.tscCtlVer ;
248+
249+ if (version >= 5326 ) {
250+ m_vtbl32 = (ITSPropertySetVtbl32*)m_pTSPropertySet->vtbl ;
251+ } else {
252+ m_vtbl30 = (ITSPropertySetVtbl30*)m_pTSPropertySet->vtbl ;
253+ }
254+ }
255+ else
256+ {
257+ m_vtbl30 = (ITSPropertySetVtbl30*)m_pTSPropertySet->vtbl ;
258+ }
259+
260+ if (!g_TSPropertySet_Hooked) {
261+ TSPropertySet_Hook (m_pTSPropertySet, m_vtbl30, m_vtbl32);
262+ g_TSPropertySet_Hooked = true ;
263+ }
218264 }
219265 }
220266
@@ -308,6 +354,8 @@ class CMsRdpPropertySet : public IMsRdpExtendedSettings
308354 return SetBStrProperty (propName, pValue->bstrVal );
309355 }
310356
357+ delete[] propName;
358+
311359 return E_INVALIDARG;
312360 }
313361
@@ -336,6 +384,8 @@ class CMsRdpPropertySet : public IMsRdpExtendedSettings
336384 }
337385 }
338386
387+ delete[] propName;
388+
339389 return hr;
340390 }
341391
@@ -356,19 +406,29 @@ class CMsRdpPropertySet : public IMsRdpExtendedSettings
356406 }
357407
358408 HRESULT __stdcall GetVBoolProperty (const char * propName, VARIANT_BOOL* propValue) {
359- HRESULT hr;
409+ HRESULT hr = E_FAIL ;
360410 int iVal = 0 ;
361- hr = m_pTSPropertySet->vtbl ->GetBoolProperty (m_pTSPropertySet, propName, &iVal);
411+
412+ if (m_vtbl32) {
413+ hr = m_vtbl32->GetBoolProperty (m_pTSPropertySet, propName, &iVal);
414+ } else if (m_vtbl30) {
415+ hr = m_vtbl30->GetBoolProperty (m_pTSPropertySet, propName, &iVal);
416+ }
417+
362418 *propValue = iVal ? VARIANT_TRUE : VARIANT_FALSE;
363419 return hr;
364420 }
365421
366422 HRESULT __stdcall GetBStrProperty (const char * propName, BSTR* propValue) {
367- HRESULT hr;
423+ HRESULT hr = E_FAIL ;
368424 BSTR bstrVal = NULL ;
369425 WCHAR* wstrVal = NULL ;
370426
371- hr = m_pTSPropertySet->vtbl ->GetStringProperty (m_pTSPropertySet, propName, &wstrVal);
427+ if (m_vtbl32) {
428+ hr = m_vtbl32->GetStringProperty (m_pTSPropertySet, propName, &wstrVal);
429+ } else if (m_vtbl30) {
430+ hr = m_vtbl30->GetStringProperty (m_pTSPropertySet, propName, &wstrVal);
431+ }
372432
373433 if (hr != S_OK)
374434 return hr;
@@ -382,6 +442,8 @@ class CMsRdpPropertySet : public IMsRdpExtendedSettings
382442 ULONG m_refCount;
383443 IUnknown* m_pUnknown;
384444 ITSPropertySet* m_pTSPropertySet;
445+ ITSPropertySetVtbl30* m_vtbl30 = NULL ;
446+ ITSPropertySetVtbl32* m_vtbl32 = NULL ;
385447};
386448
387449CMsRdpExtendedSettings::CMsRdpExtendedSettings (IUnknown* pUnknown, GUID* pSessionId)
@@ -498,7 +560,7 @@ HRESULT __stdcall CMsRdpExtendedSettings::put_Property(BSTR bstrPropertyName, VA
498560 hr = this ->SetKdcProxyUrl (propValue);
499561 }
500562
501- free ( propValue) ;
563+ delete[] propValue;
502564 hr = S_OK;
503565 }
504566 else if (MsRdpEx_StringEquals (propName, " EnableMouseJiggler" ))
@@ -540,6 +602,7 @@ HRESULT __stdcall CMsRdpExtendedSettings::put_Property(BSTR bstrPropertyName, VA
540602
541603 char * propValueA = _com_util::ConvertBSTRToString ((BSTR)pValue->bstrVal );
542604 strncpy_s (m_KeyboardHookToggleShortcutKey, propValueA, sizeof (m_KeyboardHookToggleShortcutKey) - 1 );
605+ delete[] propValueA;
543606
544607 hr = S_OK;
545608 }
@@ -548,12 +611,14 @@ HRESULT __stdcall CMsRdpExtendedSettings::put_Property(BSTR bstrPropertyName, VA
548611 if (pValue->vt == VT_BSTR) {
549612 char * propValueA = _com_util::ConvertBSTRToString ((BSTR)pValue->bstrVal );
550613 MsRdpEx_LogPrint (TRACE, " CMsRdpExtendedSettings::put_Property(%s, \" %s\" )" , propName, propValueA);
614+ delete[] propValueA;
551615 }
552616
553617 hr = m_pMsRdpExtendedSettings->put_Property (bstrPropertyName, pValue);
554618 }
555619
556620end:
621+ delete[] propName;
557622 return hr;
558623}
559624
@@ -645,6 +710,8 @@ HRESULT __stdcall CMsRdpExtendedSettings::get_Property(BSTR bstrPropertyName, VA
645710 hr = m_pMsRdpExtendedSettings->get_Property (bstrPropertyName, pValue);
646711 }
647712
713+ delete[] propName;
714+
648715 return hr;
649716}
650717
@@ -653,6 +720,7 @@ HRESULT __stdcall CMsRdpExtendedSettings::get_Property(BSTR bstrPropertyName, VA
653720HRESULT __stdcall CMsRdpExtendedSettings::put_CoreProperty (BSTR bstrPropertyName, VARIANT* pValue) {
654721 char * propName = _com_util::ConvertBSTRToString (bstrPropertyName);
655722 MsRdpEx_LogPrint (DEBUG, " CMsRdpExtendedSettings::put_CoreProperty(%s)" , propName);
723+ delete[] propName;
656724
657725 if (!m_CoreProps)
658726 return E_INVALIDARG;
@@ -663,6 +731,7 @@ HRESULT __stdcall CMsRdpExtendedSettings::put_CoreProperty(BSTR bstrPropertyName
663731HRESULT __stdcall CMsRdpExtendedSettings::get_CoreProperty (BSTR bstrPropertyName, VARIANT* pValue) {
664732 char * propName = _com_util::ConvertBSTRToString (bstrPropertyName);
665733 MsRdpEx_LogPrint (DEBUG, " CMsRdpExtendedSettings::get_CoreProperty(%s)" , propName);
734+ delete[] propName;
666735
667736 if (!m_CoreProps)
668737 return E_INVALIDARG;
@@ -673,6 +742,7 @@ HRESULT __stdcall CMsRdpExtendedSettings::get_CoreProperty(BSTR bstrPropertyName
673742HRESULT __stdcall CMsRdpExtendedSettings::put_BaseProperty (BSTR bstrPropertyName, VARIANT* pValue) {
674743 char * propName = _com_util::ConvertBSTRToString (bstrPropertyName);
675744 MsRdpEx_LogPrint (DEBUG, " CMsRdpExtendedSettings::put_BaseProperty(%s)" , propName);
745+ delete[] propName;
676746
677747 if (!m_BaseProps)
678748 return E_INVALIDARG;
@@ -683,6 +753,7 @@ HRESULT __stdcall CMsRdpExtendedSettings::put_BaseProperty(BSTR bstrPropertyName
683753HRESULT __stdcall CMsRdpExtendedSettings::get_BaseProperty (BSTR bstrPropertyName, VARIANT* pValue) {
684754 char * propName = _com_util::ConvertBSTRToString (bstrPropertyName);
685755 MsRdpEx_LogPrint (DEBUG, " CMsRdpExtendedSettings::get_BaseProperty(%s)" , propName);
756+ delete[] propName;
686757
687758 if (!m_BaseProps)
688759 return E_INVALIDARG;
0 commit comments