System.IO.FileNotFoundException: File or Assembly FileMonInject

Jul 25, 2009 at 6:04 PM
Edited Jul 26, 2009 at 10:48 AM

Hi everyone,

I am trying to learn about how to use EasyHook but I am not even able to run the example provided. I seem to have all files in my "Debug" (FileMonInject.dll) directory but I'm still getting exceptions about missing files.
The following is my code.

namespace Hooking
{

  public class FileMonInterface : MarshalByRefObject
  {
  public void IsInstalled(Int32 InClientPID)
  {
  Console.WriteLine("FileMon has been installed in target {0}.\r\n", InClientPID);
  }

  public void OnCreateFile(Int32 InClientPID, String[] InFileNames)
  {
  for (int i = 0; i < InFileNames.Length; i++)
  {
  Console.WriteLine(InFileNames[i]);
  }
  }

  public void ReportException(Exception InInfo)
  {
  Console.WriteLine("The target process has reported" +
  " an error:\r\n" + InInfo.ToString());
  }

  public void Ping()
  {
  }
  }

  class Hooking
  {
  static String ChannelName = null;


  public Hooking() 
  {
  hook();
  }

  static public void hook() {
  try
  {
  Config.Register(
  "A FileMon like demo application.",
  "FileMon.exe",
  "FileMonInject.dll");

  Console.WriteLine("Registered!");

  RemoteHooking.IpcCreateServer<FileMonInterface>(ref
ChannelName, WellKnownObjectMode.SingleCall);

  RemoteHooking.Inject(2776, "FileMonInject.dll", "FileMonInject.dll", ChannelName);

  Console.ReadLine();
  }
  catch (Exception ExtInfo)
  { 
  Console.WriteLine("There was an error while connecting to target:\r\n{0}", ExtInfo.ToString());
  }
  }
  }
}

So RemoteHooking.Inject(...) is failing with the following Exception.

There was an error while connecting to target:System.IO.FileNotFoundException: File or Assembly "FileMonInject, Version=1.0.0.0

I don't understand why this file is missing. It's in "Debug".

Well, I have no idea why but now I am getting something completely else.

There was an error while connecting to target:
System.Reflection.TargetInvocationException: Ein Aufrufziel hat einen Ausnahmefehler verursacht. ---> System.Runtime.Remoting.RemotingException: Es wurde versucht, eine Methode aufzurufen, die im Typ "FileMon.FileMonInterface" für ein Objekt deklariert wurde, das "Hooking.FileMonInterface" verfügbar macht.

Any idea what is wrong? Is there a method beeing called which is not in place in the injected DLL?

Cheers
Vaneo

Jul 29, 2009 at 5:01 PM

I have the same error too, easyhook can't find the DLL assembly or something:

System.IO.FileNotFoundException was unhandled
  Message="Could not load file or assembly 'GDLoaderDLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified."
  Source="mscorlib"
  FileName="GDLoaderDLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
  FusionLog="WRN: Assembly binding logging is turned OFF.\r\nTo enable assembly bind failure logging, set the registry value [HKLM\\Software\\Microsoft\\Fusion!EnableLog] (DWORD) to 1.\r\nNote: There is some performance penalty associated with assembly bind failure logging.\r\nTo turn this feature off, remove the registry value [HKLM\\Software\\Microsoft\\Fusion!EnableLog].\r\n"
  StackTrace:
       at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
       at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
       at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
       at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
       at System.Reflection.Assembly.ReflectionOnlyLoad(String assemblyString)
       at EasyHook.RemoteHooking.PrepareInjection(ManagedRemoteInfo InRemoteInfo, String& InLibraryPath_x86, String& InLibraryPath_x64, MemoryStream InPassThruStream) in E:\My Documents\Visual Studio 2008\Projects\CSharpConsole\CSharpConsole\EasyBook\RemoteHook.cs:line 523
       at EasyHook.RemoteHooking.InjectEx(Int32 InHostPID, Int32 InTargetPID, Int32 InWakeUpTID, Int32 InNativeOptions, String InLibraryPath_x86, String InLibraryPath_x64, Boolean InCanBypassWOW64, Boolean InCanCreateService, Object[] InPassThruArgs) in E:\My Documents\Visual Studio 2008\Projects\CSharpConsole\CSharpConsole\EasyBook\RemoteHook.cs:line 567
       at EasyHook.RemoteHooking.Inject(Int32 InTargetPID, String InLibraryPath_x86, String InLibraryPath_x64, Object[] InPassThruArgs) in E:\My Documents\Visual Studio 2008\Projects\CSharpConsole\CSharpConsole\EasyBook\RemoteHook.cs:line 482
       at CSharpConsole.Mainz.Main() in E:\My Documents\Visual Studio 2008\Projects\CSharpConsole\CSharpConsole\Program.cs:line 40
  InnerException:

Jul 29, 2009 at 6:49 PM
Edited Jul 30, 2009 at 4:43 AM

k nvm, just wrote my own C# injector which injects an unmanaged DLL from C# (using C#+API imports) in 195 lines of code for unicode, xp, vista, windows7, 32bit, 64bit