private void Read() { var size = (this.Stream.ReadRawByte() << 8) | this.Stream.ReadRawByte(); // header size. var headerData = this.Stream.ReadRawBytes(size); // header data. this.Header = bnet.protocol.Header.ParseFrom(headerData); // parse header. }
private StringBuilder ShortHeader(bnet.protocol.Header header) { var result = new StringBuilder("service_id: " + header.ServiceId); result.Append(header.HasMethodId ? " method_id: " + header.MethodId.ToString() : ""); result.Append(header.HasToken ? " token: " + header.Token.ToString() : ""); result.Append(header.HasObjectId ? " object_id: " + header.ObjectId.ToString() : ""); result.Append(header.HasSize ? " size: " + header.Size.ToString() : ""); result.Append(header.HasStatus ? " status: " + header.Status.ToString() : ""); result.AppendLine(); return(result); }
// Dumps the current packet onto the tee stream. // The packet has to be reconstructed according to the rules found in the respective // encoding(..) method. private void DumpPacket(string typeName, object thisObj) { // Object that does the duplication of packets. var dumper = DumpServer.Get(); // the name of the packet is retrievable in generalized form. Type packetType = thisObj.GetType(); // More packet specific details. string packetTypeString = packetType.Name; int methodID = -1; int serviceID = -1; if (packetType.Equals(typeof(BattleNetPacket))) { var packet = ((BattleNetPacket)thisObj); // Debug information bnet.protocol.Header header = packet.GetHeader(); methodID = (int)header.MethodId; serviceID = (int)header.ServiceId; byte[] packetData = DumpServer.SerializePacket(packet); dumper.SendPacket(PacketType.Battlenetpacket, PacketDirection.Incoming, 0, packetData); } else if (packetType.Equals(typeof(PegasusPacket))) { var packet = ((PegasusPacket)thisObj); // Debug information serviceID = packet.Type; byte[] packetData = DumpServer.SerializePacket(packet); dumper.SendPacket(PacketType.Pegasuspacket, PacketDirection.Incoming, 0, packetData); } else { // Returning false here would just introduce undefined behaviour HookRegistry.Panic("Unknown packet type!"); } string message = string.Format(RECEIVED_PACKET_NOTIFY, packetTypeString, serviceID, methodID); HookRegistry.Get().Internal_Log(message); }
// Dump data just as we receive it. private void DumpPacket(string typeName, object[] args) { // Object that does the duplication of packets. var dumper = DumpServer.Get(); object packetObj = args[0]; Type packetType = packetObj.GetType(); string packetTypeString = packetType.Name; int methodID = -1; int serviceID = -1; object body = null; if (packetType.Equals(typeof(BattleNetPacket))) { var packet = ((BattleNetPacket)packetObj); // Debug information bnet.protocol.Header header = packet.GetHeader(); methodID = (int)header.MethodId; serviceID = (int)header.ServiceId; body = packet.GetBody(); // Calculate the hash of the body, which is passed to analyzers. uint bodyHash = Util.GenerateHashFromObjectType(body); byte[] packetData = DumpServer.SerializePacket(packet); dumper.SendPacket(PacketType.Battlenetpacket, PacketDirection.Outgoing, bodyHash, packetData); // Test for LogonRequest body packet, since that one contains the version string var logonRequest = body as LogonRequest; if (logonRequest != null) { dumper.InitialiseHandshake(logonRequest.Version); } } else if (packetType.Equals(typeof(PegasusPacket))) { var packet = ((PegasusPacket)packetObj); // Debug information serviceID = packet.Type; body = packet.GetBody(); // Calculate the hash of the body, which is passed to analyzers. uint bodyHash = Util.GenerateHashFromObjectType(body); byte[] packetData = DumpServer.SerializePacket(packet); dumper.SendPacket(PacketType.Pegasuspacket, PacketDirection.Outgoing, bodyHash, packetData); } else { // Returning false here would just introduce undefined behaviour HookRegistry.Panic("Unknown packet type!"); } string message = string.Format(SENT_PACKET_NOTIFY, packetTypeString, serviceID, methodID, body.GetType().FullName); HookRegistry.Get().Internal_Log(message); }
public PacketIn(MooNetClient client, bnet.protocol.Header header) { this.Client = client; this.Header = header; }
public void LogOutgoing(Google.ProtocolBuffers.IMessage msg, bnet.protocol.Header header) { Log(Level.Dump, ShortHeader(header) + "[O] " + msg.AsText(), null); }
/// <summary> /// Logs an incoming moonet (protocol-buffer) packet. /// </summary> /// <param name="message">Outgoing protocol-buffer packet.</param> /// <param name="header"><see cref="bnet.protocol.Header"/> header</param> public void LogOutgoingPacket(Google.ProtocolBuffers.IMessage message, bnet.protocol.Header header) { Log(Level.PacketDump, ShortHeader(header) + "[O] " + message.AsText(), null); }
public void HandlePacket(bnet.protocol.Header header, byte[] body) { Debug.WriteLine("received packet {{ ServiceId:{0} MethodId:{1} Token:{2} Size:{3} }}", header.ServiceId, header.MethodId, header.Token, header.Size); if(header.ServiceId == 254) { HandleReponse(header.Token, body); } else { byte[] response = HandleRequest((int)header.ServiceId, (int)header.MethodId, body); if(response != null) { bnet.protocol.Header responseHeader = new bnet.protocol.Header() { ServiceId = 254, Token = header.Token, Size = (uint)response.Length }; SendPacket(responseHeader, response); } } }