本帖最后由 gto250 于 2010-9-9 11:04 编辑
一个半成品的中文键盘记录,记事本程序的中文记录,用的是P版的hook api
对ImmGetCompositionString进行hook
LONG ImmGetCompositionStringA LPVOID lpBuf (
__in HIMC hIMC,
__in DWORD dwIndex,
__out LPVOID lpBuf,
__in DWORD dwBufLen
);
我在网上看到的文章是只要dwIndex=0x0800 dwBufLen不为空就可以获取lpBuf
lpBuf就是字符串。我用的输入法是搜狗输入法,不管我输入的是什么字,获取到的lpBuf都是0x0012F96C
不知道哪里出错了,请指正#include <RTApiHook32.au3>
$hCallBack = DllCallbackRegister("_ApiHookCallBack", "dword", "handle;ptr")
$pCallBack = DllCallbackGetPtr($hCallBack)
$hProcess = _RTOpenProcess("notepad.exe")
$immA = _RTGetProcAddress("imm32.dll", "ImmGetCompositionStringA")
$immW = _RTGetProcAddress("imm32.dll", "ImmGetCompositionStringW")
$tHookimmA = _RTApiHookEx($hProcess, $immA, 4, $pCallBack, $APIHOOK_Flags_Default)
$tHookimmW = _RTApiHookEx($hProcess, $immW, 4, $pCallBack, $APIHOOK_Flags_Default)
HotKeySet("^{f5}", "_Close")
OnAutoItExitRegister("_Close")
While 1
Sleep(100)
WEnd
Func _ApiHookCallBack($hProcess, $pCallInfo)
Switch _RTApiHookReadProcedure($hProcess, $pCallInfo)
Case $tHookimmA
$dwIndex = _RTApiHookReadParam($hProcess, $pCallInfo, 2)
$dwBufLen = _RTApiHookReadParam($hProcess, $pCallInfo, 4)
$Buffer = _RTApiHookReadParam($hProcess, $pCallInfo, 3)
MsgBox(0, $dwBufLen, $Buffer)
Case $tHookimmW
EndSwitch
EndFunc ;==>_ApiHookCallBack
Func _Close()
_RTApiUnhook($hProcess, $immA, DllStructGetData($tHookimmA, 6))
_RTApiUnhook($hProcess, $immW, DllStructGetData($tHookimmW, 6))
Exit
EndFunc ;==>_Close
|