waypoit debuguing
This commit is contained in:
@@ -5,33 +5,33 @@ param(
|
|||||||
[Parameter(Position = 0, ParameterSetName = 'Match', ValueFromPipeline = $true)]
|
[Parameter(Position = 0, ParameterSetName = 'Match', ValueFromPipeline = $true)]
|
||||||
[string[]]$FilePath,
|
[string[]]$FilePath,
|
||||||
|
|
||||||
# Output file (-o / --outfile / -OutFile)
|
# Output file (-o / -OutFile)
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = 'Generate')]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Generate')]
|
||||||
[Alias('o')]
|
[Alias('o')]
|
||||||
[string]$OutFile,
|
[string]$OutFile,
|
||||||
|
|
||||||
# File containing checksums to verify (-c / --check)
|
# File containing checksums to verify (-c / -Check)
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = 'Verify')]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Verify')]
|
||||||
[Alias('c')]
|
[Alias('c')]
|
||||||
[string]$Check,
|
[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')]
|
[Parameter(Mandatory = $true, ParameterSetName = 'Match')]
|
||||||
[Alias('m')]
|
[Alias('m')]
|
||||||
[string]$Match,
|
[string]$Match,
|
||||||
|
|
||||||
# Hashing algorithm to use (Defaults to SHA256)
|
# Hashing algorithm to use (Defaults to SHA256)
|
||||||
[Parameter(Mandatory = $false)]
|
[Parameter(Mandatory = $false)]
|
||||||
[Alias('a', 'algo', 'algorithm')]
|
[Alias('a', 'algo')]
|
||||||
[ValidateSet('SHA1', 'SHA256', 'SHA384', 'SHA512', 'MD5')]
|
[ValidateSet('SHA1', 'SHA256', 'SHA384', 'SHA512', 'MD5')]
|
||||||
[string]$Algorithm,
|
[string]$Algorithm,
|
||||||
|
|
||||||
# Recursive flag (-r / --recursive)
|
# Recursive flag (-r / -Recursive)
|
||||||
[Parameter(Mandatory = $false)]
|
[Parameter(Mandatory = $false)]
|
||||||
[Alias('r')]
|
[Alias('r')]
|
||||||
[switch]$Recursive,
|
[switch]$Recursive,
|
||||||
|
|
||||||
# Help flag (-h / --help)
|
# Help flag (-h / -Help)
|
||||||
[Parameter(Mandatory = $false)]
|
[Parameter(Mandatory = $false)]
|
||||||
[Alias('h')]
|
[Alias('h')]
|
||||||
[switch]$Help
|
[switch]$Help
|
||||||
@@ -52,35 +52,34 @@ SYNOPSIS
|
|||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
Computes or verifies checksums using cryptographic hash algorithms (SHA256, SHA512, SHA1, MD5, SHA384).
|
Computes or verifies checksums using cryptographic hash algorithms (SHA256, SHA512, SHA1, MD5, SHA384).
|
||||||
Outputs hash values in standard GNU coreutils format (<hash> <filename>).
|
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.
|
Ignores checksum metadata files (.md5, .sha1, .sha256, .sha384, .sha512) during wildcards unless passed explicitly.
|
||||||
|
|
||||||
PARAMETERS
|
PARAMETERS
|
||||||
-FilePath <string[]>
|
-FilePath <string[]>
|
||||||
Specifies the target file(s) or wildcard pattern (*).
|
Specifies the target file(s) or wildcard pattern (*).
|
||||||
|
|
||||||
-o, --outfile, -OutFile <string>
|
-o, -OutFile <string>
|
||||||
Enables auto-saving checksum results to file(s).
|
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 an argument (e.g. -o custom.txt), writes to 'custom.txt'.
|
||||||
- If passed with NO argument (or empty string ""), automatically outputs to 'checksums.<algo>'.
|
- 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.
|
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.
|
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.
|
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.
|
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.
|
Specifies the hash algorithm to use.
|
||||||
Supported options: SHA1, SHA256 (default), SHA384, SHA512, MD5.
|
Supported options: SHA1, SHA256 (default), SHA384, SHA512, MD5.
|
||||||
In -c or -m mode, auto-detects algorithm from hash length if omitted.
|
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.
|
Processes target files or verification files recursively across directory structures.
|
||||||
|
|
||||||
-h, --help, -Help <switch>
|
-h, -Help <switch>
|
||||||
Displays this help documentation.
|
Displays this help documentation.
|
||||||
|
|
||||||
EXAMPLES
|
EXAMPLES
|
||||||
@@ -89,17 +88,16 @@ EXAMPLES
|
|||||||
|
|
||||||
2. Compute SHA512 checksums recursively and auto-save (prompts for filename, hit Enter for auto):
|
2. Compute SHA512 checksums recursively and auto-save (prompts for filename, hit Enter for auto):
|
||||||
.\checksum.ps1 * -r -o -a SHA512
|
.\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:
|
3. Compute SHA256 checksums and save to custom file:
|
||||||
.\checksum.ps1 * -o my_hashes.txt
|
.\checksum.ps1 * -o my_hashes.txt
|
||||||
|
|
||||||
4. Verify checksums against a verification file:
|
4. Verify checksums against a verification file:
|
||||||
.\checksum.ps1 -c checksums.sha256
|
.\checksum.ps1 -c checksums.sha256
|
||||||
.\checksum.ps1 --check checksums.sha256
|
|
||||||
|
|
||||||
5. Compare file directly against an expected hash string:
|
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 ($PSCmdlet.ParameterSetName -eq 'Match') {
|
||||||
if ([string]::IsNullOrWhiteSpace($Algorithm)) {
|
if ([string]::IsNullOrWhiteSpace($Algorithm)) {
|
||||||
$Algorithm = Get-AlgorithmFromHashLength -HashString ($Match);
|
$Algorithm = Get-AlgorithmFromHashLength -HashString ($Match);
|
||||||
@@ -213,7 +211,7 @@ process {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
# --- VERIFICATION MODE (-c / --check) ---
|
# --- VERIFICATION MODE (-c / -Check) ---
|
||||||
elseif ($PSCmdlet.ParameterSetName -eq 'Verify') {
|
elseif ($PSCmdlet.ParameterSetName -eq 'Verify') {
|
||||||
$checkFiles = @();
|
$checkFiles = @();
|
||||||
if ($Recursive) {
|
if ($Recursive) {
|
||||||
@@ -257,12 +255,10 @@ process {
|
|||||||
$expectedHash =$null;
|
$expectedHash =$null;
|
||||||
$targetFile =$null;
|
$targetFile =$null;
|
||||||
|
|
||||||
# Standard GNU checksum format: <hash> <space/asterisk> <filename>
|
|
||||||
if ($line -match '^([a-fA-F0-9]+)\s+[* ]?(.*)$') {
|
if ($line -match '^([a-fA-F0-9]+)\s+[* ]?(.*)$') {
|
||||||
$expectedHash =$Matches[1].ToLower();
|
$expectedHash =$Matches[1].ToLower();
|
||||||
$targetFile =$Matches[2].Trim().TrimStart('*');
|
$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})[* ]?(.*)$') {
|
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();
|
$expectedHash =$Matches[1].ToLower();
|
||||||
$targetFile =$Matches[2].Trim().TrimStart('*');
|
$targetFile =$Matches[2].Trim().TrimStart('*');
|
||||||
@@ -300,7 +296,6 @@ process {
|
|||||||
if ([string]::IsNullOrWhiteSpace($Algorithm)) {$Algorithm = 'SHA256';
|
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');
|
$wantOutFile =$PSBoundParameters.ContainsKey('OutFile');
|
||||||
$isAutoFile = [string]::IsNullOrWhiteSpace($OutFile);
|
$isAutoFile = [string]::IsNullOrWhiteSpace($OutFile);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user