Free & Portable Checksum Tools [file hashing utilities]

Share interesting information or links related to portable apps here.
Message
Author
User avatar
webfork
Posts: 9261
Joined: Wed Apr 11, 2007 8:06 pm
Location: US, Texas
Contact:

Re: hashdeep/md5deep (CLI hashing utilities)

#16 Post by webfork » Fri Jan 17, 2020 7:50 pm

Midas wrote:
Mon Jan 13, 2020 6:39 am
... it just dawned on me that the cause of your problem might in fact be just the default Powershell settings -- counter-intuitively, prior to running any scripts on an untouched Powershell, it's mandatory to change Set-ExecutionPolicy.
That does correspond to some conversations I've had on the topic. The tool I was using got cut off by an admin setting, but I have a different laptop with very different security settings (and a more developer-friendly culture) so I'll see where that stands with this an other powershell tools.

Thanks!

vevy
Posts: 266
Joined: Tue Sep 10, 2019 11:17 am

Re: Free & Portable Checksum Tools [file hashing utilities]

#17 Post by vevy » Sat May 09, 2020 5:05 pm

Midas wrote:
Tue Oct 29, 2019 12:00 pm
[Mod note: post moved here from hashdeep topic, where it was somehwhat off-topic.]

A further hashing script I patched together that doesn't require an updated Powershell...

Code: Select all

:: Sidecar MD5 hashing script v0.2 by Midas (2019-10-29)
:: Creates Teracopy v2.x compatible sidecar MD5 hash files
:: WARNING! Won't work if filename contains "&" or other special characters

@ECHO OFF
certutil -v -hashfile %1 MD5 | find /v "MD5" | find /v "CertUtil" > tmp_hash
SET /P hash=<tmp_hash
SET hash=%hash: =%
ECHO:%hash% *%~nx1> "%~n1".md5
DEL tmp_hash
You can simplify the certutil line by filtering out lines with ":":

Code: Select all

certutil -v -hashfile %1 MD5|find /v ":"
You can also do away with temp files:

Code: Select all

set fp="%~1%"
set fn=%~nx1%
for /f %%i in ('certutil -hashfile %fp% sha256 ^|find /v ^":^"') do echo %%i *%fn%>%fn%.sha256
I do NOT have other accounts.

User avatar
Midas
Posts: 5343
Joined: Mon Dec 07, 2009 7:09 am
Location: Sol3

Re: Free & Portable Checksum Tools [file hashing utilities]

#18 Post by Midas » Sun May 10, 2020 12:59 pm

vevy wrote:You can simplify the certutil line by filtering out lines with ":":

Code: Select all

certutil -v -hashfile %1 MD5|find /v ":"

That is a great tip, thank you. :sunglasses:

As for the temp file in my original batch script (posted at viewtopic.php?p=94544#p94544), it's by design: call it an instance of Occam's razor. Contrary to your tip above, you'd be making the code more, not less, convoluted, by replacing this:

Code: Select all

CERTUTIL -v -hashfile %1 MD5 | FIND /v ":" > tmp_hash
SET /P hash=<tmp_hash

with this:

Code: Select all

for /f %%i in ('CERTUTIL -hashfile %fp% MD5 ^|find /v ^":^"') do echo %%i *%fn%>%fn%.MD5

I like code to be easily human readable. I know all about FOR loops, but I find them highly error-prone, with rather less than intuitive syntax and overall not really newbie-friendly.

Now, if you can recommend any other way of transferring command output to a local variable, I'm all ears.

vevy
Posts: 266
Joined: Tue Sep 10, 2019 11:17 am

Re: Free & Portable Checksum Tools [file hashing utilities]

#19 Post by vevy » Sun May 10, 2020 1:05 pm

Midas wrote:
Sun May 10, 2020 12:59 pm
but I find them highly error-prone
:?:
I do NOT have other accounts.

User avatar
Midas
Posts: 5343
Joined: Mon Dec 07, 2009 7:09 am
Location: Sol3

Re: Free & Portable Checksum Tools [file hashing utilities]

#20 Post by Midas » Sun May 10, 2020 1:13 pm

Scripts are supposed to be used and adapted by human beings, not merely copy and pasted. Just look at this piece of the FOR command manpage...
Syntax
FOR /F ["options"] %%parameter IN ('command_to_process') DO command

Key
options:
delims=xxx The delimiter character(s)
(default = a space or TAB)
skip=n A number of lines to skip at the beginning.
(default = 0)

eol=; Character at the start of each line to indicate a comment
The default is a semicolon ;

tokens=n The numbered items to read from each line
(default = 1)

usebackq Use the alternate quoting style:
- Use double quotes for long file names in "filenameset".
- Use single quotes for 'Text string to process'
- Use back quotes for `command_to_process`

[...]

vevy
Posts: 266
Joined: Tue Sep 10, 2019 11:17 am

Re: Free & Portable Checksum Tools [file hashing utilities]

#21 Post by vevy » Sun May 10, 2020 1:21 pm

You mean it can trip up the user, not act up? If so, I kind of agree it is not the most intuitive! :)
Last edited by vevy on Sun May 10, 2020 2:09 pm, edited 2 times in total.
I do NOT have other accounts.

User avatar
Midas
Posts: 5343
Joined: Mon Dec 07, 2009 7:09 am
Location: Sol3

Re: Free & Portable Checksum Tools [file hashing utilities]

#22 Post by Midas » Sun May 10, 2020 1:32 pm

Precisely. :slightly_smiling_face:

vevy
Posts: 266
Joined: Tue Sep 10, 2019 11:17 am

Re: Free & Portable Checksum Tools [file hashing utilities]

#23 Post by vevy » Sun May 10, 2020 2:09 pm

Midas wrote:
Sun May 10, 2020 12:59 pm
Now, if you can recommend any other way of transferring command output to a local variable, I'm all ears.
Without using for, forfiles, or a third party tool (like sfk), no!

Other than commenting the commands, you can spread it out:

Code: Select all

set filepath="%~1%"
set filename=%~nx1%

        for /f %%i in ('
certutil -hashfile %filepath% sha256    ^|^
find /v ":"
        ') do ^
echo %%i *%filename%> %filename%.sha256
Each relevant command cleanly in a separate line.
I do NOT have other accounts.

User avatar
Midas
Posts: 5343
Joined: Mon Dec 07, 2009 7:09 am
Location: Sol3

Re: Free & Portable Checksum Tools [file hashing utilities]

#24 Post by Midas » Mon May 11, 2020 1:36 am

You're right but I think I'll leave that to user discretion. :neutral_face:

A miss in any of those hard to see diacritic chains and all you've got is a jumble of barely readable non-working code to debug.

My preferred version is much terser and if, however, you have to debug it, way simpler... it's KISS. :stuck_out_tongue_winking_eye:

vevy
Posts: 266
Joined: Tue Sep 10, 2019 11:17 am

Re: Free & Portable Checksum Tools [file hashing utilities]

#25 Post by vevy » Mon May 11, 2020 6:10 am

Midas wrote:
Mon May 11, 2020 1:36 am
You're right but I think I'll leave that to user discretion. :neutral_face:

A miss in any of those hard to see diacritic chains and all you've got is a jumble of barely readable non-working code to debug.

My preferred version is much terser and, if however you have to debug it, way simpler... it's KISS. :stuck_out_tongue_winking_eye:
Yeah, it is... well... error-prone :wink:.
It's just a preference of mine, that's all.
I do NOT have other accounts.

Post Reply