如何将 Easyhook 与非托管可执行文件一起使用

发布于 2024-10-04 14:16:18 字数 883 浏览 4 评论 0原文

我正在尝试在 c# 中进行一些挂钩(我宁愿不使用 Detours 或 c++),所以我一直在使用 EasyHook。

https://easyhook.github.io/

但是,当我这样做时,

Config.Register( "This description can be anything.", @"SomePathToAnExecutable.exe", "MyInjectionDll.dll");

我收到错误:

连接时出错 目标: System.BadImageFormatException:无法 加载给定的程序集 [SomePathToAnExecutable.exe] 为 反思。

这是一个有效的 NET 程序集吗? ---> System.BadImageFormatException:可以 不加载文件或程序集 [SomePathToAnExecutable.exe] 或其中之一 它的依赖项。该模块是 预计包含一个程序集 明显。

问题 1)我认为 SomePathToAnExecutable 是您想要挂钩的进程是否正确?

问题 2)可执行文件必须是托管代码吗?

我也在 codeplex 项目网站上询问过,但没有回复。

http://easyhook.codeplex.com/Thread/View.aspx?ThreadId= 235616

I am trying to do some hooking in c# (I'd rather not use Detours or c++) so i have been using EasyHook.

https://easyhook.github.io/

However When i'm doing this

Config.Register( "This description can be anything.", @"SomePathToAnExecutable.exe", "MyInjectionDll.dll");

I get the error:

There was an error while connecting to
target:
System.BadImageFormatException: Unable
to load given assembly
[SomePathToAnExecutable.exe] for
reflection.

Is this a valid NET assembly? --->
System.BadImageFormatException: Could
not load file or assembly
[SomePathToAnExecutable.exe] or one of
its dependencies. The module was
expected to contain an assembly
manifest.

Question 1) Am I right in thinking that SomePathToAnExecutable is the process that you want to hook into???

Question 2) Does the executable have to be managed code then??

I've also asked at on the codeplex project site, but no response.

http://easyhook.codeplex.com/Thread/View.aspx?ThreadId=235616

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半城柳色半声笛 2024-10-11 14:16:18

答案 1) 否。Config.Register 使用

        Config.Register("MyHook",
            Path.Combine(startupPath, "HookManager.dll"), 
            Path.Combine(startupPath, "NetworkIncomingHook.dll"),
            Path.Combine(startupPath, "NetworkOutgoingHook.dll")
        );

HookManager.dll 包含我用来创建 IPCServer 的接口(并且所有消息都从挂钩函数发送到该接口)。 NetworkIncomingHook.dll 和 NetworkOutgoingHook.dll 都是我注入到程序中的 dll。这是由RemoteHooking.Inject 完成的。

2) 不。您也可以挂钩非托管程序集。

Answer 1) No. Config.Register registers managed assemblies with the GAC. Thus you register all assemblies participating from your code. This includes the dll you want to inject and the assembly that provides the common interface for the IPCServer. For my it looks like this one for example:

        Config.Register("MyHook",
            Path.Combine(startupPath, "HookManager.dll"), 
            Path.Combine(startupPath, "NetworkIncomingHook.dll"),
            Path.Combine(startupPath, "NetworkOutgoingHook.dll")
        );

The HookManager.dll contains the interface I use to create the IPCServer (and where all messages are send to from the hooked functions). The NetworkIncomingHook.dll and NetworkOutgoingHook.dll are both dlls I inject into my programm. This is done by RemoteHooking.Inject.

2) No. You can hook unmanaged assemblies aswell.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文