mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
This improvement is meant to discard tool binaries that cannot be run. This is useful when you have an old install of VS that is broken for whatever reason. Now, we will ensure the tool has a valid exit code
57 lines
1.8 KiB
PowerShell
57 lines
1.8 KiB
PowerShell
param (
|
|
[string]
|
|
# Name of the file to find
|
|
$FileName
|
|
)
|
|
|
|
|
|
|
|
function EditBinCertificateIsValid() {
|
|
param (
|
|
[string]
|
|
$Path
|
|
)
|
|
|
|
# Verify file certificate
|
|
$valid_microsoft_cert_thumbprints = @(
|
|
"3BDA323E552DB1FDE5F4FBEE75D6D5B2B187EEDC",
|
|
"98ED99A67886D020C564923B7DF25E9AC019DF26",
|
|
"108E2BA23632620C427C570B6D9DB51AC31387FE"
|
|
)
|
|
$file_signature = Get-AuthenticodeSignature -FilePath $Path
|
|
if (($file_signature.Status -ne "Valid") -or ($valid_microsoft_cert_thumbprints -notcontains $file_signature.SignerCertificate.Thumbprint)) {
|
|
Write-Warning "Could not validate the signature of $Path"
|
|
return $false
|
|
} else {
|
|
return $true
|
|
}
|
|
}
|
|
|
|
|
|
function ToolCanBeExecuted {
|
|
param (
|
|
[string]
|
|
$Path
|
|
)
|
|
$null = & $Path
|
|
Write-Output ($LASTEXITCODE -gt 0)
|
|
}
|
|
|
|
$rootSearchPaths = @(
|
|
[System.IO.Directory]::EnumerateFileSystemEntries("C:\Program Files", "*Visual Studio*", [System.IO.SearchOption]::TopDirectoryOnly),
|
|
[System.IO.Directory]::EnumerateFileSystemEntries("C:\Program Files (x86)", "*Visual Studio*", [System.IO.SearchOption]::TopDirectoryOnly)
|
|
)
|
|
|
|
# Returns the first full path to the $FileName that our search can find
|
|
foreach ($searchPath in $rootSearchPaths) {
|
|
foreach ($visualStudioFolder in $searchPath) {
|
|
$matchingExes = [System.IO.Directory]::EnumerateFileSystemEntries($visualStudioFolder, $FileName, [System.IO.SearchOption]::AllDirectories)
|
|
foreach ($matchingExe in $matchingExes) {
|
|
if ((EditBinCertificateIsValid -Path $matchingExe) -and (ToolCanBeExecuted -Path $matchingExe)) {
|
|
return $matchingExe
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
Write-Error "Could not find any valid file by the name $FileName." -ErrorAction Stop |