public static DhtAddress ReadPacket(G2Header root) { // read payload DhtAddress address = new DhtAddress(); address.UserID = BitConverter.ToUInt64(root.Data, root.PayloadPos); address.ClientID = BitConverter.ToUInt16(root.Data, root.PayloadPos + 8); address.UdpPort = BitConverter.ToUInt16(root.Data, root.PayloadPos + 10); // read packets G2Protocol.ResetPacket(root); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_IP: address.IP = new IPAddress(Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize)); break; } } return(address); }
public void ReadChildren(G2Header rootPacket, TreeNode rootNode, Type packetType) { G2Header child = new G2Header(rootPacket.Data); while (G2Protocol.ReadNextChild(rootPacket, child) == G2ReadResult.PACKET_GOOD) { string name = child.Name.ToString(); if (packetType != null) { name += " : " + GetVariableName(packetType, child.Name); } TreeNode childNode = rootNode.Nodes.Add(name); if (G2Protocol.ReadPayload(child)) { //childNode.Nodes.Add( "Payload Ascii: " + Utilities.BytestoAscii(childPacket.Data, childPacket.PayloadPos, childPacket.PayloadSize)); childNode.Nodes.Add(new DataNode(child.Data, child.PayloadPos, child.PayloadSize)); } G2Protocol.ResetPacket(child); ReadChildren(child, childNode, null); } }
public static AudioPacket Decode(G2Header root) { AudioPacket packet = new AudioPacket(); if (G2Protocol.ReadPayload(root)) { packet.Audio = Utilities.ExtractBytes(root.Data, root.PayloadPos, root.PayloadSize); } G2Protocol.ResetPacket(root); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_FrameSize: packet.FrameSize = CompactNum.ToInt32(child.Data, child.PayloadPos, child.PayloadSize); break; } } return(packet); }
public static UserInfo Decode(G2Header root) { UserInfo user = new UserInfo(); if (G2Protocol.ReadPayload(root)) { user.Key = Utilities.ExtractBytes(root.Data, root.PayloadPos, root.PayloadSize); user.ID = Utilities.KeytoID(user.Key); } G2Protocol.ResetPacket(root); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_Name: user.Name = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; } } return(user); }
public static Ping Decode(G2ReceivedPacket packet) { Ping pi = new Ping(); if (G2Protocol.ReadPayload(packet.Root)) { pi.Ident = BitConverter.ToUInt16(packet.Root.Data, packet.Root.PayloadPos); } G2Protocol.ResetPacket(packet.Root); G2Header child = new G2Header(packet.Root.Data); while (G2Protocol.ReadNextChild(packet.Root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_Source: pi.Source = DhtSource.ReadPacket(child); break; case Packet_RemoteIP: pi.RemoteIP = new IPAddress(Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize)); break; } } return(pi); }
public static DhtSource ReadPacket(G2Header root) { // read payload DhtSource source = new DhtSource(); source.UserID = BitConverter.ToUInt64(root.Data, root.PayloadPos); source.ClientID = BitConverter.ToUInt16(root.Data, root.PayloadPos + 8); source.TcpPort = BitConverter.ToUInt16(root.Data, root.PayloadPos + 10); source.UdpPort = BitConverter.ToUInt16(root.Data, root.PayloadPos + 12); source.Firewall = (FirewallType)root.Data[root.PayloadPos + 14]; // read packets G2Protocol.ResetPacket(root); return(source); }
public static ChatWho Decode(G2Header root) { ChatWho who = new ChatWho(); G2Protocol.ResetPacket(root); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_Request: who.Request = BitConverter.ToBoolean(child.Data, child.PayloadPos); break; case Packet_RoomID: who.RoomID = BitConverter.ToUInt64(child.Data, child.PayloadPos); break; case Packet_Members: if (child.PayloadSize % 8 == 0) { int offset = 0; while (offset < child.PayloadSize) { UInt64 id = BitConverter.ToUInt64(child.Data, child.PayloadPos + offset); who.Members.Add(id); offset += 8; } } break; } } return(who); }
public static TunnelPacket Decode(G2Header root) { TunnelPacket tunnel = new TunnelPacket(); if (G2Protocol.ReadPayload(root)) { tunnel.Payload = Utilities.ExtractBytes(root.Data, root.PayloadPos, root.PayloadSize); } G2Protocol.ResetPacket(root); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_Source: tunnel.Source = TunnelAddress.FromBytes(child.Data, child.PayloadPos); break; case Packet_Target: tunnel.Target = TunnelAddress.FromBytes(child.Data, child.PayloadPos); break; case Packet_SourceServer: tunnel.SourceServer = DhtAddress.ReadPacket(child); break; case Packet_TargetServer: tunnel.TargetServer = DhtAddress.ReadPacket(child); break; } } return(tunnel); }
public static NetworkPacket Decode(G2Header root) { NetworkPacket gn = new NetworkPacket(); if (G2Protocol.ReadPayload(root)) { gn.InternalData = Utilities.ExtractBytes(root.Data, root.PayloadPos, root.PayloadSize); } G2Protocol.ResetPacket(root); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_SourceID: gn.SourceID = BitConverter.ToUInt64(child.Data, child.PayloadPos); break; case Packet_ClientID: gn.ClientID = BitConverter.ToUInt16(child.Data, child.PayloadPos); break; case Packet_To: gn.ToAddress = DhtAddress.ReadPacket(child); break; case Packet_From: gn.FromAddress = DhtAddress.ReadPacket(child); break; } } return(gn); }
public static OpBuddy Decode(G2Header root) { OpBuddy buddy = new OpBuddy(); if (G2Protocol.ReadPayload(root)) { buddy.Key = Utilities.ExtractBytes(root.Data, root.PayloadPos, root.PayloadSize); buddy.ID = Utilities.KeytoID(buddy.Key); } G2Protocol.ResetPacket(root); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (child.Name == Packet_Ignored) { buddy.Ignored = true; continue; } if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_Name: buddy.Name = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Group: buddy.Group = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; } } return(buddy); }
public static ChatText Decode(G2Header root) { ChatText chat = new ChatText(); G2Protocol.ResetPacket(root); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_ID: chat.ProjectID = BitConverter.ToUInt32(child.Data, child.PayloadPos); break; case Packet_Kind: chat.Kind = (RoomKind)BitConverter.ToUInt32(child.Data, child.PayloadPos); break; case Packet_Text: chat.Text = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Format: chat.Format = (TextFormat)CompactNum.ToInt32(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_RoomID: chat.RoomID = BitConverter.ToUInt64(child.Data, child.PayloadPos); break; } } return(chat); }
public static new DhtContact ReadPacket(G2Header root) { // read payload DhtContact contact = new DhtContact(); contact.UserID = BitConverter.ToUInt64(root.Data, root.PayloadPos); contact.ClientID = BitConverter.ToUInt16(root.Data, root.PayloadPos + 8); contact.UdpPort = BitConverter.ToUInt16(root.Data, root.PayloadPos + 10); contact.TcpPort = BitConverter.ToUInt16(root.Data, root.PayloadPos + 12); // read packets G2Protocol.ResetPacket(root); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_IP: contact.IP = new IPAddress(Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize)); break; case Packet_Server: contact.TunnelServer = DhtAddress.ReadPacket(child); break; case Packet_Client: contact.TunnelClient = TunnelAddress.FromBytes(child.Data, child.PayloadPos); break; } } return(contact); }
public static TransferData Decode(G2Header root) { TransferData td = new TransferData(); if (G2Protocol.ReadPayload(root)) { td.Block = Utilities.ExtractBytes(root.Data, root.PayloadPos, root.PayloadSize); } G2Protocol.ResetPacket(root); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_FileID: td.FileID = BitConverter.ToUInt64(child.Data, child.PayloadPos); break; case Packet_StartByte: td.StartByte = CompactNum.ToInt64(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Index: td.Index = CompactNum.ToInt32(child.Data, child.PayloadPos, child.PayloadSize); break; } } return(td); }
public static ChatInvite Decode(G2Header root) { ChatInvite invite = new ChatInvite(); G2Protocol.ResetPacket(root); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_RoomID: invite.RoomID = BitConverter.ToUInt64(child.Data, child.PayloadPos); break; case Packet_Title: invite.Title = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Host: invite.Host = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_SignedInvite: invite.SignedInvite = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize); break; } } return(invite); }
public static ChatStatus Decode(G2Header root) { ChatStatus status = new ChatStatus(); G2Protocol.ResetPacket(root); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_Active: if (child.PayloadSize % 8 == 0) { int offset = 0; while (offset < child.PayloadSize) { UInt64 id = BitConverter.ToUInt64(child.Data, child.PayloadPos + offset); status.ActiveRooms.Add(id); offset += 8; } } break; } } return(status); }
public static LocationNotify Decode(G2Header root) { LocationNotify notify = new LocationNotify(); if (G2Protocol.ReadPayload(root)) { notify.SignedLocation = Utilities.ExtractBytes(root.Data, root.PayloadPos, root.PayloadSize); } G2Protocol.ResetPacket(root); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (child.Name == Packet_GoingOffline) { notify.GoingOffline = true; continue; } if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_Timeout: notify.Timeout = CompactNum.ToInt32(child.Data, child.PayloadPos, child.PayloadSize); break; } } return(notify); }
public static UpdateInfo Decode(G2Header root) { // embedded public key of source we allow updates from RSACryptoServiceProvider UpdateSourcePublicKey = new RSACryptoServiceProvider(); //UpdateSourcePublicKey.FromXmlString("<RSAKeyValue><Modulus>pTmHLSxyM9TDOM4tZzI5dld9JvPsHlHC/M5i0+Qtjid1DiefGAVubPToEhK9Im4Ohy37h5Ax6J3vt2pxLG4rnIDuKBJt70YH6W6XrJewQ6tid5BvVnNEzPUOIJHGMpOnyi0VjPpzZzWgp4JK6Yuh6LtsYwCyqIIJIBt9iQ/9XN0=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>"); UpdateInfo info = new UpdateInfo(); if (G2Protocol.ReadPayload(root)) { info.Embedded = Utilities.ExtractBytes(root.Data, root.PayloadPos, root.PayloadSize); } G2Protocol.ResetPacket(root); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (G2Protocol.ReadPayload(child)) { if (child.Name == Packet_Signature) { info.Signature = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize); } } } // verify signature byte[] pubKey = UpdateSourcePublicKey.ExportParameters(false).Modulus; if (!Utilities.CheckSignedData(pubKey, info.Embedded, info.Signature)) { return(null); } root = new G2Header(info.Embedded); if (!G2Protocol.ReadPacket(root)) { return(null); } child = new G2Header(info.Embedded); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_Name: info.Name = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Key: info.Key = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Size: info.Size = CompactNum.ToInt64(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Hash: info.Hash = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Notes: info.Notes = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Beginning: info.Beginning = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_DottedVersion: info.DottedVersion = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_SequentialVersion: info.SequentialVersion = CompactNum.ToUInt32(child.Data, child.PayloadPos, child.PayloadSize); break; } } info.TempName = Utilities.ToBase64String(info.Hash); return(info); }
private void ListViewPackets_Click(object sender, System.EventArgs e) { if (ListViewPackets.SelectedItems.Count == 0) { return; } PacketListViewItem selected = (PacketListViewItem)ListViewPackets.SelectedItems[0]; // build tree TreeViewPacket.Nodes.Clear(); G2Header root = new G2Header(selected.LogEntry.Data); if (G2Protocol.ReadPacket(root)) { if (selected.LogEntry.Protocol == TransportProtocol.Rudp) { string name = root.Name.ToString() + " : " + GetVariableName(typeof(CommPacket), root.Name); TreeNode rootNode = TreeViewPacket.Nodes.Add(name); if (G2Protocol.ReadPayload(root)) { rootNode.Nodes.Add(new DataNode(root.Data, root.PayloadPos, root.PayloadSize)); } G2Protocol.ResetPacket(root); // get type Type packetType = null; switch (root.Name) { case CommPacket.SessionRequest: packetType = typeof(SessionRequest); break; case CommPacket.SessionAck: packetType = typeof(SessionAck); break; case CommPacket.KeyRequest: packetType = typeof(KeyRequest); break; case CommPacket.KeyAck: packetType = typeof(KeyAck); break; case CommPacket.Data: packetType = typeof(CommData); break; case CommPacket.Close: packetType = typeof(CommClose); break; } ReadChildren(root, rootNode, packetType); } else { string name = root.Name.ToString() + " : " + GetVariableName(typeof(RootPacket), root.Name); TreeNode rootNode = TreeViewPacket.Nodes.Add(name); DataNode payloadNode = null; if (G2Protocol.ReadPayload(root)) { payloadNode = new DataNode(root.Data, root.PayloadPos, root.PayloadSize); rootNode.Nodes.Add(payloadNode); } G2Protocol.ResetPacket(root); if (root.Name == RootPacket.Comm) { ReadChildren(root, rootNode, typeof(RudpPacket)); } if (root.Name == RootPacket.Tunnel) { ReadChildren(root, rootNode, typeof(RudpPacket)); } if (root.Name == RootPacket.Network) { ReadChildren(root, rootNode, typeof(NetworkPacket)); G2Header payloadRoot = new G2Header(payloadNode.Data); if (payloadNode.Data != null && G2Protocol.ReadPacket(payloadRoot)) { name = payloadRoot.Name.ToString() + " : " + GetVariableName(typeof(NetworkPacket), payloadRoot.Name); TreeNode netNode = payloadNode.Nodes.Add(name); if (G2Protocol.ReadPayload(payloadRoot)) { netNode.Nodes.Add(new DataNode(payloadRoot.Data, payloadRoot.PayloadPos, payloadRoot.PayloadSize)); } G2Protocol.ResetPacket(payloadRoot); Type packetType = null; switch (payloadRoot.Name) { case NetworkPacket.SearchRequest: packetType = typeof(SearchReq); break; case NetworkPacket.SearchAck: packetType = typeof(SearchAck); break; case NetworkPacket.StoreRequest: packetType = typeof(StoreReq); break; case NetworkPacket.Ping: packetType = typeof(Ping); break; case NetworkPacket.Pong: packetType = typeof(Pong); break; case NetworkPacket.Bye: packetType = typeof(Bye); break; case NetworkPacket.ProxyRequest: packetType = typeof(ProxyReq); break; case NetworkPacket.ProxyAck: packetType = typeof(ProxyAck); break; case NetworkPacket.CrawlRequest: packetType = typeof(CrawlRequest); break; case NetworkPacket.CrawlAck: packetType = typeof(CrawlAck); break; } ReadChildren(payloadRoot, netNode, packetType); } } } } /*G2Header rootPacket = new G2Header(selected.LogEntry.Data); * * int start = 0; * int size = selected.LogEntry.Data.Length; * if(G2ReadResult.PACKET_GOOD == Protocol.ReadNextPacket(rootPacket, ref start, ref size) ) * { * TreeNode rootNode = TreeViewPacket.Nodes.Add( TrimName(rootPacket.Name.ToString()) ); * * if(G2Protocol.ReadPayload(rootPacket)) * { * //rootNode.Nodes.Add( Utilities.BytestoAscii(rootPacket.Data, rootPacket.PayloadPos, rootPacket.PayloadSize)); * rootNode.Nodes.Add( Utilities.BytestoHex(rootPacket.Data, rootPacket.PayloadPos, rootPacket.PayloadSize, true)); * } * * G2Protocol.ResetPacket(rootPacket); * * ReadChildren(rootPacket, rootNode, null); * }*/ TreeViewPacket.ExpandAll(); }
public static RudpPacket Decode(G2Header root) { RudpPacket gc = new RudpPacket(); if (G2Protocol.ReadPayload(root)) { gc.Payload = Utilities.ExtractBytes(root.Data, root.PayloadPos, root.PayloadSize); } G2Protocol.ResetPacket(root); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_SenderDht: gc.SenderID = BitConverter.ToUInt64(child.Data, child.PayloadPos); break; case Packet_SenderClient: gc.SenderClient = BitConverter.ToUInt16(child.Data, child.PayloadPos); break; case Packet_TargetDht: gc.TargetID = BitConverter.ToUInt64(child.Data, child.PayloadPos); break; case Packet_TargetClient: gc.TargetClient = BitConverter.ToUInt16(child.Data, child.PayloadPos); break; case Packet_Type: gc.PacketType = child.Data[child.PayloadPos]; break; case Packet_ID: gc.PeerID = BitConverter.ToUInt16(child.Data, child.PayloadPos); break; case Packet_Seq: gc.Sequence = (byte)child.Data[child.PayloadPos]; break; case Packet_Ident: gc.Ident = BitConverter.ToUInt32(child.Data, child.PayloadPos); break; case Packet_To: gc.ToAddress = DhtAddress.ReadPacket(child); break; case Packet_Proxy: gc.RemoteProxy = DhtAddress.ReadPacket(child); break; } } return(gc); }
public static TransferPong Decode(G2Header root) { TransferPong pong = new TransferPong(); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (child.Name == Packet_Error) { pong.Error = true; } if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_FileID: pong.FileID = BitConverter.ToUInt64(child.Data, child.PayloadPos); break; case Packet_Timeout: pong.Timeout = CompactNum.ToInt32(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Status: pong.Status = (TransferStatus)CompactNum.ToInt32(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_InternalSize: pong.InternalSize = CompactNum.ToInt64(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_ChunkSize: pong.ChunkSize = CompactNum.ToInt32(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_BitCount: pong.BitCount = CompactNum.ToInt32(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_AltClient: DhtClient client = DhtClient.FromBytes(child.Data, child.PayloadPos); pong.Alts[client] = new List <DhtAddress>(); G2Protocol.ResetPacket(child); G2Header sub = new G2Header(child.Data); while (G2Protocol.ReadNextChild(child, sub) == G2ReadResult.PACKET_GOOD) { if (G2Protocol.ReadPayload(sub)) { if (sub.Name == Packet_AltAddress) { pong.Alts[client].Add(DhtAddress.ReadPacket(sub)); } } } break; } } return(pong); }