Exemplo n.º 1
0
 public void Deserialize(IoBuffer input, ISerializationContext context)
 {
     outfit_id      = input.GetUInt32();
     asset_id       = input.GetUInt64();
     sale_price     = input.GetInt32();
     purchase_price = input.GetInt32();
     owner_type     = input.GetEnum <VMGLOutfitOwner>();
     owner_id       = input.GetUInt32();
     outfit_type    = input.Get();
     outfit_source  = input.GetEnum <VMGLOutfitSource>();
 }
Exemplo n.º 2
0
        public object Deserialize(uint clsid, IoBuffer input, ISerializationContext serializer)
        {
            var result = new List <sbyte>();
            var count  = input.GetUInt32();

            for (int i = 0; i < count; i++)
            {
                result.Add((sbyte)input.Get());
            }
            return(ImmutableList.ToImmutableList(result));
        }
Exemplo n.º 3
0
        public object Deserialize(uint clsid, IoBuffer buffer, ISerializationContext serializer)
        {
            var result = new Dictionary <uint, bool>();
            var count  = buffer.GetUInt32();

            for (int i = 0; i < count; i++)
            {
                var key = buffer.GetUInt32();
                result.Add(key, buffer.Get() > 0);
            }
            return(result);
        }
Exemplo n.º 4
0
 public void Deserialize(IoBuffer input, ISerializationContext context)
 {
     this.User         = input.GetString(112, Encoding.ASCII);
     this.AriesVersion = input.GetString(80, Encoding.ASCII);
     this.Email        = input.GetString(40, Encoding.ASCII);
     this.Authserv     = input.GetString(84, Encoding.ASCII);
     this.Product      = input.GetUInt16();
     this.Unknown      = input.Get();
     this.ServiceIdent = input.GetString(3, Encoding.ASCII);
     this.Unknown2     = input.GetUInt16();
     this.Password     = input.GetString(32, Encoding.ASCII);
 }
Exemplo n.º 5
0
        public object Deserialize(uint clsid, IoBuffer input, ISerializationContext serializer)
        {
            var result = new List <byte>();
            var iclsid = input.GetUInt32();
            var count  = input.GetUInt32();

            for (int i = 0; i < count; i++)
            {
                result.Add(input.Get());
            }
            return(new cTSOGenericData(result.ToArray()));
        }
Exemplo n.º 6
0
        private IoBuffer InsertBytesToNewIoBuffer(IoSession session, IoBuffer buffer)
        {
            if (_insertByteProbability > _rng.Next(1000))
            {
                if (log.IsInfoEnabled)
                {
                    log.Info(buffer.GetHexDump());
                }

                // where to insert bytes ?
                int pos = _rng.Next(buffer.Remaining) - 1;

                // how many byte to insert ?
                int count = _rng.Next(_maxInsertByte - 1) + 1;

                IoBuffer newBuff = IoBuffer.Allocate(buffer.Remaining + count);
                for (int i = 0; i < pos; i++)
                {
                    newBuff.Put(buffer.Get());
                }
                for (int i = 0; i < count; i++)
                {
                    newBuff.Put((byte)(_rng.Next(256)));
                }
                while (buffer.Remaining > 0)
                {
                    newBuff.Put(buffer.Get());
                }
                newBuff.Flip();

                if (log.IsInfoEnabled)
                {
                    log.Info("Inserted " + count + " bytes.");
                    log.Info(newBuff.GetHexDump());
                }
                return(newBuff);
            }
            return(null);
        }
Exemplo n.º 7
0
        public IDecodingState Decode(IoBuffer input, IProtocolDecoderOutput output)
        {
            Boolean found    = false;
            Boolean finished = false;

            while (input.HasRemaining)
            {
                Byte b = input.Get();
                if (!_hasCR)
                {
                    if (b == CR)
                    {
                        _hasCR = true;
                    }
                    else
                    {
                        if (b == LF)
                        {
                            found = true;
                        }
                        else
                        {
                            input.Position = input.Position - 1;
                            found          = false;
                        }
                        finished = true;
                        break;
                    }
                }
                else
                {
                    if (b == LF)
                    {
                        found    = true;
                        finished = true;
                        break;
                    }

                    throw new ProtocolDecoderException("Expected LF after CR but was: " + (b & 0xff));
                }
            }

            if (finished)
            {
                _hasCR = false;
                return(FinishDecode(found, output));
            }

            return(this);
        }
