How to execute code in another process?

One of the methods to run your code in another process(remote process)(so-called code injection) is using Windows Hook. The process is as follows:

  1. You write your code in a function called hook function.
  2. You put the function in a dll.
  3. You write another exe program to install the hook function using SetWindowsHookEx. The prototype of SetWindowsHookEx is:
    HHOOK WINAPI SetWindowsHookEx(
    _In_ int       idHook,
    _In_ HOOKPROC  lpfn,
    _In_ HINSTANCE hMod,
    _In_ DWORD     dwThreadId
    );
    So, typically, you will need to load the dll to get the dll instance(hMod) and the address of your hook function(lpfn). dwThreadId is the thread you want to hook. If dwThreadId is 0, all threads are hooked.
  4. When a message(generated by the system, the user input, or any program including yours) is sent to the hooked thread(may be in a remote process), your dll will be mapped to the target process.
  5. Your hook function in that dll will be called by the system and your code is then executed.

Here is a good article about this kind of code injection technique.

Did you like this?
Tip admin with Cryptocurrency

Donate Bitcoin to admin

Scan to Donate Bitcoin to admin
Scan the QR code or copy the address below into your wallet to send some bitcoin:

Donate Bitcoin Cash to admin

Scan to Donate Bitcoin Cash to admin
Scan the QR code or copy the address below into your wallet to send bitcoin:

Donate Ethereum to admin

Scan to Donate Ethereum to admin
Scan the QR code or copy the address below into your wallet to send some Ether:

Donate Litecoin to admin

Scan to Donate Litecoin to admin
Scan the QR code or copy the address below into your wallet to send some Litecoin:

Donate Monero to admin

Scan to Donate Monero to admin
Scan the QR code or copy the address below into your wallet to send some Monero:

Donate ZCash to admin

Scan to Donate ZCash to admin
Scan the QR code or copy the address below into your wallet to send some ZCash:
Posted in

Comments are closed, but trackbacks and pingbacks are open.