waypoit debuguing
This commit is contained in:
+124
-86
@@ -4,6 +4,7 @@ param(
|
|||||||
[Parameter(Position = 0, ParameterSetName = 'Generate', ValueFromPipeline = $true)]
|
[Parameter(Position = 0, ParameterSetName = 'Generate', ValueFromPipeline = $true)]
|
||||||
[Parameter(Position = 0, ParameterSetName = 'Match', ValueFromPipeline = $true)]
|
[Parameter(Position = 0, ParameterSetName = 'Match', ValueFromPipeline = $true)]
|
||||||
[Parameter(Position = 0, ParameterSetName = 'PrincessPi', ValueFromPipeline = $false)]
|
[Parameter(Position = 0, ParameterSetName = 'PrincessPi', ValueFromPipeline = $false)]
|
||||||
|
[Alias('i', 'input', 'if', 'InputFile')]
|
||||||
[string[]]$FilePath,
|
[string[]]$FilePath,
|
||||||
|
|
||||||
# Custom output file (-f / -OutFile / -of)
|
# Custom output file (-f / -OutFile / -of)
|
||||||
@@ -11,9 +12,9 @@ param(
|
|||||||
[Alias('f', 'of')]
|
[Alias('f', 'of')]
|
||||||
[string]$OutFile,
|
[string]$OutFile,
|
||||||
|
|
||||||
# Auto output file switch (-s / -Save)
|
# Auto output file switch (-s / -Save / -o)
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = 'Generate')]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Generate')]
|
||||||
[Alias('s')]
|
[Alias('s', 'o')]
|
||||||
[switch]$Save,
|
[switch]$Save,
|
||||||
|
|
||||||
# File containing checksums to verify (-c / -Check)
|
# File containing checksums to verify (-c / -Check)
|
||||||
@@ -69,10 +70,10 @@ DESCRIPTION
|
|||||||
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, -i, -input, -if, -InputFile <string[]>
|
||||||
Specifies the target file(s) or wildcard pattern (*).
|
Specifies the target file(s) or wildcard pattern (*).
|
||||||
|
|
||||||
-s, -S, -Save
|
-s, -S, -Save, -o, -O <switch>
|
||||||
Auto-saves checksum results. (Takes no arguments).
|
Auto-saves checksum results. (Takes no arguments).
|
||||||
- If input filename contains a wildcard (*), saves to 'checksums.<algo>'.
|
- If input filename contains a wildcard (*), saves to 'checksums.<algo>'.
|
||||||
- If input filename does NOT contain a wildcard, saves to '<filename>.<algo>'.
|
- If input filename does NOT contain a wildcard, saves to '<filename>.<algo>'.
|
||||||
@@ -120,7 +121,8 @@ EXAMPLES
|
|||||||
5. Compare file directly against an expected hash string:
|
5. Compare file directly against an expected hash string:
|
||||||
.\checksum.ps1 myfile.bin -m 406653a68bd3538975656831f33f031b
|
.\checksum.ps1 myfile.bin -m 406653a68bd3538975656831f33f031b
|
||||||
|
|
||||||
Priness Pi LOVES YOU!~
|
Princess Pi LOVES YOU!~
|
||||||
|
https://linktr.ee/princesspi3
|
||||||
'@
|
'@
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -133,61 +135,64 @@ Priness Pi LOVES YOU!~
|
|||||||
|
|
||||||
function Show-PrincessPiArt {
|
function Show-PrincessPiArt {
|
||||||
$art = @'
|
$art = @'
|
||||||
.. .....
|
|
||||||
....------..
|
=#= -- ##*+++++ *+
|
||||||
..:--------.. .......
|
-#=#- +# -*%%= ##++++++++++# ##*********#
|
||||||
..----------.. ....---..
|
#==#= *** %%++%% -++# #++++++++++++*+ *#***************#
|
||||||
...---------=------::....:----:..
|
#===#= %***+%++#*%%@+++++% #++++++++++++**+++#******++********#
|
||||||
..-----=+**************=-----:...
|
====+#%@*******###%=%++##++% #+++++++++++*++++++++#***====+****++#
|
||||||
.----+****************=-----...
|
=#=*==**#*#########%++#*+++@ *++++++++#+++++++++++#****==+******#
|
||||||
.--=****************=-----=**+:::--:....
|
*#=====%####***%%++++#*+++**% ++++++++*+++++++++++++#************#*******
|
||||||
.-#*********##**++=---====++**+-----:.
|
@****#==%####**#*+++++++#+++#**# #+++++++++++++++++++#####+*****************#
|
||||||
..:==********#=.+@%-==++===++===++*=----...
|
@****#######%**@+*%**#%+++++%##*** #+++++++++++++++++#+++++++#****+======*****+
|
||||||
.:=::******%%+-::=++====+==++====+**=--...
|
#****##%####@**%+*******@@+++@###**% #+++++++++++++*++++++++++****========****#
|
||||||
.+..+*****--@===-:-%--====-=+====+*#=:..
|
****#####%%*%*%+***@@@%%@*+++@####** *+++++++++++++++++++++#****=======****#
|
||||||
.-.-****#=.#+===--=+===----======+*+..
|
%***####%%**+%%*++*@=##@@%@++++%###*** +++++*+++++++++++#+**************#
|
||||||
.::=:+****#@#+=====-**-----*+====++**:.
|
@%%%@@##%%#++++++++==**@@**+++%*###**% +++++++++++#*+++++#*********####
|
||||||
.. .=****=--======-..%-----%+==++***+-..
|
%###%++++++++====**#++++%**##**% @% ++++#+++++++++++++**************#
|
||||||
..=++***+-.----======..*-----#+==+***#%#+..
|
%###%++++++++++++++++++%**%##**%@###@ %++++++++++++++++***=====********
|
||||||
.. .:-..---=====--------=-+==+**-@*. ............::::::....
|
###%%++++++++%++++++*%%%%###***##%##@ +++++++++++++##**************#
|
||||||
..=:..--===+-:-------*%+==*+#%**=. .....:-------------------------:.
|
###%%%%+++++##+++++++#*+%###***%%%##@ ++++++++++++++%********+############%@
|
||||||
..............-:..--===+-..:-------+==+==.:... ...:----------------------------::.
|
@%%*@*%%%%###****+*%%****++%##***%##@@@ #+++++++++++++++*********###*****#########*
|
||||||
......:----------::=:...--==+--:.:-------+==+=:.... ....--------------------------:.....
|
#%%###***#####%**++++##**%#@@#@ ##+++++++++*###%#+***+***##*************#######
|
||||||
..:::----------------=-::.:--===---:.:------=--:.... ...:---------------------------...
|
@#%%####%%####%+++++++##*######%++++++++++++++#*+++++#%###%#######*********######%
|
||||||
..:------------------=--:..:--=+=--------::.:+-..... ...------------------------------..
|
##%########@%@+++@###%*%#####@+++++++++++%**++++++++++%%%%%%########***==**###%##%
|
||||||
...:-----------------:....----==-------:...=%*.......:::--------------------------------:..
|
%#%###%###########@@%#%#@@##++++++++****++++********+++ %########**===*###%*#
|
||||||
...--------------:+......---------------:+%%#.----------------------------:.......-----:..
|
#**##%####@@####%@######%*++++++++++++++++#++**+*#++++# ########******###% %
|
||||||
.:----===-------:-.. .:--------------*%%%%=--------------========------:.......-------:...
|
@#***# ###%@@##%#######@+++++++++++++++++++++%*++**++++# *########******##% @
|
||||||
..-:.:------------....-.=---------=#%%%%##%------------=-----------------------------------..
|
%*******% %##% =@#########++++++++++++++++++#++++*%++*#%#++# ########******##%
|
||||||
.:--:....:--------:##*=:.-------=#%%%%%%#%+-----------=-------------------------------------:
|
#@%@# %% *@#@@###*+++++++++++++++++++%+++##+++###++* ##*#####******##@
|
||||||
..:-----------------::*%%#-------=###%%%%##=--------------------------------------:............
|
**##%*++%++++++++++++++++++++++++++++++++% +#**#####******###
|
||||||
..:-------------------:.-#%%##+==+%%%%%%#%+------------------------...:::--------------::::::..
|
##%#######*@***+#+++++++++++++++#***#++++++++++++ %**#####*******#%
|
||||||
...:----------------------..-#%#%%%%%%%%*+#%=-------------------------=-:....:----------------:...
|
*+++++++****##****++++++++##% #******#+++++++++++ %**#####*******#@
|
||||||
--------------------------:.-#%%%%%%%%+#@%%%--------------------------=++=-::---------------:...
|
#++++++++*******- ++++++++# *******#++++++++++# @**#####*******#
|
||||||
---------------------------...+%%%%%]%%%%#---------------------------------------------:....
|
#@@+++++++******- *+++++++# #******#+++++++++* **####%**==+**@
|
||||||
............------.....----:....-#%%%%%%%*=------------------------------::+=---------.......
|
@@@@@+++ %+++++++# ******# %+++++++ %*###%***===**@ %=
|
||||||
..:-... ....-----.. ....-=-------------------------------------.=*+=.......
|
@@@@@@@@@ #+++++++# =****** #++++++% *###%#***=+**% %**
|
||||||
..---:....:-----:.......:--------------------------:-------------==+=-......
|
@@@@@@@@@@ ++++++++# ******# #++++++# *##@%********% @*@
|
||||||
.:-------------..........:---------------------------..:-------------==..........
|
@@+@@@++@@+ ++++++++# #******# #++++++# @## #*********@ #***#
|
||||||
..-------------:... ...--------:...----------------....:-----------==-...........
|
@@+@@++@@@++ @@@++++++* @@@%**** #@@++++% +## %#****************%
|
||||||
..:----==------:..-.... ..--------:...:---------------.....:----------=+-.....
|
@*@**@+++# @@@@+++++ @@@@@@**# @@@@+++# @# %#****************
|
||||||
..------==+=++==-..+--:. .:--------.....-----------=*%=.. ..----------=+=......
|
+#+++++# @@@@@@+++% @@@@@@@@# @@@@@@@++ @ %##************%
|
||||||
....------------........:... ..:--------.....-------+#%%#@%.. ...----------=+=......
|
#+++** @@@@@@@@@@ @@@@@@@@@ @@@@@@@@@ %###********%*
|
||||||
..---------===:............... .:----=+*#=. ..--+#**+%@@@#%+. ..:-:..=----=*=*=:.....
|
@@@@@@@@@@+ @@@@@@@@@@ =@@@@@@@@@ %%#####%%
|
||||||
:............:=::+=:--:=.=-.::=... ..*@*-+%@@@:.....-@@#%@*#@@@#%:.. ..-:..---:-#**+-.........
|
*@@@@@@@@@@ @+*@@@@@@@= @@++@@@@@@
|
||||||
.. ...::::....::-.:.::-.. ..*%:..*@@@*.. ..-%#%@@+%@@@@=.. ...::.=#=..-%*++=:... ...
|
@++@@@@@@@@ #**@**@@@@@ *@@*#@@@@@@ -=
|
||||||
...... .......... ..**...*#=*%:. .--*#@%+#%@@@@+... ..*%@%+...+%+=*+=-...
|
@%#@@@@@@@@ *#***@@@@@@ @+#+@++#@@@
|
||||||
..*#:.-#+..+-. .--*#**%%*%@@%=.. ..-%@@*:..+@%=:+**+=:..
|
#+++@++@@@@@ **********# #+++++@+@@@@
|
||||||
..*@#*%%=..==. .-*%@#%@##@@@#-. ...#@@%*-=%@@#:..-=++=-
|
##+#+++@@@@@@ ##****#### *+#+##+++@@%%
|
||||||
.:#@*-:++..==. .=#%@%*@@*%*=+*:....:.+@*::+%@@@%=......-*
|
#+++++++++++# #++++++++++#
|
||||||
.-%+...=%##%-. .+@*@%*%@##*-:*+..:-==*@=..:#@+:=*:.......
|
#########*
|
||||||
.:*#:..:*@@@%:. .--%@*%@#*%*#=..-%-....:+#=-.:#%-.:+-.......
|
|
||||||
.+@#=.-*@@@@*.. ....-%@@@@@@=..+%*.. .--%--=+#%-.:*-. ....
|
____ ____ ____ _ _ ___ ____ ___ ___ ____ ____
|
||||||
.-=++++++++=... .:***+++==::::... .-%#=-*#%#**#-.
|
( _ \( _ \(_ _)( \( )/ __)( ___)/ __)/ __) ( _ \(_ _)/\/
|
||||||
|
)___/ ) / _)(_ ) (( (__ )__) \__ \\__ \ )___/ _)(_
|
||||||
|
(__) (_)\_)(____)(_)\_)\___)(____)(___/(___/ (__) (____)
|
||||||
|
|
||||||
Princess Pi
|
Princess Pi
|
||||||
https://linktr.ee/princesspi3
|
https://linktr.ee/princesspi3
|
||||||
'@
|
'@
|
||||||
Write-Host $art -ForegroundColor Magenta;
|
Write-Host $art -ForegroundColor Blue;
|
||||||
};
|
};
|
||||||
|
|
||||||
function Get-AlgorithmFromHashLength {
|
function Get-AlgorithmFromHashLength {
|
||||||
@@ -315,7 +320,7 @@ process {
|
|||||||
|
|
||||||
$expectedHash = $Match.Trim().ToLower();
|
$expectedHash = $Match.Trim().ToLower();
|
||||||
$totalFiles = $allItems.Count;
|
$totalFiles = $allItems.Count;
|
||||||
$currentIndex = 0;
|
$currentIndex = [ref]0;
|
||||||
|
|
||||||
$results = $allItems | ForEach-Object -Parallel {
|
$results = $allItems | ForEach-Object -Parallel {
|
||||||
$item = $_
|
$item = $_
|
||||||
@@ -334,8 +339,8 @@ process {
|
|||||||
} -ThrottleLimit 16;
|
} -ThrottleLimit 16;
|
||||||
|
|
||||||
foreach ($res in $results) {
|
foreach ($res in $results) {
|
||||||
$currentIndex++;
|
$currentIndex.Value++;
|
||||||
Write-Progress -Activity "Matching Checksums ($Algorithm)" -Status "Processing file $currentIndex of $totalFiles" -PercentComplete (($currentIndex / $totalFiles) * 100);
|
Write-Progress -Activity "Matching Checksums ($Algorithm)" -Status "Processing file $($currentIndex.Value) of $totalFiles" -PercentComplete (($currentIndex.Value / $totalFiles) * 100);
|
||||||
|
|
||||||
if ($res.IsMatch) {
|
if ($res.IsMatch) {
|
||||||
Write-Host "$($res.TargetFile): " -NoNewline;
|
Write-Host "$($res.TargetFile): " -NoNewline;
|
||||||
@@ -385,6 +390,8 @@ process {
|
|||||||
if ([string]::IsNullOrWhiteSpace($fileAlgo)) { $fileAlgo = 'SHA256'; };
|
if ([string]::IsNullOrWhiteSpace($fileAlgo)) { $fileAlgo = 'SHA256'; };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# Parse verification items
|
||||||
|
$verifyItems = @();
|
||||||
foreach ($line in ($lines)) {
|
foreach ($line in ($lines)) {
|
||||||
if ([string]::IsNullOrWhiteSpace($line) -or $line.StartsWith("#")) { continue; };
|
if ([string]::IsNullOrWhiteSpace($line) -or $line.StartsWith("#")) { continue; };
|
||||||
|
|
||||||
@@ -402,32 +409,63 @@ process {
|
|||||||
|
|
||||||
if ($expectedHash -and $targetFile) {
|
if ($expectedHash -and $targetFile) {
|
||||||
$targetFullPath = Join-Path -Path ($baseDir) -ChildPath ($targetFile);
|
$targetFullPath = Join-Path -Path ($baseDir) -ChildPath ($targetFile);
|
||||||
|
$verifyItems += [PSCustomObject]@{
|
||||||
if (Test-Path -Path ($targetFullPath) -PathType 'Leaf') {
|
ExpectedHash = $expectedHash
|
||||||
$actualHash = (Get-FileHash -Path ($targetFullPath) -Algorithm ($fileAlgo)).Hash.ToLower();
|
TargetFile = $targetFile
|
||||||
|
TargetFullPath = $targetFullPath
|
||||||
$displayPath = Resolve-Path -Path ($targetFullPath) -Relative -ErrorAction 'SilentlyContinue';
|
BaseDir = $baseDir
|
||||||
if (-not $displayPath) { $displayPath = $targetFile; };
|
|
||||||
if ($displayPath.StartsWith(".\") -or $displayPath.StartsWith("./")) { $displayPath = $displayPath.Substring(2); };
|
|
||||||
|
|
||||||
if ($actualHash -eq $expectedHash) {
|
|
||||||
Write-Host "${displayPath}: " -NoNewline;
|
|
||||||
Write-Host "OK" -ForegroundColor Green;
|
|
||||||
} else {
|
|
||||||
Write-Host "${displayPath}: " -NoNewline;
|
|
||||||
Write-Host "FAILED" -ForegroundColor Red;
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
$displayPath = $targetFile;
|
|
||||||
if ($baseDir -ne (Get-Location).Path) {
|
|
||||||
$displayPath = Join-Path -Path (Resolve-Path -Path ($baseDir) -Relative -ErrorAction 'SilentlyContinue') -ChildPath ($targetFile);
|
|
||||||
if ($displayPath.StartsWith(".\") -or $displayPath.StartsWith("./")) { $displayPath = $displayPath.Substring(2); };
|
|
||||||
};
|
|
||||||
Write-Host "${displayPath}: " -NoNewline;
|
|
||||||
Write-Host "FAILED open or read" -ForegroundColor Red;
|
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
$totalFiles = $verifyItems.Count;
|
||||||
|
$currentIndex = [ref]0;
|
||||||
|
|
||||||
|
# Run verification items in parallel
|
||||||
|
$verifyResults = $verifyItems | ForEach-Object -Parallel {
|
||||||
|
$item = $_
|
||||||
|
$algo = $using:fileAlgo
|
||||||
|
|
||||||
|
if (Test-Path -Path ($item.TargetFullPath) -PathType 'Leaf') {
|
||||||
|
$actualHash = (Get-FileHash -Path ($item.TargetFullPath) -Algorithm ($algo)).Hash.ToLower();
|
||||||
|
|
||||||
|
$displayPath = Resolve-Path -Path ($item.TargetFullPath) -Relative -ErrorAction 'SilentlyContinue';
|
||||||
|
if (-not $displayPath) { $displayPath = $item.TargetFile; };
|
||||||
|
if ($displayPath.StartsWith(".\") -or $displayPath.StartsWith("./")) { $displayPath = $displayPath.Substring(2); };
|
||||||
|
|
||||||
|
[PSCustomObject]@{
|
||||||
|
DisplayPath = $displayPath
|
||||||
|
Status = if ($actualHash -eq $item.ExpectedHash) { "OK" } else { "FAILED" }
|
||||||
|
IsError = $false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$displayPath = $item.TargetFile;
|
||||||
|
if ($item.BaseDir -ne (Get-Location).Path) {
|
||||||
|
$displayPath = Join-Path -Path (Resolve-Path -Path ($item.BaseDir) -Relative -ErrorAction 'SilentlyContinue') -ChildPath ($item.TargetFile);
|
||||||
|
if ($displayPath.StartsWith(".\") -or $displayPath.StartsWith("./")) { $displayPath = $displayPath.Substring(2); };
|
||||||
|
};
|
||||||
|
[PSCustomObject]@{
|
||||||
|
DisplayPath = $displayPath
|
||||||
|
Status = "FAILED open or read"
|
||||||
|
IsError = $true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} -ThrottleLimit 16;
|
||||||
|
|
||||||
|
foreach ($res in $verifyResults) {
|
||||||
|
$currentIndex.Value++;
|
||||||
|
Write-Progress -Activity "Verifying Checksums ($fileAlgo)" -Status "Processing file $($currentIndex.Value) of $totalFiles" -PercentComplete (($currentIndex.Value / $totalFiles) * 100);
|
||||||
|
|
||||||
|
Write-Host "$($res.DisplayPath): " -NoNewline;
|
||||||
|
if ($res.IsError) {
|
||||||
|
Write-Host "$($res.Status)" -ForegroundColor Red;
|
||||||
|
} elseif ($res.Status -eq "OK") {
|
||||||
|
Write-Host "OK" -ForegroundColor Green;
|
||||||
|
} else {
|
||||||
|
Write-Host "FAILED" -ForegroundColor Red;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Write-Progress -Activity "Verifying Checksums ($fileAlgo)" -Completed;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
# --- GENERATION MODE ---
|
# --- GENERATION MODE ---
|
||||||
|
|||||||
Reference in New Issue
Block a user