Skip to content

Commit

Permalink
fix: use respnse header for encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
yi-Xu-0100 committed Jun 11, 2022
1 parent e1a5f5d commit b7291cb
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
3 changes: 2 additions & 1 deletion bin/describe.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions lib/autoupdate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion lib/description.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 4 additions & 2 deletions lib/manifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"
}
Expand Down
3 changes: 2 additions & 1 deletion libexec/scoop-virustotal.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit b7291cb

Please sign in to comment.