NDog Posted November 21, 2012 Posted November 21, 2012 (edited) I want to point to a folder and generate hash of all contents.I'm familiar with using which works very well with single files... a fallback option I have is to take a zip archive the aforementioned folder and then hash the archive... but I'm hoping to not have to do that.Kind regards Edited November 22, 2012 by NDog
Danyfirex Posted November 21, 2012 Posted November 21, 2012 I think you can use FileFindFirstFile & FileFindFirstFile to walk across your folder and going using MD5 from Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut
NDog Posted November 22, 2012 Author Posted November 22, 2012 Thanks for the suggestion, however I want to get a single hash of the folder and its contents, not individual file hashes .
dany Posted November 22, 2012 Posted November 22, 2012 (edited) Then you'll have to do something like this: #include <Crypt.au3> _Crypt_Startup() ; Assuming $aAListOfFilesInAFolder is an array of file names. For $i = 1 To $aAListOfFilesInAFolder[0] $sFileContent = FileRead( $aAListOfFilesInAFolder[$i]) ; Third parameter should be True for the last iteration. $sHash = _Crypt_HashData($sFileContent, $CALG_MD5, False, $sHash) Next _Crypt_Shutdown() Edited November 22, 2012 by dany [center]Spiderskank Spiderskank[/center]GetOpt Parse command line options UDF | AU3Text Program internationalization UDF | Identicon visual hash UDF
NDog Posted November 22, 2012 Author Posted November 22, 2012 Solved. Thanks for your suggestions danny and Danyfirex - md5 enumerator - _RecFileListToArray#include <RecFileListToArray.au3> #include <md5.au3> $dir = FileSelectFolder("Select Folder to Traverse","",4) $FilesList = _RecFileListToArray($dir, "*", 1, 1, 1, 2) Dim $BufferSize = 0x20000, $Timer = TimerInit() $MD5CTX = _MD5Init() ; start reading input into the buffer For $i = 1 To $FilesList[0] $Filename = $FilesList[$i] $FileHandle = FileOpen($FilesList[$i], 16) For $j = 1 To Ceiling(FileGetSize($Filename) / $BufferSize) _MD5Input($MD5CTX, FileRead($FileHandle, $BufferSize)) ; add input into the buffer Next FileClose($FileHandle) Next $Hash = _MD5Result($MD5CTX) ; finish reading input into the buffer ConsoleWrite("MD5 Result: "& $Hash & " in " & Round(TimerDiff($Timer)) & " ms"&@CRLF)
guinness Posted November 22, 2012 Posted November 22, 2012 (edited) Ndog, To save on time with large files maybe only hash a small percentage of the file. Here is an idea >> #include <File.au3> #include <Crypt.au3> _Crypt_Startup() Example() _Crypt_Shutdown() Func Example() Local $aArray = _FileListToArray(@ScriptDir, '*', 1), $sHash = '' For $i = 1 To $aArray[0] $sHash = _MD5Hash($aArray[$i], 25) ; Read only 25% of the file. ConsoleWrite($aArray[$i] & ' :: ' & $sHash & @CRLF) Next EndFunc ;==>Example ; By guinness - 2012. Func _MD5Hash($sFilePath, $iRead = Default) ; Default is 100% If ($iRead > 100) Or ($iRead < 0) Or $iRead = Default Then $iRead = 100 EndIf $iRead = ($iRead / 100) * FileGetSize($sFilePath) Return _Crypt_HashData(FileRead($sFilePath, $iRead), $CALG_MD5) EndFunc ;==>_MD5Hash OR look at trancexx's MD5 UDF too, in particular this entry >> Edited November 22, 2012 by guinness UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
NDog Posted November 23, 2012 Author Posted November 23, 2012 Thanks for the example Guinness. Sorry if I sound daft but how could I concatenate multiple md5 hash into one md5 hash? With my example I am feeding multiple values into the buffer, but if there is a way to have an array of multiple md5 hashes, how could I take that array and make it into a single md5 hash?
guinness Posted November 23, 2012 Posted November 23, 2012 Using my example or yours? As I can only offer advice with mine at this time. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
ripdad Posted November 24, 2012 Posted November 24, 2012 Perhaps you can do something like this ---> dir c:windows /s > c:list.txtOr use a _FileListToArray function like the one guinness posted.And then hash the list.txt file? "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward
Moderators SmOke_N Posted November 24, 2012 Moderators Posted November 24, 2012 Perhaps you can do something like this ---> dir c:windows /s > c:list.txtOr use a _FileListToArray function like the one guinness posted.And then hash the list.txt file?I can only assume logic here from the OP.Knowing if a file was added or removed is not necessarily what they're looking for.Knowing if there has been "any change" to the structure ( file added, removed, or data inside the file changed in anyway ( not just byte size ) ) would be what they're after.Hashing File names, Directory names, and File contents, on a concatenation process is the only thing that makes sense to me for this to work. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
ripdad Posted November 25, 2012 Posted November 25, 2012 (edited) SmOke_N, True, but... what if list.txt contained all the file hashes? A single hash can then be made on list.txt. If there is a difference between checks, then finding the difference between the text files with a compare function should produce the desired results on which file changed. I haven't played with it enough to know what would be the most efficient in this regard, but it's a place to start, thats all I was trying to convey. -edited forum formatting- Edited November 25, 2012 by ripdad "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward
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