Exemplo n.º 1
0
 public ScriptForm(string pPath, FiestaPacket pPacket)
 {
     mPath   = pPath;
     mPacket = pPacket;
     InitializeComponent();
     try {
         if (pPacket != null)
         {
             Text = "Script 0x" + pPacket.Opcode.ToString("X4") + ", " + (pPacket.Outbound ? "Outbound" : "Inbound");
         }
         else if (Path.GetFileName(pPath).Contains("Global"))
         {
             Text = "Global Script";
         }
         else if (Path.GetFileName(pPath).Contains("Common"))
         {
             Text = "Common Script";
         }
         else
         {
             Text = "Script";
         }
     } catch (Exception e) {
         // Shoudn't reach this
         MessageBox.Show("Exception in ScriptForm(). Make picture of it and post it in Forum." + Environment.NewLine +
                         e.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
Exemplo n.º 2
0
 private void mPacketContextMenu_Opening(object pSender, CancelEventArgs pArgs)
 {
     mPacketContextNameBox.Text = "";
     //mPacketContextIgnoreMenu.Checked = false;
     if (mPacketList.SelectedItems.Count == 0)
     {
         pArgs.Cancel = true;
     }
     else
     {
         FiestaPacket packet     = mPacketList.SelectedItems[0] as FiestaPacket;
         Definition   definition = Config.Instance.Definitions.Find(d => d.Outbound == packet.Outbound && d.Opcode == packet.Opcode);
         if (definition != null)
         {
             mPacketContextNameBox.Text = definition.Name;
             if (definition.Ignore)
             {
                 mPacketContextIgnoreMenu.Checked = true;
             }
             else
             {
                 mPacketContextIgnoreMenu.Checked = false;
             }
         }
     }
 }
Exemplo n.º 3
0
        private void mNextOpcodeButton_Click(object pSender, EventArgs pArgs)
        {
            SessionForm session = DockPanel.ActiveDocument as SessionForm;

            if (session == null || mOpcodeCombo.SelectedIndex < 0)
            {
                return;
            }
            Pair <bool, ushort> search = (DockPanel.ActiveDocument as SessionForm).Opcodes[mOpcodeCombo.SelectedIndex];
            int initialIndex           = session.ListView.SelectedIndices.Count == 0 ? 0 : session.ListView.SelectedIndices[0] + 1;

            for (int index = initialIndex; index < session.ListView.Items.Count; ++index)
            {
                FiestaPacket packet = session.ListView.Items[index] as FiestaPacket;
                if (packet.Outbound == search.First && packet.Opcode == search.Second)
                {
                    session.ListView.SelectedIndices.Clear();
                    session.ListView.SelectedIndices.Add(index);
                    packet.EnsureVisible();
                    session.ListView.Focus();
                    return;
                }
            }
            MessageBox.Show("No further packets found with the selected opcode.", "End Of Search", MessageBoxButtons.OK, MessageBoxIcon.Information);
            session.ListView.Focus();
        }
Exemplo n.º 4
0
 public ScriptForm(string pPath, FiestaPacket pPacket)
 {
     mPath   = pPath;
     mPacket = pPacket;
     InitializeComponent();
     Text = "Script 0x" + pPacket.Opcode.ToString("X4") + ", " + (pPacket.Outbound ? "Outbound" : "Inbound");
 }
Exemplo n.º 5
0
        private void CommonScript_FormClosed(object pSender, FormClosedEventArgs pArgs)
        {
            if (mPacketList.SelectedIndices.Count == 0)
            {
                return;
            }
            FiestaPacket packet = mPacketList.SelectedItems[0] as FiestaPacket;

            MainForm.StructureForm.ParseFiestaPacket(packet);
            Activate();
        }
Exemplo n.º 6
0
        public void RefreshPackets()
        {
            FiestaPacket previous = mPacketList.SelectedItems.Count > 0 ? mPacketList.SelectedItems[0] as FiestaPacket : null;

            mOpcodes.Clear();
            mPacketList.Items.Clear();
            MainForm.pDataForm.HexBox.ByteProvider = null;
            MainForm.StructureForm.Tree.Nodes.Clear();
            MainForm.PropertyForm.Properties.SelectedObject = null;
            if (!mViewOutboundMenu.Checked && !mViewInboundMenu.Checked)
            {
                return;
            }

            for (int index = 0; index < mPackets.Count; ++index)
            {
                FiestaPacket packet = mPackets[index];
                if (packet.Outbound && !mViewOutboundMenu.Checked)
                {
                    continue;
                }
                if (!packet.Outbound && !mViewInboundMenu.Checked)
                {
                    continue;
                }
                if (FilterOut(packet))
                {
                    continue;
                }
                Definition definition = Config.Instance.Definitions.Find(d => d.Build == mBuild && d.Outbound == packet.Outbound && d.Opcode == packet.Opcode);
                packet.Name = definition == null ? "" : definition.Name;
                if (!mOpcodes.Exists(kv => kv.Item1 == packet.Outbound && kv.Item2 == packet.Opcode))
                {
                    mOpcodes.Add(new Tuple <bool, ushort>(packet.Outbound, packet.Opcode));
                }

                if (definition != null && !mViewIgnoredMenu.Checked && definition.Ignore)
                {
                    continue;
                }

                mPacketList.Items.Add(packet);

                if (packet == previous)
                {
                    packet.Selected = true;
                }
            }
        }
Exemplo n.º 7
0
        private void mPacketContextIgnoreMenu_CheckedChanged(object pSender, EventArgs pArgs)
        {
            FiestaPacket packet     = mPacketList.SelectedItems[0] as FiestaPacket;
            Definition   definition = Config.Instance.Definitions.Find(d => d.Outbound == packet.Outbound && d.Opcode == packet.Opcode);

            if (definition == null)
            {
                definition          = new Definition();
                definition.Outbound = packet.Outbound;
                definition.Opcode   = packet.Opcode;
                Config.Instance.Definitions.Add(definition);
            }
            definition.Ignore = mPacketContextIgnoreMenu.Checked;
            Config.Instance.Save();
            RefreshPackets();
        }
Exemplo n.º 8
0
        private void mPrevSeq_Click(object sender, EventArgs e)
        {
            SessionForm session = DockPanel.ActiveDocument as SessionForm;

            if (session == null)
            {
                return;
            }
            int initialIndex = session.ListView.SelectedIndices.Count == 0 ? 0 : session.ListView.SelectedIndices[0];

            byte[] pattern    = (mSequenceHex.ByteProvider as DynamicByteProvider).Bytes.ToArray();
            long   startIndex = MainForm.DataForm.HexBox.SelectionLength > 0 ? MainForm.DataForm.HexBox.SelectionStart : -1;

            for (int index = initialIndex; index >= 0; --index)
            {
                FiestaPacket packet      = session.ListView.Items[index] as FiestaPacket;
                long         searchIndex = startIndex + 1;
                bool         found       = false;
                while (searchIndex <= packet.InnerBuffer.Length - pattern.Length)
                {
                    found = true;
                    for (int patternIndex = 0; found && patternIndex < pattern.Length; ++patternIndex)
                    {
                        found = packet.InnerBuffer[searchIndex + patternIndex] == pattern[patternIndex];
                    }
                    if (found)
                    {
                        break;
                    }
                    ++searchIndex;
                }
                if (found)
                {
                    session.ListView.SelectedIndices.Clear();
                    session.ListView.SelectedIndices.Add(index);
                    packet.EnsureVisible();
                    MainForm.DataForm.HexBox.SelectionStart  = searchIndex;
                    MainForm.DataForm.HexBox.SelectionLength = pattern.Length;
                    MainForm.DataForm.HexBox.ScrollByteIntoView();
                    session.ListView.Focus();
                    return;
                }
                startIndex = -1;
            }
            MessageBox.Show("No further sequences found.", "End Of Search", MessageBoxButtons.OK, MessageBoxIcon.Information);
            session.ListView.Focus();
        }
Exemplo n.º 9
0
        public void RefreshPackets()
        {
            Pair <bool, ushort> search   = (MainForm.SearchForm.ComboBox.SelectedIndex >= 0 ? mOpcodes[MainForm.SearchForm.ComboBox.SelectedIndex] : null);
            FiestaPacket        previous = mPacketList.SelectedItems.Count > 0 ? mPacketList.SelectedItems[0] as FiestaPacket : null;

            mOpcodes.Clear();
            mPacketList.Items.Clear();
            MainForm.DataForm.HexBox.ByteProvider = null;
            MainForm.StructureForm.Tree.Nodes.Clear();
            MainForm.PropertyForm.Properties.SelectedObject = null;
            if (!mViewOutboundMenu.Checked && !mViewInboundMenu.Checked)
            {
                return;
            }
            mPacketList.BeginUpdate();
            for (int index = 0; index < mPackets.Count; ++index)
            {
                FiestaPacket packet = mPackets[index];
                if (packet.Outbound && !mViewOutboundMenu.Checked)
                {
                    continue;
                }
                if (!packet.Outbound && !mViewInboundMenu.Checked)
                {
                    continue;
                }
                Definition definition = Config.Instance.Definitions.Find(d => d.Outbound == packet.Outbound && d.Opcode == packet.Opcode);
                packet.definition     = definition;
                packet.DefinitionName = definition == null ? "" : definition.Name;
                if (!mOpcodes.Exists(kv => kv.First == packet.Outbound && kv.Second == packet.Opcode))
                {
                    mOpcodes.Add(new Pair <bool, ushort>(packet.Outbound, packet.Opcode));
                }
                if (packet.definition != null && !mViewIgnoredMenu.Checked && packet.definition.Ignore)
                {
                    continue;
                }
                mPacketList.Items.Add(packet);
                if (packet == previous)
                {
                    packet.Selected = true;
                }
            }
            mPacketList.EndUpdate();
            MainForm.SearchForm.RefreshOpcodes(true);
        }
Exemplo n.º 10
0
        public void ParseFiestaPacket(FiestaPacket pPacket)
        {
            if (pPacket == null)
            {
                return;
            }
            mTree.Nodes.Clear();
            mSubNodes.Clear();
            pPacket.Rewind();

            string scriptPath = "Scripts" + Path.DirectorySeparatorChar + (pPacket.Outbound ? "Outbound" : "Inbound") + Path.DirectorySeparatorChar + "0x" + pPacket.Opcode.ToString("X4") + ".txt";
            string beforePath = "Scripts" + Path.DirectorySeparatorChar + "Global.txt";
            string afterPath  = "Scripts" + Path.DirectorySeparatorChar + "Common.txt";

            if (File.Exists(scriptPath))
            {
                mParsing = pPacket;

                try {
                    StringBuilder scriptCode = new StringBuilder();
                    this.showTypes = false; this.showData = false;
                    if (File.Exists(beforePath))
                    {
                        scriptCode.Append(File.ReadAllText(beforePath));
                    }
                    scriptCode.Append(Environment.NewLine + File.ReadAllText(scriptPath) + Environment.NewLine);
                    if (File.Exists(afterPath))
                    {
                        scriptCode.Append(File.ReadAllText(afterPath));
                    }
                    Script script = Script.Compile(scriptCode.ToString());
                    script.Context.SetItem("ScriptAPI", new ScriptAPI(this));
                    script.Execute();
                } catch (Exception exc) {
                    OutputForm output = new OutputForm("Script Error");
                    output.Append(exc.ToString());
                    output.Show(DockPanel, new Rectangle(MainForm.Location, new Size(400, 400)));
                }

                mParsing = null;
            }
            if (pPacket.Remaining > 0)
            {
                mTree.Nodes.Add(new StructureNode("Undefined", pPacket.InnerBuffer, pPacket.Cursor, pPacket.Remaining));
            }
        }
Exemplo n.º 11
0
        private void mPacketList_ItemActivate(object pSender, EventArgs pArgs)
        {
            if (mPacketList.SelectedIndices.Count == 0)
            {
                return;
            }
            FiestaPacket packet     = mPacketList.SelectedItems[0] as FiestaPacket;
            string       scriptPath = "Scripts" + Path.DirectorySeparatorChar + (packet.Outbound ? "Outbound" : "Inbound") + Path.DirectorySeparatorChar + "0x" + packet.Opcode.ToString("X4") + ".txt";

            if (!Directory.Exists(Path.GetDirectoryName(scriptPath)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(scriptPath));
            }
            ScriptForm script = new ScriptForm(scriptPath, packet);

            script.FormClosed += Script_FormClosed;
            script.Show(DockPanel, new Rectangle(MainForm.Location, new Size(600, 300)));
        }
Exemplo n.º 12
0
 private void mPacketContextNameBox_KeyDown(object pSender, KeyEventArgs pArgs)
 {
     if (pArgs.Modifiers == Keys.None && pArgs.KeyCode == Keys.Enter)
     {
         FiestaPacket packet     = mPacketList.SelectedItems[0] as FiestaPacket;
         Definition   definition = Config.Instance.Definitions.Find(d => d.Outbound == packet.Outbound && d.Opcode == packet.Opcode);
         if (definition == null)
         {
             definition          = new Definition();
             definition.Outbound = packet.Outbound;
             definition.Opcode   = packet.Opcode;
             Config.Instance.Definitions.Add(definition);
         }
         definition.Name = mPacketContextNameBox.Text;
         Config.Instance.Save();
         pArgs.SuppressKeyPress = true;
         mPacketContextMenu.Close();
         RefreshPackets();
     }
 }
Exemplo n.º 13
0
 public void OpenReadOnly(string pFilename)
 {
     mFileSaveMenu.Enabled = false;
     mTerminated           = true;
     using (FileStream stream = new FileStream(pFilename, FileMode.Open, FileAccess.Read))
     {
         BinaryReader reader = new BinaryReader(stream);
         mBuild     = reader.ReadUInt16();
         mLocalPort = reader.ReadUInt16();
         while (stream.Position < stream.Length)
         {
             long   timestamp = reader.ReadInt64();
             ushort size      = reader.ReadUInt16();
             ushort opcode    = reader.ReadUInt16();
             bool   outbound  = (size & 0x8000) != 0;
             size = (ushort)(size & 0x7FFF);
             byte[]       buffer     = reader.ReadBytes(size);
             int          Type       = opcode >> 10;
             int          Header     = opcode & 1023;
             Definition   definition = Config.Instance.Definitions.Find(d => d.Build == mBuild && d.Outbound == outbound && d.Opcode == opcode);
             FiestaPacket packet     = new FiestaPacket(new DateTime(timestamp), outbound, opcode, Type, Header, definition == null ? "" : definition.Name, buffer);
             mPackets.Add(packet);
             if (!mOpcodes.Exists(kv => kv.Item1 == packet.Outbound && kv.Item2 == packet.Opcode))
             {
                 mOpcodes.Add(new Tuple <bool, ushort>(packet.Outbound, packet.Opcode));
             }
             if (definition != null && definition.Ignore)
             {
                 continue;
             }
             mPacketList.Items.Add(packet);
         }
         if (mPacketList.Items.Count > 0)
         {
             mPacketList.EnsureVisible(0);
         }
     }
     Text = string.Format("Port {0} (ReadOnly)", mLocalPort);
 }