CodeGuru
Earthweb Search
Login Forums Wireless Jars Gamelan Developer.com
CodeGuru Navigation
RSS Feeds

RSSAll

RSSVC++/C++

RSS.NET/C#

RSSVB

See more EarthWeb Network feeds

follow us on Twitter

Member Sign In
User ID:
Password:
Remember Me:
Forgot Password?
Not a member?
Click here for more information and to register.

Become a Marketplace Partner

jobs.internet.com

internet.commerce
Partners & Affiliates
















Home >> Visual C++ / C++ >> Windows Programming >> DLL


Injecting a DLL into Another Process's Address Space
Rating: none

Zoltan Csizmadia (view profile)
September 21, 2000

This sample shows how to use the CreateRemoteThread() function to load a DLL to another process memory.

To use the CreateRemoteThread() you have to follow these steps:

  1. Allocate a page of memory in target for the code, via VirtualAllocEx()
  2. Allocate a page of memory in target for the parameters, via VirtualAllocEx()
  3. Write the name of the DLL (and other parameters) into the target memory (#2), via WriteProcessMemory()
  4. Write the code into the target memory (#1), via WriteProcessMemory()
  5. Call CreateRemoteThread(), passing it the address of the function (#2) and the allocated parameter memory (#2)
  6. Wait for finishing the remote thread
  7. Read back the return values from the target memory
  8. Free the memories with VirtualFreeEx() (#1, #2)

(continued)




Before you want to allocate memory in the target address space you have to have and enable the SeDebugPrivilege.

The attached example:

Usage: LOADDLL [/L] [/U] processID dllPath [functionName]
       /L              Loads the module
       /U              Unloads the module
       processID       Process ID
       dllPath         Path for the module
       functionName    Called function. Mustn't have parameters

Examples:

Loads and then unloads the module for process #728
LOADDLL /L /U 728 your.dll

Loads, calls the fnTest and unloads the module for process #728
LOADDLL /L /U 728 your.dll fnTest

Call the fnTest function. The module has to be loaded to the process
LOADDLL 728 your.dll fnTest

Unload the "your.dll" from process #728
LOADDLL /U 728 your.dll

Breaks the remote process
LOADDLL 728 kernel32.dll DebugBreak

Acknowledgements

This article is based on
Felix Kasza's CreateRemoteThread() example. Thanks Felix!

Downloads

Download source - 46 Kb

Tools:
Add www.codeguru.com to your favorites
Add www.codeguru.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed







RATE THIS ARTICLE:   Excellent  Very Good  Average  Below Average  Poor  

(You must be signed in to rank an article. Not a member? Click here to register)

Latest Comments:
Working in VistaX64? - GalaticDan (09/30/2009)
Can this method be used to copy a Bitmap in another process? - Legacy CodeGuru (11/17/2003)
Windows XP - Legacy CodeGuru (08/28/2003)
Excellent sample - Legacy CodeGuru (05/19/2003)
Retrive a control's object From other application - Legacy CodeGuru (03/10/2002)

View All Comments
Add a Comment:
Title:
Comment:
Pre-Formatted: Check this if you want the text to display with the formatting as typed (good for source code)



(You must be signed in to comment on an article. Not a member? Click here to register)

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs