从通过 CreateRemoteThread 创建的线程调用函数

Call function from thread created via CreateRemoteThread

我正在研究 dll 注入,到目前为止,我设法在导致消息框显示的进程中注入了一个 dll。

即使经过大量阅读和研究,我还是不太明白的部分是如何将参数传递给 dll,或调用其中的特定函数。

dll:

extern "C" __declspec(dllexport) bool WINAPI
DllMain(HINSTANCE hInstDll, DWORD fdwReason, LPVOID lpvReserved)
{

switch (fdwReason)
{
    case DLL_PROCESS_ATTACH:
    {
        MessageBoxA(NULL, "Hello World!", "Dll says:", MB_OK);

    break;
    }

    case DLL_PROCESS_DETACH:
        break;

    case DLL_THREAD_ATTACH:
        break;

    case DLL_THREAD_DETACH:
        break;
}

return true;
}

注入:

char dllPath[] = "sampleDll.dll";

// For dll path injection.
int memAmountToAllocate = strlen(dllPath);

LPVOID dllPathAddress = VirtualAllocEx(procHandle, 0, memAmountToAllocated, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);

FARPROC loadLibraryAddr = GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");

WriteProcessMemory(procHandle, dllPathAddress, dllPath, memAmountToAllocated, 0);

// creating a thread that will call LoadLibraryA with allocMemAddress as argument
CreateRemoteThread(procHandle, 0, 0, loadLibraryAddr, dllPathAddress, 0, 0);

正如我所说,注入工作正常,即出现消息框。 但是说我在dll中有一个方法foo(LPVOID ptrToData)。如何调用 foo 函数? 我有我要在目标进程上执行的函数的地址,它是一个添加函数,所以我需要传递 x 和 y。

我可以这样调用函数

          _asm
        {
            push 0;
            push 0x7;
            mov ecx, esi;
            mov eax, 0x41367C;
            call eax;
        }

但是 push 的值必须来自注入过程。

我该怎么做?

我的问题的解决方案是使用 IPC 机制让我的主应用程序和 dll 进行通信。 我使用了命名管道。

我在 C# 中创建了管道,然后在注入 dll 时连接到管道。