Has it changed in Win10?
Code: Select all
C:\Users\User\Code\NestBat>certutil -hashfile NestBat.bat
SHA1 hash of NestBat.bat:
fc5650b221ed08b5403cb2cfb308caea79c33d8a
CertUtil: -hashfile command completed successfully.
Moderator: DosItHelp
Code: Select all
C:\Users\User\Code\NestBat>certutil -hashfile NestBat.bat
SHA1 hash of NestBat.bat:
fc5650b221ed08b5403cb2cfb308caea79c33d8a
CertUtil: -hashfile command completed successfully.
C:\Users\User\Code\NestBat>..\hashsum /c hashsum <nestbat.bat
---------- "hashsum" ----------
OK: batling.bat
OK: NestBat.bat
========== SUMMARY ==========
Total manifests = 1
Matched files = 2
Interesting - yes. I have confirmed on my Win 10 machine that CERTUTIL behavior has changed. It now outputs a continuous stream of hex digits without spaces.
I don't have an option to check just one file within a manifest. But you can manually check a single file with the /C option, as implied by the documentation:
Code: Select all
/C - Read hash values and file names from File (the manifest), and verify
that local files match. File may include path information with /C.
If File is not given, then read hash and file names from standard
input. Each line of input must have a hash, followed by two spaces,
or a space and an asterisk, followed by a file name.
Code: Select all
echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx *file.ext | hashsum /c
Code: Select all
find "*file.ext" <manifest.md5 | hashsum /c
findstr /l "*file.ext" manifest.md5 | hashsum /c
Not via HASHSUM.BAT, but you can certainly edit the manifest with your favorite text editor.
Ask the developers of md5sum. I'm simply emulating the behavior of the existing unix tool(s). Two spaces is supposed to indicate text mode, and space asterisk is supposed to indicate binary mode. But as described in the HASHSUM.BAT documentation, HASHSUM always uses binary mode.
Yep, that's the magic one!
Happy for you to tidy up these two lines that do most of it:
Code: Select all
find /v /i "NestBat.bat" Manifest.MD5 | find /v /i "----------" | findstr /v "^$"> Manifest.tmp
hashsum /T /A MD5 "NestBat.bat" | find "NestBat.bat" >> Manifest.tmp
Code: Select all
:: UpdateManifest
call ..\hashsum /T /A MD5 ???????.bat >Manifest.MD5
Type Manifest.MD5
find /v /i "NestBat.bat" Manifest.MD5 | find /v /i "----------" | findstr /v "^$"> Manifest.tmp
Type Manifest.tmp
call ..\hashsum /T /A MD5 "NestBat.bat" | find "NestBat.bat" >> Manifest.tmp
Type Mainfest.tmp
Del Manifest.MD5
Ren Manifest.tmp *.MD5
Type Manifest.MD5
Code: Select all
C:\Users\User\Code\NestBat>..\hashsum /T /A MD5 ???????.bat >Manifest.MD5
C:\Users\User\Code\NestBat>Type Manifest.MD5
7b2cb4aa6c6d6a2023eae1dee98ec025 batling.bat
c19c099a7703768ef1b8dbeec3c45dba NestBat.bat
C:\Users\User\Code\NestBat>find /v /i "NestBat.bat" Manifest.MD5 | find /v /i "----------" | findstr /v "^$"> Manifest.tmp
C:\Users\User\Code\NestBat>Type Manifest.tmp
7b2cb4aa6c6d6a2023eae1dee98ec025 batling.bat
C:\Users\User\Code\NestBat>..\hashsum /T /A MD5 "NestBat.bat" | find "NestBat.bat" >> Manifest.tmp
C:\Users\User\Code\NestBat>Del Manifest.MD5
C:\Users\User\Code\NestBat>Ren Manifest.tmp *.MD5
C:\Users\User\Code\NestBat>Type Manifest.MD5
7b2cb4aa6c6d6a2023eae1dee98ec025 batling.bat
c19c099a7703768ef1b8dbeec3c45dba NestBat.bat
Microsoft can't be consistent from fciv to CertUtil so you might as well. So option case is critical?
Code: Select all
hashsum /nh /ns /f file.ext /c manifest.md5
Sorry, I was imprecise with my language. My intent is for HASHSUM.BAT to be able to work with digests produced by md5sum etc., as well as be able to create digests that are compatible with md5sum. I'm not worried about exactly replicating the option syntax or functionality. For example, HASHSUM is better able to process directory trees than md5sum.
I strongly recommend preserving the asterisk (ditch the /T option), as HASHSUM always uses binary mode, and the asterisk implies binary.flywire wrote: ↑17 Feb 2018 18:22Happy for you to tidy up these two lines that do most of it:My demo UpdateManifest.bat failed:Code: Select all
find /v /i "NestBat.bat" Manifest.MD5 | find /v /i "----------" | findstr /v "^$"> Manifest.tmp hashsum /T /A MD5 "NestBat.bat" | find "NestBat.bat" >> Manifest.tmp
Code: Select all
:: UpdateManifest call ..\hashsum /T /A MD5 ???????.bat >Manifest.MD5 Type Manifest.MD5 find /v /i "NestBat.bat" Manifest.MD5 | find /v /i "----------" | findstr /v "^$"> Manifest.tmp Type Manifest.tmp call ..\hashsum /T /A MD5 "NestBat.bat" | find "NestBat.bat" >> Manifest.tmp Type Mainfest.tmp Del Manifest.MD5 Ren Manifest.tmp *.MD5 Type Manifest.MD5
Code: Select all
>Manifest.MD5.new (findstr /ivc:"NestBat.bat" Manifest.MD5 & ..\hashsum /t /a md5 "NestBat.bat")
move /y Manifest.MD5.new Manifest.MD5 >nul
Code: Select all
/H - Prints the HASHSUM.BAT history.
/F FileName
When using /C, only check lines within the manifest that contain the
string FileName. The search ignores case.
/FR FileRegEx
When using /C, only check lines within the manifest that match the
FINDSTR regular expression FileRegEx. The search ignores case.
/NH - (No Headers) Suppresses listing of manifest name(s) when using /C.
Code: Select all
hashsum /nh /ns /f "*test.bat" /c manifest.md5
Code: Select all
hashsum /nh /ns /f ".bat" /c manifest.md5
Code: Select all
hashsum /nh /ns /fr "\*t.*\.bat" /c manifest.md5
Code: Select all
call ..\hashsum /T /A MD5 ???????.bat >Manifest.MD5
I don't understand why I can't process all lines in the batch file.
Say this example:
Code: Select all
C:\Users\User\Code\NestBat>type ..\updatemanifest.bat
:: UpdateManifest
echo Position 1
>Manifest.MD5.new (findstr /ivc:"NestBat.bat" Manifest.MD5 & ..\hashsum /t /a md5 "NestBat.bat")
move /y Manifest.MD5.new Manifest.MD5
echo Position 2
Code: Select all
C:\Users\User\Code\NestBat>..\updatemanifest
C:\Users\User\Code\NestBat>echo Position 1
Position 1
C:\Users\User\Code\NestBat>(findstr /ivc:"NestBat.bat" Manifest.MD5 & ..\hashsum /t /a md5 "NestBat.bat" ) 1>Manifest.MD5.new
C:\Users\User\Code\NestBat>
More than 256 chars in the file content causes an errorbajabaq2000 wrote: ↑28 Jun 2019 13:10Not sure if this could be considered a bug report (or if you can do anything about it), but if you have a file with more than 256 characters hashsum.bat throws an ERROR (which is correct), but it be "more" correct / helpful if it would say "why" this error occured