Right-click Hashes and Pythons ASCII command-line

By Thursday, December 11, 2014 0 , Permalink 1

This post is a guest post by Gil Dollberg

A while ago I wrote a Python script that calculates MD5 and SHA1 hashes on a file with a right click. Here’s the script that calculates the MD5 and the script that writes the .reg file. What you probably want to download is just the reg file – double click, install, and you’re set. Note the pythonw.exe caveat below though…

Quick right-click hashes for a file on Windows, with some Python and Windows registry fu

The non-ASCII pitfall

Out of the box, Python on Windows doesn’t deal well with non-ASCII command-line arguments. Windows will convert accented characters to their unaccented counterparts and non-latin characters to ?s, and that doesn’t go well with trying to open paths with such characters in them. Turns out part of the reason is that Python 2.x’s default environment encoding is ASCII, because bad things happen otherwise. Fortunately, we can use the lovely GetCommandLineW function to get the real command line.

Python on Windows doesn’t deal well with non-ASCII command-line arguments…

Yay for StackOverflow (and ActiveState), there’s good code that does just that. The code in the answer is adapted from ActiveState’s website, and the code there is licensed under the PSF License, so consider all the above scripts licensed under the same license as well.

Don’t miss this essay on unicode & character sets, from Joel Spolsky.

pythonw path caveat

Currently, the scripts assume Python 2.7 installed in C:\Python27, and looks for pythonw.exe there.

If your environment is different, you’ll need to modify the path in make_reg.py.

Doing something with the hashes

Once the message box pops up, you can Ctrl+c it to get the contained text. This will allow you to do something with the resulting hash, if you need to.

No Comments Yet.

Leave a Reply