找回密码
 加入
搜索
查看: 2968|回复: 4

论坛新开!前来找MD5文件效验Func

[复制链接]
发表于 2008-5-6 21:55:02 | 显示全部楼层 |阅读模式
记得之前有人发过调用md5deep.exe来检测文件的MD5值!!
之前的作者看到的话,贡献出宝贵的源码!!感激不尽!!!

[ 本帖最后由 scandisk 于 2008-5-10 14:00 编辑 ]
发表于 2008-5-6 23:43:49 | 显示全部楼层
发表于 2010-12-6 17:44:39 | 显示全部楼层
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]
        $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 $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
                DllCall("kernel32.dll", "int", "UnmapViewOfFile", "ptr", $pFile)
                DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFileMappingObject)
                Return SetError(4, 0, "")
        EndIf

        DllCall("advapi32.dll", "none", "MD5Update", _
                        "ptr", DllStructGetPtr($tMD5_CTX), _
                        "ptr", $pFile, _
                        "dword", $iBufferSize)
        If @error Then
                DllCall("kernel32.dll", "int", "UnmapViewOfFile", "ptr", $pFile)
                DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFileMappingObject)
                Return SetError(5, 0, "")
        EndIf
       DllCall("advapi32.dll", "none", "MD5Final", "ptr", DllStructGetPtr($tMD5_CTX))

        If @error Then
                DllCall("kernel32.dll", "int", "UnmapViewOfFile", "ptr", $pFile)
                DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFileMappingObject)
                Return SetError(6, 0, "")
        EndIf
        DllCall("kernel32.dll", "int", "UnmapViewOfFile", "ptr", $pFile)
        DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFileMappingObject)
        Local $sMD5 = Hex(DllStructGetData($tMD5_CTX, "digest"))
        Return SetError(0, 0, $sMD5)

EndFunc   ;==>_MD5ForFile
发表于 2012-9-16 14:37:36 | 显示全部楼层
我也正在找呢。
发表于 2017-4-12 11:53:15 | 显示全部楼层
这个好,喜欢
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-28 17:30 , Processed in 0.073265 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表