Skip to content

Instantly share code, notes, and snippets.

@pawlos
Forked from kruxmeier/fix vmwp.bat
Created February 16, 2021 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pawlos/c48c9ebe545161ed304f335dd84ae0cb to your computer and use it in GitHub Desktop.
Save pawlos/c48c9ebe545161ed304f335dd84ae0cb to your computer and use it in GitHub Desktop.
enable hardware performance counters in WSL2
REM open cmd.exe as admin to run this
REM Creates a patched vmwp.exe replacing these bytes:
REM 0F B6 43 64 41 89 47 64 0F B6 43 65 41 89 47 68 0F B6 43 66 41 89 47 6C 0F B6 43 67 41 89 47 70
REM 41 C7 47 64 01 00 00 00 41 C7 47 68 01 00 00 00 41 C7 47 6C 01 00 00 00 41 C7 47 70 01 00 00 00
REM Enables PMU, LBR, PEBS, IPT
cd %TEMP%
copy %windir%\system32\vmwp.exe .
@REM version with Intel Processor Trace
wsl bash -c "sed -i 's#\x0F\xB6\x43\x64\x41\x89\x47\x64\x0F\xB6\x43\x65\x41\x89\x47\x68\x0F\xB6\x43\x66\x41\x89\x47\x6C\x0F\xB6\x43\x67\x41\x89\x47\x70#\x41\xC7\x47\x64\x01\x00\x00\x00\x41\xC7\x47\x68\x01\x00\x00\x00\x41\xC7\x47\x6C\x01\x00\x00\x00\x41\xC7\x47\x70\x01\x00\x00\x00#g' vmwp.exe"
@REM version without Intel Processor Trace
@REM wsl bash -c "sed -i 's#\x0F\xB6\x43\x64\x41\x89\x47\x64\x0F\xB6\x43\x65\x41\x89\x47\x68\x0F\xB6\x43\x66\x41\x89\x47\x6C#\x41\xC7\x47\x64\x01\x00\x00\x00\x41\xC7\x47\x68\x01\x00\x00\x00\x41\xC7\x47\x6C\x01\x00\x00\x00#g' vmwp.exe"
wsl --shutdown
@REM taskkill /F /IM vmwp.exe
@REM taskkill /F /IM vmmem
takeown /F %windir%\system32\vmwp.exe /A
icacls %windir%\system32\vmwp.exe /grant Administrators:F
icacls %windir%\system32\vmwp.exe /grant Administratoren:F
move /Y %windir%\system32\vmwp.exe %windir%\system32\vmwp.exe.bak
move /Y vmwp.exe %windir%\system32
wsl bash -c "echo 'Patch successfully applied'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment