Control which Runtime the .NET DLL gets injected into

May 14, 2013 at 5:58 PM
I'm new to Easy Hook. Love it so far.

I need to inject a .Net DLL into an existing running application that is either running on a CLR 2.0 or a CLR 4.0.

When I inject my DLL currently into a .NET app running on CLR 2.0, it spins up a CLR 4.0 instance and installs my .Net DLL into the new CLR instance. This means I cannot access the application running on the 2.0 CLR since 2.0 and 4.0 CLRs don't talk to each other.

My current DLL is compiled with .NET 3.5 as its target Framework.

Is there a way to control which CLR my DLL will get injected into?

May 14, 2013 at 7:16 PM
I think I found the answer.... In Entry.cpp I found the following comment:
            It is possible to create a ICLRRuntimeInfo object based on the runtime required by InInfo->UserLibrary
            however this requires that the assembly containing the "EasyHook.InjectionLoader" (usually EasyHook.dll)
            must be targetting the same framework version as the assembly(ies) to be injected. This is because the
            first CLR assembly injected into the target process in this case is usually the EasyHook.dll assembly.

            So instead we are providing a specific .NET version (for now v4.0.30319), this will need to be
            passed as a parameter in the future.
        // TODO: add documentation about what happens when injecting into a managed process where the .NET framework is already loaded
        LPCWSTR frameworkVersion = L"v4.0.30319"; // TODO: .NET version string to be passed in "InInfo"

I changed to LPCWSTR frameworkVersion = L"v2.0.50727";

and bool UseCorBindToRuntime = true;

and now it injects into 2.0 CLR every time.

So it looks like a feature that is not implemented yet.