Пример #1
0
        /// <summary>
        /// Creates a new pipe.
        /// </summary>
        /// <param name="AnId">The pipe's Id.</param>
        /// <param name="outpoint">The outpoint of the pipe.</param>
        /// <param name="inpoint">The inpoint of the pipe.</param>
        /// <param name="BufferSize">The size of buffer to use within the pipe.</param>
        public Pipe(int AnId, PipeOutpoint outpoint, PipeInpoint inpoint, int BufferSize)
        {
            Id       = AnId;
            Outpoint = outpoint;
            Inpoint  = inpoint;

            Buffer        = new byte[BufferSize];
            DataAvailable = 0;

            ThreadsWaitingToRead  = new UInt32Queue(5, true);
            ThreadsWaitingToWrite = new UInt32Queue(5, true);
            SizesWaitingToWrite   = new UInt32Queue(5, true);
        }
Пример #2
0
        /// <summary>
        /// Attempts to create a new pipe.
        /// </summary>
        /// <param name="InProcessId">The Id of the target process which owns the inpoint.</param>
        /// <param name="OutProcessId">The Id of the target process which owns the outpoint.</param>
        /// <param name="request">A pointer to the request structure (Also used to store the result).</param>
        /// <returns>True if the request was successful. Otherwise, false.</returns>
        public static bool CreatePipe(uint InProcessId, uint OutProcessId, CreatePipeRequest *request)
        {
            // Validate inputs
            //  - Check out process exists
            //  - Check in process exists
            //  - Check request isn't null (should've been pre-allocated)
            Process InProcess = ProcessManager.GetProcessById(InProcessId);

            if (InProcess == null)
            {
                return(false);
            }
            else if (ProcessManager.GetProcessById(OutProcessId) == null)
            {
                return(false);
            }
            else if (request == null)
            {
                return(false);
            }

            // Need access to the request structure
            bool ShouldDisableKernelAccessToProcessMemory = true;

            ProcessManager.EnableKernelAccessToProcessMemory(InProcessId);

            bool OK = true;

            // Find the outpoint
            PipeOutpoint outpoint = GetOutpoint(OutProcessId, request->Class, request->Subclass);

            // Check that we actually found the outpoint
            if (outpoint == null)
            {
                OK = false;
            }

            if (OK)
            {
                // Check there are sufficient connections available
                if (outpoint.NumConnections >= outpoint.MaxConnections &&
                    outpoint.MaxConnections != PipeConstants.UnlimitedConnections)
                {
                    OK = false;
                }

                if (OK)
                {
                    // Create new inpoint
                    PipeInpoint inpoint = new PipeInpoint(InProcessId, request->Class, request->Subclass);

                    // Create new pipe
                    Pipe pipe = new Pipe(PipeIdGenerator++, outpoint, inpoint, request->BufferSize);
                    // Add new pipe to list of pipes
                    Pipes.Add(pipe);
                    // Increment number of connections to the outpoint
                    outpoint.NumConnections++;

                    // Set result information
                    request->Result.Id = pipe.Id;

                    ShouldDisableKernelAccessToProcessMemory = false;
                    ProcessManager.DisableKernelAccessToProcessMemory(InProcessId);

                    // Wake any threads (/processes) which were waiting on a pipe to be created
                    WakeWaitingThreads(outpoint, pipe.Id);
                }
            }

            if (ShouldDisableKernelAccessToProcessMemory)
            {
                ProcessManager.DisableKernelAccessToProcessMemory(InProcessId);
            }

            return(OK);
        }
Пример #3
0
        /// <summary>
        /// Creates a new pipe.
        /// </summary>
        /// <param name="AnId">The pipe's Id.</param>
        /// <param name="outpoint">The outpoint of the pipe.</param>
        /// <param name="inpoint">The inpoint of the pipe.</param>
        /// <param name="BufferSize">The size of buffer to use within the pipe.</param>
        public Pipe(int AnId, PipeOutpoint outpoint, PipeInpoint inpoint, int BufferSize)
        {
            Id = AnId;
            Outpoint = outpoint;
            Inpoint = inpoint;

            Buffer = new byte[BufferSize];
            DataAvailable = 0;

            ThreadsWaitingToRead = new UInt32Queue(5, true);
            ThreadsWaitingToWrite = new UInt32Queue(5, true);
            SizesWaitingToWrite = new UInt32Queue(5, true);
        }
Пример #4
0
        /// <summary>
        /// Attempts to create a new pipe.
        /// </summary>
        /// <param name="InProcessId">The Id of the target process which owns the inpoint.</param>
        /// <param name="OutProcessId">The Id of the target process which owns the outpoint.</param>
        /// <param name="request">A pointer to the request structure (Also used to store the result).</param>
        /// <returns>True if the request was successful. Otherwise, false.</returns>
        public static bool CreatePipe(uint InProcessId, uint OutProcessId, CreatePipeRequest* request)
        {
            // Validate inputs
            //  - Check out process exists
            //  - Check in process exists
            //  - Check request isn't null (should've been pre-allocated)
            Process InProcess = ProcessManager.GetProcessById(InProcessId);
            if (InProcess == null)
            {
                return false;
            }
            else if (ProcessManager.GetProcessById(OutProcessId) == null)
            {
                return false;
            }
            else if (request == null)
            {
                return false;
            }

            // Merge memory layouts 
            //  so we can access the request structure
            MemoryLayout OriginalMemoryLayout = SystemCallsHelpers.EnableAccessToMemoryOfProcess(InProcess);
            bool OK = true;

            // Find the outpoint
            PipeOutpoint outpoint = GetOutpoint(OutProcessId, request->Class, request->Subclass);

            // Check that we actually found the outpoint
            if (outpoint == null)
            {
                OK = false;
            }

            if (OK)
            {
                // Check there are sufficient connections available
                if (outpoint.NumConnections >= outpoint.MaxConnections &&
                    outpoint.MaxConnections != PipeConstants.UnlimitedConnections)
                {
                    OK = false;
                }

                if (OK)
                {
                    // Create new inpoint
                    PipeInpoint inpoint = new PipeInpoint(InProcessId, request->Class, request->Subclass);

                    // Create new pipe
                    Pipe pipe = new Pipe(PipeIdGenerator++, outpoint, inpoint, request->BufferSize);
                    // Add new pipe to list of pipes
                    Pipes.Add(pipe);
                    // Increment number of connections to the outpoint
                    outpoint.NumConnections++;

                    // Set result information
                    request->Result.Id = pipe.Id;

                    // Wake any threads (/processes) which were waiting on a pipe to be created
                    WakeWaitingThreads(outpoint, pipe.Id);
                }
            }

            SystemCallsHelpers.DisableAccessToMemoryOfProcess(OriginalMemoryLayout);

            return OK;
        }