DLL注入需要完成的步骤以及所需要的API函数:
1.在要注入的进程中为DLL代码分配所需占据的空间---->VirtualAllocEx
LPVOID WINAPI VirtualAllocEx(
__in HANDLE hProcess,
__in_opt LPVOID lpAddress,
__in SIZE_T dwSize,
__in DWORD flAllocationType,
__in DWORD flProtect);
2.在要注入的进程中为要注入的DLL所需的参数分配空间---->VirtualAllocEx
3.把DLL的名字和代码写入要注入进程的存储空间---->WriteProcessMemory
BOOL WriteProcessMemory(
HANDLE hProcess, // handle to process whose memory is written to
LPVOID lpBaseAddress, // address to start writing to
LPVOID lpBuffer, // pointer to buffer to write data to
DWORD nSize, // number of bytes to write
LPDWORD lpNumberOfBytesWritten // actual number of bytes written
);
4.在要注入进程中创建线程---->CreateRemoteThread
HANDLE CreateRemoteThread(
HANDLE hProcess, // handle to process to create thread in
LPSECURITY_ATTRIBUTES lpThreadAttributes, // pointer to security attributes
DWorD dwStackSize, // initial thread stack size, in bytes
LPTHREAD_START_ROUTINE lpStartAddress, // pointer to thread function
LPVOID lpParameter, // argument for new thread
DWorD dwCreationFlags, // creation flags
LPDWorD lpThreadId // pointer to returned thread identifier
);
5.最后就是清除所消耗的资源了