-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path__ahkhook.ahk
96 lines (81 loc) · 3.06 KB
/
__ahkhook.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <memlib\memlib>
#include <shell>
SetWorkingDir %A_ScriptDir%
OnMessage(0x4a, "WM_COPYDATA")
if !A_iscompiled
runwait, Ahk2Exe.exe /in %A_scriptName% /out ahkhook.exe /mpress 0
compileScript("HookClass.ahk")
FileInstall, HookClass.txt, ?Dummy
global proc
global target := GetCommandLineValueB("-t")
global script := GetCommandLineValueB("-s")
global no_argv0 := instr(dllcall("GetCommandLine", str), "-n")
global args := GetCommandLineValueB("-a")
global env := GetCommandLineValueB("-e")
fileread, script, %script%
r := dllcall("GetBinaryType", astr, target, "uint*", type)
if (type = 6)
{
cmd := dllcall("GetCommandLineW", str)
runwait, ahkhook64.exe %cmd%, , , ProcessID
hProcess := DllCall("OpenProcess", "Int", 0x0008 | 0x0010 | 0x0020 | 0x0400, "char", 0, "uint", ProcessID, "uint")
process, waitclose, %ProcessID%
dllcall("GetExitCodeProcess", uint, hProcess, "uint*", exitcode)
ExitApp, %exitcode%
}
launchTarget(target)
launchTarget(target)
{
if env
envset, remote_settings, %env%
envset, injector_hwnd, %A_scripthwnd%
g_ahkpath := A_scriptdir "\AutoHotkey.dll"
g_peixotopath := A_scriptdir "\ahkhook.dll"
dllcall("LoadLibraryW", str, g_ahkpath) ?: Quit(1, A_lasterror)
dllcall("LoadLibraryW", str, g_peixotopath) ?: Quit(2, A_lasterror)
SplitPath, target, name, dir
__args := (no_argv0) ? "" : """" target """ "
__args .= args
if ! isobject( (proc := CreateIdleProcess(target, dir, __args)) )
quit(3, proc)
(err := dllcallEx(proc.hProcess, "Kernel32.dll", "LoadLibraryW", g_ahkpath)) ? Quit(4, err)
(err := dllcallEx(proc.hProcess, "Kernel32.dll", "LoadLibraryW", g_peixotopath)) ? Quit(5, err)
success := dllcallEx(proc.hProcess, "autohotkey.dll", "ahktextdll", LoadResource("HookClass.txt", A_iscompiled ? "": "ahkhook.exe") "`n" script "`nresume()")
success ? quit(6, success)
id := proc.Process_id
process, waitclose, %id%
exitapp
}
quit(level, lasterror)
{
exitcode := (level<<16) | lasterror
ExitApp, %exitcode%
}
WM_COPYDATA(wParam, lParam)
{
ResumeProcess(proc.hThread)
}
compileScript(script)
{
if A_iscompiled
return
splitpath, script, , , ,script_name
runwait, Ahk2Exe.exe /in %script% /out %script_name%.exe
script_txt := LoadResource(">AUTOHOTKEY SCRIPT<", script_name ".exe")
filedelete, %script_name%.txt
fileappend, %script_txt%, %script_name%.txt
}
LoadResource(resource, module = "")
{
if not module
hModule := dllcall("GetModuleHandle", uint, 0)
else FreeLater := hModule := dllcall("LoadLibraryW", str, module, uint, 0, uint, (LOAD_LIBRARY_AS_DATAFILE := 0x00000002))
HRSRC := dllcall("FindResourceW", uint, hModule, str, resource, ptr, 10)
hResource := dllcall("LoadResource", uint, hModule, uint, HRSRC)
DataSize := DllCall("SizeofResource", ptr, hModule, ptr, HRSRC, uint)
pResData := dllcall("LockResource", uint, hResource, ptr)
ret := strget(pResData, DataSize, "UTF-8")
;dllcall("FreeResource", uint, hResource)
FreeLater ? dllcall("FreeLibrary", uint, hModule)
return ret
}