Skip to content

Commit

Permalink
fixed big file URL
Browse files Browse the repository at this point in the history
fixed big file URL
  • Loading branch information
HotCakeX committed Oct 13, 2024
1 parent 3e0673f commit b1298bc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
38 changes: 24 additions & 14 deletions .github/Workflowstuff/VirusTotal.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ function Upload-FileToVirusTotal {
[System.String]$ApiKey
)


# Headers for the VirusTotal API request
[System.Collections.Hashtable]$Headers = @{}
$Headers.Add('accept', 'application/json')
Expand All @@ -14,31 +13,43 @@ function Upload-FileToVirusTotal {

# Prepare the file for upload
[System.Collections.Hashtable]$Form = @{
file = Get-Item $FilePath
file = Get-Item -Path $FilePath
}

# Check if file size is greater than 20MB (20 * 1024 * 1024 bytes)
if ($FileItem.Length -gt (20 * 1024 * 1024)) {
Write-Host 'File is larger than 20MB. Using big file upload URL.' -ForegroundColor Cyan
$UploadUrl = 'https://www.virustotal.com/api/v3/files/upload_url'

# https://docs.virustotal.com/reference/files-upload-url

[System.Collections.Hashtable]$BigFileUploadHeaders = @{}
$BigFileUploadHeaders.Add('accept', 'application/json')
$BigFileUploadHeaders.Add('x-apikey', $ApiKey)
$BigFileUploadResponse = Invoke-WebRequest -Uri 'https://www.virustotal.com/api/v3/files/upload_url' -Method GET -Headers $BigFileUploadHeaders

$BigFileUploadResponseJSON = $BigFileUploadResponse.Content | ConvertFrom-Json
[System.String]$UploadUrl = $BigFileUploadResponseJSON.data
}
else {
$UploadUrl = 'https://www.virustotal.com/api/v3/files'
[System.String]$UploadUrl = 'https://www.virustotal.com/api/v3/files'
}

# Upload the file to VirusTotal
try {

Write-Host "Uploading file to VirusTotal: $FilePath" -ForegroundColor Yellow
$Response = Invoke-WebRequest -Uri $UploadUrl -Method Post -Headers $Headers -Form $Form
$Json = $Response.Content | ConvertFrom-Json

# Return the analysis ID and URL
return [PSCustomObject]@{
ID = $Json.data.id
ID = $Json.data.id
URL = $Json.data.links.self
}
Write-Host 'Upload completed.' -ForegroundColor Yellow
}
catch {
Write-Host "Error uploading file: $_"
Write-Host "Error uploading file: $_" -ForegroundColor Red
exit 1
}
}
Expand All @@ -64,13 +75,13 @@ function Get-VirusTotalReport {
$JsonResponse = $Response.Content | ConvertFrom-Json

if ($JsonResponse.data.attributes.status -eq 'queued') {
Write-Host "Waiting 10 more seconds. Status: $($JsonResponse.data.attributes.status)"
Write-Host "Waiting 10 more seconds. Status: $($JsonResponse.data.attributes.status)" -ForegroundColor Blue
Start-Sleep 10
}
}
until ($JsonResponse.data.attributes.status -eq 'completed')

Write-Host "Status is now: $($JsonResponse.data.attributes.status)"
Write-Host "Status is now: $($JsonResponse.data.attributes.status)" -ForegroundColor Blue

# Display detailed report
Write-Host -Object "Results URL: https://www.virustotal.com/gui/file/$($JsonResponse.meta.file_info.sha256)" -ForegroundColor Magenta
Expand All @@ -89,21 +100,20 @@ function Get-VirusTotalReport {
# $JsonResponse.data.attributes.status | Format-List *
# $JsonResponse.data.attributes.results | Format-List *
# $JsonResponse.data.attributes.results.Microsoft | Format-List *

}

# VirusTotal API Key
$VTApi = $env:VTAPIsecret

# Submit the ZIP of the repository to VirusTotal
$repoZip = '.\repository.zip'
$RepoZip = '.\repository.zip'

Get-VirusTotalReport -FilePath $repoZip -ApiKey $VTApi
Get-VirusTotalReport -FilePath $RepoZip -ApiKey $VTApi

# Submit each release file in the release_assets folder
$releaseFiles = Get-ChildItem -Path './release_assets' -File
$ReleaseFiles = Get-ChildItem -Path './release_assets' -File

foreach ($file in $releaseFiles) {
foreach ($file in $ReleaseFiles) {
# Submit each file to VirusTotal
Get-VirusTotalReport -FilePath $file.FullName -ApiKey $VTApi
Get-VirusTotalReport -FilePath $file.FullName -ApiKey $VTApi
}
8 changes: 4 additions & 4 deletions .github/workflows/VirusTotal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
steps:
# Step to check out the repository
- uses: actions/checkout@v4

# Step to create ZIP of the repository
- name: Create Repository Zip
shell: pwsh
Expand All @@ -25,16 +25,16 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # GitHub API access token
run: |
New-Item -Path './release_assets' -ItemType Directory # Create folder for release assets
# Get latest release information from GitHub API
$release = Invoke-RestMethod -Uri "https://api.github.com/repos/${{ github.repository }}/releases/latest" -Headers @{Authorization = "token $env:GITHUB_TOKEN"} -UseBasicParsing
# Download assets if they exist
if ($release.assets.Count -gt 0) {
foreach ($asset in $release.assets) {
$assetUrl = $asset.browser_download_url
$assetName = $asset.name
# Download each asset into the release_assets folder
Invoke-WebRequest -Uri $assetUrl -OutFile "./release_assets/$assetName"
Write-Host "Downloaded: $assetName"
Expand Down

0 comments on commit b1298bc

Please sign in to comment.