Added call stack disassembly

This commit is contained in:
x1nixmzeng 2018-01-21 16:12:25 +00:00
parent aaed9a18e3
commit ed02200d6c
6 changed files with 112 additions and 37 deletions

3
.gitmodules vendored
View File

@ -1,3 +1,6 @@
[submodule "import/subhook"]
path = import/subhook
url = https://github.com/Zeex/subhook
[submodule "import/cs_x86"]
path = import/cs_x86
url = https://github.com/x1nixmzeng/cs_x86

View File

@ -1,13 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.6
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Cxbx", "Cxbx.vcxproj", "{E7A72D3D-5810-4078-A243-348B59726365}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "subhook", "subhook.vcxproj", "{CD2DDE93-B45E-4D11-876D-D0056C3DD407}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CxbxDebugger", "..\..\src\CxbxDebugger\CxbxDebugger.csproj", "{4A68E962-3805-4376-99D3-0AC59E9BEE69}"
ProjectSection(ProjectDependencies) = postProject
{9131B025-5019-4DEE-84A3-86D2703A81C0} = {9131B025-5019-4DEE-84A3-86D2703A81C0}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cs_x86", "..\..\import\cs_x86\cs_x86\cs_x86.csproj", "{9131B025-5019-4DEE-84A3-86D2703A81C0}"
ProjectSection(ProjectDependencies) = postProject
{2171C0E8-4915-49B9-AC23-A484FA08C126} = {2171C0E8-4915-49B9-AC23-A484FA08C126}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "capstone_dll_2015", "..\..\import\cs_x86\capstone_2015\capstone_dll_2015.vcxproj", "{2171C0E8-4915-49B9-AC23-A484FA08C126}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Debugger", "Debugger", "{174CB14E-34E3-422F-9A99-DBE88FF0EFBB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -49,8 +61,35 @@ Global
{4A68E962-3805-4376-99D3-0AC59E9BEE69}.Release|Win32.Build.0 = Release|Any CPU
{4A68E962-3805-4376-99D3-0AC59E9BEE69}.Release|x64.ActiveCfg = Release|Any CPU
{4A68E962-3805-4376-99D3-0AC59E9BEE69}.Release|x64.Build.0 = Release|Any CPU
{9131B025-5019-4DEE-84A3-86D2703A81C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9131B025-5019-4DEE-84A3-86D2703A81C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9131B025-5019-4DEE-84A3-86D2703A81C0}.Debug|Win32.ActiveCfg = Debug|Any CPU
{9131B025-5019-4DEE-84A3-86D2703A81C0}.Debug|Win32.Build.0 = Debug|Any CPU
{9131B025-5019-4DEE-84A3-86D2703A81C0}.Debug|x64.ActiveCfg = Debug|Any CPU
{9131B025-5019-4DEE-84A3-86D2703A81C0}.Debug|x64.Build.0 = Debug|Any CPU
{9131B025-5019-4DEE-84A3-86D2703A81C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9131B025-5019-4DEE-84A3-86D2703A81C0}.Release|Any CPU.Build.0 = Release|Any CPU
{9131B025-5019-4DEE-84A3-86D2703A81C0}.Release|Win32.ActiveCfg = Release|Any CPU
{9131B025-5019-4DEE-84A3-86D2703A81C0}.Release|Win32.Build.0 = Release|Any CPU
{9131B025-5019-4DEE-84A3-86D2703A81C0}.Release|x64.ActiveCfg = Release|Any CPU
{9131B025-5019-4DEE-84A3-86D2703A81C0}.Release|x64.Build.0 = Release|Any CPU
{2171C0E8-4915-49B9-AC23-A484FA08C126}.Debug|Any CPU.ActiveCfg = Debug|Win32
{2171C0E8-4915-49B9-AC23-A484FA08C126}.Debug|Win32.ActiveCfg = Debug|Win32
{2171C0E8-4915-49B9-AC23-A484FA08C126}.Debug|Win32.Build.0 = Debug|Win32
{2171C0E8-4915-49B9-AC23-A484FA08C126}.Debug|x64.ActiveCfg = Debug|x64
{2171C0E8-4915-49B9-AC23-A484FA08C126}.Debug|x64.Build.0 = Debug|x64
{2171C0E8-4915-49B9-AC23-A484FA08C126}.Release|Any CPU.ActiveCfg = Release|Win32
{2171C0E8-4915-49B9-AC23-A484FA08C126}.Release|Win32.ActiveCfg = Release|Win32
{2171C0E8-4915-49B9-AC23-A484FA08C126}.Release|Win32.Build.0 = Release|Win32
{2171C0E8-4915-49B9-AC23-A484FA08C126}.Release|x64.ActiveCfg = Release|x64
{2171C0E8-4915-49B9-AC23-A484FA08C126}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{4A68E962-3805-4376-99D3-0AC59E9BEE69} = {174CB14E-34E3-422F-9A99-DBE88FF0EFBB}
{9131B025-5019-4DEE-84A3-86D2703A81C0} = {174CB14E-34E3-422F-9A99-DBE88FF0EFBB}
{2171C0E8-4915-49B9-AC23-A484FA08C126} = {174CB14E-34E3-422F-9A99-DBE88FF0EFBB}
EndGlobalSection
EndGlobal

