public void OnDelete(GDB.Response aResponse)
        {
            string[] xSplit = aResponse.Reply.Split(' ');
            int      xID    = int.Parse(xSplit[1]);
            var      xUC    = mBreakpoints[xID];

            mBreakpoints.Remove(xID);

            // Delete UC
            Controls.Remove(xUC);
            xUC.Dispose();
        }
Example #2
0
        protected void OnDisassemble(GDB.Response xResponse)
        {
            var xResult = xResponse.Text;

            // In some cases GDB might return no results. This is common when no symbols are loaded.
            if (xResult.Count == 0)
            {
                return;
            }
            // Get function name
            var xSplit = GDB.Unescape(xResult[0]).Split(Global.SpaceSeparator, StringSplitOptions.RemoveEmptyEntries);

            mFuncName = xSplit[xSplit.Length - 1];
            textCurrentFunction.Text = mFuncName;

            // remove ':'
            mFuncName = mFuncName.Substring(0, mFuncName.Length - 1);

            int labelLine = Global.AsmSource.GetLineOfLabel(mFuncName);

            labelLine++;

            // 1 and -2 to eliminate header and footer line
            for (int i = 1; i <= xResult.Count - 2; i++, labelLine++)
            {
                var asmLine = Global.AsmSource.Lines[labelLine];

                while (asmLine.IsLabel ||
                       (asmLine.FirstToken != null && (asmLine.FirstToken == "global" || asmLine.FirstToken.StartsWith(";"))))
                {
                    labelLine++;
                    asmLine = Global.AsmSource.Lines[labelLine];
                }

                var gdbLine = new GdbAsmLine(xResult[i]);
                asmLine.Address = gdbLine.mAddr;

                // check if line different, if so, we set a line for tooltip
                string strGdbLine                 = gdbLine.ToString();
                string gdbLineWithoutAddress      = strGdbLine.Substring(strGdbLine.IndexOf(":") + 3);
                string gdbLineWithoutAddressLower = gdbLineWithoutAddress.Replace(" ", string.Empty).ToLower().Replace("dwordptr", string.Empty);

                string asmlineFromFile             = asmLine.OrignalLine.TrimStart('\t', ' ').ToLower().Replace("dword", string.Empty);
                string asmlineFromFileWithoutspace = asmlineFromFile.Replace(" ", string.Empty);
                if (gdbLineWithoutAddressLower != asmlineFromFileWithoutspace)
                {
                    asmLine.GDBLine = gdbLineWithoutAddress;
                }
            }
        }
Example #3
0
 public void OnWhere(GDB.Response aResponse)
 {
     lboxCallStack.BeginUpdate();
     try {
         lboxCallStack.Items.Clear();
         foreach (var x in aResponse.Text)
         {
             //#0  0x0056d5df in DebugStub_Start ()
             //#1  0x0057572b in System_Void__Cosmos_User_Kernel_Program_Init____DOT__00000001 ()
             //#2  0x00550018 in Before_Kernel_Stack ()
             //#3  0x005a5427 in __ENGINE_ENTRYPOINT__ ()
             //~Backtrace stopped: frame did not save the PC
             if (x.StartsWith("#"))
             {
                 lboxCallStack.Items.Add(new CallStack(x));
             }
         }
     } finally {
         lboxCallStack.EndUpdate();
     }
 }
        public void OnBreak(GDB.Response aResponse)
        {
            var    xCmdParts = aResponse.Command.Split(Global.SpaceSeparator, StringSplitOptions.RemoveEmptyEntries);
            string xLabel    = xCmdParts[1];

            var xSplit = aResponse.Text[0].Split(Global.SpaceSeparator, StringSplitOptions.RemoveEmptyEntries);

            if (xSplit[0].ToLower() == "breakpoint")
            {
                // http://stackoverflow.com/questions/27674/dynamic-top-down-list-of-controls-in-windowsforms-and-c
                var xUC = new BreakpointUC();
                mBreakpoints.Add(int.Parse(xSplit[1]), xUC);

                xUC.Dock = DockStyle.Top;
                xUC.cboxEnabled.Checked = true;
                xUC.lablNum.Text        = xSplit[1];
                xUC.lablName.Text       = xLabel;
                xUC.Delete += new Action <int>(xUC_Delete);
                panl.Controls.Add(xUC);
            }
        }
Example #5
0
        protected void OnGDBResponse(GDB.Response aResponse)
        {
            try {
                Windows.mLogForm.Log(aResponse);
                var xCmdLine = aResponse.Command.ToLower();
                if (xCmdLine == "info registers")
                {
                    Windows.mRegistersForm.UpdateRegisters(aResponse);
                    Windows.UpdateAfterRegisterUpdate();
                }
                else if (xCmdLine.Length == 0)
                {
                    if (aResponse.Text.Count == 2 && aResponse.Text[0] == "Breakpoint")
                    {
                        // program breaks on aResponse.Text[1]
                    }
                    else
                    {
                        // contains address where we are
                    }
                }
                else
                {
                    var xCmdParts = xCmdLine.Split(Global.SpaceSeparator);
                    var xCmd      = xCmdParts[0];
                    if (xCmd.EndsWith("&"))
                    {
                        xCmd = xCmd.Substring(0, xCmd.Length - 1);
                    }
                    if (xCmd == "disassemble")
                    {
                        OnDisassemble(aResponse);
                    }
                    else if (xCmd == "symbol-file")     // nothing
                    {
                    }
                    else if (xCmd == "add-symbol-file")     //nothing
                    {
                    }
                    else if (xCmd == "set")     // nothing
                    {
                    }
                    else if (xCmd == "target")
                    {
                        if (Global.GDB.Connected)
                        {
                            mitmRefresh.Enabled   = true;
                            lablConnected.Visible = true;
                            lablRunning.Visible   = true;

                            mitmConnect.Enabled = true;
                            butnConnect.Enabled = true;
                            mitmConnect.Text    = "&Disconnect";
                            butnConnect.Text    = "&Disconnect";

                            Settings.InitWindows();

                            lboxDisassemble.SetItems(Global.AsmSource.Lines);
                        }
                        else
                        {
                            if (mConnectRetry < MAX_RETRY + 1)
                            {
                                Connect();
                            }
                            else
                            {
                                mitmConnect.Enabled = true;
                                butnConnect.Enabled = true;
                                mitmConnect.Text    = "&Connect";
                                butnConnect.Text    = "&Connect";
                                lboxDisassemble.Items.Clear();
                            }
                        }
                    }
                    else if (xCmd == "detach")
                    {
                        if (false == Global.GDB.Connected)
                        {
                            mitmConnect.Text     = "&Connect";
                            butnConnect.Text     = "&Connect";
                            mitmRefresh.Enabled  = false;
                            mitmContinue.Enabled = false;
                            butnContinue.Enabled = false;
                            mitmStepInto.Enabled = false;
                            mitmStepOver.Enabled = false;
                            lboxDisassemble.Items.Clear();
                            lablConnected.Visible       = false;
                            lablRunning.Visible         = false;
                            textCurrentFunction.Visible = false;
                        }
                    }
                    else if (xCmd == "delete")
                    {
                        Windows.mBreakpointsForm.OnDelete(aResponse);
                    }
                    else if ((xCmd == "stepi") || (xCmd == "nexti"))
                    {
                    }
                    else if (xCmd == "continue" || xCmd == "fg")
                    {
                        //lboxDisassemble.Items.Clear();
                    }
                    else if (xCmd == "where")
                    {
                        Windows.mCallStackForm.OnWhere(aResponse);
                    }
                    else if (xCmd == "break")
                    {
                        Windows.mBreakpointsForm.OnBreak(aResponse);
                    }
                    else if (xCmd.StartsWith("x/"))
                    {
                        Windows.mWatchesForm.OnWatchUpdate(aResponse);
                    }
                    else
                    {
                        throw new Exception("Unrecognized command response: " + aResponse.Command);
                    }
                }
            } catch (Exception e) {
                MessageBox.Show("Exception: " + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
            }
        }
Example #6
0
        public void OnWatchUpdate(GDB.Response aResponse)
        {
            var xCmdParts          = aResponse.Command.Split(' ');
            var xAddressOfResponse = Global.FromHexWithLeadingZeroX(xCmdParts[1]);
            var xFoundForUpdate    = new List <WatchUC>();

            // check if a register have this adress
            foreach (var item in mWatches.Values)
            {
                uint     xKey;
                RegNames?xReg = item.mRegister;
                if (xReg.HasValue)
                {
                    xKey = Windows.mRegistersForm.GetRegisterValue(xReg.Value);
                }
                else
                {
                    xKey = Global.FromHexWithLeadingZeroX(item.lablAddress.Text);
                }
                if (xKey == xAddressOfResponse)
                {
                    xFoundForUpdate.Add(item);
                }
            }

            if (xFoundForUpdate.Count == 0)
            {
                return;
            }

            var xB = new StringBuilder();

            if (aResponse.Error)
            {
                xB.Append(aResponse.ErrorMsg);
            }
            else
            {
                int xCurrentCountOnLine = 0;
                foreach (var item in aResponse.Text)
                {
                    var xIndex = item.IndexOf('\t');
                    var xPart  = item.Substring(xIndex);
                    var xSplit = xPart.Split(Global.TabSeparator, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var mem in xSplit)
                    {
                        if (xCurrentCountOnLine == 2)
                        {
                            xB.AppendLine();
                            xCurrentCountOnLine = 0;
                        }
                        else if (xCurrentCountOnLine > 0)
                        {
                            xB.Append("  ");
                        }
                        xB.Append(mem.ToUpper());
                        xCurrentCountOnLine++;
                    }
                }
            }

            var value = xB.ToString();

            foreach (var item in xFoundForUpdate)
            {
                item.lablValue.Text = value;
            }
        }
Example #7
0
        public void UpdateRegisters(GDB.Response aResponse)
        {
            var xResult = aResponse.Text;
            {
                // reset all to black
                foreach (var item in this.Controls[0].Controls)
                {
                    Label xL = item as Label;
                    if (xL != null && xL.ForeColor != Color.Black)
                    {
                        xL.ForeColor = Color.Black;
                    }
                }
            }

            int    i = 0;
            CPUReg xReg;
            CPUReg xEIP = null;

            while (i < xResult.Count - 1)
            {
                xReg = new CPUReg(xResult, ref i);
                mCurrentValues[xReg.mName] = xReg.mValue;
                if (xReg.mName == RegNames.EAX)
                {
                    SetRegLabels(lablEAX, lablAX, lablAH, lablAL, xReg.mValue);
                }
                else if (xReg.mName == RegNames.EBX)
                {
                    SetRegLabels(lablEBX, lablBX, lablBH, lablBL, xReg.mValue);
                }
                else if (xReg.mName == RegNames.ECX)
                {
                    SetRegLabels(lablECX, lablCX, lablCH, lablCL, xReg.mValue);
                }
                else if (xReg.mName == RegNames.EDX)
                {
                    SetRegLabels(lablEDX, lablDX, lablDH, lablDL, xReg.mValue);
                }
                else if (xReg.mName == RegNames.EIP)
                {
                    xEIP = xReg;
                    SetAddress(lablEIP, xReg);
                    lablEIPText.Text    = xReg.mText;
                    lablEIPText.Visible = true;
                }
                else if (xReg.mName == RegNames.EFLAGS)
                {
                    // http://en.wikipedia.org/wiki/FLAGS_register_%28computing%29
                    SetAddress(lablFlags, xReg);
                    lablFlagsText.Text    = xReg.mText;
                    lablFlagsText.Visible = true;
                }
                else if (xReg.mName == RegNames.ESP)
                {
                    SetAddress(lablESP, xReg);
                }
                else if (xReg.mName == RegNames.EBP)
                {
                    SetAddress(lablEBP, xReg);
                }
                else if (xReg.mName == RegNames.ESI)
                {
                    SetAddress(lablESI, xReg);
                }
                else if (xReg.mName == RegNames.EDI)
                {
                    SetAddress(lablEDI, xReg);
                }
                else if (xReg.mName == RegNames.SS)
                {
                    SetAddress(lablSS, xReg);
                }
                else if (xReg.mName == RegNames.CS)
                {
                    SetAddress(lablCS, xReg);
                }
                else if (xReg.mName == RegNames.DS)
                {
                    SetAddress(lablDS, xReg);
                }
                else if (xReg.mName == RegNames.ES)
                {
                    SetAddress(lablES, xReg);
                }
                else if (xReg.mName == RegNames.FS)
                {
                    SetAddress(lablFS, xReg);
                }
                else if (xReg.mName == RegNames.GS)
                {
                    SetAddress(lablGS, xReg);
                }
            }
            if (xEIP != null)
            {
                Windows.mMainForm.SetEIP(xEIP.mValue);
            }
        }
Example #8
0
 public void Log(GDB.Response aResponse)
 {
     lboxCmd.SelectedIndex = lboxCmd.Items.Add(aResponse);
     Application.DoEvents();
 }