private void ReconstructList(bool stringsOnly) { BeginUpdate(); for (int i = 0; i < _chunks.Count; i++) { object chunk = _chunks[i]; if (!(chunk is string) && stringsOnly) { continue; } string encoded = HMessage.ToString(HMessage.ConstructBody(Destination, Protocol, chunk)); Items[i].SubItems[2].Text = encoded; var value = chunk as string; if (value != null) { string encodedLength = string.Empty; if ((Destination == HDestination.Server && Protocol == HProtocol.Ancient) || Protocol == HProtocol.Modern) { ushort valueLength = (ushort)value.Length; byte[] data = Protocol == HProtocol.Ancient ? Ancient.CypherShort(valueLength) : Modern.CypherShort(valueLength); encodedLength = HMessage.ToString(data) + " | "; } Items[i].ToolTipText = string.Format("Type: String\nValue: {0}\n{1}Encoded: {2}", value, string.Format("Length: {0}{1}\n", encodedLength, value.Length), encoded); } else { Items[i].ToolTipText = Items[i].ToolTipText.Replace(Items[i].ToolTipText.GetChild("Encoded: ", '\n'), encoded); } } EndUpdate(); }
private void ExtractValuesBtn_Click(object sender, EventArgs e) { VL64Chunks.Items.Clear(); VL64ChunkTxt.Text = VL64ValueTxt.Text = string.Empty; ChunksFoundLbl.Text = "Chunks Found: 0"; string vl64String = VL64StringTxt.Text; while (vl64String.Length != 0) { int chunkLength = (vl64String[0] >> 3) & 7; if (chunkLength > 0 && chunkLength <= vl64String.Length) { string chunk = vl64String.Substring(0, chunkLength); int value = Ancient.DecypherInt(chunk); var vl64Item = new ListViewItem(new[] { chunk, value.ToString() }); VL64Chunks.Items.Add(vl64Item); vl64String = vl64String.Substring(chunkLength); } else { return; } } ChunksFoundLbl.Text = "Chunks Found: " + VL64Chunks.Items.Count; VL64Chunks.Items[0].Selected = true; VL64Chunks.Select(); }
public void ReplaceSelected(object value) { _lastHeader = 0; int index = SelectedIndices[0]; if (value.Equals(_chunks[index])) { return; } _chunks[index] = value; ListViewItem curItem = Items[index]; string type = value is string? "String" : value is int? "Integer" : "Boolean"; string encoded = HMessage.ToString(HMessage.ConstructBody(Destination, Protocol, value)); curItem.SubItems[0].Text = type; curItem.SubItems[1].Text = value.ToString(); curItem.SubItems[2].Text = encoded; string encodedLength = string.Empty; if (value is string) { if ((Destination == HDestination.Server && Protocol == HProtocol.Ancient) || Protocol == HProtocol.Modern) { ushort valueLength = (ushort)value.ToString().Length; byte[] data = Protocol == HProtocol.Ancient ? Ancient.CypherShort(valueLength) : Modern.CypherShort(valueLength); encodedLength = HMessage.ToString(data) + " | "; } } curItem.ToolTipText = string.Format("Type: {0}\nValue: {1}\n{2}Encoded: {3}", type, value, string.Format("Length: {0}{1}\n", encodedLength, value.ToString().Length), encoded); }
private void AncientDecypherShortBtn_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(AncientShortOutputTxt.Text)) { AncientShortInputTxt.Text = Ancient.DecypherShort(HMessage.ToBytes(AncientShortOutputTxt.Text)).ToString(); } }
private void DataFromClient(IAsyncResult iAr) { try { if (_clientS == null) { return; } int length = _clientS.EndReceive(iAr); if (length < 1) { Disconnect(); return; } byte[] data = ByteUtils.CopyBlock(_clientB, 0, length); #region Official Socket Check if (!_hasOfficialSocket) { bool isModern = Modern.DecypherShort(data, 4) == 4000; if (_hasOfficialSocket = (isModern || Ancient.DecypherShort(data, 3) == 206)) { ResetHost(); _htcpExt.Stop(); _htcpExt = null; Protocol = isModern ? HProtocol.Modern : HProtocol.Ancient; OnConnected(EventArgs.Empty); } else { SendToServer(data); return; } } #endregion #region Decrypt/Split if (ClientDecrypt != null) { ClientDecrypt.Parse(data); } if (_toServerS == 3 && Protocol == HProtocol.Modern) { int dLength = data.Length >= 6 ? Modern.DecypherInt(data) : 0; RequestEncrypted = (dLength != data.Length - 4); } byte[][] chunks = RequestEncrypted ? new[] { data } : ByteUtils.Split(ref _clientC, data, HDestination.Server, Protocol); #endregion foreach (byte[] chunk in chunks) { ProcessOutgoing(chunk); } ReadClientData(); } catch { Disconnect(); } }
private void AncientCypherShortBtn_Click(object sender, EventArgs e) { ushort value; if (ushort.TryParse(AncientShortInputTxt.Text, out value)) { AncientShortOutputTxt.Text = HMessage.ToString(Ancient.CypherShort(value)); } else { MessageBox.Show(NotUInt16, TanjiError, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void AncientCypherIntegerBtn_Click(object sender, EventArgs e) { int value; if (int.TryParse(AncientIntegerInputTxt.Text, out value)) { AncientIntegerOutputTxt.Text = HMessage.ToString(Ancient.CypherInt(value)); } else { MessageBox.Show(NotInt32, TanjiError, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void AppendChunk(string value) { _chunks.Add(value); string encodedLength = string.Empty; string encoded = HMessage.ToString(HMessage.ConstructBody(Destination, Protocol, value)); if (Destination == HDestination.Server || Protocol == HProtocol.Modern) { ushort valueLength = (ushort)value.Length; byte[] data = Protocol == HProtocol.Ancient ? Ancient.CypherShort(valueLength) : Modern.CypherShort(valueLength); encodedLength = HMessage.ToString(data) + " | "; } AddItemChunk("String", value, encoded, string.Format("Length: {0}{1}\n", encodedLength, value.Length)); }
//适配器设计模式有两种实现方式: 对象适配器和类适配器。 //适配器的目的是为了让对象有指定的接口。 //主要用于要求对现存(老)的对象有新的(接口)要求,使一些不兼容的类可以一起工作。 //类适配器是通过类派生实现。 //对象适配器通过聚合和组合实现。 static Int32 Main() { Console.WriteLine(MethodBase.GetCurrentMethod().DeclaringType.Namespace); ITelescope clsAdapter = new ClsAdapter(); Console.WriteLine(clsAdapter.Look()); ITelescope obAdapter = new ObAdapter(); Console.WriteLine(obAdapter.Look()); Ancient ancient = new Ancient(); obAdapter = new ObAdapter(ancient); ancient.DisplayName = "Aggregation"; Console.WriteLine(obAdapter.Look()); Console.ReadKey(); return(0); }
private void DataFromClient(IAsyncResult iAr) { try { if (ClientS == null) { return; } int Length = ClientS.EndReceive(iAr); if (Length > 0) { byte[] Data = ByteUtils.CopyBlock(ClientB, 0, Length); #region Official Socket Check if (!HasOfficialSocket) { bool IsModern = false; if (HasOfficialSocket = (Ancient.DecypherShort(Data, 3) == 206 || (IsModern = BigEndian.DecypherShort(Data, 4) == 4000))) { TCP.Stop(); TCP = null; ResetHost(); Protocol = IsModern ? HProtocols.Modern : HProtocols.Ancient; if (OnConnected != null) { OnConnected(this, EventArgs.Empty); } } else { SendToServer(Data); return; } } #endregion try { #region Decrypt/Split if (ClientDecrypt != null) { ClientDecrypt.Parse(Data); } if ((ToServerS + 1) == 4 && Protocol == HProtocols.Modern) { int DLength = BigEndian.DecypherInt(Data); RequestEncrypted = (DLength > Data.Length - 4 || DLength < 6); } byte[][] Chunks = RequestEncrypted ? new byte[1][] { Data } : Chunks = ByteUtils.Split(ref SCache, Data, HDestinations.Server, Protocol); #endregion foreach (byte[] Chunk in Chunks) { ++ToServerS; if (DataToServer == null) { SendToServer(Chunk); } else { DataToEventArgs Args = new DataToEventArgs(Chunk, HDestinations.Server, ToServerS); try { DataToServer(this, Args); } catch { SendToServer(Chunk); continue; } if (!Args.Skip) { SendToServer(Args.Packet.ToBytes()); } } if (CaptureEvents && !RequestEncrypted) { DataFromClient(Chunk); } } } catch { SendToServer(Data); } ReadClientData(); } else { Disconnect(); } } catch { Disconnect(); } }
public void AppendChunk(string Value) { HMChunks.Add(Value); string EncodedLength = string.Empty; string Encoded = HMessage.ToString(HMessage.ConstructBody(Destination, Protocol, Value)); if ((Destination == HDestinations.Server && Protocol == HProtocols.Ancient) || Protocol == HProtocols.Modern) { EncodedLength = (Protocol == HProtocols.Modern ? HMessage.ToString(BigEndian.CypherShort((ushort)Value.Length)) : HMessage.ToString(Ancient.CypherShort((ushort)Value.Length))) + " | "; } AddItemChunk("String", Value, Encoded, string.Format("Length: {0}{1}\n", EncodedLength, Value.Length)); }
private void ReconstructList(bool StringsOnly) { BeginUpdate(); for (int i = 0; i < HMChunks.Count; i++) { object Chunk = HMChunks[i]; if (!(Chunk is string) && StringsOnly) { continue; } string Encoded = HMessage.ToString(HMessage.ConstructBody(Destination, Protocol, Chunk)); Items[i].SubItems[2].Text = Encoded; if (Chunk is string) { string Value = (string)Chunk; string EncodedLength = string.Empty; if ((Destination == HDestinations.Server && Protocol == HProtocols.Ancient) || Protocol == HProtocols.Modern) { EncodedLength = (Protocol == HProtocols.Modern ? HMessage.ToString(BigEndian.CypherShort((ushort)Value.Length)) : HMessage.ToString(Ancient.CypherShort((ushort)Value.Length))) + " | "; } Items[i].ToolTipText = string.Format("Type: String\nValue: {0}\n{1}Encoded: {2}", Value, string.Format("Length: {0}{1}\n", EncodedLength, Value.Length), Encoded); } else { Items[i].ToolTipText = Items[i].ToolTipText.Replace(Items[i].ToolTipText.GetChild("Encoded: ", '\n'), Encoded); } } EndUpdate(); }
public void ReplaceSelected(object Value) { int Index = SelectedIndices[0]; if (Value.Equals(HMChunks[Index])) { return; } HMChunks[Index] = Value; ListViewItem CurItem = Items[Index]; string Type = Value is string? "String" : Value is int? "Integer" : "Boolean"; string Encoded = HMessage.ToString(HMessage.ConstructBody(Destination, Protocol, Value)); Items[Index].SubItems[0].Text = Type; Items[Index].SubItems[1].Text = Value.ToString(); Items[Index].SubItems[2].Text = Encoded; string EncodedLength = string.Empty; if (Value is string) { if ((Destination == HDestinations.Server && Protocol == HProtocols.Ancient) || Protocol == HProtocols.Modern) { EncodedLength = (Protocol == HProtocols.Modern ? HMessage.ToString(BigEndian.CypherShort((ushort)Value.ToString().Length)) : HMessage.ToString(Ancient.CypherShort((ushort)Value.ToString().Length))) + " | "; } } Items[Index].ToolTipText = string.Format("Type: {0}\nValue: {1}\n{2}Encoded: {3}", Type, Value, string.Format("Length: {0}{1}\n", EncodedLength, Value.ToString().Length), Encoded); }