Skip to content

Commit

Permalink
Allow MemGC and PageHeap.cmd to function in odd environments
Browse files Browse the repository at this point in the history
* 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
.
  • Loading branch information
SkyLined committed Oct 23, 2017
1 parent 8db5dc2 commit e89527a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
14 changes: 7 additions & 7 deletions MemGC.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
20 changes: 10 additions & 10 deletions PageHeap.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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.
)
Expand Down Expand Up @@ -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.
)
Expand All @@ -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
Expand Down

0 comments on commit e89527a

Please sign in to comment.