I am trying create a tool for performing DLL-Injection
by writing the the DLL in the Memory of a running process using VirtualAclloc()
API and then finding the offset of the entrypoint and passing it to the CreateRemoteThread()
API by adding the entry point offset to the base address of the VirtualAlloc
function.
As I don't have any arguments that needs to be passed to lpStartAddress
while calling CreateRemoteThread()
, I initialized lpParameter
as NULL.
LPVOID lpParameter = NULL;
...
...
thread_handle = CreateRemoteThread(process_handle, NULL, 0, (LPTHREAD_START_ROUTINE)(base_address + offset), lpParameter, 0, NULL);
While compiling the code I am getting the error :
LPVOID: Unknown Size" and the message "Expression must be a pointer to a complete object type.
Is there a way I can pass the value of lpParameter
as NULL?
base_address + offset
adds offset*sizeof *base_address
bytes to the pointer base_address
. But if the type of base_address
is LPVOID
then *base_address
has no size, so this is an error. Have a look at the section on pointer arithmetic in your C++ book.
From the context I guess you should change base_address
to be char*
instead of LPVOID
. Or you could add a cast like this (LPTHREAD_START_ROUTINE)((char*)base_address + offset)
.