Exemplo n.º 1
0
            public GdbAsmLine(string aInput)
            {
                //"0x0056d2b9 <_end_data+0>:\tmov    DWORD PTR ds:0x550020,ebx\n"
                var s       = GDB.Unescape(aInput);
                var xSplit1 = s.Split(Global.TabSeparator, StringSplitOptions.RemoveEmptyEntries);

                var xSplit2 = xSplit1[0].Split(Global.SpaceSeparator, StringSplitOptions.RemoveEmptyEntries);

                int xIndex = 0;

                //newer gdb above 6.6 or higher versions
                if (xSplit2[0] == "=>")
                {
                    mEIPHere = true;
                    xIndex   = 1;
                }
                mAddr = Global.FromHexWithLeadingZeroX(xSplit2[xIndex]);
                string xLabel;

                if (xSplit2.Length > xIndex + 1)
                {
                    xLabel = xSplit2[xIndex + 1];
                }

                xSplit2 = xSplit1[1].Split(Global.SpaceSeparator, StringSplitOptions.RemoveEmptyEntries);
                mOp     = xSplit2[0];
                if (xSplit2.Length > 1)
                {
                    for (int j = 1; j < xSplit2.Length; j++)
                    {
                        mData += xSplit2[j] + " ";
                    }
                    mData = mData.TrimEnd();
                }
            }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
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;
                }
            }
        }
Exemplo n.º 4
0
        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);
            }
        }
Exemplo n.º 5
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();
     }
 }
Exemplo n.º 6
0
 public void Log(GDB.Response aResponse) {
     lboxCmd.SelectedIndex = lboxCmd.Items.Add(aResponse);
     Application.DoEvents();
 }
Exemplo n.º 7
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; 
			}
		}
Exemplo n.º 8
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);
            }
        }