Danyfirex Posted December 21, 2014 Share Posted December 21, 2014 I was needing to get SHA-256 from some file. and I made this. expandcollapse popup#include <File.au3> Opt("MustDeclareVars",1) Global Const $iHashLen=32 Global Const $Advapi32="Advapi32.dll" Global Const $PROV_RSA_AES=24 Global Const $CALG_SHA_256=0x0000800c Global Const $CRYPT_VERIFYCONTEXT = 0xF0000000 Global Const $HP_HASHVAL=0x0002 Local $aFiles=_FileListToArray(@SystemDir,"*.exe",1,True) _ArrayDisplay($aFiles) Local $aFiles2[UBound($aFiles)-1][2] For $i= 1 to $aFiles[0] $aFiles2[$i-1][0]=$aFiles[$i] $aFiles2[$i-1][1]=SHA256($aFiles[$i]) Next _ArrayDisplay($aFiles2) Func SHA256($sFile) Local $hCryptProv=0 Local $hHash=0 Local $Ret = 0 Local $iSize=0 Local $tBuffer=0 Local $hHash=0 Local $tHashData=0 Local $sHASH="" if not FileExists($sFile) Then Return "" $iSize=FileGetSize($sFile) $Ret = DllCall($Advapi32, "bool", "CryptAcquireContextW", "handle*", 0, "ptr", NULL, "ptr", Null,"dword",$PROV_RSA_AES,"dword",$CRYPT_VERIFYCONTEXT) ConsoleWrite("+ CryptAcquireContextW Ret= " & $Ret[0] & @TAB & '>Error code: ' & @error & @CRLF) $hCryptProv=$Ret[1] ConsoleWrite("$hCryptProv= " & $hCryptProv & @CRLF) $Ret = DllCall($Advapi32, "bool", "CryptCreateHash", "handle", $hCryptProv, "dword",$CALG_SHA_256,"dword",0,"dword",0,"handle*",0) ConsoleWrite("+ CryptCreateHash Ret= " & $Ret[0] & @TAB & '>Error code: ' & @error & @CRLF) $hHash=$Ret[5] ConsoleWrite("$pHash= " & $hHash & @CRLF) $tBuffer=DllStructCreate("byte Data[" & $iSize & "]") $tBuffer.Data=FileRead($sFile) $Ret = DllCall($Advapi32, "bool", "CryptHashData", "handle", $hHash,"ptr",DllStructGetPtr($tBuffer),"dword",DllStructGetSize($tBuffer),"dword",0) ConsoleWrite("+ CryptHashData Ret= " & $Ret[0] & @TAB & '>Error code: ' & @error & @CRLF) $tHashData=DllStructCreate("byte[" & $iHashLen & "]") $Ret = DllCall($Advapi32, "bool", "CryptGetHashParam", "handle", $hHash, "dword",$HP_HASHVAL,"ptr",DllStructGetPtr($tHashData),"dword*",$iHashLen,"dword",0) ConsoleWrite("+ CryptGetHashParam Ret= " & $Ret[0] & @TAB & '>Error code: ' & @error & @CRLF) For $i=1 to $iHashLen $sHASH&=Hex(DllStructGetData($tHashData, 1, $i), 2) Next if $hHash Then $Ret = DllCall($Advapi32, "bool", "CryptDestroyHash", "handle",$hHash) ConsoleWrite("+ CryptDestroyHash Ret= " & $Ret[0] & @TAB & '>Error code: ' & @error & @CRLF) EndIf If $hCryptProv Then $Ret = DllCall($Advapi32, "bool", "CryptReleaseContext", "handle", $hCryptProv, "dword",0) ConsoleWrite("+ CryptReleaseContext Ret= " & $Ret[0] & @TAB & '>Error code: ' & @error & @CRLF) EndIf $tBuffer=Null $tHashData=Null Return $sHASH EndFunc Saludos Ascer and Luigi 2 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 Link to comment Share on other sites More sharing options...
UEZ Posted December 21, 2014 Share Posted December 21, 2014 Thanks for sharing it - might be useful someday... Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
iamtheky Posted December 21, 2014 Share Posted December 21, 2014 (edited) ...like for updating crypt, tomorrow? Edited December 21, 2014 by boththose ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Danyfirex Posted December 22, 2014 Author Share Posted December 22, 2014 Thanks for sharing it - might be useful someday... Br, UEZ Thank's UEZ ...like for updating crypt, tomorrow? It should be great. Saludos 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 Link to comment Share on other sites More sharing options...
kaesereibe Posted December 22, 2014 Share Posted December 22, 2014 (edited) #2296 - SHA2 for Crypt.au3Erweiterung Crypt.au3 um SHA2 (.de)$CALG_SHA_256 = 0x0000800c $CALG_SHA_384 = 0x0000800d $CALG_SHA_512 = 0x0000800e Edited December 22, 2014 by kaesereibe iamtheky 1 BIN 2 DEC | ConvertTemp | DEC 2 BIN | GetWeekday | HEX 2 RGB | INT 2 HEX | QueryPerformance Link to comment Share on other sites More sharing options...
Danyfirex Posted December 22, 2014 Author Share Posted December 22, 2014 thanks kaesereibe. I notice that with crypt.au3 was easy to make the funtion. (after I made it :S) Saludos 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 Link to comment Share on other sites More sharing options...
guinness Posted December 23, 2014 Share Posted December 23, 2014 Those constants are declared in the UDF and therefore don't need to be included at the top of your script. 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 Link to comment Share on other sites More sharing options...
Danyfirex Posted December 23, 2014 Author Share Posted December 23, 2014 Those constants are declared in the UDF and therefore don't need to be included at the top of your script. In the version 3.3.12.0 are as comment. Saludos 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 Link to comment Share on other sites More sharing options...
Carm01 Posted October 24, 2015 Share Posted October 24, 2015 I compared several files using HashMyFiles by NirSoft, and HashTab by ImplbitsI noticed that the two programs listed above when hashing files in sha256 were always the same when comparing random files.Using the code here to compare the same random file i picked can at times generate a different hash. Not all the time or per say the same file type. Can anyone confirm of deny this? 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