注射CLR主机到正在运行的进程 - 可能吗? [英] Injecting a CLR host into a running process - possible?

查看:210
本文介绍了注射CLR主机到正在运行的进程 - 可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这路就疯狂,我知道了。

This way lies madness, I know.

我有一个可执行文件(来源$ C ​​$ C,而我没有访问),我想通过.NET扩展。这是一个原生的可执行文件,所以我需要一个CLR主机为了做到这一点注入。我的基本思想是提供经由.NET语言脚本一样的功能(C#,例如)和提供钩子在目标可执行的脚本操作,反之亦然。

I have an executable (the source code to which I do not have access) that I would like to extend via .NET. It's a native executable, so I would need to inject a CLR host in order to do this. My basic idea is to provide scripting-like functionality via a .NET language (C#, for example) and provide hooks in the target executable for the scripts to manipulate, and vice versa.

我知道我需要使用各种技术来实现这一目标 - 注入DLL,某些运行时ASM注射液等,但我想知道的是:是什么,我说的是可能的吗?更妙的是 - ?有没有人做过这样的事情之前

I know I'll need to use various techniques to achieve this - DLL injection, some runtime ASM injection, etc., but what I'd like to know is this: is what I'm talking about possible? Better still - has anyone done something like this before?

推荐答案

您可以使用COM互操作,如果您的本机的可执行文件能够使用COM对象做到这一点。如果您注册.NET程序集互操作那么你的本机的可执行文件可以使用.NET类就像普通的COM对象,并创建第一个时,它就会旋转起来的CLR本机进程中。类似地,如果你可以公开COM对象从本机的可执行文件,那么你可以用它们从你的.NET code,如果你创建一个互操作程序集(甚至没有一个类型库,如果你只使用IDispatch接口)。

You can do this using COM interop, if your native executable is capable of using COM objects. If you register your .NET assembly for interop then your native executable can use your .NET classes just like "ordinary" COM objects, and when the first one is created it will spin up the CLR inside the native process. Similary if you can expose COM objects from the native executable then you can use them from your .NET code if you create an interop assembly (or even without a type library, if you use only IDispatch).

其基本用法简单,但我只是冰山一角 - 对于这样一个严重的项目,你需要一个严重的参考。我强烈建议 .NET和COM,在完全的互操作性指南亚当森。这是一本大书,不留下多少没说,也有很多伟大的有关设计.NET和COM类互操作干净。这也解释了如何直接主办的CLR内的本机应用程序,但该选项可能不切合实际没有访问源$ C ​​$ C。我肯定会开始与COM互操作的路线,只有主办CLR本身,如果你没有其他选择。

The basics are straightforward but I'm just scratching the surface - for a serious project like this you need a serious reference. I highly recommend .NET and COM, The Complete Interoperability Guide by Adam Nathan. It's a big book that doesn't leave much unsaid, and it also has a lot of great information on designing .NET and COM classes to interop cleanly. It also explains how to host the CLR directly inside a native app, but that option may not be practical without access to the source code. I would definitely start with the COM interop route, and only host the CLR natively if you have no other option.

这篇关于注射CLR主机到正在运行的进程 - 可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