-
Notifications
You must be signed in to change notification settings - Fork 3
/
hookclass.ahk
55 lines (45 loc) · 1.98 KB
/
hookclass.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#NoEnv
#persistent
#notrayicon
#KeyHistory 0
#MaxThreads 1
critical, 0xFFFFFFFF
ListLines Off
SetBatchLines, -1
resume()
{
envget, injector_hwnd, injector_hwnd
StringToSend := "resume"
VarSetCapacity(CopyDataStruct, 3*A_PtrSize, 0)
SizeInBytes := (StrLen(StringToSend) + 1) * (A_IsUnicode ? 2 : 1)
NumPut(SizeInBytes, CopyDataStruct, A_PtrSize)
NumPut(&StringToSend, CopyDataStruct, 2*A_PtrSize)
return dllcall("SendMessageW", uint, injector_hwnd, uint, 0x4a, uint, 0, uint, &CopyDataStruct)
}
class Hook {
__new(hook, dll, function2hook, callback_options = "F")
{
if ! (hModule := dllcall("GetModuleHandle", "str", (A_ptrsize=4) ? "ahkhook.dll" : "ahkhook64.dll", ptr) )
return "Failed to get a handle to ahkhook.dll with error " A_lasterror
if ! (sethooks := dllcall("GetProcAddress", "ptr", hModule, "astr", "sethook", ptr) )
return "Failed to get the address of the sethook procedure with error " A_lasterror
if ! (this.unhook := dllcall("GetProcAddress", "ptr", hModule, "astr", "unhook", ptr) )
return "Failed to get the address of the unhook procedure with error " A_lasterror
if ! (this.hook_callback := registercallback(hook, callback_options) )
return "Failed to register the autohotkey callback"
if ! (hHookedModule := dllcall("GetModuleHandle", "str", dll, ptr) )
return "Failed to get a handle to dll that exports the function to be hooked with error " A_lasterror
if ! (function2hook_add := dllcall("GetProcAddress", "ptr", hHookedModule, "astr", function2hook, ptr) )
return "Failed to get the address of the function to hook with error " A_lasterror
this.OriginalPtr := function2hook_add
r := dllcall(sethooks, "Ptr*", function2hook_add, "Ptr", this.hook_callback, int)
if r
return r
this.Trampoline := function2hook_add
}
__delete()
{
if ! (dllcall(this.unhook, "Ptr*", This.OriginalPtr, "Ptr", this.Trampoline))
DllCall("GlobalFree", "Ptr", this.hook_callback, "Ptr")
}
}