예제 #1
0
        public void Start()
        {
            if(_running)
            {
                return;
            }

            Win32API.SECURITY_DESCRIPTOR sd = new Win32API.SECURITY_DESCRIPTOR();
            Win32API.SECURITY_ATTRIBUTES sa = new Win32API.SECURITY_ATTRIBUTES();

            try
            {
                _pSecurityDescriptor = Marshal.AllocHGlobal(Marshal.SizeOf(sd));
            }
            catch(System.Exception)
            {
                throw new Exception("Unable to allocate global buffer for SECURITY_DESCRIPTOR");
            }

            Marshal.StructureToPtr(sd, _pSecurityDescriptor, false);
            sa.bInheritHandle = true;
            sa.nLength = Marshal.SizeOf(sa);
            sa.lpSecurityDescriptor = _pSecurityDescriptor;

            if(!Win32API.InitializeSecurityDescriptor(_pSecurityDescriptor, Win32API.SECURITY_DESCRIPTOR_REVISION))
            {
                throw new Exception("Unable to initialise security descriptor, error code: " + Marshal.GetLastWin32Error());
            }
	
            if(!Win32API.SetSecurityDescriptorDacl(_pSecurityDescriptor, true, IntPtr.Zero, false))
            {
                throw new Exception("Unable to set security descriptor dacl, error code: " + Marshal.GetLastWin32Error());
            }

            _hAckEvent = Win32API.CreateEvent(ref sa, false, false, "DBWIN_BUFFER_READY");
            if(_hAckEvent == 0)
            {
                throw new Exception("Unable to create synchronisation object DBWIN_BUFFER_READY");
            }

            if(Marshal.GetLastWin32Error() == Win32API.ERROR_ALREADY_EXISTS)
            {
                throw new Exception("Another instance of a debug listener is already running");
            }

            _hReadyEvent = Win32API.CreateEvent(ref sa, false, false, "DBWIN_DATA_READY");
            if(_hReadyEvent == 0)
            {
                throw new Exception("Unable to create synchronisation object DBWIN_DATA_READY");
            }

            _hSharedFile = Win32API.CreateFileMapping(-1, ref sa, Win32API.PAGE_READWRITE,  0, 4096, "DBWIN_BUFFER");
            if(_hSharedFile == 0)
            {
                throw new Exception("Unable to create file mapping object DBWIN_BUFFER");
            }

            _nativePointer = Win32API.MapViewOfFile(_hSharedFile, Win32API.FILE_MAP_READ,  0, 0, SHARED_MEMORY_BUFFER_SIZE);
            if(_nativePointer == IntPtr.Zero)
            {
                throw new Exception("Unable to map shared memory");
            }

            _thread = new Thread(new ThreadStart(this.ThreadProc));
            _thread.Priority = ThreadPriority.Highest;
            _thread.Start();

            _running = true;
        }
예제 #2
0
        public void Start()
        {
            if (_running)
            {
                return;
            }

            Win32API.SECURITY_DESCRIPTOR sd = new Win32API.SECURITY_DESCRIPTOR();
            Win32API.SECURITY_ATTRIBUTES sa = new Win32API.SECURITY_ATTRIBUTES();

            try
            {
                _pSecurityDescriptor = Marshal.AllocHGlobal(Marshal.SizeOf(sd));
            }
            catch (System.Exception)
            {
                throw new Exception("Unable to allocate global buffer for SECURITY_DESCRIPTOR");
            }

            Marshal.StructureToPtr(sd, _pSecurityDescriptor, false);
            sa.bInheritHandle       = true;
            sa.nLength              = Marshal.SizeOf(sa);
            sa.lpSecurityDescriptor = _pSecurityDescriptor;

            if (!Win32API.InitializeSecurityDescriptor(_pSecurityDescriptor, Win32API.SECURITY_DESCRIPTOR_REVISION))
            {
                throw new Exception("Unable to initialise security descriptor, error code: " + Marshal.GetLastWin32Error());
            }

            if (!Win32API.SetSecurityDescriptorDacl(_pSecurityDescriptor, true, IntPtr.Zero, false))
            {
                throw new Exception("Unable to set security descriptor dacl, error code: " + Marshal.GetLastWin32Error());
            }

            _hAckEvent = Win32API.CreateEvent(ref sa, false, false, "DBWIN_BUFFER_READY");
            if (_hAckEvent == 0)
            {
                throw new Exception("Unable to create synchronisation object DBWIN_BUFFER_READY");
            }

            if (Marshal.GetLastWin32Error() == Win32API.ERROR_ALREADY_EXISTS)
            {
                throw new Exception("Another instance of a debug listener is already running");
            }

            _hReadyEvent = Win32API.CreateEvent(ref sa, false, false, "DBWIN_DATA_READY");
            if (_hReadyEvent == 0)
            {
                throw new Exception("Unable to create synchronisation object DBWIN_DATA_READY");
            }

            _hSharedFile = Win32API.CreateFileMapping(-1, ref sa, Win32API.PAGE_READWRITE, 0, 4096, "DBWIN_BUFFER");
            if (_hSharedFile == 0)
            {
                throw new Exception("Unable to create file mapping object DBWIN_BUFFER");
            }

            _nativePointer = Win32API.MapViewOfFile(_hSharedFile, Win32API.FILE_MAP_READ, 0, 0, SHARED_MEMORY_BUFFER_SIZE);
            if (_nativePointer == IntPtr.Zero)
            {
                throw new Exception("Unable to map shared memory");
            }

            _thread          = new Thread(new ThreadStart(this.ThreadProc));
            _thread.Priority = ThreadPriority.Highest;
            _thread.Start();

            _running = true;
        }