private List <PacketSummary> HandleIncomingData(string str) { List <PacketSummary> packets = new List <PacketSummary>(); try { int amountRead = 0; while (amountRead < str.Length) { int recieveLength = Base64Encoding.DecodeInt32(str.Substring(amountRead, 3)); amountRead += 3; string packet = str.Substring(amountRead, recieveLength); PacketSummary summary = new PacketSummary(packet.Substring(0, 2), (packet.Substring(0, 2).Length > 0 ? packet.Substring(2) : "")); packets.Add(summary); amountRead += recieveLength; } } catch { } return(packets); }
private void btnToB64_Click(object sender, EventArgs e) { try { string value = Base64Encoding.EncodeInt32(int.Parse(txtToB64.Text), 2); txtFromB64.Text = value; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public void ProcessPacketHooking(bool showMessage) { _hookedIncomingIds.Clear(); _hookedOutgoingIds.Clear(); foreach (DataRow row in _incomingDataTable.Rows) { string headerId = row.Field <string>(0); string header = row.Field <string>(1); if (headerId != null && headerId.Length > 0) { try { _hookedIncomingIds.Add(int.Parse(headerId)); continue; } catch { } } if (header != null && header.Length > 0) { _hookedIncomingIds.Add(Base64Encoding.DecodeInt32(header)); } } foreach (DataRow row in _outgoingDataTable.Rows) { string headerId = row.Field <string>(0); string header = row.Field <string>(1); if (headerId != null && headerId.Length > 0) { try { _hookedOutgoingIds.Add(int.Parse(headerId)); continue; } catch { } } if (header != null && header.Length > 0) { _hookedOutgoingIds.Add(Base64Encoding.DecodeInt32(header)); } } if (showMessage) { MessageBox.Show("Added " + _hookedIncomingIds.Count + " incoming headers and " + _hookedOutgoingIds.Count + " outgoing headers to be hooked."); } }
private void btnSendToServer_Click(object sender, EventArgs e) { string sendPacket = AddUnreadableCharacters("@" + Base64Encoding.EncodeInt32(txtSendData.Text.Length, 2) + txtSendData.Text); byte[] data = Encoding.Default.GetBytes(sendPacket); try { frmMain.Form.TcpForwarder.DestinationState.DestinationSocket.Send(data, data.Length, SocketFlags.None); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private string BuildPacket(PacketSummary packet, string packetData, bool incoming) { string response; if (this._incoming) { response = packet.Header + packetData; response = "@" + Base64Encoding.EncodeInt32(response.Length, 2) + response; } else { response = packet.Header + packetData; } return(response); }
private void btnFromB64_Click(object sender, EventArgs e) { try { try { int value = Base64Encoding.DecodeInt32(txtFromB64.Text); txtToB64.Text = value + ""; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public PacketSummary(string Header, string Data) { this.Header = Header; this.HeaderId = Base64Encoding.DecodeInt32(this.Header); this.Data = Data; }