3

The one of technique of input emulation protection with automation toools like AutoIt or ACTools used most of simple game bot programs is SetWindowsHookEx usage WH_KEYBOARD_LL flags. This solution is not silver bullet and (for example) the bot software can use PS/2 driver to emulate hardware input. Is this question let's assume that the PS/2 problem has already been solved.

WH_KEYBOARD_LL installs a hook procedure that monitors low-level keyboard input events. For more information, see the LowLevelKeyboardProc hook procedure.

WH_KEYBOARD_LL is used (instead of WH_KEYBOARD) because of just LowLevelKeyboardProc contains pointer to KBDLLHOOKSTRUCT with event-injected flags, context code, and transition-state flag. The sample protection code is quite simple:

LRESULT CALLBACK KeyboardProc(int code, WPARAM wParam, LPARAM lParam) {
  if (code < 0)
    return CallNextHookEx(_hookKeybrd, code, wParam, lParam);

  KBDLLHOOKSTRUCT& ll = *(KBDLLHOOKSTRUCT*)lParam;
  if (ll.flags & LLKHF_INJECTED)
    return 1; //emulation case

  return CallNextHookEx(_hookKeybrd, code, wParam, lParam);
}
...
SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardProc, GetModuleHandle(NULL), 0);

But if application uses this code it sould be system wide.

Questions:

  • If any way to limit this to specific application?
  • Is any other ways to prevent input emulation in specific application?
12
  • Which way are you looking to limit it to specfic application? From a developer point of view? If your the developer, you could use dll injection and use SetWindowsHookEx with WH_KEYBOARD for local process rather than global like WH_KEYBOARD_LL.
    – Paul
    Feb 1, 2016 at 9:43
  • I mean if my application filter input from system (and other software) is any way to filter input sended from specific application? For example input from remote terminal is allowed but input from unknown software disallowed. Also WH_KEYBOARD do not contains any information about input nature. WH_KEYBOARD_LL allow to differ software generated input from software generated. Feb 1, 2016 at 9:48
  • I'm putting this in a comment because being wrong in a comment is MUCH less embarrassing than being wrong in an answer. What about the null hypothesis? If I can show that you can't stop an emulation from happening, then the answer would be that you can't stop everything. SetWindowsHookEx can't detect joystick input. And joystick input can't be blocked. Joystick input via WM_INPUT isn't in the same format as keyboard input anyway, so it doesn't matter whether you use different methods to detect them. What if you create a joystick profile that emulates a keyboard joytokey.net/en
    – Everett
    Feb 2, 2016 at 5:20
  • SetWindowsHookEx can detect joystick input because it sends like software mouse/keyboard. Also joytokey can be blocked by disable they driver. Any way using SetWindowsHookEx stops most of middle level attackers. Feb 2, 2016 at 8:51
  • @misterion Does it matter if it's an impractical solution? Feb 5, 2016 at 3:10

0

You must log in to answer this question.

Browse other questions tagged .