private InjectedModule InjectLibraryInternal(string libraryPath) { // It's hardly "injecting" when we're in-process, but for the sake of keeping the API uniform we'll go with it. // All we have to do is call LoadLibrary on the local process and wrap it in an InjectedModule type. var lib = SafeLibraryHandle.LoadLibraryEx(libraryPath); if (lib == null) { throw new InjectionException("LoadLibrary failed in local process!"); } var module = Process.GetCurrentProcess().Modules.Cast <ProcessModule>().FirstOrDefault(s => s.FileName == libraryPath); if (module == null) { throw new InjectionException("The injected library couldn't be found in the Process' module list!"); } return(new InjectedModule(module, _memory)); }