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 CachedIP Decode(G2Header root) { CachedIP saved = new CachedIP(); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_Contact: saved.Contact = DhtContact.ReadPacket(child); break; case Packet_LastSeen: saved.LastSeen = DateTime.FromBinary(BitConverter.ToInt64(child.Data, child.PayloadPos)); break; case Packet_Bootstrap: saved.Bootstrap = BitConverter.ToBoolean(child.Data, child.PayloadPos); break; } } saved.Contact.LastSeen = saved.LastSeen; return(saved); }
public static OneWayInvite Decode(G2Header root) { OneWayInvite invite = new OneWayInvite(); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_UserName: invite.UserName = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_OpName: invite.OpName = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_OpAccess: invite.OpAccess = (AccessType)child.Data[child.PayloadPos]; break; case Packet_OpID: invite.OpID = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize); break; } } return(invite); }
public static CommData Decode(G2Header root) { CommData data = new CommData(); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_Service: data.Service = CompactNum.ToUInt32(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_DataType: data.DataType = CompactNum.ToUInt32(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Data: data.Data = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize); break; } } return(data); }
public static ServiceData Decode(byte[] data) { G2Header root = new G2Header(data); G2Protocol.ReadPacket(root); if (root.Name != LocationPacket.Data) { return(null); } ServiceData packet = new ServiceData(); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_Date: packet.Date = DateTime.FromBinary(BitConverter.ToInt64(child.Data, child.PayloadPos)); break; case Packet_Tag: packet.Tags.Add(PatchTag.FromBytes(child.Data, child.PayloadPos, child.PayloadSize)); break; } } return(packet); }
public static SubHashPacket Decode(G2Header root) { SubHashPacket subhash = new SubHashPacket(); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_ChunkSize: subhash.ChunkSize = BitConverter.ToInt32(child.Data, child.PayloadPos); break; case Packet_TotalCount: subhash.TotalCount = BitConverter.ToInt32(child.Data, child.PayloadPos); break; case Packet_SubHashes: subhash.SubHashes = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize); break; } } return(subhash); }
public static PostInfo Decode(G2Header root) { PostInfo info = new PostInfo(); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_Subject: info.Subject = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Format: info.Format = (TextFormat)CompactNum.ToInt32(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Quip: info.Quip = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Unique: info.Unique = BitConverter.ToInt32(child.Data, child.PayloadPos); break; } } return(info); }
public static PostFile Decode(G2Header root) { PostFile file = new PostFile(); 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: file.Name = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Size: file.Size = CompactNum.ToInt64(child.Data, child.PayloadPos, child.PayloadSize); break; } } return(file); }
public static MailDestination Decode(G2Header root) { MailDestination dest = new MailDestination(); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_Key: dest.Key = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize); dest.KeyID = Utilities.KeytoID(dest.Key); break; case Packet_CC: dest.CC = BitConverter.ToBoolean(child.Data, child.PayloadPos); break; } } return(dest); }
public static MessageData Decode(G2Header root) { MessageData msg = new MessageData(); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_Text: msg.Text = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Format: msg.Format = (TextFormat)CompactNum.ToInt32(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_TargetID: msg.TargetID = BitConverter.ToUInt64(child.Data, child.PayloadPos); break; } } return(msg); }
public static LinkData Decode(G2Header root) { LinkData link = new LinkData(); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_Project: link.Project = BitConverter.ToUInt32(child.Data, child.PayloadPos); break; case Packet_Target: link.Target = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize); link.TargetID = Utilities.KeytoID(link.Target); break; case Packet_Uplink: link.Uplink = BitConverter.ToBoolean(child.Data, child.PayloadPos); break; case Packet_Title: link.Title = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; } } return(link); }
public static ProjectData Decode(G2Header root) { ProjectData project = new ProjectData(); 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: project.ID = BitConverter.ToUInt32(child.Data, child.PayloadPos); break; case Packet_Name: project.Name = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_UserName: project.UserName = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; } } return(project); }
public static ProfileField Decode(G2Header root) { ProfileField field = new ProfileField(); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_Type: field.FieldType = (ProfileFieldType)child.Data[child.PayloadPos]; break; case Packet_Name: field.Name = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Value: field.Value = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize); break; } } return(field); }
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 WebCache Decode(G2Header root) { WebCache cache = new WebCache(); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_Address: cache.Address = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_AccessKey: cache.AccessKey = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_LastSeen: cache.LastSeen = DateTime.FromBinary(BitConverter.ToInt64(child.Data, child.PayloadPos)); break; case Packet_LastTried: cache.LastTried = DateTime.FromBinary(BitConverter.ToInt64(child.Data, child.PayloadPos)); break; } } return(cache); }
public static SignedData Decode(G2Header root) { SignedData signed = new SignedData(); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_Signature: signed.Signature = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Data: signed.Data = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize); break; } } return(signed); }
public static ShareCollection Decode(G2Header header, ulong user) { ShareCollection root = new ShareCollection(user); G2Header child = new G2Header(header.Data); while (G2Protocol.ReadNextChild(header, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_Hash: root.Hash = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Size: root.Size = CompactNum.ToInt64(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Key: root.Key = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize); break; } } return(root); }
public static LargeDataPacket Decode(G2Header root) { LargeDataPacket packet = new LargeDataPacket(root.Name, 0, null); // size packet G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } if (child.Name == Packet_Size) { packet.Size = BitConverter.ToInt32(child.Data, child.PayloadPos); } if (child.Name == Packet_Hash) { packet.Hash = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize); } } return(packet); }
public static ProxyReq Decode(G2ReceivedPacket packet) { ProxyReq pr = new ProxyReq(); G2Header child = new G2Header(packet.Root.Data); while (G2Protocol.ReadNextChild(packet.Root, child) == G2ReadResult.PACKET_GOOD) { switch (child.Name) { case Packet_Source: if (G2Protocol.ReadPayload(child)) { pr.SenderID = BitConverter.ToUInt64(child.Data, child.PayloadPos); } break; case Packet_Blocked: pr.Type = ProxyType.ClientBlocked; break; case Packet_NAT: pr.Type = ProxyType.ClientNAT; break; } } return(pr); }
public static KeyRequest Decode(G2ReceivedPacket packet) { KeyRequest kr = new KeyRequest(); G2Header child = new G2Header(packet.Root.Data); while (G2Protocol.ReadNextChild(packet.Root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } if (child.Name == Packet_Encryption) { kr.Encryption = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); } else if (child.Name == Packet_Key) { kr.Key = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize); } else if (child.Name == Packet_IV) { kr.IV = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize); } } return(kr); }
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 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 static ProxyAck Decode(G2ReceivedPacket packet) { ProxyAck pa = new ProxyAck(); G2Header child = new G2Header(packet.Root.Data); while (G2Protocol.ReadNextChild(packet.Root, child) == G2ReadResult.PACKET_GOOD) { switch (child.Name) { case Packet_Source: if (G2Protocol.ReadPayload(child)) { pa.Source = DhtSource.ReadPacket(child); } break; case Packet_Accept: pa.Accept = true; break; case Packet_Contacts: if (G2Protocol.ReadPayload(child)) { pa.ContactList.Add(DhtContact.ReadPacket(child)); } break; } } return(pa); }
public static TempData Decode(ulong target, byte[] data) { G2Header root = new G2Header(data); G2Protocol.ReadPacket(root); if (root.Name != TempPacket.Data) { return(null); } TempData temp = new TempData(target); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_TTL: temp.TTL = CompactNum.ToInt32(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Data: temp.Data = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize); break; } } return(temp); }
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 StorageFolder Decode(G2Header root) { StorageFolder folder = new StorageFolder(); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_UID: folder.UID = BitConverter.ToUInt64(child.Data, child.PayloadPos); break; case Packet_ParentUID: folder.ParentUID = BitConverter.ToUInt64(child.Data, child.PayloadPos); break; case Packet_Name: folder.Name = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Date: folder.Date = DateTime.FromBinary(BitConverter.ToInt64(child.Data, child.PayloadPos)); break; case Packet_Flags: folder.Flags = (StorageFlags)BitConverter.ToUInt16(child.Data, child.PayloadPos); break; case Packet_Note: folder.Note = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Revs: folder.Revs = child.Data[child.PayloadPos]; break; case Packet_Integrated: folder.IntegratedID = BitConverter.ToUInt64(child.Data, child.PayloadPos); break; case Packet_Scope: folder.Scope[BitConverter.ToUInt64(child.Data, child.PayloadPos)] = BitConverter.ToInt16(child.Data, child.PayloadPos + 8); break; } } return(folder); }
public static PlanItem Decode(G2Header root) { PlanItem item = new PlanItem(); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_Ident: item.Ident = BitConverter.ToInt32(child.Data, child.PayloadPos); break; case Packet_BranchUp: item.BranchUp = BitConverter.ToInt32(child.Data, child.PayloadPos); break; case Packet_Project: item.Project = BitConverter.ToUInt32(child.Data, child.PayloadPos); break; case Packet_Title: item.Title = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Start: item.Start = DateTime.FromBinary(BitConverter.ToInt64(child.Data, child.PayloadPos)); break; case Packet_End: item.End = DateTime.FromBinary(BitConverter.ToInt64(child.Data, child.PayloadPos)); break; case Packet_Desc: item.Description = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_HoursCompleted: item.HoursCompleted = BitConverter.ToInt32(child.Data, child.PayloadPos); break; case Packet_HoursTotal: item.HoursTotal = BitConverter.ToInt32(child.Data, child.PayloadPos); break; } } return(item); }
private static void DecodeKey(G2Header child, SettingsPacket settings) { G2Header key = new G2Header(child.Data); RSAParameters rsa = new RSAParameters(); while (G2Protocol.ReadNextChild(child, key) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(key)) { continue; } switch (key.Name) { case Key_D: rsa.D = Utilities.ExtractBytes(key.Data, key.PayloadPos, key.PayloadSize); break; case Key_DP: rsa.DP = Utilities.ExtractBytes(key.Data, key.PayloadPos, key.PayloadSize); break; case Key_DQ: rsa.DQ = Utilities.ExtractBytes(key.Data, key.PayloadPos, key.PayloadSize); break; case Key_Exponent: rsa.Exponent = Utilities.ExtractBytes(key.Data, key.PayloadPos, key.PayloadSize); break; case Key_InverseQ: rsa.InverseQ = Utilities.ExtractBytes(key.Data, key.PayloadPos, key.PayloadSize); break; case Key_Modulus: rsa.Modulus = Utilities.ExtractBytes(key.Data, key.PayloadPos, key.PayloadSize); break; case Key_P: rsa.P = Utilities.ExtractBytes(key.Data, key.PayloadPos, key.PayloadSize); break; case Key_Q: rsa.Q = Utilities.ExtractBytes(key.Data, key.PayloadPos, key.PayloadSize); break; } } settings.KeyPair.ImportParameters(rsa); settings.KeyPublic = rsa.Modulus; }
public static TransferPing Decode(G2Header root) { TransferPing ping = new TransferPing(); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (child.Name == Packet_RequestInfo) { ping.RequestInfo = true; } if (child.Name == Packet_RequestAlts) { ping.RequestAlts = true; } if (child.Name == Packet_BitfieldUpdated) { ping.BitfieldUpdated = true; } if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_Target: ping.Target = BitConverter.ToUInt64(child.Data, child.PayloadPos); break; case Packet_Details: ping.Details = FileDetails.Decode(Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize)); break; case Packet_Status: ping.Status = (TransferStatus)BitConverter.ToInt32(child.Data, child.PayloadPos); break; case Packet_MissingDepth: ping.MissingDepth = CompactNum.ToInt32(child.Data, child.PayloadPos, child.PayloadSize); break; } } return(ping); }
public static SearchReq Decode(G2ReceivedPacket packet) { SearchReq req = new SearchReq(); 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: req.Source = DhtSource.ReadPacket(child); break; case Packet_SearchID: req.SearchID = BitConverter.ToUInt32(child.Data, child.PayloadPos); break; case Packet_Target: req.TargetID = BitConverter.ToUInt64(child.Data, child.PayloadPos); break; case Packet_Service: req.Service = CompactNum.ToUInt32(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_DataType: req.DataType = CompactNum.ToUInt32(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Parameters: req.Parameters = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Nodes: req.Nodes = BitConverter.ToBoolean(child.Data, child.PayloadPos); break; case Packet_EndSearch: req.EndProxySearch = true; break; } } return(req); }