diff options
Diffstat (limited to 'src/burn/engine/core.cpp')
| -rw-r--r-- | src/burn/engine/core.cpp | 151 |
1 files changed, 144 insertions, 7 deletions
diff --git a/src/burn/engine/core.cpp b/src/burn/engine/core.cpp index 3e45cdfc..e8c51187 100644 --- a/src/burn/engine/core.cpp +++ b/src/burn/engine/core.cpp | |||
| @@ -22,6 +22,23 @@ static HRESULT CoreRecreateCommandLine( | |||
| 22 | __in BOOTSTRAPPER_RELATION_TYPE relationType, | 22 | __in BOOTSTRAPPER_RELATION_TYPE relationType, |
| 23 | __in BOOL fPassthrough | 23 | __in BOOL fPassthrough |
| 24 | ); | 24 | ); |
| 25 | static HRESULT AppendEscapedArgumentToCommandLine( | ||
| 26 | __in_z LPCWSTR wzEscapedArgument, | ||
| 27 | __deref_inout_z LPWSTR* psczCommandLine, | ||
| 28 | __deref_inout_z_opt LPWSTR* psczObfuscatedCommandLine | ||
| 29 | ); | ||
| 30 | static HRESULT EscapeAndAppendArgumentToCommandLineFormatted( | ||
| 31 | __deref_inout_z LPWSTR* psczCommandLine, | ||
| 32 | __deref_inout_z_opt LPWSTR* psczObfuscatedCommandLine, | ||
| 33 | __in __format_string LPCWSTR wzFormat, | ||
| 34 | ... | ||
| 35 | ); | ||
| 36 | static HRESULT EscapeAndAppendArgumentToCommandLineFormattedArgs( | ||
| 37 | __deref_inout_z LPWSTR* psczCommandLine, | ||
| 38 | __deref_inout_z_opt LPWSTR* psczObfuscatedCommandLine, | ||
| 39 | __in __format_string LPCWSTR wzFormat, | ||
| 40 | __in va_list args | ||
| 41 | ); | ||
| 25 | static HRESULT AppendLayoutToCommandLine( | 42 | static HRESULT AppendLayoutToCommandLine( |
| 26 | __in BOOTSTRAPPER_ACTION action, | 43 | __in BOOTSTRAPPER_ACTION action, |
| 27 | __in_z LPCWSTR wzLayoutDirectory, | 44 | __in_z LPCWSTR wzLayoutDirectory, |
| @@ -207,11 +224,12 @@ extern "C" HRESULT CoreInitializeConstants( | |||
| 207 | for (DWORD i = 0; i < pEngineState->packages.cPackages; ++i) | 224 | for (DWORD i = 0; i < pEngineState->packages.cPackages; ++i) |
| 208 | { | 225 | { |
| 209 | BURN_PACKAGE* pPackage = pEngineState->packages.rgPackages + i; | 226 | BURN_PACKAGE* pPackage = pEngineState->packages.rgPackages + i; |
| 210 | 227 | ||
| 211 | if (BURN_PACKAGE_TYPE_EXE == pPackage->type && BURN_EXE_PROTOCOL_TYPE_BURN == pPackage->Exe.protocol) // TODO: Don't assume exePackages with burn protocol are bundles. | 228 | if (BURN_PACKAGE_TYPE_EXE == pPackage->type && BURN_EXE_PROTOCOL_TYPE_BURN == pPackage->Exe.protocol) // TODO: Don't assume exePackages with burn protocol are bundles. |
| 212 | { | 229 | { |
| 213 | // Pass along any ancestors and ourself to prevent infinite loops. | 230 | // Pass along any ancestors and ourself to prevent infinite loops. |
| 214 | pPackage->Exe.wzAncestors = pRegistration->sczBundlePackageAncestors; | 231 | pPackage->Exe.wzAncestors = pRegistration->sczBundlePackageAncestors; |
| 232 | pPackage->Exe.wzEngineWorkingDirectory = pInternalCommand->sczWorkingDirectory; | ||
| 215 | } | 233 | } |
| 216 | } | 234 | } |
| 217 | 235 | ||
| @@ -1001,6 +1019,9 @@ static HRESULT CoreRecreateCommandLine( | |||
| 1001 | ExitOnFailure(hr, "Failed to append ancestors to command-line."); | 1019 | ExitOnFailure(hr, "Failed to append ancestors to command-line."); |
| 1002 | } | 1020 | } |
| 1003 | 1021 | ||
| 1022 | hr = CoreAppendEngineWorkingDirectoryToCommandLine(pInternalCommand->sczWorkingDirectory, psczCommandLine, NULL); | ||
| 1023 | ExitOnFailure(hr, "Failed to append the custom working directory to command-line."); | ||
| 1024 | |||
| 1004 | if (wzRelationTypeCommandLine) | 1025 | if (wzRelationTypeCommandLine) |
| 1005 | { | 1026 | { |
| 1006 | hr = StrAllocConcatFormatted(psczCommandLine, L" /%ls", wzRelationTypeCommandLine); | 1027 | hr = StrAllocConcatFormatted(psczCommandLine, L" /%ls", wzRelationTypeCommandLine); |
| @@ -1060,7 +1081,7 @@ extern "C" HRESULT CoreCreateCleanRoomCommandLine( | |||
| 1060 | hr = StrAllocConcatFormatted(psczCommandLine, L" /%ls", wzLogParameter); | 1081 | hr = StrAllocConcatFormatted(psczCommandLine, L" /%ls", wzLogParameter); |
| 1061 | ExitOnFailure(hr, "Failed to append logging switch."); | 1082 | ExitOnFailure(hr, "Failed to append logging switch."); |
| 1062 | 1083 | ||
| 1063 | hr = PathCommandLineAppend(psczCommandLine, pInternalCommand->sczLogFile); | 1084 | hr = AppAppendCommandLineArgument(psczCommandLine, pInternalCommand->sczLogFile); |
| 1064 | ExitOnFailure(hr, "Failed to append custom log path."); | 1085 | ExitOnFailure(hr, "Failed to append custom log path."); |
| 1065 | } | 1086 | } |
| 1066 | 1087 | ||
| @@ -1091,7 +1112,7 @@ extern "C" HRESULT CoreCreateCleanRoomCommandLine( | |||
| 1091 | hr = StrAllocConcat(psczCommandLine, L" /originalsource", 0); | 1112 | hr = StrAllocConcat(psczCommandLine, L" /originalsource", 0); |
| 1092 | ExitOnFailure(hr, "Failed to append /originalsource."); | 1113 | ExitOnFailure(hr, "Failed to append /originalsource."); |
| 1093 | 1114 | ||
| 1094 | hr = PathCommandLineAppend(psczCommandLine, pInternalCommand->sczOriginalSource); | 1115 | hr = AppAppendCommandLineArgument(psczCommandLine, pInternalCommand->sczOriginalSource); |
| 1095 | ExitOnFailure(hr, "Failed to append original source."); | 1116 | ExitOnFailure(hr, "Failed to append original source."); |
| 1096 | } | 1117 | } |
| 1097 | 1118 | ||
| @@ -1256,6 +1277,28 @@ LExit: | |||
| 1256 | return hr; | 1277 | return hr; |
| 1257 | } | 1278 | } |
| 1258 | 1279 | ||
| 1280 | extern "C" HRESULT CoreAppendEngineWorkingDirectoryToCommandLine( | ||
| 1281 | __in_z_opt LPCWSTR wzEngineWorkingDirectory, | ||
| 1282 | __deref_inout_z LPWSTR* psczCommandLine, | ||
| 1283 | __deref_inout_z_opt LPWSTR* psczObfuscatedCommandLine | ||
| 1284 | ) | ||
| 1285 | { | ||
| 1286 | HRESULT hr = S_OK; | ||
| 1287 | LPWSTR sczArgument = NULL; | ||
| 1288 | |||
| 1289 | if (wzEngineWorkingDirectory) | ||
| 1290 | { | ||
| 1291 | hr = EscapeAndAppendArgumentToCommandLineFormatted(psczCommandLine, psczObfuscatedCommandLine, L"-%ls=%ls", BURN_COMMANDLINE_SWITCH_WORKING_DIRECTORY, wzEngineWorkingDirectory); | ||
| 1292 | ExitOnFailure(hr, "Failed to append the custom working directory to the command line."); | ||
| 1293 | } | ||
| 1294 | |||
| 1295 | LExit: | ||
| 1296 | ReleaseStr(sczArgument); | ||
| 1297 | |||
| 1298 | return hr; | ||
| 1299 | } | ||
| 1300 | |||
| 1301 | |||
| 1259 | extern "C" void CoreCleanup( | 1302 | extern "C" void CoreCleanup( |
| 1260 | __in BURN_ENGINE_STATE* pEngineState | 1303 | __in BURN_ENGINE_STATE* pEngineState |
| 1261 | ) | 1304 | ) |
| @@ -1678,6 +1721,27 @@ extern "C" HRESULT CoreParseCommandLine( | |||
| 1678 | ExitOnFailure(hr, "Failed to allocate the list of ancestors."); | 1721 | ExitOnFailure(hr, "Failed to allocate the list of ancestors."); |
| 1679 | } | 1722 | } |
| 1680 | } | 1723 | } |
| 1724 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, &argv[i][1], lstrlenW(BURN_COMMANDLINE_SWITCH_WORKING_DIRECTORY), BURN_COMMANDLINE_SWITCH_WORKING_DIRECTORY, lstrlenW(BURN_COMMANDLINE_SWITCH_WORKING_DIRECTORY))) | ||
| 1725 | { | ||
| 1726 | // Get a pointer to the next character after the switch. | ||
| 1727 | LPCWSTR wzParam = &argv[i][1 + lstrlenW(BURN_COMMANDLINE_SWITCH_WORKING_DIRECTORY)]; | ||
| 1728 | if (L'=' != wzParam[0]) | ||
| 1729 | { | ||
| 1730 | fInvalidCommandLine = TRUE; | ||
| 1731 | TraceLog(E_INVALIDARG, "Invalid switch: %ls", argv[i]); | ||
| 1732 | } | ||
| 1733 | else if (L'\0' == wzParam[1]) | ||
| 1734 | { | ||
| 1735 | // Need to grab the current directory here since this is passed on to other processes. | ||
| 1736 | hr = DirGetCurrent(&pInternalCommand->sczWorkingDirectory); | ||
| 1737 | ExitOnFailure(hr, "Failed to get current directory for custom working directory."); | ||
| 1738 | } | ||
| 1739 | else | ||
| 1740 | { | ||
| 1741 | hr = StrAllocString(&pInternalCommand->sczWorkingDirectory, wzParam + 1, 0); | ||
| 1742 | ExitOnFailure(hr, "Failed to allocate the custom working directory."); | ||
| 1743 | } | ||
| 1744 | } | ||
| 1681 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, &argv[i][1], lstrlenW(BURN_COMMANDLINE_SWITCH_FILEHANDLE_ATTACHED), BURN_COMMANDLINE_SWITCH_FILEHANDLE_ATTACHED, lstrlenW(BURN_COMMANDLINE_SWITCH_FILEHANDLE_ATTACHED))) | 1745 | else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, &argv[i][1], lstrlenW(BURN_COMMANDLINE_SWITCH_FILEHANDLE_ATTACHED), BURN_COMMANDLINE_SWITCH_FILEHANDLE_ATTACHED, lstrlenW(BURN_COMMANDLINE_SWITCH_FILEHANDLE_ATTACHED))) |
| 1682 | { | 1746 | { |
| 1683 | LPCWSTR wzParam = &argv[i][2 + lstrlenW(BURN_COMMANDLINE_SWITCH_FILEHANDLE_ATTACHED)]; | 1747 | LPCWSTR wzParam = &argv[i][2 + lstrlenW(BURN_COMMANDLINE_SWITCH_FILEHANDLE_ATTACHED)]; |
| @@ -1807,6 +1871,79 @@ LExit: | |||
| 1807 | 1871 | ||
| 1808 | // internal helper functions | 1872 | // internal helper functions |
| 1809 | 1873 | ||
| 1874 | static HRESULT AppendEscapedArgumentToCommandLine( | ||
| 1875 | __in_z LPCWSTR wzEscapedArgument, | ||
| 1876 | __deref_inout_z LPWSTR* psczCommandLine, | ||
| 1877 | __deref_inout_z_opt LPWSTR* psczObfuscatedCommandLine | ||
| 1878 | ) | ||
| 1879 | { | ||
| 1880 | HRESULT hr = S_OK; | ||
| 1881 | |||
| 1882 | // If there is already data in the command line, | ||
| 1883 | // append a space before appending the argument. | ||
| 1884 | if (*psczCommandLine && **psczCommandLine) | ||
| 1885 | { | ||
| 1886 | hr = StrAllocConcatSecure(psczCommandLine, L" ", 0); | ||
| 1887 | ExitOnFailure(hr, "Failed to append space to command line with existing data."); | ||
| 1888 | } | ||
| 1889 | |||
| 1890 | hr = StrAllocConcatSecure(psczCommandLine, wzEscapedArgument, 0); | ||
| 1891 | ExitOnFailure(hr, "Failed to append escaped command line argument."); | ||
| 1892 | |||
| 1893 | if (psczObfuscatedCommandLine) | ||
| 1894 | { | ||
| 1895 | if (*psczObfuscatedCommandLine && **psczObfuscatedCommandLine) | ||
| 1896 | { | ||
| 1897 | hr = StrAllocConcat(psczObfuscatedCommandLine, L" ", 0); | ||
| 1898 | ExitOnFailure(hr, "Failed to append space to obfuscated command line with existing data."); | ||
| 1899 | } | ||
| 1900 | |||
| 1901 | hr = StrAllocConcat(psczObfuscatedCommandLine, wzEscapedArgument, 0); | ||
| 1902 | ExitOnFailure(hr, "Failed to append escaped argument to obfuscated command line."); | ||
| 1903 | } | ||
| 1904 | |||
| 1905 | LExit: | ||
| 1906 | return hr; | ||
| 1907 | } | ||
| 1908 | |||
| 1909 | static HRESULT EscapeAndAppendArgumentToCommandLineFormatted( | ||
| 1910 | __deref_inout_z LPWSTR* psczCommandLine, | ||
| 1911 | __deref_inout_z_opt LPWSTR* psczObfuscatedCommandLine, | ||
| 1912 | __in __format_string LPCWSTR wzFormat, | ||
| 1913 | ... | ||
| 1914 | ) | ||
| 1915 | { | ||
| 1916 | HRESULT hr = S_OK; | ||
| 1917 | va_list args; | ||
| 1918 | |||
| 1919 | va_start(args, wzFormat); | ||
| 1920 | hr = EscapeAndAppendArgumentToCommandLineFormattedArgs(psczCommandLine, psczObfuscatedCommandLine, wzFormat, args); | ||
| 1921 | va_end(args); | ||
| 1922 | |||
| 1923 | return hr; | ||
| 1924 | } | ||
| 1925 | |||
| 1926 | static HRESULT EscapeAndAppendArgumentToCommandLineFormattedArgs( | ||
| 1927 | __deref_inout_z LPWSTR* psczCommandLine, | ||
| 1928 | __deref_inout_z_opt LPWSTR* psczObfuscatedCommandLine, | ||
| 1929 | __in __format_string LPCWSTR wzFormat, | ||
| 1930 | __in va_list args | ||
| 1931 | ) | ||
| 1932 | { | ||
| 1933 | HRESULT hr = S_OK; | ||
| 1934 | LPWSTR sczArgument = NULL; | ||
| 1935 | |||
| 1936 | hr = AppEscapeCommandLineArgumentFormattedArgs(&sczArgument, wzFormat, args); | ||
| 1937 | ExitOnFailure(hr, "Failed to escape the argument for the command line."); | ||
| 1938 | |||
| 1939 | hr = AppendEscapedArgumentToCommandLine(sczArgument, psczCommandLine, psczObfuscatedCommandLine); | ||
| 1940 | |||
| 1941 | LExit: | ||
| 1942 | ReleaseStr(sczArgument); | ||
| 1943 | |||
| 1944 | return hr; | ||
| 1945 | } | ||
| 1946 | |||
| 1810 | static HRESULT AppendLayoutToCommandLine( | 1947 | static HRESULT AppendLayoutToCommandLine( |
| 1811 | __in BOOTSTRAPPER_ACTION action, | 1948 | __in BOOTSTRAPPER_ACTION action, |
| 1812 | __in_z LPCWSTR wzLayoutDirectory, | 1949 | __in_z LPCWSTR wzLayoutDirectory, |
| @@ -1822,7 +1959,7 @@ static HRESULT AppendLayoutToCommandLine( | |||
| 1822 | 1959 | ||
| 1823 | if (wzLayoutDirectory) | 1960 | if (wzLayoutDirectory) |
| 1824 | { | 1961 | { |
| 1825 | hr = PathCommandLineAppend(psczCommandLine, wzLayoutDirectory); | 1962 | hr = AppAppendCommandLineArgument(psczCommandLine, wzLayoutDirectory); |
| 1826 | ExitOnFailure(hr, "Failed to append layout directory."); | 1963 | ExitOnFailure(hr, "Failed to append layout directory."); |
| 1827 | } | 1964 | } |
| 1828 | } | 1965 | } |
| @@ -1883,16 +2020,16 @@ static HRESULT GetSanitizedCommandLine( | |||
| 1883 | } | 2020 | } |
| 1884 | 2021 | ||
| 1885 | // Remember command-line switch to pass off to BA. | 2022 | // Remember command-line switch to pass off to BA. |
| 1886 | PathCommandLineAppend(&pCommand->wzCommandLine, argv[i]); | 2023 | AppAppendCommandLineArgument(&pCommand->wzCommandLine, argv[i]); |
| 1887 | } | 2024 | } |
| 1888 | 2025 | ||
| 1889 | if (fHidden) | 2026 | if (fHidden) |
| 1890 | { | 2027 | { |
| 1891 | PathCommandLineAppend(psczSanitizedCommandLine, sczSanitizedArgument); | 2028 | AppAppendCommandLineArgument(psczSanitizedCommandLine, sczSanitizedArgument); |
| 1892 | } | 2029 | } |
| 1893 | else | 2030 | else |
| 1894 | { | 2031 | { |
| 1895 | PathCommandLineAppend(psczSanitizedCommandLine, argv[i]); | 2032 | AppAppendCommandLineArgument(psczSanitizedCommandLine, argv[i]); |
| 1896 | } | 2033 | } |
| 1897 | } | 2034 | } |
| 1898 | 2035 | ||
