如何从另一个注入同一程序的.dll调用函数?

时间:2014-09-14 01:24:50

标签: c++ dll directx-9

我的问题非常重要,但我会在下面提供更多相关信息:

我有一个程序首先需要我的" false" d3d9.dll,这个DLL然后加载到我正在逆向工程的游戏中。经过一段时间和.dll加载,以及所有其他游戏依赖项,我想注入我的DLL,这将完成逆向工程的所有肮脏的工作。

我想我可以使用LoadLibrary将这个DLL加载到程序中,但是当我使用我注入的DLL来运行主要的逆向工程代码时。有没有我可以用来从d3d9.dll调用某些东西的函数?

这是因为我仍然需要访问d3d9库以使用我注入的.dll渲染我可能想要添加到屏幕上的内容。我也不想使用d3d9.dll,因为这会导致加载时间和内存更改的问题。

我也不打算在DLL中使用DllMain,这意味着我还需要从d3d9.dll调用远程函数到注入的DLL,以确保安全的进程启动。

很抱歉,如果这是一个愚蠢的问题,不过感谢您的回答。

1 个答案:

答案 0 :(得分:1)

在过去,我们使用CreateRemoteThread并使用LoadLibraryA作为lpStartAddress的地址(此地址在所有进程中都是相同的)。诀窍是使用VirtualAllocEx分配您正在注入的DLL名称,并将其用作lpParameter。有效地,您的线程使用您要注入的DLL名称调用LoadLibraryA。当Dll加载时,Dllmain被调用,你可以在附加dll的时间(DLL_PROCESS_ATTACH)中运行Dllmain中的代码。

这个link有一些关于这样做的非常好的信息。但是,这种技术依赖于Dllmain函数。如果你可以使用Dllmain,那么这个机制可能会起作用。该文章的步骤摘要概述了:

现在,我们可以通过以下步骤总结这项技术:

Retrieve a HANDLE to the remote process (OpenProces).
Allocate memory in the remote process's address space for injected data (VirtualAllocEx).
Write a copy of the initialised INJDATA structure to the allocated memory (WriteProcessMemory).
Allocate memory in the remote process's address space for injected code.
Write a copy of ThreadFunc to the allocated memory.
Start the remote copy of ThreadFunc via CreateRemoteThread.
Wait until the remote thread terminates (WaitForSingleObject).
Retrieve the result from the remote process (ReadProcessMemory or GetExitCodeThread).
Free the memory allocated in Steps #2 and #4 (VirtualFreeEx).
Close the handles retrieved in Steps #6 and #1 (CloseHandle).

我看到你对太多信息的评论。不确定我完全理解。但是,Dllmain有一些限制,例如大多数Win32 API调用都无法使用。有一些例外,其中一个是CreateThread。你有没有考虑过一个线程来做工作?如果你在Dllmain中使用CreateThread,它会被有效阻止,直到Dllmain退出。所以一旦Dllmain返回,Thread就会执行。