Skip to content

Commit

Permalink
Fix architecture (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
potatoqualitee authored Aug 1, 2022
1 parent dff4c4e commit 80301c6
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 25 deletions.
124 changes: 117 additions & 7 deletions public/Get-KbUpdate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,46 @@ function Get-KbUpdate {
if ($item.SupportedProducts -match "\|") {
$item.SupportedProducts = $item.SupportedProducts -split "\|"
}

if ($item.Architecture -eq "n/a") {
$item.Architecture = $null
}
if ($item.title -match "ia32") {
$item.Architecture = "IA32"
}
if ($item.title -match "ia64") {
$item.Architecture = "IA64"
}
if ($item.title -match "64-Bit" -and $item.title -notmatch "32-Bit" -and -not $item.Architecture) {
$item.Architecture = "x64"
}
if ($item.title -notmatch "64-Bit" -and $item.title -match "32-Bit" -and -not $item.Architecture) {
$item.Architecture = "x86"
}
if ($item.title -match "x64" -or $item.title -match "AMD64") {
$item.Architecture = "x64"
}
if ($item.title -match "x86") {
$item.Architecture = "x86"
}
if ($item.title -match "ARM64") {
$item.Architecture = "ARM64"
}
if ($item.title -match "ARM-based") {
$item.Architecture = "ARM32"
}
if ($item.link -match "x64" -or $item.link -match "AMD64" -and -not $item.Architecture) {
$item.Architecture = "x64"
}
if ($item.link -match "x86" -and -not $item.Architecture) {
$item.Architecture = "x86"
}
if ($item.link -match "ARM64" -and -not $item.Architecture) {
$item.Architecture = "ARM64"
}
if ($item.link -match "ARM-based" -and -not $item.Architecture) {
$item.Architecture = "ARM32"
}
}

if (-not $item -and $Source -eq "Database") {
Expand Down Expand Up @@ -206,6 +246,44 @@ function Get-KbUpdate {
$link = $null
}

if ($title -match "ia32") {
$arch = "IA32"
}
if ($title -match "ia64") {
$arch = "IA64"
}
if ($title -match "64-Bit" -and $title -notmatch "32-Bit" -and -not $arch) {
$arch = "x64"
}
if ($title -notmatch "64-Bit" -and $title -match "32-Bit" -and -not $arch) {
$arch = "x86"
}
if ($title -match "x64" -or $title -match "AMD64") {
$arch = "x64"
}
if ($title -match "x86") {
$arch = "x86"
}
if ($title -match "ARM64") {
$arch = "ARM64"
}
if ($title -match "ARM-based") {
$arch = "ARM32"
}

if ($link -match "x64" -or $link -match "AMD64" -and -not $arch) {
$arch = "x64"
}
if ($link -match "x86" -and -not $arch) {
$arch = "x86"
}
if ($link -match "ARM64" -and -not $arch) {
$arch = "ARM64"
}
if ($link -match "ARM-based" -and -not $arch) {
$arch = "ARM32"
}

$null = $script:kbcollection.Add($hashkey, (
[pscustomobject]@{
Title = $wsuskb.Title
Expand Down Expand Up @@ -379,7 +457,7 @@ function Get-KbUpdate {

foreach ($downloaddialog in $downloaddialogs) {
$title = Get-Info -Text $downloaddialog -Pattern 'enTitle ='
$arch = Get-Info -Text $downloaddialog -Pattern 'architectures ='
$arch = $null
$longlang = Get-Info -Text $downloaddialog -Pattern 'longLanguages ='
if ($Pattern -match '^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$') {
$updateid = "$Pattern"
Expand All @@ -394,21 +472,34 @@ function Get-KbUpdate {
} else {
$ishotfix = "False"
}

if ($longlang -eq "all") {
$longlang = "All"
}
if ($arch -eq "") {
$arch = $null
if ($title -match "ia32") {
$arch = "IA32"
}
if ($arch -eq "AMD64") {
if ($title -match "ia64") {
$arch = "IA64"
}
if ($title -match "64-Bit" -and $title -notmatch "32-Bit" -and -not $arch) {
$arch = "x64"
}
if ($title -match '64-Bit' -and $title -notmatch '32-Bit' -and -not $arch) {
if ($title -notmatch "64-Bit" -and $title -match "32-Bit" -and -not $arch) {
$arch = "x86"
}
if ($title -match "x64" -or $title -match "AMD64") {
$arch = "x64"
}
if ($title -notmatch '64-Bit' -and $title -match '32-Bit' -and -not $arch) {
if ($title -match "x86") {
$arch = "x86"
}
if ($title -match "ARM64") {
$arch = "ARM64"
}
if ($title -match "ARM-based") {
$arch = "ARM32"
}

if (-not $Simple) {
# Multi-byte character is corrupted if passing BasicHtmlWebResponseObject to Get-Info -Text.
Expand All @@ -417,6 +508,9 @@ function Get-KbUpdate {
$lastmodified = Get-Info -Text $detaildialog -Pattern '<span id="ScopedViewHandler_date">'
$size = Get-Info -Text $detaildialog -Pattern '<span id="ScopedViewHandler_size">'
$classification = Get-Info -Text $detaildialog -Pattern '<span id="ScopedViewHandler_labelClassification_Separator" class="labelTitle">'
if (-not $arch) {
$arch = Get-Info -Text $detaildialog -Pattern '<span id="ScopedViewHandler_labelArchitecture_Separator" class="labelTitle">'
}
$supportedproducts = Get-Info -Text $detaildialog -Pattern '<span id="ScopedViewHandler_labelSupportedProducts_Separator" class="labelTitle">'
$msrcnumber = Get-Info -Text $detaildialog -Pattern '<span id="ScopedViewHandler_labelSecurityBulliten_Separator" class="labelTitle">'
$msrcseverity = Get-Info -Text $detaildialog -Pattern '<span id="ScopedViewHandler_msrcSeverity">'
Expand Down Expand Up @@ -444,6 +538,22 @@ function Get-KbUpdate {
$links = $downloaddialog | Select-String -AllMatches -Pattern "(http[s]?\://.*download\.windowsupdate\.com\/[^\'\""]*)" | Select-Object -Unique

foreach ($link in $links) {
if ($arch -eq "n/a") {
$arch = $null
}
if ($link -match "x64" -or $link -match "AMD64") {
$arch = "x64"
}
if ($link -match "x86") {
$arch = "x86"
}
if ($link -match "ARM64") {
$arch = "ARM64"
}
if ($link -match "ARM-based") {
$arch = "ARM32"
}

if ($kbnumbers -eq "n/a") {
$kbnumbers = $null
}
Expand Down Expand Up @@ -487,7 +597,7 @@ function Get-KbUpdate {
Title = $title
Id = $kbnumbers
Architecture = $arch
Language = $longlang
Language = $Language
Hotfix = $ishotfix
Description = $description
LastModified = $lastmodified
Expand Down
29 changes: 11 additions & 18 deletions tests/Integration.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ Describe "Integration Tests" -Tag "IntegrationTests" {
)
}

It -Skip "properly supports languages" {
It "properly supports languages" {
$results = Get-KbUpdate -Pattern KB968930 -Language Japanese -Architecture x86 -Simple
$results.Count -eq 4
$results.Count -eq 5
$results.Link | Select-Object -Last 1 | Should -Match jpn

$results = Get-KbUpdate -Pattern "KB2764916 Nederlands" -Simple
Expand Down Expand Up @@ -107,17 +107,11 @@ Describe "Integration Tests" -Tag "IntegrationTests" {
$results.Count | Should -Be 3
}

# Language-specific installs no longer appear to be supported
It -Skip "does not overwrite links" {
$results = Get-KbUpdate -Pattern "sql 2016 sp1" -Latest -Language Japanese -Source Web
$results.Link.Count | Should -Be 3
$results.Link.Count | Should -Be 6
"$($results.Link)" -match "jpn_"
"$($results.Link)" -notmatch "kor_"

$results = Get-KbUpdate -Pattern "sql 2016 sp1" -Latest -Source Web
$results.Link.Count | Should -BeGreaterThan 3
"$($results.Link)" -match "jpn_"
"$($results.Link)" -match "kor_"
}

It "Calls with specific language" {
Expand All @@ -126,20 +120,17 @@ Describe "Integration Tests" -Tag "IntegrationTests" {
$results.Link -match '-jpn_'
}
# microsoft's CDN appears to be having massive issues and sometimes this does not appear
It -Skip "x64 should work when AMD64 is used (#52)" {
It "x64 should work when AMD64 is used (#52)" {
$results = Get-KbUpdate 2864dff9-d197-48b8-82e3-f36ad242928d -Architecture x64 -Source Web
$results.Architecture | Should -Be "IA64_AMD64_X86_ARM_ARM64"
$results.Architecture | Should -Be "AMD64"
}


# microsoft's CDN appears to be having massive issues and sometimes this does not appear
# Langauges no longer appear to be supported
It -Skip "should find langauge in langauge (#50)" {
# Langauges are now supported via headers
It "should find langauge in langauge (#50)" {
$results = Get-KbUpdate 40B42C1B-086F-4E4A-B020-000ABCDC89C7 -Source Web -Language Slovenian -WarningAction SilentlyContinue
$results.Language | Should -match "Slovenian"

$results = Get-KbUpdate 40B42C1B-086F-4E4A-B020-000ABCDC89C7 -Source Web -Language Afrikaans -WarningAction SilentlyContinue
$results | Should -Be $null
}

# CDN is too flakey right now
Expand All @@ -150,8 +141,10 @@ Describe "Integration Tests" -Tag "IntegrationTests" {
$db.Id | Should -Be $web.Id
$db.Title | Should -Be $web.Title
$db.Description | Should -Be $web.Description
#$db.Architecture | Should -Be $web.Architecture
#$db.Language | Should -Be $web.Language
$db.Architecture | Should -Be $web.Architecture
if ($db.Language) {
$db.Language | Should -Be $web.Language
}
$db.Classification | Should -Be $web.Classification
$db.SupportedProducts | Should -Be $web.SupportedProducts
$db.MSRCNumber | Should -Be $web.MSRCNumber
Expand Down

0 comments on commit 80301c6

Please sign in to comment.