MinHook - API Hooking Library

Post your working scripts, libraries and tools
tmplinshi
Posts: 1281
Joined: 01 Oct 2013, 14:57

MinHook - API Hooking Library

11 Aug 2018, 06:59

An AHK wrapper for MinHook.

Example 1 - Hook MessageBoxW

Code: Select all

#Include <MinHook>

hook1 := New MinHook("user32.dll", "MessageBoxW", "MessageBoxW_Hook")

hook1.Enable()
MsgBox, 64, Hello, World

hook1.Disable()
MsgBox, 64, Hello, I'm back.

hook1 := "" ; Remove hook

MessageBoxW_Hook(hWnd, lpText, lpCaption, uType) {
	global hook1
	return DllCall(hook1.original, "ptr", hWnd, "str", "Hooked!", "ptr", lpCaption, "uint", 48)
}
Example 2 - Set value for input file type in webbrowser control
Example 3 - Hook another process using HotkeyIt's InjectAhkDll and AutoHotkey.dll

Download
burque505
Posts: 689
Joined: 22 Jan 2017, 19:37

Re: MinHook - API Hooking Library

11 Aug 2018, 14:56

Hi, tmplinshi, how do I handle

Code: Select all

#Include <MinHook>
? I can see that AutoHotkey_H lists its license on the github page, and found a program or two that use the DLL, but I don't find a library MinHook.ahk anywhere.
Edit: :facepalm: Wow. I don't know how much more obvious it could have been. :facepalm:
Sorry.
Regards,
burque505
Edit: That's really classy, tmplinshi, thank you. That will doubtless come in handy. I had to pull _Struct.ahk and sizeof.ahk out of the Lib folder because I already had them in my main Lib folder. Everything works great, ex. 3 works with AHK_H 1.1.29.01 v002.
Thanks again!
guest3456
Posts: 2471
Joined: 09 Oct 2013, 10:31

Re: MinHook - API Hooking Library

13 Aug 2018, 23:41

excellent

tmplinshi
Posts: 1281
Joined: 01 Oct 2013, 14:57

Update to v1.1 (2018-8-16)

16 Aug 2018, 01:29

  • The module dll will now unload when the hook removed. (Except for standard DLL - User32.dll, Kernel32.dll, ComCtl32.dll, or Gdi32.dll)
  • Added more directories to search for MinHook.dll. You can place Minhook.dll in one of the following directories:
    • WorkingDir
    • WorkingDir\MinHook\x32 and/or WorkingDir\MinHook\x64
    • Minhook.ahk Directory
    • Minhook.ahk Directory\MinHook\x32 and/or Minhook.ahk Directory\MinHook\x64
feiyue
Posts: 130
Joined: 08 Aug 2014, 04:08

Re: MinHook - API Hooking Library

16 Aug 2018, 03:56

Hi tmplinshi, This is a very useful script! thanks for sharing! :wave:

I think Example2 needs to modify one line (Otherwise I can't see the effect.):

Example2 - GetOpenFileNameW.ahk
return DllCall(hook1.original, "ptr", ofn), hook1 := ""
tmplinshi
Posts: 1281
Joined: 01 Oct 2013, 14:57

Re: MinHook - API Hooking Library

16 Aug 2018, 06:46

feiyue wrote:I think Example2 needs to modify one line (Otherwise I can't see the effect.):

Example2 - GetOpenFileNameW.ahk
return DllCall(hook1.original, "ptr", ofn), hook1 := ""
But then a window will popup, which was the Example2 trying to avoid. :)

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 55 guests