Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Hooking a kernel API, and dealing with advanced data types.



  • Please log in to reply
16 replies to this topic
Verdlin
  • Members
  • 256 posts
  • Last active: Apr 29 2016 06:46 PM
  • Joined: 21 Dec 2012
✓  Best Answer

Finally got it all figured out! The answer lay in RtlMoveMemory. Special thanks to HotKeyIt for helping me out!

 

Here's the post from his answer in the Autohotkey.dll thread.

 

Try this.

Here we start a separate process and inject the dll which hooks GetsystemTime function.

Then we DllCall GetSystemTime function and the dll thread sets the pointer memory.

 

MasterScript.ahk


 

SSystemTime :="WORD wYear;WORD wMonth;WORD wDayOfWeek;WORD wDay;WORD wHour;WORD wMinute;WORD wSecond;WORD wMilliseconds"
PID:=DynaRun("MsgBox Press Ok to start`nst:=Struct(""" SSystemTime """)`nDllCall(""GetSystemTime"",""PTR"",st[])`nMsgbox `% st.wYear ""``n"" st.wMilliseconds")
FileRead,HookScript,HookScript.ahk
rThread:=InjectAhkDll(PID,A_ScriptDir "\AutoHotkey.dll",HookScript)
MsgBox Press Ok to unload AutoHotkey.dll from Remote Process
 

 

 

HookScript.ahk:


 

SSystemTime :="WORD wYear;WORD wMonth;WORD wDayOfWeek;WORD wDay;WORD wHour;WORD wMinute;WORD wSecond;WORD wMilliseconds"
global g_vSystemTime := Struct(SSystemTime)

g_vSystemTime.wYear := 2011
g_vSystemTime.wMonth := 1
g_vSystemTime.wDayOfWeek := 1
g_vSystemTime.wDay := 1
g_vSystemTime.wHour := 1
g_vSystemTime.wMinute := 1
g_vSystemTime.wSecond := 1
g_vSystemTime.wMilliseconds := 1

OnExit,UnHook
If !HookFunction("kernel32.dll", "GetSystemTime", MyGetSystemTime:=RegisterCallback("GetSystemTime","", 1), hGetSystemTime)
MsgBox Function could not be hooked
MsgBox Function hooked
Return

UnHook:
UnHookFunction("kernel32.dll", "GetSystemTime", hGetSystemTime)
ExitApp


GetSystemTime(lpSystemTime)
{
DllCall("RtlMoveMemory","PTR",lpSystemTime,"PTR",g_vSystemTime[],"UINT",sizeof(g_vSystemTime))
return 1
}
 

Scripts are written and tested using AHK_H 64w (unless otherwise specified).

CFlyout. EasyIni. Dynamic Label Execution (No Reload). Word Lookup.


_3D_
  • Members
  • 79 posts
  • Last active: Mar 14 2014 07:49 PM
  • Joined: 28 Feb 2013

Is there some DirectInput hook / detours that may be used in games that used DirectInput ?

 

Mean Hook DirectInput (keyboard and mouse) then use Autohotkey scripts to control game.

Thanks in advance.