Exemple #1
0
        public unsafe uint SyncMessage(ulong bufferAddr, uint bufferSize, out bool closeHandle)
        {
            var buffer = (byte *)bufferAddr;
            //new Span<byte>(buffer, (int) bufferSize).Hexdump();
            var incoming = new IncomingMessage(buffer, IsDomainObject);
            var outgoing = new OutgoingMessage(buffer, IsDomainObject, incoming);
            var ret      = 0xF601U;

            closeHandle = false;
            var target = this;

            if (IsDomainObject && incoming.DomainHandle != ThisHandle && incoming.Type == 4)
            {
                target = (IpcInterface)DomainHandles[incoming.DomainHandle];
            }
            if (!IsDomainObject || incoming.DomainCommand == 1 || incoming.Type == 2 || incoming.Type == 5)
            {
                switch (incoming.Type)
                {
                case 2:
                    closeHandle = true;
                    outgoing.Initialize(0, 0, 0);
                    ret = 0x25a0b;
                    break;

                case 4:
                case 6:
                    $"IPC command {incoming.CommandId} for {target}".Debug();
                    target.Dispatch(incoming, outgoing);
                    ret = 0;
                    break;

                case 5:
                case 7:
                    switch (incoming.CommandId)
                    {
                    case 0:                                     // ConvertSessionToDomain
                        "Converting session to domain...".Debug();
                        outgoing.Initialize(0, 0, 4);
                        IsDomainObject = true;
                        outgoing.SetData(8, ThisHandle);
                        break;

                    case 2:                                     // DuplicateSession
                        outgoing.IsDomainObject = false;
                        outgoing.Initialize(1, 0, 0);
                        outgoing.Move(0, Handle);
                        break;

                    case 3:                                     // QueryPointerBufferSize
                        outgoing.Initialize(0, 0, 4);
                        outgoing.SetData(8, 0x500U);
                        break;

                    case 4:                                     // DuplicateSessionEx
                        outgoing.IsDomainObject = false;
                        outgoing.Initialize(1, 0, 0);
                        outgoing.Move(0, Handle);
                        outgoing.ErrCode = 0;
                        break;

                    default:
                        throw new NotImplementedException($"Unknown domain command ID: {incoming.CommandId}");
                    }
                    ret = 0;
                    break;

                default:
                    throw new NotImplementedException($"Unknown message type: {incoming.Type}");
                }
            }
            else
            {
                switch (incoming.DomainCommand)
                {
                case 2:
                    DomainHandles.Remove(incoming.DomainHandle);
                    outgoing.Initialize(0, 0, 0);
                    outgoing.ErrCode = 0;
                    ret = 0;
                    break;

                default:
                    throw new NotImplementedException($"Unknown domain command ID: {incoming.DomainCommand}");
                }
            }
            if (ret == 0)
            {
                outgoing.Bake();
            }
            //new Span<byte>(buffer, (int) bufferSize).Hexdump();
            return(ret);
        }
Exemple #2
0
 public abstract void _Dispatch(IncomingMessage incoming, OutgoingMessage outgoing);