0

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

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
Lee Englestone
  • 4,545
  • 13
  • 51
  • 85

1 Answers1

1

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.

Fge
  • 2,971
  • 4
  • 23
  • 37
  • Can you please point me in the direction of some simple c# examples of hooking managed assemblies into an unmanaged executable? – Lee Englestone Dec 05 '10 at 03:06
  • @Lee: My shared interface: http://pastebin.com/C5SRVqtB . Must be put into your real application. My class that handles to hooking in of my application into the unmanaged: http://pastebin.com/4FnM25bS. To actually hook an instance I've to call the HookInstance method of course (with the process id as parameter). – Fge Dec 05 '10 at 09:52