Exemplo n.º 8
0
        public override void Deserialize(IoBuffer input, ISerializationContext context)
        {
            var dataLen = input.GetInt32(); //TODO: limits? 4MB is probably reasonable.
            var data    = new byte[dataLen];

            input.Get(data, 0, dataLen);
            using (var mem = new MemoryStream(data))
            {
                using (var reader = new BinaryReader(mem))
                {
                    Tuning = new DynamicTuning(reader);
                }
            }
        }
Exemplo n.º 9
0
            public override void MessageReceived(IoSession session, Object message)
            {
                IoBuffer buffer = (IoBuffer)message;

                Byte[] data = new Byte[buffer.Remaining];
                buffer.Get(data, 0, data.Length);
                Object sync = session.GetAttribute("lock");

                lock (sync)
                {
                    StringBuilder sb = session.GetAttribute <StringBuilder>("received");
                    sb.Append(Encoding.ASCII.GetString(data));
                    Monitor.PulseAll(sync);
                }
            }
Exemplo n.º 10
0
        protected override bool DoDecode(IoSession session, IoBuffer buffer, IProtocolDecoderOutput output)
        {
            if (buffer.Remaining < 8)
            {
                return(false);
            }

            /**
             * We expect aries, voltron or electron packets
             */
            var startPosition = buffer.Position;

            buffer.Order = ByteOrder.LittleEndian;
            uint packetType  = buffer.GetUInt32(); //currently unused
            uint payloadSize = buffer.GetUInt32();

            if (buffer.Remaining < payloadSize)
            {
                /** Not all here yet **/
                buffer.Position = startPosition;
                return(false);
            }

            var type = (VMNetMessageType)buffer.Get();
            var data = new List <byte>();

            for (int i = 0; i < payloadSize - 1; i++)
            {
                data.Add(buffer.Get());
            }
            var packet = new VMNetMessage(type, data.ToArray());

            output.Write(packet);

            return(true);
        }
Exemplo n.º 11
0
        public override void Deserialize(IoBuffer input, ISerializationContext context)
        {
            this.SendingAvatarID = input.GetUInt32();
            this.RequestTypeID   = input.GetUInt32();

            var bodySize  = input.GetUInt32();
            var bodyBytes = new byte[bodySize];

            input.Get(bodyBytes, 0, (int)bodySize);
            this.Body = bodyBytes;
            var bodyBuffer = IoBuffer.Wrap(bodyBytes);
            var bodyType   = bodyBuffer.GetUInt32();

            this.Body = context.ModelSerializer.Deserialize(bodyType, bodyBuffer, context);
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine(typeof(Program).FullName + " <hostname> <port>");
                return;
            }

            // Create TCP/IP connector.
            AsyncSocketConnector connector = new AsyncSocketConnector();

            // Set connect timeout.
            connector.ConnectTimeoutInMillis = 30 * 1000L;

            // Set reader idle time to 10 seconds.
            // sessionIdle(...) method will be invoked when no data is read
            // for 10 seconds.
            connector.SessionOpened += (s, e) => e.Session.Config.SetIdleTime(IdleStatus.ReaderIdle, 10);

            // Print out total number of bytes read from the remote peer.
            connector.SessionClosed += (s, e) => Console.WriteLine("Total " + e.Session.ReadBytes + " byte(s)");

            connector.SessionIdle += (s, e) =>
            {
                if (e.IdleStatus == IdleStatus.ReaderIdle)
                {
                    e.Session.Close(true);
                }
            };

            connector.MessageReceived += (s, e) =>
            {
                IoBuffer buf = (IoBuffer)e.Message;
                while (buf.HasRemaining)
                {
                    Console.Write((Char)buf.Get());
                }
            };

            // Start communication.
            IConnectFuture cf = connector.Connect(new IPEndPoint(Dns.GetHostEntry(args[0]).AddressList[3], Int32.Parse(args[1])));

            // Wait for the connection attempt to be finished.
            cf.Await();
            cf.Session.CloseFuture.Await();

            connector.Dispose();
        }
