找回密码
 加入
搜索
查看: 2642|回复: 1

[系统综合] 结束线程模块[已解决]

[复制链接]
发表于 2010-7-28 14:57:21 | 显示全部楼层 |阅读模式
本帖最后由 xsjtxy 于 2010-7-28 16:44 编辑

求教结束IE里面加载的dll模块
以下是论坛里面搜到的关于线程模块的查看和结束的贴子。查看所有加载的线程是没问题。
但是结束的贴子不管用。麻烦各位大侠改进一下。
http://www.autoitx.com/forum.php ... hlight=%C4%A3%BF%E9
http://www.autoitx.com/forum.php ... hlight=%C4%A3%BF%E9
#include <LocalSecurityAuthority.au3>

$iProcessID = ProcessExists("IEXPLORE.EXE")
$sModule = "C:\windows\system32\bbns.dll"
_UnloadDll($iProcessID, $sModule) ; Returns True if succeeds.


Func _UnloadDll($iProcessID, $sModule)
        Local $aModule, $hModule, $pFreeLibrary, $hThread, $hProcess
        Local $hToken, $aPriv[1][2] = [[$SE_DEBUG_NAME, 2]], $iFlags

        $hToken = _OpenProcessToken(-1)
        _AdjustTokenPrivileges($hToken, $aPriv)
        _LsaCloseHandle($hToken)

        $hProcess = _OpenProcess($iProcessID)
        If $hProcess < 1 Then Return SetError(@error, 0, 0)

        $sModule = _GetFullPathName($sModule)
        $hModule = _GetModuleHandle("Kernel32.dll")
        $pFreeLibrary = _GetProcAddress($hModule, "FreeLibrary")

        $aModule = _EnumProcessModules($hProcess)
        For $i = 1 To $aModule[0][0]
                If $aModule[$i][1] <> $sModule Then ContinueLoop
                $hThread = _CreateRemoteThread($hProcess, 0, 0, $pFreeLibrary, $aModule[$i][0], 0)
                If @extended Then $iFlags = 1
                _LsaCloseHandle($hThread)
        Next
        $aModule = _EnumProcessModules($hProcess)
        For $i = 1 To $aModule[0][0]
                If $aModule[$i][1] = $sModule Then $iFlags = 0
        Next
        Return SetError(0, _LsaCloseHandle($hProcess), $iFlags)
EndFunc        ;==>_UnloadDll

Func _GetFullPathName($sFile)
        Local $iResult
        $iResult = DllCall("Kernel32.dll", "int", "GetFullPathName", _
                        "str", $sFile, "dword", 260, "str", "", "str", "")
        Return $iResult[3]
EndFunc        ;==>_GetFullPathName

Func _GetModuleHandle($sModule)
        Local $iResult
        $iResult = DllCall("Kernel32.dll", "long", "GetModuleHandle", "str", $sModule)
        Return SetError(_GetLastError(), 0, $iResult[0])
EndFunc        ;==>_GetModuleHandle

Func _EnumProcessModules($hProcess)
        Local $pBuffer, $tBuffer, $iResult, $aResult[1][2]

        $iResult = DllCall("Psapi.dll", "int", "EnumProcessModules", "hWnd", $hProcess, _
                        "ptr", 0, "dword", 0, "dword*", 0)
        $pBuffer = _HeapAlloc($iResult[4])
        $iResult = DllCall("Psapi.dll", "int", "EnumProcessModules", "hWnd", $hProcess, _
                        "ptr", $pBuffer, "dword", $iResult[4], "dword*", 0)
        $tBuffer = DllStructCreate("hWnd Modules[" & ($iResult[4] / 4) & "]", $pBuffer)
        $aResult[0][0] = $iResult[4] / 4
        Redim $aResult[$aResult[0][0] + 1][2]
        For $i = 1 To $aResult[0][0]
                $aResult[$i][0] = DllStructGetData($tBuffer, "Modules", $i)
                $aResult[$i][1] = _GetModuleFileNameEx($hProcess, $aResult[$i][0])
        Next
        _HeapFree($pBuffer)
        Return SetError(0, _FreeVariable($tBuffer), $aResult)
EndFunc        ;==>_EnumProcessModules

Func _GetModuleFileNameEx($hProcess, $hModule)
        Local $iResult
        $iResult = DllCall("Psapi.dll", "dword", "GetModuleFileNameEx", "hWnd", $hProcess, _
                        "hWnd", $hModule, "str", "", "dword", 260)
        Return $iResult[3]
EndFunc        ;==>_GetModuleFileNameEx

Func _GetProcAddress($hModule, $sProcdure)
        Local $iResult
        $iResult = DllCall("Kernel32.dll", "hWnd", "GetProcAddress", "hWnd", $hModule, "str", $sProcdure)
        Return $iResult[0]
EndFunc        ;==>_GetProcAddress

Func _CreateRemoteThread($hProcess, $pThreadSecur, $iStackSize, $pStartAddr, $pParam, $iFlags)
        Local $iResult
        $iResult = DllCall("Kernel32.dll", "hWnd", "CreateRemoteThread", "hWnd", $hProcess, _
                        "ptr", $pThreadSecur, "dword", $iStackSize, "ptr", $pStartAddr, _
                        "ptr", $pParam, "dword", $iFlags, "dword*", 0)
        Return SetError(_GetLastError(), $iResult[7], $iResult[0])
EndFunc        ;==>_CreateRemoteThread

评分

参与人数 1金钱 +10 收起 理由
afan + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

 楼主| 发表于 2010-7-28 16:44:34 | 显示全部楼层
经过反复测试发现原来是因为某些DLL的原因。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-10-3 12:31 , Processed in 0.072184 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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