| 19 | } |
| 20 | |
| 21 | long call_set_input_hook(HWND hwnd, int mode) { |
| 22 | DWORD pid = 0; |
| 23 | ::GetWindowThreadProcessId(hwnd, &pid); |
| 24 | if (pid == 0) |
| 25 | return 0; |
| 26 | |
| 27 | blackbone::Process proc; |
| 28 | const NTSTATUS status = proc.Attach(pid); |
| 29 | if (!NT_SUCCESS(status)) { |
| 30 | setlog(L"input hook attach failed. pid=%d hwnd=%p status=0x%X", pid, hwnd, status); |
| 31 | return 0; |
| 32 | } |
| 33 | |
| 34 | long ret = 0; |
| 35 | const std::wstring dll_name = resolve_hook_dll(proc); |
| 36 | bool injected = proc.modules().GetModule(dll_name) != nullptr; |
| 37 | if (!injected) { |
| 38 | const std::wstring dll_path = RuntimeEnvironment::getBasePath() + L"\\" + dll_name; |
| 39 | if (::PathFileExistsW(dll_path.c_str())) { |
| 40 | auto inject_ret = proc.modules().Inject(dll_path); |
| 41 | injected = inject_ret ? true : false; |
| 42 | if (!injected) { |
| 43 | setlog(L"input hook inject failed. pid=%d hwnd=%p status=0x%X dll=%s", pid, hwnd, inject_ret.status, |
| 44 | dll_path.c_str()); |
| 45 | } |
| 46 | } else { |
| 47 | setlog(L"input hook dll not exists: %s", dll_path.c_str()); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | if (injected) { |
| 52 | using set_input_hook_t = long(__stdcall *)(HWND, int); |
| 53 | auto remote = blackbone::MakeRemoteFunction<set_input_hook_t>(proc, dll_name, "SetInputHook"); |
| 54 | if (remote) { |
| 55 | auto call_ret = remote(hwnd, mode); |
| 56 | ret = call_ret.result(); |
| 57 | } else { |
| 58 | setlog(L"remote function 'SetInputHook' not found in %s.", dll_name.c_str()); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | proc.Detach(); |
| 63 | return ret; |
| 64 | } |
| 65 | |
| 66 | long call_release_input_hook(HWND hwnd) { |
| 67 | DWORD pid = 0; |
no test coverage detected