1
import/cs_x86 Submodule

@ -0,0 +1 @@
Subproject commit e219bde89794b26cd09e116921bc6e9e5a157089

View File

@ -49,6 +49,10 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="cs_x86, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\build\win32\Debug\cs_x86.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Windows" />

View File

@ -39,7 +39,9 @@
this.btnDumpCallstack = new System.Windows.Forms.ToolStripButton();
this.tableLayoutPanel3 = new System.Windows.Forms.TableLayoutPanel();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage4 = new System.Windows.Forms.TabPage();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.textBox3 = new System.Windows.Forms.TextBox();
this.lbCallstack = new System.Windows.Forms.ListBox();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.groupBox1 = new System.Windows.Forms.GroupBox();
@ -52,14 +54,12 @@
this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.lbOpenedFiles = new System.Windows.Forms.ListBox();
this.tabPage4 = new System.Windows.Forms.TabPage();
this.tabPage5 = new System.Windows.Forms.TabPage();
this.button1 = new System.Windows.Forms.Button();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.lblStatus = new System.Windows.Forms.ToolStripStatusLabel();
this.textBox3 = new System.Windows.Forms.TextBox();
this.toolStrip1.SuspendLayout();
this.tableLayoutPanel3.SuspendLayout();
this.tabControl1.SuspendLayout();
@ -183,7 +183,16 @@
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(756, 235);
this.tabControl1.TabIndex = 3;
this.tabControl1.SelectedIndexChanged += new System.EventHandler(this.tabControl1_SelectedIndexChanged);
//
// tabPage4
//
this.tabPage4.Location = new System.Drawing.Point(4, 22);
this.tabPage4.Name = "tabPage4";
this.tabPage4.Padding = new System.Windows.Forms.Padding(3);
this.tabPage4.Size = new System.Drawing.Size(748, 209);
this.tabPage4.TabIndex = 3;
this.tabPage4.Text = "Xbe Info";
this.tabPage4.UseVisualStyleBackColor = true;
//
// tabPage1
//
@ -197,6 +206,17 @@
this.tabPage1.Text = "Disassembly";
this.tabPage1.UseVisualStyleBackColor = true;
//
// textBox3
//
this.textBox3.Font = new System.Drawing.Font("Lucida Console", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.textBox3.Location = new System.Drawing.Point(218, 6);
this.textBox3.Multiline = true;
this.textBox3.Name = "textBox3";
this.textBox3.ReadOnly = true;
this.textBox3.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.textBox3.Size = new System.Drawing.Size(524, 197);
this.textBox3.TabIndex = 1;
//
// lbCallstack
//
this.lbCallstack.FormattingEnabled = true;
@ -204,6 +224,7 @@
this.lbCallstack.Name = "lbCallstack";
this.lbCallstack.Size = new System.Drawing.Size(209, 186);
this.lbCallstack.TabIndex = 0;
this.lbCallstack.SelectedIndexChanged += new System.EventHandler(this.lbCallstack_SelectedIndexChanged);
//
// tabPage2
//
@ -314,16 +335,6 @@
this.lbOpenedFiles.Size = new System.Drawing.Size(216, 203);
this.lbOpenedFiles.TabIndex = 0;
//
// tabPage4
//
this.tabPage4.Location = new System.Drawing.Point(4, 22);
this.tabPage4.Name = "tabPage4";
this.tabPage4.Padding = new System.Windows.Forms.Padding(3);
this.tabPage4.Size = new System.Drawing.Size(748, 209);
this.tabPage4.TabIndex = 3;
this.tabPage4.Text = "Xbe Info";
this.tabPage4.UseVisualStyleBackColor = true;
//
// tabPage5
//
this.tabPage5.Controls.Add(this.button1);
@ -339,30 +350,30 @@
//
// button1
//
this.button1.Location = new System.Drawing.Point(400, 7);
this.button1.Location = new System.Drawing.Point(593, 6);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.Size = new System.Drawing.Size(149, 23);
this.button1.TabIndex = 2;
this.button1.Text = "Read";
this.button1.Text = "Read Memory";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(278, 9);
this.textBox2.Location = new System.Drawing.Point(471, 8);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(116, 20);
this.textBox2.TabIndex = 1;
//
// textBox1
//
this.textBox1.Font = new System.Drawing.Font("Lucida Console", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.textBox1.Font = new System.Drawing.Font("Lucida Console", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.textBox1.Location = new System.Drawing.Point(6, 6);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.ReadOnly = true;
this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.textBox1.Size = new System.Drawing.Size(266, 197);
this.textBox1.Size = new System.Drawing.Size(459, 197);
this.textBox1.TabIndex = 0;
//
// statusStrip1
@ -381,17 +392,6 @@
this.lblStatus.Size = new System.Drawing.Size(39, 17);
this.lblStatus.Text = "Ready";
//
// textBox3
//
this.textBox3.Font = new System.Drawing.Font("Lucida Console", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.textBox3.Location = new System.Drawing.Point(218, 6);
this.textBox3.Multiline = true;
this.textBox3.Name = "textBox3";
this.textBox3.ReadOnly = true;
this.textBox3.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.textBox3.Size = new System.Drawing.Size(524, 197);
this.textBox3.TabIndex = 1;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

View File

@ -9,6 +9,7 @@ using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using cs_x86;
namespace CxbxDebugger
{
@ -363,6 +364,7 @@ namespace CxbxDebugger
frm.DebugModules.Add(Process);
}
public void OnProcessExit(DebuggerProcess Process, uint ExitCode)
{
int remainingThreads = Process.Threads.Count;
@ -561,12 +563,15 @@ namespace CxbxDebugger
return bmp;
}
List<IntPtr> CallstackAddress = new List<IntPtr>();
private void btnDumpCallstack_Click(object sender, EventArgs e)
{
int Index = cbThreads.SelectedIndex;
if (Index == -1)
return;
CallstackAddress.Clear();
lbCallstack.Items.Clear();
int OtherModuleCount = 0;
@ -596,6 +601,7 @@ namespace CxbxDebugger
if (OtherModuleCount > 0)
{
CallstackAddress.Add(IntPtr.Zero);
lbCallstack.Items.Add("[External Code]");
OtherModuleCount = 0;
}
@ -603,21 +609,18 @@ namespace CxbxDebugger
uint ModuleOffset = (uint)StackFrame.PC - ModuleBase;
string FrameString = string.Format("{0} +{1:X8} ({2:X8})", ModuleName, ModuleOffset, (uint)StackFrame.PC);
CallstackAddress.Add(StackFrame.PC);
lbCallstack.Items.Add(FrameString);
}
if (OtherModuleCount > 0)
{
CallstackAddress.Add(IntPtr.Zero);
lbCallstack.Items.Add("[External Code]");
OtherModuleCount = 0;
}
}
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
uint addr = 0;
@ -655,5 +658,30 @@ namespace CxbxDebugger
// TODO Fix the frame buffer lookup
//pictureBox1.Image = DumpFramebuffer();
}
private void lbCallstack_SelectedIndexChanged(object sender, EventArgs e)
{
if( lbCallstack.SelectedIndex != -1 )
{
IntPtr ptr = CallstackAddress[lbCallstack.SelectedIndex];
if (ptr == IntPtr.Zero)
return;
byte[] data = DebugThreads[0].OwningProcess.ReadMemoryBlock(ptr, 32);
string disassembly = "";
using (Capstone cs = Capstone.CreateEngine())
{
cs.DisassembleIt(data, (ulong)ptr, delegate (CapstoneInstruction Instruction)
{
disassembly += string.Format("{0:x8} {1}", Instruction.Address, Instruction.Disassembly) + "\r\n";
});
}
textBox1.Text = disassembly;
}
}
}
}