private void Form1_Load(object sender, EventArgs e) { var bytes = System.IO.File.ReadAllBytes("UnitTestDll.dll"); var bytespdb = System.IO.File.ReadAllBytes("UnitTestDll.pdb"); System.IO.MemoryStream ms = new System.IO.MemoryStream(bytes); System.IO.MemoryStream mspdb = new System.IO.MemoryStream(bytespdb); env = new CLRSharp.CLRSharp_Environment(this); this.Text += " L# Ver:" + env.version; env.LoadModule(ms, mspdb); var types = env.GetAllTypes(); foreach (var t in types) { var tclr = env.GetType(t, null) as CLRSharp.Type_Common_CLRSharp; if (tclr != null && tclr.type_CLRSharp.HasMethods) { TreeNode node = new TreeNode(t); treeView1.Nodes.Add(node); foreach (var m in tclr.type_CLRSharp.Methods) { TreeNode method = new TreeNode(m.Name); method.Tag = m; node.Nodes.Add(method); if (m.HasParameters == false && m.Name.Contains("UnitTest") && m.IsStatic) { method.BackColor = Color.Yellow; } } if (tclr.type_CLRSharp.HasNestedTypes) { TreeNode nt = new TreeNode("NestedTypes"); node.Nodes.Add(nt); foreach (var ttt in tclr.type_CLRSharp.NestedTypes) { TreeNode snt = new TreeNode(ttt.Name); nt.Nodes.Add(snt); if (ttt.HasMethods) { foreach (var m in ttt.Methods) { TreeNode method = new TreeNode(m.Name); method.Tag = m; snt.Nodes.Add(method); } } } } } } SortTreeView(); treeView1.ExpandAll(); }
public void Init(CLRSharp.ICLRSharp_Environment env) { if (bInited) { return; } if (bodyNative.HasVariables) { typelistForLoc = new MethodParamList(env, bodyNative.Variables); } }
public void Init(CLRSharp.ICLRSharp_Environment env) { if (bInited) { return; } if (bodyNative.HasVariables) { typelistForLoc = new MethodParamList(env, bodyNative.Variables); } for (int i = 0; i < bodyNative.Instructions.Count; i++) { var code = bodyNative.Instructions[i]; OpCode c = new OpCode(); c.code = (CodeEx)(int)code.OpCode.Code; c.addr = code.Offset; if (code.SequencePoint != null) { if (debugDoc == null) { debugDoc = new Dictionary <string, int>(); } if (debugDoc.ContainsKey(code.SequencePoint.Document.Url) == false) { debugDoc.Add(code.SequencePoint.Document.Url, code.SequencePoint.StartLine); } c.debugline = code.SequencePoint.StartLine; } this.opCodes.Add(c); addr[c.addr] = i;; } var context = ThreadContext.activeContext; for (int i = 0; i < bodyNative.Instructions.Count; i++) { OpCode c = opCodes[i]; var code = bodyNative.Instructions[i]; c.InitToken(context, this, code.Operand); } bInited = true; }
//以后准备用自定义Body采集一遍,可以先过滤处理掉Mono.Cecil的代码中的指向,执行会更快 public CodeBody(CLRSharp.ICLRSharp_Environment env, Mono.Cecil.MethodDefinition _def) { this.method = _def; Init(env); }
private void Form1_Load(object sender, EventArgs e) { var bytes = System.IO.File.ReadAllBytes("UnitTestDll.dll"); var bytespdb = System.IO.File.ReadAllBytes("UnitTestDll.pdb"); //var bytesmdb = System.IO.File.ReadAllBytes("UnitTestDll.dll.mdb");//现在支持mdb了 System.IO.MemoryStream ms = new System.IO.MemoryStream(bytes); System.IO.MemoryStream mspdb = new System.IO.MemoryStream(bytespdb); //System.IO.MemoryStream msmdb = new System.IO.MemoryStream(bytesmdb); env = new CLRSharp.CLRSharp_Environment(this); this.Text += " L# Ver:" + env.version; try { env.LoadModule(ms, mspdb, new Mono.Cecil.Pdb.PdbReaderProvider()); //env.LoadModule(ms, msmdb, new Mono.Cecil.Mdb.MdbReaderProvider()); } catch (Exception err) { try { env.LoadModule(ms, null, null); Log_Error("符号文件无法识别"); } catch { this.Log_Error(err.ToString()); this.Log_Error("模块未加载完成,请检查错误"); } } var types = env.GetAllTypes(); foreach (var t in types) { var tclr = env.GetType(t) as CLRSharp.Type_Common_CLRSharp; if (tclr != null && tclr.type_CLRSharp.HasMethods) { TreeNode node = new TreeNode(t); treeView1.Nodes.Add(node); foreach (var m in tclr.type_CLRSharp.Methods) { TreeNode method = new TreeNode(m.Name); method.Tag = m; node.Nodes.Add(method); if (m.HasParameters == false && m.Name.Contains("UnitTest") && m.IsStatic) { method.BackColor = Color.Yellow; } } if (tclr.type_CLRSharp.HasNestedTypes) { TreeNode nt = new TreeNode("NestedTypes"); node.Nodes.Add(nt); foreach (var ttt in tclr.type_CLRSharp.NestedTypes) { TreeNode snt = new TreeNode(ttt.Name); nt.Nodes.Add(snt); if (ttt.HasMethods) { foreach (var m in ttt.Methods) { TreeNode method = new TreeNode(m.Name); method.Tag = m; snt.Nodes.Add(method); } } } } } } SortTreeView(); treeView1.ExpandAll(); }
private void Form1_Load(object sender, EventArgs e) { var bytes = System.IO.File.ReadAllBytes("UnitTestDll.dll"); var bytespdb = System.IO.File.ReadAllBytes("UnitTestDll.pdb"); //var bytesmdb = System.IO.File.ReadAllBytes("UnitTestDll.dll.mdb");//现在支持mdb了 System.IO.MemoryStream ms = new System.IO.MemoryStream(bytes); System.IO.MemoryStream mspdb = new System.IO.MemoryStream(bytespdb); //System.IO.MemoryStream msmdb = new System.IO.MemoryStream(bytesmdb); env = new CLRSharp.CLRSharp_Environment(this); this.Text += " L# Ver:" + env.version; try { env.LoadModule(ms, mspdb, new Mono.Cecil.Pdb.PdbReaderProvider()); //env.LoadModule(ms, msmdb, new Mono.Cecil.Mdb.MdbReaderProvider()); } catch (Exception err) { this.Log_Error(err.ToString()); this.Log_Error("模块未加载完成,请检查错误"); } var types = env.GetAllTypes(); foreach (var t in types) { var tclr = env.GetType(t) as CLRSharp.Type_Common_CLRSharp; if (tclr != null && tclr.type_CLRSharp.HasMethods) { TreeNode node = new TreeNode(t); treeView1.Nodes.Add(node); foreach (var m in tclr.type_CLRSharp.Methods) { TreeNode method = new TreeNode(m.Name); method.Tag = m; node.Nodes.Add(method); if (m.HasParameters == false && m.Name.Contains("UnitTest") && m.IsStatic) { method.BackColor = Color.Yellow; } } if (tclr.type_CLRSharp.HasNestedTypes) { TreeNode nt = new TreeNode("NestedTypes"); node.Nodes.Add(nt); foreach (var ttt in tclr.type_CLRSharp.NestedTypes) { TreeNode snt = new TreeNode(ttt.Name); nt.Nodes.Add(snt); if (ttt.HasMethods) { foreach (var m in ttt.Methods) { TreeNode method = new TreeNode(m.Name); method.Tag = m; snt.Nodes.Add(method); } } } } } } SortTreeView(); treeView1.ExpandAll(); }