微剋多資訊

 找回密碼
 註冊

Login

Login

搜索
回覆 0則 瀏覽 2916篇

[碼源] autoit 兩個檔案MD5 比較

該用戶從未簽到

發表於 2014-5-22 21:59 | 顯示全部樓層 |閱讀模式
  1. #include <GUIConstants.au3>
  2. #include <WindowsConstants.au3>
  3. #include <EditConstants.au3>
  4. #include <Array.au3>
  5. #include <ListboxConstants.au3>
  6. #Include <GuiListBox.au3>
  7. #NoTrayIcon

  8. Dim $Width = 400,$Height = 400,$Distance = 15
  9. Dim $Reg = "HKCU\Software\Dang\AnimeReName"

  10. $GUI = GUICreate ( "MD5", $Width*2+($Distance*5), $Height+($Distance*5)+5)

  11. $MD5_List_1 = GUICtrlCreateList ( "", $Distance, $Distance*3, $Width, $Height-5, $LBS_NOTIFY)
  12. $MD5_List_2 = GUICtrlCreateList ( "", $Width+($Distance*4), $Distance*3, $Width, $Height-5, $LBS_NOTIFY)

  13. $MD5_List_Cnt_1 = GUICtrlCreateLabel ( "", $Distance*8, $Distance, 85, 25)
  14.         GUICtrlSetFont ( -1, 10, 800)
  15. $MD5_List_Cnt_2 = GUICtrlCreateLabel ( "", ($Distance*11)+$Width, $Distance, 85, 25)
  16.         GUICtrlSetFont ( -1, 10, 800)

  17. $btn1 = GUICtrlCreateButton ( "瀏覽", $Distance, $Distance-5, 100, 25)
  18. $btn2 = GUICtrlCreateButton ( "瀏覽", ($Distance*4)+$Width, $Distance-5, 100, 25)

  19. GUISetState ()

  20. While 1
  21.         $msg = GUIGetMsg()

  22.         Switch $msg
  23.                 Case $GUI_EVENT_CLOSE
  24.                         Exit
  25.                 Case $btn1
  26.                         _FileOpen_1()
  27.                 Case $btn2
  28.                         _FileOpen_2()
  29.         EndSwitch
  30. WEnd

  31. Func _FileOpen_1()
  32.         GUICtrlSetData ( $MD5_List_1, "")
  33.         Local $str, $FileRut

  34.         $input = FileOpenDialog ( "", @ScriptDir&"\", "任何檔案 (*.*)", 7)
  35.         If $input = "" Then Return
  36.         $tmpStr = StringSplit ( $input, "|", 2)

  37.         If UBound ($tmpStr) <> 1 Then
  38.                 Global $MD5_1[UBound ($tmpStr)-1]
  39.                 For $i = 1 To UBound ($tmpStr)-1
  40.                         $FileRut = $tmpStr[0]&"\"&$tmpStr[$i]
  41.                         $MD5_1[$i-1] = _MD5($FileRut)
  42.                 Next
  43.         Else
  44.                 Global $MD5_1[1],$strtme
  45.                 $MD5_1[0] = _MD5($tmpStr[0])
  46.         EndIf

  47.         For $i = 0 To UBound ($MD5_1, 1)-1
  48.                 $str = StringFormat ( "%s%s|", $str, $MD5_1[$i])
  49.         Next
  50.         GUICtrlSetData ( $MD5_List_1, $str)
  51.         GUICtrlSetData ( $MD5_List_Cnt_1, StringFormat ( "%d個", UBound ($MD5_1, 1)))
  52. EndFunc

  53. Func _FileOpen_2()
  54.         GUICtrlSetData ( $MD5_List_2, "")
  55.         Local $str, $FileRut

  56.         $input = FileOpenDialog ( "", @ScriptDir&"\", "任何檔案 (*.*)", 7)
  57.         If $input = "" Then Return
  58.         $tmpStr = StringSplit ( $input, "|", 2)

  59.         If UBound ($tmpStr) <> 1 Then
  60.                 Global $MD5_2[UBound ($tmpStr)-1]
  61.                 For $i = 1 To UBound ($tmpStr)-1
  62.                         $FileRut = $tmpStr[0]&"\"&$tmpStr[$i]
  63.                         $MD5_2[$i-1] = $FileRut
  64.                         $MD5_2[$i-1] = _MD5($FileRut)
  65.                 Next
  66.         Else
  67.                 Global $MD5_2[1],$strtme
  68.                 $MD5_2[0] = _MD5($tmpStr[0])
  69.         EndIf

  70.         For $i = 0 To UBound ($MD5_2, 1)-1
  71.                 $str = StringFormat ( "%s%s|", $str, $MD5_2[$i])
  72.         Next
  73.         GUICtrlSetData ( $MD5_List_2, $str)
  74.         GUICtrlSetData ( $MD5_List_Cnt_2, StringFormat ( "%d個", UBound ($MD5_2, 1)))
  75. EndFunc

  76. Func _MD5($sFile)
  77.         Local Const $CALG_MD2 = 0x8001
  78.         Local Const $CALG_MD4 = 0x8002
  79.         Local Const $CALG_MD5 = 0x8003
  80.         Local Const $CALG_SHA1 = 0x8004

  81.         $hFile = FileOpen ($sFile, 16)
  82.         $bData = FileRead ($hFile)
  83.         $iLength = BinaryLen ($bData)
  84.         FileClose($hFile)

  85.         $tBuffer = DllStructCreate("byte[" & $iLength & "]")
  86.         $pBuffer = DllStructGetPtr($tBuffer)
  87.         DllStructSetData($tBuffer, 1, $bData)

  88.         $iResult = DllCall ("Crypt32.dll", "int", "CryptHashCertificate", "hWnd", 0, "dword", $CALG_MD5, "dword", 0, "ptr", $pBuffer, "dword", $iLength, "ptr", 0, "dword*", 0)
  89.         $tResult = DllStructCreate ("byte[" & $iResult[7] & "]")
  90.         $pResult = DllStructGetPtr ($tResult)
  91.         $iResult = DllCall ("Crypt32.dll", "int", "CryptHashCertificate", "hWnd", 0, "dword", $CALG_MD5, "dword", 0, "ptr", $pBuffer, "dword", $iLength, "ptr", $pResult, "dword*", $iResult[7])
  92.         If $iResult[0] <> 0 Then Return StringTrimLeft (DllStructGetData ($tResult, 1), 2)
  93.         $tBuffer = 0
  94.         $tResult = 0
  95. EndFunc
複製代碼
您需要登入後才可以回帖 登入 | 註冊

本版積分規則

小黑屋|Archiver|微剋多資訊(MicroDuo)

GMT+8, 2016-12-9 04:01

Discuz! X

© 2009-2016 Microduo

快速回覆 返回頂部 返回列表