Skip to content

Commit

Permalink
add PasswordContainsSCardPin .RDP file option
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc-André Moreau authored and awakecoding committed Apr 10, 2024
1 parent a797881 commit 1758cb9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
36 changes: 36 additions & 0 deletions dll/RdpSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ static ITSPropertySet_SetIntProperty Real_ITSPropertySet_SetIntProperty = NULL;
static ITSPropertySet_GetIntProperty Real_ITSPropertySet_GetIntProperty = NULL;
static ITSPropertySet_SetStringProperty Real_ITSPropertySet_SetStringProperty = NULL;
static ITSPropertySet_GetStringProperty Real_ITSPropertySet_GetStringProperty = NULL;
static ITSPropertySet_SetSecureStringProperty Real_ITSPropertySet_SetSecureStringProperty = NULL;
static ITSPropertySet_GetSecureStringProperty Real_ITSPropertySet_GetSecureStringProperty = NULL;

static HRESULT Hook_ITSPropertySet_SetBoolProperty(ITSPropertySet* This, const char* propName, int propValue)
{
Expand Down Expand Up @@ -146,6 +148,30 @@ static HRESULT Hook_ITSPropertySet_GetStringProperty(ITSPropertySet* This, const
return hr;
}

static HRESULT Hook_ITSPropertySet_SetSecureStringProperty(ITSPropertySet* This, const char* propName, WCHAR* propValue)
{
HRESULT hr;

char* propValueA = _com_util::ConvertBSTRToString((BSTR)propValue);

MsRdpEx_LogPrint(TRACE, "ITSPropertySet::SetSecureStringProperty(%s, \"%s\")", propName, propValueA);

hr = Real_ITSPropertySet_SetSecureStringProperty(This, propName, propValue);

return hr;
}

static HRESULT Hook_ITSPropertySet_GetSecureStringProperty(ITSPropertySet* This, const char* propName, WCHAR** propValue, uint32_t* propLength)
{
HRESULT hr;

hr = Real_ITSPropertySet_GetSecureStringProperty(This, propName, propValue, propLength);

MsRdpEx_LogPrint(TRACE, "ITSPropertySet::GetSecureStringProperty(%s)", propName);

return hr;
}

static bool TSPropertySet_Hook(ITSPropertySet* pTSPropertySet)
{
LONG error;
Expand All @@ -160,13 +186,17 @@ static bool TSPropertySet_Hook(ITSPropertySet* pTSPropertySet)
Real_ITSPropertySet_GetIntProperty = pTSPropertySet->vtbl->GetIntProperty;
Real_ITSPropertySet_SetStringProperty = pTSPropertySet->vtbl->SetStringProperty;
Real_ITSPropertySet_GetStringProperty = pTSPropertySet->vtbl->GetStringProperty;
Real_ITSPropertySet_SetSecureStringProperty = pTSPropertySet->vtbl->SetSecureStringProperty;
Real_ITSPropertySet_GetSecureStringProperty = pTSPropertySet->vtbl->GetSecureStringProperty;

DetourAttach((PVOID*)(&Real_ITSPropertySet_SetBoolProperty), Hook_ITSPropertySet_SetBoolProperty);
DetourAttach((PVOID*)(&Real_ITSPropertySet_GetBoolProperty), Hook_ITSPropertySet_GetBoolProperty);
DetourAttach((PVOID*)(&Real_ITSPropertySet_SetIntProperty), Hook_ITSPropertySet_SetIntProperty);
DetourAttach((PVOID*)(&Real_ITSPropertySet_GetIntProperty), Hook_ITSPropertySet_GetIntProperty);
DetourAttach((PVOID*)(&Real_ITSPropertySet_SetStringProperty), Hook_ITSPropertySet_SetStringProperty);
DetourAttach((PVOID*)(&Real_ITSPropertySet_GetStringProperty), Hook_ITSPropertySet_GetStringProperty);
DetourAttach((PVOID*)(&Real_ITSPropertySet_SetSecureStringProperty), Hook_ITSPropertySet_SetSecureStringProperty);
DetourAttach((PVOID*)(&Real_ITSPropertySet_GetSecureStringProperty), Hook_ITSPropertySet_GetSecureStringProperty);

error = DetourTransactionCommit();
return true;
Expand Down Expand Up @@ -792,6 +822,12 @@ HRESULT CMsRdpExtendedSettings::ApplyRdpFile(void* rdpFilePtr)
else if (MsRdpEx_RdpFileEntry_IsMatch(entry, 's', "GatewayPassword")) {
pMsRdpExtendedSettings->SetGatewayPassword(entry->value);
}
else if (MsRdpEx_RdpFileEntry_IsMatch(entry, 'i', "PasswordContainsSCardPin")) {
if (MsRdpEx_RdpFileEntry_GetVBoolValue(entry, &value)) {
bstr_t propName = _com_util::ConvertStringToBSTR(entry->name);
pMsRdpExtendedSettings->put_CoreProperty(propName, &value);
}
}
else if (MsRdpEx_RdpFileEntry_IsMatch(entry, 's', "TargetUserName")) {
bstr_t propName = _com_util::ConvertStringToBSTR("UserName");
bstr_t propValue = _com_util::ConvertStringToBSTR(entry->value);
Expand Down
5 changes: 4 additions & 1 deletion dll/TSObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ typedef HRESULT (__stdcall* ITSPropertySet_GetIntProperty)(ITSPropertySet* This,
typedef HRESULT (__stdcall* ITSPropertySet_SetStringProperty)(ITSPropertySet* This, const char* propName, WCHAR* propValue);
typedef HRESULT (__stdcall* ITSPropertySet_GetStringProperty)(ITSPropertySet* This, const char* propName, WCHAR** propValue);

typedef HRESULT(__stdcall* ITSPropertySet_SetSecureStringProperty)(ITSPropertySet* This, const char* propName, WCHAR* propValue);
typedef HRESULT(__stdcall* ITSPropertySet_GetSecureStringProperty)(ITSPropertySet* This, const char* propName, WCHAR** propValue, uint32_t* propLength);

typedef struct ITSPropertySetVtbl
{
HRESULT(__stdcall* QueryInterface)(ITSPropertySet* This, REFIID riid, void** ppvObject);
Expand All @@ -73,7 +76,7 @@ typedef struct ITSPropertySetVtbl
HRESULT(__stdcall* GetIUnknownProperty)(ITSPropertySet* This, const char* propName, IUnknown** propValue);
HRESULT(__stdcall* GetBoolProperty)(ITSPropertySet* This, const char* propName, int* propValue);
HRESULT(__stdcall* GetStringProperty)(ITSPropertySet* This, const char* propName, WCHAR** propValue);
HRESULT(__stdcall* GetSecureStringProperty)(ITSPropertySet* This, const char* propName, WCHAR* a1, uint32_t* a2);
HRESULT(__stdcall* GetSecureStringProperty)(ITSPropertySet* This, const char* propName, WCHAR** propValue, uint32_t* propLength);
HRESULT(__stdcall* GetUlongPtrProperty)(ITSPropertySet* This, const char* propName, ULONG_PTR* propValue);
HRESULT(__stdcall* EnterReadLock)(ITSPropertySet* This);
HRESULT(__stdcall* LeaveReadLock)(ITSPropertySet* This);
Expand Down

0 comments on commit 1758cb9

Please sign in to comment.