#include <LocalSecurityAuthority.au3>
$iProcessID = ProcessExists("iexplore.exe")
$sModule = "C:\Watcher\APIHook_Dll.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
LocalSecurityAuthority.au3 -