Exemplo n.º 13
0
        public MessageDecoderResult Decode(IoSession session, IoBuffer input, IProtocolDecoderOutput output)
        {
            int totalLen = input.GetInt32();
            int len      = totalLen - 4;

            if (input.Remaining < len)
            {
                return(MessageDecoderResult.NeedData);
            }
            byte[] jsonBuffer = new byte[len];
            input.Get(jsonBuffer, 0, len);
            string msg = System.Text.Encoding.UTF8.GetString(jsonBuffer);

            output.Write(msg);
            return(MessageDecoderResult.OK);
        }
Exemplo n.º 14
0
        private static FileInfo CreateLargeFile()
        {
            IoBuffer buffer = IoBuffer.Allocate(FILE_SIZE);

            for (Int32 i = 0; i < FILE_SIZE / 4; i++)
            {
                buffer.PutInt32(i);
            }
            buffer.Flip();

            String path = Path.GetTempFileName();

            Byte[] data = new Byte[buffer.Remaining];
            buffer.Get(data, 0, data.Length);
            File.WriteAllBytes(path, data);
            return(new FileInfo(path));
        }
Exemplo n.º 15
0
 public override void Deserialize(IoBuffer input, ISerializationContext context)
 {
     this.MajorVersion     = input.GetUInt16();
     this.MinorVersion     = input.GetUInt16();
     this.PointVersion     = input.GetUInt16();
     this.ArtVersion       = input.GetUInt16();
     this.Timestamp        = input.GetUInt64();
     this.NumberOfAttempts = input.Get();
     this.LastExitCode     = input.Get();
     this.LastFailureType  = input.Get();
     this.FailureCount     = input.Get();
     this.IsRunning        = input.Get();
     this.IsReLogging      = input.Get();
 }
Exemplo n.º 16
0
            public override void FilterWrite(INextFilter nextFilter, IoSession session, IWriteRequest writeRequest)
            {
                _counter++;

                IoBuffer buf = writeRequest.Message as IoBuffer;

                if (buf == null)
                {
                    throw new AssertFailedException("Wrong message type");
                }
                if (_counter == 3)
                {
                    Assert.AreEqual(1, buf.Limit);
                    Assert.AreEqual(0, buf.Get());
                }
                else
                {
                    Assert.AreEqual(10, buf.Limit);
                }
            }
Exemplo n.º 17
0
        public MessageDecoderResult Decode(IoSession session, IoBuffer input, IProtocolDecoderOutput output)
        {
            int limit    = input.Limit;
            int position = input.Position;
            var len      = input.GetInt32();
            var version  = input.Get();

            input.Position = position;
            input.Limit    = input.Position + len;
            var buffer = input.Slice();

            input.Position = input.Limit;
            input.Limit    = limit;
            var message = DoDecode(version.ToEnum <MessageVersion>(), buffer);

            if (message != null)
            {
                output.Write(message);
            }
            return(MessageDecoderResult.OK);
        }
Exemplo n.º 18
0
        public void Deserialize(IoBuffer input, ISerializationContext context)
        {
            var count = input.GetUInt32();

            Items = new List <Top100Entry>((int)count);

            for (var i = 0; i < count; i++)
            {
                var item = new Top100Entry();
                item.Rank = input.Get();

                var hasValue = input.GetBool();
                if (hasValue)
                {
                    item.TargetId   = input.GetUInt32();
                    item.TargetName = input.GetPascalVLCString();
                }

                Items.Add(item);
            }
        }
Exemplo n.º 19
0
        public override void Deserialize(IoBuffer input, ISerializationContext context)
        {
            Type = input.GetEnum <MailResponseType>();
            var numMessages = input.GetInt32();

            Messages = new MessageItem[numMessages];
            for (int j = 0; j < numMessages; j++)
            {
                var length = input.GetInt32();
                var dat    = new byte[length];
                for (int i = 0; i < length; i++)
                {
                    dat[i] = input.Get();
                }

                using (var str = new MemoryStream(dat))
                {
                    Messages[j] = new MessageItem(str);
                }
            }
        }
