以下 java
程序在 C
中呼叫本地方法,该方法应该打印一条消息 ,如果用户按下密钥,你按下密钥!
。但是,我看不到消息是i按下密钥。 我还会检查函数 SetWindowsHookEx
是否返回无效,但没有,它不会返回无效。
Java 代码:
package keylogger;
public class TestKeys {
private native void setWinHook();
public static void main(String args[]) {
TestKeys o = new TestKeys();
try {
o.setWinHook();
Thread.sleep(10000);
} catch(Exception exc) {
exc.printStackTrace();
}
}
static {
System.loadLibrary("MyHook");
}
} C Code :
#include <stdio.h>
#include <windows.h>
#include <w32api.h>
#include "keylogger_TestKeys.h"
static HHOOK handleKeyboardHook = NULL;
HINSTANCE hInst = NULL;
static LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) {
printf("You pressed a key !
");
return CallNextHookEx(handleKeyboardHook, nCode, wParam, lParam);
}
void Java_keylogger_TestKeys_setWinHook
(JNIEnv *env, jobject obj) {
hInst = GetModuleHandle(NULL); // include or exclude,i don t see the result
handleKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc,NULL, 0);
if(handleKeyboardHook==NULL) {
printf("Is Null");
} else {
printf("Is not Null");
}
printf("Inside fucntion setWinHook !");
}
/*int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
printf("Hello World !");
handleKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, hInstance, 0);
if(handleKeyboardHook==NULL) {
printf("Is Null");
} else {
printf("Is not Null");
}
MSG msg;
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}*/
我看到的唯一输出是 不是NullInside fucntion 设置 WinHook!
问题在哪里?
What should i do so that this program returns me the message when i press the key.
The only output that I see is : Inside function setWinHook !
注:
如果上面的程序运行在某人的S机器上 请提及这一点
Exput Pic:
""https://i.sstatic.net/39nY8.jpg" alt="此处输入图像描述"/"
我看不到任何关于密钥窃听的信息。 程序在10秒后退出, 没有显示消息 。