diff --git a/base/system/rundll32/rundll32.c b/base/system/rundll32/rundll32.c index 23bba1e253..803095c5f7 100644 --- a/base/system/rundll32/rundll32.c +++ b/base/system/rundll32/rundll32.c @@ -31,6 +31,8 @@ #include #include "resource.h" +#include +#include typedef int (WINAPI *DllWinMainW)( HWND hWnd, @@ -334,6 +336,9 @@ int WINAPI _tWinMain( { int argc; TCHAR szMsg[RC_STRING_MAX_SIZE]; + WCHAR szFixed[RC_STRING_MAX_SIZE]; + WCHAR szRemain[RC_STRING_MAX_SIZE]; + WCHAR szCmdEnd[RC_STRING_MAX_SIZE]; LPTSTR *argv; LPTSTR lptCmdLine,lptDllName,lptFuncName,lptMsgBuffer; @@ -350,9 +355,67 @@ int WINAPI _tWinMain( HANDLE hActCtx; ULONG_PTR cookie; BOOL bActivated; + UINT cmdpos; + const WCHAR* temp = _wgetenv(L"TEMP"); + WCHAR* remain; + WCHAR* space; - // Get command-line in argc-argv format +DPRINT1("Command Line is '%S' and length is '%d'.\n", GetCommandLine(), wcslen(GetCommandLine())); + +if (wcsstr(temp, L" ")) +{ + DPRINT1("Probably BtrFS File System.\n"); + /* Copy the original command line to the new one that we want to fix */ + wcsncpy(szFixed, GetCommandLine(), wcslen(GetCommandLine())); + /* See if the command contains the %TEMP% environment variable */ + remain = wcsstr(szFixed, temp); + + /* If %TEMP% is contained then try to do a workaround. If not null then we will use our original copy of szFixed */ + if (remain != NULL) + { + /* Copy into string array szRemain what our pointer shows is the remainder of the command line */ + wcsncpy(szRemain, remain, wcslen(remain)); + /* Find where the %TEMP% variable starts and get into our pointer */ + remain = wcsstr(szRemain,temp); + /* Now we want to know how many characters into our original string the %TEMP% variable is found */ + cmdpos = wcslen(szFixed) - wcslen(remain); + /* Clear szFixed so that we can use "cat" functions to build our new Fixed string */ + wcscpy(szFixed, L""); + /* Used this to copy the first part of our line up to the %TEMP% variable and end with NULL character */ + wcsncat(szFixed, GetCommandLine(), cmdpos); + /* Now we add our beginning double quote by appending it */ + wcscat(szFixed, L"\""); + /* Now we add back the %TEMP% variable by appending it */ + wcscat(szFixed, temp); + /* Now we index our pointer past the %TEMP% variable pointer for remain to begin our search for space*/ + remain += wcslen(temp); + + /* Find the position of the first space after the %TEMP% variable */ + space = wcsstr(remain, L" "); + /* Now we want to know how many characters into our string the space was found */ + cmdpos = wcslen(remain) - wcslen(space); + /* Clear szCmdEnd to that we can build our ending command line */ + wcscpy(szCmdEnd, L""); + /* Used this to copy the first part of our line up to the space and end with NULL character */ + wcsncat(szCmdEnd, remain, cmdpos); + /* Now we add our beginning to the ending to get our command line up to the space after the %TEMP% variable */ + wcscat(szFixed, szCmdEnd); + /* We append the second double quote */ + wcscat(szFixed, L"\""); + /* Our space pointer points to the ending of the line, so we add it onto our modified partial command line */ + wcscat(szFixed, space); + + DPRINT1("Final szFixed is '%S'.\n", szFixed); + } + + argv = CommandLineToArgv(szFixed, &argc); +} +else +/* Original code path */ +{ + DPRINT1("Probably not BtrFS File System.\n"); argv = CommandLineToArgv(GetCommandLine(),&argc); +} // Skip all beginning arguments starting with a slash (/) for (i = 1; i < argc; i++)