Exemplo n.º 20
0
        public IDecodingState Decode(IoBuffer input, IProtocolDecoderOutput output)
        {
            Int32 beginPos = input.Position;
            Int32 limit    = input.Limit;

            for (Int32 i = beginPos; i < limit; i++)
            {
                Byte b = input.Get(i);
                if (!CanSkip(b))
                {
                    input.Position = i;
                    Int32 answer = _skippedBytes;
                    _skippedBytes = 0;
                    return(FinishDecode(answer));
                }

                _skippedBytes++;
            }

            input.Position = limit;
            return(this);
        }
Exemplo n.º 21
0
        public override void Deserialize(IoBuffer input, ISerializationContext context)
        {
            Type = input.GetEnum <MailRequestType>();
            if (Type == MailRequestType.SEND)
            {
                var length = input.GetInt32();
                var dat    = new byte[length];
                for (int i = 0; i < length; i++)
                {
                    dat[i] = input.Get();
                }

                using (var str = new MemoryStream(dat))
                {
                    Item = new MessageItem(str);
                }
            }
            else
            {
                TimestampID = input.GetInt64();
            }
        }
Exemplo n.º 22
0
        private void DecodeVoltronStylePackets(IoBuffer buffer, ref uint payloadSize, IProtocolDecoderOutput output, Func <ushort, Type> typeResolver)
        {
            while (payloadSize > 0)
            {
                /** Voltron packet **/
                buffer.Order = ByteOrder.BigEndian;
                ushort type             = buffer.GetUInt16();
                uint   innerPayloadSize = buffer.GetUInt32() - 6;

                byte[] data = new byte[(int)innerPayloadSize];
                buffer.Get(data, 0, (int)innerPayloadSize);

                var packetClass = typeResolver(type);
                if (packetClass != null)
                {
                    IoBufferDeserializable packet = (IoBufferDeserializable)Activator.CreateInstance(packetClass);
                    packet.Deserialize(IoBuffer.Wrap(data), Context);
                    output.Write(packet);
                }

                payloadSize -= innerPayloadSize + 6;
            }
        }
Exemplo n.º 23
0
        public MessageDecoderResult Decodable(IoSession session, IoBuffer input)
        {
            if (input.Remaining < MIN_PACKET_LENGTH)
            {
                return(MessageDecoderResult.NeedData);
            }
            var symbol = input.GetArray(2);

            if (DataPacket.True(symbol))
            {
                input.Skip(1);
                var len = input.Get();
                input.Rewind();
                if (len > input.Remaining)
                {
                    return(MessageDecoderResult.NeedData);
                }
            }
            else if (!CtlPacket.True(symbol))
            {
                return(MessageDecoderResult.NotOK);
            }
            return(MessageDecoderResult.OK);
        }
Exemplo n.º 24
0
        public override void MessageSent(INextFilter nextFilter, IoSession session, IWriteRequest writeRequest)
        {
            IVoltronPacket voltronPacket = writeRequest.OriginalRequest.Message as IVoltronPacket;

            if (voltronPacket != null)
            {
                var voltronBuffer = IoBuffer.Allocate(512);
                voltronBuffer.Order      = ByteOrder.BigEndian;
                voltronBuffer.AutoExpand = true;
                voltronPacket.Serialize(voltronBuffer, Context);
                voltronBuffer.Flip();

                var byteArray = new byte[voltronBuffer.Remaining];
                voltronBuffer.Get(byteArray, 0, voltronBuffer.Remaining);

                PacketLogger.OnPacket(new Packet
                {
                    Data      = byteArray,
                    Type      = PacketType.VOLTRON,
                    SubType   = voltronPacket.GetPacketType().GetPacketCode(),
                    Direction = PacketDirection.OUTPUT
                });
                nextFilter.MessageSent(session, writeRequest);
                return;
            }

            IAriesPacket ariesPacket = writeRequest.OriginalRequest.Message as IAriesPacket;

            if (ariesPacket != null)
            {
                IoBuffer ariesBuffer = IoBuffer.Allocate(128);
                ariesBuffer.AutoExpand = true;
                ariesBuffer.Order      = ByteOrder.LittleEndian;
                ariesPacket.Serialize(ariesBuffer, Context);
                ariesBuffer.Flip();

                var byteArray = new byte[ariesBuffer.Remaining];
                ariesBuffer.Get(byteArray, 0, ariesBuffer.Remaining);

                PacketLogger.OnPacket(new Packet
                {
                    Data      = byteArray,
                    Type      = PacketType.ARIES,
                    SubType   = ariesPacket.GetPacketType().GetPacketCode(),
                    Direction = PacketDirection.OUTPUT
                });
                nextFilter.MessageSent(session, writeRequest);
                return;
            }

            IoBuffer buffer = writeRequest.Message as IoBuffer;

            if (buffer == null)
            {
                nextFilter.MessageSent(session, writeRequest);
                return;
            }

            TryParseAriesFrame(buffer, PacketDirection.OUTPUT);
            nextFilter.MessageSent(session, writeRequest);
        }
