Skip to content

Instantly share code, notes, and snippets.

@lazerl0rd
Last active March 28, 2022 14:30
Show Gist options
  • Save lazerl0rd/8f63d1f42f1863ca91b7a37c02bdb1f3 to your computer and use it in GitHub Desktop.
Save lazerl0rd/8f63d1f42f1863ca91b7a37c02bdb1f3 to your computer and use it in GitHub Desktop.
$arr = @()
$nvlaxwslpath = '$HOME/nvlax/build/nvlax_encode'
$temppath = "$env:TEMP\NVENC Patcher"
$arr += , @("$env:WINDIR\SysWOW64", "nvEncodeAPI.dll")
$arr += , @("$env:WINDIR\System32", "nvEncodeAPI64.dll")
Try {
New-Item -Path $temppath -ItemType Directory -Force
Start-Process cipher.exe -ArgumentList ("/D /S:`"" + $temppath + "`"") -Wait -NoNewWindow
Push-Location -Path $temppath
ForEach ($i in $arr) {
Start-Process wsl.exe -ArgumentList ($nvlaxwslpath + " -i " + "`$(wslpath -a `"" + ($i[0] + "\" + $i[1]) + "`") -o " + $i[1]) -Wait -NoNewWindow -RedirectStandardError "error.log" -RedirectStandardOutput "output.log"
If ((Get-Content "output.log") -Like "*successfully*") {
Start-Process powershell.exe -Verb runAs -ArgumentList ("-Command Copy-Item -Path '" + $temppath + "\" + $i[1] + "' -Destination '" + ($i[0] + "\" + $i[1]) + "' -Force") -Wait
Write-Host "The NVENC library,", (($i[0] + "\" + $i[1]) + ","), "was patched."
}
ElseIf ((Get-Content "error.log") -Like "*signature seems corrupted*") {
Write-Host "The patch has already been applied to the", ($i[0] + "\" + $i[1]), "library."
}
Else {
Throw ""
}
}
}
Catch [System.Management.Automation.CommandNotFoundException] { Write-Host "There was an error using WSL. This patch requires WSL set up with a nvlax_encode binary at", ($nvlaxwslpath + ".") }
Catch [System.InvalidOperationException] { Write-Host "There was an error requesting admin privileges." }
Catch {
Write-Host "There was an error running patching the NVENC libraries."
Write-Host $_
}
Finally {
Pop-Location
Remove-Item $temppath -Recurse -ErrorAction SilentlyContinue
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment