1

我一直在尝试从一个“注入器”程序切换我不拥有的程序的 Dll 目录,该程序假设切换 Dll 加载目录以加载修改或点击的 Dll。

这是功能:

void AddDirectory(HANDLE Handle, const char* DllPath)
{
    void *Function, *String;
    Function = (void*)(SetDllDirectoryA);
    String = (void*)VirtualAllocEx(Handle, NULL, strlen(DllPath), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
    CreateRemoteThread(Handle, NULL, NULL, (LPTHREAD_START_ROUTINE)Function, (void*)String, NULL, NULL);
}

我无法弄清楚为什么这不起作用?

4

1 回答 1

1

感谢 Ben Volgt 在上面提供的帮助!

编辑:注意,正如 Ben Volgt 所说,您必须确定您可以及时拦截该过程,以便在加载 DLL 之前更改目录。因此,这并不总是有效,尽管在我的情况下它确实有效。

如果有人想拦截加载位置的进程,可以在这里找到代码:

    void AddDirectory(HANDLE Handle, const char* DllPath)
{
    if (!Handle)
    {
        //Error Message or Redirect
    }

    LPVOID AddDllDirAddr = (LPVOID)GetProcAddress(GetModuleHandleA("kernel32.dll"), "SetDllDirectoryA");
    if (!AddDllDirAddr)
    {
        //Error Message or Redirect
    }

    LPVOID Alloc = VirtualAllocEx(Handle, NULL, strlen(DllPath), MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
    if (!Alloc)
    {
        //Error Message or Redirect
    }

    WriteProcessMemory(Handle, Alloc, DllPath, strlen(DllPath), NULL);
    HANDLE Thread = CreateRemoteThread(Handle, NULL, NULL, (LPTHREAD_START_ROUTINE)AddDllDirAddr, Alloc, 0, NULL);
    if (!Thread)
    {
        //Error Message or Redirect
    }

    WaitForSingleObject(Thread, INFINITE);
    VirtualFreeEx(Handle, Alloc, strlen(DllPath), MEM_RELEASE);
    CloseHandle(Thread);
    CloseHandle(Handle);
}
于 2015-01-24T14:31:29.820 回答