Three Ways to Inject Your Code into Another Process

Contents

Introduction

Three Ways to Inject Your Code into Another Process

Several password spy tutorials have been posted to The Code Project, but all of them rely on Windows hooks. Is there any other way to make such a utility? Yes, there is. But first, let me review the problem briefly, just to make sure we're all on the same page.

To "read" the contents of any control - either belonging to your application or not - you generally send theWM_GETTEXTmessage to it. This also applies to edit controls, except in one special case. If the edit control belongs to another process and theES_PASSWORDstyle is set, this approach fails. Only the process that "owns" the password control can get its contents viaWM_GETTEXT. So, our problem reduces to the following: How to get

Three Ways to Inject Your Code into Another ProcessCollapse
::SendMessage( hPwdEdit, WM_GETTEXT, nMaxChars, psBuffer );

executed in the address space of another process.

In general, there are three possibilities to solve this problem:

  1. Put your code into a DLL; then, map the DLL to the remote process viawindows hooks.
  2. Put your code into a DLL and map the DLL to the remote process using theCreateRemoteThread & LoadLibrarytechnique.
  3. Instead of writing a separate DLL, copy your code to the remote process directly - viaWriteProcessMemory- and start its execution withCreateRemoteThread. A detailed description of this technique can be foundhere.