2009-04-16 05:14:07 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Net;
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
|
using System.Data;
|
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
using System.Threading;
|
|
|
|
|
|
using GridProxy;
|
|
|
|
|
|
using OpenMetaverse;
|
|
|
|
|
|
using OpenMetaverse.Packets;
|
|
|
|
|
|
using OpenMetaverse.StructuredData;
|
|
|
|
|
|
using OpenMetaverse.Interfaces;
|
|
|
|
|
|
using OpenMetaverse.Messages.Linden;
|
|
|
|
|
|
using Nwc.XmlRpc;
|
|
|
|
|
|
using System.Xml;
|
|
|
|
|
|
|
|
|
|
|
|
namespace WinGridProxy
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class Form1 : Form
|
|
|
|
|
|
{
|
2009-04-17 10:02:16 +00:00
|
|
|
|
private static SettingsStore Store = new SettingsStore();
|
|
|
|
|
|
|
2009-04-16 05:14:07 +00:00
|
|
|
|
private static bool IsProxyRunning = false;
|
|
|
|
|
|
|
|
|
|
|
|
ProxyManager proxy;
|
|
|
|
|
|
private Assembly openmvAssembly;
|
|
|
|
|
|
|
|
|
|
|
|
private int PacketCounter = 0;
|
2009-04-17 00:48:52 +00:00
|
|
|
|
|
|
|
|
|
|
private int CapsInCounter = 0;
|
|
|
|
|
|
private int CapsInBytes = 0;
|
|
|
|
|
|
private int CapsOutCounter = 0;
|
|
|
|
|
|
private int CapsOutBytes = 0;
|
|
|
|
|
|
|
|
|
|
|
|
private int PacketsInCounter = 0;
|
|
|
|
|
|
private int PacketsInBytes;
|
|
|
|
|
|
private int PacketsOutCounter = 0;
|
|
|
|
|
|
private int PacketsOutBytes;
|
2009-04-16 05:14:07 +00:00
|
|
|
|
|
|
|
|
|
|
public Form1()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
|
|
ProxyManager.OnPacketLog += new ProxyManager.PacketLogHandler(ProxyManager_OnPacketLog);
|
|
|
|
|
|
ProxyManager.OnMessageLog += new ProxyManager.MessageLogHandler(ProxyManager_OnMessageLog);
|
|
|
|
|
|
ProxyManager.OnLoginResponse += new ProxyManager.LoginLogHandler(ProxyManager_OnLoginResponse);
|
|
|
|
|
|
openmvAssembly = Assembly.Load("OpenMetaverse");
|
|
|
|
|
|
if (openmvAssembly == null) throw new Exception("Assembly load exception");
|
|
|
|
|
|
|
2009-04-17 10:02:16 +00:00
|
|
|
|
//Store.DeserializeFromFile("settings.osd");
|
2009-04-16 05:14:07 +00:00
|
|
|
|
|
2009-04-17 10:02:16 +00:00
|
|
|
|
//InitProxyFilters();
|
|
|
|
|
|
|
2009-04-16 05:14:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void InitProxyFilters()
|
|
|
|
|
|
{
|
2009-04-17 10:02:16 +00:00
|
|
|
|
Store.DeserializeFromFile("settings.osd");
|
|
|
|
|
|
|
2009-04-16 08:19:45 +00:00
|
|
|
|
Type packetTypeType = typeof(PacketType);
|
|
|
|
|
|
System.Reflection.MemberInfo[] packetTypes = packetTypeType.GetMembers();
|
2009-04-17 10:02:16 +00:00
|
|
|
|
checkedListBoxFiltersPackets.BeginUpdate();
|
2009-04-16 08:19:45 +00:00
|
|
|
|
for (int i = 0; i < packetTypes.Length; i++)
|
2009-04-16 05:14:07 +00:00
|
|
|
|
{
|
2009-04-16 08:19:45 +00:00
|
|
|
|
if (packetTypes[i].MemberType == System.Reflection.MemberTypes.Field
|
|
|
|
|
|
&& packetTypes[i].DeclaringType == packetTypeType)
|
2009-04-16 05:14:07 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
2009-04-16 08:19:45 +00:00
|
|
|
|
string name = packetTypes[i].Name;
|
|
|
|
|
|
|
|
|
|
|
|
PacketType pType;
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
pType = packetTypeFromName(name);
|
2009-04-17 10:02:16 +00:00
|
|
|
|
checkedListBoxFiltersPackets.Items.Add(name, false);
|
2009-04-16 08:19:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception)
|
|
|
|
|
|
{
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2009-04-16 05:14:07 +00:00
|
|
|
|
}
|
2009-04-17 10:02:16 +00:00
|
|
|
|
checkedListBoxFiltersPackets.Sorted = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// load from previous stored settings
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
checkedListBoxFiltersPackets.EndUpdate();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (KeyValuePair<string, bool> kvp in Store.MessageSessions)
|
|
|
|
|
|
{
|
|
|
|
|
|
checkedListBoxFiltersMessages.Items.Add(kvp.Key, kvp.Value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2009-04-16 05:14:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static PacketType packetTypeFromName(string name)
|
|
|
|
|
|
{
|
|
|
|
|
|
Type packetTypeType = typeof(PacketType);
|
|
|
|
|
|
System.Reflection.FieldInfo f = packetTypeType.GetField(name);
|
|
|
|
|
|
if (f == null) throw new ArgumentException("Bad packet type");
|
|
|
|
|
|
|
|
|
|
|
|
return (PacketType)Enum.ToObject(packetTypeType, (int)f.GetValue(packetTypeType));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ProxyManager_OnPacketLog(Packet packet, Direction direction, IPEndPoint endpoint)
|
|
|
|
|
|
{
|
|
|
|
|
|
PacketAnalyzer_OnPacketLog(packet, direction, endpoint);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ProxyManager_OnLoginResponse(object request, Direction direction)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (this.InvokeRequired)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.BeginInvoke(new MethodInvoker(delegate()
|
|
|
|
|
|
{
|
|
|
|
|
|
ProxyManager_OnLoginResponse(request, direction);
|
|
|
|
|
|
}));
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
PacketCounter++;
|
2009-04-16 08:19:45 +00:00
|
|
|
|
|
2009-04-17 00:48:52 +00:00
|
|
|
|
string t = (request is XmlRpcRequest) ? "Login Request" : "Login Response";
|
|
|
|
|
|
string l = request.ToString().Length.ToString();
|
|
|
|
|
|
string[] s = { PacketCounter.ToString(), "HTTPS", t, l, textBoxLoginURL.Text };
|
2009-04-16 05:14:07 +00:00
|
|
|
|
ListViewItem session = new ListViewItem(s);
|
|
|
|
|
|
session.Tag = request;
|
2009-04-17 00:48:52 +00:00
|
|
|
|
session.ImageIndex = (request is XmlRpcRequest) ? 1 : 0;
|
2009-04-16 05:14:07 +00:00
|
|
|
|
|
|
|
|
|
|
listViewSessions.Items.Add(session);
|
|
|
|
|
|
|
2009-04-16 08:19:45 +00:00
|
|
|
|
// TODO: this needs to refresh the Capabilities filters
|
2009-04-16 05:14:07 +00:00
|
|
|
|
if (request is XmlRpcResponse)
|
|
|
|
|
|
{
|
|
|
|
|
|
XmlRpcResponse r = (XmlRpcResponse)request;
|
|
|
|
|
|
if (!r.IsFault)
|
|
|
|
|
|
{
|
|
|
|
|
|
Hashtable ht = (Hashtable)r.Value;
|
|
|
|
|
|
string st = String.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
if (ht.ContainsKey("login"))
|
|
|
|
|
|
{
|
|
|
|
|
|
if ((string)ht["login"] == "true")
|
|
|
|
|
|
{
|
2009-04-16 08:19:45 +00:00
|
|
|
|
|
2009-04-16 05:14:07 +00:00
|
|
|
|
Console.WriteLine("Refresh");
|
|
|
|
|
|
buttonRefreshCapsList_Click(this, new EventArgs());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void PacketAnalyzer_OnPacketLog(Packet packet, Direction direction, IPEndPoint endpoint)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (this.InvokeRequired)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.BeginInvoke(new MethodInvoker(delegate()
|
|
|
|
|
|
{
|
|
|
|
|
|
PacketAnalyzer_OnPacketLog(packet, direction, endpoint);
|
|
|
|
|
|
}));
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
PacketCounter++;
|
2009-04-17 00:48:52 +00:00
|
|
|
|
|
|
|
|
|
|
string[] s = { PacketCounter.ToString(), "UDP", packet.Type.ToString(), packet.Length.ToString(), endpoint.ToString() };
|
2009-04-16 05:14:07 +00:00
|
|
|
|
ListViewItem session = new ListViewItem(s);
|
2009-04-17 00:48:52 +00:00
|
|
|
|
|
2009-04-16 05:14:07 +00:00
|
|
|
|
session.Tag = packet;
|
|
|
|
|
|
|
2009-04-17 00:48:52 +00:00
|
|
|
|
if (direction == Direction.Incoming)
|
|
|
|
|
|
{
|
|
|
|
|
|
session.ImageIndex = 0;
|
|
|
|
|
|
PacketsInCounter++;
|
|
|
|
|
|
PacketsInBytes += packet.Length;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
session.ImageIndex = 1;
|
|
|
|
|
|
PacketsOutCounter++;
|
|
|
|
|
|
PacketsOutBytes += packet.Length;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2009-04-16 05:14:07 +00:00
|
|
|
|
listViewSessions.Items.Add(session);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ProxyManager_OnMessageLog(CapsRequest req, CapsStage stage)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (this.InvokeRequired)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.BeginInvoke(new MethodInvoker(delegate()
|
|
|
|
|
|
{
|
|
|
|
|
|
ProxyManager_OnMessageLog(req, stage);
|
|
|
|
|
|
}));
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
PacketCounter++;
|
2009-04-17 00:48:52 +00:00
|
|
|
|
|
|
|
|
|
|
string size = (stage == CapsStage.Request) ? req.Request.ToString().Length.ToString() : req.Response.ToString().Length.ToString();
|
|
|
|
|
|
string[] s = { PacketCounter.ToString(), "CAPS", req.Info.CapType, size, req.Info.URI };
|
2009-04-16 05:14:07 +00:00
|
|
|
|
ListViewItem session = new ListViewItem(s);
|
2009-04-17 00:48:52 +00:00
|
|
|
|
|
2009-04-16 05:14:07 +00:00
|
|
|
|
session.Tag = req;
|
|
|
|
|
|
|
2009-04-17 00:48:52 +00:00
|
|
|
|
if (stage == CapsStage.Request)
|
|
|
|
|
|
{
|
|
|
|
|
|
CapsOutCounter++;
|
|
|
|
|
|
CapsOutBytes += req.Request.ToString().Length;
|
|
|
|
|
|
session.ImageIndex = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
CapsInCounter++;
|
|
|
|
|
|
CapsInBytes += req.Response.ToString().Length;
|
|
|
|
|
|
session.ImageIndex = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2009-04-16 05:14:07 +00:00
|
|
|
|
listViewSessions.Items.Add(session);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2009-04-17 00:48:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
2009-04-16 05:14:07 +00:00
|
|
|
|
if (button1.Text.StartsWith("Start") && IsProxyRunning.Equals(false))
|
|
|
|
|
|
{
|
2009-04-17 10:02:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
2009-04-16 08:19:45 +00:00
|
|
|
|
proxy = new ProxyManager(textBoxProxyPort.Text, textBoxProxyListenIP.Text, textBoxLoginURL.Text);
|
2009-04-16 05:14:07 +00:00
|
|
|
|
// start the proxy
|
|
|
|
|
|
textBoxProxyListenIP.Enabled = textBoxProxyPort.Enabled = textBoxLoginURL.Enabled = false;
|
2009-04-17 10:02:16 +00:00
|
|
|
|
|
|
|
|
|
|
InitProxyFilters();
|
|
|
|
|
|
|
2009-04-16 05:14:07 +00:00
|
|
|
|
proxy.Start();
|
2009-04-17 00:48:52 +00:00
|
|
|
|
grpUDPFilters.Enabled = grpCapsFilters.Enabled = IsProxyRunning = true;
|
2009-04-16 05:14:07 +00:00
|
|
|
|
button1.Text = "Stop Proxy";
|
2009-04-16 16:25:47 +00:00
|
|
|
|
|
2009-04-17 00:48:52 +00:00
|
|
|
|
if (!timer1.Enabled)
|
|
|
|
|
|
timer1.Enabled = true;
|
2009-04-17 10:02:16 +00:00
|
|
|
|
proxy.AddCapsDelegate("ParcelProperties", true);
|
|
|
|
|
|
proxy.AddCapsDelegate("AgentGroupDataUpdate", true);
|
2009-04-16 05:14:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if (button1.Text.StartsWith("Stop") && IsProxyRunning.Equals(true))
|
|
|
|
|
|
{
|
|
|
|
|
|
// stop the proxy
|
|
|
|
|
|
proxy.Stop();
|
2009-04-17 00:48:52 +00:00
|
|
|
|
grpUDPFilters.Enabled = grpCapsFilters.Enabled = IsProxyRunning = false;
|
2009-04-16 05:14:07 +00:00
|
|
|
|
button1.Text = "Start Proxy";
|
|
|
|
|
|
textBoxProxyListenIP.Enabled = textBoxProxyPort.Enabled = textBoxLoginURL.Enabled = true;
|
2009-04-16 16:25:47 +00:00
|
|
|
|
|
2009-04-17 00:48:52 +00:00
|
|
|
|
if (timer1.Enabled)
|
|
|
|
|
|
timer1.Enabled = false;
|
2009-04-16 05:14:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void checkBox1_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2009-04-17 10:02:16 +00:00
|
|
|
|
for (int i = 0; i < checkedListBoxFiltersPackets.Items.Count; i++)
|
2009-04-16 05:14:07 +00:00
|
|
|
|
{
|
2009-04-17 10:02:16 +00:00
|
|
|
|
checkedListBoxFiltersPackets.SetItemChecked(i, checkBox1.Checked);
|
2009-04-16 05:14:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (e.CurrentValue != e.NewValue)
|
|
|
|
|
|
{
|
2009-04-17 10:02:16 +00:00
|
|
|
|
proxy.AddUDPDelegate(packetTypeFromName(checkedListBoxFiltersPackets.Items[e.Index].ToString()), (e.NewValue == CheckState.Checked));
|
2009-04-16 05:14:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void buttonRefreshCapsList_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2009-04-17 10:02:16 +00:00
|
|
|
|
OSDMap map = new OSDMap(1);
|
|
|
|
|
|
|
|
|
|
|
|
OSDArray capsArray = new OSDArray();
|
2009-04-16 08:19:45 +00:00
|
|
|
|
foreach (KeyValuePair<string, CapInfo> kvp in proxy.GetCapabilities())
|
2009-04-16 05:14:07 +00:00
|
|
|
|
{
|
2009-04-17 10:02:16 +00:00
|
|
|
|
OSDMap cap = new OSDMap(1);
|
|
|
|
|
|
cap["capability"] = OSD.FromString(kvp.Value.CapType);
|
|
|
|
|
|
cap["Enabled"] = OSD.FromBoolean(true);
|
|
|
|
|
|
capsArray.Add(cap);
|
|
|
|
|
|
checkedListBoxFiltersMessages.BeginUpdate();
|
|
|
|
|
|
if (!checkedListBoxFiltersMessages.Items.Contains(kvp.Value.CapType))
|
2009-04-16 08:19:45 +00:00
|
|
|
|
{
|
2009-04-17 10:02:16 +00:00
|
|
|
|
checkedListBoxFiltersMessages.Items.Add(kvp.Value.CapType);
|
2009-04-16 08:19:45 +00:00
|
|
|
|
}
|
2009-04-17 10:02:16 +00:00
|
|
|
|
checkedListBoxFiltersMessages.Sorted = true;
|
|
|
|
|
|
checkedListBoxFiltersMessages.EndUpdate();
|
2009-04-16 05:14:07 +00:00
|
|
|
|
}
|
2009-04-17 10:02:16 +00:00
|
|
|
|
map["Capabilities"] = capsArray;
|
|
|
|
|
|
|
|
|
|
|
|
System.IO.File.WriteAllText("capabilities.osd", map.ToString());
|
|
|
|
|
|
|
2009-04-16 05:14:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void checkBoxCheckallCaps_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2009-04-17 10:02:16 +00:00
|
|
|
|
for (int i = 0; i < checkedListBoxFiltersMessages.Items.Count; i++)
|
2009-04-16 05:14:07 +00:00
|
|
|
|
{
|
2009-04-17 10:02:16 +00:00
|
|
|
|
checkedListBoxFiltersMessages.SetItemChecked(i, checkBox2.Checked);
|
2009-04-16 05:14:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void checkedListBoxCaps_ItemCheck(object sender, ItemCheckEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (e.CurrentValue != e.NewValue)
|
|
|
|
|
|
{
|
2009-04-17 10:02:16 +00:00
|
|
|
|
proxy.AddCapsDelegate(checkedListBoxFiltersMessages.Items[e.Index].ToString(), (e.NewValue == CheckState.Checked));
|
2009-04-16 05:14:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2009-04-16 08:19:45 +00:00
|
|
|
|
// This is from omv Utils, once we get it prettied up put it back there
|
2009-04-16 05:14:07 +00:00
|
|
|
|
public static string PacketToString(Packet packet)
|
|
|
|
|
|
{
|
|
|
|
|
|
StringBuilder result = new StringBuilder();
|
|
|
|
|
|
|
2009-04-17 00:48:52 +00:00
|
|
|
|
//result.AppendFormat("{0}" + System.Environment.NewLine, packet.Type);
|
|
|
|
|
|
|
2009-04-16 05:14:07 +00:00
|
|
|
|
foreach (FieldInfo packetField in packet.GetType().GetFields())
|
|
|
|
|
|
{
|
|
|
|
|
|
object packetDataObject = packetField.GetValue(packet);
|
|
|
|
|
|
|
2009-04-17 00:48:52 +00:00
|
|
|
|
result.AppendFormat("-- {0,30} --" + System.Environment.NewLine, packetField.Name);
|
2009-04-16 05:14:07 +00:00
|
|
|
|
foreach (FieldInfo packetValueField in packetField.GetValue(packet).GetType().GetFields())
|
|
|
|
|
|
{
|
2009-04-17 00:48:52 +00:00
|
|
|
|
result.AppendFormat("{0,30}: {1}" + System.Environment.NewLine,
|
2009-04-16 05:14:07 +00:00
|
|
|
|
packetValueField.Name, packetValueField.GetValue(packetDataObject));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// handle blocks that are arrays
|
|
|
|
|
|
if (packetDataObject.GetType().IsArray)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (object nestedArrayRecord in packetDataObject as Array)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (FieldInfo packetArrayField in nestedArrayRecord.GetType().GetFields())
|
|
|
|
|
|
{
|
2009-04-16 08:19:45 +00:00
|
|
|
|
if (packetArrayField.GetValue(nestedArrayRecord).GetType() == typeof(System.Byte[]))
|
|
|
|
|
|
{
|
|
|
|
|
|
result.AppendFormat("{0,30}: {1}" + System.Environment.NewLine,
|
|
|
|
|
|
packetArrayField.Name, new Color4((byte[])packetArrayField.GetValue(nestedArrayRecord), 0, false).ToString());// c4.ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
result.AppendFormat("{0,30}: {1}" + System.Environment.NewLine,
|
|
|
|
|
|
packetArrayField.Name, packetArrayField.GetValue(nestedArrayRecord));
|
|
|
|
|
|
}
|
2009-04-16 05:14:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// handle non array data blocks
|
|
|
|
|
|
foreach (PropertyInfo packetPropertyField in packetField.GetValue(packet).GetType().GetProperties())
|
|
|
|
|
|
{
|
|
|
|
|
|
// Handle fields named "Data" specifically, this is generally binary data, we'll display it as hex values
|
|
|
|
|
|
if (packetPropertyField.PropertyType.Equals(typeof(System.Byte[]))
|
|
|
|
|
|
&& packetPropertyField.Name.Equals("Data"))
|
|
|
|
|
|
{
|
2009-04-16 08:19:45 +00:00
|
|
|
|
result.AppendFormat("{0,5}: {1}" + System.Environment.NewLine,
|
2009-04-16 05:14:07 +00:00
|
|
|
|
packetPropertyField.Name,
|
|
|
|
|
|
Utils.BytesToHexString((byte[])packetPropertyField.GetValue(packetDataObject, null), packetPropertyField.Name));
|
|
|
|
|
|
}
|
|
|
|
|
|
// decode bytes into strings
|
|
|
|
|
|
else if (packetPropertyField.PropertyType.Equals(typeof(System.Byte[])))
|
|
|
|
|
|
{
|
2009-04-16 08:19:45 +00:00
|
|
|
|
result.AppendFormat("{0,30}: {1}" + System.Environment.NewLine,
|
2009-04-16 05:14:07 +00:00
|
|
|
|
packetPropertyField.Name,
|
|
|
|
|
|
Utils.BytesToString((byte[])packetPropertyField.GetValue(packetDataObject, null)));
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2009-04-16 08:19:45 +00:00
|
|
|
|
// this seems to be limited to the length property, since all others have been previously handled
|
2009-04-17 00:48:52 +00:00
|
|
|
|
if (packetPropertyField.Name != "Length")
|
|
|
|
|
|
{
|
|
|
|
|
|
result.AppendFormat("{0,30}: {1}" + System.Environment.NewLine,
|
|
|
|
|
|
packetPropertyField.Name, packetPropertyField.GetValue(packetDataObject, null));
|
|
|
|
|
|
}
|
2009-04-16 05:14:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return result.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void listViewSessions_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (e.IsSelected)
|
|
|
|
|
|
{
|
2009-04-16 08:19:45 +00:00
|
|
|
|
tabControl1.SelectTab("tabPageInspect");
|
2009-04-17 00:48:52 +00:00
|
|
|
|
object tag = e.Item.Tag;
|
|
|
|
|
|
|
|
|
|
|
|
if (tag is XmlRpcRequest)
|
2009-04-16 05:14:07 +00:00
|
|
|
|
{
|
2009-04-17 00:48:52 +00:00
|
|
|
|
XmlRpcRequest requestData = (XmlRpcRequest)tag;
|
|
|
|
|
|
|
2009-04-17 10:02:16 +00:00
|
|
|
|
richTextBoxRawLogRequest.Text = requestData.ToString();
|
|
|
|
|
|
updateTreeView(requestData.ToString(), treeViewRequestXml);
|
2009-04-16 05:14:07 +00:00
|
|
|
|
|
2009-04-17 00:48:52 +00:00
|
|
|
|
Be.Windows.Forms.DynamicByteProvider data = new Be.Windows.Forms.DynamicByteProvider(Utils.StringToBytes(requestData.ToString()));
|
2009-04-17 10:02:16 +00:00
|
|
|
|
hexBoxRequest.ByteProvider = data;
|
|
|
|
|
|
|
|
|
|
|
|
hexBoxResponse.ByteProvider = null;
|
|
|
|
|
|
richTextBoxRawLogResponse.Text = String.Empty;
|
|
|
|
|
|
treeViewResponseXml.Nodes.Clear();
|
2009-04-16 05:14:07 +00:00
|
|
|
|
}
|
2009-04-17 00:48:52 +00:00
|
|
|
|
else if (tag is XmlRpcResponse)
|
2009-04-16 05:14:07 +00:00
|
|
|
|
{
|
2009-04-17 00:48:52 +00:00
|
|
|
|
XmlRpcResponse responseData = (XmlRpcResponse)tag;
|
|
|
|
|
|
|
2009-04-17 10:02:16 +00:00
|
|
|
|
richTextBoxRawLogResponse.Text = responseData.ToString();
|
|
|
|
|
|
updateTreeView(responseData.ToString(), treeViewResponseXml);
|
|
|
|
|
|
|
2009-04-17 00:48:52 +00:00
|
|
|
|
Be.Windows.Forms.DynamicByteProvider data = new Be.Windows.Forms.DynamicByteProvider(Utils.StringToBytes(responseData.ToString()));
|
2009-04-17 10:02:16 +00:00
|
|
|
|
hexBoxResponse.ByteProvider = data;
|
|
|
|
|
|
|
|
|
|
|
|
hexBoxRequest.ByteProvider = null;
|
|
|
|
|
|
richTextBoxRawLogRequest.Text = "No Data";
|
|
|
|
|
|
treeViewRequestXml.Nodes.Clear();
|
2009-04-16 05:14:07 +00:00
|
|
|
|
}
|
2009-04-17 00:48:52 +00:00
|
|
|
|
else if (tag is Packet)
|
2009-04-16 05:14:07 +00:00
|
|
|
|
{
|
2009-04-17 00:48:52 +00:00
|
|
|
|
Packet packet = (Packet)tag;
|
2009-04-17 10:02:16 +00:00
|
|
|
|
|
|
|
|
|
|
richTextBoxRawLogResponse.Text = PacketToString(packet);
|
2009-04-17 00:48:52 +00:00
|
|
|
|
|
|
|
|
|
|
Be.Windows.Forms.DynamicByteProvider data = new Be.Windows.Forms.DynamicByteProvider(packet.ToBytes());
|
2009-04-17 10:02:16 +00:00
|
|
|
|
hexBoxResponse.ByteProvider = data;
|
2009-04-16 05:14:07 +00:00
|
|
|
|
}
|
2009-04-17 00:48:52 +00:00
|
|
|
|
else if (tag is CapsRequest)
|
2009-04-16 05:14:07 +00:00
|
|
|
|
{
|
2009-04-17 00:48:52 +00:00
|
|
|
|
CapsRequest capsData = (CapsRequest)tag;
|
|
|
|
|
|
|
2009-04-17 10:02:16 +00:00
|
|
|
|
if (capsData.Request != null)
|
2009-04-17 00:48:52 +00:00
|
|
|
|
{
|
2009-04-17 10:02:16 +00:00
|
|
|
|
richTextBoxRawLogRequest.Text = capsData.Request.ToString();
|
|
|
|
|
|
updateTreeView(OSDParser.SerializeLLSDXmlString(capsData.Request), treeViewRequestXml);
|
2009-04-17 00:48:52 +00:00
|
|
|
|
Be.Windows.Forms.DynamicByteProvider data = new Be.Windows.Forms.DynamicByteProvider(Utils.StringToBytes(capsData.Request.ToString()));
|
2009-04-17 10:02:16 +00:00
|
|
|
|
hexBoxRequest.ByteProvider = data;
|
|
|
|
|
|
}
|
2009-04-16 05:14:07 +00:00
|
|
|
|
else
|
2009-04-16 08:19:45 +00:00
|
|
|
|
{
|
2009-04-17 10:02:16 +00:00
|
|
|
|
richTextBoxRawLogRequest.Text = "No Data";
|
|
|
|
|
|
treeViewRequestXml.Nodes.Clear();
|
|
|
|
|
|
hexBoxRequest.ByteProvider = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (capsData.Response != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
richTextBoxRawLogResponse.Text = capsData.Response.ToString();
|
|
|
|
|
|
updateTreeView(OSDParser.SerializeLLSDXmlString(capsData.Response), treeViewResponseXml);
|
|
|
|
|
|
Be.Windows.Forms.DynamicByteProvider data = new Be.Windows.Forms.DynamicByteProvider(Utils.StringToBytes(capsData.Response.ToString()));
|
|
|
|
|
|
hexBoxResponse.ByteProvider = data;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
richTextBoxRawLogResponse.Text = "No Data";
|
|
|
|
|
|
treeViewResponseXml.Nodes.Clear();
|
|
|
|
|
|
hexBoxResponse.ByteProvider = null;
|
2009-04-16 08:19:45 +00:00
|
|
|
|
}
|
2009-04-16 05:14:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2009-04-17 10:02:16 +00:00
|
|
|
|
private void updateTreeView(string xml, TreeView treeView)
|
2009-04-16 08:19:45 +00:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2009-04-17 10:02:16 +00:00
|
|
|
|
treeViewResponseXml.Nodes.Clear();
|
2009-04-16 08:19:45 +00:00
|
|
|
|
|
|
|
|
|
|
XmlDocument tmpxmldoc = new XmlDocument();
|
|
|
|
|
|
tmpxmldoc.LoadXml(xml);
|
2009-04-17 10:02:16 +00:00
|
|
|
|
FillTree(tmpxmldoc.DocumentElement, treeView.Nodes);
|
|
|
|
|
|
treeView.ExpandAll();
|
2009-04-16 08:19:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine("Error during xml conversion:" + ex.Message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2009-04-16 05:14:07 +00:00
|
|
|
|
|
2009-04-16 08:19:45 +00:00
|
|
|
|
private void FillTree(XmlNode node, TreeNodeCollection parentnode)
|
|
|
|
|
|
{
|
|
|
|
|
|
// End recursion if the node is a text type
|
|
|
|
|
|
if (node == null || node.NodeType == XmlNodeType.Text || node.NodeType == XmlNodeType.CDATA)
|
|
|
|
|
|
return;
|
2009-04-16 05:14:07 +00:00
|
|
|
|
|
2009-04-16 08:19:45 +00:00
|
|
|
|
TreeNodeCollection tmptreenodecollection = AddNodeToTree(node, parentnode);
|
2009-04-16 05:14:07 +00:00
|
|
|
|
|
2009-04-16 08:19:45 +00:00
|
|
|
|
// Add all the children of the current node to the treeview
|
|
|
|
|
|
foreach (XmlNode tmpchildnode in node.ChildNodes)
|
|
|
|
|
|
{
|
|
|
|
|
|
FillTree(tmpchildnode, tmptreenodecollection);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2009-04-16 05:14:07 +00:00
|
|
|
|
|
2009-04-16 08:19:45 +00:00
|
|
|
|
private TreeNodeCollection AddNodeToTree(XmlNode node, TreeNodeCollection parentnode)
|
|
|
|
|
|
{
|
|
|
|
|
|
TreeNode newchildnode = CreateTreeNodeFromXmlNode(node);
|
2009-04-16 05:14:07 +00:00
|
|
|
|
|
2009-04-16 08:19:45 +00:00
|
|
|
|
// if nothing to add, return the parent item
|
|
|
|
|
|
if (newchildnode == null) return parentnode;
|
2009-04-16 05:14:07 +00:00
|
|
|
|
|
2009-04-16 08:19:45 +00:00
|
|
|
|
// add the newly created tree node to its parent
|
|
|
|
|
|
if (parentnode != null) parentnode.Add(newchildnode);
|
2009-04-16 05:14:07 +00:00
|
|
|
|
|
2009-04-16 08:19:45 +00:00
|
|
|
|
return newchildnode.Nodes;
|
|
|
|
|
|
}
|
2009-04-16 05:14:07 +00:00
|
|
|
|
|
2009-04-16 08:19:45 +00:00
|
|
|
|
private TreeNode CreateTreeNodeFromXmlNode(XmlNode node)
|
2009-04-16 05:14:07 +00:00
|
|
|
|
{
|
2009-04-16 08:19:45 +00:00
|
|
|
|
TreeNode tmptreenode = new TreeNode();
|
2009-04-16 05:14:07 +00:00
|
|
|
|
|
2009-04-16 08:19:45 +00:00
|
|
|
|
if ((node.HasChildNodes) && (node.FirstChild.Value != null))
|
2009-04-16 05:14:07 +00:00
|
|
|
|
{
|
2009-04-16 08:19:45 +00:00
|
|
|
|
tmptreenode = new TreeNode(node.Name);
|
|
|
|
|
|
TreeNode tmptreenode2 = new TreeNode(node.FirstChild.Value);
|
|
|
|
|
|
tmptreenode.Nodes.Add(tmptreenode2);
|
2009-04-16 05:14:07 +00:00
|
|
|
|
}
|
2009-04-16 08:19:45 +00:00
|
|
|
|
else if (node.NodeType != XmlNodeType.CDATA)
|
2009-04-16 05:14:07 +00:00
|
|
|
|
{
|
2009-04-16 08:19:45 +00:00
|
|
|
|
tmptreenode = new TreeNode(node.Name);
|
2009-04-16 05:14:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2009-04-16 08:19:45 +00:00
|
|
|
|
return tmptreenode;
|
|
|
|
|
|
}
|
2009-04-16 05:14:07 +00:00
|
|
|
|
|
|
|
|
|
|
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (IsProxyRunning)
|
|
|
|
|
|
proxy.Stop();
|
2009-04-17 10:02:16 +00:00
|
|
|
|
|
|
|
|
|
|
SaveAllSettings("settings.osd");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void SaveAllSettings(string fileName)
|
|
|
|
|
|
{
|
|
|
|
|
|
Store.MessageSessions.Clear();
|
|
|
|
|
|
Store.PacketSessions.Clear();
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < checkedListBoxFiltersMessages.Items.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool cbchecked = false;
|
|
|
|
|
|
if (checkedListBoxFiltersMessages.CheckedItems.Contains(checkedListBoxFiltersMessages.Items[i]))
|
|
|
|
|
|
cbchecked = true;
|
|
|
|
|
|
|
|
|
|
|
|
Store.MessageSessions.Add(checkedListBoxFiltersMessages.Items[i].ToString(), cbchecked);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < checkedListBoxFiltersPackets.Items.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool cbchecked = false;
|
|
|
|
|
|
if (checkedListBoxFiltersPackets.CheckedItems.Contains(checkedListBoxFiltersPackets.Items[i]))
|
|
|
|
|
|
cbchecked = true;
|
|
|
|
|
|
|
|
|
|
|
|
Store.PacketSessions.Add(checkedListBoxFiltersPackets.Items[i].ToString(), cbchecked);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Store.SerializeToFile(fileName);
|
2009-04-16 05:14:07 +00:00
|
|
|
|
}
|
2009-04-17 00:48:52 +00:00
|
|
|
|
|
|
|
|
|
|
void Position_Changed(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2009-04-17 10:02:16 +00:00
|
|
|
|
//toolStripStatusLabel1.Text = string.Format("Ln {0} Col {1} Bytes {2}",
|
|
|
|
|
|
// hexBoxResponse.CurrentLine, hexBoxResponse.CurrentPositionInLine, hexBoxResponse.ByteProvider.Length);
|
2009-04-17 00:48:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void timer1_Tick(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (this.InvokeRequired)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.BeginInvoke(new MethodInvoker(delegate()
|
|
|
|
|
|
{
|
|
|
|
|
|
timer1_Tick(sender, e);
|
|
|
|
|
|
}));
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
label1PacketsOut.Text = String.Format("{0} ({1} bytes)", PacketsOutCounter, PacketsOutBytes);
|
|
|
|
|
|
labelPacketsIn.Text = String.Format("{0} ({1} bytes)", PacketsInCounter, PacketsInBytes);
|
|
|
|
|
|
labelPacketsTotal.Text = String.Format("{0} ({1} bytes)", PacketsOutCounter + PacketsInCounter, PacketsOutBytes + PacketsInBytes);
|
|
|
|
|
|
|
|
|
|
|
|
labelCapsIn.Text = String.Format("{0} ({1} bytes)", CapsInCounter, CapsInBytes);
|
|
|
|
|
|
labelCapsOut.Text = String.Format("{0} ({1} bytes)", CapsOutCounter, CapsOutBytes);
|
|
|
|
|
|
labelCapsTotal.Text = String.Format("{0} ({1} bytes)", CapsInCounter + CapsOutCounter, CapsOutBytes + CapsInBytes);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2009-04-17 10:02:16 +00:00
|
|
|
|
|
|
|
|
|
|
// select all items
|
|
|
|
|
|
private void allToolStripMenuItem1_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (ListViewItem item in listViewSessions.Items)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.Selected = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// unselect all items
|
|
|
|
|
|
private void noneToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (ListViewItem item in listViewSessions.Items)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.Selected = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// invert selection
|
|
|
|
|
|
private void invertSelectionsToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (ListViewItem item in listViewSessions.Items)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.Selected = !item.Selected;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// remove all sessions
|
|
|
|
|
|
private void allToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
listViewSessions.Items.Clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// remove sessions that are currently selected
|
|
|
|
|
|
private void selectedToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (ListViewItem item in listViewSessions.Items)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item.Selected)
|
|
|
|
|
|
listViewSessions.Items.Remove(item);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// remove sessions that are not currently selected
|
|
|
|
|
|
private void unselectedSessionsToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (ListViewItem item in listViewSessions.Items)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!item.Selected)
|
|
|
|
|
|
listViewSessions.Items.Remove(item);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void MarkColorToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
ToolStripMenuItem menu = (ToolStripMenuItem)sender;
|
|
|
|
|
|
|
|
|
|
|
|
foreach (ListViewItem item in listViewSessions.Items)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item.Selected)
|
|
|
|
|
|
item.BackColor = Color.FromName(menu.Text);
|
|
|
|
|
|
}
|
|
|
|
|
|
noneToolStripMenuItem_Click(sender, e);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void removeToolStripMenuItem1_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (ListViewItem item in listViewSessions.Items)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item.Selected)
|
|
|
|
|
|
item.BackColor = Color.White;
|
|
|
|
|
|
}
|
|
|
|
|
|
noneToolStripMenuItem_Click(sender, e);
|
|
|
|
|
|
}
|
2009-04-17 00:48:52 +00:00
|
|
|
|
}
|
2009-04-16 05:14:07 +00:00
|
|
|
|
|
|
|
|
|
|
public class ProxyManager
|
|
|
|
|
|
{
|
|
|
|
|
|
public delegate void PacketLogHandler(Packet packet, Direction direction, IPEndPoint endpoint);
|
|
|
|
|
|
public static event PacketLogHandler OnPacketLog;
|
|
|
|
|
|
|
|
|
|
|
|
public delegate void MessageLogHandler(CapsRequest req, CapsStage stage);
|
|
|
|
|
|
public static event MessageLogHandler OnMessageLog;
|
|
|
|
|
|
|
|
|
|
|
|
public delegate void LoginLogHandler(object request, Direction direction);
|
|
|
|
|
|
public static event LoginLogHandler OnLoginResponse;
|
|
|
|
|
|
|
2009-04-17 10:02:16 +00:00
|
|
|
|
private string _Port;
|
|
|
|
|
|
private string _ListenIP;
|
|
|
|
|
|
private string _LoginURI;
|
|
|
|
|
|
|
2009-04-16 05:14:07 +00:00
|
|
|
|
ProxyFrame Proxy;
|
|
|
|
|
|
ProxyPlugin analyst;
|
2009-04-17 10:02:16 +00:00
|
|
|
|
|
2009-04-16 08:19:45 +00:00
|
|
|
|
public ProxyManager(string port, string listenIP, string loginUri)
|
2009-04-16 05:14:07 +00:00
|
|
|
|
{
|
2009-04-16 08:19:45 +00:00
|
|
|
|
|
2009-04-17 10:02:16 +00:00
|
|
|
|
_Port = string.Format("--proxy-login-port={0}", port);
|
2009-04-16 08:19:45 +00:00
|
|
|
|
|
|
|
|
|
|
IPAddress remoteIP; // not used
|
|
|
|
|
|
if (IPAddress.TryParse(listenIP, out remoteIP))
|
2009-04-17 10:02:16 +00:00
|
|
|
|
_ListenIP = String.Format("--proxy-client-facing-address={0}", listenIP);
|
2009-04-16 08:19:45 +00:00
|
|
|
|
else
|
2009-04-17 10:02:16 +00:00
|
|
|
|
_ListenIP = "--proxy-client-facing-address=127.0.0.1";
|
2009-04-16 08:19:45 +00:00
|
|
|
|
|
|
|
|
|
|
if (String.IsNullOrEmpty(loginUri))
|
2009-04-17 10:02:16 +00:00
|
|
|
|
_LoginURI = "https://login.agni.lindenlab.com/cgi-bin/login.cgi";
|
|
|
|
|
|
else
|
|
|
|
|
|
_LoginURI = loginUri;
|
2009-04-16 08:19:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
2009-04-17 10:02:16 +00:00
|
|
|
|
string[] args = { _Port, _ListenIP, _LoginURI };
|
2009-04-16 08:19:45 +00:00
|
|
|
|
/*
|
2009-04-17 00:48:52 +00:00
|
|
|
|
help
|
|
|
|
|
|
proxy-help
|
|
|
|
|
|
proxy-login-port
|
|
|
|
|
|
proxy-client-facing-address
|
|
|
|
|
|
proxy-remote-facing-address
|
|
|
|
|
|
proxy-remote-login-uri
|
|
|
|
|
|
verbose
|
|
|
|
|
|
quiet
|
2009-04-16 08:19:45 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
2009-04-16 05:14:07 +00:00
|
|
|
|
Proxy = new ProxyFrame(args);
|
2009-04-16 08:19:45 +00:00
|
|
|
|
|
2009-04-16 05:14:07 +00:00
|
|
|
|
analyst = new PacketAnalyzer(Proxy);
|
|
|
|
|
|
analyst.Init();
|
|
|
|
|
|
|
|
|
|
|
|
Proxy.proxy.SetLoginRequestDelegate(new XmlRpcRequestDelegate(LoginRequest));
|
|
|
|
|
|
Proxy.proxy.SetLoginResponseDelegate(new XmlRpcResponseDelegate(LoginResponse));
|
2009-04-16 08:19:45 +00:00
|
|
|
|
|
2009-04-16 05:14:07 +00:00
|
|
|
|
AddCapsDelegate("SeedCapability", true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Start()
|
|
|
|
|
|
{
|
2009-04-16 08:19:45 +00:00
|
|
|
|
|
2009-04-16 05:14:07 +00:00
|
|
|
|
Proxy.proxy.Start();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Stop()
|
|
|
|
|
|
{
|
|
|
|
|
|
Proxy.proxy.Stop();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void LoginRequest(XmlRpcRequest request)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (OnLoginResponse != null)
|
|
|
|
|
|
OnLoginResponse(request, Direction.Outgoing);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void LoginResponse(XmlRpcResponse response)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (OnLoginResponse != null)
|
|
|
|
|
|
OnLoginResponse(response, Direction.Incoming);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
internal Dictionary<string, CapInfo> GetCapabilities()
|
|
|
|
|
|
{
|
|
|
|
|
|
return Proxy.proxy.KnownCaps;
|
|
|
|
|
|
}
|
2009-04-16 08:19:45 +00:00
|
|
|
|
|
2009-04-16 05:14:07 +00:00
|
|
|
|
internal void AddCapsDelegate(string capsKey, bool add)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (add)
|
|
|
|
|
|
Proxy.proxy.AddCapsDelegate(capsKey, new CapsDelegate(CapsHandler));
|
|
|
|
|
|
else
|
|
|
|
|
|
Proxy.proxy.RemoveCapRequestDelegate(capsKey, new CapsDelegate(CapsHandler));
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private bool CapsHandler(CapsRequest req, CapsStage stage)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (OnMessageLog != null)
|
|
|
|
|
|
OnMessageLog(req, stage);
|
|
|
|
|
|
//Console.WriteLine(req);
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
internal void AddUDPDelegate(PacketType packetType, bool add)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (add)
|
|
|
|
|
|
{
|
2009-04-17 00:48:52 +00:00
|
|
|
|
Proxy.proxy.AddDelegate(packetType, Direction.Incoming, new PacketDelegate(PacketInHandler));
|
|
|
|
|
|
Proxy.proxy.AddDelegate(packetType, Direction.Outgoing, new PacketDelegate(PacketOutHandler));
|
2009-04-16 05:14:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2009-04-17 00:48:52 +00:00
|
|
|
|
Proxy.proxy.RemoveDelegate(packetType, Direction.Incoming, new PacketDelegate(PacketInHandler));
|
|
|
|
|
|
Proxy.proxy.RemoveDelegate(packetType, Direction.Outgoing, new PacketDelegate(PacketOutHandler));
|
2009-04-16 05:14:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2009-04-17 00:48:52 +00:00
|
|
|
|
private Packet PacketInHandler(Packet packet, IPEndPoint endPoint)
|
2009-04-16 05:14:07 +00:00
|
|
|
|
{
|
2009-04-16 08:19:45 +00:00
|
|
|
|
if (OnPacketLog != null)
|
2009-04-16 05:14:07 +00:00
|
|
|
|
OnPacketLog(packet, Direction.Incoming, endPoint);
|
|
|
|
|
|
|
|
|
|
|
|
return packet;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2009-04-17 00:48:52 +00:00
|
|
|
|
private Packet PacketOutHandler(Packet packet, IPEndPoint endPoint)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (OnPacketLog != null)
|
|
|
|
|
|
OnPacketLog(packet, Direction.Outgoing, endPoint);
|
|
|
|
|
|
|
|
|
|
|
|
return packet;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2009-04-16 05:14:07 +00:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class PacketAnalyzer : ProxyPlugin
|
|
|
|
|
|
{
|
|
|
|
|
|
private ProxyFrame frame;
|
|
|
|
|
|
private Proxy proxy;
|
|
|
|
|
|
|
|
|
|
|
|
public PacketAnalyzer(ProxyFrame frame)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.frame = frame;
|
|
|
|
|
|
this.proxy = frame.proxy;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void Init()
|
|
|
|
|
|
{
|
2009-04-16 08:19:45 +00:00
|
|
|
|
|
2009-04-16 05:14:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|