waypoit debuguing

This commit is contained in:
2026-09-25 15:56:47 -06:00
parent e5435d124e
commit 4377cc6a45
+16 -21
View File
@@ -5,33 +5,33 @@ param(
[Parameter(Position = 0, ParameterSetName = 'Match', ValueFromPipeline = $true)]
[string[]]$FilePath,
# Output file (-o / --outfile / -OutFile)
# Output file (-o / -OutFile)
[Parameter(Mandatory = $false, ParameterSetName = 'Generate')]
[Alias('o')]
[string]$OutFile,
# File containing checksums to verify (-c / --check)
# File containing checksums to verify (-c / -Check)
[Parameter(Mandatory = $false, ParameterSetName = 'Verify')]
[Alias('c')]
[string]$Check,
# Direct checksum hash string to match against (-m / --match)
# Direct checksum hash string to match against (-m / -Match)
[Parameter(Mandatory = $true, ParameterSetName = 'Match')]
[Alias('m')]
[string]$Match,
# Hashing algorithm to use (Defaults to SHA256)
[Parameter(Mandatory = $false)]
[Alias('a', 'algo', 'algorithm')]
[Alias('a', 'algo')]
[ValidateSet('SHA1', 'SHA256', 'SHA384', 'SHA512', 'MD5')]
[string]$Algorithm,
# Recursive flag (-r / --recursive)
# Recursive flag (-r / -Recursive)
[Parameter(Mandatory = $false)]
[Alias('r')]
[switch]$Recursive,
# Help flag (-h / --help)
# Help flag (-h / -Help)
[Parameter(Mandatory = $false)]
[Alias('h')]
[switch]$Help
@@ -52,35 +52,34 @@ SYNOPSIS
DESCRIPTION
Computes or verifies checksums using cryptographic hash algorithms (SHA256, SHA512, SHA1, MD5, SHA384).
Outputs hash values in standard GNU coreutils format (<hash> <filename>).
Supports both single-dash (-o, -c, -r) and double-dash (--outfile, --check, --recursive) GNU-style flags.
Ignores checksum metadata files (.md5, .sha1, .sha256, .sha384, .sha512) during wildcards unless passed explicitly.
PARAMETERS
-FilePath <string[]>
Specifies the target file(s) or wildcard pattern (*).
-o, --outfile, -OutFile <string>
-o, -OutFile <string>
Enables auto-saving checksum results to file(s).
- If passed with an argument (e.g. -o custom.txt), writes to 'custom.txt'.
- If passed with NO argument (or empty string ""), automatically outputs to 'checksums.<algo>'.
When combined with -r and *, recursively auto-generates checksum files per directory.
-c, --check, -Check <string>
-c, -Check <string>
Reads hashes from a specified checksum file and verifies target files on disk.
If -r is specified, recursively looks for and validates checksum files by name across subdirectories.
-m, --match, -Match <string>
-m, -Match <string>
Compares the computed hash of target file(s) directly against a given hash string.
-a, --algo, --algorithm, -Algorithm <string>
-a, -algo, -Algorithm <string>
Specifies the hash algorithm to use.
Supported options: SHA1, SHA256 (default), SHA384, SHA512, MD5.
In -c or -m mode, auto-detects algorithm from hash length if omitted.
-r, --recursive, -Recursive <switch>
-r, -Recursive <switch>
Processes target files or verification files recursively across directory structures.
-h, --help, -Help <switch>
-h, -Help <switch>
Displays this help documentation.
EXAMPLES
@@ -89,17 +88,16 @@ EXAMPLES
2. Compute SHA512 checksums recursively and auto-save (prompts for filename, hit Enter for auto):
.\checksum.ps1 * -r -o -a SHA512
.\checksum.ps1 * --recursive --outfile "" --algo SHA512
.\checksum.ps1 * -Recursive -OutFile "" -Algorithm SHA512
3. Compute SHA256 checksums and save to custom file:
.\checksum.ps1 * -o my_hashes.txt
4. Verify checksums against a verification file:
.\checksum.ps1 -c checksums.sha256
.\checksum.ps1 --check checksums.sha256
5. Compare file directly against an expected hash string:
.\checksum.ps1 myfile.bin --match 406653a68bd3538975656831f33f031b
.\checksum.ps1 myfile.bin -m 406653a68bd3538975656831f33f031b
'@
};
@@ -189,7 +187,7 @@ process {
};
};
# --- DIRECT MATCH MODE (-m / --match) ---
# --- DIRECT MATCH MODE (-m / -Match) ---
if ($PSCmdlet.ParameterSetName -eq 'Match') {
if ([string]::IsNullOrWhiteSpace($Algorithm)) {
$Algorithm = Get-AlgorithmFromHashLength -HashString ($Match);
@@ -213,7 +211,7 @@ process {
};
};
}
# --- VERIFICATION MODE (-c / --check) ---
# --- VERIFICATION MODE (-c / -Check) ---
elseif ($PSCmdlet.ParameterSetName -eq 'Verify') {
$checkFiles = @();
if ($Recursive) {
@@ -257,12 +255,10 @@ process {
$expectedHash =$null;
$targetFile =$null;
# Standard GNU checksum format: <hash> <space/asterisk> <filename>
if ($line -match '^([a-fA-F0-9]+)\s+[* ]?(.*)$') {
$expectedHash =$Matches[1].ToLower();
$targetFile =$Matches[2].Trim().TrimStart('*');
}
# Fallback for unspaced files: <hash><filename>
elseif ($line -match '^([a-fA-F0-9]{128}\vert{}[a-fA-F0-9]{96}\vert{}[a-fA-F0-9]{64}\vert{}[a-fA-F0-9]{40}\vert{}[a-fA-F0-9]{32})[* ]?(.*)$') {
$expectedHash =$Matches[1].ToLower();
$targetFile =$Matches[2].Trim().TrimStart('*');
@@ -300,7 +296,6 @@ process {
if ([string]::IsNullOrWhiteSpace($Algorithm)) {$Algorithm = 'SHA256';
};
# Detect if the parameter was used AT ALL, even if they hit Enter at the prompt (resulting in empty string)
$wantOutFile =$PSBoundParameters.ContainsKey('OutFile');
$isAutoFile = [string]::IsNullOrWhiteSpace($OutFile);