Skip to content

Feature/thor seed improvements#9

Open
Neo23x0 wants to merge 19 commits intomasterfrom
feature/thor-seed-improvements
Open

Feature/thor seed improvements#9
Neo23x0 wants to merge 19 commits intomasterfrom
feature/thor-seed-improvements

Conversation

@Neo23x0
Copy link
Contributor

@Neo23x0 Neo23x0 commented Feb 5, 2026

DRAFT

@Neo23x0 Neo23x0 requested a review from Copilot February 5, 2026 13:02
@Neo23x0 Neo23x0 self-assigned this Feb 5, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the THOR Seed script by renaming the -UseThorCloud parameter to -UseCloud for consistency, improving error handling, and adding validation and retry logic. The changes enhance the script's reliability and user experience.

Changes:

  • Renamed parameter from -UseThorCloud to -UseCloud throughout the codebase
  • Added validation for CustomUrl parameter and improved error handling with retry logic for downloads
  • Enhanced OS detection with fallback mechanisms and improved logging throughout the script

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
thor-seed/thor-seed.ps1 Renamed parameter, added URL validation, improved error handling with retries, enhanced OS detection fallback, added SSL callback restoration, improved logging and summary output
thor-seed/README.md Updated documentation to reflect parameter rename and corrected spelling errors, added unblocking instructions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

[Alias('CU')]
[string]$CustomUrl,

[Parameter(HelpMessage = 'Add a random sleep delay to the scan start to avoid all scripts starting at the exact same second')]
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ValidateRange attribute replaces ValidateNotNullOrEmpty for RandomDelay. However, ValidateRange already prevents null values for value types like [int], making the previous validation redundant. Consider documenting the 0-3600 range (0-60 minutes) in the parameter's HelpMessage to clarify the acceptable values for users.

Suggested change
[Parameter(HelpMessage = 'Add a random sleep delay to the scan start to avoid all scripts starting at the exact same second')]
[Parameter(HelpMessage = 'Add a random sleep delay in seconds (0-3600, i.e. 0-60 minutes) to the scan start to avoid all scripts starting at the exact same second')]

Copilot uses AI. Check for mistakes.
# THOR still running --------------------------------------------------
# ---------------------------------------------------------------------
$ThorProcess = Get-Process -Name "thor64" -ErrorAction SilentlyContinue
$ThorProcess = Get-Process -Name "thor64", "thor" -ErrorAction SilentlyContinue | Select-Object -First 1
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The improved process detection now checks for both 'thor64' and 'thor' processes. Consider whether the order matters (thor64 before thor) if both processes exist simultaneously, as Select-Object -First 1 will only return the first match found.

Suggested change
$ThorProcess = Get-Process -Name "thor64", "thor" -ErrorAction SilentlyContinue | Select-Object -First 1
$ThorProcess = Get-Process -Name "thor64" -ErrorAction SilentlyContinue | Select-Object -First 1
if (-not $ThorProcess)
{
$ThorProcess = Get-Process -Name "thor" -ErrorAction SilentlyContinue | Select-Object -First 1
}

Copilot uses AI. Check for mistakes.
throw "Downloaded package too small ($FileSize bytes) - likely corrupted or error response"
}
# Verify ZIP header (PK signature = 0x504B)
$ZipHeader = [System.IO.File]::ReadAllBytes($TempPackage)[0..1]
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReadAllBytes loads the entire file into memory before extracting the first 2 bytes. For potentially large ZIP files, this is inefficient. Consider using a FileStream to read only the first 2 bytes: $stream = [System.IO.File]::OpenRead($TempPackage); $ZipHeader = New-Object byte[] 2; $stream.Read($ZipHeader, 0, 2); $stream.Close()

Suggested change
$ZipHeader = [System.IO.File]::ReadAllBytes($TempPackage)[0..1]
$ZipHeader = New-Object byte[] 2
$stream = [System.IO.File]::OpenRead($TempPackage)
$null = $stream.Read($ZipHeader, 0, 2)
$stream.Close()

Copilot uses AI. Check for mistakes.
Copy link

@Codehardt Codehardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes regarding UseThorCloud and the newComment parameter look good. Unfortunately, I can't comment on the rest as I don't speak Powershell.

Implements robust failure detection and analysis throughout the THOR download and execution workflow. Introduces exit code tracking, failure reason capture, and automated diagnosis of scan termination causes including crashes, resource safeguards, and external interruptions.

Adds CPU limit control and resource safeguard override options to provide flexibility in managing system impact during scans. Includes preflight checks for administrator privileges and output path writability to catch configuration issues early.

Enhances user guidance with contextual error messages and actionable recommendations based on detected failure patterns. Improves cleanup logic to preserve artifacts when troubleshooting is needed.

Strengthens Analysis Cockpit upload workflow with better error handling for missing logs and failed uploads. Adds parameter validation guards against common user mistakes like typos in command-line flags.

Expands documentation with comprehensive usage examples covering ASGARD, cloud, and custom deployment scenarios.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants