Index: Analyst.cs =================================================================== --- Analyst.cs (revision 2001) +++ Analyst.cs (working copy) @@ -31,6 +31,7 @@ using System; using System.Collections; +using System.Collections.Generic; using System.Globalization; using System.IO; using System.Net; @@ -48,7 +49,7 @@ private Proxy proxy; private Hashtable loggedPackets = new Hashtable(); private string logGrep = null; - private Hashtable modifiedPackets = new Hashtable(); + private Dictionary> modifiedPackets = new Dictionary>(); private Assembly openmvAssembly; public Analyst(ProxyFrame frame) @@ -188,18 +189,18 @@ return; } - Hashtable fields; - if (modifiedPackets.Contains(pType)) - fields = (Hashtable)modifiedPackets[pType]; + Dictionary fields; + if (modifiedPackets.ContainsKey(pType)) + fields = (Dictionary)modifiedPackets[pType]; else - fields = new Hashtable(); + fields = new Dictionary(); fields[new BlockField(words[2], words[3])] = value; modifiedPackets[pType] = fields; proxy.AddDelegate(pType, Direction.Incoming, new PacketDelegate(ModifyIn)); proxy.AddDelegate(pType, Direction.Outgoing, new PacketDelegate(ModifyOut)); - + SayToUser("setting " + words[1] + "." + words[2] + "." + words[3] + " = " + valueString); } } @@ -214,7 +215,7 @@ proxy.RemoveDelegate(pType, Direction.Incoming, new PacketDelegate(ModifyIn)); proxy.RemoveDelegate(pType, Direction.Outgoing, new PacketDelegate(ModifyOut)); } - modifiedPackets = new Hashtable(); + modifiedPackets = new Dictionary>(); SayToUser("stopped setting all fields"); } @@ -232,9 +233,9 @@ } - if (modifiedPackets.Contains(pType)) + if (modifiedPackets.ContainsKey(pType)) { - Hashtable fields = (Hashtable)modifiedPackets[pType]; + Dictionary fields = modifiedPackets[pType]; fields.Remove(new BlockField(words[2], words[3])); if (fields.Count == 0) @@ -596,21 +597,33 @@ // Modify: modify a packet private Packet Modify(Packet packet, IPEndPoint endPoint, Direction direction) { - if (modifiedPackets.Contains(packet.Type)) + if (modifiedPackets.ContainsKey(packet.Type)) { try { - Hashtable changes = (Hashtable)modifiedPackets[packet.Type]; + Dictionary changes = modifiedPackets[packet.Type]; Type packetClass = packet.GetType(); - foreach (BlockField bf in changes.Keys) + foreach (KeyValuePair change in changes) { - //FIXME: support variable blocks - + BlockField bf = change.Key; FieldInfo blockField = packetClass.GetField(bf.block); - //Type blockClass = blockField.FieldType; - object blockObject = blockField.GetValue(packet); - MagicSetField(blockObject, bf.field, changes[blockField]); + if (blockField.FieldType.IsArray) // We're modifying a variable block. + { + // Modify each block in the variable block identically. + // This is really simple, can probably be improved. + object[] blockArray = (object[])blockField.GetValue(packet); + foreach (object blockElement in blockArray) + { + MagicSetField(blockElement, bf.field, change.Value); + } + } + else + { + //Type blockClass = blockField.FieldType; + object blockObject = blockField.GetValue(packet); + MagicSetField(blockObject, bf.field, change.Value); + } } } catch (Exception e)