Skip to content

Commit

Permalink
Improve error handling and reporting when querying vlscppe.microsoft.com
Browse files Browse the repository at this point in the history
* Also use a better default icon and add a preemptive localized message for
  future countermeasures from Microsoft.
  • Loading branch information
pbatard committed Jan 9, 2023
1 parent 8cf4a27 commit ad79094
Showing 1 changed file with 41 additions and 33 deletions.
74 changes: 41 additions & 33 deletions Fido.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Fido v1.39 - Feature ISO Downloader, for retail Windows images and UEFI Shell
# Fido v1.40 - Feature ISO Downloader, for retail Windows images and UEFI Shell
# Copyright © 2019-2023 Pete Batard <pete@akeo.ie>
# Command line support: Copyright © 2021 flx5
# ConvertTo-ImageSource: Copyright © 2016 Chris Carter
Expand All @@ -24,7 +24,7 @@
#region Parameters
param(
# (Optional) The title to display on the application window.
[string]$AppTitle = "Fido - Retail Windows ISO Downloader",
[string]$AppTitle = "Fido - Feature ISO Downloader",
# (Optional) '|' separated UI localization strings.
[string]$LocData,
# (Optional) Path to a file that should be used for the UI icon.
Expand Down Expand Up @@ -617,7 +617,7 @@ if ($Cmd) {

# Localization
$EnglishMessages = "en-US|Version|Release|Edition|Language|Architecture|Download|Continue|Back|Close|Cancel|Error|Please wait...|" +
"Download using a browser|Temporarily banned by Microsoft for requesting too many downloads - Please try again later...|" +
"Download using a browser|Download of Windows ISOs is unavailable due to Microsoft having altered their website to prevent it.|" +
"PowerShell 3.0 or later is required to run this script.|Do you want to go online and download it?"
[string[]]$English = $EnglishMessages.Split('|')
[string[]]$Localized = $null
Expand Down Expand Up @@ -712,7 +712,15 @@ function Get-Windows-Languages([int]$SelectedVersion, [int]$SelectedEdition)
} else {
# Microsoft download protection now requires the sessionId to be whitelisted through vlscppe.microsoft.com/tags
$url = "https://vlscppe.microsoft.com/tags?org_id=y6jn8c31&session_id=" + $SessionId
Invoke-WebRequest -UseBasicParsing -MaximumRedirection 0 -UserAgent $UserAgent $url | Out-Null
if ($Verbosity -ge 2) {
Write-Host Querying $url
}
try {
Invoke-WebRequest -UseBasicParsing -MaximumRedirection 0 -UserAgent $UserAgent $url | Out-Null
} catch {
Error($_.Exception.Message)
return @()
}
$url = "https://www.microsoft.com/" + $QueryLocale + "/api/controls/contentinclude/html"
$url += "?pageId=" + $RequestData["GetLangs"][0]
$url += "&host=www.microsoft.com"
Expand Down Expand Up @@ -814,7 +822,7 @@ function Get-Windows-Download-Links([int]$SelectedVersion, [int]$SelectedRelease

try {
$Is64 = [Environment]::Is64BitOperatingSystem
# Must add a referer for POST requests, else Microsoft's servers will deny them
# Must add a referer for this request, else Microsoft's servers will deny it
$ref = "https://www.microsoft.com/software-download/windows11"
$wr = [System.Net.WebRequest]::Create($url)
# Windows 7 PowerShell doesn't support 'Invoke-WebRequest -Headers @{"Referer" = $ref}'
Expand All @@ -831,7 +839,7 @@ function Get-Windows-Download-Links([int]$SelectedVersion, [int]$SelectedRelease
$m = $regex.Match($r)
# Make the typical error message returned by Microsoft's servers more presentable
$Alt = $m.Groups[1] -replace "<[^>]+>" -replace "\s+", " "
$Alt += " " + $SessionId
$Alt += " " + $SessionId + "."
if (-not $Alt) {
$Alt = "Could not retrieve architectures from server"
}
Expand Down Expand Up @@ -1065,7 +1073,7 @@ $XMLForm.Title = $AppTitle
if ($Icon) {
$XMLForm.Icon = $Icon
} else {
$XMLForm.Icon = [Gui.Utils]::ExtractIcon("shell32.dll", -41, $true) | ConvertTo-ImageSource
$XMLForm.Icon = [Gui.Utils]::ExtractIcon("imageres.dll", -5205, $true) | ConvertTo-ImageSource
}
if ($Locale.StartsWith("ar") -or $Locale.StartsWith("fa") -or $Locale.StartsWith("he")) {
$XMLForm.FlowDirection = "RightToLeft"
Expand Down Expand Up @@ -1203,8 +1211,8 @@ exit $ExitCode
# SIG # Begin signature block
# MIIkWQYJKoZIhvcNAQcCoIIkSjCCJEYCAQExDzANBglghkgBZQMEAgEFADB5Bgor
# BgEEAYI3AgEEoGswaTA0BgorBgEEAYI3AgEeMCYCAwEAAAQQH8w7YFlLCE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AI
# z7bGgUFgJ4DVEbQWvy9/mMOpO50DsmwNdAFqj67N9wfZm6mPTiDldINEAN6K3QtN
# oGn9d/kLGKY3Uxxej0TLNb8wCpQPWMgryyHy32PjSvbaXnDy8FLUnw9u5NpgK7qV
# EJjcjiwTaR+PrDbskzu+knaphRGWkk8TmqKVLC3Zi/puTeDBafarunOPzXIV
# SIG # End signature block

0 comments on commit ad79094

Please sign in to comment.