From e89527a17cd467de62f5c57dde423be4096da8a6 Mon Sep 17 00:00:00 2001 From: SkyLined Date: Mon, 23 Oct 2017 17:38:14 +0200 Subject: [PATCH] Allow MemGC and PageHeap.cmd to function in odd environments * Specify full path to reg.exe and find.exe in order to prevent environments in which `reg` and `find` would resolve to different binaries from resulting in errors . --- MemGC.cmd | 14 +++++++------- PageHeap.cmd | 20 ++++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/MemGC.cmd b/MemGC.cmd index 9b043524..407b758e 100644 --- a/MemGC.cmd +++ b/MemGC.cmd @@ -12,13 +12,13 @@ IF "%~1" == "" ( CALL :SHOW_USAGE ) ELSE IF "%~1" == "ON" ( ECHO * Enabling MemGC... - REG ADD "HKCU\SOFTWARE\Microsoft\Internet Explorer\Main" /v "OverrideMemoryProtectionSetting" /t REG_DWORD /d 3 /f >nul + "%WinDir%\System32\reg.exe" ADD "HKCU\SOFTWARE\Microsoft\Internet Explorer\Main" /v "OverrideMemoryProtectionSetting" /t REG_DWORD /d 3 /f >nul IF ERRORLEVEL 1 GOTO :ERROR CALL :SHOW_STATE IF ERRORLEVEL 1 GOTO :ERROR ) ELSE IF "%~1" == "OFF" ( ECHO * Disabling MemGC... - REG ADD "HKCU\SOFTWARE\Microsoft\Internet Explorer\Main" /v "OverrideMemoryProtectionSetting" /t REG_DWORD /d 0 /f >nul + "%WinDir%\System32\reg.exe" ADD "HKCU\SOFTWARE\Microsoft\Internet Explorer\Main" /v "OverrideMemoryProtectionSetting" /t REG_DWORD /d 0 /f >nul IF ERRORLEVEL 1 GOTO :ERROR CALL :SHOW_STATE IF ERRORLEVEL 1 GOTO :ERROR @@ -41,28 +41,28 @@ EXIT /B 0 :SHOW_STATE REM Query the MemGC setting and display the current state if known. - REG QUERY "HKCU\SOFTWARE\Microsoft\Internet Explorer\Main" /v "OverrideMemoryProtectionSetting" | find "0x3" >nul + "%WinDir%\System32\reg.exe" QUERY "HKCU\SOFTWARE\Microsoft\Internet Explorer\Main" /v "OverrideMemoryProtectionSetting" | "%WinDir%\System32\find.exe" "0x3" >nul IF %ERRORLEVEL% == 0 ( ECHO + MemGC is enabled. EXIT /B 0 ) - REG QUERY "HKCU\SOFTWARE\Microsoft\Internet Explorer\Main" /v "OverrideMemoryProtectionSetting" | find "0x2" >nul + "%WinDir%\System32\reg.exe" QUERY "HKCU\SOFTWARE\Microsoft\Internet Explorer\Main" /v "OverrideMemoryProtectionSetting" | "%WinDir%\System32\find.exe" "0x2" >nul IF %ERRORLEVEL% == 0 ( ECHO - MemGC is disabled, Memory protector is enabled with forced mark-and-reclaim. EXIT /B 0 ) - REG QUERY "HKCU\SOFTWARE\Microsoft\Internet Explorer\Main" /v "OverrideMemoryProtectionSetting" | find "0x1" >nul + "%WinDir%\System32\reg.exe" QUERY "HKCU\SOFTWARE\Microsoft\Internet Explorer\Main" /v "OverrideMemoryProtectionSetting" | "%WinDir%\System32\find.exe" "0x1" >nul IF %ERRORLEVEL% == 0 ( ECHO - MemGC is disabled, Memory protector is enabled. EXIT /B 0 ) - REG QUERY "HKCU\SOFTWARE\Microsoft\Internet Explorer\Main" /v "OverrideMemoryProtectionSetting" | find "0x0" >nul + "%WinDir%\System32\reg.exe" QUERY "HKCU\SOFTWARE\Microsoft\Internet Explorer\Main" /v "OverrideMemoryProtectionSetting" | "%WinDir%\System32\find.exe" "0x0" >nul IF %ERRORLEVEL% == 0 ( ECHO - MemGC and Memory protector are disabled. EXIT /B 0 ) ECHO - Error: Unknown "OverrideMemoryProtectionSetting" value: - REG QUERY "HKCU\SOFTWARE\Microsoft\Internet Explorer\Main" /v "OverrideMemoryProtectionSetting" | find "OverrideMemoryProtectionSetting" + "%WinDir%\System32\reg.exe" QUERY "HKCU\SOFTWARE\Microsoft\Internet Explorer\Main" /v "OverrideMemoryProtectionSetting" | "%WinDir%\System32\find.exe" "OverrideMemoryProtectionSetting" PAUSE EXIT /B 1 diff --git a/PageHeap.cmd b/PageHeap.cmd index 94c19280..b98f4f61 100644 --- a/PageHeap.cmd +++ b/PageHeap.cmd @@ -28,15 +28,15 @@ IF "%~1" == "" ( ) ELSE IF "%~1" == "chrome" ( IF "%~2" == "ON" ( SET CHROME_ALLOCATOR=winheap - REG ADD "HKCU\Environment" /v "CHROME_ALLOCATOR" /t REG_SZ /d "winheap" /f + "%WinDir%\System32\reg.exe" ADD "HKCU\Environment" /v "CHROME_ALLOCATOR" /t REG_SZ /d "winheap" /f IF ERRORLEVEL 1 ( ECHO - Cannot set CHROME_ALLOCATOR enironment variable in the registry. ) ) ELSE ( SET CHROME_ALLOCATOR= - REG QUERY "HKCU\Environment" /v "CHROME_ALLOCATOR" >nul 2>&1 + "%WinDir%\System32\reg.exe" QUERY "HKCU\Environment" /v "CHROME_ALLOCATOR" >nul 2>&1 IF NOT ERRORLEVEL 1 ( - REG DELETE "HKCU\Environment" /v "CHROME_ALLOCATOR" /f >nul + "%WinDir%\System32\reg.exe" DELETE "HKCU\Environment" /v "CHROME_ALLOCATOR" /f >nul IF ERRORLEVEL 1 ( ECHO - Cannot remove CHROME_ALLOCATOR enironment variable from the registry. ) @@ -132,15 +132,15 @@ EXIT /B 0 REM 00400000 Enable close exception ## I don't think this is useful IF "%~2" == "OFF" ( ECHO * Disabling page heap for binary %~1... - REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\%~1" /v "GlobalFlag" /t REG_SZ /d "0x00000000" /f >nul + "%WinDir%\System32\reg.exe" ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\%~1" /v "GlobalFlag" /t REG_SZ /d "0x00000000" /f >nul IF ERRORLEVEL 1 GOTO :ERROR ) ELSE IF "%~2" == "ON" ( ECHO * Enabling page heap for binary %~1... - REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\%~1" /v "GlobalFlag" /t REG_SZ /d "0x02109870" /f >nul + "%WinDir%\System32\reg.exe" ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\%~1" /v "GlobalFlag" /t REG_SZ /d "0x02109870" /f >nul IF ERRORLEVEL 1 GOTO :ERROR ) ELSE IF "%~2" == "" ( ECHO * Querying current page heap flags for binary %~1... - REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\%~1" /v "GlobalFlag" 2>nul | find "GlobalFlag" + "%WinDir%\System32\reg.exe" QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\%~1" /v "GlobalFlag" 2>nul | "%WinDir%\System32\find.exe" "GlobalFlag" IF ERRORLEVEL 1 ( ECHO - No page heap settings are defined for this binary. ) @@ -153,23 +153,23 @@ EXIT /B 0 EXIT /B 0 :SHOW_PAGE_HEAP - REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\%~1" /v "GlobalFlag" 2>nul >nul + "%WinDir%\System32\reg.exe" QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\%~1" /v "GlobalFlag" 2>nul >nul IF ERRORLEVEL 1 ( ECHO - Page heap is disabled for binary %~1. EXIT /B 0 ) - REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\%~1" /v "GlobalFlag" | find "0x02109870" > nul + "%WinDir%\System32\reg.exe" QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\%~1" /v "GlobalFlag" | "%WinDir%\System32\find.exe" "0x02109870" > nul IF %ERRORLEVEL% == 0 ( ECHO + Page heap is enabled for binary %~1. EXIT /B 0 ) - REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\%~1" /v "GlobalFlag" | find "0x00000000" > nul + "%WinDir%\System32\reg.exe" QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\%~1" /v "GlobalFlag" | "%WinDir%\System32\find.exe" "0x00000000" > nul IF %ERRORLEVEL% == 0 ( ECHO - Page heap is disabled for binary %~1. EXIT /B 0 ) ECHO * Custom page heap settings are enabled for binary %~1: - REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\%~1" /v "GlobalFlag" | find "GlobalFlag" + "%WinDir%\System32\reg.exe" QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\%~1" /v "GlobalFlag" | "%WinDir%\System32\find.exe" "GlobalFlag" EXIT /B 1 :ERROR