public CodeRow(XInstruction inst) { UseItemStyleForSubItems = false; Inst = inst; Text = Inst.Offset.ToString("X"); SubItems.Add(Inst.OpCode); var lineItem = SubItems.Add(inst.Line); if (inst.RefId != 0) { lineItem.ForeColor = Color.Blue; } }
private void SaveCode(XNodeOut classNode, MethodDefinition method) { XNodeOut methodNode = classNode.AddMethod(method); if (Build.DecompileCSharp) { methodNode.CSharp = DecompileMethod(method); } if (method.Body == null) { return; } // record MSIL if (Build.SaveMsil) { methodNode.Msil = new List <XInstruction>(); foreach (var inst in method.Body.Instructions) { var xInst = new XInstruction(); xInst.Offset = inst.Offset; xInst.OpCode = inst.OpCode.Name; xInst.Line = (inst.Operand != null) ? inst.Operand.ToString() : ""; if (inst.OpCode == OpCodes.Call || inst.OpCode == OpCodes.Calli || inst.OpCode == OpCodes.Callvirt || inst.OpCode == OpCodes.Newobj || inst.OpCode == OpCodes.Ldftn) // pushes a function pointer to the stack { var call = inst.Operand as MethodReference; if (call != null) { var classRef = GetClassRef(call.DeclaringType); var methodRef = classRef.AddMethod(call); xInst.RefId = methodRef.ID; } else { Debug.WriteLine("Unable to track: " + inst.Operand.ToString()); } } else if (inst.OpCode == OpCodes.Stfld || inst.OpCode == OpCodes.Stsfld || inst.OpCode == OpCodes.Ldfld || inst.OpCode == OpCodes.Ldflda || inst.OpCode == OpCodes.Ldsfld || inst.OpCode == OpCodes.Ldsflda) { var fieldDef = inst.Operand as FieldReference; var classRef = GetClassRef(fieldDef.DeclaringType); var fieldRef = classRef.AddField(fieldDef); xInst.RefId = fieldRef.ID; } else if (inst.OpCode.FlowControl == FlowControl.Branch || inst.OpCode.FlowControl == FlowControl.Cond_Branch) { var op = inst.Operand as Instruction; if (op != null) { int offset = op.Offset; xInst.Line = "goto " + offset.ToString("X"); xInst.RefId = offset; } } methodNode.Msil.Add(xInst); } } }
public CodeRow(XInstruction inst) { UseItemStyleForSubItems = false; Inst = inst; Text = Inst.Offset.ToString("X"); SubItems.Add(Inst.OpCode); var lineItem = SubItems.Add(inst.Line); if (inst.RefId != 0) lineItem.ForeColor = Color.Blue; }