Esempio n. 1
0
        public void Hook()
        {
            if (IsHooked)
            {
                return;
            }

            var ri = new RemoteInterface
            {
                //Wrap the target delegate in our own delegate for reference safety
                SystemId     = (x, y) => _systemDeviceId(x, y),
                Unload       = () => !IsHooked,
                ErrorHandler = RaiseOnError
            };

            RemoteHooking.IpcCreateServer(ref _channelName, WellKnownObjectMode.Singleton, ri);

            RemoteHooking.Inject(
                _processId,
                InjectionOptions.DoNotRequireStrongName,
                typeof(IMMDeviceEnumerator).Assembly.Location,
                typeof(IMMDeviceEnumerator).Assembly.Location,
                _channelName);

            IsHooked = true;
        }
Esempio n. 2
0
 private static void ReportError(RemoteInterface remoteInterface, Exception ex)
 {
     try
     {
         remoteInterface.ReportError(RemoteHooking.GetCurrentProcessId(), ex);
     }
     catch
     {
         // ignored
     }
 }
Esempio n. 3
0
        public bool Hook(int processId)
        {
            if (Status == EHookStatus.Active || Status == EHookStatus.Pending)
            {
                return(false);
            }

            Status           = EHookStatus.Pending;
            _hookedProcessId = processId;

            _interface = new RemoteInterface
                         (
                (x, y) => _systemDeviceId(x, y),
                CanUnload,
                HookInstalled,
                OnComplete,
                OnError
                         );

            _ipcChannel = RemoteHooking.IpcCreateServer(ref _channelName, WellKnownObjectMode.Singleton, _interface);

            try
            {
                RemoteHooking.Inject(
                    processId,
                    InjectionOptions.DoNotRequireStrongName,
                    typeof(IMultimediaDeviceEnumerator).Assembly.Location,
                    typeof(IMultimediaDeviceEnumerator).Assembly.Location,
                    _channelName);

                //2000ms due time. This will give the hook 2seconds to become active
                //then it will check every 500ms
                _hookIsLiveTimer  = new Timer(HookIsLive, null, 2000, 500);
                _lastMessageCount = -1;

                _completeSignalled = false;

                return(true);
            }
            catch (Exception ex)
            {
                Status = EHookStatus.Inactive;
                Error?.Invoke(_hookedProcessId, ex);
            }


            return(false);
        }
Esempio n. 4
0
 public EntryPoint(RemoteHooking.IContext inContext, string inChannelName)
 {
     _interface = RemoteHooking.IpcConnectClient <RemoteInterface>(inChannelName);
 }