ReadRawBytes() 공개 메소드

Read a fixed size of bytes from the input.
/// the end of the stream or the current limit was reached ///
public ReadRawBytes ( int size ) : System.ByteBuffer
size int
리턴 System.ByteBuffer
예제 #1
0
        public void ResetSizeCounter()
        {
            CodedInputStream input = CodedInputStream.CreateInstance(
                new SmallBlockInputStream(new byte[256], 8));

            input.SetSizeLimit(16);
            input.ReadRawBytes(16);

            try
            {
                input.ReadRawByte();
                Assert.Fail("Should have thrown an exception!");
            }
            catch (InvalidProtocolBufferException)
            {
                // Success.
            }

            input.ResetSizeCounter();
            input.ReadRawByte(); // No exception thrown.

            try
            {
                input.ReadRawBytes(16); // Hits limit again.
                Assert.Fail("Should have thrown an exception!");
            }
            catch (InvalidProtocolBufferException)
            {
                // Success.
            }
        }
예제 #2
0
        public void ResetSizeCounter()
        {
            CodedInputStream input = CodedInputStream.CreateInstance(
                new SmallBlockInputStream(new byte[256], 8));

            input.SetSizeLimit(16);
            input.ReadRawBytes(16);

            Assert.Throws <InvalidProtocolBufferException>(() => input.ReadRawByte());

            input.ResetSizeCounter();
            input.ReadRawByte(); // No exception thrown.

            Assert.Throws <InvalidProtocolBufferException>(() => input.ReadRawBytes(16));
        }
예제 #3
0
        public static void Identify(IClient client, CodedInputStream stream)
        {
            var header = new Header(stream);
            var payload = new byte[header.PayloadLength];
            payload = stream.ReadRawBytes((int)header.PayloadLength);

            var packet = new Packet(header, payload);
            var service = Service.GetByID(header.ServiceID);

            if (service == null)
            {
                Logger.Error("No service exists with id: 0x{0}", header.ServiceID.ToString("X2"));
                return;
            }

            var method = service.DescriptorForType.Methods[(int)header.MethodID - 1];
            var proto = service.GetRequestPrototype(method);
            var builder = proto.WeakCreateBuilderForType();

            try
            {
                var message = builder.WeakMergeFrom(CodedInputStream.CreateInstance(packet.Payload.ToArray())).WeakBuild();

                ((IServerService) service).Client = client;
                service.CallMethod(method, null, message, (msg => SendResponse(client, header.RequestID, msg)));
            }
            catch (NotImplementedException)
            {
                Logger.Debug(string.Format("Unimplemented service method: {0} {1}", service.GetType().Name, method.Name));
            }
            catch(Exception e)
            {
                Logger.DebugException(e,string.Empty);
            }
        }
예제 #4
0
        public static void Identify(CodedInputStream stream)
        {
            try
            {
                var header = new BNetHeader(stream);
                var payload = new byte[header.PayloadLength];

                payload = stream.ReadRawBytes((int) header.PayloadLength);

                var packet = new BNetPacket(header, payload);
                if (header.ServiceID == 0xfe) return;

                var service = Service.GetByID(header.ServiceID);
                if (service == null) return;

                var method =
                    service.DescriptorForType.Methods.Single(
                        m => (uint) m.Options[bnet.protocol.Rpc.MethodId.Descriptor] == header.MethodID);

                var proto = service.GetRequestPrototype(method);
                var builder = proto.WeakCreateBuilderForType();

                var message =
                    builder.WeakMergeFrom(CodedInputStream.CreateInstance(packet.Payload.ToArray())).WeakBuild();
                service.CallMethod(method, null, message, (msg => { }));
            }
            catch (UninitializedMessageException e)
            {
                Console.WriteLine("Failed to parse message: {0}", e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
예제 #5
0
        private void Handle(CodedInputStream stream)
        {
            if (first)
            {
                first = false;
                new HardcodedGsPackets(this.stream);
            }

            var size = stream.ReadInt32Reversed(); // includes size of size

            var payLoad = stream.ReadRawBytes(size - 4);
            payLoad.PrintHex();

            var opcode = payLoad[0]; // assume that opcode is 1 byte for now

            Console.WriteLine("GS: Opcode {0:X2}, payload size {1}", opcode, size - 4);
        }
예제 #6
0
        public static int Identify(IClient client, CodedInputStream stream)
        {
            var header = new Header(stream);
            var payload = new byte[header.PayloadLength];
            payload = stream.ReadRawBytes((int)header.PayloadLength);
            
            var packet = new Packet(header, payload);
            var service = ServiceManager.GetServerServiceByID(header.ServiceID);

            if(service!=null)
            {
                service.CallMethod(header.MethodID, client, packet);
                return packet.Length;
            }

            Console.WriteLine("\n===========[Unknown Crap]===========\nHeader\t: {0}Payload\t: {1}", header.Data.Dump(), payload.Dump());
            return 0;
        }
예제 #7
0
        public static void Identify(IConnection connection, CodedInputStream stream)
        {
            var header = new BNetHeader(stream);
            var payload = new byte[header.PayloadLength];
            payload = stream.ReadRawBytes((int)header.PayloadLength);

            var packet = new BNetPacket(header, payload);
            var service = Service.GetByID(header.ServiceID);

            if (service == null)
            {
                Logger.Error("No service exists with id: 0x{0}", header.ServiceID.ToString("X2"));
                return;
            }

            //var method = service.DescriptorForType.Methods[(int)header.MethodID - 1];
            //Logger.Warn("METHODID: {0}, from header: {1}", (uint)method.Options[bnet.protocol.Rpc.MethodId.Descriptor], header.MethodID);
            var method = service.DescriptorForType.Methods.Single(m => (uint)m.Options[bnet.protocol.Rpc.MethodId.Descriptor] == header.MethodID);
            var proto = service.GetRequestPrototype(method);
            var builder = proto.WeakCreateBuilderForType();

            try
            {
                var message = builder.WeakMergeFrom(CodedInputStream.CreateInstance(packet.Payload.ToArray())).WeakBuild();
                lock (service) // lock the service so that it's in-context client does not get changed..
                {
                    //Logger.Debug("service-call data:{0}", message.ToString());
                    ((IServerService) service).Client = (IBNetClient)connection.Client;
                    service.CallMethod(method, null, message, (msg => SendResponse(connection, header.RequestID, msg)));
                }
            }
            catch (NotImplementedException)
            {
                Logger.Debug("Unimplemented service method: {0} {1}", service.GetType().Name, method.Name);
            }
            catch (UninitializedMessageException e)
            {
                Logger.Debug("Failed to parse message: {0}", e.Message);
            }
            catch (Exception e)
            {
                Logger.DebugException(e, string.Empty);
            }
        }
예제 #8
0
파일: PacketIn.cs 프로젝트: wow4all/mooege
 public byte[] GetPayload(CodedInputStream stream)
 {
     return stream.ReadRawBytes((int)this.Header.Size);
 }