-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hashTest: New module for getting/checking hashes
... in the file explorer
- Loading branch information
Showing
3 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
[ | ||
{ | ||
"author": "eric", | ||
"date": "2022 6 9", | ||
"description": "Get and compare sha256 hashes from seleceted files in Explorer.", | ||
"display_name": "", | ||
"tags": [ | ||
"file", | ||
"code", | ||
"wip" | ||
], | ||
"typ": "nfo", | ||
"url": "", | ||
"version": "0.1" | ||
}, | ||
{ | ||
"disablable": true, | ||
"enabled": true, | ||
"functionCode": "hashTest()", | ||
"functionMode": 0, | ||
"key": [ | ||
"Alt+Shift+H" | ||
], | ||
"keyChange": true, | ||
"label": "Make a hash check with selected file", | ||
"multiple": true, | ||
"name": "hashTest_Hotkey", | ||
"scope": [ | ||
"ahk_class CabinetWClass" | ||
], | ||
"scopeChange": true, | ||
"scopeMode": 1, | ||
"typ": "hotkey" | ||
}, | ||
{ | ||
"file": "hashTest.ahk", | ||
"typ": "include" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
; hashTest - hashTest.ahk | ||
; author: eric | ||
; created: 2022 6 9 | ||
|
||
hashTest() { | ||
selection := explorer_get_selected() | ||
if (selection.Length() != 1) { | ||
msgbox_error("Select 1 File!", "hashTest") | ||
return | ||
} | ||
|
||
; get hash value from python hash getter script: | ||
output := string_strip(StrUpper(python_get_output(path_neighbor(A_LineFile, "hashtest.py"), selection[1]))) | ||
; check against clipboard | ||
clip_val := string_strip(StrUpper(Clipboard)) | ||
if (StrLen(output) != StrLen(clip_val)) { | ||
Clipboard := output | ||
msg := "From the selected file """ path_basename(selection[1]) """`n" | ||
msg .= "I got this sha256 hash and put it to the clipboard:`n`n " output | ||
msgbox_info(msg, "hashTest - got hash") | ||
Return | ||
} | ||
if (output == clip_val) { | ||
msg := "Hash values Match! From the selected file """ path_basename(selection[1]) """ I got this hash and it matches with the one in the clipboard:`n" output | ||
msgbox_info(msg, "hashTest - It's A Match!") | ||
} | ||
else { | ||
msg := "The clipboard contains a string of matching length!`n" | ||
msg .= "But it does NOT match the hash I got from the selected file """ path_basename(selection[1]) """`n" | ||
msg .= output " != " clip_val | ||
msgbox_error(msg, "hashTest - Mismatch!") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import sys | ||
import hashlib | ||
|
||
|
||
def main(): | ||
try: | ||
file_path = sys.argv[1] | ||
except IndexError as error: | ||
raise RuntimeError('I need a file path to get the hash from!') from error | ||
try: | ||
hasher_name = sys.argv[2] | ||
except IndexError: | ||
hasher_name = 'sha256' | ||
|
||
try: | ||
hasher = getattr(hashlib, hasher_name.lower()) | ||
except AttributeError: | ||
raise RuntimeError('Could not get hash algorithm "%s"! Available are:\n %s' % ', '.join(hashlib.algorithms_available)) | ||
|
||
binary = True | ||
block_size = 2**16 | ||
mode = 'rb' if binary else 'r' | ||
|
||
with open(file_path, mode) as file_object: | ||
buffer_object = file_object.read(block_size) | ||
hasherobj = hasher() | ||
len_buf = len(buffer_object) | ||
while len_buf > 0: | ||
if binary: | ||
hasherobj.update(buffer_object) | ||
else: | ||
hasherobj.update(buffer_object.encode('utf8')) | ||
buffer_object = file_object.read(block_size) | ||
len_buf = len(buffer_object) | ||
print(hasherobj.hexdigest()) | ||
|
||
|
||
if __name__ == '__main__': | ||
# sys.argv.append(r'C:\Users\eric\Downloads\AutoHotkey_1.1.34.03_setup(1).exe') | ||
main() |