Compare commits

...

5 Commits
v1.37 ... v1.41

Author SHA1 Message Date
Pete Batard
9552df66d5 Update language option regexp to match latest Microsoft HTML fragment
* Addresses pbatard/rufus#2146
* Also update .gitattributes to clean up release archives
2023-01-25 20:04:14 +00:00
Pete Batard
4bafb688da Remove unneeded files
* .whitesource is unneeded because we don't use external dependencies.
* VS project files are unneeded when we just edit the .ps1 in a text editor.
2023-01-11 20:22:13 +00:00
Pete Batard
ad79094c30 Improve error handling and reporting when querying vlscppe.microsoft.com
* Also use a better default icon and add a preemptive localized message for
  future countermeasures from Microsoft.
2023-01-09 17:32:59 +00:00
Pete Batard
8cf4a279ff Work around Microsoft's new ISO download countermeasures
* The Microsoft servers now use session Id whitelisting, so add querying
  of https://vlscppe.microsoft.com/tags with the session Id.
* Closes #52.
* Also harmonize/improve -replace calls
* Also make sure we use POST for the getskuinformationbyproductedition
  query (in case Microsoft add some more countermeasures).
* Also drop 'cmd /c' invocation in sign.sh since the cygwin people can't
  seem to get their act together there...
2023-01-08 22:10:01 +00:00
Pete Batard
84f833b067 Improve error reporting
* Now return the error message from the Microsoft server where possible (See #52)
2023-01-06 21:58:20 +00:00
6 changed files with 61 additions and 106 deletions

3
.gitattributes vendored
View File

@@ -1,3 +1,6 @@
* text=auto
*.ps1 eol=crlf
*.sh eol=lf
.gitattributes export-ignore
.gitignore export-ignore
sign.sh export-ignore

View File

@@ -1,8 +0,0 @@
{
"checkRunSettings": {
"vulnerableCheckRunConclusionLevel": "failure"
},
"issueSettings": {
"minSeverityLevel": "LOW"
}
}

View File

@@ -1,6 +1,6 @@
#
# Fido v1.37 - Feature ISO Downloader, for retail Windows images and UEFI Shell
# Copyright © 2019-2022 Pete Batard <pete@akeo.ie>
# Fido v1.41 - 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
#
@@ -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.
@@ -499,7 +499,7 @@ function ConvertTo-ImageSource
function Throw-Error([object]$Req, [string]$Alt)
{
$Err = $(GetElementById -Request $r -Id "errorModalMessage").innerText
$Err = $(GetElementById -Request $Req -Id "errorModalMessage").innerText -replace "<[^>]+>" -replace "\s+", " "
if (-not $Err) {
$Err = $Alt
} else {
@@ -602,7 +602,7 @@ $RequestData["GetLangs"] = @("a8f8f489-4c7f-463a-9ca6-5cff94d8d041", "getskuinfo
# This GUID applies to visitors of the en-US download page. Other locales may get a different GUID.
$RequestData["GetLinks"] = @("6e2a1789-ef16-4f27-a296-74ef7ef5d96b", "GetProductDownloadLinksBySku" )
# Create a semi-random Linux User-Agent string
$FirefoxVersion = Get-Random -Minimum 50 -Maximum 90
$FirefoxVersion = Get-Random -Minimum 90 -Maximum 110
$FirefoxDate = Get-RandomDate
$UserAgent = "Mozilla/5.0 (X11; Linux i586; rv:$FirefoxVersion.0) Gecko/$FirefoxDate Firefox/$FirefoxVersion.0"
$Verbosity = 2
@@ -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
@@ -710,6 +710,17 @@ function Get-Windows-Languages([int]$SelectedVersion, [int]$SelectedEdition)
} elseif ($WindowsVersions[$SelectedVersion][0][1].StartsWith("UEFI_SHELL")) {
$languages += @(New-Object PsObject -Property @{ DisplayLanguage = "English (US)"; Language = "en-us"; Id = 0 })
} 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
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"
@@ -724,11 +735,12 @@ function Get-Windows-Languages([int]$SelectedVersion, [int]$SelectedEdition)
$script:SelectedIndex = 0
try {
$r = Invoke-WebRequest -UseBasicParsing -UserAgent $UserAgent -SessionVariable "Session" $url
$r = Invoke-WebRequest -Method Post -UseBasicParsing -UserAgent $UserAgent -SessionVariable "Session" $url
if ($r -match "errorModalMessage") {
Throw-Error -Req $r -Alt "Could not retrieve languages from server"
}
$pattern = '(?s)<select id="product-languages">(.*)?</select>'
$r = $r -replace "`n" -replace "`r"
$pattern = '.*<select id="product-languages"[^>]+>(.*)</select>.*'
$html = [regex]::Match($r, $pattern).Groups[1].Value
# Go through an XML conversion to keep all PowerShells happy...
$html = $html.Replace("selected value", "value")
@@ -811,7 +823,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}'
@@ -824,7 +836,15 @@ function Get-Windows-Download-Links([int]$SelectedVersion, [int]$SelectedRelease
$sr = New-Object System.IO.StreamReader($wr.GetResponse().GetResponseStream())
$r = $sr.ReadToEnd()
if ($r -match "errorModalMessage") {
Throw-Error -Req $r -Alt "Could not retrieve architectures from server"
$regex = New-Object Text.RegularExpressions.Regex '<p id="errorModalMessage">(.+?)<\/p>'
$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 + "."
if (-not $Alt) {
$Alt = "Could not retrieve architectures from server"
}
Throw-Error -Req $r -Alt $Alt
}
$pattern = '(?s)(<input.*?></input>)'
ForEach-Object { [regex]::Matches($r, $pattern) } | ForEach-Object { $html += $_.Groups[1].value }
@@ -956,7 +976,7 @@ if ($Cmd) {
if (!$Ed -and $Verbosity -ge 1) {
Write-Host "No edition specified (-Ed). Defaulting to '$($edition.Edition)'."
}
$Selected += "," + $edition.Edition -replace "Windows [0-9\.]*", ""
$Selected += "," + $edition.Edition -replace "Windows [0-9\.]*"
$winEditionId = $edition.Id
break;
}
@@ -1054,7 +1074,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"
@@ -1192,8 +1212,8 @@ exit $ExitCode
# SIG # Begin signature block
# MIIkWAYJKoZIhvcNAQcCoIIkSTCCJEUCAQExDzANBglghkgBZQMEAgEFADB5Bgor
# BgEEAYI3AgEEoGswaTA0BgorBgEEAYI3AgEeMCYCAwEAAAQQH8w7YFlLCE63JNLG
# KX7zUQIBAAIBAAIBAAIBAAIBADAxMA0GCWCGSAFlAwQCAQUABCCIu9oI700HZxb3
# w6BvRyJWzIrL4aGutJadchpCiPvxiaCCElkwggVvMIIEV6ADAgECAhBI/JO0YFWU
# KX7zUQIBAAIBAAIBAAIBAAIBADAx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zdwoWM0m
# 7f2eqqbMymXmX0msLnW3fITTw19Hun1fo9YebTmgXd5XttgHvFmjdHUkZnQAZDt7
# dk9h3KkGNqd5PMPiVAZnI8/ubaqV9Py+dGWT2bmdyBMan2CoU2U9sfAyIclGHxvn
# 1dbDS9NZpruOH4GTYtcPqROkN/sePoCKWqu5hzdq7HuAdsyQmf/6OP6JL7yft1Rb
# ZKHERak8wQqsgu5B/6f5j+M3vE01ZIWHvgaMrC/a6+EzeormRQAuF3B8Eg9a7/AU
# 0C/w9SiFOKg4NYuUu2i+68HTNGTVhBUZ3eas1gZdz4AvYRj47BYIG62Ijhw=
# DQEJAzENBgsqhkiG9w0BCRABBDAcBgkqhkiG9w0BCQUxDxcNMjMwMTI1MjAwMTEw
# WjAvBgkqhkiG9w0BCQQxIgQgc3vhzrShNhu9c86BzACvzjsyq6mGfUC5lnjnmheR
# lXQwNwYLKoZIhvcNAQkQAi8xKDAmMCQwIgQgxHTOdgB9AjlODaXk3nwUxoD54oIB
# PP72U+9dtx/fYfgwCwYJKoZIhvcNAQEBBIIBABFl9vc68ULyXJl07hEAx9S8cbMg
# 3klf7ORGPe0ttXXsQZPldKylCAqT8XuJRZMAOYrMhMvG79N8LIETXvyhgyVdGGzy
# rZkVIry6HXkAuZysJ+8xu4Oshf6NFMHs1ATTg2jLWBZ8r39GrUAu1oSL+q8laQE3
# HvBvmWaM4Yv1/N1OdEHcgw2Zdxvy8P6g3bfNzv1SqMtf3Nn4TUv0RQZ5GJ9e8cfN
# W19bcP37k5QR4AIuG3ItzEAyHppFYGM2bQ+X0KtWmWGpFeRd6Zd/pauS1PD7f87q
# d7bG1jvjgyLAuxGxF/xSN/QizrOvWnV1Eya13mELBDNtg9UhUcxzmofj4Zw=
# SIG # End signature block

View File

@@ -1,35 +0,0 @@
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>6CAFC0C6-A428-4d30-A9F9-700E829FEA51</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Fido</RootNamespace>
<AssemblyName>Fido</AssemblyName>
<Name>Frida</Name>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup />
<ItemGroup>
<Compile Include="Fido.ps1" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Target Name="Build" />
<Import Project="$(MSBuildExtensionsPath)\PowerShell Tools for Visual Studio\PowerShellTools.targets" Condition="Exists('$(MSBuildExtensionsPath)\PowerShell Tools for Visual Studio\PowerShellTools.targets')" />
</Project>

View File

@@ -1,25 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.271
MinimumVisualStudioVersion = 10.0.40219.1
Project("{F5034706-568F-408A-B7B3-4D38C6DB8A32}") = "Fido", "Fido.pssproj", "{6CAFC0C6-A428-4D30-A9F9-700E829FEA51}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6CAFC0C6-A428-4D30-A9F9-700E829FEA51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6CAFC0C6-A428-4D30-A9F9-700E829FEA51}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6CAFC0C6-A428-4D30-A9F9-700E829FEA51}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6CAFC0C6-A428-4D30-A9F9-700E829FEA51}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AD54CEAE-0992-4213-BEDB-8F1CF98A9F22}
EndGlobalSection
EndGlobal

View File

@@ -21,7 +21,7 @@ sign_file() {
}
# Update the Authenticode signature
cmd.exe /c '"C:\Program Files (x86)\Windows Kits\10\bin\10.0.22000.0\x64\signtool" sign /v /sha1 3dbc3a2a0e9ce8803b422cfdbc60acd33164965d /fd SHA256 /tr http://sha256timestamp.ws.symantec.com/sha256/timestamp /td SHA256 Fido.ps1'
MSYS2_ARG_CONV_EXCL='*' "C:\Program Files (x86)\Windows Kits\10\bin\10.0.22000.0\x64\signtool" sign /v /sha1 3dbc3a2a0e9ce8803b422cfdbc60acd33164965d /fd SHA256 /tr http://sha256timestamp.ws.symantec.com/sha256/timestamp /td SHA256 Fido.ps1
read -s -p "Enter pass phrase for `realpath $PRIVATE_KEY`: " PASSWORD
echo
# Confirm that the pass phrase is valid by trying to sign a dummy file