コード例 #1
0
        public bool UnHook()
        {
            if (Status == EHookStatus.Inactive)
            {
                return(false);
            }

            Status = EHookStatus.Inactive;

            if (_hookIsLiveTimer != null)
            {
                _hookIsLiveTimer.Dispose();
                _hookIsLiveTimer = null;
            }

            _unhookWaitEvent.WaitOne(1000);

            if (_ipcChannel != null)
            {
                ChannelServices.UnregisterChannel(_ipcChannel);
                _ipcChannel.StopListening(null);
                _ipcChannel = null;
            }

            Thread.Sleep(100);

            SetDefaults();

            return(true);
        }
コード例 #2
0
        private void OnStatusChanged(EHookStatus status)
        {
            var handler = StatusChanged;

            if (handler != null)
            {
                handler(status);
            }
        }
コード例 #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);
        }
コード例 #4
0
 public DefaultDeviceHook(Func <DataFlow, Role, string> systemDeviceId)
 {
     _systemDeviceId  = systemDeviceId;
     Status           = EHookStatus.Inactive;
     _unhookWaitEvent = new ManualResetEvent(false);
 }
コード例 #5
0
 private void HookInstalled()
 {
     Status = EHookStatus.Active;
     SetDefaults();
 }