Adding compatibility with Linux (#118)

This commit is contained in:
p0w3rsh3ll 2023-04-24 20:27:08 +02:00 коммит произвёл GitHub
Родитель f70251eaca
Коммит 1eef88093b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 3 добавлений и 61 удалений

Просмотреть файл

@ -12,7 +12,7 @@
RootModule = 'MsrcSecurityUpdates.psm1'
# Version number of this module.
ModuleVersion = '1.9.8'
ModuleVersion = '1.9.9'
# Supported PSEditions
# CompatiblePSEditions = @()
@ -129,6 +129,7 @@ PrivateData = @{
# ReleaseNotes of this module
ReleaseNotes = @'
April 18, 2023 - Adding compatibility with Linux
April 17, 2023 - Add Exploitability Index Link
April 13, 2023 - Update Exploitability Index Text
Feb 17, 2022 - Update Mitre Urls and fix typo

Просмотреть файл

@ -1,52 +0,0 @@
# ParseJsonString converts from string to PowerShell objects
# (workaround to overcome ConvertFrom-Json limitation on PowerShell 4.0 and earlier)
# Based on code by Florian Feldhaus at 'ConvertFrom-Json max length'
# https://stackoverflow.com/questions/16854057/convertfrom-json-max-length
# With the following changes:
# - ParseJsonString calls ParseItem, not ParseJsonObject (suggested by Dmitry Lobanov)
# - if-else test in ParseJsonObject is replaced by '$parsedItem = ParseItem $item'
# Note: this code is much slower than ConvertFrom-Json
Add-Type -Assembly System.Web.Extensions
# .NET JSON Serializer
$javaScriptSerializer = New-Object System.Web.Script.Serialization.JavaScriptSerializer
$javaScriptSerializer.MaxJsonLength = [System.Int32]::MaxValue
$javaScriptSerializer.RecursionLimit = 99
# Functions necessary to parse JSON output from .NET serializer to PowerShell Objects
function ParseItem($jsonItem) {
if($jsonItem.PSObject.TypeNames -match "Array") {
return ParseJsonArray($jsonItem)
}
elseif($jsonItem.PSObject.TypeNames -match "Dictionary") {
return ParseJsonObject([HashTable]$jsonItem)
}
else {
return $jsonItem
}
}
function ParseJsonObject($jsonObj) {
$result = New-Object -TypeName PSCustomObject
foreach ($key in $jsonObj.Keys) {
$item = $jsonObj[$key]
$parsedItem = ParseItem $item
$result | Add-Member -MemberType NoteProperty -Name $key -Value $parsedItem
}
return $result
}
function ParseJsonArray($jsonArray) {
$result = @()
$jsonArray | ForEach-Object {
$result += , (ParseItem $_)
}
return $result
}
function ParseJsonString($json) {
$config = $javaScriptSerializer.DeserializeObject($json)
return ParseItem($config)
}

Просмотреть файл

@ -91,19 +91,12 @@ Process {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Write-Verbose -Message "Calling $($RestMethod.uri)"
$response = Invoke-RestMethod @RestMethod
Invoke-RestMethod @RestMethod
} catch {
Write-Error -Message "HTTP Get failed with status code $($_.Exception.Response.StatusCode): $($_.Exception.Response.StatusDescription)"
}
# Invoke-RestMethod will return an string on PowerShell 4.0 and earlier
# if the JSON-formatted response is larger than about two million characters
if (-not $AsXml -and $response -is [string]) {
$response = ParseJsonString($response)
}
$response
}
End {}
}