FrancoDM Posted October 9, 2020 Share Posted October 9, 2020 It would be useful to have a file checksum, as we have a pixel one. Link to comment Share on other sites More sharing options...
Musashi Posted October 9, 2020 Share Posted October 9, 2020 You may want to have a look at the following : crc32-md4-md5-sha1-for-files "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 9, 2020 Moderators Share Posted October 9, 2020 FrancoDM, Or look at the _Crypt_HashFile function, which seems to be exactly what you require. Perhaps in future you might like to look through the Help file before you post. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Musashi Posted October 9, 2020 Share Posted October 9, 2020 (edited) 1 hour ago, Melba23 said: Or look at the _Crypt_HashFile function ... You are right, I should have mentioned this variant too. @FrancoDM : Some time ago I created a small comparison program (only for myself), but it should help you as well . expandcollapse popup#include <Crypt.au3> #include <WinAPI.au3> Opt("MustDeclareVars", 1) Global $sFile = @SystemDir & '\mspaint.exe' ; <== example Global $hTimer, $iTimer, $sData ConsoleWrite('----------------------------------------------------------- ' & @CRLF) ; CRC32 von trancexx : $hTimer = TimerInit() $sData = _CRC32ForFile($sFile) $iTimer = TimerDiff($hTimer) ConsoleWrite(' CRC32 - trancexx : ' & $sData & @CRLF) ConsoleWrite(' >>> Time = ' & $iTimer & " ms" & @CRLF) ConsoleWrite('----------------------------------------------------------- ' & @CRLF) ; MD5 von trancexx : $hTimer = TimerInit() $sData = _MD5ForFile($sFile) $iTimer = TimerDiff($hTimer) ConsoleWrite(' MD5 - trancexx : ' & Hex($sData) & @CRLF) ConsoleWrite(' >>> Time = ' & $iTimer & " ms" & @CRLF) ConsoleWrite('----------------------------------------------------------- ' & @CRLF) ; MD5 mit Standard AutoIt Crypt.au3 : _Crypt_Startup() $hTimer = TimerInit() $sData = _Crypt_HashFile($sFile, $CALG_MD5) $iTimer = TimerDiff($hTimer) ConsoleWrite(' MD5 - _Crypt.au3 : ' & Hex($sData) & @CRLF) ConsoleWrite(' >>> Time = ' & $iTimer & " ms" & @CRLF) ConsoleWrite('----------------------------------------------------------- ' & @CRLF) _Crypt_Shutdown() ;------------------------------------------------------------------------ ; #FUNCTION# ;=============================================================================== ; Name...........: _CRC32ForFile ; Description ...: Calculates CRC32 value for the specific file. ; Syntax.........: _CRC32ForFile ($sFile) ; Parameters ....: $sFile - Full path to the file to process. ; Return values .: Success - Returns CRC32 value in form of hex string ; - Sets @error to 0 ; Failure - Returns empty string and sets @error: ; |1 - CreateFile function or call to it failed. ; |2 - CreateFileMapping function or call to it failed. ; |3 - MapViewOfFile function or call to it failed. ; |4 - RtlComputeCrc32 function or call to it failed. ; Author ........: trancexx ;========================================================================================== Func _CRC32ForFile($sFile) Local $a_hCall = DllCall("kernel32.dll", "hwnd", "CreateFileW", _ "wstr", $sFile, _ "dword", 0x80000000, _ ; GENERIC_READ "dword", 3, _ ; FILE_SHARE_READ|FILE_SHARE_WRITE "ptr", 0, _ "dword", 3, _ ; OPEN_EXISTING "dword", 0, _ ; SECURITY_ANONYMOUS "ptr", 0) If @error Or $a_hCall[0] = -1 Then Return SetError(1, 0, "") EndIf Local $hFile = $a_hCall[0] $a_hCall = DllCall("kernel32.dll", "ptr", "CreateFileMappingW", _ "hwnd", $hFile, _ "dword", 0, _ ; default security descriptor "dword", 2, _ ; PAGE_READONLY "dword", 0, _ "dword", 0, _ "ptr", 0) If @error Or Not $a_hCall[0] Then DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFile) Return SetError(2, 0, "") EndIf DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFile) Local $hFileMappingObject = $a_hCall[0] $a_hCall = DllCall("kernel32.dll", "ptr", "MapViewOfFile", _ "hwnd", $hFileMappingObject, _ "dword", 4, _ ; FILE_MAP_READ "dword", 0, _ "dword", 0, _ "dword", 0) If @error Or Not $a_hCall[0] Then DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFileMappingObject) Return SetError(3, 0, "") EndIf Local $pFile = $a_hCall[0] Local $iBufferSize = FileGetSize($sFile) Local $a_iCall = DllCall("ntdll.dll", "dword", "RtlComputeCrc32", _ "dword", 0, _ "ptr", $pFile, _ "int", $iBufferSize) If @error Or Not $a_iCall[0] Then DllCall("kernel32.dll", "int", "UnmapViewOfFile", "ptr", $pFile) DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFileMappingObject) Return SetError(4, 0, "") EndIf DllCall("kernel32.dll", "int", "UnmapViewOfFile", "ptr", $pFile) DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFileMappingObject) Local $iCRC32 = $a_iCall[0] Return SetError(0, 0, Hex($iCRC32)) EndFunc ;==>_CRC32ForFile ; #FUNCTION# ;=============================================================================== ; Name...........: _MD5ForFile ; Description ...: Calculates MD5 value for the specific file. ; Syntax.........: _MD5ForFile ($sFile) ; Parameters ....: $sFile - Full path to the file to process. ; Return values .: Success - Returns MD5 value in form of binary data ; - Sets @error to 0 ; Failure - Returns empty string and sets @error: ; |1 - CreateFile function or call to it failed. ; |2 - MD5Init function or call to it failed. ; |4 - ReadFile function or call to it failed. ; |5 - MD5Update function or call to it failed. ; |6 - MD5Final function or call to it failed. ; Author ........: trancexx ;========================================================================================== Func _MD5ForFile($sFile) Local $a_hCall = DllCall("kernel32.dll", "hwnd", "CreateFileW", _ "wstr", $sFile, _ "dword", 0x80000000, _ ; GENERIC_READ "dword", 1, _ ; FILE_SHARE_READ "ptr", 0, _ "dword", 3, _ ; OPEN_EXISTING "dword", 0, _ ; SECURITY_ANONYMOUS "ptr", 0) If @error Or $a_hCall[0] = -1 Then Return SetError(1, 0, "") EndIf Local $hFile = $a_hCall[0] Local $tMD5_CTX = DllStructCreate("dword i[2];" & _ "dword buf[4];" & _ "ubyte in[64];" & _ "ubyte digest[16]") DllCall("advapi32.dll", "none", "MD5Init", "ptr", DllStructGetPtr($tMD5_CTX)) If @error Then _WinAPI_CloseHandle($hFile) Return SetError(2, 0, "") EndIf Local $tBuffer = DllStructCreate("byte[524288]") Local $pBuffer = DllStructGetPtr($tBuffer), $iSize Local $iReadErr = True While _WinAPI_ReadFile($hFile, $pBuffer, 524288, $iSize) And $iSize $iReadErr = False DllCall("advapi32.dll", "none", "MD5Update", _ "ptr", DllStructGetPtr($tMD5_CTX), _ "ptr", $pBuffer, _ "dword", $iSize) If @error Then _WinAPI_CloseHandle($hFile) Return SetError(5, 0, "") EndIf WEnd If $iReadErr Then _WinAPI_CloseHandle($hFile) Return SetError(4, 0, "") EndIf DllCall("advapi32.dll", "none", "MD5Final", "ptr", DllStructGetPtr($tMD5_CTX)) If @error Then _WinAPI_CloseHandle($hFile) Return SetError(6, 0, "") EndIf _WinAPI_CloseHandle($hFile) Local $sMD5 = DllStructGetData($tMD5_CTX, "digest") Return SetError(0, 0, $sMD5) EndFunc ;==>_MD5ForFile _Crypt_HashFile is probably the easiest to implement. Edited October 9, 2020 by Musashi sparuj and FrancoDM 2 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
sparuj Posted October 15, 2020 Share Posted October 15, 2020 I would like to say thank you! I was looking for a script like that. Link to comment Share on other sites More sharing options...
Musashi Posted October 15, 2020 Share Posted October 15, 2020 37 minutes ago, sparuj said: I would like to say thank you! I was looking for a script like that. Welcome to our Forum . sparuj 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now