在进程执行之前注入 DLL

DLL injection prior to process execution

我正在尝试使用 dll 注入拦截我的应用程序对 Direct3DCreate8 的调用,以获取 Direct3d 设备的句柄并在它投影的屏幕上绘制覆盖图。对这个 API 的调用发生在应用程序执行之后,如果我理解正确的话,会使 dll 注入 运行 process 技术变得无用,因为 API 当我注入 dll 时,调用我之后已经发生了。 这个假设是否正确?如果是,如何在进程执行期间注入 dll 以捕获所需的 API 调用?

编辑: 我知道系统范围的 api 挂钩,但很高兴听到 'local' 解决这个问题的方法。

编辑 2: 忘了说,替换应用程序文件夹中的 .dll 是没有用的,因为应用程序会查找 .dll(d3d8.dll我的情况)在 System32/SysWOW64 目录中。

聚会有点晚了,我想为您提供一个使用 Microsoft Detours 的解决方案(non-commercial 在 x86 平台上免费使用,否则会花费大量金钱)。他们有一个 DetourCreateProcessWithDllEx 功能可以满足您的需要。

引用 Detours 文档:

The process is created in a suspended state with the CREATE_SUSPENDED flag to CreateProcess. Detours then modifies the image of the application binary in the new process to include the specified DLL as its first import. Execution in the process is then resumed. When execution resumes, the Windows process loader will first load the target DLL and then any other DLLs in the application's import table, before calling the application entry point.