Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Check out the code in this <a href="https://stackoverflow.com/questions/1639331/using-global-keyboard-hook-wh-keyboard-ll-in-wpf-c">post</a>, it has some decent code that is doing what you seem to want. This uses a global hook, which would be the best in your case.</p> <p><strong>Edit:</strong></p> <p>In reply to Ben's comment on wondering how it could be done to inject a hook into a specific process to watch specific threads:</p> <ul> <li>Ensure your injector process is running with administrative privs.</li> <li>Do an OpenProcess on your injector code, and get the SeDebugPrivilege priv.</li> <li>Use OpenProcess on your target, with PROCESS_CREATE_THREAD, VM_READ / WRITE privs.</li> <li>VirtualAlloc some memory in your target process, make it PAGE_EXECUTE_READWRITE.</li> <li>Write the path and name of your hook DLL into that memory.</li> <li>Get the module handle for kernel32.</li> <li>Get the proc address of LoadLibraryW in kernel32.</li> <li>Call CreateRemoteThread on your target, giving it the address of LoadLibraryW, with the address of your hook dll string you allocated.</li> <li>WaitForSingleObject on your remote thread for it to finish loading</li> <li>Clean up</li> </ul> <p>Don't forget to repeat for each process you want to hook. Also, make sure your hook code handles thread creation / deletion for your hooked processes, so you can hook those threads as well.</p> <p>If you read that a global WH_KEYBOARD hook was a bad idea, you can begin to see why this approach may be even worse.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload