void WriteTypeHeader(TypeDefinition type) { m_writer.Write(".class "); if ((type.Attributes & TypeAttributes.ClassSemanticMask) == TypeAttributes.Interface) { m_writer.Write("interface "); } int attributes = (int)type.Attributes; m_writer.WriteFlags(attributes, (int)TypeAttributes.VisibilityMask, m_typeVisibilityVals, m_typeVisibilityMap); m_writer.WriteFlags(attributes, (int)TypeAttributes.LayoutMask, m_typeLayoutVals, m_typeLayoutMap); m_writer.WriteFlags(attributes, (int)TypeAttributes.StringFormatMask, m_typeFormatVals, m_typeFormatMap); m_writer.WriteFlags(attributes, m_typeVals, m_typeMap); m_writer.WriteLine(Formater.Escape(type.Name)); if (type.BaseType != null) { m_writer.Indent(); m_writer.Write("extends "); m_writer.WriteLine(Formater.Format(type.BaseType)); m_writer.Unindent(); } }
void WriteResourceHeader(Resource r) { m_writer.Write("mresource "); m_writer.BaseWriter.Write((r.Flags & ManifestResourceAttributes.Public) > 0 ? "public" : "private"); m_writer.BaseWriter.Write(" "); m_writer.BaseWriter.WriteLine(Formater.Escape(r.Name)); }
public override void VisitAssemblyNameReference(AssemblyNameReference reference) { m_writer.Write(".assembly extern "); m_writer.WriteLine(Formater.Escape(reference.Name)); m_writer.OpenBlock(); AssemblyDetails(reference); m_writer.CloseBlock(); }
//FIXME: Where should this be? move to ReflectionDisassembler ? public void VisitMemberReference(MemberReference member) { if (member == null) { return; } MethodReference method = member as MethodReference; if (method != null) { StringBuilder sb = new StringBuilder(" "); if (method.HasThis) { sb.Append("instance "); } if (method.ReturnType.ReturnType == null) { Console.WriteLine("method = {0}, rt = {1}", method.Name, method.ReturnType); } sb.Append(Formater.Signature(method.ReturnType.ReturnType, false, true)); sb.Append(" "); sb.Append(Formater.Signature(method.DeclaringType)); sb.Append("::"); sb.Append(Formater.Escape(method.Name)); sb.Append("("); for (int i = 0; i < method.Parameters.Count; i++) { sb.Append(Formater.Signature(method.Parameters [i].ParameterType, false, true)); if (i < method.Parameters.Count - 1) { sb.Append(", "); } } sb.Append(")"); m_writer.Write(sb.ToString()); return; } FieldReference field = member as FieldReference; if (field != null) { StringBuilder sb = new StringBuilder(" "); sb.Append(Formater.Signature(field.FieldType, false, true)); sb.Append(" "); sb.Append(Formater.Signature(field.DeclaringType, true)); sb.Append("::"); sb.Append(Formater.Escape(field.Name)); m_writer.Write(sb.ToString()); return; } }
public override void VisitModuleDefinition(ModuleDefinition module) { m_writer.Write(".module "); m_writer.Write(Formater.Escape(module.Name)); m_writer.Write(" // GUID: "); m_writer.WriteLine(module.Mvid); m_writer.WriteLine(); }
//FIXME: Move to ReflectionDisassembler ? public void DisassembleMethod(MethodDefinition method, CilWriter writer) { m_writer = writer; // .method public hidebysig specialname // instance default class [mscorlib]System.IO.TextWriter get_BaseWriter () cil managed // // write method header m_writer.Write(".method "); //emit flags WriteMethodVisibility(method.Attributes); WriteMethodAttributes(method.Attributes); m_writer.WriteLine(); m_writer.Indent(); if (method.HasThis) { m_writer.Write("instance "); } //call convention WriteMethodCallingConvention(method.CallingConvention); //return type //method.ReturnType.ReturnType.Accept (m_reflectDis); //FIXME: another visitor for printing names (refs to methoddef/typedef/typeref etc m_writer.Write(Formater.Signature(method.ReturnType.ReturnType, false, true)); m_writer.Write(method.Name); //( params ) m_writer.Write(" ("); method.Parameters.Accept(m_reflectDis); m_writer.Write(") "); //cil managed WriteMethodCodeType(method.ImplAttributes); WriteMethodManagedType(method.ImplAttributes); m_writer.Unindent(); m_writer.OpenBlock(); m_reflectDis.VisitCustomAttributeCollection(method.CustomAttributes); m_reflectDis.VisitSecurityDeclarationCollection(method.SecurityDeclarations); if (method.HasBody) { VisitMethodBody(method.Body); } m_writer.CloseBlock(); }
public override void VisitModuleReferenceCollection(ModuleReferenceCollection modules) { foreach (ModuleReference module in modules) { m_writer.Write(".module extern "); m_writer.WriteLine(Formater.Escape(module.Name)); } if (modules.Count > 0) { m_writer.WriteLine(); } }
public override void VisitAssemblyDefinition(AssemblyDefinition asm) { m_writer.Write(".assembly "); m_writer.WriteLine(String.Concat("'", Formater.Escape(asm.Name.Name), "'")); m_writer.OpenBlock(); AssemblyDetails(asm.Name); m_rd.VisitCustomAttributeCollection(asm.CustomAttributes); m_rd.VisitSecurityDeclarationCollection(asm.SecurityDeclarations); m_writer.CloseBlock(); m_writer.WriteLine(); }
public override void VisitParameterDefinition(ParameterDefinition parameter) { //parameter.ParameterType.Accept (this); m_writer.Write(Formater.Signature(parameter.ParameterType, true, true)); m_writer.Write(" {0}", Formater.Escape(parameter.Name)); }
public override void VisitTypeReference(TypeReference type) { m_writer.Write(Formater.Signature(type)); }
public override void VisitLinkedResource(LinkedResource lr) { m_writer.Write(".file "); m_writer.BaseWriter.Write(Formater.Escape(lr.File)); m_writer.BaseWriter.WriteLine(" at 0x0"); }
public override void VisitAssemblyLinkedResource(AssemblyLinkedResource alr) { m_writer.Write(".assembly extern "); m_writer.BaseWriter.WriteLine(Formater.Escape(alr.Assembly.Name)); }
public override void VisitInstructionCollection(InstructionCollection instructions) { foreach (Instruction instr in instructions) { CheckExceptionHandlers(instr); m_writer.Write("{0}: {1}", Label(instr), instr.OpCode.Name); switch (instr.OpCode.OperandType) { case OperandType.InlineNone: break; case OperandType.InlineSwitch: m_writer.WriteLine("("); m_writer.Indent(); Instruction [] targets = (Instruction [])instr.Operand; for (int i = 0; i < targets.Length; i++) { m_writer.Write(Label(targets [i])); m_writer.WriteLine(i < targets.Length - 1 ? "," : string.Empty); } m_writer.Unindent(); m_writer.Write(")"); break; case OperandType.ShortInlineBrTarget: case OperandType.InlineBrTarget: m_writer.WriteLine(Label((Instruction)instr.Operand)); break; case OperandType.ShortInlineVar: case OperandType.InlineVar: VariableDefinition var = (VariableDefinition)instr.Operand; if (var.Name != null && var.Name.Length > 0) { m_writer.Write(var.Name); } else { m_writer.Write(instructions.Container.Variables.IndexOf(var)); } break; case OperandType.ShortInlineParam: case OperandType.InlineParam: ParameterDefinition param = (ParameterDefinition)instr.Operand; if (param.Name != null && param.Name.Length > 0) { m_writer.Write(Formater.Escape(param.Name)); } else { m_writer.Write(instructions.Container.Method.Parameters.IndexOf(param)); } break; case OperandType.InlineI: case OperandType.InlineI8: case OperandType.InlineR: case OperandType.ShortInlineI: case OperandType.ShortInlineR: m_writer.Write(instr.Operand.ToString()); break; case OperandType.InlineString: //FIXME: Handle unicode strings with non zero high byte StringBuilder sb = new StringBuilder(instr.Operand.ToString()); //FIXME: extract to a method sb.Replace("\"", "\\\""); sb.Replace("\t", "\\t"); sb.Replace("\r", "\\r"); sb.Replace("\n", "\\n"); m_writer.Write(String.Concat( "\"", sb.ToString(), "\"")); break; case OperandType.InlineType: m_writer.Write(Formater.Signature((TypeReference)instr.Operand)); break; case OperandType.InlineMethod: case OperandType.InlineField: VisitMemberReference(instr.Operand as MemberReference); break; case OperandType.InlineTok: if (instr.Operand is TypeReference) { m_writer.Write(Formater.Signature((TypeReference)instr.Operand, true)); } else if (instr.Operand is MemberReference) { if (instr.Operand is FieldReference) { m_writer.Write("field"); } //FIXME: method VisitMemberReference((MemberReference)instr.Operand); } break; } m_writer.WriteLine(); } }
public override void VisitVariableDefinition(VariableDefinition var) { m_writer.Write(Formater.Signature(var.VariableType)); m_writer.Write(Formater.Escape(var.Name)); }