private void toolStripButton2_Click(object sender, EventArgs e) { try { string s = richTextBox2.Text.Trim(); while (s.Contains(" ")) { s = s.Replace(" ", ""); } if ((s.Length % 2) != 0) { return; } byte[] data = ToBuff(s); uint sizeBefore = (uint)data.Length; byte[] buff = Helper.Compress(data); byte count = (byte)(sizeBefore / buff.Length); if ((sizeBefore % buff.Length) != 0) { count++; } MemoryStream m = new MemoryStream(); m.WriteByte(count); m.Write(buff, 0, buff.Length); data = Helper.Encrypt("CD&ML", m.ToArray()); StringBuilder sb = new StringBuilder(); foreach (byte b in data) { sb.Append(b.ToString("X2")); } richTextBox1.Text = sb.ToString(); } catch { richTextBox1.Text = "ERROR"; } }
public byte[] toBuffer() { MemoryStream m = new MemoryStream(); Helper.WriteU8(m, m_oSourceVPort.toByte()); Helper.WriteU8(m, m_oDestinationVPort.toByte()); byte typeFlag = (byte)type; foreach (PACKETFLAG flag in flags) { typeFlag |= (byte)((byte)flag << 3); } Helper.WriteU8(m, typeFlag); Helper.WriteU8(m, m_bySessionID); Helper.WriteU32(m, m_uiSignature); Helper.WriteU16(m, uiSeqId); if (type == PACKETTYPE.SYN || type == PACKETTYPE.CONNECT) { Helper.WriteU32(m, m_uiConnectionSignature); } if (type == PACKETTYPE.DATA) { Helper.WriteU8(m, m_byPartNumber); } byte[] tmpPayload = payload; if (tmpPayload != null && tmpPayload.Length > 0) { if (usesCompression) { uint sizeBefore = (uint)tmpPayload.Length; byte[] buff = Helper.Compress(tmpPayload); byte count = (byte)(sizeBefore / buff.Length); if ((sizeBefore % buff.Length) != 0) { count++; } MemoryStream m2 = new MemoryStream(); m2.WriteByte(count); m2.Write(buff, 0, buff.Length); tmpPayload = m2.ToArray(); tmpPayload = Helper.Encrypt(Global.keyDATA, tmpPayload); } else { MemoryStream m2 = new MemoryStream(); m2.WriteByte(0); m2.Write(tmpPayload, 0, tmpPayload.Length); tmpPayload = m2.ToArray(); tmpPayload = Helper.Encrypt(Global.keyDATA, tmpPayload); } } if (flags.Contains(PACKETFLAG.FLAG_HAS_SIZE)) { Helper.WriteU16(m, (ushort)tmpPayload.Length); } m.Write(tmpPayload, 0, tmpPayload.Length); return(AddCheckSum(m.ToArray())); }
public byte[] toBuffer() { MemoryStream m = new MemoryStream(); m.Write(sessionKey, 0, 16); Helper.WriteU32(m, serverPID); Helper.WriteU32(m, (uint)ticket.Length); m.Write(ticket, 0, ticket.Length); byte[] buff = m.ToArray(); byte[] key = Helper.DeriveKey(userPID); buff = Helper.Encrypt(key, buff); byte[] hmac = Helper.MakeHMAC(key, buff); m = new MemoryStream(); m.Write(buff, 0, buff.Length); m.Write(hmac, 0, hmac.Length); return(m.ToArray()); }
private void toolStripButton4_Click(object sender, EventArgs e) { try { string s = richTextBox2.Text.Trim(); while (s.Contains(" ")) { s = s.Replace(" ", ""); } if ((s.Length % 2) != 0) { return; } byte[] data = ToBuff(s); data = Helper.Encrypt("CD&ML", data); StringBuilder sb = new StringBuilder(); foreach (byte b in data) { sb.Append(b.ToString("X2")); } richTextBox1.Text = sb.ToString(); } catch { richTextBox1.Text = "ERROR"; } }