While it is not possible to directly call a function in another process, you can do it indirectly pretty easily with a few steps and the Windows API.
- Get the addresses of
LoadLibrary
and GetProcAddress
from your own process. kernel32.dll
should be loaded at the same address in every process, so you can rely on them being present in the process into which you are injecting
- Create a
struct
that will hold all the arguments you want to pass to your function that will call the functions in the other process (because CreateRemoteThread
can only pass one argument to a function, so we'll use it to pass a pointer to the structure) which at least contains member function pointers to hold the addresses of LoadLibrary
and GetProcAddress
- Allocate enough memory for a struct in the remote process via
VirtualAllocEx
, then fill it with the correct information with WriteProcessMemory
- Write a function, taking a pointer to the
struct
you wrote, that uses LoadLibrary
/GetProcAddress
to call the function you want. Remember to use the pointers to those functions in the struct you are passing the function, not the names.
- Allocate enough memory in the remote process to hold the function with
VirtualAllocEx
, making sure to pass VAX
the PAGE_EXECUTE_READWRITE
flag so that it can hold executable code
- Read and write the function's code from your process to the other process via
Read/WriteProcessMemory
- Call the function in the remote process (which is at the address returned by the
VirtualAllocEx
) by using CreateRemoteThread
.
Make sure that all the data you pass to the function is either stored inside the struct and/or resides in the remote process's address space (get it there with VirtualAllocEx
/WriteProcessMemory
.
It may look a little involved, but it's not really that complicated. If you need some help with it, feel free to ask in a comment.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…