From b7291cb9bea9db601137fe935ae25c09e7c9c159 Mon Sep 17 00:00:00 2001 From: yi_Xu Date: Sat, 11 Jun 2022 10:17:15 +0800 Subject: [PATCH] fix: use respnse header for encoding --- bin/describe.ps1 | 3 ++- lib/autoupdate.ps1 | 12 ++++++++---- lib/description.ps1 | 3 ++- lib/manifest.ps1 | 6 ++++-- libexec/scoop-virustotal.ps1 | 3 ++- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/bin/describe.ps1 b/bin/describe.ps1 index e92ab9d669..ae573ba484 100644 --- a/bin/describe.ps1 +++ b/bin/describe.ps1 @@ -44,7 +44,8 @@ $Queue | ForEach-Object { try { $wc = New-Object Net.Webclient $wc.Headers.Add('User-Agent', (Get-UserAgent)) - $home_html = (Get-Encoding($wc)).GetString($wc.DownloadData($manifest.homepage)) + $homepage = $wc.DownloadData($manifest.homepage) + $home_html = (Get-Encoding($wc)).GetString($homepage) } catch { Write-Host "`n$($_.Exception.Message)" -ForegroundColor Red return diff --git a/lib/autoupdate.ps1 b/lib/autoupdate.ps1 index f7f715fbba..7cf4f62053 100644 --- a/lib/autoupdate.ps1 +++ b/lib/autoupdate.ps1 @@ -6,7 +6,8 @@ function find_hash_in_rdf([String] $url, [String] $basename) { $wc = New-Object Net.Webclient $wc.Headers.Add('Referer', (strip_filename $url)) $wc.Headers.Add('User-Agent', (Get-UserAgent)) - [xml]$xml = (Get-Encoding($wc)).GetString($wc.DownloadData($url)) + $data = $wc.DownloadData($url) + [xml]$xml = (Get-Encoding($wc)).GetString($data) } catch [system.net.webexception] { write-host -f darkred $_ write-host -f darkred "URL $url is not valid" @@ -35,7 +36,8 @@ function find_hash_in_textfile([String] $url, [Hashtable] $substitutions, [Strin $wc = New-Object Net.Webclient $wc.Headers.Add('Referer', (strip_filename $url)) $wc.Headers.Add('User-Agent', (Get-UserAgent)) - $hashfile = (Get-Encoding($wc)).GetString($wc.DownloadData($url)) + $data = $wc.DownloadData($url) + $hashfile = (Get-Encoding($wc)).GetString($data) } catch [system.net.webexception] { write-host -f darkred $_ write-host -f darkred "URL $url is not valid" @@ -88,7 +90,8 @@ function find_hash_in_json([String] $url, [Hashtable] $substitutions, [String] $ $wc = New-Object Net.Webclient $wc.Headers.Add('Referer', (strip_filename $url)) $wc.Headers.Add('User-Agent', (Get-UserAgent)) - $json = (Get-Encoding($wc)).GetString($wc.DownloadData($url)) + $data = $wc.DownloadData($url) + $json = (Get-Encoding($wc)).GetString($data) } catch [system.net.webexception] { write-host -f darkred $_ write-host -f darkred "URL $url is not valid" @@ -108,7 +111,8 @@ function find_hash_in_xml([String] $url, [Hashtable] $substitutions, [String] $x $wc = New-Object Net.Webclient $wc.Headers.Add('Referer', (strip_filename $url)) $wc.Headers.Add('User-Agent', (Get-UserAgent)) - $xml = [xml]((Get-Encoding($wc)).GetString($wc.DownloadData($url))) + $data = $wc.DownloadData($url) + $xml = [xml]((Get-Encoding($wc)).GetString($data)) } catch [system.net.webexception] { write-host -f darkred $_ write-host -f darkred "URL $url is not valid" diff --git a/lib/description.ps1 b/lib/description.ps1 index 6f1d51bda4..ef1da13589 100644 --- a/lib/description.ps1 +++ b/lib/description.ps1 @@ -18,7 +18,8 @@ function find_description($url, $html, $redir = $false) { if($refresh -and !$redir) { $wc = New-Object Net.Webclient $wc.Headers.Add('User-Agent', (Get-UserAgent)) - $html = (Get-Encoding($wc)).GetString($wc.DownloadData($refresh)) + $data = $wc.DownloadData($refresh) + $html = (Get-Encoding($wc)).GetString($data) return find_description $refresh $html $true } diff --git a/lib/manifest.ps1 b/lib/manifest.ps1 index d16f02da5e..27087a4c3a 100644 --- a/lib/manifest.ps1 +++ b/lib/manifest.ps1 @@ -12,7 +12,8 @@ function url_manifest($url) { try { $wc = New-Object Net.Webclient $wc.Headers.Add('User-Agent', (Get-UserAgent)) - $str = (Get-Encoding($wc)).GetString($wc.DownloadData($url)) + $data = $wc.DownloadData($url) + $str = (Get-Encoding($wc)).GetString($data) } catch [system.management.automation.methodinvocationexception] { warn "error: $($_.exception.innerexception.message)" } catch { @@ -66,7 +67,8 @@ function save_installed_manifest($app, $bucket, $dir, $url) { if ($url) { $wc = New-Object Net.Webclient $wc.Headers.Add('User-Agent', (Get-UserAgent)) - (Get-Encoding($wc)).GetString($wc.DownloadData($url)) | Out-UTF8File "$dir\manifest.json" + $data = $wc.DownloadData($url) + (Get-Encoding($wc)).GetString($data) | Out-UTF8File "$dir\manifest.json" } else { Copy-Item (manifest_path $app $bucket) "$dir\manifest.json" } diff --git a/libexec/scoop-virustotal.ps1 b/libexec/scoop-virustotal.ps1 index e092dbde0d..cd2aa328f1 100644 --- a/libexec/scoop-virustotal.ps1 +++ b/libexec/scoop-virustotal.ps1 @@ -85,7 +85,8 @@ Function Get-VirusTotalResult($hash, $app) { $url = "https://www.virustotal.com/ui/files/$hash" $wc = New-Object Net.Webclient $wc.Headers.Add('User-Agent', (Get-UserAgent)) - $result = (Get-Encoding($wc)).GetString($wc.DownloadData($url)) + $data = $wc.DownloadData($url) + $result = (Get-Encoding($wc)).GetString($data) $stats = json_path $result '$.data.attributes.last_analysis_stats' $malicious = json_path $stats '$.malicious' $suspicious = json_path $stats '$.suspicious'