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. } }
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)); }
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); } }
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); } }
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); }
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; }
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); } }
public byte[] GetPayload(CodedInputStream stream) { return stream.ReadRawBytes((int)this.Header.Size); }