Exemplo n.º 25
0
        private void TryParseAriesFrame(IoBuffer buffer, PacketDirection direction)
        {
            buffer.Rewind();

            if (buffer.Remaining < 12)
            {
                return;
            }

            buffer.Order = ByteOrder.LittleEndian;
            uint packetType  = buffer.GetUInt32();
            uint timestamp   = buffer.GetUInt32();
            uint payloadSize = buffer.GetUInt32();

            if (buffer.Remaining < payloadSize)
            {
                buffer.Skip(-12);
                return;
            }

            while (payloadSize > 0)
            {
                if (packetType == 0)
                {
                    /** Voltron packet **/
                    buffer.Order = ByteOrder.BigEndian;
                    ushort voltronType        = buffer.GetUInt16();
                    uint   voltronPayloadSize = buffer.GetUInt32() - 6;

                    byte[] data = new byte[(int)voltronPayloadSize];
                    buffer.Get(data, 0, (int)voltronPayloadSize);

                    PacketLogger.OnPacket(new Packet
                    {
                        Data      = data,
                        Type      = PacketType.VOLTRON,
                        SubType   = voltronType,
                        Direction = direction
                    });

                    payloadSize -= voltronPayloadSize + 6;
                }
                else
                {
                    byte[] data = new byte[(int)payloadSize];
                    buffer.Get(data, 0, (int)payloadSize);

                    PacketLogger.OnPacket(new Packet
                    {
                        Data      = data,
                        Type      = PacketType.ARIES,
                        SubType   = packetType,
                        Direction = direction
                    });

                    payloadSize = 0;
                }
            }


            buffer.Rewind();
        }
Exemplo n.º 26
0
 public static bool GetBool(this IoBuffer buffer)
 {
     return(buffer.Get() == 1 ? true : false);
 }
Exemplo n.º 27
0
        private void DecodeNormal(Context ctx, IoSession session, IoBuffer input, IProtocolDecoderOutput output)
        {
            Int32 matchCount = ctx.MatchCount;

            // Try to find a match
            Int32 oldPos = input.Position, oldLimit = input.Limit;

            while (input.HasRemaining)
            {
                Byte b = input.Get();

                if (_delimBuf[matchCount] == b)
                {
                    matchCount++;

                    if (matchCount == _delimBuf.Length)
                    {
                        // Found a match.
                        Int32 pos = input.Position;
                        input.Limit    = pos;
                        input.Position = oldPos;

                        ctx.Append(input);

                        input.Limit    = oldLimit;
                        input.Position = pos;

                        if (ctx.OverflowPosition == 0)
                        {
                            IoBuffer buf = ctx.Buffer;
                            buf.Flip();
                            buf.Limit -= matchCount;
                            ArraySegment <Byte> bytes = buf.GetRemaining();
                            try
                            {
                                String str = _encoding.GetString(bytes.Array, bytes.Offset, bytes.Count);
                                WriteText(session, str, output);
                            }
                            finally
                            {
                                buf.Clear();
                            }
                        }
                        else
                        {
                            Int32 overflowPosition = ctx.OverflowPosition;
                            ctx.Reset();
                            throw new RecoverableProtocolDecoderException("Line is too long: " + overflowPosition);
                        }

                        oldPos     = pos;
                        matchCount = 0;
                    }
                }
                else
                {
                    input.Position = Math.Max(0, input.Position - matchCount);
                    matchCount     = 0;
                }
            }

            // Put remainder to buf.
            input.Position = oldPos;
            ctx.Append(input);
            ctx.MatchCount = matchCount;
        }
Exemplo n.º 28
0
        private void DecodeAuto(Context ctx, IoSession session, IoBuffer input, IProtocolDecoderOutput output)
        {
            Int32 matchCount = ctx.MatchCount;

            // Try to find a match
            Int32 oldPos = input.Position, oldLimit = input.Limit;

            while (input.HasRemaining)
            {
                Byte    b       = input.Get();
                Boolean matched = false;

                switch (b)
                {
                case 0x0d:     // \r
                    // Might be Mac, but we don't auto-detect Mac EOL
                    // to avoid confusion.
                    matchCount++;
                    break;

                case 0x0a:     // \n
                    // UNIX
                    matchCount++;
                    matched = true;
                    break;

                default:
                    matchCount = 0;
                    break;
                }

                if (matched)
                {
                    // Found a match.
                    Int32 pos = input.Position;
                    input.Limit    = pos;
                    input.Position = oldPos;

                    ctx.Append(input);

                    input.Limit    = oldLimit;
                    input.Position = pos;

                    if (ctx.OverflowPosition == 0)
                    {
                        IoBuffer buf = ctx.Buffer;
                        buf.Flip();
                        buf.Limit -= matchCount;
                        ArraySegment <Byte> bytes = buf.GetRemaining();
                        try
                        {
                            String str = _encoding.GetString(bytes.Array, bytes.Offset, bytes.Count);
                            WriteText(session, str, output);
                        }
                        finally
                        {
                            buf.Clear();
                        }
                    }
                    else
                    {
                        Int32 overflowPosition = ctx.OverflowPosition;
                        ctx.Reset();
                        throw new RecoverableProtocolDecoderException("Line is too long: " + overflowPosition);
                    }

                    oldPos     = pos;
                    matchCount = 0;
                }
            }

            // Put remainder to buf.
            input.Position = oldPos;
            ctx.Append(input);
            ctx.MatchCount = matchCount;
        }
Exemplo n.º 29
0
        public object Deserialize(uint clsid, IoBuffer input, ISerializationContext serializer)
        {
            var byteValue = input.Get();

            return(byteValue == 0x01 ? true : false);
        }
Exemplo n.º 30
0
        private void ManipulateIoBuffer(IoSession session, IoBuffer buffer)
        {
            if ((buffer.Remaining > 0) && (_removeByteProbability > _rng.Next(1000)))
            {
                if (log.IsInfoEnabled)
                {
                    log.Info(buffer.GetHexDump());
                }

                // where to remove bytes ?
                int pos = _rng.Next(buffer.Remaining);
                // how many byte to remove ?
                int count = _rng.Next(buffer.Remaining - pos) + 1;
                if (count == buffer.Remaining)
                {
                    count = buffer.Remaining - 1;
                }

                IoBuffer newBuff = IoBuffer.Allocate(buffer.Remaining - count);
                for (int i = 0; i < pos; i++)
                {
                    newBuff.Put(buffer.Get());
                }

                buffer.Skip(count); // hole
                while (newBuff.Remaining > 0)
                {
                    newBuff.Put(buffer.Get());
                }
                newBuff.Flip();
                // copy the new buffer in the old one
                buffer.Rewind();
                buffer.Put(newBuff);
                buffer.Flip();

                if (log.IsInfoEnabled)
                {
                    log.Info("Removed " + count + " bytes at position " + pos + ".");
                    log.Info(buffer.GetHexDump());
                }
            }
            if ((buffer.Remaining > 0) && (_changeByteProbability > _rng.Next(1000)))
            {
                if (log.IsInfoEnabled)
                {
                    log.Info(buffer.GetHexDump());
                }

                // how many byte to change ?
                int count = _rng.Next(buffer.Remaining - 1) + 1;

                byte[] values = new byte[count];
                _rng.NextBytes(values);
                for (int i = 0; i < values.Length; i++)
                {
                    int pos = _rng.Next(buffer.Remaining);
                    buffer.Put(pos, values[i]);
                }

                if (log.IsInfoEnabled)
                {
                    log.Info("Modified " + count + " bytes.");
                    log.Info(buffer.GetHexDump());
                }
            }
        }