c++ - 是否可以通过MS弯路注入(inject)多个Dll?

标签 c++ api hook detours

在 c++ 中,我想将多个 dll 挂接到一个进程。现在我使用 CreateProcesswithdll() 一次只能 Hook 一个 api。如何注入(inject)多个 dll?

我遇到这个问题是因为 MS detours 要求我们将自定义 dll 命名为与原始 dll 相同的名称,以便正确绕过 api 调用。因此,即使我可以在我创建的同一个绕行 dll 中处理不同的 api 调用,我也需要有不同的名称来 Hook 来自不同 api 的调用,这意味着我需要不同的绕行 Dll。这也意味着我需要注入(inject)不同的 DLL。我说得对吗?

如果我不清楚某事,我会尝试更清楚地展示它 :D

谢谢!

P.S:只是为了让我的问题更清晰。我需要将 1 个以上的 dll 注入(inject)到同一个进程中。 CreateProcesswithdll() 创建一个线程处于 sleep 状态的新进程。在绕道完成注入(inject)dll和设置钩子(Hook)后被唤醒。如果我想注入(inject)多个 dll,我显然不能重复调用 CreateProcesswithdll()

那我该怎么办??或者我对此的某些方面的理解是错误的吗?

最佳答案

调用 LoadLibrary() 和 FreeLibrary() 是 NOT SAFE来自 DLLMain()。来自 TFA:

"The entry-point function should perform only simple initialization or termination tasks. It must not call the LoadLibrary or LoadLibraryEx function (or a function that calls these functions), because this may create dependency loops in the DLL load order. This can result in a DLL being used before the system has executed its initialization code. Similarly, the entry-point function must not call the FreeLibrary function (or a function that calls FreeLibrary) during process termination, because this can result in a DLL being used after the system has executed its termination code."

编辑:抱歉 - 这是对 Serge 上述回答的评论。

关于c++ - 是否可以通过MS弯路注入(inject)多个Dll?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6143689/

相关文章:

c++ - 公共(public) C++ API 中的类型

android - screen.width 和 screen.height 在不同的 API/设备中有不同的值

passwords - WordPress 密码重置钩子(Hook)

c++ - 你喜欢什么 : C++ exception handling or passing a buffer to hold error messages as parameter?

c++ - 面向对象编程 , 继承 , 拷贝构造函数

ios - 如何从带有 JSON 数据的字符串中获取 UIImage

Python - 简单的 for 循环未按预期工作(使用请求模块)

rust - 从 Rust 中的回调访问全局状态

Mercurial 变更组 Hook 未触发; Linux

c++ - 将 std::pair 迭代器转换为 boost::iterator_range