Posted about 1 year ago, by Specific

What is the purpose of injecting a DLL into a process?

Injecting a Dynamic link library (Dll) into a process can be used for many things - that is, it's up to the programmer what they want to do.  Dll injection is most normally used to hook API in the process, however, it's often used in game hacking to redirect method calls within the game or application to the programmer's custom functions. 

In this tutorial I will show only one method of injecting a dll into a running process.  This tutorial is a little advanced for the average programmer - this is something most colleges do not teach.  If you do not have the fundamentals of creating cpp applications and little knowledge of Win32 API you should not read any further.

We start this tutorial by including couple basic libraries and defining constant variables that we will be using:

Next we create a method that will house the code to inject our dll into the process.  This method will return a boolean result and take two parameters: DWORD : ProcID, String dll.  *Note that we have not set a namespace for the string library that we'll be using, we'll specify that in the declaration of method.

And now the fun begins

First we need to find the address of the LoadLibrary api, luckily it is loaded in the same address for every process.


Then adjust token privileges to open system processes


Open the process with all access


Allocate memory to hold the path to the DLL file in the process's memory


Write the path to the DLL file at the location in process we just created


Now we create a remote thread that begins at the LoadLibrary function and is passed our memory pointer that holds path to dll file.  If the purpose of this dll injection is for a game hack, a lot of anti cheat software detect creation of remote threads.


And wait for the thread to finish.


Almost done. . . Time to clean up.  Free the memory created in the target process, and release it's handle.

Put this all together and you and inject your own dll into a target process.

Author Info Comment
iPromise
Posted about 1 year ago.
User Avatar

Programmed this in Visual Basic .NET and i'm having trouble..

 

Function:

 

Module:

 

Made a DLL called "MyDLL 2.DLL"

 

In it, I put:

 

Then, in my form I put this:

 

 

 

Press the button, no luck! Dont get a "Injected" msgbox, some help will be nice :)