/* HashTools 1.0 Beta By Enternal - December 23, 2014 Script Home Thread: http://xyplorer.com/xyfc/viewtopic.php?f=7&t=13052 http://www.xyplorer.com/ Thanks: 40k for "Hash" http://xyplorer.com/xyfc/viewtopic.php?f=7&t=9220 */ "_HTMLCode" Global $HTMLCode = << Hash Checker HTMLCode; "Hash" // ALL Filehero's Code // http://xyplorer.com/xyfc/viewtopic.php?f=7&t=9220 $Files = Get('SelectedItemsPathNames', '|', 'a'); ForEach($Item, $Files) { If Exists($Item) == 2 {Msg "Only Files Can Be Hashed!"; End(2);} } $Report = ''; Global $g_Md5; Global $g_Sha1; Global $g_Sha256; Global $g_Sha512; Global $g_Crc; ForEach($File, $Files) { //$Name = GetPathComponent($File , 'file', ); $Name = $File; $Size = Report('{Size B}', $File, , ); $g_Crc = Hash('crc32', $File, '3'); $g_Md5 = Hash('md5', $File, '3'); $g_Sha1 = Hash('sha1', $File, '3'); $g_Sha256 = Hash('sha256', $File, '3'); $g_Sha512 = Hash('sha512', $File, '3'); $Report = <<<# $Name ---------------------------------------- Size : $Size Bytes CRC32 : $g_Crc MD5 : $g_Md5 SHA1 : $g_Sha1 SHA256: $g_Sha256 SHA512: $g_Sha512 $Report #; } $Report = RegexReplace($Report, "^([ \t]*)\r?\n\s{2}$", ""); // http://stackoverflow.com/questions/12955690/regex-in-notepad-to-remove-blank-lines Text $Report, 700, 800, , "", "w"; "" "Hash Checker (Fast) - Specific File and Hash" Global $HTMLCode; Sub "_HTMLCode"; $Count = Get("CountSelected"); If $Count == 0 {Msg "Nothing Selected!"; End(1);} Elseif $Count > 1 {Msg "Only 1 File Can Be Selected!"; End(1);} $File = Get("curitem"); If Exists($File) == 2 {Msg "Only A File Can Be Hashed!"; End(1);} $Algorithm = InputSelect("Hash Algorithm", "MD5|SHA1|SHA256|SHA512|CRC32", "", "40"); $ExpectedHash = Trim(Input("Enter Expected ".$Algorithm." Hash", $File, )); If $Algorithm == "MD5" {$AlgLen = "32";} ElseIf $Algorithm == "SHA1" {$AlgLen = "40";} ElseIf $Algorithm == "SHA256" {$AlgLen = "64";} ElseIf $Algorithm == "SHA512" {$AlgLen = "128";} ElseIf $Algorithm == "CRC32" {$AlgLen = "8";} $HashCheck = RegexMatches($ExpectedHash,"[a-fA-F0-9]{$AlgLen}"); //RegexMatches("7a869af318d6d34f4ab5834cb25fa634","[^a-fA-F0-9]+"); // Find anything not related to typical hash $HashOrNot = Compare($ExpectedHash, $HashCheck); If $HashOrNot != 0 {Echo "Not A ".$Algorithm." Hash!"; End(1);} $Hash = Hash($Algorithm, , "3"); $Compare = Compare($ExpectedHash, $Hash, "i"); If $Compare == 0 {$Result = "Hashes Match!"; $CSSID = "match"; $ItemMatch = "itemmatch";} Else {$Result = "Hashes Are Different!"; $CSSID = "nomatch"; $ItemMatch = "itemnomatch";} $Content = <<
$File

Expected Hash:
$ExpectedHash
Resultant Hash:
$Hash

$Result
HTML; Html($HTMLCode.$Content,700,800); "Hash Checker (Slow) - Multiple Files and Hashes" // ALL Filehero's Code // http://xyplorer.com/xyfc/viewtopic.php?f=7&t=9220 // Did not include SHA512 due to speed and overkill. // If you want SHA512, simply uncomment and add the // respective code for the report. Global $HTMLCode; Sub "_HTMLCode"; $Content = ""; $Files = Get('SelectedItemsPathNames', '|', 'a'); $Checksums = Input('Hash', 'Paste Text Containing Known Hashes Below:', , 'm', , , ); $Report = ''; Global $g_Crc; Global $g_Md5; Global $g_Sha1; Global $g_Sha256; Global $g_Sha512; ForEach($File, $Files) { $Name = GetPathComponent($File , 'file', ); $Size = Report('{Size B}', $File, , ); $g_Crc = Hash('crc32', $File, '1'); $g_Md5 = Hash('md5', $File, '1'); $g_Sha1 = Hash('sha1', $File, '1'); $g_Sha256 = Hash('sha256', $File, '1'); $g_Sha512 = Hash('sha512', $File, '1'); $matchCRC = RegexMatches($Checksums, $g_Crc, '|', '0') ? "hashmatch" : "hash"; $matchMD5 = RegexMatches($Checksums, $g_Md5, '|', '0') ? "hashmatch" : "hash"; $matchSHA1 = RegexMatches($Checksums, $g_Sha1, '|', '0') ? "hashmatch" : "hash"; $matchSHA256 = RegexMatches($Checksums, $g_Sha256, '|', '0') ? "hashmatch" : "hash"; $matchSHA512 = RegexMatches($Checksums, $g_Sha512, '|', '0') ? "hashmatch" : "hash"; If $matchCRC == "hashmatch" || $matchMD5 == "hashmatch" || $matchSHA1 == "hashmatch" || $matchSHA256 == "hashmatch" || $matchSHA512 == "hashmatch" { $CSSID = "match"; $ItemMatch = "itemmatch"; $Result = "Hashes Match!"; } Else {$CSSID = "nomatch"; $ItemMatch = "itemnomatch"; $Result = "No Hashes Match Up."; } $Content = <<
$File

CRC32   : $g_Crc
MD5     : $g_Md5
SHA-1   : $g_Sha1
SHA-256 : $g_Sha256
SHA-512 : $g_Sha512
$Result


HTML; } $CodeBottom = << HTMLBOTTOM; Html($HTMLCode.$Content.$CodeBottom,700,800); "" "Append Hash To Filename" $AllItems = Get("SelectedItemsPathNames", "|"); $Algorithm = InputSelect("Hash Algorithm", "CRC32|MD5|SHA1|SHA256|SHA512", "", "40"); ForEach($Item, $AllItems, "|") { $Hash = Hash($Algorithm, "$Item", "3"); If Regexmatches($Item, " ") {RenameItem("* [$Hash]", "$Item");} Else {RenameItem("*_[$Hash]", "$Item");} Wait "100"; } "Verify Using Filename Inline Hash" Global $HTMLCode; Sub "_HTMLCode"; $AllItems = Get("SelectedItemsPathNames", "|"); $Content = ""; $HashTypes = "128|64|40|32|8"; ForEach($Item, $AllItems, "|") { ForEach($HashItem, $HashTypes, "|") { $ExpectedHash = RegexMatches("$Item", "(\[|{|\()[a-fA-F0-9]{$HashItem}(\]|}|\))"); If $ExpectedHash != "" {$Algorithm = $HashItem; Break (1);} } $ExpectedHash = Trim($ExpectedHash,"[{()}"); $ExpectedHash = Trim($ExpectedHash,"]"); // According to manual, "]" can only be trimmed as // individual character. If $Algorithm == "128" {$Algorithm = "sha512";} ElseIf $Algorithm == "64" {$Algorithm = "sha256";} ElseIf $Algorithm == "40" {$Algorithm = "sha1";} ElseIf $Algorithm == "32" {$Algorithm = "md5";} ElseIf $Algorithm == "8" {$Algorithm = "crc32";} Else {$Algorithm = "";} If $Algorithm != "" {$Hash = Hash($Algorithm, "$Item", "3");} Else {$Hash = "";} $Compare = Compare($ExpectedHash, $Hash, "i"); If $ExpectedHash == "" {$Result = "No Hash Found In Filename!"; $CSSID = "nomatch"; $ItemMatch = "itemnomatch";} ElseIf $Compare == 0 {$Result = "Hashes Match!"; $CSSID = "match"; $ItemMatch = "itemmatch";} Else {$Result = "Hashes Are Different!"; $CSSID = "nomatch"; $ItemMatch = "itemnomatch";} If Exists($Item) == 2 {$Result = "This Is A Folder!"} $Content = <<
$Item

Expected Hash:
$ExpectedHash
Resultant Hash:
$Hash
$Result


HTML; } $CodeBottom = << HTMLBOTTOM; Html($HTMLCode.$Content.$CodeBottom,700,800);